Loading media/codec2/components/aac/C2SoftAacEnc.cpp +25 −16 Original line number Diff line number Diff line Loading @@ -155,9 +155,7 @@ C2SoftAacEnc::C2SoftAacEnc( mNumBytesPerInputFrame(0u), mOutBufferSize(0u), mSentCodecSpecificData(false), mInputTimeSet(false), mInputSize(0), mNextFrameTimestampUs(0), mSignalledError(false), mOutIndex(0u), mRemainderLen(0u) { Loading @@ -182,9 +180,9 @@ status_t C2SoftAacEnc::initEncoder() { c2_status_t C2SoftAacEnc::onStop() { mSentCodecSpecificData = false; mInputTimeSet = false; mInputSize = 0u; mNextFrameTimestampUs = 0; mNextFrameTimestampUs.reset(); mLastFrameEndTimestampUs.reset(); mSignalledError = false; mRemainderLen = 0; return C2_OK; Loading @@ -201,9 +199,9 @@ void C2SoftAacEnc::onRelease() { c2_status_t C2SoftAacEnc::onFlush_sm() { mSentCodecSpecificData = false; mInputTimeSet = false; mInputSize = 0u; mNextFrameTimestampUs = 0; mNextFrameTimestampUs.reset(); mLastFrameEndTimestampUs.reset(); return C2_OK; } Loading Loading @@ -366,9 +364,19 @@ void C2SoftAacEnc::process( data = view.data(); capacity = view.capacity(); } if (!mInputTimeSet && capacity > 0) { c2_cntr64_t inputTimestampUs = work->input.ordinal.timestamp; if (inputTimestampUs < mLastFrameEndTimestampUs.value_or(inputTimestampUs)) { ALOGW("Correcting overlapping timestamp: last frame ended at %lldus but " "current frame is starting at %lldus. Using the last frame's end timestamp", mLastFrameEndTimestampUs->peekll(), inputTimestampUs.peekll()); inputTimestampUs = *mLastFrameEndTimestampUs; } if (capacity > 0) { if (!mNextFrameTimestampUs) { mNextFrameTimestampUs = work->input.ordinal.timestamp; mInputTimeSet = true; } mLastFrameEndTimestampUs = inputTimestampUs + (capacity / sizeof(int16_t) * 1000000ll / channelCount / sampleRate); } size_t numFrames = Loading @@ -376,8 +384,7 @@ void C2SoftAacEnc::process( / mNumBytesPerInputFrame; ALOGV("capacity = %zu; mInputSize = %zu; numFrames = %zu " "mNumBytesPerInputFrame = %u inputTS = %lld remaining = %zu", capacity, mInputSize, numFrames, mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll(), capacity, mInputSize, numFrames, mNumBytesPerInputFrame, inputTimestampUs.peekll(), mRemainderLen); std::shared_ptr<C2LinearBlock> block; Loading Loading @@ -505,8 +512,10 @@ void C2SoftAacEnc::process( mInputSize = 0; int consumed = (capacity / sizeof(int16_t)) - inargs.numInSamples + outargs.numInSamples; c2_cntr64_t currentFrameTimestampUs = mNextFrameTimestampUs; mNextFrameTimestampUs = work->input.ordinal.timestamp ALOGV("consumed = %d, capacity = %zu, inSamples = %d, outSamples = %d", consumed, capacity, inargs.numInSamples, outargs.numInSamples); c2_cntr64_t currentFrameTimestampUs = *mNextFrameTimestampUs; mNextFrameTimestampUs = inputTimestampUs + (consumed * 1000000ll / channelCount / sampleRate); std::shared_ptr<C2Buffer> buffer = createLinearBuffer(block, 0, outargs.numOutBytes); #if 0 Loading @@ -533,7 +542,7 @@ void C2SoftAacEnc::process( } ALOGV("encoderErr = %d mInputSize = %zu " "inargs.numInSamples = %d, mNextFrameTimestampUs = %lld", encoderErr, mInputSize, inargs.numInSamples, mNextFrameTimestampUs.peekll()); encoderErr, mInputSize, inargs.numInSamples, mNextFrameTimestampUs->peekll()); } if (eos && inBufferSize[0] > 0) { if (numFrames && !block) { Loading Loading @@ -617,9 +626,9 @@ c2_status_t C2SoftAacEnc::drain( (void)pool; mSentCodecSpecificData = false; mInputTimeSet = false; mInputSize = 0u; mNextFrameTimestampUs = 0; mNextFrameTimestampUs.reset(); mLastFrameEndTimestampUs.reset(); // TODO: we don't have any pending work at this time to drain. return C2_OK; Loading media/codec2/components/aac/C2SoftAacEnc.h +3 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define ANDROID_C2_SOFT_AAC_ENC_H_ #include <atomic> #include <optional> #include <SimpleC2Component.h> Loading Loading @@ -54,9 +55,9 @@ private: UINT mOutBufferSize; bool mSentCodecSpecificData; bool mInputTimeSet; size_t mInputSize; c2_cntr64_t mNextFrameTimestampUs; std::optional<c2_cntr64_t> mNextFrameTimestampUs; std::optional<c2_cntr64_t> mLastFrameEndTimestampUs; bool mSignalledError; std::atomic_uint64_t mOutIndex; Loading Loading
media/codec2/components/aac/C2SoftAacEnc.cpp +25 −16 Original line number Diff line number Diff line Loading @@ -155,9 +155,7 @@ C2SoftAacEnc::C2SoftAacEnc( mNumBytesPerInputFrame(0u), mOutBufferSize(0u), mSentCodecSpecificData(false), mInputTimeSet(false), mInputSize(0), mNextFrameTimestampUs(0), mSignalledError(false), mOutIndex(0u), mRemainderLen(0u) { Loading @@ -182,9 +180,9 @@ status_t C2SoftAacEnc::initEncoder() { c2_status_t C2SoftAacEnc::onStop() { mSentCodecSpecificData = false; mInputTimeSet = false; mInputSize = 0u; mNextFrameTimestampUs = 0; mNextFrameTimestampUs.reset(); mLastFrameEndTimestampUs.reset(); mSignalledError = false; mRemainderLen = 0; return C2_OK; Loading @@ -201,9 +199,9 @@ void C2SoftAacEnc::onRelease() { c2_status_t C2SoftAacEnc::onFlush_sm() { mSentCodecSpecificData = false; mInputTimeSet = false; mInputSize = 0u; mNextFrameTimestampUs = 0; mNextFrameTimestampUs.reset(); mLastFrameEndTimestampUs.reset(); return C2_OK; } Loading Loading @@ -366,9 +364,19 @@ void C2SoftAacEnc::process( data = view.data(); capacity = view.capacity(); } if (!mInputTimeSet && capacity > 0) { c2_cntr64_t inputTimestampUs = work->input.ordinal.timestamp; if (inputTimestampUs < mLastFrameEndTimestampUs.value_or(inputTimestampUs)) { ALOGW("Correcting overlapping timestamp: last frame ended at %lldus but " "current frame is starting at %lldus. Using the last frame's end timestamp", mLastFrameEndTimestampUs->peekll(), inputTimestampUs.peekll()); inputTimestampUs = *mLastFrameEndTimestampUs; } if (capacity > 0) { if (!mNextFrameTimestampUs) { mNextFrameTimestampUs = work->input.ordinal.timestamp; mInputTimeSet = true; } mLastFrameEndTimestampUs = inputTimestampUs + (capacity / sizeof(int16_t) * 1000000ll / channelCount / sampleRate); } size_t numFrames = Loading @@ -376,8 +384,7 @@ void C2SoftAacEnc::process( / mNumBytesPerInputFrame; ALOGV("capacity = %zu; mInputSize = %zu; numFrames = %zu " "mNumBytesPerInputFrame = %u inputTS = %lld remaining = %zu", capacity, mInputSize, numFrames, mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll(), capacity, mInputSize, numFrames, mNumBytesPerInputFrame, inputTimestampUs.peekll(), mRemainderLen); std::shared_ptr<C2LinearBlock> block; Loading Loading @@ -505,8 +512,10 @@ void C2SoftAacEnc::process( mInputSize = 0; int consumed = (capacity / sizeof(int16_t)) - inargs.numInSamples + outargs.numInSamples; c2_cntr64_t currentFrameTimestampUs = mNextFrameTimestampUs; mNextFrameTimestampUs = work->input.ordinal.timestamp ALOGV("consumed = %d, capacity = %zu, inSamples = %d, outSamples = %d", consumed, capacity, inargs.numInSamples, outargs.numInSamples); c2_cntr64_t currentFrameTimestampUs = *mNextFrameTimestampUs; mNextFrameTimestampUs = inputTimestampUs + (consumed * 1000000ll / channelCount / sampleRate); std::shared_ptr<C2Buffer> buffer = createLinearBuffer(block, 0, outargs.numOutBytes); #if 0 Loading @@ -533,7 +542,7 @@ void C2SoftAacEnc::process( } ALOGV("encoderErr = %d mInputSize = %zu " "inargs.numInSamples = %d, mNextFrameTimestampUs = %lld", encoderErr, mInputSize, inargs.numInSamples, mNextFrameTimestampUs.peekll()); encoderErr, mInputSize, inargs.numInSamples, mNextFrameTimestampUs->peekll()); } if (eos && inBufferSize[0] > 0) { if (numFrames && !block) { Loading Loading @@ -617,9 +626,9 @@ c2_status_t C2SoftAacEnc::drain( (void)pool; mSentCodecSpecificData = false; mInputTimeSet = false; mInputSize = 0u; mNextFrameTimestampUs = 0; mNextFrameTimestampUs.reset(); mLastFrameEndTimestampUs.reset(); // TODO: we don't have any pending work at this time to drain. return C2_OK; Loading
media/codec2/components/aac/C2SoftAacEnc.h +3 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define ANDROID_C2_SOFT_AAC_ENC_H_ #include <atomic> #include <optional> #include <SimpleC2Component.h> Loading Loading @@ -54,9 +55,9 @@ private: UINT mOutBufferSize; bool mSentCodecSpecificData; bool mInputTimeSet; size_t mInputSize; c2_cntr64_t mNextFrameTimestampUs; std::optional<c2_cntr64_t> mNextFrameTimestampUs; std::optional<c2_cntr64_t> mLastFrameEndTimestampUs; bool mSignalledError; std::atomic_uint64_t mOutIndex; Loading