Loading media/codec2/components/aac/C2SoftAacEnc.cpp +44 −8 Original line number Diff line number Diff line Loading @@ -159,7 +159,8 @@ C2SoftAacEnc::C2SoftAacEnc( mInputSize(0), mNextFrameTimestampUs(0), mSignalledError(false), mOutIndex(0u) { mOutIndex(0u), mRemainderLen(0u) { } C2SoftAacEnc::~C2SoftAacEnc() { Loading @@ -185,6 +186,7 @@ c2_status_t C2SoftAacEnc::onStop() { mInputSize = 0u; mNextFrameTimestampUs = 0; mSignalledError = false; mRemainderLen = 0; return C2_OK; } Loading Loading @@ -369,18 +371,21 @@ void C2SoftAacEnc::process( mInputTimeSet = true; } size_t numFrames = (capacity + mInputSize + (eos ? mNumBytesPerInputFrame - 1 : 0)) size_t numFrames = (mRemainderLen + capacity + mInputSize + (eos ? mNumBytesPerInputFrame - 1 : 0)) / mNumBytesPerInputFrame; ALOGV("capacity = %zu; mInputSize = %zu; numFrames = %zu " "mNumBytesPerInputFrame = %u inputTS = %lld", "mNumBytesPerInputFrame = %u inputTS = %lld remaining = %zu", capacity, mInputSize, numFrames, mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll()); mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll(), mRemainderLen); std::shared_ptr<C2LinearBlock> block; std::unique_ptr<C2WriteView> wView; uint8_t *outPtr = temp; size_t outAvailable = 0u; uint64_t inputIndex = work->input.ordinal.frameIndex.peeku(); size_t bytesPerSample = channelCount * sizeof(int16_t); AACENC_InArgs inargs; AACENC_OutArgs outargs; Loading Loading @@ -449,7 +454,25 @@ void C2SoftAacEnc::process( }; std::list<OutputBuffer> outputBuffers; while (encoderErr == AACENC_OK && inargs.numInSamples > 0) { if (mRemainderLen > 0) { size_t offset = 0; for (; mRemainderLen < bytesPerSample && offset < capacity; ++offset) { mRemainder[mRemainderLen++] = data[offset]; } data += offset; capacity -= offset; if (mRemainderLen == bytesPerSample) { inBuffer[0] = mRemainder; inBufferSize[0] = bytesPerSample; inargs.numInSamples = channelCount; mRemainderLen = 0; ALOGV("Processing remainder"); } else { // We have exhausted the input already inargs.numInSamples = 0; } } while (encoderErr == AACENC_OK && inargs.numInSamples >= channelCount) { if (numFrames && !block) { C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; // TODO: error handling, proper usage, etc. Loading Loading @@ -486,7 +509,7 @@ void C2SoftAacEnc::process( mNextFrameTimestampUs = work->input.ordinal.timestamp + (consumed * 1000000ll / channelCount / sampleRate); std::shared_ptr<C2Buffer> buffer = createLinearBuffer(block, 0, outargs.numOutBytes); #if defined(LOG_NDEBUG) && !LOG_NDEBUG #if 0 hexdump(outPtr, std::min(outargs.numOutBytes, 256)); #endif outPtr = temp; Loading @@ -503,12 +526,17 @@ void C2SoftAacEnc::process( inBufferSize[0] -= outargs.numInSamples * sizeof(int16_t); inargs.numInSamples -= outargs.numInSamples; } if (inBuffer[0] == mRemainder) { inBuffer[0] = const_cast<uint8_t *>(data); inBufferSize[0] = capacity; inargs.numInSamples = capacity / sizeof(int16_t); } } ALOGV("encoderErr = %d mInputSize = %zu " "inargs.numInSamples = %d, mNextFrameTimestampUs = %lld", encoderErr, mInputSize, inargs.numInSamples, mNextFrameTimestampUs.peekll()); } if (eos && inBufferSize[0] > 0) { if (numFrames && !block) { C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; Loading Loading @@ -539,6 +567,14 @@ void C2SoftAacEnc::process( &outBufDesc, &inargs, &outargs); inBufferSize[0] = 0; } if (inBufferSize[0] > 0) { for (size_t i = 0; i < inBufferSize[0]; ++i) { mRemainder[i] = static_cast<uint8_t *>(inBuffer[0])[i]; } mRemainderLen = inBufferSize[0]; } while (outputBuffers.size() > 1) { Loading media/codec2/components/aac/C2SoftAacEnc.h +4 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,10 @@ private: bool mSignalledError; std::atomic_uint64_t mOutIndex; // We support max 6 channels uint8_t mRemainder[6 * sizeof(int16_t)]; size_t mRemainderLen; status_t initEncoder(); status_t setAudioParams(); Loading Loading
media/codec2/components/aac/C2SoftAacEnc.cpp +44 −8 Original line number Diff line number Diff line Loading @@ -159,7 +159,8 @@ C2SoftAacEnc::C2SoftAacEnc( mInputSize(0), mNextFrameTimestampUs(0), mSignalledError(false), mOutIndex(0u) { mOutIndex(0u), mRemainderLen(0u) { } C2SoftAacEnc::~C2SoftAacEnc() { Loading @@ -185,6 +186,7 @@ c2_status_t C2SoftAacEnc::onStop() { mInputSize = 0u; mNextFrameTimestampUs = 0; mSignalledError = false; mRemainderLen = 0; return C2_OK; } Loading Loading @@ -369,18 +371,21 @@ void C2SoftAacEnc::process( mInputTimeSet = true; } size_t numFrames = (capacity + mInputSize + (eos ? mNumBytesPerInputFrame - 1 : 0)) size_t numFrames = (mRemainderLen + capacity + mInputSize + (eos ? mNumBytesPerInputFrame - 1 : 0)) / mNumBytesPerInputFrame; ALOGV("capacity = %zu; mInputSize = %zu; numFrames = %zu " "mNumBytesPerInputFrame = %u inputTS = %lld", "mNumBytesPerInputFrame = %u inputTS = %lld remaining = %zu", capacity, mInputSize, numFrames, mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll()); mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll(), mRemainderLen); std::shared_ptr<C2LinearBlock> block; std::unique_ptr<C2WriteView> wView; uint8_t *outPtr = temp; size_t outAvailable = 0u; uint64_t inputIndex = work->input.ordinal.frameIndex.peeku(); size_t bytesPerSample = channelCount * sizeof(int16_t); AACENC_InArgs inargs; AACENC_OutArgs outargs; Loading Loading @@ -449,7 +454,25 @@ void C2SoftAacEnc::process( }; std::list<OutputBuffer> outputBuffers; while (encoderErr == AACENC_OK && inargs.numInSamples > 0) { if (mRemainderLen > 0) { size_t offset = 0; for (; mRemainderLen < bytesPerSample && offset < capacity; ++offset) { mRemainder[mRemainderLen++] = data[offset]; } data += offset; capacity -= offset; if (mRemainderLen == bytesPerSample) { inBuffer[0] = mRemainder; inBufferSize[0] = bytesPerSample; inargs.numInSamples = channelCount; mRemainderLen = 0; ALOGV("Processing remainder"); } else { // We have exhausted the input already inargs.numInSamples = 0; } } while (encoderErr == AACENC_OK && inargs.numInSamples >= channelCount) { if (numFrames && !block) { C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; // TODO: error handling, proper usage, etc. Loading Loading @@ -486,7 +509,7 @@ void C2SoftAacEnc::process( mNextFrameTimestampUs = work->input.ordinal.timestamp + (consumed * 1000000ll / channelCount / sampleRate); std::shared_ptr<C2Buffer> buffer = createLinearBuffer(block, 0, outargs.numOutBytes); #if defined(LOG_NDEBUG) && !LOG_NDEBUG #if 0 hexdump(outPtr, std::min(outargs.numOutBytes, 256)); #endif outPtr = temp; Loading @@ -503,12 +526,17 @@ void C2SoftAacEnc::process( inBufferSize[0] -= outargs.numInSamples * sizeof(int16_t); inargs.numInSamples -= outargs.numInSamples; } if (inBuffer[0] == mRemainder) { inBuffer[0] = const_cast<uint8_t *>(data); inBufferSize[0] = capacity; inargs.numInSamples = capacity / sizeof(int16_t); } } ALOGV("encoderErr = %d mInputSize = %zu " "inargs.numInSamples = %d, mNextFrameTimestampUs = %lld", encoderErr, mInputSize, inargs.numInSamples, mNextFrameTimestampUs.peekll()); } if (eos && inBufferSize[0] > 0) { if (numFrames && !block) { C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; Loading Loading @@ -539,6 +567,14 @@ void C2SoftAacEnc::process( &outBufDesc, &inargs, &outargs); inBufferSize[0] = 0; } if (inBufferSize[0] > 0) { for (size_t i = 0; i < inBufferSize[0]; ++i) { mRemainder[i] = static_cast<uint8_t *>(inBuffer[0])[i]; } mRemainderLen = inBufferSize[0]; } while (outputBuffers.size() > 1) { Loading
media/codec2/components/aac/C2SoftAacEnc.h +4 −0 Original line number Diff line number Diff line Loading @@ -61,6 +61,10 @@ private: bool mSignalledError; std::atomic_uint64_t mOutIndex; // We support max 6 channels uint8_t mRemainder[6 * sizeof(int16_t)]; size_t mRemainderLen; status_t initEncoder(); status_t setAudioParams(); Loading