content/media/mediasource/MediaSource.h

branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
equal deleted inserted replaced
-1:000000000000 0:d2a01eadb20c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 #ifndef mozilla_dom_MediaSource_h_
8 #define mozilla_dom_MediaSource_h_
9
10 #include "MediaSourceDecoder.h"
11 #include "js/RootingAPI.h"
12 #include "mozilla/Assertions.h"
13 #include "mozilla/Attributes.h"
14 #include "mozilla/DOMEventTargetHelper.h"
15 #include "mozilla/dom/MediaSourceBinding.h"
16 #include "nsAutoPtr.h"
17 #include "nsCOMPtr.h"
18 #include "nsCycleCollectionNoteChild.h"
19 #include "nsCycleCollectionParticipant.h"
20 #include "nsID.h"
21 #include "nsISupports.h"
22 #include "nscore.h"
23
24 struct JSContext;
25 class JSObject;
26 class nsPIDOMWindow;
27
28 namespace mozilla {
29
30 class ErrorResult;
31 template <typename T> class AsyncEventRunner;
32
33 namespace dom {
34
35 class GlobalObject;
36 class SourceBuffer;
37 class SourceBufferList;
38 template <typename T> class Optional;
39
40 #define MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID \
41 { 0x3839d699, 0x22c5, 0x439f, \
42 { 0x94, 0xca, 0x0e, 0x0b, 0x26, 0xf9, 0xca, 0xbf } }
43
44 class MediaSource MOZ_FINAL : public DOMEventTargetHelper
45 {
46 public:
47 /** WebIDL Methods. */
48 static already_AddRefed<MediaSource>
49 Constructor(const GlobalObject& aGlobal,
50 ErrorResult& aRv);
51
52 SourceBufferList* SourceBuffers();
53 SourceBufferList* ActiveSourceBuffers();
54 MediaSourceReadyState ReadyState();
55
56 double Duration();
57 void SetDuration(double aDuration, ErrorResult& aRv);
58
59 already_AddRefed<SourceBuffer> AddSourceBuffer(const nsAString& aType, ErrorResult& aRv);
60 void RemoveSourceBuffer(SourceBuffer& aSourceBuffer, ErrorResult& aRv);
61
62 void EndOfStream(const Optional<MediaSourceEndOfStreamError>& aError, ErrorResult& aRv);
63 static bool IsTypeSupported(const GlobalObject&, const nsAString& aType);
64 /** End WebIDL Methods. */
65
66 NS_DECL_ISUPPORTS_INHERITED
67 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(MediaSource, DOMEventTargetHelper)
68 NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
69
70 nsPIDOMWindow* GetParentObject() const;
71
72 JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
73
74 // Attach this MediaSource to Decoder aDecoder. Returns false if already attached.
75 bool Attach(MediaSourceDecoder* aDecoder);
76 void Detach();
77
78 // Set mReadyState to aState and fire the required events at the MediaSource.
79 void SetReadyState(MediaSourceReadyState aState);
80
81 // Used by SourceBuffer to call CreateSubDecoder.
82 MediaSourceDecoder* GetDecoder()
83 {
84 return mDecoder;
85 }
86
87 // Called by SourceBuffers to notify this MediaSource that data has
88 // been evicted from the buffered data. The start and end times
89 // that were evicted are provided.
90 void NotifyEvicted(double aStart, double aEnd);
91
92 private:
93 explicit MediaSource(nsPIDOMWindow* aWindow);
94
95 friend class AsyncEventRunner<MediaSource>;
96 void DispatchSimpleEvent(const char* aName);
97 void QueueAsyncSimpleEvent(const char* aName);
98
99 void DurationChange(double aNewDuration, ErrorResult& aRv);
100
101 double mDuration;
102
103 nsRefPtr<SourceBufferList> mSourceBuffers;
104 nsRefPtr<SourceBufferList> mActiveSourceBuffers;
105
106 nsRefPtr<MediaSourceDecoder> mDecoder;
107
108 MediaSourceReadyState mReadyState;
109 };
110
111 NS_DEFINE_STATIC_IID_ACCESSOR(MediaSource, MOZILLA_DOM_MEDIASOURCE_IMPLEMENTATION_IID)
112
113 } // namespace dom
114
115 } // namespace mozilla
116 #endif /* mozilla_dom_MediaSource_h_ */

mercurial