Skip to content

Commit

Permalink
#434: initial work on decode startup delay and MSE spoofing
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Aug 30, 2017
1 parent 3f66b79 commit 1c7323d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
38 changes: 36 additions & 2 deletions dom/media/MediaDecoderStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ static uint32_t sVideoQueueDefaultSize = MAX_VIDEO_QUEUE_SIZE;
static uint32_t sVideoQueueHWAccelSize = MIN_VIDEO_QUEUE_SIZE;
static uint32_t sVideoQueueSendToCompositorSize = VIDEO_QUEUE_SEND_TO_COMPOSITOR_SIZE;

// TenFourFox issue 434
// Seconds to stall the video decoder on initial startup to allow sufficient
// buildup in memory and other items onscreen to render.
static const uint32_t DEFAULT_VIDEO_DECODE_STARTUP_DELAY = 6;
static uint32_t sVideoDecodeStartupDelay = DEFAULT_VIDEO_DECODE_STARTUP_DELAY;

static void InitVideoQueuePrefs() {
MOZ_ASSERT(NS_IsMainThread());
static bool sPrefInit = false;
Expand All @@ -193,6 +199,8 @@ static void InitVideoQueuePrefs() {
"media.video-queue.hw-accel-size", MIN_VIDEO_QUEUE_SIZE);
sVideoQueueSendToCompositorSize = Preferences::GetUint(
"media.video-queue.send-to-compositor-size", VIDEO_QUEUE_SEND_TO_COMPOSITOR_SIZE);
sVideoDecodeStartupDelay = Preferences::GetUint(
"tenfourfox.media.decode_delay", DEFAULT_VIDEO_DECODE_STARTUP_DELAY);
}
}

Expand Down Expand Up @@ -2040,8 +2048,16 @@ MediaDecoderStateMachine::OnMetadataRead(MetadataHolder* aMetadata)
return;
}

StartDecoding();

// TenFourFox issue 434
SetState(DECODER_STATE_STARTUP_DELAY);
if (HasVideo() && MOZ_LIKELY(sVideoDecodeStartupDelay > 0)) {
FrameStatistics& frameStats = *mFrameStats;
// Fake out MSE by saying we've already dropped a crapload of frames.
frameStats.NotifyDecodedFrames(0, 0, 2000);
// Stall a bit to let everything load.
ScheduleStateMachineIn(USECS_PER_S * sVideoDecodeStartupDelay);
return;
}
ScheduleStateMachine();
}

Expand Down Expand Up @@ -2321,6 +2337,22 @@ nsresult MediaDecoderStateMachine::RunStateMachine()
return NS_OK;
}

// TenFourFox issue 434
case DECODER_STATE_STARTUP_DELAY: {
// We have to implement this as a separate phase, because we don't
// know if we haz video until after metadata is read.
StartDecoding();

if (HasVideo() && MOZ_LIKELY(sVideoDecodeStartupDelay > 0)) {
FrameStatistics& frameStats = *mFrameStats;
// Fake out MSE by saying we've dropped a crapload more of frames.
frameStats.NotifyDecodedFrames(0, 0, 2000);
}

ScheduleStateMachine();
return NS_OK;
}

case DECODER_STATE_DECODING: {
if (IsDecodingFirstFrame()) {
// We haven't completed decoding our first frames, we can't start
Expand Down Expand Up @@ -2509,6 +2541,7 @@ MediaDecoderStateMachine::CheckFrameValidity(VideoData* aData)
// hardware acceleration. We use 10 as the corrupt value because RollingMean<>
// only supports integer types.
mCorruptFrames.insert(10);
#if(0)
if (mReader->VideoIsHardwareAccelerated() &&
frameStats.GetPresentedFrames() > 60 &&
mCorruptFrames.mean() >= 2 /* 20% */) {
Expand All @@ -2518,6 +2551,7 @@ MediaDecoderStateMachine::CheckFrameValidity(VideoData* aData)
mCorruptFrames.clear();
gfxCriticalNote << "Too many dropped/corrupted frames, disabling DXVA";
}
#endif
} else {
mCorruptFrames.insert(0);
}
Expand Down
1 change: 1 addition & 0 deletions dom/media/MediaDecoderStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class MediaDecoderStateMachine
enum State {
DECODER_STATE_DECODING_NONE,
DECODER_STATE_DECODING_METADATA,
DECODER_STATE_STARTUP_DELAY, // issue 434
DECODER_STATE_WAIT_FOR_CDM,
DECODER_STATE_DORMANT,
DECODER_STATE_DECODING,
Expand Down

0 comments on commit 1c7323d

Please sign in to comment.