diff --git a/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp b/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp index 6d0cd1102263f928f953772c665a9f496f5d7dfd..f5a34c201a3689189ecec2950156fca05ec3200e 100644 --- a/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp +++ b/services/media_engine/plugins/ffmpeg_adapter/demuxer/ffmpeg_demuxer_plugin.cpp @@ -53,6 +53,8 @@ namespace Media { namespace Plugins { namespace Ffmpeg { const uint32_t DEFAULT_READ_SIZE = 4096; +const uint32_t DOUBLE_PROBE_SIZE = DEFAULT_READ_SIZE * 2; +const uint32_t MP3_SNIFF_LIMIT = 5; const uint32_t STR_MAX_LEN = 4; const uint32_t RANK_MAX = 100; const uint32_t NAL_START_CODE_SIZE = 4; @@ -1410,7 +1412,7 @@ bool FFmpegDemuxerPlugin::CanDropHevcPkt(const AVPacket& pkt) namespace { // plugin set int Sniff(const std::string& pluginName, std::shared_ptr dataSource) { - MEDIA_LOG_D("Sniff: plugin name " PUBLIC_LOG_S ".", pluginName.c_str()); + MEDIA_LOG_I("Sniff: plugin name " PUBLIC_LOG_S ".", pluginName.c_str()); FALSE_RETURN_V_MSG_E(!pluginName.empty(), 0, "Sniff failed due to plugin name is empty."); FALSE_RETURN_V_MSG_E(dataSource != nullptr, 0, "Sniff failed due to dataSource invalid."); @@ -1420,9 +1422,16 @@ int Sniff(const std::string& pluginName, std::shared_ptr dataSource) "Sniff failed due to get plugin for " PUBLIC_LOG_S " failed.", pluginName.c_str()); size_t bufferSize = DEFAULT_READ_SIZE; + if (StartWith(plugin->name, "mp3")) { + bufferSize = DOUBLE_PROBE_SIZE; // mp3 needs more data to sniff, refs to ffmpeg + MEDIA_LOG_I("Sniff: expand probe size for mp3"); + } uint64_t fileSize = 0; if (dataSource->GetSize(fileSize) == Status::OK) { bufferSize = (bufferSize < fileSize) ? bufferSize : fileSize; + if (bufferSize == fileSize) { + MEDIA_LOG_I("Sniff: file data is not enough, reset probe size to file size"); + } } // fix ffmpeg probe crash,refer to ffmpeg/tools/probetest.c std::vector buff(bufferSize + AVPROBE_PADDING_SIZE); @@ -1438,8 +1447,11 @@ int Sniff(const std::string& pluginName, std::shared_ptr dataSource) AVProbeData probeData{"", buff.data(), static_cast(bufferInfo->GetMemory()->GetSize()), ""}; int confidence = plugin->read_probe(&probeData); - - MEDIA_LOG_D("Sniff: plugin name " PUBLIC_LOG_S ", probability " PUBLIC_LOG_D32 "/100.", + if (StartWith(plugin->name, "mp3") && confidence < MP3_SNIFF_LIMIT) { // score too low for mp3,misdetection possible + confidence = 0; + MEIDA_LOG_W("Sniff: probe score is too low, misdetection possible, reset to 0/100"); + } + MEDIA_LOG_I("Sniff: plugin name " PUBLIC_LOG_S ", probability " PUBLIC_LOG_D32 "/100.", plugin->name, confidence); return confidence;