From 7d2785b4a8575d567167cbb1073e987762da46e2 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Fri, 30 Jun 2017 10:11:42 +0800 Subject: [PATCH] Bug 1377370. P1 - let HLSDecoder override Load() so it can create an HLSResource directly without going through MediaResource::Create(). r=kikuo MozReview-Commit-ID: BL8bt2JtKfa --HG-- extra : rebase_source : 70231ab332fee2316e86aa73e834f108183b23d8 extra : source : e97125ebc28890e0d538c4ef4d8abc9232e69bac --- dom/media/ChannelMediaDecoder.h | 9 +++++---- dom/media/MediaDecoder.h | 3 +-- dom/media/hls/HLSDecoder.cpp | 36 +++++++++++++++++++++++++++++++++ dom/media/hls/HLSDecoder.h | 5 +++++ 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/dom/media/ChannelMediaDecoder.h b/dom/media/ChannelMediaDecoder.h index ab35449633af..0d52190794ce 100644 --- a/dom/media/ChannelMediaDecoder.h +++ b/dom/media/ChannelMediaDecoder.h @@ -52,6 +52,7 @@ class ChannelMediaDecoder : public MediaDecoder const RefPtr mAbstractMainThread; }; +protected: RefPtr mResourceCallback; public: @@ -63,10 +64,10 @@ public: // Subclasses must implement this. virtual ChannelMediaDecoder* Clone(MediaDecoderInit& aInit) = 0; - nsresult Load(nsIChannel* aChannel, - bool aIsPrivateBrowsing, - nsIStreamListener** aStreamListener); - nsresult Load(MediaResource* aOriginal); + virtual nsresult Load(nsIChannel* aChannel, + bool aIsPrivateBrowsing, + nsIStreamListener** aStreamListener); + virtual nsresult Load(MediaResource* aOriginal); private: nsresult OpenResource(nsIStreamListener** aStreamListener); diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h index f6ac925b69a8..be8525a55883 100644 --- a/dom/media/MediaDecoder.h +++ b/dom/media/MediaDecoder.h @@ -131,8 +131,7 @@ public: // Called if the media file encounters a network error. void NetworkError(); - // Get the current MediaResource being used. Its URI will be returned - // by currentSrc. Returns what was passed to Load(), if Load() has been called. + // Get the current MediaResource being used. // Note: The MediaResource is refcounted, but it outlives the MediaDecoder, // so it's OK to use the reference returned by this function without // refcounting, *unless* you need to store and use the reference after the diff --git a/dom/media/hls/HLSDecoder.cpp b/dom/media/hls/HLSDecoder.cpp index 968c379b9fd8..0863ebf950fe 100644 --- a/dom/media/hls/HLSDecoder.cpp +++ b/dom/media/hls/HLSDecoder.cpp @@ -14,6 +14,8 @@ #include "MediaDecoderStateMachine.h" #include "MediaFormatReader.h" #include "MediaPrefs.h" +#include "MediaShutdownManager.h" +#include "nsNetUtil.h" namespace mozilla { @@ -56,4 +58,38 @@ HLSDecoder::IsSupportedType(const MediaContainerType& aContainerType) DecoderTraits::IsHttpLiveStreamingType(aContainerType); } +nsresult +HLSDecoder::Load(nsIChannel* aChannel, + bool aIsPrivateBrowsing, + nsIStreamListener**) +{ + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(!mResource); + + nsCOMPtr uri; + nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + mResource = new HLSResource(mResourceCallback, aChannel, uri); + + rv = MediaShutdownManager::Instance().Register(this); + if (NS_WARN_IF(NS_FAILED(rv))) { + return rv; + } + + SetStateMachine(CreateStateMachine()); + NS_ENSURE_TRUE(GetStateMachine(), NS_ERROR_FAILURE); + + return InitializeStateMachine(); +} + +nsresult +HLSDecoder::Load(MediaResource*) +{ + MOZ_CRASH("Clone is not supported"); + return NS_ERROR_FAILURE; +} + } // namespace mozilla diff --git a/dom/media/hls/HLSDecoder.h b/dom/media/hls/HLSDecoder.h index 0938ac67b28e..fc64ed237d36 100644 --- a/dom/media/hls/HLSDecoder.h +++ b/dom/media/hls/HLSDecoder.h @@ -33,6 +33,11 @@ public: // If provided, codecs are checked for support. static bool IsSupportedType(const MediaContainerType& aContainerType); + nsresult Load(nsIChannel* aChannel, + bool aIsPrivateBrowsing, + nsIStreamListener**) override; + nsresult Load(MediaResource*) override; + private: RefPtr mReader; };