Loading media/codec2/sfplugin/CCodec.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -2916,6 +2916,21 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) { : work->worklets.front()->output.configUpdate) { updates.push_back(C2Param::Copy(*param)); } // Check for change in resources required. if (!updates.empty() && android::media::codec::codec_availability_support()) { for (const std::unique_ptr<C2Param>& param : updates) { if (param->index() == C2ResourcesNeededTuning::PARAM_TYPE) { // Update the required resources. if (mCodecResources) { mCodecResources->updateRequiredResources( C2ResourcesNeededTuning::From(param.get())); } // Report to MediaCodec mCallback->onRequiredResourcesChanged(); break; } } } unsigned stream = 0; std::vector<std::shared_ptr<C2Buffer>> &outputBuffers = work->worklets.front()->output.buffers; Loading media/codec2/sfplugin/CCodecResources.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -108,6 +108,7 @@ c2_status_t queryGlobalResources(const std::shared_ptr<Codec2Client>& client, static status_t getSystemResource(const C2ResourcesNeededTuning* systemResourcesInfo, const std::string& storeName, std::vector<InstanceResourceInfo>& resources) { resources.clear(); if (systemResourcesInfo && *systemResourcesInfo) { for (size_t i = 0; i < systemResourcesInfo->flexCount(); ++i) { const C2SystemResourceStruct& resource = Loading Loading @@ -186,4 +187,12 @@ std::vector<InstanceResourceInfo> CCodecResources::getRequiredResources() { return *resourcesLocked; } status_t CCodecResources::updateRequiredResources( const C2ResourcesNeededTuning* systemResourcesInfo) { // Update the required resources from the given systemResourcesInfo. Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked(mResources); std::vector<InstanceResourceInfo>& resources = *resourcesLocked; return getSystemResource(systemResourcesInfo, mStoreName, resources); } } // namespace android media/codec2/sfplugin/include/media/stagefright/CCodecResources.h +7 −0 Original line number Diff line number Diff line Loading @@ -32,13 +32,20 @@ class CCodecResources { public: CCodecResources(const std::string& storeName); /// Gets the globally available resources from the /// default store. static std::vector<GlobalResourceInfo> GetGloballyAvailableResources(); /// Queries the regurired resources for the given codec component. status_t queryRequiredResources( const std::shared_ptr<Codec2Client::Component>& comp); /// Gets the required resources. std::vector<InstanceResourceInfo> getRequiredResources(); /// Updates the required resources. status_t updateRequiredResources(const C2ResourcesNeededTuning* systemResourcesInfo); private: const std::string mStoreName; Mutexed<std::vector<InstanceResourceInfo>> mResources; Loading media/libstagefright/MediaCodec.cpp +54 −36 Original line number Diff line number Diff line Loading @@ -821,6 +821,7 @@ enum { kWhatFirstTunnelFrameReady = 'ftfR', kWhatPollForRenderedBuffers = 'plrb', kWhatMetricsUpdated = 'mtru', kWhatRequiredResourcesChanged = 'reqR', }; class CryptoAsyncCallback : public CryptoAsync::CryptoAsyncCallback { Loading Loading @@ -968,6 +969,7 @@ public: virtual void onOutputBuffersChanged() override; virtual void onFirstTunnelFrameReady() override; virtual void onMetricsUpdated(const sp<AMessage> &updatedMetrics) override; virtual void onRequiredResourcesChanged() override; private: const sp<AMessage> mNotify; }; Loading Loading @@ -1101,6 +1103,12 @@ void CodecCallback::onMetricsUpdated(const sp<AMessage> &updatedMetrics) { notify->post(); } void CodecCallback::onRequiredResourcesChanged() { sp<AMessage> notify(mNotify->dup()); notify->setInt32("what", kWhatRequiredResourcesChanged); notify->post(); } static MediaResourceSubType toMediaResourceSubType(bool isHardware, MediaCodec::Domain domain) { switch (domain) { case MediaCodec::DOMAIN_VIDEO: Loading Loading @@ -1282,6 +1290,22 @@ static float getOperatingFrameRate(const sp<AMessage>& format, return frameRate; } bool MediaCodec::getRequiredSystemResources() { if (android::media::codec::codec_availability() && android::media::codec::codec_availability_support()) { // Get the required system resources now. Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked( mRequiredResourceInfo); *resourcesLocked = mCodec->getRequiredSystemResources(); // Update the dynamic resource usage with the current operating frame-rate. *resourcesLocked = computeDynamicResources(*resourcesLocked); return !(*resourcesLocked).empty(); } return false; } /** * Convert per frame/input/output resources into static_count * Loading Loading @@ -2752,9 +2776,8 @@ status_t MediaCodec::getRequiredResources(std::vector<InstanceResourceInfo>& res } Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked(mRequiredResourceInfo); std::vector<InstanceResourceInfo>& requiredResourceInfo = *resourcesLocked; if (!requiredResourceInfo.empty()) { resources = requiredResourceInfo; if (!(*resourcesLocked).empty()) { resources = *resourcesLocked; return OK; } Loading Loading @@ -4523,19 +4546,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { mFlags |= kFlagUsesSoftwareRenderer; } if (android::media::codec::codec_availability() && android::media::codec::codec_availability_support()) { // Get the required system resources now. Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked( mRequiredResourceInfo); *resourcesLocked = mCodec->getRequiredSystemResources(); // Use input and output formats to get operating frame-rate. bool isEncoder = mFlags & kFlagIsEncoder; mFrameRate = getOperatingFrameRate(mInputFormat, mFrameRate, isEncoder); mFrameRate = getOperatingFrameRate(mOutputFormat, mFrameRate, isEncoder); // Update the dynamic resource usage with the current operating frame-rate. *resourcesLocked = computeDynamicResources(*resourcesLocked); } getRequiredSystemResources(); setState(CONFIGURED); postPendingRepliesAndDeferredMessages("kWhatComponentConfigured"); Loading Loading @@ -4686,8 +4701,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { android::media::codec::codec_availability_support()) { Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked( mRequiredResourceInfo); std::vector<InstanceResourceInfo>& requiredResourceInfo = *resourcesLocked; for (const InstanceResourceInfo& resource : requiredResourceInfo) { for (const InstanceResourceInfo& resource : *resourcesLocked) { resources.push_back(getMediaResourceParcel(resource)); } } Loading Loading @@ -4972,6 +4986,16 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { break; } case kWhatRequiredResourcesChanged: { // Get the updated required system resources. if (getRequiredSystemResources()) { onRequiredResourcesChanged(); } break; } case kWhatEOS: { // We already notify the client of this by using the Loading @@ -4997,8 +5021,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { android::media::codec::codec_availability_support()) { Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked( mRequiredResourceInfo); std::vector<InstanceResourceInfo>& requiredResourceInfo = *resourcesLocked; for (const InstanceResourceInfo& resource : requiredResourceInfo) { for (const InstanceResourceInfo& resource : *resourcesLocked) { resources.push_back(getMediaResourceParcel(resource)); } } Loading Loading @@ -6291,9 +6314,15 @@ void MediaCodec::handleOutputFormatChangeIfNeeded(const sp<MediaCodecBuffer> &bu bool isEncoder = mFlags & kFlagIsEncoder; // Since the output format has changed, see if we need to update // operating frame-rate. mFrameRate = getOperatingFrameRate(mOutputFormat, mFrameRate, isEncoder); // TODO: (girishshetty): See if the change in operating frame-rate calls for // onRequiredResourcesChanged callback. float frameRate = getOperatingFrameRate(mOutputFormat, mFrameRate, isEncoder); // if the operating frame-rate has changed, we need to recalibrate the // required system resources again and notify the caller. if (frameRate != mFrameRate) { mFrameRate = frameRate; if (getRequiredSystemResources()) { onRequiredResourcesChanged(); } } } } Loading Loading @@ -7332,19 +7361,8 @@ void MediaCodec::onOutputFormatChanged() { } } void MediaCodec::onRequiredResourcesChanged( const std::vector<InstanceResourceInfo>& resourceInfo) { bool canIssueCallback = false; if (android::media::codec::codec_availability() && android::media::codec::codec_availability_support()) { Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked(mRequiredResourceInfo); *resourcesLocked = resourceInfo; // Convert per frame/input/output resources into static_count *resourcesLocked = computeDynamicResources(*resourcesLocked); canIssueCallback = true; } // Make sure codec availability feature is on. if (mCallback != nullptr && canIssueCallback) { void MediaCodec::onRequiredResourcesChanged() { if (mCallback != nullptr) { // Post the callback sp<AMessage> msg = mCallback->dup(); msg->setInt32("callbackID", CB_REQUIRED_RESOURCES_CHANGED); Loading media/libstagefright/include/media/stagefright/CodecBase.h +4 −0 Original line number Diff line number Diff line Loading @@ -219,6 +219,10 @@ struct CodecBase : public AHandler, /* static */ ColorUtils { * @param updatedMetrics metrics need to be updated. */ virtual void onMetricsUpdated(const sp<AMessage> &updatedMetrics) = 0; /** * Notify MediaCodec that there is a change in the required resources. */ virtual void onRequiredResourcesChanged() = 0; }; /** Loading Loading
media/codec2/sfplugin/CCodec.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -2916,6 +2916,21 @@ void CCodec::onMessageReceived(const sp<AMessage> &msg) { : work->worklets.front()->output.configUpdate) { updates.push_back(C2Param::Copy(*param)); } // Check for change in resources required. if (!updates.empty() && android::media::codec::codec_availability_support()) { for (const std::unique_ptr<C2Param>& param : updates) { if (param->index() == C2ResourcesNeededTuning::PARAM_TYPE) { // Update the required resources. if (mCodecResources) { mCodecResources->updateRequiredResources( C2ResourcesNeededTuning::From(param.get())); } // Report to MediaCodec mCallback->onRequiredResourcesChanged(); break; } } } unsigned stream = 0; std::vector<std::shared_ptr<C2Buffer>> &outputBuffers = work->worklets.front()->output.buffers; Loading
media/codec2/sfplugin/CCodecResources.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -108,6 +108,7 @@ c2_status_t queryGlobalResources(const std::shared_ptr<Codec2Client>& client, static status_t getSystemResource(const C2ResourcesNeededTuning* systemResourcesInfo, const std::string& storeName, std::vector<InstanceResourceInfo>& resources) { resources.clear(); if (systemResourcesInfo && *systemResourcesInfo) { for (size_t i = 0; i < systemResourcesInfo->flexCount(); ++i) { const C2SystemResourceStruct& resource = Loading Loading @@ -186,4 +187,12 @@ std::vector<InstanceResourceInfo> CCodecResources::getRequiredResources() { return *resourcesLocked; } status_t CCodecResources::updateRequiredResources( const C2ResourcesNeededTuning* systemResourcesInfo) { // Update the required resources from the given systemResourcesInfo. Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked(mResources); std::vector<InstanceResourceInfo>& resources = *resourcesLocked; return getSystemResource(systemResourcesInfo, mStoreName, resources); } } // namespace android
media/codec2/sfplugin/include/media/stagefright/CCodecResources.h +7 −0 Original line number Diff line number Diff line Loading @@ -32,13 +32,20 @@ class CCodecResources { public: CCodecResources(const std::string& storeName); /// Gets the globally available resources from the /// default store. static std::vector<GlobalResourceInfo> GetGloballyAvailableResources(); /// Queries the regurired resources for the given codec component. status_t queryRequiredResources( const std::shared_ptr<Codec2Client::Component>& comp); /// Gets the required resources. std::vector<InstanceResourceInfo> getRequiredResources(); /// Updates the required resources. status_t updateRequiredResources(const C2ResourcesNeededTuning* systemResourcesInfo); private: const std::string mStoreName; Mutexed<std::vector<InstanceResourceInfo>> mResources; Loading
media/libstagefright/MediaCodec.cpp +54 −36 Original line number Diff line number Diff line Loading @@ -821,6 +821,7 @@ enum { kWhatFirstTunnelFrameReady = 'ftfR', kWhatPollForRenderedBuffers = 'plrb', kWhatMetricsUpdated = 'mtru', kWhatRequiredResourcesChanged = 'reqR', }; class CryptoAsyncCallback : public CryptoAsync::CryptoAsyncCallback { Loading Loading @@ -968,6 +969,7 @@ public: virtual void onOutputBuffersChanged() override; virtual void onFirstTunnelFrameReady() override; virtual void onMetricsUpdated(const sp<AMessage> &updatedMetrics) override; virtual void onRequiredResourcesChanged() override; private: const sp<AMessage> mNotify; }; Loading Loading @@ -1101,6 +1103,12 @@ void CodecCallback::onMetricsUpdated(const sp<AMessage> &updatedMetrics) { notify->post(); } void CodecCallback::onRequiredResourcesChanged() { sp<AMessage> notify(mNotify->dup()); notify->setInt32("what", kWhatRequiredResourcesChanged); notify->post(); } static MediaResourceSubType toMediaResourceSubType(bool isHardware, MediaCodec::Domain domain) { switch (domain) { case MediaCodec::DOMAIN_VIDEO: Loading Loading @@ -1282,6 +1290,22 @@ static float getOperatingFrameRate(const sp<AMessage>& format, return frameRate; } bool MediaCodec::getRequiredSystemResources() { if (android::media::codec::codec_availability() && android::media::codec::codec_availability_support()) { // Get the required system resources now. Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked( mRequiredResourceInfo); *resourcesLocked = mCodec->getRequiredSystemResources(); // Update the dynamic resource usage with the current operating frame-rate. *resourcesLocked = computeDynamicResources(*resourcesLocked); return !(*resourcesLocked).empty(); } return false; } /** * Convert per frame/input/output resources into static_count * Loading Loading @@ -2752,9 +2776,8 @@ status_t MediaCodec::getRequiredResources(std::vector<InstanceResourceInfo>& res } Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked(mRequiredResourceInfo); std::vector<InstanceResourceInfo>& requiredResourceInfo = *resourcesLocked; if (!requiredResourceInfo.empty()) { resources = requiredResourceInfo; if (!(*resourcesLocked).empty()) { resources = *resourcesLocked; return OK; } Loading Loading @@ -4523,19 +4546,11 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { mFlags |= kFlagUsesSoftwareRenderer; } if (android::media::codec::codec_availability() && android::media::codec::codec_availability_support()) { // Get the required system resources now. Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked( mRequiredResourceInfo); *resourcesLocked = mCodec->getRequiredSystemResources(); // Use input and output formats to get operating frame-rate. bool isEncoder = mFlags & kFlagIsEncoder; mFrameRate = getOperatingFrameRate(mInputFormat, mFrameRate, isEncoder); mFrameRate = getOperatingFrameRate(mOutputFormat, mFrameRate, isEncoder); // Update the dynamic resource usage with the current operating frame-rate. *resourcesLocked = computeDynamicResources(*resourcesLocked); } getRequiredSystemResources(); setState(CONFIGURED); postPendingRepliesAndDeferredMessages("kWhatComponentConfigured"); Loading Loading @@ -4686,8 +4701,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { android::media::codec::codec_availability_support()) { Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked( mRequiredResourceInfo); std::vector<InstanceResourceInfo>& requiredResourceInfo = *resourcesLocked; for (const InstanceResourceInfo& resource : requiredResourceInfo) { for (const InstanceResourceInfo& resource : *resourcesLocked) { resources.push_back(getMediaResourceParcel(resource)); } } Loading Loading @@ -4972,6 +4986,16 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { break; } case kWhatRequiredResourcesChanged: { // Get the updated required system resources. if (getRequiredSystemResources()) { onRequiredResourcesChanged(); } break; } case kWhatEOS: { // We already notify the client of this by using the Loading @@ -4997,8 +5021,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { android::media::codec::codec_availability_support()) { Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked( mRequiredResourceInfo); std::vector<InstanceResourceInfo>& requiredResourceInfo = *resourcesLocked; for (const InstanceResourceInfo& resource : requiredResourceInfo) { for (const InstanceResourceInfo& resource : *resourcesLocked) { resources.push_back(getMediaResourceParcel(resource)); } } Loading Loading @@ -6291,9 +6314,15 @@ void MediaCodec::handleOutputFormatChangeIfNeeded(const sp<MediaCodecBuffer> &bu bool isEncoder = mFlags & kFlagIsEncoder; // Since the output format has changed, see if we need to update // operating frame-rate. mFrameRate = getOperatingFrameRate(mOutputFormat, mFrameRate, isEncoder); // TODO: (girishshetty): See if the change in operating frame-rate calls for // onRequiredResourcesChanged callback. float frameRate = getOperatingFrameRate(mOutputFormat, mFrameRate, isEncoder); // if the operating frame-rate has changed, we need to recalibrate the // required system resources again and notify the caller. if (frameRate != mFrameRate) { mFrameRate = frameRate; if (getRequiredSystemResources()) { onRequiredResourcesChanged(); } } } } Loading Loading @@ -7332,19 +7361,8 @@ void MediaCodec::onOutputFormatChanged() { } } void MediaCodec::onRequiredResourcesChanged( const std::vector<InstanceResourceInfo>& resourceInfo) { bool canIssueCallback = false; if (android::media::codec::codec_availability() && android::media::codec::codec_availability_support()) { Mutexed<std::vector<InstanceResourceInfo>>::Locked resourcesLocked(mRequiredResourceInfo); *resourcesLocked = resourceInfo; // Convert per frame/input/output resources into static_count *resourcesLocked = computeDynamicResources(*resourcesLocked); canIssueCallback = true; } // Make sure codec availability feature is on. if (mCallback != nullptr && canIssueCallback) { void MediaCodec::onRequiredResourcesChanged() { if (mCallback != nullptr) { // Post the callback sp<AMessage> msg = mCallback->dup(); msg->setInt32("callbackID", CB_REQUIRED_RESOURCES_CHANGED); Loading
media/libstagefright/include/media/stagefright/CodecBase.h +4 −0 Original line number Diff line number Diff line Loading @@ -219,6 +219,10 @@ struct CodecBase : public AHandler, /* static */ ColorUtils { * @param updatedMetrics metrics need to be updated. */ virtual void onMetricsUpdated(const sp<AMessage> &updatedMetrics) = 0; /** * Notify MediaCodec that there is a change in the required resources. */ virtual void onRequiredResourcesChanged() = 0; }; /** Loading