Bug 1411504. P4 - handle CacheClientResume/CacheClientSuspend off the main thread.
MozReview-Commit-ID: GRbcNo7KtKH
--- a/dom/media/ChannelMediaResource.cpp
+++ b/dom/media/ChannelMediaResource.cpp
@@ -888,28 +888,31 @@ ChannelMediaResource::CacheClientSeek(in
// client Read and Seek operations on those streams to fail. Blocked
// Reads will also be woken up.
self->Close();
}
});
mCallback->AbstractMainThread()->Dispatch(r.forget());
}
-nsresult
+void
ChannelMediaResource::CacheClientSuspend()
{
- Suspend(false);
- return NS_OK;
+ mCallback->AbstractMainThread()->Dispatch(
+ NewRunnableMethod<bool>("ChannelMediaResource::Suspend",
+ this,
+ &ChannelMediaResource::Suspend,
+ false));
}
-nsresult
+void
ChannelMediaResource::CacheClientResume()
{
- Resume();
- return NS_OK;
+ mCallback->AbstractMainThread()->Dispatch(NewRunnableMethod(
+ "ChannelMediaResource::Resume", this, &ChannelMediaResource::Resume));
}
int64_t
ChannelMediaResource::GetNextCachedData(int64_t aOffset)
{
return mCacheStream.GetNextCachedData(aOffset);
}
--- a/dom/media/ChannelMediaResource.h
+++ b/dom/media/ChannelMediaResource.h
@@ -98,19 +98,19 @@ public:
// These are called on the main thread by MediaCache. These shouldn't block,
// but they may grab locks --- the media cache is not holding its lock
// when these are called.
// Start a new load at the given aOffset. The old load is cancelled
// and no more data from the old load will be notified via
// MediaCacheStream::NotifyDataReceived/Ended.
void CacheClientSeek(int64_t aOffset, bool aResume);
// Suspend the current load since data is currently not wanted
- nsresult CacheClientSuspend();
+ void CacheClientSuspend();
// Resume the current load since data is wanted again
- nsresult CacheClientResume();
+ void CacheClientResume();
bool IsSuspended();
void ThrottleReadahead(bool bThrottle) override;
// Main thread
nsresult Open(nsIStreamListener** aStreamListener) override;
nsresult Close() override;
--- a/dom/media/MediaCache.cpp
+++ b/dom/media/MediaCache.cpp
@@ -1492,47 +1492,38 @@ MediaCache::Update()
break;
default:
break;
}
}
for (uint32_t i = 0; i < mStreams.Length(); ++i) {
MediaCacheStream* stream = mStreams[i];
- nsresult rv = NS_OK;
switch (actions[i].mTag) {
case StreamAction::SEEK:
LOG("Stream %p CacheSeek to %" PRId64 " (resume=%d)",
stream,
actions[i].mSeekTarget,
actions[i].mResume);
stream->mClient->CacheClientSeek(actions[i].mSeekTarget,
actions[i].mResume);
break;
case StreamAction::RESUME:
LOG("Stream %p Resumed", stream);
- rv = stream->mClient->CacheClientResume();
+ stream->mClient->CacheClientResume();
QueueSuspendedStatusUpdate(stream->mResourceID);
break;
case StreamAction::SUSPEND:
LOG("Stream %p Suspended", stream);
- rv = stream->mClient->CacheClientSuspend();
+ stream->mClient->CacheClientSuspend();
QueueSuspendedStatusUpdate(stream->mResourceID);
break;
default:
- rv = NS_OK;
break;
}
-
- if (NS_FAILED(rv)) {
- // Close the streams that failed due to error. This will cause all
- // client Read and Seek operations on those streams to fail. Blocked
- // Reads will also be woken up.
- stream->mClient->Close();
- }
}
// Notify streams about the suspended status changes.
for (uint32_t i = 0; i < mSuspendedStatusToNotify.Length(); ++i) {
MediaCache::ResourceStreamIterator iter(this, mSuspendedStatusToNotify[i]);
while (MediaCacheStream* stream = iter.Next()) {
stream->mClient->CacheClientNotifySuspendedStatusChanged();
}