Bug 1108960 - notify all steams for the resource ID when any stream get closed/suspended/resumed. r=roc.

This commit is contained in:
JW Wang 2014-12-18 23:48:00 +01:00
parent 60562b2ff6
commit d67f117ca8
3 changed files with 39 additions and 4 deletions

View File

@ -194,6 +194,10 @@ public:
// This queues a call to Update() on the main thread.
void QueueUpdate();
// Notify all streams for the resource ID that the suspended status changed
// at the end of MediaCache::Update.
void QueueSuspendedStatusUpdate(int64_t aResourceID);
// Updates the cache state asynchronously on the main thread:
// -- try to trim the cache back to its desired size, if necessary
// -- suspend channels that are going to read data that's lower priority
@ -347,6 +351,8 @@ protected:
#ifdef DEBUG
bool mInUpdate;
#endif
// A list of resource IDs to notify about the change in suspended status.
nsTArray<int64_t> mSuspendedStatusToNotify;
};
NS_IMETHODIMP
@ -1351,10 +1357,12 @@ MediaCache::Update()
case RESUME:
CACHE_LOG(PR_LOG_DEBUG, ("Stream %p Resumed", stream));
rv = stream->mClient->CacheClientResume();
QueueSuspendedStatusUpdate(stream->mResourceID);
break;
case SUSPEND:
CACHE_LOG(PR_LOG_DEBUG, ("Stream %p Suspended", stream));
rv = stream->mClient->CacheClientSuspend();
QueueSuspendedStatusUpdate(stream->mResourceID);
break;
default:
rv = NS_OK;
@ -1369,6 +1377,15 @@ MediaCache::Update()
stream->CloseInternal(mon);
}
}
// Notify streams about the suspended status changes.
for (uint32_t i = 0; i < mSuspendedStatusToNotify.Length(); ++i) {
MediaCache::ResourceStreamIterator iter(mSuspendedStatusToNotify[i]);
while (MediaCacheStream* stream = iter.Next()) {
stream->mClient->CacheClientNotifySuspendedStatusChanged();
}
}
mSuspendedStatusToNotify.Clear();
}
class UpdateEvent : public nsRunnable
@ -1399,6 +1416,15 @@ MediaCache::QueueUpdate()
NS_DispatchToMainThread(event);
}
void
MediaCache::QueueSuspendedStatusUpdate(int64_t aResourceID)
{
NS_ASSERTION(NS_IsMainThread(), "Only call on main thread");
if (!mSuspendedStatusToNotify.Contains(aResourceID)) {
mSuspendedStatusToNotify.AppendElement(aResourceID);
}
}
#ifdef DEBUG_VERIFY_CACHE
void
MediaCache::Verify()
@ -1980,6 +2006,10 @@ MediaCacheStream::CloseInternal(ReentrantMonitorAutoEnter& aReentrantMonitor)
if (mClosed)
return;
mClosed = true;
// Closing a stream will change the return value of
// MediaCacheStream::AreAllStreamsForResourceSuspended as well as
// ChannelMediaResource::IsSuspendedByCache. Let's notify it.
gMediaCache->QueueSuspendedStatusUpdate(mResourceID);
gMediaCache->ReleaseStreamBlocks(this);
// Wake up any blocked readers
aReentrantMonitor.NotifyAll();

View File

@ -1009,6 +1009,13 @@ ChannelMediaResource::CacheClientNotifyPrincipalChanged()
mDecoder->NotifyPrincipalChanged();
}
void
ChannelMediaResource::CacheClientNotifySuspendedStatusChanged()
{
NS_ASSERTION(NS_IsMainThread(), "Don't call on non-main thread");
mDecoder->NotifySuspendedStatusChanged();
}
nsresult
ChannelMediaResource::CacheClientSeek(int64_t aOffset, bool aResume)
{
@ -1067,8 +1074,6 @@ nsresult
ChannelMediaResource::CacheClientSuspend()
{
Suspend(false);
mDecoder->NotifySuspendedStatusChanged();
return NS_OK;
}
@ -1076,8 +1081,6 @@ nsresult
ChannelMediaResource::CacheClientResume()
{
Resume();
mDecoder->NotifySuspendedStatusChanged();
return NS_OK;
}

View File

@ -538,6 +538,8 @@ public:
void CacheClientNotifyDataEnded(nsresult aStatus);
// Notify that the principal for the cached resource changed.
void CacheClientNotifyPrincipalChanged();
// Notify the decoder that the cache suspended status changed.
void CacheClientNotifySuspendedStatusChanged();
// 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