diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 6bdd1fb290d..f6d7fa47b0e 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -218,7 +218,6 @@ MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder, mCurrentTimeBeforeSeek(0), mCorruptFrames(30), mDecodingFirstFrame(true), - mDisabledHardwareAcceleration(false), mSentLoadedMetadataEvent(false), mSentFirstFrameLoadedEvent(false), mSentPlaybackEndedEvent(false), @@ -2482,14 +2481,13 @@ bool MediaDecoderStateMachine::CheckFrameValidity(VideoData* aData) // hardware acceleration. We use 10 as the corrupt value because RollingMean<> // only supports integer types. mCorruptFrames.insert(10); - if (!mDisabledHardwareAcceleration && - mReader->VideoIsHardwareAccelerated() && + if (mReader->VideoIsHardwareAccelerated() && frameStats.GetPresentedFrames() > 30 && mCorruptFrames.mean() >= 1 /* 10% */) { nsCOMPtr task = NS_NewRunnableMethod(mReader, &MediaDecoderReader::DisableHardwareAcceleration); DecodeTaskQueue()->Dispatch(task.forget()); - mDisabledHardwareAcceleration = true; + mCorruptFrames.clear(); gfxCriticalNote << "Too many dropped/corrupted frames, disabling DXVA"; } return false; diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h index 1190a0d8a45..0da374d4e9d 100644 --- a/dom/media/MediaDecoderStateMachine.h +++ b/dom/media/MediaDecoderStateMachine.h @@ -1271,8 +1271,6 @@ private: // successeeding. bool mDecodingFirstFrame; - bool mDisabledHardwareAcceleration; - // True if we are back from DECODER_STATE_DORMANT state and // LoadedMetadataEvent was already sent. bool mSentLoadedMetadataEvent; diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index f0d95ae37ce..45bd09a624e 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -73,6 +73,7 @@ MediaFormatReader::MediaFormatReader(AbstractMediaDecoder* aDecoder, , mSeekable(false) , mIsEncrypted(false) , mTrackDemuxersMayBlock(false) + , mHardwareAccelerationDisabled(false) { MOZ_ASSERT(aDemuxer); MOZ_COUNT_CTOR(MediaFormatReader); @@ -467,8 +468,11 @@ MediaFormatReader::EnsureDecodersCreated() false); mVideo.mDecoderInitialized = false; + // If we've disabled hardware acceleration for this reader, then we can't use + // the shared decoder. if (mSharedDecoderManager && - mPlatform->SupportsSharedDecoders(mInfo.mVideo)) { + mPlatform->SupportsSharedDecoders(mInfo.mVideo) && + !mHardwareAccelerationDisabled) { mVideo.mDecoder = mSharedDecoderManager->CreateVideoDecoder(mPlatform, mVideo.mInfo ? @@ -479,13 +483,16 @@ MediaFormatReader::EnsureDecodersCreated() mVideo.mTaskQueue, mVideo.mCallback); } else { + // Decoders use the layers backend to decide if they can use hardware decoding, + // so specify LAYERS_NONE if we want to forcibly disable it. mVideo.mDecoder = mPlatform->CreateDecoder(mVideo.mInfo ? *mVideo.mInfo->GetAsVideoInfo() : mInfo.mVideo, mVideo.mTaskQueue, mVideo.mCallback, - mLayersBackendType, + mHardwareAccelerationDisabled ? LayersBackend::LAYERS_NONE : + mLayersBackendType, mDecoder->GetImageContainer()); } NS_ENSURE_TRUE(mVideo.mDecoder != nullptr, false); @@ -590,8 +597,8 @@ void MediaFormatReader::DisableHardwareAcceleration() { MOZ_ASSERT(OnTaskQueue()); - if (HasVideo()) { - mPlatform->DisableHardwareAcceleration(); + if (HasVideo() && !mHardwareAccelerationDisabled) { + mHardwareAccelerationDisabled = true; Flush(TrackInfo::kVideoTrack); mVideo.mDecoder->Shutdown(); mVideo.mDecoder = nullptr; diff --git a/dom/media/MediaFormatReader.h b/dom/media/MediaFormatReader.h index 6431e9d4823..485dd1ba4b3 100644 --- a/dom/media/MediaFormatReader.h +++ b/dom/media/MediaFormatReader.h @@ -399,6 +399,8 @@ private: // Set to true if any of our track buffers may be blocking. bool mTrackDemuxersMayBlock; + bool mHardwareAccelerationDisabled; + // Seeking objects. bool IsSeeking() const { return mPendingSeekTime.isSome(); } void AttemptSeek(); diff --git a/dom/media/platforms/PlatformDecoderModule.h b/dom/media/platforms/PlatformDecoderModule.h index c2f985e2bf6..e41dc54f0be 100644 --- a/dom/media/platforms/PlatformDecoderModule.h +++ b/dom/media/platforms/PlatformDecoderModule.h @@ -110,8 +110,6 @@ public: // feeding it to MediaDataDecoder::Input. virtual ConversionRequired DecoderNeedsConversion(const TrackInfo& aConfig) const = 0; - virtual void DisableHardwareAcceleration() {} - virtual bool SupportsSharedDecoders(const VideoInfo& aConfig) const { return !AgnosticMimeType(aConfig.mMimeType); } diff --git a/dom/media/platforms/SharedDecoderManager.cpp b/dom/media/platforms/SharedDecoderManager.cpp index d538abf2775..29fde2c34fe 100644 --- a/dom/media/platforms/SharedDecoderManager.cpp +++ b/dom/media/platforms/SharedDecoderManager.cpp @@ -120,13 +120,6 @@ SharedDecoderManager::CreateVideoDecoder( return proxy.forget(); } -void -SharedDecoderManager::DisableHardwareAcceleration() -{ - MOZ_ASSERT(mPDM); - mPDM->DisableHardwareAcceleration(); -} - bool SharedDecoderManager::Recreate(const VideoInfo& aConfig) { diff --git a/dom/media/platforms/SharedDecoderManager.h b/dom/media/platforms/SharedDecoderManager.h index 43944e040cc..25775289c44 100644 --- a/dom/media/platforms/SharedDecoderManager.h +++ b/dom/media/platforms/SharedDecoderManager.h @@ -41,7 +41,6 @@ public: friend class SharedDecoderProxy; friend class SharedDecoderCallback; - void DisableHardwareAcceleration(); bool Recreate(const VideoInfo& aConfig); private: diff --git a/dom/media/platforms/wmf/WMFDecoderModule.cpp b/dom/media/platforms/wmf/WMFDecoderModule.cpp index 3aa21d75d03..697998cc6bd 100644 --- a/dom/media/platforms/wmf/WMFDecoderModule.cpp +++ b/dom/media/platforms/wmf/WMFDecoderModule.cpp @@ -41,13 +41,6 @@ WMFDecoderModule::~WMFDecoderModule() } } -void -WMFDecoderModule::DisableHardwareAcceleration() -{ - sDXVAEnabled = false; - sIsIntelDecoderEnabled = false; -} - static void SetNumOfDecoderThreads() { @@ -133,14 +126,6 @@ WMFDecoderModule::CreateAudioDecoder(const AudioInfo& aConfig, return decoder.forget(); } -bool -WMFDecoderModule::SupportsSharedDecoders(const VideoInfo& aConfig) const -{ - // If DXVA is enabled, but we're not going to use it for this specific config, then - // we can't use the shared decoder. - return !AgnosticMimeType(aConfig.mMimeType); -} - bool WMFDecoderModule::SupportsMimeType(const nsACString& aMimeType) { diff --git a/dom/media/platforms/wmf/WMFDecoderModule.h b/dom/media/platforms/wmf/WMFDecoderModule.h index e4f5e886572..e68d60c8e53 100644 --- a/dom/media/platforms/wmf/WMFDecoderModule.h +++ b/dom/media/platforms/wmf/WMFDecoderModule.h @@ -33,9 +33,6 @@ public: bool SupportsMimeType(const nsACString& aMimeType) override; - virtual void DisableHardwareAcceleration() override; - virtual bool SupportsSharedDecoders(const VideoInfo& aConfig) const override; - virtual ConversionRequired DecoderNeedsConversion(const TrackInfo& aConfig) const override;