mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-19 01:10:22 +00:00
Bug 1311872. Part 1 - remove dormant code from MediaDecoder and its friends. We will let MDSM solely decide when to enter/exit dormant. r=cpearce,jya
MozReview-Commit-ID: 4rRSGcruy7Z --HG-- extra : rebase_source : 6bff3bde442dbc96ce23a4a1aabae9ec79f1b9f0 extra : intermediate-source : 456de41037090ff072925d937b001de31a479556 extra : source : 525be5a0f46950ced9efba9a7cfeda26ce73cfb8
This commit is contained in:
parent
8326d4e877
commit
9fcd26988d
@ -41,9 +41,6 @@ using namespace mozilla::dom;
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla::media;
|
||||
|
||||
// Default timeout msecs until try to enter dormant state by heuristic.
|
||||
static const int DEFAULT_HEURISTIC_DORMANT_TIMEOUT_MSECS = 10000;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
// The amount of instability we tollerate in calls to
|
||||
@ -298,120 +295,7 @@ MediaDecoder::NotifyOwnerActivityChanged(bool aIsVisible)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!IsShutdown());
|
||||
|
||||
SetElementVisibility(aIsVisible);
|
||||
|
||||
UpdateDormantState(false /* aDormantTimeout */, false /* aActivity */);
|
||||
// Start dormant timer if necessary
|
||||
StartDormantTimer();
|
||||
}
|
||||
|
||||
bool
|
||||
MediaDecoder::IsHeuristicDormantSupported() const
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
// We disallow dormant for encrypted media until bug 1181864 is fixed.
|
||||
return mInfo &&
|
||||
!mInfo->IsEncrypted() &&
|
||||
mIsHeuristicDormantSupported;
|
||||
}
|
||||
|
||||
void
|
||||
MediaDecoder::UpdateDormantState(bool aDormantTimeout, bool aActivity)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!IsShutdown());
|
||||
|
||||
if (!mDecoderStateMachine ||
|
||||
!mOwner->GetVideoFrameContainer() ||
|
||||
(mOwner->GetMediaElement() && mOwner->GetMediaElement()->IsBeingDestroyed()) ||
|
||||
!mDormantSupported)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DECODER_LOG("UpdateDormantState aTimeout=%d aActivity=%d mIsDormant=%d "
|
||||
"ownerActive=%d mIsVisible=%d mIsHeuristicDormant=%d "
|
||||
"mPlayState=%s encrypted=%s",
|
||||
aDormantTimeout, aActivity, mIsDormant, mOwner->IsActive(),
|
||||
mIsVisible.Ref(), mIsHeuristicDormant, PlayStateStr(),
|
||||
(!mInfo ? "Unknown" : (mInfo->IsEncrypted() ? "1" : "0")));
|
||||
|
||||
bool prevDormant = mIsDormant;
|
||||
mIsDormant = false;
|
||||
#ifdef MOZ_WIDGET_GONK
|
||||
if (mOwner->IsHidden()) {
|
||||
mIsDormant = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Try to enable dormant by idle heuristic, when the owner is hidden.
|
||||
bool prevHeuristicDormant = mIsHeuristicDormant;
|
||||
mIsHeuristicDormant = false;
|
||||
if (IsHeuristicDormantSupported() && !mIsVisible) {
|
||||
// Do not enter dormant when MediaDecoder is not paused nor ended.
|
||||
if ((aDormantTimeout || !mOwner->IsActive()) && !aActivity &&
|
||||
(mPlayState == PLAY_STATE_PAUSED || IsEnded())) {
|
||||
// Enable heuristic dormant
|
||||
mIsHeuristicDormant = true;
|
||||
} else if(prevHeuristicDormant && !aActivity) {
|
||||
// Continue heuristic dormant
|
||||
mIsHeuristicDormant = true;
|
||||
}
|
||||
|
||||
if (mIsHeuristicDormant) {
|
||||
mIsDormant = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (prevDormant == mIsDormant) {
|
||||
// No update to dormant state
|
||||
return;
|
||||
}
|
||||
|
||||
DECODER_LOG("UpdateDormantState() %s DORMANT state", mIsDormant ? "entering" : "exiting");
|
||||
mDecoderStateMachine->DispatchSetDormant(mIsDormant);
|
||||
}
|
||||
|
||||
void
|
||||
MediaDecoder::DormantTimerExpired(nsITimer* aTimer, void* aClosure)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aClosure);
|
||||
MediaDecoder* decoder = static_cast<MediaDecoder*>(aClosure);
|
||||
decoder->UpdateDormantState(true /* aDormantTimeout */,
|
||||
false /* aActivity */);
|
||||
}
|
||||
|
||||
void
|
||||
MediaDecoder::StartDormantTimer()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!IsHeuristicDormantSupported() ||
|
||||
mIsHeuristicDormant ||
|
||||
mIsVisible ||
|
||||
(mPlayState != PLAY_STATE_PAUSED && !IsEnded())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!mDormantTimer) {
|
||||
mDormantTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
}
|
||||
mDormantTimer->InitWithFuncCallback(&MediaDecoder::DormantTimerExpired,
|
||||
this,
|
||||
mHeuristicDormantTimeout,
|
||||
nsITimer::TYPE_ONE_SHOT);
|
||||
}
|
||||
|
||||
void
|
||||
MediaDecoder::CancelDormantTimer()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
if (mDormantTimer) {
|
||||
mDormantTimer->Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -487,7 +371,6 @@ MediaDecoder::IsInfinite() const
|
||||
|
||||
MediaDecoder::MediaDecoder(MediaDecoderOwner* aOwner)
|
||||
: mWatchManager(this, AbstractThread::MainThread())
|
||||
, mDormantSupported(false)
|
||||
, mLogicalPosition(0.0)
|
||||
, mDuration(std::numeric_limits<double>::quiet_NaN())
|
||||
, mResourceCallback(new ResourceCallback())
|
||||
@ -504,13 +387,6 @@ MediaDecoder::MediaDecoder(MediaDecoderOwner* aOwner)
|
||||
, mFiredMetadataLoaded(false)
|
||||
, mElementVisible(!aOwner->IsHidden())
|
||||
, mForcedHidden(false)
|
||||
, mIsDormant(false)
|
||||
, mIsHeuristicDormantSupported(
|
||||
Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false))
|
||||
, mHeuristicDormantTimeout(
|
||||
Preferences::GetInt("media.decoder.heuristic.dormant.timeout",
|
||||
DEFAULT_HEURISTIC_DORMANT_TIMEOUT_MSECS))
|
||||
, mIsHeuristicDormant(false)
|
||||
, INIT_MIRROR(mStateMachineIsShutdown, true)
|
||||
, INIT_MIRROR(mBuffered, TimeIntervals())
|
||||
, INIT_MIRROR(mNextFrameStatus, MediaDecoderOwner::NEXT_FRAME_UNINITIALIZED)
|
||||
@ -623,8 +499,6 @@ MediaDecoder::Shutdown()
|
||||
mResource->Close();
|
||||
}
|
||||
|
||||
CancelDormantTimer();
|
||||
|
||||
ChangeState(PLAY_STATE_SHUTDOWN);
|
||||
mOwner = nullptr;
|
||||
}
|
||||
@ -790,7 +664,6 @@ nsresult
|
||||
MediaDecoder::Play()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
UpdateDormantState(false /* aDormantTimeout */, true /* aActivity */);
|
||||
|
||||
NS_ASSERTION(mDecoderStateMachine != nullptr, "Should have state machine.");
|
||||
if (mPlaybackRate == 0) {
|
||||
@ -814,9 +687,6 @@ MediaDecoder::Seek(double aTime, SeekTarget::Type aSeekType, dom::Promise* aProm
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!IsShutdown());
|
||||
|
||||
UpdateDormantState(false /* aDormantTimeout */, true /* aActivity */);
|
||||
|
||||
MOZ_ASSERT(!mIsDormant, "should be out of dormant by now");
|
||||
MOZ_ASSERT(aTime >= 0.0, "Cannot seek to a negative value.");
|
||||
|
||||
int64_t timeUsecs = TimeUnit::FromSeconds(aTime).ToMicroseconds();
|
||||
@ -990,9 +860,9 @@ MediaDecoder::FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!IsShutdown());
|
||||
|
||||
DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d mPlayState=%s mIsDormant=%d",
|
||||
DECODER_LOG("FirstFrameLoaded, channels=%u rate=%u hasAudio=%d hasVideo=%d mPlayState=%s",
|
||||
aInfo->mAudio.mChannels, aInfo->mAudio.mRate,
|
||||
aInfo->HasAudio(), aInfo->HasVideo(), PlayStateStr(), mIsDormant);
|
||||
aInfo->HasAudio(), aInfo->HasVideo(), PlayStateStr());
|
||||
|
||||
mInfo = aInfo.forget();
|
||||
|
||||
@ -1005,7 +875,7 @@ MediaDecoder::FirstFrameLoaded(nsAutoPtr<MediaInfo> aInfo,
|
||||
// before reaching here, so only change the
|
||||
// state if we're still set to the original
|
||||
// loading state.
|
||||
if (mPlayState == PLAY_STATE_LOADING && !mIsDormant) {
|
||||
if (mPlayState == PLAY_STATE_LOADING) {
|
||||
ChangeState(mNextState);
|
||||
}
|
||||
|
||||
@ -1318,10 +1188,6 @@ MediaDecoder::ChangeState(PlayState aState)
|
||||
} else if (IsEnded()) {
|
||||
RemoveMediaTracks();
|
||||
}
|
||||
|
||||
CancelDormantTimer();
|
||||
// Start dormant timer if necessary
|
||||
StartDormantTimer();
|
||||
}
|
||||
|
||||
void
|
||||
@ -1890,10 +1756,10 @@ MediaDecoder::DumpDebugInfo()
|
||||
{
|
||||
MOZ_ASSERT(!IsShutdown());
|
||||
DUMP_LOG("metadata: channels=%u rate=%u hasAudio=%d hasVideo=%d, "
|
||||
"state: mPlayState=%s mIsDormant=%d, mdsm=%p",
|
||||
"state: mPlayState=%s mdsm=%p",
|
||||
mInfo ? mInfo->mAudio.mChannels : 0, mInfo ? mInfo->mAudio.mRate : 0,
|
||||
mInfo ? mInfo->HasAudio() : 0, mInfo ? mInfo->HasVideo() : 0,
|
||||
PlayStateStr(), mIsDormant, GetStateMachine());
|
||||
PlayStateStr(), GetStateMachine());
|
||||
|
||||
nsString str;
|
||||
GetMozDebugReaderData(str);
|
||||
|
@ -184,14 +184,8 @@ public:
|
||||
virtual nsresult Play();
|
||||
|
||||
// Notify activity of the decoder owner is changed.
|
||||
// Based on the activity, dormant state is updated.
|
||||
// Dormant state is a state to free all scarce media resources
|
||||
// (like hw video codec), did not decoding and stay dormant.
|
||||
// It is used to share scarece media resources in system.
|
||||
virtual void NotifyOwnerActivityChanged(bool aIsVisible);
|
||||
|
||||
void UpdateDormantState(bool aDormantTimeout, bool aActivity);
|
||||
|
||||
// Pause video playback.
|
||||
virtual void Pause();
|
||||
// Adjust the speed of the playback, optionally with pitch correction,
|
||||
@ -506,14 +500,6 @@ protected:
|
||||
|
||||
void SetStateMachineParameters();
|
||||
|
||||
static void DormantTimerExpired(nsITimer *aTimer, void *aClosure);
|
||||
|
||||
// Start a timer for heuristic dormant.
|
||||
void StartDormantTimer();
|
||||
|
||||
// Cancel a timer for heuristic dormant.
|
||||
void CancelDormantTimer();
|
||||
|
||||
bool IsShutdown() const;
|
||||
|
||||
// Called by the state machine to notify the decoder that the duration
|
||||
@ -542,9 +528,6 @@ protected:
|
||||
* The following members should be accessed with the decoder lock held.
|
||||
******/
|
||||
|
||||
// Whether the decoder implementation supports dormant mode.
|
||||
bool mDormantSupported;
|
||||
|
||||
// The logical playback position of the media resource in units of
|
||||
// seconds. This corresponds to the "official position" in HTML5. Note that
|
||||
// we need to store this as a double, rather than an int64_t (like
|
||||
@ -628,9 +611,6 @@ protected:
|
||||
void DiscardOngoingSeekIfExists();
|
||||
virtual void CallSeek(const SeekTarget& aTarget, dom::Promise* aPromise);
|
||||
|
||||
// Returns true if heuristic dormant is supported.
|
||||
bool IsHeuristicDormantSupported() const;
|
||||
|
||||
MozPromiseRequestHolder<SeekPromise> mSeekRequest;
|
||||
RefPtr<dom::Promise> mSeekDOMPromise;
|
||||
|
||||
@ -699,21 +679,6 @@ protected:
|
||||
// If true, forces the decoder to be considered hidden.
|
||||
bool mForcedHidden;
|
||||
|
||||
// True if MediaDecoder is in dormant state.
|
||||
bool mIsDormant;
|
||||
|
||||
// True if heuristic dormant is supported.
|
||||
const bool mIsHeuristicDormantSupported;
|
||||
|
||||
// Timeout ms of heuristic dormant timer.
|
||||
const int mHeuristicDormantTimeout;
|
||||
|
||||
// True if MediaDecoder is in dormant by heuristic.
|
||||
bool mIsHeuristicDormant;
|
||||
|
||||
// Timer to schedule updating dormant state.
|
||||
nsCOMPtr<nsITimer> mDormantTimer;
|
||||
|
||||
// A listener to receive metadata updates from MDSM.
|
||||
MediaEventListener mTimedMetadataListener;
|
||||
|
||||
|
@ -2455,14 +2455,6 @@ void MediaDecoderStateMachine::RecomputeDuration()
|
||||
mDuration = Some(duration);
|
||||
}
|
||||
|
||||
void
|
||||
MediaDecoderStateMachine::DispatchSetDormant(bool aDormant)
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> r = NewRunnableMethod<bool>(
|
||||
this, &MediaDecoderStateMachine::SetDormant, aDormant);
|
||||
OwnerThread()->Dispatch(r.forget());
|
||||
}
|
||||
|
||||
void
|
||||
MediaDecoderStateMachine::SetDormant(bool aDormant)
|
||||
{
|
||||
|
@ -180,9 +180,6 @@ public:
|
||||
this, &MediaDecoderStateMachine::SetPlaybackRate, aPlaybackRate));
|
||||
}
|
||||
|
||||
// Set/Unset dormant state.
|
||||
void DispatchSetDormant(bool aDormant);
|
||||
|
||||
RefPtr<ShutdownPromise> BeginShutdown();
|
||||
|
||||
// Notifies the state machine that should minimize the number of samples
|
||||
|
@ -31,7 +31,6 @@ namespace mozilla {
|
||||
MP4Decoder::MP4Decoder(MediaDecoderOwner* aOwner)
|
||||
: MediaDecoder(aOwner)
|
||||
{
|
||||
mDormantSupported = Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false);
|
||||
}
|
||||
|
||||
MediaDecoderStateMachine* MP4Decoder::CreateStateMachine()
|
||||
|
@ -43,14 +43,6 @@ public:
|
||||
media::TimeIntervals GetSeekable() override;
|
||||
media::TimeIntervals GetBuffered() override;
|
||||
|
||||
// We can't do this in the constructor because we don't know what type of
|
||||
// media we're dealing with by that point.
|
||||
void NotifyDormantSupported(bool aSupported)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mDormantSupported = aSupported;
|
||||
}
|
||||
|
||||
void Shutdown() override;
|
||||
|
||||
static already_AddRefed<MediaResource> CreateResource(nsIPrincipal* aPrincipal = nullptr);
|
||||
|
@ -312,9 +312,6 @@ SourceBuffer::SourceBuffer(MediaSource* aMediaSource, const nsACString& aType)
|
||||
mTrackBuffersManager =
|
||||
new TrackBuffersManager(aMediaSource->GetDecoder(), aType);
|
||||
|
||||
// Now that we know what type we're dealing with, enable dormant as needed.
|
||||
aMediaSource->GetDecoder()->NotifyDormantSupported(Preferences::GetBool("media.decoder.heuristic.dormant.enabled", false));
|
||||
|
||||
MSE_DEBUG("Create mTrackBuffersManager=%p",
|
||||
mTrackBuffersManager.get());
|
||||
|
||||
|
@ -334,9 +334,6 @@ pref("media.play-stand-alone", true);
|
||||
pref("media.hardware-video-decoding.enabled", true);
|
||||
pref("media.hardware-video-decoding.force-enabled", false);
|
||||
|
||||
pref("media.decoder.heuristic.dormant.enabled", true);
|
||||
pref("media.decoder.heuristic.dormant.timeout", 10000);
|
||||
|
||||
#ifdef MOZ_DIRECTSHOW
|
||||
pref("media.directshow.enabled", true);
|
||||
#endif
|
||||
|
@ -312,10 +312,6 @@ user_pref("media.eme.enabled", true);
|
||||
|
||||
user_pref("media.autoplay.enabled", true);
|
||||
|
||||
#if defined(XP_WIN)
|
||||
user_pref("media.decoder.heuristic.dormant.timeout", 0);
|
||||
#endif
|
||||
|
||||
// Don't use auto-enabled e10s
|
||||
user_pref("browser.tabs.remote.autostart.1", false);
|
||||
user_pref("browser.tabs.remote.autostart.2", false);
|
||||
|
Loading…
x
Reference in New Issue
Block a user