michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=8 sts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef MOZILLA_SUBBUFFERDECODER_H_ michael@0: #define MOZILLA_SUBBUFFERDECODER_H_ michael@0: michael@0: #include "BufferDecoder.h" michael@0: #include "SourceBufferResource.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: class MediaSourceDecoder; michael@0: michael@0: class SubBufferDecoder : public BufferDecoder michael@0: { michael@0: public: michael@0: // This class holds a weak pointer to MediaResource. It's the responsibility michael@0: // of the caller to manage the memory of the MediaResource object. michael@0: SubBufferDecoder(MediaResource* aResource, MediaSourceDecoder* aParentDecoder) michael@0: : BufferDecoder(aResource), mParentDecoder(aParentDecoder), mReader(nullptr) michael@0: { michael@0: } michael@0: michael@0: void SetReader(MediaDecoderReader* aReader) michael@0: { michael@0: MOZ_ASSERT(!mReader); michael@0: mReader = aReader; michael@0: } michael@0: michael@0: MediaDecoderReader* GetReader() michael@0: { michael@0: return mReader; michael@0: } michael@0: michael@0: virtual ReentrantMonitor& GetReentrantMonitor() MOZ_OVERRIDE; michael@0: virtual bool OnStateMachineThread() const MOZ_OVERRIDE; michael@0: virtual bool OnDecodeThread() const MOZ_OVERRIDE; michael@0: virtual SourceBufferResource* GetResource() const MOZ_OVERRIDE; michael@0: virtual void SetMediaDuration(int64_t aDuration) MOZ_OVERRIDE; michael@0: virtual void UpdateEstimatedMediaDuration(int64_t aDuration) MOZ_OVERRIDE; michael@0: virtual void SetMediaSeekable(bool aMediaSeekable) MOZ_OVERRIDE; michael@0: virtual void SetTransportSeekable(bool aTransportSeekable) MOZ_OVERRIDE; michael@0: virtual layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE; michael@0: virtual MediaDecoderOwner* GetOwner() MOZ_OVERRIDE; michael@0: michael@0: void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) michael@0: { michael@0: mReader->NotifyDataArrived(aBuffer, aLength, aOffset); michael@0: michael@0: // XXX: Params make no sense to parent decoder as it relates to a michael@0: // specific SubBufferDecoder's data stream. Pass bogus values here to michael@0: // force parent decoder's state machine to recompute end time for michael@0: // infinite length media. michael@0: mParentDecoder->NotifyDataArrived(nullptr, 0, 0); michael@0: } michael@0: michael@0: nsresult GetBuffered(dom::TimeRanges* aBuffered) michael@0: { michael@0: // XXX: Need mStartTime (from StateMachine) instead of passing 0. michael@0: return mReader->GetBuffered(aBuffered, 0); michael@0: } michael@0: michael@0: // Given a time convert it into an approximate byte offset from the michael@0: // cached data. Returns -1 if no such value is computable. michael@0: int64_t ConvertToByteOffset(double aTime); michael@0: michael@0: int64_t GetMediaDuration() MOZ_OVERRIDE michael@0: { michael@0: return mMediaDuration; michael@0: } michael@0: michael@0: private: michael@0: MediaSourceDecoder* mParentDecoder; michael@0: nsAutoPtr mReader; michael@0: int64_t mMediaDuration; michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif /* MOZILLA_SUBBUFFERDECODER_H_ */