OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 18 matching lines...) Expand all Loading... | |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/mediasource/MediaSourceBase.h" | 32 #include "modules/mediasource/MediaSourceBase.h" |
33 | 33 |
34 #include "bindings/v8/ExceptionState.h" | 34 #include "bindings/v8/ExceptionState.h" |
35 #include "bindings/v8/ExceptionStatePlaceholder.h" | 35 #include "bindings/v8/ExceptionStatePlaceholder.h" |
36 #include "core/dom/ExceptionCode.h" | 36 #include "core/dom/ExceptionCode.h" |
37 #include "core/events/Event.h" | 37 #include "core/events/Event.h" |
38 #include "core/events/GenericEventQueue.h" | 38 #include "core/events/GenericEventQueue.h" |
39 #include "core/platform/graphics/SourceBufferPrivate.h" | 39 #include "core/html/TimeRanges.h" |
40 #include "modules/mediasource/MediaSourceRegistry.h" | 40 #include "modules/mediasource/MediaSourceRegistry.h" |
41 #include "platform/Logging.h" | 41 #include "platform/Logging.h" |
42 #include "platform/TraceEvent.h" | 42 #include "platform/TraceEvent.h" |
43 #include "public/platform/WebMediaSource.h" | |
44 #include "public/platform/WebSourceBuffer.h" | |
43 #include "wtf/text/WTFString.h" | 45 #include "wtf/text/WTFString.h" |
44 | 46 |
47 using blink::WebMediaSource; | |
48 using blink::WebSourceBuffer; | |
49 | |
45 namespace WebCore { | 50 namespace WebCore { |
46 | 51 |
47 MediaSourceBase::MediaSourceBase(ExecutionContext* context) | 52 MediaSourceBase::MediaSourceBase(ExecutionContext* context) |
48 : ActiveDOMObject(context) | 53 : ActiveDOMObject(context) |
49 , m_readyState(closedKeyword()) | 54 , m_readyState(closedKeyword()) |
50 , m_asyncEventQueue(GenericEventQueue::create(this)) | 55 , m_asyncEventQueue(GenericEventQueue::create(this)) |
51 , m_attachedElement(0) | 56 , m_attachedElement(0) |
52 { | 57 { |
53 } | 58 } |
54 | 59 |
(...skipping 12 matching lines...) Expand all Loading... | |
67 DEFINE_STATIC_LOCAL(const AtomicString, closed, ("closed", AtomicString::Con structFromLiteral)); | 72 DEFINE_STATIC_LOCAL(const AtomicString, closed, ("closed", AtomicString::Con structFromLiteral)); |
68 return closed; | 73 return closed; |
69 } | 74 } |
70 | 75 |
71 const AtomicString& MediaSourceBase::endedKeyword() | 76 const AtomicString& MediaSourceBase::endedKeyword() |
72 { | 77 { |
73 DEFINE_STATIC_LOCAL(const AtomicString, ended, ("ended", AtomicString::Const ructFromLiteral)); | 78 DEFINE_STATIC_LOCAL(const AtomicString, ended, ("ended", AtomicString::Const ructFromLiteral)); |
74 return ended; | 79 return ended; |
75 } | 80 } |
76 | 81 |
77 void MediaSourceBase::setPrivateAndOpen(PassOwnPtr<MediaSourcePrivate> mediaSour cePrivate) | 82 void MediaSourceBase::setWebMediaSourceAndOpen(PassOwnPtr<WebMediaSource> webMed iaSource) |
78 { | 83 { |
79 TRACE_EVENT_ASYNC_END0("media", "MediaSourceBase::attachToElement", this); | 84 TRACE_EVENT_ASYNC_END0("media", "MediaSourceBase::attachToElement", this); |
80 ASSERT(mediaSourcePrivate); | 85 ASSERT(webMediaSource); |
81 ASSERT(!m_private); | 86 ASSERT(!m_webMediaSource); |
82 ASSERT(m_attachedElement); | 87 ASSERT(m_attachedElement); |
83 m_private = mediaSourcePrivate; | 88 m_webMediaSource = webMediaSource; |
84 setReadyState(openKeyword()); | 89 setReadyState(openKeyword()); |
85 } | 90 } |
86 | 91 |
87 void MediaSourceBase::addedToRegistry() | 92 void MediaSourceBase::addedToRegistry() |
88 { | 93 { |
89 setPendingActivity(this); | 94 setPendingActivity(this); |
90 } | 95 } |
91 | 96 |
92 void MediaSourceBase::removedFromRegistry() | 97 void MediaSourceBase::removedFromRegistry() |
93 { | 98 { |
94 unsetPendingActivity(this); | 99 unsetPendingActivity(this); |
95 } | 100 } |
96 | 101 |
97 double MediaSourceBase::duration() const | 102 double MediaSourceBase::duration() const |
98 { | 103 { |
99 return isClosed() ? std::numeric_limits<float>::quiet_NaN() : m_private->dur ation(); | 104 return isClosed() ? std::numeric_limits<float>::quiet_NaN() : m_webMediaSour ce->duration(); |
100 } | 105 } |
101 | 106 |
102 PassRefPtr<TimeRanges> MediaSourceBase::buffered() const | 107 PassRefPtr<TimeRanges> MediaSourceBase::buffered() const |
103 { | 108 { |
104 // Implements MediaSource algorithm for HTMLMediaElement.buffered. | 109 // Implements MediaSource algorithm for HTMLMediaElement.buffered. |
105 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#htmlmediaelement-extensions | 110 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#htmlmediaelement-extensions |
106 Vector<RefPtr<TimeRanges> > ranges = activeRanges(); | 111 Vector<RefPtr<TimeRanges> > ranges = activeRanges(); |
107 | 112 |
108 // 1. If activeSourceBuffers.length equals 0 then return an empty TimeRanges object and abort these steps. | 113 // 1. If activeSourceBuffers.length equals 0 then return an empty TimeRanges object and abort these steps. |
109 if (ranges.isEmpty()) | 114 if (ranges.isEmpty()) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 return; | 155 return; |
151 } | 156 } |
152 if (!isOpen()) { | 157 if (!isOpen()) { |
153 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 158 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
154 return; | 159 return; |
155 } | 160 } |
156 | 161 |
157 // Synchronously process duration change algorithm to enforce any required | 162 // Synchronously process duration change algorithm to enforce any required |
158 // seek is started prior to returning. | 163 // seek is started prior to returning. |
159 m_attachedElement->durationChanged(duration); | 164 m_attachedElement->durationChanged(duration); |
160 m_private->setDuration(duration); | 165 m_webMediaSource->setDuration(duration); |
161 } | 166 } |
162 | 167 |
163 | 168 |
164 void MediaSourceBase::setReadyState(const AtomicString& state) | 169 void MediaSourceBase::setReadyState(const AtomicString& state) |
165 { | 170 { |
166 ASSERT(state == openKeyword() || state == closedKeyword() || state == endedK eyword()); | 171 ASSERT(state == openKeyword() || state == closedKeyword() || state == endedK eyword()); |
167 | 172 |
168 AtomicString oldState = readyState(); | 173 AtomicString oldState = readyState(); |
169 LOG(Media, "MediaSourceBase::setReadyState() %p : %s -> %s", this, oldState. string().ascii().data(), state.string().ascii().data()); | 174 LOG(Media, "MediaSourceBase::setReadyState() %p : %s -> %s", this, oldState. string().ascii().data(), state.string().ascii().data()); |
170 | 175 |
171 if (state == closedKeyword()) { | 176 if (state == closedKeyword()) { |
172 m_private.clear(); | 177 m_webMediaSource.clear(); |
173 m_attachedElement = 0; | 178 m_attachedElement = 0; |
174 } | 179 } |
175 | 180 |
176 if (oldState == state) | 181 if (oldState == state) |
177 return; | 182 return; |
178 | 183 |
179 m_readyState = state; | 184 m_readyState = state; |
180 | 185 |
181 onReadyStateChange(oldState, state); | 186 onReadyStateChange(oldState, state); |
182 } | 187 } |
183 | 188 |
184 void MediaSourceBase::endOfStream(const AtomicString& error, ExceptionState& es) | 189 void MediaSourceBase::endOfStream(const AtomicString& error, ExceptionState& es) |
185 { | 190 { |
186 DEFINE_STATIC_LOCAL(const AtomicString, network, ("network", AtomicString::C onstructFromLiteral)); | 191 DEFINE_STATIC_LOCAL(const AtomicString, network, ("network", AtomicString::C onstructFromLiteral)); |
187 DEFINE_STATIC_LOCAL(const AtomicString, decode, ("decode", AtomicString::Con structFromLiteral)); | 192 DEFINE_STATIC_LOCAL(const AtomicString, decode, ("decode", AtomicString::Con structFromLiteral)); |
188 | 193 |
189 // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-sour ce.html#dom-endofstream | 194 // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-sour ce.html#dom-endofstream |
190 // 1. If the readyState attribute is not in the "open" state then throw an | 195 // 1. If the readyState attribute is not in the "open" state then throw an |
191 // InvalidStateError exception and abort these steps. | 196 // InvalidStateError exception and abort these steps. |
192 if (!isOpen()) { | 197 if (!isOpen()) { |
193 es.throwUninformativeAndGenericDOMException(InvalidStateError); | 198 es.throwUninformativeAndGenericDOMException(InvalidStateError); |
194 return; | 199 return; |
195 } | 200 } |
196 | 201 |
197 MediaSourcePrivate::EndOfStreamStatus eosStatus = MediaSourcePrivate::EosNoE rror; | 202 WebMediaSource::EndOfStreamStatus eosStatus = WebMediaSource::EndOfStreamSta tusNoError; |
198 | 203 |
199 if (error.isNull() || error.isEmpty()) { | 204 if (error.isNull() || error.isEmpty()) { |
200 eosStatus = MediaSourcePrivate::EosNoError; | 205 eosStatus = WebMediaSource::EndOfStreamStatusNoError; |
201 } else if (error == network) { | 206 } else if (error == network) { |
202 eosStatus = MediaSourcePrivate::EosNetworkError; | 207 eosStatus = WebMediaSource::EndOfStreamStatusNetworkError; |
203 } else if (error == decode) { | 208 } else if (error == decode) { |
204 eosStatus = MediaSourcePrivate::EosDecodeError; | 209 eosStatus = WebMediaSource::EndOfStreamStatusDecodeError; |
205 } else { | 210 } else { |
206 es.throwUninformativeAndGenericDOMException(InvalidAccessError); | 211 es.throwUninformativeAndGenericDOMException(InvalidAccessError); |
207 return; | 212 return; |
208 } | 213 } |
209 | 214 |
210 // 2. Change the readyState attribute value to "ended". | 215 // 2. Change the readyState attribute value to "ended". |
211 setReadyState(endedKeyword()); | 216 setReadyState(endedKeyword()); |
212 m_private->markEndOfStream(eosStatus); | 217 m_webMediaSource->markEndOfStream(eosStatus); |
213 } | 218 } |
214 | 219 |
215 bool MediaSourceBase::isOpen() const | 220 bool MediaSourceBase::isOpen() const |
216 { | 221 { |
217 return readyState() == openKeyword(); | 222 return readyState() == openKeyword(); |
218 } | 223 } |
219 | 224 |
220 bool MediaSourceBase::isClosed() const | 225 bool MediaSourceBase::isClosed() const |
221 { | 226 { |
222 return readyState() == closedKeyword(); | 227 return readyState() == closedKeyword(); |
(...skipping 15 matching lines...) Expand all Loading... | |
238 m_attachedElement = element; | 243 m_attachedElement = element; |
239 return true; | 244 return true; |
240 } | 245 } |
241 | 246 |
242 void MediaSourceBase::openIfInEndedState() | 247 void MediaSourceBase::openIfInEndedState() |
243 { | 248 { |
244 if (m_readyState != endedKeyword()) | 249 if (m_readyState != endedKeyword()) |
245 return; | 250 return; |
246 | 251 |
247 setReadyState(openKeyword()); | 252 setReadyState(openKeyword()); |
248 m_private->unmarkEndOfStream(); | 253 m_webMediaSource->unmarkEndOfStream(); |
249 } | 254 } |
250 | 255 |
251 bool MediaSourceBase::hasPendingActivity() const | 256 bool MediaSourceBase::hasPendingActivity() const |
252 { | 257 { |
253 return m_private || m_asyncEventQueue->hasPendingEvents() | 258 return m_webMediaSource || m_asyncEventQueue->hasPendingEvents() |
254 || ActiveDOMObject::hasPendingActivity(); | 259 || ActiveDOMObject::hasPendingActivity(); |
255 } | 260 } |
256 | 261 |
257 void MediaSourceBase::stop() | 262 void MediaSourceBase::stop() |
258 { | 263 { |
259 m_asyncEventQueue->close(); | 264 m_asyncEventQueue->close(); |
260 if (!isClosed()) | 265 if (!isClosed()) |
261 setReadyState(closedKeyword()); | 266 setReadyState(closedKeyword()); |
262 m_private.clear(); | 267 m_webMediaSource.clear(); |
263 } | 268 } |
264 | 269 |
265 PassOwnPtr<SourceBufferPrivate> MediaSourceBase::createSourceBufferPrivate(const String& type, const MediaSourcePrivate::CodecsArray& codecs, ExceptionState& es ) | 270 PassOwnPtr<WebSourceBuffer> MediaSourceBase::createWebSourceBuffer(const String& type, const Vector<String>& codecs, ExceptionState& es) |
266 { | 271 { |
267 OwnPtr<SourceBufferPrivate> sourceBufferPrivate; | 272 WebSourceBuffer* webSourceBuffer = 0; |
268 switch (m_private->addSourceBuffer(type, codecs, &sourceBufferPrivate)) { | 273 switch (m_webMediaSource->addSourceBuffer(type, codecs, &webSourceBuffer)) { |
269 case MediaSourcePrivate::Ok: { | 274 case WebMediaSource::AddStatusOk: |
270 return sourceBufferPrivate.release(); | 275 return adoptPtr(webSourceBuffer); |
271 } | 276 case WebMediaSource::AddStatusNotSupported: |
adamk
2013/11/12 20:59:19
Can you add ASSERT(!webSourceBuffer) here and...
philipj_slow
2013/11/12 22:13:46
Done.
| |
272 case MediaSourcePrivate::NotSupported: | |
273 // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/m edia-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type | 277 // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/m edia-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type |
274 // Step 2: If type contains a MIME type ... that is not supported with t he types | 278 // Step 2: If type contains a MIME type ... that is not supported with t he types |
275 // specified for the other SourceBuffer objects in sourceBuffers, then t hrow | 279 // specified for the other SourceBuffer objects in sourceBuffers, then t hrow |
276 // a NotSupportedError exception and abort these steps. | 280 // a NotSupportedError exception and abort these steps. |
277 es.throwUninformativeAndGenericDOMException(NotSupportedError); | 281 es.throwUninformativeAndGenericDOMException(NotSupportedError); |
278 return nullptr; | 282 return nullptr; |
279 case MediaSourcePrivate::ReachedIdLimit: | 283 case WebMediaSource::AddStatusReachedIdLimit: |
adamk
2013/11/12 20:59:19
...here too? That gives us back some of the safety
philipj_slow
2013/11/12 22:13:46
Done.
| |
280 // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/m edia-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type | 284 // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/m edia-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type |
281 // Step 3: If the user agent can't handle any more SourceBuffer objects then throw | 285 // Step 3: If the user agent can't handle any more SourceBuffer objects then throw |
282 // a QuotaExceededError exception and abort these steps. | 286 // a QuotaExceededError exception and abort these steps. |
283 es.throwUninformativeAndGenericDOMException(QuotaExceededError); | 287 es.throwUninformativeAndGenericDOMException(QuotaExceededError); |
284 return nullptr; | 288 return nullptr; |
285 } | 289 } |
286 | 290 |
287 ASSERT_NOT_REACHED(); | 291 ASSERT_NOT_REACHED(); |
288 return nullptr; | 292 return nullptr; |
289 } | 293 } |
(...skipping 12 matching lines...) Expand all Loading... | |
302 { | 306 { |
303 return ActiveDOMObject::executionContext(); | 307 return ActiveDOMObject::executionContext(); |
304 } | 308 } |
305 | 309 |
306 URLRegistry& MediaSourceBase::registry() const | 310 URLRegistry& MediaSourceBase::registry() const |
307 { | 311 { |
308 return MediaSourceRegistry::registry(); | 312 return MediaSourceRegistry::registry(); |
309 } | 313 } |
310 | 314 |
311 } | 315 } |
OLD | NEW |