Loading media/codec2/sfplugin/CCodec.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ #include <media/stagefright/CCodec.h> #include <media/stagefright/BufferProducerWrapper.h> #include <media/stagefright/MediaCodecConstants.h> #include <media/stagefright/MediaCodecMetricsConstants.h> #include <media/stagefright/PersistentSurface.h> #include <media/stagefright/RenderedFrameInfo.h> #include <utils/NativeHandle.h> Loading Loading @@ -1536,6 +1537,9 @@ void CCodec::configure(const sp<AMessage> &msg) { config->queryConfiguration(comp); mMetrics = new AMessage; mChannel->resetBuffersPixelFormat((config->mDomain & Config::IS_ENCODER) ? true : false); mCallback->onComponentConfigured(config->mInputFormat, config->mOutputFormat); } Loading Loading @@ -2499,6 +2503,19 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) { } mChannel->onWorkDone( std::move(work), outputFormat, initData ? initData.get() : nullptr); // log metrics to MediaCodec if (mMetrics->countEntries() == 0) { Mutexed<std::unique_ptr<Config>>::Locked configLocked(mConfig); const std::unique_ptr<Config> &config = *configLocked; uint32_t pf = PIXEL_FORMAT_UNKNOWN; if (!config->mInputSurface) { pf = mChannel->getBuffersPixelFormat(config->mDomain & Config::IS_ENCODER); } if (pf != PIXEL_FORMAT_UNKNOWN) { mMetrics->setInt64(kCodecPixelFormat, pf); mCallback->onMetricsUpdated(mMetrics); } } break; } case kWhatWatch: { Loading media/codec2/sfplugin/CCodecBufferChannel.cpp +40 −0 Original line number Diff line number Diff line Loading @@ -2384,6 +2384,46 @@ void CCodecBufferChannel::setDescrambler(const sp<IDescrambler> &descrambler) { mDescrambler = descrambler; } uint32_t CCodecBufferChannel::getBuffersPixelFormat(bool isEncoder) { if (isEncoder) { return getInputBuffersPixelFormat(); } else { return getOutputBuffersPixelFormat(); } } uint32_t CCodecBufferChannel::getInputBuffersPixelFormat() { Mutexed<Input>::Locked input(mInput); if (input->buffers == nullptr) { return PIXEL_FORMAT_UNKNOWN; } return input->buffers->getPixelFormatIfApplicable(); } uint32_t CCodecBufferChannel::getOutputBuffersPixelFormat() { Mutexed<Output>::Locked output(mOutput); if (output->buffers == nullptr) { return PIXEL_FORMAT_UNKNOWN; } return output->buffers->getPixelFormatIfApplicable(); } void CCodecBufferChannel::resetBuffersPixelFormat(bool isEncoder) { if (isEncoder) { Mutexed<Input>::Locked input(mInput); if (input->buffers == nullptr) { return; } input->buffers->resetPixelFormatIfApplicable(); } else { Mutexed<Output>::Locked output(mOutput); if (output->buffers == nullptr) { return; } output->buffers->resetPixelFormatIfApplicable(); } } status_t toStatusT(c2_status_t c2s, c2_operation_t c2op) { // C2_OK is always translated to OK. if (c2s == C2_OK) { Loading media/codec2/sfplugin/CCodecBufferChannel.h +13 −0 Original line number Diff line number Diff line Loading @@ -207,7 +207,20 @@ public: void setMetaMode(MetaMode mode); /** * get pixel format from output buffers. * * @return 0 if no valid pixel format found. */ uint32_t getBuffersPixelFormat(bool isEncoder); void resetBuffersPixelFormat(bool isEncoder); private: uint32_t getInputBuffersPixelFormat(); uint32_t getOutputBuffersPixelFormat(); class QueueGuard; /** Loading media/codec2/sfplugin/CCodecBuffers.cpp +44 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define LOG_TAG "CCodecBuffers" #include <utils/Log.h> #include <C2AllocatorGralloc.h> #include <C2PlatformSupport.h> #include <media/stagefright/foundation/ADebug.h> Loading Loading @@ -121,6 +122,10 @@ void CCodecBuffers::handleImageData(const sp<Codec2Buffer> &buffer) { buffer->setFormat(mFormatWithImageData); } uint32_t CCodecBuffers::getPixelFormatIfApplicable() { return PIXEL_FORMAT_UNKNOWN; } bool CCodecBuffers::resetPixelFormatIfApplicable() { return false; } // InputBuffers sp<Codec2Buffer> InputBuffers::cloneAndReleaseBuffer(const sp<MediaCodecBuffer> &buffer) { Loading Loading @@ -1043,7 +1048,8 @@ GraphicInputBuffers::GraphicInputBuffers( const char *componentName, const char *name) : InputBuffers(componentName, name), mImpl(mName), mLocalBufferPool(LocalBufferPool::Create()) { } mLocalBufferPool(LocalBufferPool::Create()), mPixelFormat(PIXEL_FORMAT_UNKNOWN) { } bool GraphicInputBuffers::requestNewBuffer(size_t *index, sp<MediaCodecBuffer> *buffer) { sp<Codec2Buffer> newBuffer = createNewBuffer(); Loading Loading @@ -1109,8 +1115,16 @@ size_t GraphicInputBuffers::numActiveSlots() const { sp<Codec2Buffer> GraphicInputBuffers::createNewBuffer() { C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; mPixelFormat = extractPixelFormat(mFormat); return AllocateInputGraphicBuffer( mPool, mFormat, extractPixelFormat(mFormat), usage, mLocalBufferPool); mPool, mFormat, mPixelFormat, usage, mLocalBufferPool); } uint32_t GraphicInputBuffers::getPixelFormatIfApplicable() { return mPixelFormat; } bool GraphicInputBuffers::resetPixelFormatIfApplicable() { mPixelFormat = PIXEL_FORMAT_UNKNOWN; return true; } // OutputBuffersArray Loading Loading @@ -1269,6 +1283,8 @@ status_t FlexOutputBuffers::registerBuffer( *index = mImpl.assignSlot(newBuffer); handleImageData(newBuffer); *clientBuffer = newBuffer; extractPixelFormatFromC2Buffer(buffer); ALOGV("[%s] registered buffer %zu", mName, *index); return OK; } Loading Loading @@ -1309,6 +1325,32 @@ size_t FlexOutputBuffers::numActiveSlots() const { return mImpl.numActiveSlots(); } bool FlexOutputBuffers::extractPixelFormatFromC2Buffer(const std::shared_ptr<C2Buffer> &buffer) { if (buffer == nullptr) { return false; } const C2BufferData &data = buffer->data(); // only extract the first pixel format in a metric session. if (mPixelFormat != PIXEL_FORMAT_UNKNOWN || data.type() != C2BufferData::GRAPHIC || data.graphicBlocks().empty()) { return false; } const C2Handle *const handle = data.graphicBlocks().front().handle(); uint32_t pf = ExtractFormatFromCodec2GrallocHandle(handle); if (pf == PIXEL_FORMAT_UNKNOWN) { return false; } mPixelFormat = pf; return true; } bool FlexOutputBuffers::resetPixelFormatIfApplicable() { mPixelFormat = PIXEL_FORMAT_UNKNOWN; return true; } uint32_t FlexOutputBuffers::getPixelFormatIfApplicable() { return mPixelFormat; } // LinearOutputBuffers void LinearOutputBuffers::flush( Loading media/codec2/sfplugin/CCodecBuffers.h +27 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,16 @@ public: */ void handleImageData(const sp<Codec2Buffer> &buffer); /** * Get the first pixel format of a metric session. */ virtual uint32_t getPixelFormatIfApplicable(); /** * Reset the pixel format when a new metric session started. */ virtual bool resetPixelFormatIfApplicable(); protected: std::string mComponentName; ///< name of component for debugging std::string mChannelName; ///< name of channel for debugging Loading Loading @@ -938,12 +948,17 @@ public: size_t numActiveSlots() const final; uint32_t getPixelFormatIfApplicable() override; bool resetPixelFormatIfApplicable() override; protected: sp<Codec2Buffer> createNewBuffer() override; private: FlexBuffersImpl mImpl; std::shared_ptr<LocalBufferPool> mLocalBufferPool; uint32_t mPixelFormat; }; class DummyInputBuffers : public InputBuffers { Loading Loading @@ -1107,8 +1122,20 @@ public: */ virtual std::function<sp<Codec2Buffer>()> getAlloc() = 0; uint32_t getPixelFormatIfApplicable() override; bool resetPixelFormatIfApplicable() override; private: FlexBuffersImpl mImpl; uint32_t mPixelFormat; /** * extract pixel format from C2Buffer when register. * * \param buffer The C2Buffer used to extract pixel format. */ bool extractPixelFormatFromC2Buffer(const std::shared_ptr<C2Buffer> &buffer); }; class LinearOutputBuffers : public FlexOutputBuffers { Loading Loading
media/codec2/sfplugin/CCodec.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ #include <media/stagefright/CCodec.h> #include <media/stagefright/BufferProducerWrapper.h> #include <media/stagefright/MediaCodecConstants.h> #include <media/stagefright/MediaCodecMetricsConstants.h> #include <media/stagefright/PersistentSurface.h> #include <media/stagefright/RenderedFrameInfo.h> #include <utils/NativeHandle.h> Loading Loading @@ -1536,6 +1537,9 @@ void CCodec::configure(const sp<AMessage> &msg) { config->queryConfiguration(comp); mMetrics = new AMessage; mChannel->resetBuffersPixelFormat((config->mDomain & Config::IS_ENCODER) ? true : false); mCallback->onComponentConfigured(config->mInputFormat, config->mOutputFormat); } Loading Loading @@ -2499,6 +2503,19 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) { } mChannel->onWorkDone( std::move(work), outputFormat, initData ? initData.get() : nullptr); // log metrics to MediaCodec if (mMetrics->countEntries() == 0) { Mutexed<std::unique_ptr<Config>>::Locked configLocked(mConfig); const std::unique_ptr<Config> &config = *configLocked; uint32_t pf = PIXEL_FORMAT_UNKNOWN; if (!config->mInputSurface) { pf = mChannel->getBuffersPixelFormat(config->mDomain & Config::IS_ENCODER); } if (pf != PIXEL_FORMAT_UNKNOWN) { mMetrics->setInt64(kCodecPixelFormat, pf); mCallback->onMetricsUpdated(mMetrics); } } break; } case kWhatWatch: { Loading
media/codec2/sfplugin/CCodecBufferChannel.cpp +40 −0 Original line number Diff line number Diff line Loading @@ -2384,6 +2384,46 @@ void CCodecBufferChannel::setDescrambler(const sp<IDescrambler> &descrambler) { mDescrambler = descrambler; } uint32_t CCodecBufferChannel::getBuffersPixelFormat(bool isEncoder) { if (isEncoder) { return getInputBuffersPixelFormat(); } else { return getOutputBuffersPixelFormat(); } } uint32_t CCodecBufferChannel::getInputBuffersPixelFormat() { Mutexed<Input>::Locked input(mInput); if (input->buffers == nullptr) { return PIXEL_FORMAT_UNKNOWN; } return input->buffers->getPixelFormatIfApplicable(); } uint32_t CCodecBufferChannel::getOutputBuffersPixelFormat() { Mutexed<Output>::Locked output(mOutput); if (output->buffers == nullptr) { return PIXEL_FORMAT_UNKNOWN; } return output->buffers->getPixelFormatIfApplicable(); } void CCodecBufferChannel::resetBuffersPixelFormat(bool isEncoder) { if (isEncoder) { Mutexed<Input>::Locked input(mInput); if (input->buffers == nullptr) { return; } input->buffers->resetPixelFormatIfApplicable(); } else { Mutexed<Output>::Locked output(mOutput); if (output->buffers == nullptr) { return; } output->buffers->resetPixelFormatIfApplicable(); } } status_t toStatusT(c2_status_t c2s, c2_operation_t c2op) { // C2_OK is always translated to OK. if (c2s == C2_OK) { Loading
media/codec2/sfplugin/CCodecBufferChannel.h +13 −0 Original line number Diff line number Diff line Loading @@ -207,7 +207,20 @@ public: void setMetaMode(MetaMode mode); /** * get pixel format from output buffers. * * @return 0 if no valid pixel format found. */ uint32_t getBuffersPixelFormat(bool isEncoder); void resetBuffersPixelFormat(bool isEncoder); private: uint32_t getInputBuffersPixelFormat(); uint32_t getOutputBuffersPixelFormat(); class QueueGuard; /** Loading
media/codec2/sfplugin/CCodecBuffers.cpp +44 −2 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ #define LOG_TAG "CCodecBuffers" #include <utils/Log.h> #include <C2AllocatorGralloc.h> #include <C2PlatformSupport.h> #include <media/stagefright/foundation/ADebug.h> Loading Loading @@ -121,6 +122,10 @@ void CCodecBuffers::handleImageData(const sp<Codec2Buffer> &buffer) { buffer->setFormat(mFormatWithImageData); } uint32_t CCodecBuffers::getPixelFormatIfApplicable() { return PIXEL_FORMAT_UNKNOWN; } bool CCodecBuffers::resetPixelFormatIfApplicable() { return false; } // InputBuffers sp<Codec2Buffer> InputBuffers::cloneAndReleaseBuffer(const sp<MediaCodecBuffer> &buffer) { Loading Loading @@ -1043,7 +1048,8 @@ GraphicInputBuffers::GraphicInputBuffers( const char *componentName, const char *name) : InputBuffers(componentName, name), mImpl(mName), mLocalBufferPool(LocalBufferPool::Create()) { } mLocalBufferPool(LocalBufferPool::Create()), mPixelFormat(PIXEL_FORMAT_UNKNOWN) { } bool GraphicInputBuffers::requestNewBuffer(size_t *index, sp<MediaCodecBuffer> *buffer) { sp<Codec2Buffer> newBuffer = createNewBuffer(); Loading Loading @@ -1109,8 +1115,16 @@ size_t GraphicInputBuffers::numActiveSlots() const { sp<Codec2Buffer> GraphicInputBuffers::createNewBuffer() { C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE }; mPixelFormat = extractPixelFormat(mFormat); return AllocateInputGraphicBuffer( mPool, mFormat, extractPixelFormat(mFormat), usage, mLocalBufferPool); mPool, mFormat, mPixelFormat, usage, mLocalBufferPool); } uint32_t GraphicInputBuffers::getPixelFormatIfApplicable() { return mPixelFormat; } bool GraphicInputBuffers::resetPixelFormatIfApplicable() { mPixelFormat = PIXEL_FORMAT_UNKNOWN; return true; } // OutputBuffersArray Loading Loading @@ -1269,6 +1283,8 @@ status_t FlexOutputBuffers::registerBuffer( *index = mImpl.assignSlot(newBuffer); handleImageData(newBuffer); *clientBuffer = newBuffer; extractPixelFormatFromC2Buffer(buffer); ALOGV("[%s] registered buffer %zu", mName, *index); return OK; } Loading Loading @@ -1309,6 +1325,32 @@ size_t FlexOutputBuffers::numActiveSlots() const { return mImpl.numActiveSlots(); } bool FlexOutputBuffers::extractPixelFormatFromC2Buffer(const std::shared_ptr<C2Buffer> &buffer) { if (buffer == nullptr) { return false; } const C2BufferData &data = buffer->data(); // only extract the first pixel format in a metric session. if (mPixelFormat != PIXEL_FORMAT_UNKNOWN || data.type() != C2BufferData::GRAPHIC || data.graphicBlocks().empty()) { return false; } const C2Handle *const handle = data.graphicBlocks().front().handle(); uint32_t pf = ExtractFormatFromCodec2GrallocHandle(handle); if (pf == PIXEL_FORMAT_UNKNOWN) { return false; } mPixelFormat = pf; return true; } bool FlexOutputBuffers::resetPixelFormatIfApplicable() { mPixelFormat = PIXEL_FORMAT_UNKNOWN; return true; } uint32_t FlexOutputBuffers::getPixelFormatIfApplicable() { return mPixelFormat; } // LinearOutputBuffers void LinearOutputBuffers::flush( Loading
media/codec2/sfplugin/CCodecBuffers.h +27 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,16 @@ public: */ void handleImageData(const sp<Codec2Buffer> &buffer); /** * Get the first pixel format of a metric session. */ virtual uint32_t getPixelFormatIfApplicable(); /** * Reset the pixel format when a new metric session started. */ virtual bool resetPixelFormatIfApplicable(); protected: std::string mComponentName; ///< name of component for debugging std::string mChannelName; ///< name of channel for debugging Loading Loading @@ -938,12 +948,17 @@ public: size_t numActiveSlots() const final; uint32_t getPixelFormatIfApplicable() override; bool resetPixelFormatIfApplicable() override; protected: sp<Codec2Buffer> createNewBuffer() override; private: FlexBuffersImpl mImpl; std::shared_ptr<LocalBufferPool> mLocalBufferPool; uint32_t mPixelFormat; }; class DummyInputBuffers : public InputBuffers { Loading Loading @@ -1107,8 +1122,20 @@ public: */ virtual std::function<sp<Codec2Buffer>()> getAlloc() = 0; uint32_t getPixelFormatIfApplicable() override; bool resetPixelFormatIfApplicable() override; private: FlexBuffersImpl mImpl; uint32_t mPixelFormat; /** * extract pixel format from C2Buffer when register. * * \param buffer The C2Buffer used to extract pixel format. */ bool extractPixelFormatFromC2Buffer(const std::shared_ptr<C2Buffer> &buffer); }; class LinearOutputBuffers : public FlexOutputBuffers { Loading