Bug 1808804 - part3 : keep statistic data growing correctly. r=jolin

The new statistic data sent from the new media engine which we created
after crash would be a completedly new data.

However, we might have accumulated some data in our `mFrameStats` before
crash. We need to consider the statistic data we've accumulated before
in order to make `mFramsStats` growing correctly.

Differential Revision: https://phabricator.services.mozilla.com/D166412
This commit is contained in:
alwu 2023-01-17 20:00:47 +00:00
Родитель d7d8b580d4
Коммит f146623d42
2 изменённых файлов: 42 добавлений и 6 удалений

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

@ -32,7 +32,16 @@ MFMediaEngineChild::MFMediaEngineChild(MFMediaEngineWrapper* aOwner,
: mOwner(aOwner),
mManagerThread(RemoteDecoderManagerChild::GetManagerThread()),
mMediaEngineId(0 /* invalid id, will be initialized later */),
mFrameStats(WrapNotNull(aFrameStats)) {}
mFrameStats(WrapNotNull(aFrameStats)) {
if (mFrameStats->GetPresentedFrames() > 0) {
mAccumulatedPresentedFramesFromPrevEngine =
Some(mFrameStats->GetPresentedFrames());
}
if (mFrameStats->GetDroppedSinkFrames() > 0) {
mAccumulatedDroppedFramesFromPrevEngine =
Some(mFrameStats->GetDroppedSinkFrames());
}
}
RefPtr<GenericNonExclusivePromise> MFMediaEngineChild::Init(
bool aShouldPreload) {
@ -174,21 +183,38 @@ mozilla::ipc::IPCResult MFMediaEngineChild::RecvUpdateStatisticData(
const StatisticData& aData) {
AssertOnManagerThread();
const uint64_t currentRenderedFrames = mFrameStats->GetPresentedFrames();
const uint64_t newRenderedFrames = GetUpdatedRenderedFrames(aData);
// Media engine won't tell us that which stage those dropped frames happened,
// so we treat all of them as the frames dropped in the a/v sync stage (sink).
const uint64_t currentDroppedSinkFrames = mFrameStats->GetDroppedSinkFrames();
MOZ_ASSERT(aData.renderedFrames() >= currentRenderedFrames);
MOZ_ASSERT(aData.droppedFrames() >= currentDroppedSinkFrames);
mFrameStats->Accumulate({0, 0, aData.renderedFrames() - currentRenderedFrames,
0, aData.droppedFrames() - currentDroppedSinkFrames,
0});
const uint64_t newDroppedSinkFrames = GetUpdatedDroppedFrames(aData);
mFrameStats->Accumulate({0, 0, newRenderedFrames - currentRenderedFrames, 0,
newDroppedSinkFrames - currentDroppedSinkFrames, 0});
CLOG("Update statictis data (rendered %" PRIu64 " -> %" PRIu64
", dropped %" PRIu64 " -> %" PRIu64 ")",
currentRenderedFrames, mFrameStats->GetPresentedFrames(),
currentDroppedSinkFrames, mFrameStats->GetDroppedSinkFrames());
MOZ_ASSERT(mFrameStats->GetPresentedFrames() >= currentRenderedFrames);
MOZ_ASSERT(mFrameStats->GetDroppedSinkFrames() >= currentDroppedSinkFrames);
return IPC_OK();
}
uint64_t MFMediaEngineChild::GetUpdatedRenderedFrames(
const StatisticData& aData) {
return mAccumulatedPresentedFramesFromPrevEngine
? (aData.renderedFrames() +
*mAccumulatedPresentedFramesFromPrevEngine)
: aData.renderedFrames();
}
uint64_t MFMediaEngineChild::GetUpdatedDroppedFrames(
const StatisticData& aData) {
return mAccumulatedDroppedFramesFromPrevEngine
? (aData.droppedFrames() +
*mAccumulatedDroppedFramesFromPrevEngine)
: aData.droppedFrames();
}
void MFMediaEngineChild::OwnerDestroyed() {
Unused << ManagerThread()->Dispatch(NS_NewRunnableFunction(
"MFMediaEngineChild::OwnerDestroy", [self = RefPtr{this}, this] {

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

@ -53,6 +53,9 @@ class MFMediaEngineChild final : public PMFMediaEngineChild {
private:
~MFMediaEngineChild() = default;
uint64_t GetUpdatedRenderedFrames(const StatisticData& aData);
uint64_t GetUpdatedDroppedFrames(const StatisticData& aData);
// Only modified on the manager thread.
MFMediaEngineWrapper* MOZ_NON_OWNING_REF mOwner;
@ -73,6 +76,13 @@ class MFMediaEngineChild final : public PMFMediaEngineChild {
NotNull<FrameStatistics*> const MOZ_NON_OWNING_REF mFrameStats;
bool mShutdown = false;
// Whenever the remote media engine process crashes, we will create a new
// engine child to rebuild the connection. These engine child shares the same
// frame stats data so we need to keep accumulate same data from previous
// engine.
Maybe<uint64_t> mAccumulatedPresentedFramesFromPrevEngine;
Maybe<uint64_t> mAccumulatedDroppedFramesFromPrevEngine;
};
/**