Bug 1367705. P3 - fix MediaChannelStatistics which no longer needs to be sharable.
MozReview-Commit-ID: 8guyyGquFnV
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -377,17 +377,16 @@ MediaDecoder::MediaDecoder(MediaDecoderO
, mResourceCallback(new ResourceCallback(aOwner->AbstractMainThread()))
, mCDMProxyPromise(mCDMProxyPromiseHolder.Ensure(__func__))
, mIgnoreProgressData(false)
, mInfiniteStream(false)
, mOwner(aOwner)
, mAbstractMainThread(aOwner->AbstractMainThread())
, mFrameStats(new FrameStatistics())
, mVideoFrameContainer(aOwner->GetVideoFrameContainer())
- , mPlaybackStatistics(new MediaChannelStatistics())
, mPinnedForSeek(false)
, mMinimizePreroll(false)
, mFiredMetadataLoaded(false)
, mIsDocumentVisible(false)
, mElementVisibility(Visibility::UNTRACKED)
, mIsElementInTree(false)
, mForcedHidden(false)
, mHasSuspendTaint(false)
@@ -535,20 +534,20 @@ MediaDecoder::~MediaDecoder()
UnpinForSeek();
}
void
MediaDecoder::OnPlaybackEvent(MediaEventType aEvent)
{
switch (aEvent) {
case MediaEventType::PlaybackStarted:
- mPlaybackStatistics->Start();
+ mPlaybackStatistics.Start();
break;
case MediaEventType::PlaybackStopped:
- mPlaybackStatistics->Stop();
+ mPlaybackStatistics.Stop();
ComputePlaybackRate();
break;
case MediaEventType::PlaybackEnded:
PlaybackEnded();
break;
case MediaEventType::SeekStarted:
SeekingStarted();
break;
@@ -1011,17 +1010,17 @@ MediaDecoder::ComputePlaybackRate()
&& mDuration > 0
&& length >= 0) {
mPlaybackRateReliable = true;
mPlaybackBytesPerSecond = length / mDuration;
return;
}
bool reliable = false;
- mPlaybackBytesPerSecond = mPlaybackStatistics->GetRateAtLastStop(&reliable);
+ mPlaybackBytesPerSecond = mPlaybackStatistics.GetRateAtLastStop(&reliable);
mPlaybackRateReliable = reliable;
}
void
MediaDecoder::UpdatePlaybackRate()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mResource);
@@ -1128,17 +1127,17 @@ MediaDecoder::NotifyBytesConsumed(int64_
MOZ_DIAGNOSTIC_ASSERT(!IsShutdown());
if (mIgnoreProgressData) {
return;
}
MOZ_ASSERT(mDecoderStateMachine);
if (aOffset >= mDecoderPosition) {
- mPlaybackStatistics->AddBytes(aBytes);
+ mPlaybackStatistics.AddBytes(aBytes);
}
mDecoderPosition = aOffset + aBytes;
}
void
MediaDecoder::OnSeekResolved()
{
MOZ_ASSERT(NS_IsMainThread());
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -655,17 +655,17 @@ protected:
// Counters related to decode and presentation of frames.
const RefPtr<FrameStatistics> mFrameStats;
RefPtr<VideoFrameContainer> mVideoFrameContainer;
// Data needed to estimate playback data rate. The timeline used for
// this estimate is "decode time" (where the "current time" is the
// time of the last decoded video frame).
- RefPtr<MediaChannelStatistics> mPlaybackStatistics;
+ MediaChannelStatistics mPlaybackStatistics;
// True when our media stream has been pinned. We pin the stream
// while seeking.
bool mPinnedForSeek;
// Be assigned from media element during the initialization and pass to
// AudioStream Class.
dom::AudioChannel mAudioChannel;
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -80,35 +80,34 @@ ChannelMediaResource::ChannelMediaResour
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)
+ const MediaChannelStatistics& aStatistics)
: BaseMediaResource(aCallback, aChannel, aURI, aContainerType)
, mOffset(0)
, mReopenOnError(false)
, mIgnoreClose(false)
, mCacheStream(this, /* aIsPrivateBrowsing = */ false)
, mLock("ChannelMediaResource.mLock")
- , mChannelStatistics(new MediaChannelStatistics(aStatistics))
+ , mChannelStatistics(aStatistics)
, mIgnoreResume(false)
, mSuspendAgent(mChannel)
{
}
ChannelMediaResource::~ChannelMediaResource()
{
if (mListener) {
@@ -324,17 +323,17 @@ ChannelMediaResource::OnStartRequest(nsI
}
mCallback->SetInfinite(!dataIsBounded);
}
mCacheStream.SetTransportSeekable(seekable);
{
MutexAutoLock lock(mLock);
- mChannelStatistics->Start();
+ mChannelStatistics.Start();
}
mReopenOnError = false;
mIgnoreClose = false;
mSuspendAgent.UpdateSuspendedStatusIfNeeded();
// Fires an initial progress event.
@@ -400,17 +399,17 @@ nsresult
ChannelMediaResource::OnStopRequest(nsIRequest* aRequest, nsresult aStatus)
{
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
NS_ASSERTION(!mSuspendAgent.IsSuspended(),
"How can OnStopRequest fire while we're suspended?");
{
MutexAutoLock lock(mLock);
- mChannelStatistics->Stop();
+ mChannelStatistics.Stop();
}
// Note that aStatus might have succeeded --- this might be a normal close
// --- even in situations where the server cut us off because we were
// suspended. So we need to "reopen on error" in that case too. The only
// cases where we don't need to reopen are when *we* closed the stream.
// But don't reopen if we need to seek and we don't think we can... that would
// cause us to just re-read the stream, which would be really bad.
@@ -495,17 +494,17 @@ nsresult
ChannelMediaResource::OnDataAvailable(nsIRequest* aRequest,
nsIInputStream* aStream,
uint32_t aCount)
{
NS_ASSERTION(mChannel.get() == aRequest, "Wrong channel!");
{
MutexAutoLock lock(mLock);
- mChannelStatistics->AddBytes(aCount);
+ mChannelStatistics.AddBytes(aCount);
}
CopySegmentClosure closure;
nsIScriptSecurityManager* secMan = nsContentUtils::GetSecurityManager();
if (secMan && mChannel) {
secMan->GetChannelResultPrincipal(mChannel, getter_AddRefs(closure.mPrincipal));
}
closure.mResource = this;
@@ -652,28 +651,28 @@ already_AddRefed<MediaResource> ChannelM
// 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->Stop();
+ resource->mChannelStatistics.Stop();
}
return resource.forget();
}
void ChannelMediaResource::CloseChannel()
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
{
MutexAutoLock lock(mLock);
- mChannelStatistics->Stop();
+ mChannelStatistics.Stop();
}
if (mListener) {
mListener->Revoke();
mListener = nullptr;
}
if (mChannel) {
@@ -773,17 +772,17 @@ void ChannelMediaResource::Suspend(bool
CloseChannel();
element->DownloadSuspended();
}
if (mSuspendAgent.Suspend()) {
if (mChannel) {
{
MutexAutoLock lock(mLock);
- mChannelStatistics->Stop();
+ mChannelStatistics.Stop();
}
element->DownloadSuspended();
}
}
}
void ChannelMediaResource::Resume()
{
@@ -800,17 +799,17 @@ void ChannelMediaResource::Resume()
return;
}
if (mSuspendAgent.Resume()) {
if (mChannel) {
// Just wake up our existing channel
{
MutexAutoLock lock(mLock);
- mChannelStatistics->Start();
+ mChannelStatistics.Start();
}
// if an error occurs after Resume, assume it's because the server
// timed out the connection and we should reopen it.
mReopenOnError = true;
element->DownloadResumed();
} else {
int64_t totalLength = mCacheStream.GetLength();
// If mOffset is at the end of the stream, then we shouldn't try to
@@ -1056,17 +1055,17 @@ ChannelMediaResource::Unpin()
{
mCacheStream.Unpin();
}
double
ChannelMediaResource::GetDownloadRate(bool* aIsReliable)
{
MutexAutoLock lock(mLock);
- return mChannelStatistics->GetRate(aIsReliable);
+ return mChannelStatistics.GetRate(aIsReliable);
}
int64_t
ChannelMediaResource::GetLength()
{
return mCacheStream.GetLength();
}
--- a/dom/media/MediaResource.h
+++ b/dom/media/MediaResource.h
@@ -60,33 +60,19 @@ class MediaChannelStatistics;
* kind of average of the data passing through over the time the
* channel is active.
*
* All methods take "now" as a parameter so the user of this class can
* control the timeline used.
*/
class MediaChannelStatistics {
public:
- MediaChannelStatistics()
- : mAccumulatedBytes(0)
- , mIsStarted(false)
- {
- Reset();
- }
+ MediaChannelStatistics() = default;
- explicit MediaChannelStatistics(MediaChannelStatistics * aCopyFrom)
- {
- MOZ_ASSERT(aCopyFrom);
- mAccumulatedBytes = aCopyFrom->mAccumulatedBytes;
- mAccumulatedTime = aCopyFrom->mAccumulatedTime;
- mLastStartTime = aCopyFrom->mLastStartTime;
- mIsStarted = aCopyFrom->mIsStarted;
- }
-
- NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaChannelStatistics)
+ MediaChannelStatistics(const MediaChannelStatistics&) = default;
void Reset() {
mLastStartTime = TimeStamp();
mAccumulatedTime = TimeDuration(0);
mAccumulatedBytes = 0;
mIsStarted = false;
}
void Start() {
@@ -125,21 +111,20 @@ public:
double seconds = time.ToSeconds();
*aReliable = (seconds >= 3.0) ||
(mAccumulatedBytes >= RELIABLE_DATA_THRESHOLD);
if (seconds <= 0.0)
return 0.0;
return static_cast<double>(mAccumulatedBytes)/seconds;
}
private:
- ~MediaChannelStatistics() {}
- int64_t mAccumulatedBytes;
+ int64_t mAccumulatedBytes = 0;
TimeDuration mAccumulatedTime;
- TimeStamp mLastStartTime;
- bool mIsStarted;
+ TimeStamp mLastStartTime;
+ bool mIsStarted = false;
};
// Represents a section of contiguous media, with a start and end offset.
// Used to denote ranges of data which are cached.
typedef media::Interval<int64_t> MediaByteRange;
typedef media::IntervalSet<int64_t> MediaByteRangeSet;
@@ -530,17 +515,17 @@ public:
nsIChannel* aChannel,
nsIURI* aURI,
const MediaContainerType& aContainerType,
bool aIsPrivateBrowsing);
ChannelMediaResource(MediaResourceCallback* aDecoder,
nsIChannel* aChannel,
nsIURI* aURI,
const MediaContainerType& aContainerType,
- MediaChannelStatistics* aStatistics);
+ const 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();
@@ -699,17 +684,17 @@ protected:
// channel.
bool mIgnoreClose;
// Any thread access
MediaCacheStream mCacheStream;
// This lock protects mChannelStatistics
Mutex mLock;
- RefPtr<MediaChannelStatistics> mChannelStatistics;
+ MediaChannelStatistics mChannelStatistics;
// True if we couldn't suspend the stream and we therefore don't want
// to resume later. This is usually due to the channel not being in the
// isPending state at the time of the suspend request.
bool mIgnoreResume;
ChannelSuspendAgent mSuspendAgent;
};