--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -68,29 +68,49 @@ MediaResource::Destroy()
NewNonOwningRunnableMethod(this, &MediaResource::Destroy));
MOZ_ALWAYS_SUCCEEDS(rv);
}
NS_IMPL_ADDREF(MediaResource)
NS_IMPL_RELEASE_WITH_DESTROY(MediaResource, Destroy())
NS_IMPL_QUERY_INTERFACE0(MediaResource)
-ChannelMediaResource::ChannelMediaResource(MediaResourceCallback* aCallback,
- nsIChannel* aChannel,
- nsIURI* aURI,
- const MediaContainerType& aContainerType,
- bool aIsPrivateBrowsing)
- : BaseMediaResource(aCallback, aChannel, aURI, aContainerType),
- mOffset(0),
- mReopenOnError(false),
- mIgnoreClose(false),
- mCacheStream(this, aIsPrivateBrowsing),
- mLock("ChannelMediaResource.mLock"),
- mIgnoreResume(false),
- mSuspendAgent(mChannel)
+ChannelMediaResource::ChannelMediaResource(
+ MediaResourceCallback* aCallback,
+ nsIChannel* aChannel,
+ nsIURI* aURI,
+ const MediaContainerType& aContainerType,
+ bool aIsPrivateBrowsing)
+ : BaseMediaResource(aCallback, aChannel, aURI, aContainerType)
+ , mOffset(0)
+ , mReopenOnError(false)
+ , mIgnoreClose(false)
+ , mCacheStream(this, aIsPrivateBrowsing)
+ , mLock("ChannelMediaResource.mLock")
+ , mChannelStatistics(new MediaChannelStatistics())
+ , mIgnoreResume(false)
+ , mSuspendAgent(mChannel)
+{
+}
+
+ChannelMediaResource::ChannelMediaResource(
+ MediaResourceCallback* aCallback,
+ nsIChannel* aChannel,
+ nsIURI* aURI,
+ const MediaContainerType& aContainerType,
+ MediaChannelStatistics* aStatistics)
+ : BaseMediaResource(aCallback, aChannel, aURI, aContainerType)
+ , mOffset(0)
+ , mReopenOnError(false)
+ , mIgnoreClose(false)
+ , mCacheStream(this, /* aIsPrivateBrowsing = */ false)
+ , mLock("ChannelMediaResource.mLock")
+ , mChannelStatistics(new MediaChannelStatistics(aStatistics))
+ , mIgnoreResume(false)
+ , mSuspendAgent(mChannel)
{
}
ChannelMediaResource::~ChannelMediaResource()
{
if (mListener) {
// Kill its reference to us since we're going away
mListener->Revoke();
@@ -503,20 +523,16 @@ ChannelMediaResource::OnDataAvailable(ns
return NS_OK;
}
nsresult ChannelMediaResource::Open(nsIStreamListener **aStreamListener)
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
- if (!mChannelStatistics) {
- mChannelStatistics = new MediaChannelStatistics();
- }
-
nsresult rv = mCacheStream.Init();
if (NS_FAILED(rv))
return rv;
NS_ASSERTION(mOffset == 0, "Who set mOffset already?");
if (!mChannel) {
// When we're a clone, the decoder might ask us to Open even though
// we haven't established an mChannel (because we might not need one)
@@ -625,31 +641,27 @@ bool ChannelMediaResource::CanClone()
return mCacheStream.IsAvailableForSharing();
}
already_AddRefed<MediaResource> ChannelMediaResource::CloneData(MediaResourceCallback* aCallback)
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
NS_ASSERTION(mCacheStream.IsAvailableForSharing(), "Stream can't be cloned");
- RefPtr<ChannelMediaResource> resource =
- new ChannelMediaResource(aCallback,
- nullptr,
- mURI,
- GetContentType());
+ RefPtr<ChannelMediaResource> resource = new ChannelMediaResource(
+ aCallback, nullptr, mURI, GetContentType(), mChannelStatistics);
if (resource) {
// Initially the clone is treated as suspended by the cache, because
// we don't have a channel. If the cache needs to read data from the clone
// it will call CacheClientResume (or CacheClientSeek with aResume true)
// which will recreate the channel. This way, if all of the media data
// is already in the cache we don't create an unnecessary HTTP channel
// and perform a useless HTTP transaction.
resource->mSuspendAgent.Suspend();
resource->mCacheStream.InitAsClone(&mCacheStream);
- resource->mChannelStatistics = new MediaChannelStatistics(mChannelStatistics);
resource->mChannelStatistics->Stop();
}
return resource.forget();
}
void ChannelMediaResource::CloseChannel()
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -525,17 +525,22 @@ private:
*/
class ChannelMediaResource : public BaseMediaResource
{
public:
ChannelMediaResource(MediaResourceCallback* aDecoder,
nsIChannel* aChannel,
nsIURI* aURI,
const MediaContainerType& aContainerType,
- bool aIsPrivateBrowsing = false);
+ bool aIsPrivateBrowsing);
+ ChannelMediaResource(MediaResourceCallback* aDecoder,
+ nsIChannel* aChannel,
+ nsIURI* aURI,
+ const MediaContainerType& aContainerType,
+ MediaChannelStatistics* aStatistics);
~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
// if this stream didn't read any data, since another stream might have
// received data for the same resource.
void CacheClientNotifyDataReceived();