Bug 1386956. P2 - move mResource to sub-classes. r=gerald

MozReview-Commit-ID: Ixx8NwZfjhO

--HG--
extra : rebase_source : 65529a6cf6736e6fde61ddd413efa6f38cd96922
extra : intermediate-source : 1d75a416e8452c356f533d13c3037cae07aeb291
extra : source : d14219446670baf0f02da86c412932ec59dbf178
This commit is contained in:
JW Wang 2017-08-03 15:38:28 +08:00
parent f86786c3e8
commit d685ec7cc3
8 changed files with 41 additions and 16 deletions

View File

@ -155,6 +155,12 @@ ChannelMediaDecoder::ChannelMediaDecoder(MediaDecoderInit& aInit)
mResourceCallback->Connect(this);
}
MediaResource*
ChannelMediaDecoder::GetResource() const
{
return mResource;
}
MediaDecoderStateMachine* ChannelMediaDecoder::CreateStateMachine()
{
MOZ_ASSERT(NS_IsMainThread());

View File

@ -53,12 +53,15 @@ class ChannelMediaDecoder : public MediaDecoder
protected:
RefPtr<ResourceCallback> mResourceCallback;
RefPtr<MediaResource> mResource;
public:
explicit ChannelMediaDecoder(MediaDecoderInit& aInit);
MediaDecoderStateMachine* CreateStateMachine() override;
MediaResource* GetResource() const override final;
void Shutdown() override;
// Create a new decoder of the same type as this one.

View File

@ -135,7 +135,7 @@ public:
// MediaDecoder has been destroyed. You might need to do this if you're
// wrapping the MediaResource in some kind of byte stream interface to be
// passed to a platform decoder.
MediaResource* GetResource() const { return mResource; }
virtual MediaResource* GetResource() const = 0;
// Return the principal of the current URI being played or downloaded.
virtual already_AddRefed<nsIPrincipal> GetCurrentPrincipal();
@ -505,9 +505,6 @@ protected:
* The following member variables can be accessed from any thread.
******/
// Media data resource.
RefPtr<MediaResource> mResource;
RefPtr<MediaFormatReader> mReader;
// Amount of buffered data ahead of current time required to consider that

View File

@ -19,13 +19,18 @@
namespace mozilla {
MediaResource*
HLSDecoder::GetResource() const
{
return mResource;
}
void
HLSDecoder::Shutdown()
{
MOZ_ASSERT(NS_IsMainThread());
auto resource = static_cast<HLSResource*>(mResource.get());
if (resource) {
resource->Detach();
if (mResource) {
mResource->Detach();
}
MediaDecoder::Shutdown();
}
@ -35,9 +40,8 @@ HLSDecoder::CreateStateMachine()
{
MOZ_ASSERT(NS_IsMainThread());
MediaResource* resource = GetResource();
MOZ_ASSERT(resource);
auto resourceWrapper = static_cast<HLSResource*>(resource)->GetResourceWrapper();
MOZ_ASSERT(mResource);
auto resourceWrapper = mResource->GetResourceWrapper();
MOZ_ASSERT(resourceWrapper);
MediaFormatReaderInit init;
init.mVideoFrameContainer = GetVideoFrameContainer();
@ -93,8 +97,7 @@ HLSDecoder::Play()
{
MOZ_ASSERT(NS_IsMainThread());
HLS_DEBUG("HLSDecoder", "MediaElement called Play");
auto resourceWrapper =
static_cast<HLSResource*>(GetResource())->GetResourceWrapper();
auto resourceWrapper = mResource->GetResourceWrapper();
resourceWrapper->Play();
return MediaDecoder::Play();
}
@ -104,8 +107,7 @@ HLSDecoder::Pause()
{
MOZ_ASSERT(NS_IsMainThread());
HLS_DEBUG("HLSDecoder", "MediaElement called Pause");
auto resourceWrapper =
static_cast<HLSResource*>(GetResource())->GetResourceWrapper();
auto resourceWrapper = mResource->GetResourceWrapper();
resourceWrapper->Pause();
return MediaDecoder::Pause();
}

View File

@ -7,6 +7,7 @@
#ifndef HLSDecoder_h_
#define HLSDecoder_h_
#include "HLSResource.h"
#include "MediaDecoder.h"
namespace mozilla {
@ -20,6 +21,8 @@ public:
{
}
MediaResource* GetResource() const override final;
void Shutdown() override;
MediaDecoderStateMachine* CreateStateMachine() override;
@ -37,6 +40,9 @@ public:
nsresult Play() override;
void Pause() override;
private:
RefPtr<HLSResource> mResource;
};
} // namespace mozilla

View File

@ -10,6 +10,7 @@
#include "GeneratedJNINatives.h"
#include "GeneratedJNIWrappers.h"
#include "HLSUtils.h"
#include "MediaResource.h"
#include "nsContentUtils.h"
#define UNIMPLEMENTED() HLS_DEBUG("HLSResource", "UNIMPLEMENTED FUNCTION")

View File

@ -34,6 +34,12 @@ MediaSourceDecoder::MediaSourceDecoder(MediaDecoderInit& aInit)
mExplicitDuration.emplace(UnspecifiedNaN<double>());
}
MediaResource*
MediaSourceDecoder::GetResource() const
{
return mResource;
}
MediaDecoderStateMachine*
MediaSourceDecoder::CreateStateMachine()
{
@ -193,7 +199,7 @@ void
MediaSourceDecoder::Ended(bool aEnded)
{
MOZ_ASSERT(NS_IsMainThread());
static_cast<MediaSourceResource*>(mResource.get())->SetEnded(aEnded);
mResource->SetEnded(aEnded);
if (aEnded) {
// We want the MediaSourceReader to refresh its buffered range as it may
// have been modified (end lined up).

View File

@ -18,12 +18,12 @@ class nsIStreamListener;
namespace mozilla {
class MediaResource;
class MediaDecoderStateMachine;
class SourceBufferDecoder;
class TrackBuffer;
enum MSRangeRemovalAction : uint8_t;
class MediaSourceDemuxer;
class MediaSourceResource;
namespace dom {
@ -37,6 +37,8 @@ class MediaSourceDecoder : public MediaDecoder
public:
explicit MediaSourceDecoder(MediaDecoderInit& aInit);
MediaResource* GetResource() const override final;
MediaDecoderStateMachine* CreateStateMachine() override;
nsresult Load(nsIPrincipal* aPrincipal);
media::TimeIntervals GetSeekable() override;
@ -77,6 +79,8 @@ private:
void DoSetMediaSourceDuration(double aDuration);
media::TimeInterval ClampIntervalToEnd(const media::TimeInterval& aInterval);
RefPtr<MediaSourceResource> mResource;
// The owning MediaSource holds a strong reference to this decoder, and
// calls Attach/DetachMediaSource on this decoder to set and clear
// mMediaSource.