Loading camera/ndk/impl/ACameraCaptureSession.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,9 @@ ACameraCaptureSession::~ACameraCaptureSession() { dev->unlockDevice(); } // Fire onClosed callback if (mUserSessionCallback.onClosed != nullptr) { (*mUserSessionCallback.onClosed)(mUserSessionCallback.context, this); } ALOGV("~ACameraCaptureSession: %p is deleted", this); } Loading camera/ndk/ndk_vendor/tests/AImageReaderVendorTest.cpp +2 −14 Original line number Diff line number Diff line Loading @@ -253,21 +253,9 @@ class CameraHelper { return true; } static void onDeviceDisconnected(void* /*obj*/, ACameraDevice* /*device*/) {} static void onDeviceError(void* /*obj*/, ACameraDevice* /*device*/, int /*errorCode*/) {} static void onSessionClosed(void* /*obj*/, ACameraCaptureSession* /*session*/) {} static void onSessionReady(void* /*obj*/, ACameraCaptureSession* /*session*/) {} static void onSessionActive(void* /*obj*/, ACameraCaptureSession* /*session*/) {} private: ACameraDevice_StateCallbacks mDeviceCb{this, onDeviceDisconnected, onDeviceError}; ACameraCaptureSession_stateCallbacks mSessionCb{ this, onSessionClosed, onSessionReady, onSessionActive}; ACameraDevice_StateCallbacks mDeviceCb{this, nullptr, nullptr}; ACameraCaptureSession_stateCallbacks mSessionCb{ this, nullptr, nullptr, nullptr}; native_handle_t* mImgReaderAnw = nullptr; // not owned by us. Loading media/bufferpool/2.0/AccessorImpl.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ namespace { static constexpr int64_t kLogDurationUs = 5000000; // 5 secs static constexpr size_t kMinAllocBytesForEviction = 1024*1024*15; static constexpr size_t kMinBufferCountForEviction = 40; static constexpr size_t kMinBufferCountForEviction = 25; } // Buffer structure in bufferpool process Loading Loading @@ -718,8 +718,8 @@ void Accessor::Impl::BufferPool::cleanUp(bool clearCache) { mStats.mTotalFetches, mStats.mTotalTransfers); } for (auto freeIt = mFreeBuffers.begin(); freeIt != mFreeBuffers.end();) { if (!clearCache && mStats.mSizeCached < kMinAllocBytesForEviction && mBuffers.size() < kMinBufferCountForEviction) { if (!clearCache && (mStats.mSizeCached < kMinAllocBytesForEviction || mBuffers.size() < kMinBufferCountForEviction)) { break; } auto it = mBuffers.find(*freeIt); Loading media/codec2/components/aac/C2SoftAacEnc.cpp +67 −24 Original line number Diff line number Diff line Loading @@ -155,11 +155,10 @@ C2SoftAacEnc::C2SoftAacEnc( mNumBytesPerInputFrame(0u), mOutBufferSize(0u), mSentCodecSpecificData(false), mInputTimeSet(false), mInputSize(0), mNextFrameTimestampUs(0), mSignalledError(false), mOutIndex(0u) { mOutIndex(0u), mRemainderLen(0u) { } C2SoftAacEnc::~C2SoftAacEnc() { Loading @@ -181,10 +180,11 @@ 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 @@ -199,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 @@ -364,23 +364,35 @@ 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 = (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", capacity, mInputSize, numFrames, mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll()); "mNumBytesPerInputFrame = %u inputTS = %lld remaining = %zu", capacity, mInputSize, numFrames, mNumBytesPerInputFrame, inputTimestampUs.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 +461,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 @@ -482,11 +512,13 @@ 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 defined(LOG_NDEBUG) && !LOG_NDEBUG #if 0 hexdump(outPtr, std::min(outargs.numOutBytes, 256)); #endif outPtr = temp; Loading @@ -498,7 +530,11 @@ void C2SoftAacEnc::process( mInputSize += outargs.numInSamples * sizeof(int16_t); } if (outargs.numInSamples > 0) { if (inBuffer[0] == mRemainder) { inBuffer[0] = const_cast<uint8_t *>(data); inBufferSize[0] = capacity; inargs.numInSamples = capacity / sizeof(int16_t); } else if (outargs.numInSamples > 0) { inBuffer[0] = (int16_t *)inBuffer[0] + outargs.numInSamples; inBufferSize[0] -= outargs.numInSamples * sizeof(int16_t); inargs.numInSamples -= outargs.numInSamples; Loading @@ -506,9 +542,8 @@ 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) { C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; Loading Loading @@ -539,6 +574,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 Loading @@ -583,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 +7 −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,13 +55,17 @@ 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; // We support max 6 channels uint8_t mRemainder[6 * sizeof(int16_t)]; size_t mRemainderLen; status_t initEncoder(); status_t setAudioParams(); Loading Loading
camera/ndk/impl/ACameraCaptureSession.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -33,7 +33,9 @@ ACameraCaptureSession::~ACameraCaptureSession() { dev->unlockDevice(); } // Fire onClosed callback if (mUserSessionCallback.onClosed != nullptr) { (*mUserSessionCallback.onClosed)(mUserSessionCallback.context, this); } ALOGV("~ACameraCaptureSession: %p is deleted", this); } Loading
camera/ndk/ndk_vendor/tests/AImageReaderVendorTest.cpp +2 −14 Original line number Diff line number Diff line Loading @@ -253,21 +253,9 @@ class CameraHelper { return true; } static void onDeviceDisconnected(void* /*obj*/, ACameraDevice* /*device*/) {} static void onDeviceError(void* /*obj*/, ACameraDevice* /*device*/, int /*errorCode*/) {} static void onSessionClosed(void* /*obj*/, ACameraCaptureSession* /*session*/) {} static void onSessionReady(void* /*obj*/, ACameraCaptureSession* /*session*/) {} static void onSessionActive(void* /*obj*/, ACameraCaptureSession* /*session*/) {} private: ACameraDevice_StateCallbacks mDeviceCb{this, onDeviceDisconnected, onDeviceError}; ACameraCaptureSession_stateCallbacks mSessionCb{ this, onSessionClosed, onSessionReady, onSessionActive}; ACameraDevice_StateCallbacks mDeviceCb{this, nullptr, nullptr}; ACameraCaptureSession_stateCallbacks mSessionCb{ this, nullptr, nullptr, nullptr}; native_handle_t* mImgReaderAnw = nullptr; // not owned by us. Loading
media/bufferpool/2.0/AccessorImpl.cpp +3 −3 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ namespace { static constexpr int64_t kLogDurationUs = 5000000; // 5 secs static constexpr size_t kMinAllocBytesForEviction = 1024*1024*15; static constexpr size_t kMinBufferCountForEviction = 40; static constexpr size_t kMinBufferCountForEviction = 25; } // Buffer structure in bufferpool process Loading Loading @@ -718,8 +718,8 @@ void Accessor::Impl::BufferPool::cleanUp(bool clearCache) { mStats.mTotalFetches, mStats.mTotalTransfers); } for (auto freeIt = mFreeBuffers.begin(); freeIt != mFreeBuffers.end();) { if (!clearCache && mStats.mSizeCached < kMinAllocBytesForEviction && mBuffers.size() < kMinBufferCountForEviction) { if (!clearCache && (mStats.mSizeCached < kMinAllocBytesForEviction || mBuffers.size() < kMinBufferCountForEviction)) { break; } auto it = mBuffers.find(*freeIt); Loading
media/codec2/components/aac/C2SoftAacEnc.cpp +67 −24 Original line number Diff line number Diff line Loading @@ -155,11 +155,10 @@ C2SoftAacEnc::C2SoftAacEnc( mNumBytesPerInputFrame(0u), mOutBufferSize(0u), mSentCodecSpecificData(false), mInputTimeSet(false), mInputSize(0), mNextFrameTimestampUs(0), mSignalledError(false), mOutIndex(0u) { mOutIndex(0u), mRemainderLen(0u) { } C2SoftAacEnc::~C2SoftAacEnc() { Loading @@ -181,10 +180,11 @@ 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 @@ -199,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 @@ -364,23 +364,35 @@ 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 = (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", capacity, mInputSize, numFrames, mNumBytesPerInputFrame, work->input.ordinal.timestamp.peekll()); "mNumBytesPerInputFrame = %u inputTS = %lld remaining = %zu", capacity, mInputSize, numFrames, mNumBytesPerInputFrame, inputTimestampUs.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 +461,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 @@ -482,11 +512,13 @@ 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 defined(LOG_NDEBUG) && !LOG_NDEBUG #if 0 hexdump(outPtr, std::min(outargs.numOutBytes, 256)); #endif outPtr = temp; Loading @@ -498,7 +530,11 @@ void C2SoftAacEnc::process( mInputSize += outargs.numInSamples * sizeof(int16_t); } if (outargs.numInSamples > 0) { if (inBuffer[0] == mRemainder) { inBuffer[0] = const_cast<uint8_t *>(data); inBufferSize[0] = capacity; inargs.numInSamples = capacity / sizeof(int16_t); } else if (outargs.numInSamples > 0) { inBuffer[0] = (int16_t *)inBuffer[0] + outargs.numInSamples; inBufferSize[0] -= outargs.numInSamples * sizeof(int16_t); inargs.numInSamples -= outargs.numInSamples; Loading @@ -506,9 +542,8 @@ 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) { C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; Loading Loading @@ -539,6 +574,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 Loading @@ -583,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 +7 −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,13 +55,17 @@ 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; // We support max 6 channels uint8_t mRemainder[6 * sizeof(int16_t)]; size_t mRemainderLen; status_t initEncoder(); status_t setAudioParams(); Loading