From a5df92b66f6b43f947d4e70026d3151d1eaf6aa3 Mon Sep 17 00:00:00 2001 From: Blake Wu Date: Thu, 7 Aug 2014 18:23:45 +0800 Subject: [PATCH] Bug 941302 - Part 3: Changes for adding Gonk Decode Module. r=cpearce From de67de8646b413bce991789b42d09f398b162b53 Mon Sep 17 00:00:00 2001 --- b2g/app/b2g.js | 5 +- content/media/fmp4/MP4Decoder.cpp | 7 +++ content/media/fmp4/MP4Reader.cpp | 56 +++++++++++++++++++- content/media/fmp4/MP4Reader.h | 12 +++++ content/media/fmp4/PlatformDecoderModule.cpp | 14 +++++ content/media/fmp4/PlatformDecoderModule.h | 14 +++++ content/media/fmp4/moz.build | 6 ++- 7 files changed, 110 insertions(+), 4 deletions(-) diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 0080a4bf21d3..b3f90b5924b0 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -309,7 +309,10 @@ pref("dom.indexedDB.warningQuota", 5); pref("media.preload.default", 1); // default to preload none pref("media.preload.auto", 2); // preload metadata if preload=auto pref("media.cache_size", 4096); // 4MB media cache - +#ifdef MOZ_FMP4 +// Enable/Disable Gonk Decoder Module +pref("media.fragmented-mp4.gonk.enabled", false); +#endif // The default number of decoded video frames that are enqueued in // MediaDecoderReader's mVideoQueue. pref("media.video-queue.default-size", 3); diff --git a/content/media/fmp4/MP4Decoder.cpp b/content/media/fmp4/MP4Decoder.cpp index a36ceb922e80..7313bbdd7c4b 100644 --- a/content/media/fmp4/MP4Decoder.cpp +++ b/content/media/fmp4/MP4Decoder.cpp @@ -135,6 +135,12 @@ IsAppleAvailable() #endif } +static bool +IsGonkMP4DecoderAvailable() +{ + return Preferences::GetBool("media.fragmented-mp4.gonk.enabled", false); +} + static bool HavePlatformMPEGDecoders() { @@ -145,6 +151,7 @@ HavePlatformMPEGDecoders() #endif IsFFmpegAvailable() || IsAppleAvailable() || + IsGonkMP4DecoderAvailable() || // TODO: Other platforms... false; } diff --git a/content/media/fmp4/MP4Reader.cpp b/content/media/fmp4/MP4Reader.cpp index daa5b3c0f1ce..119de3864905 100644 --- a/content/media/fmp4/MP4Reader.cpp +++ b/content/media/fmp4/MP4Reader.cpp @@ -236,8 +236,14 @@ private: }; #endif -bool MP4Reader::IsWaitingMediaResources() -{ +bool MP4Reader::IsWaitingOnCodecResource() { +#ifdef MOZ_GONK_MEDIACODEC + return mVideo.mDecoder && mVideo.mDecoder->IsWaitingMediaResources(); +#endif + return false; +} + +bool MP4Reader::IsWaitingOnCDMResource() { #ifdef MOZ_EME nsRefPtr proxy; { @@ -263,6 +269,15 @@ bool MP4Reader::IsWaitingMediaResources() #endif } +bool MP4Reader::IsWaitingMediaResources() +{ + // IsWaitingOnCDMResource() *must* come first, because we don't know whether + // we can create a decoder until the CDM is initialized and it has told us + // whether *it* will decode, or whether we need to create a PDM to do the + // decoding + return IsWaitingOnCDMResource() || IsWaitingOnCodecResource(); +} + void MP4Reader::ExtractCryptoInitData(nsTArray& aInitData) { @@ -304,7 +319,12 @@ MP4Reader::ReadMetadata(MediaInfo* aInfo, // an encrypted stream and we need to wait for a CDM to be set, we don't // need to reinit the demuxer. mDemuxerInitialized = true; + } else if (mPlatform && !IsWaitingMediaResources()) { + *aInfo = mInfo; + *aTags = nullptr; + return NS_OK; } + if (mDemuxer->Crypto().valid) { #ifdef MOZ_EME if (!sIsEMEEnabled) { @@ -750,4 +770,36 @@ MP4Reader::GetBuffered(dom::TimeRanges* aBuffered, int64_t aStartTime) return NS_OK; } +bool MP4Reader::IsDormantNeeded() +{ +#ifdef MOZ_GONK_MEDIACODEC + return mVideo.mDecoder && mVideo.mDecoder->IsDormantNeeded(); +#endif + return false; +} + +void MP4Reader::ReleaseMediaResources() +{ +#ifdef MOZ_GONK_MEDIACODEC + // Before freeing a video codec, all video buffers needed to be released + // even from graphics pipeline. + VideoFrameContainer* container = mDecoder->GetVideoFrameContainer(); + if (container) { + container->ClearCurrentFrame(); + } + if (mVideo.mDecoder) { + mVideo.mDecoder->ReleaseMediaResources(); + } +#endif +} + +void MP4Reader::NotifyResourcesStatusChanged() +{ +#ifdef MOZ_GONK_MEDIACODEC + if (mDecoder) { + mDecoder->NotifyWaitingForResourcesStatusChanged(); + } +#endif +} + } // namespace mozilla diff --git a/content/media/fmp4/MP4Reader.h b/content/media/fmp4/MP4Reader.h index 1fc8822802e3..4bf010c678e0 100644 --- a/content/media/fmp4/MP4Reader.h +++ b/content/media/fmp4/MP4Reader.h @@ -58,7 +58,10 @@ public: virtual nsresult GetBuffered(dom::TimeRanges* aBuffered, int64_t aStartTime) MOZ_OVERRIDE; + // For Media Resource Management virtual bool IsWaitingMediaResources() MOZ_OVERRIDE; + virtual bool IsDormantNeeded() MOZ_OVERRIDE; + virtual void ReleaseMediaResources() MOZ_OVERRIDE; virtual nsresult ResetDecode() MOZ_OVERRIDE; @@ -83,6 +86,9 @@ private: bool Decode(mp4_demuxer::TrackType aTrack); void Flush(mp4_demuxer::TrackType aTrack); void DrainComplete(mp4_demuxer::TrackType aTrack); + void NotifyResourcesStatusChanged(); + bool IsWaitingOnCodecResource(); + bool IsWaitingOnCDMResource(); nsAutoPtr mDemuxer; nsAutoPtr mPlatform; @@ -107,6 +113,12 @@ private: virtual void DrainComplete() MOZ_OVERRIDE { mReader->DrainComplete(mType); } + virtual void NotifyResourcesStatusChanged() MOZ_OVERRIDE { + mReader->NotifyResourcesStatusChanged(); + } + virtual void ReleaseMediaResources() MOZ_OVERRIDE { + mReader->ReleaseMediaResources(); + } private: MP4Reader* mReader; mp4_demuxer::TrackType mType; diff --git a/content/media/fmp4/PlatformDecoderModule.cpp b/content/media/fmp4/PlatformDecoderModule.cpp index 06edf04f6895..2f594bfcf48d 100644 --- a/content/media/fmp4/PlatformDecoderModule.cpp +++ b/content/media/fmp4/PlatformDecoderModule.cpp @@ -14,6 +14,10 @@ #ifdef MOZ_APPLEMEDIA #include "AppleDecoderModule.h" #endif +#ifdef MOZ_GONK_MEDIACODEC +#include "GonkDecoderModule.h" +#endif + #include "mozilla/Preferences.h" #ifdef MOZ_EME #include "EMEDecoderModule.h" @@ -28,6 +32,7 @@ extern PlatformDecoderModule* CreateBlankDecoderModule(); bool PlatformDecoderModule::sUseBlankDecoder = false; bool PlatformDecoderModule::sFFmpegDecoderEnabled = false; +bool PlatformDecoderModule::sGonkDecoderEnabled = false; /* static */ void @@ -44,6 +49,10 @@ PlatformDecoderModule::Init() "media.fragmented-mp4.use-blank-decoder"); Preferences::AddBoolVarCache(&sFFmpegDecoderEnabled, "media.fragmented-mp4.ffmpeg.enabled", false); +#ifdef MOZ_GONK_MEDIACODEC + Preferences::AddBoolVarCache(&sGonkDecoderEnabled, + "media.fragmented-mp4.gonk.enabled", false); +#endif #ifdef XP_WIN WMFDecoderModule::Init(); #endif @@ -132,6 +141,11 @@ PlatformDecoderModule::Create() if (NS_SUCCEEDED(m->Startup())) { return m.forget(); } +#endif +#ifdef MOZ_GONK_MEDIACODEC + if (sGonkDecoderEnabled) { + return new GonkDecoderModule(); + } #endif return nullptr; } diff --git a/content/media/fmp4/PlatformDecoderModule.h b/content/media/fmp4/PlatformDecoderModule.h index 629a8714ebb7..9c677139a8e5 100644 --- a/content/media/fmp4/PlatformDecoderModule.h +++ b/content/media/fmp4/PlatformDecoderModule.h @@ -125,6 +125,7 @@ protected: // Caches pref media.fragmented-mp4.use-blank-decoder static bool sUseBlankDecoder; static bool sFFmpegDecoderEnabled; + static bool sGonkDecoderEnabled; }; // A callback used by MediaDataDecoder to return output/errors to the @@ -146,6 +147,10 @@ public: virtual void InputExhausted() = 0; virtual void DrainComplete() = 0; + + virtual void NotifyResourcesStatusChanged() {}; + + virtual void ReleaseMediaResources() {}; }; // MediaDataDecoder is the interface exposed by decoders created by the @@ -211,6 +216,15 @@ public: // returned. virtual nsresult Shutdown() = 0; + // For Codec Resource Management + virtual bool IsWaitingMediaResources() { + return false; + }; + virtual bool IsDormantNeeded() { + return false; + }; + virtual void ReleaseMediaResources() {}; + virtual void ReleaseDecoder() {}; }; } // namespace mozilla diff --git a/content/media/fmp4/moz.build b/content/media/fmp4/moz.build index fc830bf542c6..d254ab0251a9 100644 --- a/content/media/fmp4/moz.build +++ b/content/media/fmp4/moz.build @@ -59,12 +59,16 @@ if CONFIG['MOZ_APPLEMEDIA']: '-framework AudioToolbox', ] +if CONFIG['ANDROID_VERSION'] >= '18'and CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk': + DEFINES['MOZ_GONK_MEDIACODEC'] = True + DIRS += ['gonk'] + include('/ipc/chromium/chromium-config.mozbuild') LOCAL_INCLUDES += [ '../base', ] - + FINAL_LIBRARY = 'xul' FAIL_ON_WARNINGS = True