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.
--- a/content/media/MediaResource.cpp
+++ b/content/media/MediaResource.cpp
@@ -44,17 +44,17 @@ PRLogModuleInfo* gMediaResourceLog;
static const uint32_t HTTP_OK_CODE = 200;
static const uint32_t HTTP_PARTIAL_RESPONSE_CODE = 206;
namespace mozilla {
ChannelMediaResource::ChannelMediaResource(MediaDecoder* aDecoder,
nsIChannel* aChannel, nsIURI* aURI)
- : MediaResource(aDecoder, aChannel, aURI),
+ : BaseMediaResource(aDecoder, aChannel, aURI),
mOffset(0), mSuspendCount(0),
mReopenOnError(false), mIgnoreClose(false),
mCacheStream(this),
mLock("ChannelMediaResource.mLock"),
mIgnoreResume(false),
mSeekingForMetadata(false),
mByteRangeDownloads(false),
mByteRangeFirstOpen(true),
@@ -1148,21 +1148,21 @@ ChannelMediaResource::PossiblyResume()
{
if (!mIgnoreResume) {
mChannel->Resume();
} else {
mIgnoreResume = false;
}
}
-class FileMediaResource : public MediaResource
+class FileMediaResource : public BaseMediaResource
{
public:
FileMediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) :
- MediaResource(aDecoder, aChannel, aURI),
+ BaseMediaResource(aDecoder, aChannel, aURI),
mSize(-1),
mLock("FileMediaResource.mLock"),
mSizeInitialized(false)
{
}
~FileMediaResource()
{
}
@@ -1509,17 +1509,17 @@ MediaResource::Create(MediaDecoder* aDec
nsCOMPtr<nsIFileChannel> fc = do_QueryInterface(aChannel);
if (fc || IsBlobURI(uri)) {
return new FileMediaResource(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?");
mLoadInBackground = true;
if (!mChannel) {
// No channel, resource is probably already loaded.
return;
}
MediaDecoderOwner* owner = mDecoder->GetMediaOwner();
@@ -1540,17 +1540,17 @@ void MediaResource::MoveLoadsToBackgroun
DebugOnly<nsresult> rv = mChannel->GetLoadFlags(&loadFlags);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetLoadFlags() failed!");
loadFlags |= nsIRequest::LOAD_BACKGROUND;
ModifyLoadFlags(loadFlags);
}
}
-void MediaResource::ModifyLoadFlags(nsLoadFlags aFlags)
+void BaseMediaResource::ModifyLoadFlags(nsLoadFlags aFlags)
{
nsCOMPtr<nsILoadGroup> loadGroup;
DebugOnly<nsresult> rv = mChannel->GetLoadGroup(getter_AddRefs(loadGroup));
NS_ASSERTION(NS_SUCCEEDED(rv), "GetLoadGroup() failed!");
nsresult status;
mChannel->GetStatus(&status);
--- a/content/media/MediaResource.h
+++ b/content/media/MediaResource.h
@@ -141,24 +141,21 @@ public:
* handle any URI for which Necko supports AsyncOpen.
* The 'file:' protocol can be implemented efficiently with direct random
* access, so the FileMediaResource implementation class bypasses the cache.
* MediaResource::Create automatically chooses the best implementation class.
*/
class MediaResource
{
public:
- virtual ~MediaResource()
- {
- MOZ_COUNT_DTOR(MediaResource);
- }
+ virtual ~MediaResource() {}
// The following can be called on the main thread only:
// Get the URI
- nsIURI* URI() const { return mURI; }
+ virtual nsIURI* URI() const { return nullptr; }
// Close the resource, stop any listeners, channels, etc.
// Cancels any currently blocking Read request and forces that request to
// return an error.
virtual nsresult Close() = 0;
// Suspend any downloads that are in progress.
// If aCloseImmediately is set, resources should be released immediately
// since we don't expect to resume again any time soon. Otherwise we
// may resume again soon so resources should be held for a little
@@ -222,17 +219,17 @@ public:
virtual nsresult Seek(int32_t aWhence, int64_t aOffset) = 0;
virtual void StartSeekingForMetadata() = 0;
virtual void EndSeekingForMetadata() = 0;
// Report the current offset in bytes from the start of the stream.
virtual int64_t Tell() = 0;
// 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)
// will also be in the background.
- void MoveLoadsToBackground();
+ virtual void MoveLoadsToBackground() {}
// Ensures that the value returned by IsSuspendedByCache below is up to date
// (i.e. the cache has examined this stream at least once).
virtual void EnsureCacheUpToDate() {}
// These can be called on any thread.
// Cached blocks associated with this stream will not be evicted
// while the stream is pinned.
virtual void Pin() = 0;
@@ -302,25 +299,35 @@ public:
}
/**
* Fills aRanges with MediaByteRanges representing the data which is cached
* in the media cache. Stream should be pinned during call and while
* aRanges is being used.
*/
virtual nsresult GetCachedRanges(nsTArray<MediaByteRange>& aRanges) = 0;
+};
+
+class BaseMediaResource : public MediaResource {
+public:
+ virtual nsIURI* URI() const { return mURI; }
+ virtual void MoveLoadsToBackground();
protected:
- MediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) :
+ BaseMediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI) :
mDecoder(aDecoder),
mChannel(aChannel),
mURI(aURI),
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
// load group, the request is removed from the group, the flags are set, and
// then the request is added back to the load group.
void ModifyLoadFlags(nsLoadFlags aFlags);
// This is not an nsCOMPointer to prevent a circular reference
@@ -344,17 +351,17 @@ protected:
/**
* This is the MediaResource implementation that wraps Necko channels.
* Much of its functionality is actually delegated to MediaCache via
* an underlying MediaCacheStream.
*
* All synchronization is performed by MediaCacheStream; all off-main-
* thread operations are delegated directly to that object.
*/
-class ChannelMediaResource : public MediaResource
+class ChannelMediaResource : public BaseMediaResource
{
public:
ChannelMediaResource(MediaDecoder* aDecoder, nsIChannel* aChannel, nsIURI* aURI);
~ChannelMediaResource();
// These are called on the main thread by MediaCache. These must
// not block or grab locks, because the media cache is holding its lock.
// Notify that data is available from the cache. This can happen even