Bug 1418213 - always run MediaCacheStream::NotifyDataReceived() off the main thread. r=bechen,gerald

MozReview-Commit-ID: GBQ0lEf8rVI

--HG--
extra : rebase_source : cbcd69dd220c06e2e1cc0d12e33d23ce2f4e21ef
extra : intermediate-source : 9e304fc5f5ee0b4d44f0e54a4cb2a6a9fe90979d
extra : source : 1b29a7cde3c40ba3a35ee19eee63ad68e6d12176
This commit is contained in:
JW Wang 2017-11-15 17:56:10 +08:00
parent 0a20585745
commit c5401dfc03
2 changed files with 19 additions and 7 deletions

View File

@ -303,7 +303,6 @@ ChannelMediaResource::OnStartRequest(nsIRequest* aRequest,
// Fires an initial progress event.
owner->DownloadProgressed();
// TODO: Don't turn this on until we fix all data races.
nsCOMPtr<nsIThreadRetargetableRequest> retarget;
if (Preferences::GetBool("media.omt_data_delivery.enabled", false) &&
(retarget = do_QueryInterface(aRequest))) {
@ -417,12 +416,25 @@ ChannelMediaResource::CopySegmentToCache(nsIInputStream* aInStream,
uint32_t aCount,
uint32_t* aWriteCount)
{
Closure* closure = static_cast<Closure*>(aClosure);
closure->mResource->mCacheStream.NotifyDataReceived(
closure->mLoadID,
aCount,
reinterpret_cast<const uint8_t*>(aFromSegment));
*aWriteCount = aCount;
Closure* closure = static_cast<Closure*>(aClosure);
MediaCacheStream* cacheStream = &closure->mResource->mCacheStream;
if (cacheStream->OwnerThread()->IsOnCurrentThread()) {
cacheStream->NotifyDataReceived(
closure->mLoadID, aCount, reinterpret_cast<const uint8_t*>(aFromSegment));
return NS_OK;
}
RefPtr<ChannelMediaResource> self = closure->mResource;
uint32_t loadID = closure->mLoadID;
UniquePtr<uint8_t[]> data = MakeUnique<uint8_t[]>(aCount);
memcpy(data.get(), aFromSegment, aCount);
cacheStream->OwnerThread()->Dispatch(NS_NewRunnableFunction(
"MediaCacheStream::NotifyDataReceived",
[ self, loadID, data = Move(data), aCount ]() {
self->mCacheStream.NotifyDataReceived(loadID, aCount, data.get());
}));
return NS_OK;
}

View File

@ -2006,8 +2006,8 @@ MediaCacheStream::NotifyDataReceived(uint32_t aLoadID,
uint32_t aCount,
const uint8_t* aData)
{
MOZ_ASSERT(OwnerThread()->IsOnCurrentThread());
MOZ_ASSERT(aLoadID > 0);
// This might happen off the main thread.
ReentrantMonitorAutoEnter mon(mMediaCache->GetReentrantMonitor());
if (mClosed) {