diff --git a/content/media/AbstractMediaDecoder.h b/content/media/AbstractMediaDecoder.h index 40b7ec20e5d..7b2786c0937 100644 --- a/content/media/AbstractMediaDecoder.h +++ b/content/media/AbstractMediaDecoder.h @@ -119,8 +119,11 @@ public: // required to begin playback have been acquired. Can be called on any thread. virtual void NotifyWaitingForResourcesStatusChanged() = 0; - // Called by Reader if the current audio track can be offloaded - virtual void SetCanOffloadAudio(bool aCanOffloadAudio) {} + // Set by Reader if the current audio track can be offloaded + virtual void SetPlatformCanOffloadAudio(bool aCanOffloadAudio) {} + + // Called by Decoder/State machine to check audio offload condtions are met + virtual bool CheckDecoderCanOffloadAudio() { return false; } // Called from HTMLMediaElement when owner document activity changes virtual void SetElementVisibility(bool aIsVisible) {} diff --git a/content/media/MediaDecoderStateMachine.cpp b/content/media/MediaDecoderStateMachine.cpp index d34b52d8ee8..7dbcac3fc4d 100644 --- a/content/media/MediaDecoderStateMachine.cpp +++ b/content/media/MediaDecoderStateMachine.cpp @@ -1135,6 +1135,11 @@ void MediaDecoderStateMachine::StartPlayback() NS_ASSERTION(!IsPlaying(), "Shouldn't be playing when StartPlayback() is called"); AssertCurrentThreadInMonitor(); + if (mDecoder->CheckDecoderCanOffloadAudio()) { + DECODER_LOG(PR_LOG_DEBUG, "Offloading playback"); + return; + } + mDecoder->NotifyPlaybackStarted(); SetPlayStartTime(TimeStamp::Now()); diff --git a/content/media/omx/MediaOmxCommonDecoder.cpp b/content/media/omx/MediaOmxCommonDecoder.cpp index 9d43832918f..7c2cfdf69e8 100644 --- a/content/media/omx/MediaOmxCommonDecoder.cpp +++ b/content/media/omx/MediaOmxCommonDecoder.cpp @@ -41,12 +41,19 @@ MediaOmxCommonDecoder::MediaOmxCommonDecoder() } void -MediaOmxCommonDecoder::SetCanOffloadAudio(bool aCanOffloadAudio) +MediaOmxCommonDecoder::SetPlatformCanOffloadAudio(bool aCanOffloadAudio) { ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); mCanOffloadAudio = aCanOffloadAudio; } +bool +MediaOmxCommonDecoder::CheckDecoderCanOffloadAudio() +{ + return (mCanOffloadAudio && !mFallbackToStateMachine && !mOutputStreams.Length() && + mInitialPlaybackRate == 1.0); +} + void MediaOmxCommonDecoder::MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) @@ -55,8 +62,7 @@ MediaOmxCommonDecoder::MetadataLoaded(MediaInfo* aInfo, MediaDecoder::MetadataLoaded(aInfo, aTags); ReentrantMonitorAutoEnter mon(GetReentrantMonitor()); - if (!mCanOffloadAudio || mFallbackToStateMachine || mOutputStreams.Length() || - mInitialPlaybackRate != 1.0) { + if (!CheckDecoderCanOffloadAudio()) { DECODER_LOG(PR_LOG_DEBUG, ("In %s Offload Audio check failed", __PRETTY_FUNCTION__)); return; @@ -79,6 +85,7 @@ MediaOmxCommonDecoder::MetadataLoaded(MediaInfo* aInfo, } mAudioOffloadPlayer = nullptr; + mFallbackToStateMachine = true; DECODER_LOG(PR_LOG_DEBUG, ("In %s Unable to start offload audio %d." "Switching to normal mode", __PRETTY_FUNCTION__, err)); } diff --git a/content/media/omx/MediaOmxCommonDecoder.h b/content/media/omx/MediaOmxCommonDecoder.h index 5fe2e2fd5ee..4b1be7b633c 100644 --- a/content/media/omx/MediaOmxCommonDecoder.h +++ b/content/media/omx/MediaOmxCommonDecoder.h @@ -31,7 +31,8 @@ public: virtual void PlaybackPositionChanged(); virtual void UpdateReadyStateForData(); virtual void SetElementVisibility(bool aIsVisible); - virtual void SetCanOffloadAudio(bool aCanOffloadAudio); + virtual void SetPlatformCanOffloadAudio(bool aCanOffloadAudio); + virtual bool CheckDecoderCanOffloadAudio(); virtual void AddOutputStream(ProcessedMediaStream* aStream, bool aFinishWhenEnded); virtual void SetPlaybackRate(double aPlaybackRate); diff --git a/content/media/omx/MediaOmxCommonReader.cpp b/content/media/omx/MediaOmxCommonReader.cpp index 4af94c2ff06..93a1ef38a6d 100644 --- a/content/media/omx/MediaOmxCommonReader.cpp +++ b/content/media/omx/MediaOmxCommonReader.cpp @@ -73,7 +73,7 @@ void MediaOmxCommonReader::CheckAudioOffload() if ((meta.get()) && hasNoVideo && isNotStreaming && isTypeMusic && canOffloadStream(meta, false, false, AUDIO_STREAM_MUSIC)) { DECODER_LOG(PR_LOG_DEBUG, ("Can offload this audio stream")); - mDecoder->SetCanOffloadAudio(true); + mDecoder->SetPlatformCanOffloadAudio(true); } } #endif