Bug 1426578. P4 - offload InitAsClone() to another thread. r=bechen,gerald

MozReview-Commit-ID: H8bQRmkJ8jU

--HG--
extra : rebase_source : a6fd3ec4d48974a36c0eec24503d10258ed5f5d4
extra : source : 2ffac43de24706551d3e183072d4e53c137ecb5f
This commit is contained in:
JW Wang 2017-12-19 17:32:55 +08:00
Родитель e43ca27ba0
Коммит ea7483e4ce
2 изменённых файлов: 17 добавлений и 2 удалений

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

@ -1804,8 +1804,6 @@ MediaCache::OpenStream(AutoLock& aLock,
MediaCacheStream* aStream,
bool aIsClone)
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
LOG("Stream %p opened", aStream);
mStreams.AppendElement(aStream);
@ -2890,6 +2888,19 @@ MediaCacheStream::InitAsClone(MediaCacheStream* aOriginal)
mCacheSuspended = true;
mChannelEnded = true;
OwnerThread()->Dispatch(
NS_NewRunnableFunction("MediaCacheStream::InitAsClone", [
this,
aOriginal,
r1 = RefPtr<ChannelMediaResource>(mClient),
r2 = RefPtr<ChannelMediaResource>(aOriginal->mClient)
]() { InitAsCloneInternal(aOriginal); }));
}
void
MediaCacheStream::InitAsCloneInternal(MediaCacheStream* aOriginal)
{
MOZ_ASSERT(OwnerThread()->IsOnCurrentThread());
AutoLock lock(aOriginal->mMediaCache->Monitor());
mResourceID = aOriginal->mResourceID;
@ -2927,6 +2938,9 @@ MediaCacheStream::InitAsClone(MediaCacheStream* aOriginal)
BLOCK_SIZE);
mMediaCache->OpenStream(lock, this, true /* aIsClone */);
// Wake up the reader which is waiting for the cloned data.
lock.NotifyAll();
}
nsIEventTarget*

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

@ -466,6 +466,7 @@ private:
void UpdateDownloadStatistics(AutoLock&);
void CloseInternal(AutoLock&);
void InitAsCloneInternal(MediaCacheStream* aOriginal);
// Instance of MediaCache to use with this MediaCacheStream.
RefPtr<MediaCache> mMediaCache;