Loading media/codec2/sfplugin/C2OMXNode.cpp +20 −14 Original line number Diff line number Diff line Loading @@ -50,14 +50,8 @@ public: } // namespace C2OMXNode::C2OMXNode(const std::shared_ptr<Codec2Client::Component> &comp) : mComp(comp), mFrameIndex(0), mWidth(0), mHeight(0), : mComp(comp), mFrameIndex(0), mWidth(0), mHeight(0), mUsage(0), mAdjustTimestampGapUs(0), mFirstInputFrame(true) { // TODO: read from intf() if (!strncmp(comp->getName().c_str(), "c2.android.", 11)) { mUsage = GRALLOC_USAGE_SW_READ_OFTEN; } else { mUsage = GRALLOC_USAGE_HW_VIDEO_ENCODER; } } status_t C2OMXNode::freeNode() { Loading Loading @@ -103,13 +97,25 @@ status_t C2OMXNode::getParameter(OMX_INDEXTYPE index, void *params, size_t size) } status_t C2OMXNode::setParameter(OMX_INDEXTYPE index, const void *params, size_t size) { if (params == NULL) { return BAD_VALUE; } switch ((uint32_t)index) { case OMX_IndexParamMaxFrameDurationForBitrateControl: // handle max/fixed frame duration control if (index == (OMX_INDEXTYPE)OMX_IndexParamMaxFrameDurationForBitrateControl && params != NULL && size == sizeof(OMX_PARAM_U32TYPE)) { if (size != sizeof(OMX_PARAM_U32TYPE)) { return BAD_VALUE; } // The incoming number is an int32_t contained in OMX_U32. mAdjustTimestampGapUs = (int32_t)((OMX_PARAM_U32TYPE*)params)->nU32; return OK; case OMX_IndexParamConsumerUsageBits: if (size != sizeof(OMX_U32)) { return BAD_VALUE; } mUsage = *((OMX_U32 *)params); return OK; } return ERROR_UNSUPPORTED; } Loading media/codec2/sfplugin/CCodec.cpp +26 −6 Original line number Diff line number Diff line Loading @@ -183,9 +183,11 @@ public: GraphicBufferSourceWrapper( const sp<BGraphicBufferSource> &source, uint32_t width, uint32_t height) uint32_t height, uint64_t usage) : mSource(source), mWidth(width), mHeight(height) { mDataSpace = HAL_DATASPACE_BT709; mConfig.mUsage = usage; } ~GraphicBufferSourceWrapper() override = default; Loading @@ -193,6 +195,12 @@ public: mNode = new C2OMXNode(comp); mNode->setFrameSize(mWidth, mHeight); // Usage is queried during configure(), so setting it beforehand. OMX_U32 usage = mConfig.mUsage & 0xFFFFFFFF; (void)mNode->setParameter( (OMX_INDEXTYPE)OMX_IndexParamConsumerUsageBits, &usage, sizeof(usage)); // NOTE: we do not use/pass through color aspects from GraphicBufferSource as we // communicate that directly to the component. mSource->configure(mNode, mDataSpace); Loading Loading @@ -364,7 +372,8 @@ public: // color aspects (android._color-aspects) // consumer usage // consumer usage is queried earlier. ALOGD("ISConfig%s", status.str().c_str()); return err; } Loading Loading @@ -813,6 +822,7 @@ void CCodec::configure(const sp<AMessage> &msg) { config->mISConfig->mSuspended = true; } } config->mISConfig->mUsage = 0; } /* Loading Loading @@ -876,9 +886,15 @@ void CCodec::configure(const sp<AMessage> &msg) { indices.size(), params.size()); return UNKNOWN_ERROR; } if (usage && (usage.value & C2MemoryUsage::CPU_READ)) { if (usage) { if (usage.value & C2MemoryUsage::CPU_READ) { config->mInputFormat->setInt32("using-sw-read-often", true); } if (config->mISConfig) { C2AndroidMemoryUsage androidUsage(C2MemoryUsage(usage.value)); config->mISConfig->mUsage = androidUsage.asGrallocUsage(); } } // NOTE: we don't blindly use client specified input size if specified as clients // at times specify too small size. Instead, mimic the behavior from OMX, where the Loading Loading @@ -1068,10 +1084,12 @@ void CCodec::createInputSurface() { sp<AMessage> inputFormat; sp<AMessage> outputFormat; uint64_t usage = 0; { Mutexed<Config>::Locked config(mConfig); inputFormat = config->mInputFormat; outputFormat = config->mOutputFormat; usage = config->mISConfig ? config->mISConfig->mUsage : 0; } sp<PersistentSurface> persistentSurface = CreateCompatibleInputSurface(); Loading @@ -1095,7 +1113,7 @@ void CCodec::createInputSurface() { int32_t height = 0; (void)outputFormat->findInt32("height", &height); err = setupInputSurface(std::make_shared<GraphicBufferSourceWrapper>( persistentSurface->getBufferSource(), width, height)); persistentSurface->getBufferSource(), width, height, usage)); bufferProducer = persistentSurface->getBufferProducer(); } Loading Loading @@ -1155,10 +1173,12 @@ void CCodec::initiateSetInputSurface(const sp<PersistentSurface> &surface) { void CCodec::setInputSurface(const sp<PersistentSurface> &surface) { sp<AMessage> inputFormat; sp<AMessage> outputFormat; uint64_t usage = 0; { Mutexed<Config>::Locked config(mConfig); inputFormat = config->mInputFormat; outputFormat = config->mOutputFormat; usage = config->mISConfig ? config->mISConfig->mUsage : 0; } auto hidlTarget = surface->getHidlTarget(); if (hidlTarget) { Loading @@ -1182,7 +1202,7 @@ void CCodec::setInputSurface(const sp<PersistentSurface> &surface) { int32_t height = 0; (void)outputFormat->findInt32("height", &height); status_t err = setupInputSurface(std::make_shared<GraphicBufferSourceWrapper>( surface->getBufferSource(), width, height)); surface->getBufferSource(), width, height, usage)); if (err != OK) { ALOGE("Failed to set up input surface: %d", err); mCallback->onInputSurfaceDeclined(err); Loading media/codec2/sfplugin/InputSurfaceWrapper.h +1 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public: // IN PARAMS (CODEC WRAPPER) float mFixedAdjustedFps; // fixed fps via PTS manipulation float mMinAdjustedFps; // minimum fps via PTS manipulation uint64_t mUsage; // consumer usage }; /** Loading Loading
media/codec2/sfplugin/C2OMXNode.cpp +20 −14 Original line number Diff line number Diff line Loading @@ -50,14 +50,8 @@ public: } // namespace C2OMXNode::C2OMXNode(const std::shared_ptr<Codec2Client::Component> &comp) : mComp(comp), mFrameIndex(0), mWidth(0), mHeight(0), : mComp(comp), mFrameIndex(0), mWidth(0), mHeight(0), mUsage(0), mAdjustTimestampGapUs(0), mFirstInputFrame(true) { // TODO: read from intf() if (!strncmp(comp->getName().c_str(), "c2.android.", 11)) { mUsage = GRALLOC_USAGE_SW_READ_OFTEN; } else { mUsage = GRALLOC_USAGE_HW_VIDEO_ENCODER; } } status_t C2OMXNode::freeNode() { Loading Loading @@ -103,13 +97,25 @@ status_t C2OMXNode::getParameter(OMX_INDEXTYPE index, void *params, size_t size) } status_t C2OMXNode::setParameter(OMX_INDEXTYPE index, const void *params, size_t size) { if (params == NULL) { return BAD_VALUE; } switch ((uint32_t)index) { case OMX_IndexParamMaxFrameDurationForBitrateControl: // handle max/fixed frame duration control if (index == (OMX_INDEXTYPE)OMX_IndexParamMaxFrameDurationForBitrateControl && params != NULL && size == sizeof(OMX_PARAM_U32TYPE)) { if (size != sizeof(OMX_PARAM_U32TYPE)) { return BAD_VALUE; } // The incoming number is an int32_t contained in OMX_U32. mAdjustTimestampGapUs = (int32_t)((OMX_PARAM_U32TYPE*)params)->nU32; return OK; case OMX_IndexParamConsumerUsageBits: if (size != sizeof(OMX_U32)) { return BAD_VALUE; } mUsage = *((OMX_U32 *)params); return OK; } return ERROR_UNSUPPORTED; } Loading
media/codec2/sfplugin/CCodec.cpp +26 −6 Original line number Diff line number Diff line Loading @@ -183,9 +183,11 @@ public: GraphicBufferSourceWrapper( const sp<BGraphicBufferSource> &source, uint32_t width, uint32_t height) uint32_t height, uint64_t usage) : mSource(source), mWidth(width), mHeight(height) { mDataSpace = HAL_DATASPACE_BT709; mConfig.mUsage = usage; } ~GraphicBufferSourceWrapper() override = default; Loading @@ -193,6 +195,12 @@ public: mNode = new C2OMXNode(comp); mNode->setFrameSize(mWidth, mHeight); // Usage is queried during configure(), so setting it beforehand. OMX_U32 usage = mConfig.mUsage & 0xFFFFFFFF; (void)mNode->setParameter( (OMX_INDEXTYPE)OMX_IndexParamConsumerUsageBits, &usage, sizeof(usage)); // NOTE: we do not use/pass through color aspects from GraphicBufferSource as we // communicate that directly to the component. mSource->configure(mNode, mDataSpace); Loading Loading @@ -364,7 +372,8 @@ public: // color aspects (android._color-aspects) // consumer usage // consumer usage is queried earlier. ALOGD("ISConfig%s", status.str().c_str()); return err; } Loading Loading @@ -813,6 +822,7 @@ void CCodec::configure(const sp<AMessage> &msg) { config->mISConfig->mSuspended = true; } } config->mISConfig->mUsage = 0; } /* Loading Loading @@ -876,9 +886,15 @@ void CCodec::configure(const sp<AMessage> &msg) { indices.size(), params.size()); return UNKNOWN_ERROR; } if (usage && (usage.value & C2MemoryUsage::CPU_READ)) { if (usage) { if (usage.value & C2MemoryUsage::CPU_READ) { config->mInputFormat->setInt32("using-sw-read-often", true); } if (config->mISConfig) { C2AndroidMemoryUsage androidUsage(C2MemoryUsage(usage.value)); config->mISConfig->mUsage = androidUsage.asGrallocUsage(); } } // NOTE: we don't blindly use client specified input size if specified as clients // at times specify too small size. Instead, mimic the behavior from OMX, where the Loading Loading @@ -1068,10 +1084,12 @@ void CCodec::createInputSurface() { sp<AMessage> inputFormat; sp<AMessage> outputFormat; uint64_t usage = 0; { Mutexed<Config>::Locked config(mConfig); inputFormat = config->mInputFormat; outputFormat = config->mOutputFormat; usage = config->mISConfig ? config->mISConfig->mUsage : 0; } sp<PersistentSurface> persistentSurface = CreateCompatibleInputSurface(); Loading @@ -1095,7 +1113,7 @@ void CCodec::createInputSurface() { int32_t height = 0; (void)outputFormat->findInt32("height", &height); err = setupInputSurface(std::make_shared<GraphicBufferSourceWrapper>( persistentSurface->getBufferSource(), width, height)); persistentSurface->getBufferSource(), width, height, usage)); bufferProducer = persistentSurface->getBufferProducer(); } Loading Loading @@ -1155,10 +1173,12 @@ void CCodec::initiateSetInputSurface(const sp<PersistentSurface> &surface) { void CCodec::setInputSurface(const sp<PersistentSurface> &surface) { sp<AMessage> inputFormat; sp<AMessage> outputFormat; uint64_t usage = 0; { Mutexed<Config>::Locked config(mConfig); inputFormat = config->mInputFormat; outputFormat = config->mOutputFormat; usage = config->mISConfig ? config->mISConfig->mUsage : 0; } auto hidlTarget = surface->getHidlTarget(); if (hidlTarget) { Loading @@ -1182,7 +1202,7 @@ void CCodec::setInputSurface(const sp<PersistentSurface> &surface) { int32_t height = 0; (void)outputFormat->findInt32("height", &height); status_t err = setupInputSurface(std::make_shared<GraphicBufferSourceWrapper>( surface->getBufferSource(), width, height)); surface->getBufferSource(), width, height, usage)); if (err != OK) { ALOGE("Failed to set up input surface: %d", err); mCallback->onInputSurfaceDeclined(err); Loading
media/codec2/sfplugin/InputSurfaceWrapper.h +1 −0 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public: // IN PARAMS (CODEC WRAPPER) float mFixedAdjustedFps; // fixed fps via PTS manipulation float mMinAdjustedFps; // minimum fps via PTS manipulation uint64_t mUsage; // consumer usage }; /** Loading