Bug 1572043 - Check the version of the stored benchmarks when a video decoder is initialized.r=jya

Introduce a static method to call the CheckVersion method of the IPDL protocol from the content process. Every time a video decoder is initialized, the method is called to verify the version of the stored benchmark entries.

Differential Revision: https://phabricator.services.mozilla.com/D41003

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alex Chronopoulos 2019-08-13 09:54:27 +00:00
Родитель 04185356f6
Коммит 060c64a502
3 изменённых файлов: 62 добавлений и 2 удалений

Просмотреть файл

@ -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();

Просмотреть файл

@ -162,7 +162,8 @@ nsCString CreateStoreKey(const DecoderBenchmarkInfo& aBenchInfo) {
void DecoderBenchmark::Store(const DecoderBenchmarkInfo& aBenchInfo,
RefPtr<FrameStatistics> 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<BenchmarkScorePromise> 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<BenchmarkScorePromise> DecoderBenchmark::Get(
return bench->GetScore(aBenchInfo.mContentType, CreateStoreKey(aBenchInfo));
}
static nsDataHashtable<nsCStringHashKey, int32_t> DecoderVersionTable() {
nsDataHashtable<nsCStringHashKey, int32_t> 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<nsresult> rv =
GetMainThreadEventTarget()->Dispatch(NS_NewRunnableFunction(
"DecoderBenchmark::CheckVersion", [name, version]() {
BenchmarkStorageChild::Instance()->SendCheckVersion(name, version);
}));
MOZ_ASSERT(NS_SUCCEEDED(rv));
}
} // namespace mozilla

Просмотреть файл

@ -33,6 +33,12 @@ class DecoderBenchmark final {
static RefPtr<BenchmarkScorePromise> 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<FrameStatistics> aStats);