From 1db9ea982a161e38c6c8329b29a49f9ff5757718 Mon Sep 17 00:00:00 2001 From: Matthew Gregan Date: Fri, 22 Aug 2014 14:14:36 +1200 Subject: [PATCH] Bug 1056534 - Add logging to stubbed out member functions to speed up debugging. r=cajbir --HG-- rename : content/media/mediasource/SubBufferDecoder.cpp => content/media/mediasource/SourceBufferDecoder.cpp rename : content/media/mediasource/SubBufferDecoder.h => content/media/mediasource/SourceBufferDecoder.h rename : content/media/BufferDecoder.cpp => content/media/webaudio/BufferDecoder.cpp rename : content/media/BufferDecoder.h => content/media/webaudio/BufferDecoder.h --- .../media/mediasource/MediaSourceDecoder.cpp | 5 +- .../media/mediasource/MediaSourceDecoder.h | 4 +- .../media/mediasource/MediaSourceReader.cpp | 19 +- content/media/mediasource/MediaSourceReader.h | 8 +- .../media/mediasource/MediaSourceResource.h | 19 +- content/media/mediasource/SourceBuffer.cpp | 4 +- content/media/mediasource/SourceBuffer.h | 6 +- .../media/mediasource/SourceBufferDecoder.cpp | 254 ++++++++++++++++++ .../media/mediasource/SourceBufferDecoder.h | 109 ++++++++ .../media/mediasource/SourceBufferResource.h | 44 ++- .../media/mediasource/SubBufferDecoder.cpp | 145 ---------- content/media/mediasource/SubBufferDecoder.h | 95 ------- content/media/mediasource/moz.build | 2 +- content/media/moz.build | 2 - .../media/{ => webaudio}/BufferDecoder.cpp | 0 content/media/{ => webaudio}/BufferDecoder.h | 52 ++-- content/media/webaudio/moz.build | 1 + 17 files changed, 463 insertions(+), 306 deletions(-) create mode 100644 content/media/mediasource/SourceBufferDecoder.cpp create mode 100644 content/media/mediasource/SourceBufferDecoder.h delete mode 100644 content/media/mediasource/SubBufferDecoder.cpp delete mode 100644 content/media/mediasource/SubBufferDecoder.h rename content/media/{ => webaudio}/BufferDecoder.cpp (100%) rename content/media/{ => webaudio}/BufferDecoder.h (54%) diff --git a/content/media/mediasource/MediaSourceDecoder.cpp b/content/media/mediasource/MediaSourceDecoder.cpp index f63b7e76b55b..fdb5b66b5a79 100644 --- a/content/media/mediasource/MediaSourceDecoder.cpp +++ b/content/media/mediasource/MediaSourceDecoder.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MediaSourceDecoder.h" +#include "prlog.h" #include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/dom/TimeRanges.h" #include "MediaDecoderStateMachine.h" @@ -28,7 +29,7 @@ extern PRLogModuleInfo* GetMediaSourceAPILog(); namespace mozilla { -class SubBufferDecoder; +class SourceBufferDecoder; MediaSourceDecoder::MediaSourceDecoder(dom::HTMLMediaElement* aElement) : mMediaSource(nullptr) @@ -105,7 +106,7 @@ MediaSourceDecoder::DetachMediaSource() mMediaSource = nullptr; } -already_AddRefed +already_AddRefed MediaSourceDecoder::CreateSubDecoder(const nsACString& aType) { MOZ_ASSERT(mReader); diff --git a/content/media/mediasource/MediaSourceDecoder.h b/content/media/mediasource/MediaSourceDecoder.h index 082d26e50f72..9f26e505296a 100644 --- a/content/media/mediasource/MediaSourceDecoder.h +++ b/content/media/mediasource/MediaSourceDecoder.h @@ -19,7 +19,7 @@ namespace mozilla { class MediaResource; class MediaDecoderStateMachine; class MediaSourceReader; -class SubBufferDecoder; +class SourceBufferDecoder; namespace dom { @@ -43,7 +43,7 @@ public: void AttachMediaSource(dom::MediaSource* aMediaSource); void DetachMediaSource(); - already_AddRefed CreateSubDecoder(const nsACString& aType); + already_AddRefed CreateSubDecoder(const nsACString& aType); private: // The owning MediaSource holds a strong reference to this decoder, and diff --git a/content/media/mediasource/MediaSourceReader.cpp b/content/media/mediasource/MediaSourceReader.cpp index d22703758b8d..b0853794600f 100644 --- a/content/media/mediasource/MediaSourceReader.cpp +++ b/content/media/mediasource/MediaSourceReader.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "MediaSourceReader.h" +#include "prlog.h" #include "mozilla/dom/TimeRanges.h" #include "DecoderTraits.h" #include "MediaDataDecodedListener.h" @@ -12,7 +13,7 @@ #include "MediaSource.h" #include "MediaSourceDecoder.h" #include "MediaSourceUtils.h" -#include "SubBufferDecoder.h" +#include "SourceBufferDecoder.h" #ifdef MOZ_FMP4 #include "MP4Decoder.h" @@ -217,7 +218,7 @@ MediaSourceReader::SwitchReaders(SwitchType aType) double decodeTarget = double(mTimeThreshold) / USECS_PER_S; for (uint32_t i = 0; i < mDecoders.Length(); ++i) { - SubBufferDecoder* decoder = mDecoders[i]; + SourceBufferDecoder* decoder = mDecoders[i]; const MediaInfo& info = decoder->GetReader()->GetMediaInfo(); nsRefPtr ranges = new dom::TimeRanges(); @@ -258,7 +259,7 @@ MediaSourceReader::SetMediaSourceDuration(double aDuration) class ReleaseDecodersTask : public nsRunnable { public: - ReleaseDecodersTask(nsTArray>& aDecoders) + ReleaseDecodersTask(nsTArray>& aDecoders) { mDecoders.SwapElements(aDecoders); } @@ -269,7 +270,7 @@ public: } private: - nsTArray> mDecoders; + nsTArray> mDecoders; }; void @@ -277,7 +278,7 @@ MediaSourceReader::InitializePendingDecoders() { ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); for (uint32_t i = 0; i < mPendingDecoders.Length(); ++i) { - nsRefPtr decoder = mPendingDecoders[i]; + nsRefPtr decoder = mPendingDecoders[i]; MediaDecoderReader* reader = decoder->GetReader(); MSE_DEBUG("MediaSourceReader(%p): Initializing subdecoder %p reader %p", this, decoder.get(), reader); @@ -339,12 +340,12 @@ CreateReaderForType(const nsACString& aType, AbstractMediaDecoder* aDecoder) return DecoderTraits::CreateReader(aType, aDecoder); } -already_AddRefed +already_AddRefed MediaSourceReader::CreateSubDecoder(const nsACString& aType) { MOZ_ASSERT(GetTaskQueue()); - nsRefPtr decoder = - new SubBufferDecoder(new SourceBufferResource(nullptr, aType), mDecoder); + nsRefPtr decoder = + new SourceBufferDecoder(new SourceBufferResource(nullptr, aType), mDecoder); nsRefPtr reader(CreateReaderForType(aType, decoder)); if (!reader) { return nullptr; @@ -433,12 +434,14 @@ MediaSourceReader::Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, ResetDecode(); if (mAudioReader) { nsresult rv = mAudioReader->Seek(aTime, aStartTime, aEndTime, aCurrentTime); + MSE_DEBUG("MediaSourceReader(%p)::Seek audio reader=%p rv=%xf", this, mAudioReader.get(), rv); if (NS_FAILED(rv)) { return rv; } } if (mVideoReader) { nsresult rv = mVideoReader->Seek(aTime, aStartTime, aEndTime, aCurrentTime); + MSE_DEBUG("MediaSourceReader(%p)::Seek video reader=%p rv=%xf", this, mVideoReader.get(), rv); if (NS_FAILED(rv)) { return rv; } diff --git a/content/media/mediasource/MediaSourceReader.h b/content/media/mediasource/MediaSourceReader.h index ecd2456ddf0e..f4d24176faad 100644 --- a/content/media/mediasource/MediaSourceReader.h +++ b/content/media/mediasource/MediaSourceReader.h @@ -18,7 +18,7 @@ namespace mozilla { class MediaSourceDecoder; -class SubBufferDecoder; +class SourceBufferDecoder; namespace dom { @@ -70,7 +70,7 @@ public: nsresult ReadMetadata(MediaInfo* aInfo, MetadataTags** aTags) MOZ_OVERRIDE; nsresult Seek(int64_t aTime, int64_t aStartTime, int64_t aEndTime, int64_t aCurrentTime) MOZ_OVERRIDE; - already_AddRefed CreateSubDecoder(const nsACString& aType); + already_AddRefed CreateSubDecoder(const nsACString& aType); void Shutdown(); @@ -105,8 +105,8 @@ private: bool mDropAudioBeforeThreshold; bool mDropVideoBeforeThreshold; - nsTArray> mPendingDecoders; - nsTArray> mDecoders; + nsTArray> mPendingDecoders; + nsTArray> mDecoders; nsRefPtr mAudioReader; nsRefPtr mVideoReader; diff --git a/content/media/mediasource/MediaSourceResource.h b/content/media/mediasource/MediaSourceResource.h index 6e1920942224..39f7c6577c93 100644 --- a/content/media/mediasource/MediaSourceResource.h +++ b/content/media/mediasource/MediaSourceResource.h @@ -8,6 +8,18 @@ #define MOZILLA_MEDIASOURCERESOURCE_H_ #include "MediaResource.h" +#include "prlog.h" + +#ifdef PR_LOGGING +extern PRLogModuleInfo* GetMediaSourceLog(); +extern PRLogModuleInfo* GetMediaSourceAPILog(); + +#define MSE_DEBUG(...) PR_LOG(GetMediaSourceLog(), PR_LOG_DEBUG, (__VA_ARGS__)) +#else +#define MSE_DEBUG(...) +#endif + +#define UNIMPLEMENTED() MSE_DEBUG("MediaSourceResource(%p): UNIMPLEMENTED FUNCTION at line %d", this, __LINE__) namespace mozilla { @@ -44,12 +56,13 @@ public: virtual nsresult GetCachedRanges(nsTArray& aRanges) MOZ_OVERRIDE { + UNIMPLEMENTED(); aRanges.AppendElement(MediaByteRange(0, GetLength())); return NS_OK; } - virtual bool IsTransportSeekable() MOZ_OVERRIDE { return true; } - virtual const nsCString& GetContentType() const MOZ_OVERRIDE { return mType; } + virtual bool IsTransportSeekable() MOZ_OVERRIDE { UNIMPLEMENTED(); return true; } + virtual const nsCString& GetContentType() const MOZ_OVERRIDE { UNIMPLEMENTED(); return mType; } private: virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const MOZ_OVERRIDE @@ -70,4 +83,6 @@ private: } // namespace mozilla +#undef UNIMPLEMENTED + #endif /* MOZILLA_MEDIASOURCERESOURCE_H_ */ diff --git a/content/media/mediasource/SourceBuffer.cpp b/content/media/mediasource/SourceBuffer.cpp index 8bb527f2cff5..6cc03075d05e 100644 --- a/content/media/mediasource/SourceBuffer.cpp +++ b/content/media/mediasource/SourceBuffer.cpp @@ -21,7 +21,7 @@ #include "nsIRunnable.h" #include "nsThreadUtils.h" #include "prlog.h" -#include "SubBufferDecoder.h" +#include "SourceBufferDecoder.h" #include "mozilla/Preferences.h" struct JSContext; @@ -381,7 +381,7 @@ SourceBuffer::InitNewDecoder() MSE_DEBUG("SourceBuffer(%p)::InitNewDecoder", this); MOZ_ASSERT(!mDecoder); MediaSourceDecoder* parentDecoder = mMediaSource->GetDecoder(); - nsRefPtr decoder = parentDecoder->CreateSubDecoder(mType); + nsRefPtr decoder = parentDecoder->CreateSubDecoder(mType); if (!decoder) { return false; } diff --git a/content/media/mediasource/SourceBuffer.h b/content/media/mediasource/SourceBuffer.h index 14d6bc1bd1a6..0eaa97331c07 100644 --- a/content/media/mediasource/SourceBuffer.h +++ b/content/media/mediasource/SourceBuffer.h @@ -32,7 +32,7 @@ namespace mozilla { class ContainerParser; class ErrorResult; class SourceBufferResource; -class SubBufferDecoder; +class SourceBufferDecoder; template class AsyncEventRunner; namespace dom { @@ -141,8 +141,8 @@ private: nsAutoPtr mParser; - nsRefPtr mDecoder; - nsTArray> mDecoders; + nsRefPtr mDecoder; + nsTArray> mDecoders; double mAppendWindowStart; double mAppendWindowEnd; diff --git a/content/media/mediasource/SourceBufferDecoder.cpp b/content/media/mediasource/SourceBufferDecoder.cpp new file mode 100644 index 000000000000..763d4f9f53bc --- /dev/null +++ b/content/media/mediasource/SourceBufferDecoder.cpp @@ -0,0 +1,254 @@ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "SourceBufferDecoder.h" +#include "prlog.h" +#include "AbstractMediaDecoder.h" +#include "MediaDecoderReader.h" +#include "mozilla/dom/TimeRanges.h" + +#ifdef PR_LOGGING +extern PRLogModuleInfo* GetMediaSourceLog(); +extern PRLogModuleInfo* GetMediaSourceAPILog(); + +#define MSE_DEBUG(...) PR_LOG(GetMediaSourceLog(), PR_LOG_DEBUG, (__VA_ARGS__)) +#define MSE_API(...) PR_LOG(GetMediaSourceAPILog(), PR_LOG_DEBUG, (__VA_ARGS__)) +#else +#define MSE_DEBUG(...) +#define MSE_API(...) +#endif + +namespace mozilla { + +class ReentrantMonitor; + +namespace layers { + +class ImageContainer; + +} // namespace layers + +NS_IMPL_ISUPPORTS0(SourceBufferDecoder) + +SourceBufferDecoder::SourceBufferDecoder(MediaResource* aResource, + AbstractMediaDecoder* aParentDecoder) + : mResource(aResource) + , mParentDecoder(aParentDecoder) + , mReader(nullptr) + , mMediaDuration(-1) + , mDiscarded(false) +{ + MOZ_ASSERT(NS_IsMainThread()); + MOZ_COUNT_CTOR(SourceBufferDecoder); +} + +SourceBufferDecoder::~SourceBufferDecoder() +{ + MOZ_COUNT_DTOR(SourceBufferDecoder); +} + +bool +SourceBufferDecoder::IsShutdown() const +{ + // SourceBufferDecoder cannot be shut down. + MSE_DEBUG("SourceBufferDecoder(%p)::IsShutdown UNIMPLEMENTED", this); + return false; +} + +void +SourceBufferDecoder::NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) +{ + MSE_DEBUG("SourceBufferDecoder(%p)::NotifyBytesConsumed UNIMPLEMENTED", this); +} + +int64_t +SourceBufferDecoder::GetEndMediaTime() const +{ + MSE_DEBUG("SourceBufferDecoder(%p)::GetEndMediaTime UNIMPLEMENTED", this); + return -1; +} + +int64_t +SourceBufferDecoder::GetMediaDuration() +{ + return mMediaDuration; +} + +VideoFrameContainer* +SourceBufferDecoder::GetVideoFrameContainer() +{ + MSE_DEBUG("SourceBufferDecoder(%p)::GetVideoFrameContainer UNIMPLEMENTED", this); + return nullptr; +} + +bool +SourceBufferDecoder::IsTransportSeekable() +{ + MSE_DEBUG("SourceBufferDecoder(%p)::IsTransportSeekable UNIMPLEMENTED", this); + return false; +} + +bool +SourceBufferDecoder::IsMediaSeekable() +{ + MSE_DEBUG("SourceBufferDecoder(%p)::IsMediaSeekable UNIMPLEMENTED", this); + return false; +} + +void +SourceBufferDecoder::MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) +{ + MSE_DEBUG("SourceBufferDecoder(%p)::MetadataLoaded UNIMPLEMENTED", this); +} + +void +SourceBufferDecoder::QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) +{ + MSE_DEBUG("SourceBufferDecoder(%p)::QueueMetadata UNIMPLEMENTED", this); +} + +void +SourceBufferDecoder::RemoveMediaTracks() +{ + MSE_DEBUG("SourceBufferDecoder(%p)::RemoveMediaTracks UNIMPLEMENTED", this); +} + +void +SourceBufferDecoder::SetMediaEndTime(int64_t aTime) +{ + MSE_DEBUG("SourceBufferDecoder(%p)::SetMediaEndTime UNIMPLEMENTED", this); +} + +void +SourceBufferDecoder::UpdatePlaybackPosition(int64_t aTime) +{ + MSE_DEBUG("SourceBufferDecoder(%p)::UpdatePlaybackPosition UNIMPLEMENTED", this); +} + +void +SourceBufferDecoder::OnReadMetadataCompleted() +{ + MSE_DEBUG("SourceBufferDecoder(%p)::OnReadMetadataCompleted UNIMPLEMENTED", this); +} + +void +SourceBufferDecoder::NotifyWaitingForResourcesStatusChanged() +{ + MSE_DEBUG("SourceBufferDecoder(%p)::NotifyWaitingForResourcesStatusChanged UNIMPLEMENTED", this); +} + +ReentrantMonitor& +SourceBufferDecoder::GetReentrantMonitor() +{ + return mParentDecoder->GetReentrantMonitor(); +} + +bool +SourceBufferDecoder::OnStateMachineThread() const +{ + return mParentDecoder->OnStateMachineThread(); +} + +bool +SourceBufferDecoder::OnDecodeThread() const +{ + return mParentDecoder->OnDecodeThread(); +} + +SourceBufferResource* +SourceBufferDecoder::GetResource() const +{ + return static_cast(mResource.get()); +} + +void +SourceBufferDecoder::NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) +{ + return mParentDecoder->NotifyDecodedFrames(aParsed, aDecoded); +} + +void +SourceBufferDecoder::SetMediaDuration(int64_t aDuration) +{ + mMediaDuration = aDuration; +} + +void +SourceBufferDecoder::UpdateEstimatedMediaDuration(int64_t aDuration) +{ + MSE_DEBUG("SourceBufferDecoder(%p)::UpdateEstimatedMediaDuration UNIMPLEMENTED", this); +} + +void +SourceBufferDecoder::SetMediaSeekable(bool aMediaSeekable) +{ + MSE_DEBUG("SourceBufferDecoder(%p)::SetMediaSeekable UNIMPLEMENTED", this); +} + +layers::ImageContainer* +SourceBufferDecoder::GetImageContainer() +{ + return mParentDecoder->GetImageContainer(); +} + +MediaDecoderOwner* +SourceBufferDecoder::GetOwner() +{ + return mParentDecoder->GetOwner(); +} + +void +SourceBufferDecoder::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) +{ + mReader->NotifyDataArrived(aBuffer, aLength, aOffset); + + // XXX: Params make no sense to parent decoder as it relates to a + // specific SourceBufferDecoder's data stream. Pass bogus values here to + // force parent decoder's state machine to recompute end time for + // infinite length media. + mParentDecoder->NotifyDataArrived(nullptr, 0, 0); +} + +nsresult +SourceBufferDecoder::GetBuffered(dom::TimeRanges* aBuffered) +{ + // XXX: Need mStartTime (from StateMachine) instead of passing 0. + return mReader->GetBuffered(aBuffered, 0); +} + +int64_t +SourceBufferDecoder::ConvertToByteOffset(double aTime) +{ + int64_t readerOffset = mReader->GetEvictionOffset(aTime); + if (readerOffset >= 0) { + return readerOffset; + } + + // Uses a conversion based on (aTime/duration) * length. For the + // purposes of eviction this should be adequate since we have the + // byte threshold as well to ensure data actually gets evicted and + // we ensure we don't evict before the current playable point. + if (mMediaDuration <= 0) { + return -1; + } + int64_t length = GetResource()->GetLength(); + MOZ_ASSERT(length > 0); + int64_t offset = (aTime / (double(mMediaDuration) / USECS_PER_S)) * length; + return offset; +} + +bool +SourceBufferDecoder::ContainsTime(double aTime) +{ + ErrorResult dummy; + nsRefPtr ranges = new dom::TimeRanges(); + nsresult rv = GetBuffered(ranges); + if (NS_FAILED(rv) || ranges->Length() == 0) { + return false; + } + return ranges->Find(aTime) != dom::TimeRanges::NoIndex; +} + +} // namespace mozilla diff --git a/content/media/mediasource/SourceBufferDecoder.h b/content/media/mediasource/SourceBufferDecoder.h new file mode 100644 index 000000000000..b1cf8edf2781 --- /dev/null +++ b/content/media/mediasource/SourceBufferDecoder.h @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef MOZILLA_SOURCEBUFFERDECODER_H_ +#define MOZILLA_SOURCEBUFFERDECODER_H_ + +#include "AbstractMediaDecoder.h" +#include "mozilla/Attributes.h" +#include "mozilla/ReentrantMonitor.h" +#include "SourceBufferResource.h" + +namespace mozilla { + +class MediaResource; +class MediaDecoderReader; + +namespace dom { + +class TimeRanges; + +} // namespace dom + +class SourceBufferDecoder : public AbstractMediaDecoder +{ +public: + // This class holds a weak pointer to MediaResource. It's the responsibility + // of the caller to manage the memory of the MediaResource object. + SourceBufferDecoder(MediaResource* aResource, AbstractMediaDecoder* aParentDecoder); + + NS_DECL_THREADSAFE_ISUPPORTS + + virtual bool IsMediaSeekable() MOZ_FINAL MOZ_OVERRIDE; + virtual bool IsShutdown() const MOZ_FINAL MOZ_OVERRIDE; + virtual bool IsTransportSeekable() MOZ_FINAL MOZ_OVERRIDE; + virtual bool OnDecodeThread() const MOZ_FINAL MOZ_OVERRIDE; + virtual bool OnStateMachineThread() const MOZ_FINAL MOZ_OVERRIDE; + virtual int64_t GetEndMediaTime() const MOZ_FINAL MOZ_OVERRIDE; + virtual int64_t GetMediaDuration() MOZ_FINAL MOZ_OVERRIDE; + virtual layers::ImageContainer* GetImageContainer() MOZ_FINAL MOZ_OVERRIDE; + virtual MediaDecoderOwner* GetOwner() MOZ_FINAL MOZ_OVERRIDE; + virtual SourceBufferResource* GetResource() const MOZ_FINAL MOZ_OVERRIDE; + virtual ReentrantMonitor& GetReentrantMonitor() MOZ_FINAL MOZ_OVERRIDE; + virtual VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE; + virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE; + virtual void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) MOZ_FINAL MOZ_OVERRIDE; + virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) MOZ_FINAL MOZ_OVERRIDE; + virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) MOZ_FINAL MOZ_OVERRIDE; + virtual void NotifyWaitingForResourcesStatusChanged() MOZ_FINAL MOZ_OVERRIDE; + virtual void OnReadMetadataCompleted() MOZ_FINAL MOZ_OVERRIDE; + virtual void QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE; + virtual void RemoveMediaTracks() MOZ_FINAL MOZ_OVERRIDE; + virtual void SetMediaDuration(int64_t aDuration) MOZ_FINAL MOZ_OVERRIDE; + virtual void SetMediaEndTime(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE; + 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; + + // SourceBufferResource specific interface below. + + // Warning: this mirrors GetBuffered in MediaDecoder, but this class's base is + // AbstractMediaDecoder, which does not supply this interface. + nsresult GetBuffered(dom::TimeRanges* aBuffered); + + void SetReader(MediaDecoderReader* aReader) + { + MOZ_ASSERT(!mReader); + mReader = aReader; + } + + MediaDecoderReader* GetReader() + { + return mReader; + } + + // Given a time convert it into an approximate byte offset from the + // cached data. Returns -1 if no such value is computable. + int64_t ConvertToByteOffset(double aTime); + + bool IsDiscarded() + { + return mDiscarded; + } + + void SetDiscarded() + { + GetResource()->Ended(); + mDiscarded = true; + } + + // Returns true if the data buffered by this decoder contains the given time. + bool ContainsTime(double aTime); + +private: + virtual ~SourceBufferDecoder(); + + nsRefPtr mResource; + + AbstractMediaDecoder* mParentDecoder; + nsRefPtr mReader; + int64_t mMediaDuration; + bool mDiscarded; +}; + +} // namespace mozilla + +#endif /* MOZILLA_SOURCEBUFFERDECODER_H_ */ diff --git a/content/media/mediasource/SourceBufferResource.h b/content/media/mediasource/SourceBufferResource.h index cc6dbc2723ee..5834fcb134f7 100644 --- a/content/media/mediasource/SourceBufferResource.h +++ b/content/media/mediasource/SourceBufferResource.h @@ -18,6 +18,18 @@ #include "nsString.h" #include "nsTArray.h" #include "nscore.h" +#include "prlog.h" + +#ifdef PR_LOGGING +extern PRLogModuleInfo* GetMediaSourceLog(); +extern PRLogModuleInfo* GetMediaSourceAPILog(); + +#define MSE_DEBUG(...) PR_LOG(GetMediaSourceLog(), PR_LOG_DEBUG, (__VA_ARGS__)) +#else +#define MSE_DEBUG(...) +#endif + +#define UNIMPLEMENTED() MSE_DEBUG("SourceBufferResource(%p): UNIMPLEMENTED FUNCTION at line %d", this, __LINE__) class nsIStreamListener; @@ -37,8 +49,8 @@ public: SourceBufferResource(nsIPrincipal* aPrincipal, const nsACString& aType); virtual nsresult Close() MOZ_OVERRIDE; - virtual void Suspend(bool aCloseImmediately) MOZ_OVERRIDE {} - virtual void Resume() MOZ_OVERRIDE {} + virtual void Suspend(bool aCloseImmediately) MOZ_OVERRIDE { UNIMPLEMENTED(); } + virtual void Resume() MOZ_OVERRIDE { UNIMPLEMENTED(); } virtual already_AddRefed GetCurrentPrincipal() MOZ_OVERRIDE { @@ -47,29 +59,30 @@ public: virtual already_AddRefed CloneData(MediaDecoder* aDecoder) MOZ_OVERRIDE { + UNIMPLEMENTED(); return nullptr; } - virtual void SetReadMode(MediaCacheStream::ReadMode aMode) MOZ_OVERRIDE {} - virtual void SetPlaybackRate(uint32_t aBytesPerSecond) MOZ_OVERRIDE {} + virtual void SetReadMode(MediaCacheStream::ReadMode aMode) MOZ_OVERRIDE { UNIMPLEMENTED(); } + virtual void SetPlaybackRate(uint32_t aBytesPerSecond) MOZ_OVERRIDE { UNIMPLEMENTED(); } virtual nsresult Read(char* aBuffer, uint32_t aCount, uint32_t* aBytes) MOZ_OVERRIDE; virtual nsresult ReadAt(int64_t aOffset, char* aBuffer, uint32_t aCount, uint32_t* aBytes) MOZ_OVERRIDE; virtual nsresult Seek(int32_t aWhence, int64_t aOffset) MOZ_OVERRIDE; - virtual void StartSeekingForMetadata() MOZ_OVERRIDE { } - virtual void EndSeekingForMetadata() MOZ_OVERRIDE {} + virtual void StartSeekingForMetadata() MOZ_OVERRIDE { UNIMPLEMENTED(); } + virtual void EndSeekingForMetadata() MOZ_OVERRIDE { UNIMPLEMENTED(); } virtual int64_t Tell() MOZ_OVERRIDE { return mOffset; } - virtual void Pin() MOZ_OVERRIDE {} - virtual void Unpin() MOZ_OVERRIDE {} - virtual double GetDownloadRate(bool* aIsReliable) MOZ_OVERRIDE { *aIsReliable = false; return 0; } + virtual void Pin() MOZ_OVERRIDE { UNIMPLEMENTED(); } + virtual void Unpin() MOZ_OVERRIDE { UNIMPLEMENTED(); } + virtual double GetDownloadRate(bool* aIsReliable) MOZ_OVERRIDE { UNIMPLEMENTED(); *aIsReliable = false; return 0; } virtual int64_t GetLength() MOZ_OVERRIDE { return mInputBuffer.GetLength(); } virtual int64_t GetNextCachedData(int64_t aOffset) MOZ_OVERRIDE { return GetLength() == aOffset ? -1 : aOffset; } virtual int64_t GetCachedDataEnd(int64_t aOffset) MOZ_OVERRIDE { return GetLength(); } - virtual bool IsDataCachedToEndOfResource(int64_t aOffset) MOZ_OVERRIDE { return false; } - virtual bool IsSuspendedByCache() MOZ_OVERRIDE { return false; } - virtual bool IsSuspended() MOZ_OVERRIDE { return false; } + virtual bool IsDataCachedToEndOfResource(int64_t aOffset) MOZ_OVERRIDE { UNIMPLEMENTED(); return false; } + virtual bool IsSuspendedByCache() MOZ_OVERRIDE { UNIMPLEMENTED(); return false; } + virtual bool IsSuspended() MOZ_OVERRIDE { UNIMPLEMENTED(); return false; } virtual nsresult ReadFromCache(char* aBuffer, int64_t aOffset, uint32_t aCount) MOZ_OVERRIDE; - virtual bool IsTransportSeekable() MOZ_OVERRIDE { return true; } - virtual nsresult Open(nsIStreamListener** aStreamListener) MOZ_OVERRIDE { return NS_ERROR_FAILURE; } + virtual bool IsTransportSeekable() MOZ_OVERRIDE { UNIMPLEMENTED(); return true; } + virtual nsresult Open(nsIStreamListener** aStreamListener) MOZ_OVERRIDE { UNIMPLEMENTED(); return NS_ERROR_FAILURE; } virtual nsresult GetCachedRanges(nsTArray& aRanges) MOZ_OVERRIDE { @@ -134,4 +147,7 @@ private: }; } // namespace mozilla + +#undef UNIMPLEMENTED + #endif /* MOZILLA_SOURCEBUFFERRESOURCE_H_ */ diff --git a/content/media/mediasource/SubBufferDecoder.cpp b/content/media/mediasource/SubBufferDecoder.cpp deleted file mode 100644 index 3dfe8b075e96..000000000000 --- a/content/media/mediasource/SubBufferDecoder.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "SubBufferDecoder.h" -#include "AbstractMediaDecoder.h" -#include "MediaDecoderReader.h" -#include "mozilla/dom/TimeRanges.h" - -#ifdef PR_LOGGING -extern PRLogModuleInfo* GetMediaSourceLog(); -extern PRLogModuleInfo* GetMediaSourceAPILog(); - -#define MSE_DEBUG(...) PR_LOG(GetMediaSourceLog(), PR_LOG_DEBUG, (__VA_ARGS__)) -#define MSE_API(...) PR_LOG(GetMediaSourceAPILog(), PR_LOG_DEBUG, (__VA_ARGS__)) -#else -#define MSE_DEBUG(...) -#define MSE_API(...) -#endif - -namespace mozilla { - -class ReentrantMonitor; - -namespace layers { - -class ImageContainer; - -} // namespace layers - - -ReentrantMonitor& -SubBufferDecoder::GetReentrantMonitor() -{ - return mParentDecoder->GetReentrantMonitor(); -} - -bool -SubBufferDecoder::OnStateMachineThread() const -{ - return mParentDecoder->OnStateMachineThread(); -} - -bool -SubBufferDecoder::OnDecodeThread() const -{ - return mParentDecoder->OnDecodeThread(); -} - -SourceBufferResource* -SubBufferDecoder::GetResource() const -{ - return static_cast(mResource.get()); -} - -void -SubBufferDecoder::NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) -{ - return mParentDecoder->NotifyDecodedFrames(aParsed, aDecoded); -} - -void -SubBufferDecoder::SetMediaDuration(int64_t aDuration) -{ - mMediaDuration = aDuration; -} - -void -SubBufferDecoder::UpdateEstimatedMediaDuration(int64_t aDuration) -{ - MSE_DEBUG("SubBufferDecoder(%p)::UpdateEstimatedMediaDuration(aDuration=%lld)", this, aDuration); -} - -void -SubBufferDecoder::SetMediaSeekable(bool aMediaSeekable) -{ - MSE_DEBUG("SubBufferDecoder(%p)::SetMediaSeekable(aMediaSeekable=%d)", this, aMediaSeekable); -} - -layers::ImageContainer* -SubBufferDecoder::GetImageContainer() -{ - return mParentDecoder->GetImageContainer(); -} - -MediaDecoderOwner* -SubBufferDecoder::GetOwner() -{ - return mParentDecoder->GetOwner(); -} - -void -SubBufferDecoder::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) -{ - mReader->NotifyDataArrived(aBuffer, aLength, aOffset); - - // XXX: Params make no sense to parent decoder as it relates to a - // specific SubBufferDecoder's data stream. Pass bogus values here to - // force parent decoder's state machine to recompute end time for - // infinite length media. - mParentDecoder->NotifyDataArrived(nullptr, 0, 0); -} - -nsresult -SubBufferDecoder::GetBuffered(dom::TimeRanges* aBuffered) -{ - // XXX: Need mStartTime (from StateMachine) instead of passing 0. - return mReader->GetBuffered(aBuffered, 0); -} - -int64_t -SubBufferDecoder::ConvertToByteOffset(double aTime) -{ - int64_t readerOffset = mReader->GetEvictionOffset(aTime); - if (readerOffset >= 0) { - return readerOffset; - } - - // Uses a conversion based on (aTime/duration) * length. For the - // purposes of eviction this should be adequate since we have the - // byte threshold as well to ensure data actually gets evicted and - // we ensure we don't evict before the current playable point. - if (mMediaDuration <= 0) { - return -1; - } - int64_t length = GetResource()->GetLength(); - MOZ_ASSERT(length > 0); - int64_t offset = (aTime / (double(mMediaDuration) / USECS_PER_S)) * length; - return offset; -} - -bool -SubBufferDecoder::ContainsTime(double aTime) -{ - ErrorResult dummy; - nsRefPtr ranges = new dom::TimeRanges(); - nsresult rv = GetBuffered(ranges); - if (NS_FAILED(rv) || ranges->Length() == 0) { - return false; - } - return ranges->Find(aTime) != dom::TimeRanges::NoIndex; -} - -} // namespace mozilla diff --git a/content/media/mediasource/SubBufferDecoder.h b/content/media/mediasource/SubBufferDecoder.h deleted file mode 100644 index 06e0e012b51c..000000000000 --- a/content/media/mediasource/SubBufferDecoder.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef MOZILLA_SUBBUFFERDECODER_H_ -#define MOZILLA_SUBBUFFERDECODER_H_ - -#include "BufferDecoder.h" -#include "SourceBufferResource.h" - -namespace mozilla { - -class MediaResource; -class MediaSourceDecoder; -class MediaDecoderReader; - -namespace dom { - -class TimeRanges; - -} // namespace dom - -class SubBufferDecoder : public BufferDecoder -{ -public: - // This class holds a weak pointer to MediaResource. It's the responsibility - // of the caller to manage the memory of the MediaResource object. - SubBufferDecoder(MediaResource* aResource, AbstractMediaDecoder* aParentDecoder) - : BufferDecoder(aResource), mParentDecoder(aParentDecoder), mReader(nullptr) - , mMediaDuration(-1), mDiscarded(false) - { - } - - void SetReader(MediaDecoderReader* aReader) - { - MOZ_ASSERT(!mReader); - mReader = aReader; - } - - MediaDecoderReader* GetReader() - { - return mReader; - } - - virtual ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE; - virtual bool OnStateMachineThread() const MOZ_OVERRIDE; - virtual bool OnDecodeThread() const MOZ_OVERRIDE; - virtual SourceBufferResource* GetResource() const MOZ_OVERRIDE; - virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) MOZ_OVERRIDE; - virtual void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE; - virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE; - virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE; - virtual layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE; - virtual MediaDecoderOwner* GetOwner() MOZ_OVERRIDE; - - // Warning: these mirror calls from MediaDecoder, but this class's base is - // AbstractMediaDecoder, which does not supply this interface. - void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset); - nsresult GetBuffered(dom::TimeRanges* aBuffered); - - // Given a time convert it into an approximate byte offset from the - // cached data. Returns -1 if no such value is computable. - int64_t ConvertToByteOffset(double aTime); - - int64_t GetMediaDuration() MOZ_OVERRIDE - { - return mMediaDuration; - } - - bool IsDiscarded() - { - return mDiscarded; - } - - void SetDiscarded() - { - GetResource()->Ended(); - mDiscarded = true; - } - - // Returns true if the data buffered by this decoder contains the given time. - bool ContainsTime(double aTime); - -private: - AbstractMediaDecoder* mParentDecoder; - nsRefPtr mReader; - int64_t mMediaDuration; - bool mDiscarded; -}; - -} // namespace mozilla - -#endif /* MOZILLA_SUBBUFFERDECODER_H_ */ diff --git a/content/media/mediasource/moz.build b/content/media/mediasource/moz.build index 5aa7b143fa31..be6247271ec3 100644 --- a/content/media/mediasource/moz.build +++ b/content/media/mediasource/moz.build @@ -22,9 +22,9 @@ UNIFIED_SOURCES += [ 'MediaSourceReader.cpp', 'MediaSourceUtils.cpp', 'SourceBuffer.cpp', + 'SourceBufferDecoder.cpp', 'SourceBufferList.cpp', 'SourceBufferResource.cpp', - 'SubBufferDecoder.cpp', ] FAIL_ON_WARNINGS = True diff --git a/content/media/moz.build b/content/media/moz.build index 7197efbc0c3c..a4d21614660d 100644 --- a/content/media/moz.build +++ b/content/media/moz.build @@ -69,7 +69,6 @@ EXPORTS += [ 'AudioSampleFormat.h', 'AudioSegment.h', 'AudioStream.h', - 'BufferDecoder.h', 'BufferMediaResource.h', 'DecoderTraits.h', 'DOMMediaStream.h', @@ -133,7 +132,6 @@ UNIFIED_SOURCES += [ 'AudioStreamTrack.cpp', 'AudioTrack.cpp', 'AudioTrackList.cpp', - 'BufferDecoder.cpp', 'DOMMediaStream.cpp', 'EncodedBufferCache.cpp', 'FileBlockCache.cpp', diff --git a/content/media/BufferDecoder.cpp b/content/media/webaudio/BufferDecoder.cpp similarity index 100% rename from content/media/BufferDecoder.cpp rename to content/media/webaudio/BufferDecoder.cpp diff --git a/content/media/BufferDecoder.h b/content/media/webaudio/BufferDecoder.h similarity index 54% rename from content/media/BufferDecoder.h rename to content/media/webaudio/BufferDecoder.h index fc37f2f3ecb9..2f67bff34b97 100644 --- a/content/media/BufferDecoder.h +++ b/content/media/webaudio/BufferDecoder.h @@ -29,55 +29,55 @@ public: // This has to be called before decoding begins void BeginDecoding(nsIThread* aDecodeThread); - virtual ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE; + virtual ReentrantMonitor& GetReentrantMonitor() MOZ_FINAL MOZ_OVERRIDE; - virtual bool IsShutdown() const MOZ_OVERRIDE; + virtual bool IsShutdown() const MOZ_FINAL MOZ_OVERRIDE; - virtual bool OnStateMachineThread() const MOZ_OVERRIDE; + virtual bool OnStateMachineThread() const MOZ_FINAL MOZ_OVERRIDE; - virtual bool OnDecodeThread() const MOZ_OVERRIDE; + virtual bool OnDecodeThread() const MOZ_FINAL MOZ_OVERRIDE; - virtual MediaResource* GetResource() const MOZ_OVERRIDE; + virtual MediaResource* GetResource() const MOZ_FINAL MOZ_OVERRIDE; - virtual void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) MOZ_OVERRIDE; + virtual void NotifyBytesConsumed(int64_t aBytes, int64_t aOffset) MOZ_FINAL MOZ_OVERRIDE; - virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) MOZ_OVERRIDE; + virtual void NotifyDecodedFrames(uint32_t aParsed, uint32_t aDecoded) MOZ_FINAL MOZ_OVERRIDE; - virtual int64_t GetEndMediaTime() const MOZ_OVERRIDE; + virtual int64_t GetEndMediaTime() const MOZ_FINAL MOZ_OVERRIDE; - virtual int64_t GetMediaDuration() MOZ_OVERRIDE; + virtual int64_t GetMediaDuration() MOZ_FINAL MOZ_OVERRIDE; - virtual void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE; + virtual void SetMediaDuration(int64_t aDuration) MOZ_FINAL MOZ_OVERRIDE; - virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE; + virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_FINAL MOZ_OVERRIDE; - virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE; + virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_FINAL MOZ_OVERRIDE; - virtual VideoFrameContainer* GetVideoFrameContainer() MOZ_OVERRIDE; - virtual layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE; + virtual VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE; + virtual layers::ImageContainer* GetImageContainer() MOZ_FINAL MOZ_OVERRIDE; - virtual bool IsTransportSeekable() MOZ_OVERRIDE; + virtual bool IsTransportSeekable() MOZ_FINAL MOZ_OVERRIDE; - virtual bool IsMediaSeekable() MOZ_OVERRIDE; + virtual bool IsMediaSeekable() MOZ_FINAL MOZ_OVERRIDE; - virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) MOZ_OVERRIDE; - virtual void QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) MOZ_OVERRIDE; + virtual void MetadataLoaded(MediaInfo* aInfo, MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE; + virtual void QueueMetadata(int64_t aTime, MediaInfo* aInfo, MetadataTags* aTags) MOZ_FINAL MOZ_OVERRIDE; - virtual void RemoveMediaTracks() MOZ_OVERRIDE; + virtual void RemoveMediaTracks() MOZ_FINAL MOZ_OVERRIDE; - virtual void SetMediaEndTime(int64_t aTime) MOZ_OVERRIDE; + virtual void SetMediaEndTime(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE; - virtual void UpdatePlaybackPosition(int64_t aTime) MOZ_OVERRIDE; + virtual void UpdatePlaybackPosition(int64_t aTime) MOZ_FINAL MOZ_OVERRIDE; - virtual void OnReadMetadataCompleted() MOZ_OVERRIDE; + virtual void OnReadMetadataCompleted() MOZ_FINAL MOZ_OVERRIDE; - virtual MediaDecoderOwner* GetOwner() MOZ_OVERRIDE; + virtual MediaDecoderOwner* GetOwner() MOZ_FINAL MOZ_OVERRIDE; - virtual void NotifyWaitingForResourcesStatusChanged() MOZ_OVERRIDE; + virtual void NotifyWaitingForResourcesStatusChanged() MOZ_FINAL MOZ_OVERRIDE; - virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) MOZ_OVERRIDE; + virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) MOZ_FINAL MOZ_OVERRIDE; -protected: +private: virtual ~BufferDecoder(); // This monitor object is not really used to synchronize access to anything. diff --git a/content/media/webaudio/moz.build b/content/media/webaudio/moz.build index ade10ed0c08b..8c85597850b5 100644 --- a/content/media/webaudio/moz.build +++ b/content/media/webaudio/moz.build @@ -75,6 +75,7 @@ UNIFIED_SOURCES += [ 'AudioParam.cpp', 'AudioProcessingEvent.cpp', 'BiquadFilterNode.cpp', + 'BufferDecoder.cpp', 'ChannelMergerNode.cpp', 'ChannelSplitterNode.cpp', 'ConvolverNode.cpp',