From 119321d8c21e16b2855268a66af347b8545417f1 Mon Sep 17 00:00:00 2001 From: Jean-Yves Avenard Date: Thu, 6 Nov 2014 19:08:04 +1100 Subject: [PATCH] Bug 1092996 - MSE/WebM: limit size read to what is available. r=kinetik --- dom/media/AbstractMediaDecoder.h | 4 ++++ dom/media/mediasource/SourceBufferDecoder.cpp | 6 ++++++ dom/media/mediasource/SourceBufferDecoder.h | 1 + dom/media/webm/WebMReader.cpp | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dom/media/AbstractMediaDecoder.h b/dom/media/AbstractMediaDecoder.h index 01e198974785..8b158ffe7ab5 100644 --- a/dom/media/AbstractMediaDecoder.h +++ b/dom/media/AbstractMediaDecoder.h @@ -127,6 +127,10 @@ public: // Called from HTMLMediaElement when owner document activity changes virtual void SetElementVisibility(bool aIsVisible) {} + // Called by some MediaDecoderReader to determine if we can rely + // on the resource length to limit reads. + virtual bool HasInitializationData() { return false; } + // Stack based class to assist in notifying the frame statistics of // parsed and decoded frames. Use inside video demux & decode functions // to ensure all parsed and decoded frames are reported on all return paths. diff --git a/dom/media/mediasource/SourceBufferDecoder.cpp b/dom/media/mediasource/SourceBufferDecoder.cpp index 24cb642c856a..c284736c766c 100644 --- a/dom/media/mediasource/SourceBufferDecoder.cpp +++ b/dom/media/mediasource/SourceBufferDecoder.cpp @@ -119,6 +119,12 @@ SourceBufferDecoder::UpdatePlaybackPosition(int64_t aTime) MSE_DEBUG("SourceBufferDecoder(%p)::UpdatePlaybackPosition UNIMPLEMENTED", this); } +bool +SourceBufferDecoder::HasInitializationData() +{ + return true; +} + void SourceBufferDecoder::OnReadMetadataCompleted() { diff --git a/dom/media/mediasource/SourceBufferDecoder.h b/dom/media/mediasource/SourceBufferDecoder.h index fb272162be9a..e186c9c9df92 100644 --- a/dom/media/mediasource/SourceBufferDecoder.h +++ b/dom/media/mediasource/SourceBufferDecoder.h @@ -60,6 +60,7 @@ public: virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_FINAL MOZ_OVERRIDE; virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_FINAL MOZ_OVERRIDE; virtual void UpdatePlaybackPosition(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE; + virtual bool HasInitializationData() MOZ_FINAL MOZ_OVERRIDE; // SourceBufferResource specific interface below. diff --git a/dom/media/webm/WebMReader.cpp b/dom/media/webm/WebMReader.cpp index 91b4c3bd6f40..546f9614058a 100644 --- a/dom/media/webm/WebMReader.cpp +++ b/dom/media/webm/WebMReader.cpp @@ -287,7 +287,8 @@ nsresult WebMReader::ReadMetadata(MediaInfo* aInfo, io.seek = webm_seek; io.tell = webm_tell; io.userdata = mDecoder; - int64_t maxOffset = -1; + int64_t maxOffset = mDecoder->HasInitializationData() ? + mDecoder->GetResource()->GetLength() : -1; int r = nestegg_init(&mContext, io, &webm_log, maxOffset); if (r == -1) { return NS_ERROR_FAILURE;