From 8711fe80f7e1caf539f1e8816321c406a4daa72b Mon Sep 17 00:00:00 2001 From: SuRuoyan Date: Sun, 10 Nov 2024 00:44:12 +0800 Subject: [PATCH] add vendor aac encoder Signed-off-by: SuRuoyan --- interface/inner_api/plugin/plugin_list.h | 3 ++- src/plugin/plugin_list.cpp | 28 +++++++++++++++--------- src/plugin/plugin_manager_v2.cpp | 10 +++++++-- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/interface/inner_api/plugin/plugin_list.h b/interface/inner_api/plugin/plugin_list.h index f57b511a..b1c6c2ce 100644 --- a/interface/inner_api/plugin/plugin_list.h +++ b/interface/inner_api/plugin/plugin_list.h @@ -37,7 +37,7 @@ public: ~PluginList(); static PluginList &GetInstance(); std::vector GetAllPlugins(); - PluginDescription GetPluginByCap(PluginType pluginType, std::string needCap); + std::vector GetPluginsByCap(PluginType pluginType, std::string needCap); PluginDescription GetPluginByName(std::string name); std::vector GetPluginsByType(PluginType pluginType); private: @@ -77,6 +77,7 @@ private: void AddAmrnbAudioEncoderPlugins(); void AddMp3AudioEncoderPlugins(); void AddFFmpegMuxerPlugins(); + void AddAudioVendorAacEncodersPlugin(); std::vector pluginDescriptionList_; }; diff --git a/src/plugin/plugin_list.cpp b/src/plugin/plugin_list.cpp index 780b802d..f0821b80 100644 --- a/src/plugin/plugin_list.cpp +++ b/src/plugin/plugin_list.cpp @@ -36,7 +36,7 @@ std::vector PluginList::GetAllPlugins() return pluginDescriptionList_; } -PluginDescription PluginList::GetPluginByCap(PluginType pluginType, std::string needCap) +std::vector PluginList::GetPluginsByCap(PluginType pluginType, std::string needCap) { std::vector matchedPlugins; std::vector::iterator it; @@ -47,15 +47,11 @@ PluginDescription PluginList::GetPluginByCap(PluginType pluginType, std::string matchedPlugins.push_back(temp); } } - int32_t maxRank = 0; - PluginDescription bestMatchedPlugin; - for (it = matchedPlugins.begin(); it != matchedPlugins.end(); it++) { - PluginDescription temp = *it; - if (temp.rank > maxRank) { - bestMatchedPlugin = temp; - } - } - return bestMatchedPlugin; + std::sort(matchedPlugins.begin(), matchedPlugins.end(), + [](PluginDescription a, PluginDescription b) { + return a.rank > b.rank; + }); + return matchedPlugins; } PluginDescription PluginList::GetPluginByName(std::string name) @@ -93,6 +89,7 @@ PluginList::PluginList() AddFFmpegDemuxerPlugins(); AddFFmpegAudioDecodersPlugins(); AddAudioVividDecodersPlugins(); + AddAudioVendorAacEncodersPlugin(); AddG711muAudioDecoderPlugins(); AddLbvcAudioDecoderPlugins(); AddOpusAudioDecoderPlugins(); @@ -501,6 +498,17 @@ void PluginList::AddFFmpegAudioEncodersPlugins() pluginDescriptionList_.push_back(flacAudioEncoderPlugin); } +void PluginList::AddAudioVendorAacEncodersPlugin() +{ + PluginDescription AacEncoderPlugin; + AacEncoderPlugin.pluginName = "OH.Media.Codec.Encoder.Audio.Vendor.AAC"; + AacEncoderPlugin.packageName = "AudioVendorAacEncoder"; + AacEncoderPlugin.pluginType = PluginType::AUDIO_ENCODER; + AacEncoderPlugin.cap = "audio/mp4a-latm"; + AacEncoderPlugin.rank = DEFAULT_RANK + 1; // larger than default aac plugin + pluginDescriptionList_.push_back(AacEncoderPlugin); +} + void PluginList::AddG711muAudioEncoderPlugins() { PluginDescription g711muAudioEncoderPlugin; diff --git a/src/plugin/plugin_manager_v2.cpp b/src/plugin/plugin_manager_v2.cpp index f0befa69..90ba18d1 100644 --- a/src/plugin/plugin_manager_v2.cpp +++ b/src/plugin/plugin_manager_v2.cpp @@ -32,8 +32,14 @@ PluginManagerV2::PluginManagerV2() std::shared_ptr PluginManagerV2::CreatePluginByMime(PluginType pluginType, std::string mime) { MEDIA_LOG_I("CreatePluginByMime pluginType: " PUBLIC_LOG_D32 " mime: " PUBLIC_LOG_S, pluginType, mime.c_str()); - PluginDescription pluginDescription = PluginList::GetInstance().GetPluginByCap(pluginType, mime); - return cachedPluginPackage_->CreatePlugin(pluginDescription); + std::vector pluginDescriptions = PluginList::GetInstance().GetPluginsByCap(pluginType, mime); + for (auto desc: pluginDescriptions) { + std::shared_ptr plugin = cachedPluginPackage_->CreatePlugin(desc); + if (plugin != nullptr) { + return plugin; + } + } + return nullptr; } std::shared_ptr PluginManagerV2::CreatePluginByName(std::string name) -- Gitee