Bug 813209 - Refactor MediaResource into BaseMediaResource so that we can base the implementation of BufferMediaSource on top of MediaSource; r=cpearce

This refactoring is needed for the introduction of the BufferMediaResource class.

--HG--
extra : rebase_source : e4b5016e9b947948799f1b8975b23a3dd685a366
This commit is contained in:
Ehsan Akhgari 2012-11-16 20:31:53 -08:00
Родитель 3803556ae5
Коммит 09c0f1a536
2 изменённых файлов: 21 добавлений и 14 удалений

Просмотреть файл

@ -49,7 +49,7 @@ namespace mozilla {
ChannelMediaResource::ChannelMediaResource(MediaDecoder* aDecoder, ChannelMediaResource::ChannelMediaResource(MediaDecoder* aDecoder,
nsIChannel* aChannel, nsIURI* aURI) nsIChannel* aChannel, nsIURI* aURI)
: MediaResource(aDecoder, aChannel, aURI), : BaseMediaResource(aDecoder, aChannel, aURI),
mOffset(0), mSuspendCount(0), mOffset(0), mSuspendCount(0),
mReopenOnError(false), mIgnoreClose(false), mReopenOnError(false), mIgnoreClose(false),
mCacheStream(this), mCacheStream(this),
@ -1153,11 +1153,11 @@ ChannelMediaResource::PossiblyResume()
} }
} }
class FileMediaResource : public MediaResource class FileMediaResource : public BaseMediaResource
{ {
public: public:
FileMediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) : FileMediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) :
MediaResource(aDecoder, aChannel, aURI), BaseMediaResource(aDecoder, aChannel, aURI),
mSize(-1), mSize(-1),
mLock("FileMediaResource.mLock"), mLock("FileMediaResource.mLock"),
mSizeInitialized(false) mSizeInitialized(false)
@ -1514,7 +1514,7 @@ MediaResource::Create(MediaDecoder* aDecoder, nsIChannel* aChannel)
return new ChannelMediaResource(aDecoder, aChannel, uri); return new ChannelMediaResource(aDecoder, aChannel, uri);
} }
void MediaResource::MoveLoadsToBackground() { void BaseMediaResource::MoveLoadsToBackground() {
NS_ASSERTION(!mLoadInBackground, "Why are you calling this more than once?"); NS_ASSERTION(!mLoadInBackground, "Why are you calling this more than once?");
mLoadInBackground = true; mLoadInBackground = true;
if (!mChannel) { if (!mChannel) {
@ -1545,7 +1545,7 @@ void MediaResource::MoveLoadsToBackground() {
} }
} }
void MediaResource::ModifyLoadFlags(nsLoadFlags aFlags) void BaseMediaResource::ModifyLoadFlags(nsLoadFlags aFlags)
{ {
nsCOMPtr<nsILoadGroup> loadGroup; nsCOMPtr<nsILoadGroup> loadGroup;
DebugOnly<nsresult> rv = mChannel->GetLoadGroup(getter_AddRefs(loadGroup)); DebugOnly<nsresult> rv = mChannel->GetLoadGroup(getter_AddRefs(loadGroup));

Просмотреть файл

@ -146,14 +146,11 @@ public:
class MediaResource class MediaResource
{ {
public: public:
virtual ~MediaResource() virtual ~MediaResource() {}
{
MOZ_COUNT_DTOR(MediaResource);
}
// The following can be called on the main thread only: // The following can be called on the main thread only:
// Get the URI // Get the URI
nsIURI* URI() const { return mURI; } virtual nsIURI* URI() const { return nullptr; }
// Close the resource, stop any listeners, channels, etc. // Close the resource, stop any listeners, channels, etc.
// Cancels any currently blocking Read request and forces that request to // Cancels any currently blocking Read request and forces that request to
// return an error. // return an error.
@ -227,7 +224,7 @@ public:
// Moves any existing channel loads into the background, so that they don't // Moves any existing channel loads into the background, so that they don't
// block the load event. Any new loads initiated (for example to seek) // block the load event. Any new loads initiated (for example to seek)
// will also be in the background. // will also be in the background.
void MoveLoadsToBackground(); virtual void MoveLoadsToBackground() {}
// Ensures that the value returned by IsSuspendedByCache below is up to date // Ensures that the value returned by IsSuspendedByCache below is up to date
// (i.e. the cache has examined this stream at least once). // (i.e. the cache has examined this stream at least once).
virtual void EnsureCacheUpToDate() {} virtual void EnsureCacheUpToDate() {}
@ -307,15 +304,25 @@ public:
* aRanges is being used. * aRanges is being used.
*/ */
virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges) = 0; virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges) = 0;
};
class BaseMediaResource : public MediaResource {
public:
virtual nsIURI* URI() const { return mURI; }
virtual void MoveLoadsToBackground();
protected: protected:
MediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) : BaseMediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) :
mDecoder(aDecoder), mDecoder(aDecoder),
mChannel(aChannel), mChannel(aChannel),
mURI(aURI), mURI(aURI),
mLoadInBackground(false) mLoadInBackground(false)
{ {
MOZ_COUNT_CTOR(MediaResource); MOZ_COUNT_CTOR(BaseMediaResource);
}
virtual ~BaseMediaResource()
{
MOZ_COUNT_DTOR(BaseMediaResource);
} }
// Set the request's load flags to aFlags. If the request is part of a // Set the request's load flags to aFlags. If the request is part of a
@ -349,7 +356,7 @@ protected:
* All synchronization is performed by MediaCacheStream; all off-main- * All synchronization is performed by MediaCacheStream; all off-main-
* thread operations are delegated directly to that object. * thread operations are delegated directly to that object.
*/ */
class ChannelMediaResource : public MediaResource class ChannelMediaResource : public BaseMediaResource
{ {
public: public:
ChannelMediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI); ChannelMediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI);