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_MediaSource_h_ michael@0: #define mozilla_dom_MediaSource_h_ michael@0: michael@0: #include "MediaSourceDecoder.h" michael@0: #include "js/RootingAPI.h" michael@0: #include "mozilla/Assertions.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/dom/MediaSourceBinding.h" michael@0: #include "nsAutoPtr.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCycleCollectionNoteChild.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsID.h" michael@0: #include "nsISupports.h" michael@0: #include "nscore.h" michael@0: michael@0: struct JSContext; michael@0: class JSObject; michael@0: class nsPIDOMWindow; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class ErrorResult; michael@0: template class AsyncEventRunner; michael@0: michael@0: namespace dom { michael@0: michael@0: class GlobalObject; michael@0: class SourceBuffer; michael@0: class SourceBufferList; michael@0: template class Optional; michael@0: michael@0: #define MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID \ michael@0: { 0x3839d699, 0x22c5, 0x439f, \ michael@0: { 0x94, 0xca, 0x0e, 0x0b, 0x26, 0xf9, 0xca, 0xbf } } michael@0: michael@0: class MediaSource MOZ_FINAL : public DOMEventTargetHelper michael@0: { michael@0: public: michael@0: /** WebIDL Methods. */ michael@0: static already_AddRefed michael@0: Constructor(const GlobalObject& aGlobal, michael@0: ErrorResult& aRv); michael@0: michael@0: SourceBufferList* SourceBuffers(); michael@0: SourceBufferList* ActiveSourceBuffers(); michael@0: MediaSourceReadyState ReadyState(); michael@0: michael@0: double Duration(); michael@0: void SetDuration(double aDuration, ErrorResult& aRv); michael@0: michael@0: already_AddRefed AddSourceBuffer(const nsAString& aType, ErrorResult& aRv); michael@0: void RemoveSourceBuffer(SourceBuffer& aSourceBuffer, ErrorResult& aRv); michael@0: michael@0: void EndOfStream(const Optional& aError, ErrorResult& aRv); michael@0: static bool IsTypeSupported(const GlobalObject&, const nsAString& aType); michael@0: /** End WebIDL Methods. */ michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaSource, DOMEventTargetHelper) michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID) michael@0: michael@0: nsPIDOMWindow* GetParentObject() const; michael@0: michael@0: JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; michael@0: michael@0: // Attach this MediaSource to Decoder aDecoder. Returns false if already attached. michael@0: bool Attach(MediaSourceDecoder* aDecoder); michael@0: void Detach(); michael@0: michael@0: // Set mReadyState to aState and fire the required events at the MediaSource. michael@0: void SetReadyState(MediaSourceReadyState aState); michael@0: michael@0: // Used by SourceBuffer to call CreateSubDecoder. michael@0: MediaSourceDecoder* GetDecoder() michael@0: { michael@0: return mDecoder; michael@0: } michael@0: michael@0: // Called by SourceBuffers to notify this MediaSource that data has michael@0: // been evicted from the buffered data. The start and end times michael@0: // that were evicted are provided. michael@0: void NotifyEvicted(double aStart, double aEnd); michael@0: michael@0: private: michael@0: explicit MediaSource(nsPIDOMWindow* aWindow); 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: void DurationChange(double aNewDuration, ErrorResult& aRv); michael@0: michael@0: double mDuration; michael@0: michael@0: nsRefPtr mSourceBuffers; michael@0: nsRefPtr mActiveSourceBuffers; michael@0: michael@0: nsRefPtr mDecoder; michael@0: michael@0: MediaSourceReadyState mReadyState; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(MediaSource, MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID) michael@0: michael@0: } // namespace dom michael@0: michael@0: } // namespace mozilla michael@0: #endif /* mozilla_dom_MediaSource_h_ */