Bug 1373595. P1 - merge MediaResourceCallback::NotifyDataArrived and NotifyBytesDownloaded.
We now call NotifyDataArrived() after data written to the cache to notify
download progresses and buffer ranges re-calculation.
MozReview-Commit-ID: 3IrDuEYJYWu
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -195,38 +195,35 @@ MediaDecoder::ResourceCallback::TimerCal
thiz->mDecoder->NotifyDataArrived();
thiz->mTimerArmed = false;
}
void
MediaDecoder::ResourceCallback::NotifyDataArrived()
{
MOZ_ASSERT(NS_IsMainThread());
- if (!mDecoder || mTimerArmed) {
+ if (!mDecoder) {
+ return;
+ }
+
+ mDecoder->NotifyBytesDownloaded();
+
+ if (mTimerArmed) {
return;
}
// In situations where these notifications come from stochastic network
// activity, we can save significant computation by throttling the
// calls to MediaDecoder::NotifyDataArrived() which will update the buffer
// ranges of the reader.
mTimerArmed = true;
mTimer->InitWithFuncCallback(
TimerCallback, this, sDelay, nsITimer::TYPE_ONE_SHOT);
}
void
-MediaDecoder::ResourceCallback::NotifyBytesDownloaded()
-{
- MOZ_ASSERT(NS_IsMainThread());
- if (mDecoder) {
- mDecoder->NotifyBytesDownloaded();
- }
-}
-
-void
MediaDecoder::ResourceCallback::NotifyDataEnded(nsresult aStatus)
{
RefPtr<ResourceCallback> self = this;
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([=] () {
if (!self->mDecoder) {
return;
}
self->mDecoder->NotifyDownloadEnded(aStatus);
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -107,17 +107,16 @@ public:
void Disconnect();
private:
/* MediaResourceCallback functions */
MediaDecoderOwner* GetMediaOwner() const override;
void SetInfinite(bool aInfinite) override;
void NotifyNetworkError() override;
void NotifyDataArrived() override;
- void NotifyBytesDownloaded() override;
void NotifyDataEnded(nsresult aStatus) override;
void NotifyPrincipalChanged() override;
void NotifySuspendedStatusChanged() override;
void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) override;
static void TimerCallback(nsITimer* aTimer, void* aClosure);
// The decoder to send notifications. Main-thread only.
--- a/dom/media/MediaResource.cpp
+++ b/dom/media/MediaResource.cpp
@@ -459,18 +459,16 @@ ChannelMediaResource::OnChannelRedirect(
}
nsresult
ChannelMediaResource::CopySegmentToCache(nsIPrincipal* aPrincipal,
const char* aFromSegment,
uint32_t aCount,
uint32_t* aWriteCount)
{
- mCallback->NotifyDataArrived();
-
// Keep track of where we're up to.
LOG("CopySegmentToCache at mOffset [%" PRId64 "] add "
"[%d] bytes for decoder[%p]",
mOffset, aCount, mCallback.get());
mOffset += aCount;
mCacheStream.NotifyDataReceived(aCount, aFromSegment, aPrincipal);
*aWriteCount = aCount;
return NS_OK;
@@ -871,17 +869,17 @@ ChannelMediaResource::RecreateChannel()
return rv;
}
void
ChannelMediaResource::DoNotifyDataReceived()
{
mDataReceivedEvent.Revoke();
- mCallback->NotifyBytesDownloaded();
+ mCallback->NotifyDataArrived();
}
void
ChannelMediaResource::CacheClientNotifyDataReceived()
{
NS_ASSERTION(NS_IsMainThread(), "Don't call on non-main thread");
// NOTE: this can be called with the media cache lock held, so don't
// block or do anything which might try to acquire a lock!
--- a/dom/media/MediaResourceCallback.h
+++ b/dom/media/MediaResourceCallback.h
@@ -35,19 +35,16 @@ public:
virtual void SetInfinite(bool aInfinite) {}
// Notify that a network error is encountered.
virtual void NotifyNetworkError() {}
// Notify that data arrives on the stream and is read into the cache.
virtual void NotifyDataArrived() {}
- // Notify that MediaResource has received some data.
- virtual void NotifyBytesDownloaded() {}
-
// Notify download is ended.
// NOTE: this can be called with the media cache lock held, so don't
// block or do anything which might try to acquire a lock!
virtual void NotifyDataEnded(nsresult aStatus) {}
// Notify that the principal of MediaResource has changed.
virtual void NotifyPrincipalChanged() {}