Bug 1411504. P2 - merge NotifyDataStarted() and SetTransportSeekable().
SetTransportSeekable() is always called after NotifyDataStarted().
This is slightly more efficient for we don't acquire the lock twice.
MozReview-Commit-ID: 9myolomriIQ
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -285,18 +285,17 @@ ChannelMediaResource::OnStartRequest(nsI
startOffset = 0;
}
// Update principals before OnDataAvailable() putting the data in the cache.
// This is important, we want to make sure all principals are updated before
// any consumer can see the new data.
UpdatePrincipal();
- mCacheStream.NotifyDataStarted(mLoadID, startOffset);
- mCacheStream.SetTransportSeekable(seekable);
+ mCacheStream.NotifyDataStarted(mLoadID, startOffset, seekable);
mChannelStatistics.Start();
mReopenOnError = false;
mSuspendAgent.UpdateSuspendedStatusIfNeeded();
// Fires an initial progress event.
owner->DownloadProgressed();
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -1924,33 +1924,42 @@ MediaCacheStream::NotifyDataLength(int64
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
LOG("Stream %p DataLength: %" PRId64, this, aLength);
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
mStreamLength = aLength;
}
void
-MediaCacheStream::NotifyDataStarted(uint32_t aLoadID, int64_t aOffset)
+MediaCacheStream::NotifyDataStarted(uint32_t aLoadID,
+ int64_t aOffset,
+ bool aSeekable)
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
MOZ_ASSERT(aLoadID > 0);
LOG("Stream %p DataStarted: %" PRId64 " aLoadID=%u", this, aOffset, aLoadID);
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
NS_WARNING_ASSERTION(aOffset == mChannelOffset,
"Server is giving us unexpected offset");
MOZ_ASSERT(aOffset >= 0);
mChannelOffset = aOffset;
if (mStreamLength >= 0) {
// If we started reading at a certain offset, then for sure
// the stream is at least that long.
mStreamLength = std::max(mStreamLength, mChannelOffset);
}
mLoadID = aLoadID;
+
+ MOZ_ASSERT(aOffset == 0 || aSeekable,
+ "channel offset must be zero when we become non-seekable");
+ mIsTransportSeekable = aSeekable;
+ // Queue an Update since we may change our strategy for dealing
+ // with this stream
+ mMediaCache->QueueUpdate();
}
void
MediaCacheStream::UpdatePrincipal(nsIPrincipal* aPrincipal)
{
MOZ_ASSERT(NS_IsMainThread());
MediaCache::ResourceStreamIterator iter(mMediaCache, mResourceID);
while (MediaCacheStream* stream = iter.Next()) {
@@ -2144,28 +2153,16 @@ MediaCacheStream::~MediaCacheStream()
LOG("MediaCacheStream::~MediaCacheStream(this=%p) "
"MEDIACACHESTREAM_LENGTH_KB=%" PRIu32,
this,
lengthKb);
Telemetry::Accumulate(Telemetry::HistogramID::MEDIACACHESTREAM_LENGTH_KB,
lengthKb);
}
-void
-MediaCacheStream::SetTransportSeekable(bool aIsTransportSeekable)
-{
- ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
- NS_ASSERTION(mIsTransportSeekable || aIsTransportSeekable ||
- mChannelOffset == 0, "channel offset must be zero when we become non-seekable");
- mIsTransportSeekable = aIsTransportSeekable;
- // Queue an Update since we may change our strategy for dealing
- // with this stream
- mMediaCache->QueueUpdate();
-}
-
bool
MediaCacheStream::IsTransportSeekable()
{
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
return mIsTransportSeekable;
}
bool
--- a/dom/media/MediaCache.h
+++ b/dom/media/MediaCache.h
@@ -209,23 +209,16 @@ public:
// as the aOriginal stream.
// Exactly one of InitAsClone or Init must be called before any other method
// on this class.
void InitAsClone(MediaCacheStream* aOriginal);
nsIEventTarget* OwnerThread() const;
// These are called on the main thread.
- // Tell us whether the stream is seekable or not. Non-seekable streams
- // will always pass 0 for aOffset to CacheClientSeek. This should only
- // be called while the stream is at channel offset 0. Seekability can
- // change during the lifetime of the MediaCacheStream --- every time
- // we do an HTTP load the seekability may be different (and sometimes
- // is, in practice, due to the effects of caching proxies).
- void SetTransportSeekable(bool aIsTransportSeekable);
// This must be called (and return) before the ChannelMediaResource
// used to create this MediaCacheStream is deleted.
void Close();
// This returns true when the stream has been closed.
// Must be used on the main thread or while holding the cache lock.
bool IsClosed() const { return mClosed; }
// Returns true when this stream is can be shared by a new resource load.
// Called on the main thread only.
@@ -254,17 +247,23 @@ public:
void NotifyDataLength(int64_t aLength);
// Notifies the cache that a load has begun. We pass the offset
// because in some cases the offset might not be what the cache
// requested. In particular we might unexpectedly start providing
// data at offset 0. This need not be called if the offset is the
// offset that the cache requested in
// ChannelMediaResource::CacheClientSeek. This can be called at any
// time by the client, not just after a CacheClientSeek.
- void NotifyDataStarted(uint32_t aLoadID, int64_t aOffset);
+ // aSeekable tells us whether the stream is seekable or not. Non-seekable
+ // streams will always pass 0 for aOffset to CacheClientSeek. This should only
+ // be called while the stream is at channel offset 0. Seekability can
+ // change during the lifetime of the MediaCacheStream --- every time
+ // we do an HTTP load the seekability may be different (and sometimes
+ // is, in practice, due to the effects of caching proxies).
+ void NotifyDataStarted(uint32_t aLoadID, int64_t aOffset, bool aSeekable);
// Notifies the cache that data has been received. The stream already
// knows the offset because data is received in sequence and
// the starting offset is known via NotifyDataStarted or because
// the cache requested the offset in
// ChannelMediaResource::CacheClientSeek, or because it defaulted to 0.
void NotifyDataReceived(uint32_t aLoadID, int64_t aSize, const char* aData);
// Notifies the cache that the current bytes should be written to disk.
// Called on the main thread.