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_dom_SourceBuffer_h_ michael@0: #define mozilla_dom_SourceBuffer_h_ michael@0: michael@0: #include "MediaDecoderReader.h" michael@0: #include "MediaSource.h" michael@0: #include "js/RootingAPI.h" michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/dom/SourceBufferBinding.h" michael@0: #include "mozilla/dom/TypedArray.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/mozalloc.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCycleCollectionNoteChild.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsISupports.h" michael@0: #include "nsStringGlue.h" michael@0: #include "nscore.h" michael@0: michael@0: class JSObject; michael@0: struct JSContext; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class ContainerParser; michael@0: class ErrorResult; michael@0: class SourceBufferResource; michael@0: class SubBufferDecoder; michael@0: template class AsyncEventRunner; michael@0: michael@0: namespace dom { michael@0: michael@0: class TimeRanges; michael@0: michael@0: class SourceBuffer MOZ_FINAL : public DOMEventTargetHelper michael@0: { michael@0: public: michael@0: /** WebIDL Methods. */ michael@0: SourceBufferAppendMode Mode() const michael@0: { michael@0: return mAppendMode; michael@0: } michael@0: michael@0: void SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv); michael@0: michael@0: bool Updating() const michael@0: { michael@0: return mUpdating; michael@0: } michael@0: michael@0: already_AddRefed GetBuffered(ErrorResult& aRv); michael@0: michael@0: double TimestampOffset() const michael@0: { michael@0: return mTimestampOffset; michael@0: } michael@0: michael@0: void SetTimestampOffset(double aTimestampOffset, ErrorResult& aRv); michael@0: michael@0: double AppendWindowStart() const michael@0: { michael@0: return mAppendWindowStart; michael@0: } michael@0: michael@0: void SetAppendWindowStart(double aAppendWindowStart, ErrorResult& aRv); michael@0: michael@0: double AppendWindowEnd() const michael@0: { michael@0: return mAppendWindowEnd; michael@0: } michael@0: michael@0: void SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv); michael@0: michael@0: void AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv); michael@0: void AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv); michael@0: michael@0: void Abort(ErrorResult& aRv); michael@0: michael@0: void Remove(double aStart, double aEnd, ErrorResult& aRv); michael@0: /** End WebIDL Methods. */ michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBuffer, DOMEventTargetHelper) michael@0: michael@0: static already_AddRefed Create(MediaSource* aMediaSource, const nsACString& aType); michael@0: ~SourceBuffer(); michael@0: michael@0: MediaSource* GetParentObject() const; michael@0: michael@0: JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // Notify the SourceBuffer that it has been detached from the michael@0: // MediaSource's sourceBuffer list. michael@0: void Detach(); michael@0: bool IsAttached() const michael@0: { michael@0: return mMediaSource != nullptr; michael@0: } michael@0: michael@0: void Ended(); michael@0: michael@0: // Evict data in the source buffer in the given time range. michael@0: void Evict(double aStart, double aEnd); michael@0: michael@0: // Returns true if the data in the source buffer contains the given time. michael@0: bool ContainsTime(double aTime); michael@0: michael@0: private: michael@0: SourceBuffer(MediaSource* aMediaSource, const nsACString& aType); michael@0: michael@0: friend class AsyncEventRunner; michael@0: void DispatchSimpleEvent(const char* aName); michael@0: void QueueAsyncSimpleEvent(const char* aName); michael@0: michael@0: // Create a new decoder for mType, add it to mDecoders and update mCurrentDecoder. michael@0: bool InitNewDecoder(); michael@0: michael@0: // Update mUpdating and fire the appropriate events. michael@0: void StartUpdating(); michael@0: void StopUpdating(); michael@0: void AbortUpdating(); michael@0: michael@0: // Shared implementation of AppendBuffer overloads. michael@0: void AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv); michael@0: michael@0: // Provide the minimum start time and maximum end time that is available michael@0: // in the data buffered by this SourceBuffer. michael@0: void GetBufferedStartEndTime(double* aStart, double* aEnd); michael@0: michael@0: nsRefPtr mMediaSource; michael@0: michael@0: const nsAutoCString mType; michael@0: michael@0: nsAutoPtr mParser; michael@0: michael@0: // XXX: We only want to keep the current decoder alive, but need a way to michael@0: // query @buffered for everything this SourceBuffer is responsible for. michael@0: nsTArray> mDecoders; michael@0: nsRefPtr mCurrentDecoder; michael@0: michael@0: double mAppendWindowStart; michael@0: double mAppendWindowEnd; michael@0: michael@0: double mTimestampOffset; michael@0: michael@0: SourceBufferAppendMode mAppendMode; michael@0: bool mUpdating; michael@0: }; michael@0: michael@0: } // namespace dom michael@0: michael@0: } // namespace mozilla michael@0: #endif /* mozilla_dom_SourceBuffer_h_ */