From 1668f024f77d20b61b419bd0b906a33813a228a9 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 29 Oct 2014 09:30:36 +1300 Subject: [PATCH] Bug 1089480 - Assume a start time of 0 for MSE videos. r=cajbir --HG-- extra : rebase_source : fb44192e9f7f97a9ed1d753dd185dc82fdeaaa48 --- dom/media/MediaDecoderReader.cpp | 25 +++++++++++++++-------- dom/media/MediaDecoderReader.h | 2 ++ dom/media/MediaDecoderStateMachine.cpp | 11 +--------- dom/media/mediasource/MediaSourceReader.h | 5 +++++ 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/dom/media/MediaDecoderReader.cpp b/dom/media/MediaDecoderReader.cpp index acf892d1080c..e24badc66a85 100644 --- a/dom/media/MediaDecoderReader.cpp +++ b/dom/media/MediaDecoderReader.cpp @@ -20,15 +20,10 @@ namespace mozilla { #ifdef PR_LOGGING extern PRLogModuleInfo* gMediaDecoderLog; -#define DECODER_LOG(type, msg) PR_LOG(gMediaDecoderLog, type, msg) -#ifdef SEEK_LOGGING -#define SEEK_LOG(type, msg) PR_LOG(gMediaDecoderLog, type, msg) +#define DECODER_LOG(x, ...) \ + PR_LOG(gMediaDecoderLog, PR_LOG_DEBUG, ("Decoder=%p " x, mDecoder, ##__VA_ARGS__)) #else -#define SEEK_LOG(type, msg) -#endif -#else -#define DECODER_LOG(type, msg) -#define SEEK_LOG(type, msg) +#define DECODER_LOG(x, ...) #endif class VideoQueueMemoryFunctor : public nsDequeFunctor { @@ -139,6 +134,20 @@ MediaDecoderReader::GetBuffered(mozilla::dom::TimeRanges* aBuffered, return NS_OK; } +int64_t +MediaDecoderReader::ComputeStartTime(const VideoData* aVideo, const AudioData* aAudio) +{ + int64_t startTime = std::min(aAudio ? aAudio->mTime : INT64_MAX, + aVideo ? aVideo->mTime : INT64_MAX); + if (startTime == INT64_MAX) { + startTime = 0; + } + DECODER_LOG("ComputeStartTime first video frame start %lld", aVideo ? aVideo->mTime : -1); + DECODER_LOG("ComputeStartTime first audio frame start %lld", aAudio ? aAudio->mTime : -1); + MOZ_ASSERT(startTime >= 0); + return startTime; +} + class RequestVideoWithSkipTask : public nsRunnable { public: RequestVideoWithSkipTask(MediaDecoderReader* aReader, diff --git a/dom/media/MediaDecoderReader.h b/dom/media/MediaDecoderReader.h index d88777af1c9c..c1df1addb80e 100644 --- a/dom/media/MediaDecoderReader.h +++ b/dom/media/MediaDecoderReader.h @@ -148,6 +148,8 @@ public: virtual nsresult GetBuffered(dom::TimeRanges* aBuffered, int64_t aStartTime); + virtual int64_t ComputeStartTime(const VideoData* aVideo, const AudioData* aAudio); + // Returns the number of bytes of memory allocated by structures/frames in // the video queue. size_t SizeOfVideoQueueInBytes() const; diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index a27810d7fb84..fc2bbe746bdd 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -2016,18 +2016,9 @@ MediaDecoderStateMachine::FinishDecodeMetadata() } if (!mScheduler->IsRealTime() && !mDecodingFrozenAtStateMetadata) { - const VideoData* v = VideoQueue().PeekFront(); const AudioData* a = AudioQueue().PeekFront(); - - int64_t startTime = std::min(a ? a->mTime : INT64_MAX, - v ? v->mTime : INT64_MAX); - if (startTime == INT64_MAX) { - startTime = 0; - } - DECODER_LOG("DecodeMetadata first video frame start %lld", v ? v->mTime : -1); - DECODER_LOG("DecodeMetadata first audio frame start %lld", a ? a->mTime : -1); - SetStartTime(startTime); + SetStartTime(mReader->ComputeStartTime(v, a)); if (VideoQueue().GetSize()) { ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor()); RenderVideoFrame(VideoQueue().PeekFront(), TimeStamp::Now()); diff --git a/dom/media/mediasource/MediaSourceReader.h b/dom/media/mediasource/MediaSourceReader.h index 8227d8121edf..577e5631211d 100644 --- a/dom/media/mediasource/MediaSourceReader.h +++ b/dom/media/mediasource/MediaSourceReader.h @@ -70,6 +70,11 @@ public: return mInfo.HasAudio(); } + // We can't compute a proper start time since we won't necessarily + // have the first frame of the resource available. This does the same + // as chrome/blink and assumes that we always start at t=0. + virtual int64_t ComputeStartTime(const VideoData* aVideo, const AudioData* aAudio) MOZ_OVERRIDE { return 0; } + bool IsMediaSeekable() { return true; } nsresult ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags) MOZ_OVERRIDE;