diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 6892bb4cc2c3..9d4647e893ec 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -7,6 +7,7 @@ #include "MediaFormatReader.h" #include "AllocationPolicy.h" +#include "DecoderBenchmark.h" #include "GeckoProfiler.h" #include "MediaData.h" #include "MediaInfo.h" @@ -416,6 +417,10 @@ void MediaFormatReader::DecoderFactory::DoInitDecoder(Data& aData) { ownerData.mDecoder.get()); mOwner->SetVideoDecodeThreshold(); mOwner->ScheduleUpdate(aTrack); + if (aTrack == TrackInfo::kVideoTrack) { + DecoderBenchmark::CheckVersion( + ownerData.GetCurrentInfo()->mMimeType); + } }, [this, &aData, &ownerData](const MediaResult& aError) { aData.mInitRequest.Complete(); diff --git a/dom/media/mediacapabilities/DecoderBenchmark.cpp b/dom/media/mediacapabilities/DecoderBenchmark.cpp index 549e8c628b6d..32e2c5827108 100644 --- a/dom/media/mediacapabilities/DecoderBenchmark.cpp +++ b/dom/media/mediacapabilities/DecoderBenchmark.cpp @@ -162,7 +162,8 @@ nsCString CreateStoreKey(const DecoderBenchmarkInfo& aBenchInfo) { void DecoderBenchmark::Store(const DecoderBenchmarkInfo& aBenchInfo, RefPtr aStats) { if (!XRE_IsContentProcess()) { - NS_WARNING("Storing a benchmark allowed only from the content process."); + NS_WARNING( + "Storing a benchmark is only allowed only from the content process."); return; } StoreScore(aBenchInfo.mContentType, CreateStoreKey(aBenchInfo), aStats); @@ -172,7 +173,8 @@ void DecoderBenchmark::Store(const DecoderBenchmarkInfo& aBenchInfo, RefPtr DecoderBenchmark::Get( const DecoderBenchmarkInfo& aBenchInfo) { if (!XRE_IsContentProcess()) { - NS_WARNING("Getting a benchmark allowed only from the content process."); + NS_WARNING( + "Getting a benchmark is only allowed only from the content process."); return BenchmarkScorePromise::CreateAndReject(NS_ERROR_FAILURE, __func__); } // There is no need for any of the data members to query the database, thus @@ -181,4 +183,51 @@ RefPtr DecoderBenchmark::Get( return bench->GetScore(aBenchInfo.mContentType, CreateStoreKey(aBenchInfo)); } +static nsDataHashtable DecoderVersionTable() { + nsDataHashtable decoderVersionTable; + + /* + * For the decoders listed here, the benchmark version number will be checked. + * If the version number does not exist in the database or is different than + * the version number listed here, all the benchmark entries for this decoder + * will be erased. An example of assigning the version number `1` for AV1 + * decoder is: + * + * decoderVersionTable.Put(NS_LITERAL_CSTRING("video/av1"), 1); + * + * For the decoders not listed here the `CheckVersion` method exits early, to + * avoid sending unecessary IPC messages. + */ + + return decoderVersionTable; +} + +/* static */ +void DecoderBenchmark::CheckVersion(const nsACString& aDecoderName) { + if (!XRE_IsContentProcess()) { + NS_WARNING( + "Checking version is only allowed only from the content process."); + return; + } + + nsCString name(aDecoderName); + int32_t version; + if (!DecoderVersionTable().Get(name, &version)) { + // A version is not set for that decoder ignore. + return; + } + + if (NS_IsMainThread()) { + BenchmarkStorageChild::Instance()->SendCheckVersion(name, version); + return; + } + + DebugOnly rv = + GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction( + "DecoderBenchmark::CheckVersion", [name, version]() { + BenchmarkStorageChild::Instance()->SendCheckVersion(name, version); + })); + MOZ_ASSERT(NS_SUCCEEDED(rv)); +} + } // namespace mozilla diff --git a/dom/media/mediacapabilities/DecoderBenchmark.h b/dom/media/mediacapabilities/DecoderBenchmark.h index 72dbdf2ac6b6..8f69b1450f16 100644 --- a/dom/media/mediacapabilities/DecoderBenchmark.h +++ b/dom/media/mediacapabilities/DecoderBenchmark.h @@ -33,6 +33,12 @@ class DecoderBenchmark final { static RefPtr Get( const DecoderBenchmarkInfo& aBenchInfo); + /* For the specific decoder, specified by aDecoderName, it compares the + * version number, from a static list of versions, to the version number + * found in the database. If those numbers are different all benchmark + * entries for that decoder are deleted. */ + static void CheckVersion(const nsACString& aDecoderName); + private: void StoreScore(const nsACString& aDecoderName, const nsACString& aKey, RefPtr aStats);