|
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_SourceBuffer_h_ |
|
8 #define mozilla_dom_SourceBuffer_h_ |
|
9 |
|
10 #include "MediaDecoderReader.h" |
|
11 #include "MediaSource.h" |
|
12 #include "js/RootingAPI.h" |
|
13 #include "mozilla/Assertions.h" |
|
14 #include "mozilla/Attributes.h" |
|
15 #include "mozilla/dom/SourceBufferBinding.h" |
|
16 #include "mozilla/dom/TypedArray.h" |
|
17 #include "mozilla/DOMEventTargetHelper.h" |
|
18 #include "mozilla/mozalloc.h" |
|
19 #include "nsAutoPtr.h" |
|
20 #include "nsCOMPtr.h" |
|
21 #include "nsCycleCollectionNoteChild.h" |
|
22 #include "nsCycleCollectionParticipant.h" |
|
23 #include "nsISupports.h" |
|
24 #include "nsStringGlue.h" |
|
25 #include "nscore.h" |
|
26 |
|
27 class JSObject; |
|
28 struct JSContext; |
|
29 |
|
30 namespace mozilla { |
|
31 |
|
32 class ContainerParser; |
|
33 class ErrorResult; |
|
34 class SourceBufferResource; |
|
35 class SubBufferDecoder; |
|
36 template <typename T> class AsyncEventRunner; |
|
37 |
|
38 namespace dom { |
|
39 |
|
40 class TimeRanges; |
|
41 |
|
42 class SourceBuffer MOZ_FINAL : public DOMEventTargetHelper |
|
43 { |
|
44 public: |
|
45 /** WebIDL Methods. */ |
|
46 SourceBufferAppendMode Mode() const |
|
47 { |
|
48 return mAppendMode; |
|
49 } |
|
50 |
|
51 void SetMode(SourceBufferAppendMode aMode, ErrorResult& aRv); |
|
52 |
|
53 bool Updating() const |
|
54 { |
|
55 return mUpdating; |
|
56 } |
|
57 |
|
58 already_AddRefed<TimeRanges> GetBuffered(ErrorResult& aRv); |
|
59 |
|
60 double TimestampOffset() const |
|
61 { |
|
62 return mTimestampOffset; |
|
63 } |
|
64 |
|
65 void SetTimestampOffset(double aTimestampOffset, ErrorResult& aRv); |
|
66 |
|
67 double AppendWindowStart() const |
|
68 { |
|
69 return mAppendWindowStart; |
|
70 } |
|
71 |
|
72 void SetAppendWindowStart(double aAppendWindowStart, ErrorResult& aRv); |
|
73 |
|
74 double AppendWindowEnd() const |
|
75 { |
|
76 return mAppendWindowEnd; |
|
77 } |
|
78 |
|
79 void SetAppendWindowEnd(double aAppendWindowEnd, ErrorResult& aRv); |
|
80 |
|
81 void AppendBuffer(const ArrayBuffer& aData, ErrorResult& aRv); |
|
82 void AppendBuffer(const ArrayBufferView& aData, ErrorResult& aRv); |
|
83 |
|
84 void Abort(ErrorResult& aRv); |
|
85 |
|
86 void Remove(double aStart, double aEnd, ErrorResult& aRv); |
|
87 /** End WebIDL Methods. */ |
|
88 |
|
89 NS_DECL_ISUPPORTS_INHERITED |
|
90 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SourceBuffer, DOMEventTargetHelper) |
|
91 |
|
92 static already_AddRefed<SourceBuffer> Create(MediaSource* aMediaSource, const nsACString& aType); |
|
93 ~SourceBuffer(); |
|
94 |
|
95 MediaSource* GetParentObject() const; |
|
96 |
|
97 JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
98 |
|
99 // Notify the SourceBuffer that it has been detached from the |
|
100 // MediaSource's sourceBuffer list. |
|
101 void Detach(); |
|
102 bool IsAttached() const |
|
103 { |
|
104 return mMediaSource != nullptr; |
|
105 } |
|
106 |
|
107 void Ended(); |
|
108 |
|
109 // Evict data in the source buffer in the given time range. |
|
110 void Evict(double aStart, double aEnd); |
|
111 |
|
112 // Returns true if the data in the source buffer contains the given time. |
|
113 bool ContainsTime(double aTime); |
|
114 |
|
115 private: |
|
116 SourceBuffer(MediaSource* aMediaSource, const nsACString& aType); |
|
117 |
|
118 friend class AsyncEventRunner<SourceBuffer>; |
|
119 void DispatchSimpleEvent(const char* aName); |
|
120 void QueueAsyncSimpleEvent(const char* aName); |
|
121 |
|
122 // Create a new decoder for mType, add it to mDecoders and update mCurrentDecoder. |
|
123 bool InitNewDecoder(); |
|
124 |
|
125 // Update mUpdating and fire the appropriate events. |
|
126 void StartUpdating(); |
|
127 void StopUpdating(); |
|
128 void AbortUpdating(); |
|
129 |
|
130 // Shared implementation of AppendBuffer overloads. |
|
131 void AppendData(const uint8_t* aData, uint32_t aLength, ErrorResult& aRv); |
|
132 |
|
133 // Provide the minimum start time and maximum end time that is available |
|
134 // in the data buffered by this SourceBuffer. |
|
135 void GetBufferedStartEndTime(double* aStart, double* aEnd); |
|
136 |
|
137 nsRefPtr<MediaSource> mMediaSource; |
|
138 |
|
139 const nsAutoCString mType; |
|
140 |
|
141 nsAutoPtr<ContainerParser> mParser; |
|
142 |
|
143 // XXX: We only want to keep the current decoder alive, but need a way to |
|
144 // query @buffered for everything this SourceBuffer is responsible for. |
|
145 nsTArray<nsRefPtr<SubBufferDecoder>> mDecoders; |
|
146 nsRefPtr<SubBufferDecoder> mCurrentDecoder; |
|
147 |
|
148 double mAppendWindowStart; |
|
149 double mAppendWindowEnd; |
|
150 |
|
151 double mTimestampOffset; |
|
152 |
|
153 SourceBufferAppendMode mAppendMode; |
|
154 bool mUpdating; |
|
155 }; |
|
156 |
|
157 } // namespace dom |
|
158 |
|
159 } // namespace mozilla |
|
160 #endif /* mozilla_dom_SourceBuffer_h_ */ |