2 * Copyright (C) 2013 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "modules/mediasource/SourceBuffer.h"
34 #include "bindings/v8/ExceptionState.h"
35 #include "core/dom/ExceptionCode.h"
36 #include "core/dom/ExecutionContext.h"
37 #include "core/events/Event.h"
38 #include "core/events/GenericEventQueue.h"
39 #include "core/fileapi/FileReaderLoader.h"
40 #include "core/fileapi/Stream.h"
41 #include "core/html/TimeRanges.h"
42 #include "modules/mediasource/MediaSource.h"
43 #include "platform/Logging.h"
44 #include "platform/TraceEvent.h"
45 #include "public/platform/WebSourceBuffer.h"
46 #include "wtf/ArrayBuffer.h"
47 #include "wtf/ArrayBufferView.h"
48 #include "wtf/MathExtras.h"
52 using blink::WebSourceBuffer;
56 PassRefPtr<SourceBuffer> SourceBuffer::create(PassOwnPtr<WebSourceBuffer> webSourceBuffer, MediaSource* source, GenericEventQueue* asyncEventQueue)
58 RefPtr<SourceBuffer> sourceBuffer(adoptRef(new SourceBuffer(webSourceBuffer, source, asyncEventQueue)));
59 sourceBuffer->suspendIfNeeded();
60 return sourceBuffer.release();
63 SourceBuffer::SourceBuffer(PassOwnPtr<WebSourceBuffer> webSourceBuffer, MediaSource* source, GenericEventQueue* asyncEventQueue)
64 : ActiveDOMObject(source->executionContext())
65 , m_webSourceBuffer(webSourceBuffer)
67 , m_asyncEventQueue(asyncEventQueue)
68 , m_mode(segmentsKeyword())
70 , m_timestampOffset(0)
71 , m_appendWindowStart(0)
72 , m_appendWindowEnd(std::numeric_limits<double>::infinity())
73 , m_appendBufferAsyncPartRunner(this, &SourceBuffer::appendBufferAsyncPart)
74 , m_pendingRemoveStart(-1)
75 , m_pendingRemoveEnd(-1)
76 , m_removeAsyncPartRunner(this, &SourceBuffer::removeAsyncPart)
77 , m_streamMaxSizeValid(false)
79 , m_appendStreamAsyncPartRunner(this, &SourceBuffer::appendStreamAsyncPart)
81 ASSERT(m_webSourceBuffer);
83 ScriptWrappable::init(this);
86 SourceBuffer::~SourceBuffer()
93 const AtomicString& SourceBuffer::segmentsKeyword()
95 DEFINE_STATIC_LOCAL(const AtomicString, segments, ("segments", AtomicString::ConstructFromLiteral));
99 const AtomicString& SourceBuffer::sequenceKeyword()
101 DEFINE_STATIC_LOCAL(const AtomicString, sequence, ("sequence", AtomicString::ConstructFromLiteral));
105 void SourceBuffer::setMode(const AtomicString& newMode, ExceptionState& exceptionState)
107 // Section 3.1 On setting mode attribute steps.
108 // 1. Let new mode equal the new value being assigned to this attribute.
109 // 2. If new mode does not equal "segments" or "sequence", then throw an INVALID_ACCESS_ERR exception and abort
111 if (newMode != segmentsKeyword() && newMode != sequenceKeyword()) {
112 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessError);
116 // 3. If this object has been removed from the sourceBuffers attribute of the parent media source, then throw
117 // an INVALID_STATE_ERR exception and abort these steps.
118 // 4. If the updating attribute equals true, then throw an INVALID_STATE_ERR exception and abort these steps.
119 if (isRemoved() || m_updating) {
120 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
124 // 5. If the readyState attribute of the parent media source is in the "ended" state then run the following steps:
125 // 5.1 Set the readyState attribute of the parent media source to "open"
126 // 5.2 Queue a task to fire a simple event named sourceopen at the parent media source.
127 m_source->openIfInEndedState();
129 // 6. If the append state equals PARSING_MEDIA_SEGMENT, then throw an INVALID_STATE_ERR and abort these steps.
130 // 7. If the new mode equals "sequence", then set the group start timestamp to the highest presentation end timestamp.
131 WebSourceBuffer::AppendMode appendMode = WebSourceBuffer::AppendModeSegments;
132 if (newMode == sequenceKeyword())
133 appendMode = WebSourceBuffer::AppendModeSequence;
134 if (!m_webSourceBuffer->setMode(appendMode)) {
135 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
139 // 8. Update the attribute to new mode.
143 PassRefPtr<TimeRanges> SourceBuffer::buffered(ExceptionState& exceptionState) const
145 // Section 3.1 buffered attribute steps.
146 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an
147 // InvalidStateError exception and abort these steps.
149 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
153 // 2. Return a new static normalized TimeRanges object for the media segments buffered.
154 return TimeRanges::create(m_webSourceBuffer->buffered());
157 double SourceBuffer::timestampOffset() const
159 return m_timestampOffset;
162 void SourceBuffer::setTimestampOffset(double offset, ExceptionState& exceptionState)
164 // Section 3.1 timestampOffset attribute setter steps.
165 // 1. Let new timestamp offset equal the new value being assigned to this attribute.
166 // 2. If this object has been removed from the sourceBuffers attribute of the parent media source, then throw an
167 // InvalidStateError exception and abort these steps.
168 // 3. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
169 if (isRemoved() || m_updating) {
170 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
174 // 4. If the readyState attribute of the parent media source is in the "ended" state then run the following steps:
175 // 4.1 Set the readyState attribute of the parent media source to "open"
176 // 4.2 Queue a task to fire a simple event named sourceopen at the parent media source.
177 m_source->openIfInEndedState();
179 // 5. If the append state equals PARSING_MEDIA_SEGMENT, then throw an INVALID_STATE_ERR and abort these steps.
180 // 6. If the mode attribute equals "sequence", then set the group start timestamp to new timestamp offset.
181 if (!m_webSourceBuffer->setTimestampOffset(offset)) {
182 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
186 // 7. Update the attribute to new timestamp offset.
187 m_timestampOffset = offset;
190 double SourceBuffer::appendWindowStart() const
192 return m_appendWindowStart;
195 void SourceBuffer::setAppendWindowStart(double start, ExceptionState& exceptionState)
197 // Enforce throwing an exception on restricted double values.
198 if (std::isnan(start)
199 || start == std::numeric_limits<double>::infinity()
200 || start == -std::numeric_limits<double>::infinity()) {
201 exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchError);
205 // Section 3.1 appendWindowStart attribute setter steps.
206 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an
207 // InvalidStateError exception and abort these steps.
208 // 2. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
209 if (isRemoved() || m_updating) {
210 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
214 // 3. If the new value is less than 0 or greater than or equal to appendWindowEnd then throw an InvalidAccessError
215 // exception and abort these steps.
216 if (start < 0 || start >= m_appendWindowEnd) {
217 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessError);
221 m_webSourceBuffer->setAppendWindowStart(start);
223 // 4. Update the attribute to the new value.
224 m_appendWindowStart = start;
227 double SourceBuffer::appendWindowEnd() const
229 return m_appendWindowEnd;
232 void SourceBuffer::setAppendWindowEnd(double end, ExceptionState& exceptionState)
234 // Section 3.1 appendWindowEnd attribute setter steps.
235 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an
236 // InvalidStateError exception and abort these steps.
237 // 2. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
238 if (isRemoved() || m_updating) {
239 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
243 // 3. If the new value equals NaN, then throw an InvalidAccessError and abort these steps.
244 // 4. If the new value is less than or equal to appendWindowStart then throw an InvalidAccessError
245 // exception and abort these steps.
246 if (std::isnan(end) || end <= m_appendWindowStart) {
247 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessError);
251 m_webSourceBuffer->setAppendWindowEnd(end);
253 // 5. Update the attribute to the new value.
254 m_appendWindowEnd = end;
257 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionState& exceptionState)
259 // Section 3.2 appendBuffer()
260 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
261 // 1. If data is null then throw an InvalidAccessError exception and abort these steps.
263 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessError);
267 appendBufferInternal(static_cast<const unsigned char*>(data->data()), data->byteLength(), exceptionState);
270 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBufferView> data, ExceptionState& exceptionState)
272 // Section 3.2 appendBuffer()
273 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
274 // 1. If data is null then throw an InvalidAccessError exception and abort these steps.
276 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessError);
280 appendBufferInternal(static_cast<const unsigned char*>(data->baseAddress()), data->byteLength(), exceptionState);
283 void SourceBuffer::appendStream(PassRefPtr<Stream> stream, ExceptionState& exceptionState)
285 m_streamMaxSizeValid = false;
286 appendStreamInternal(stream, exceptionState);
289 void SourceBuffer::appendStream(PassRefPtr<Stream> stream, unsigned long long maxSize, ExceptionState& exceptionState)
291 m_streamMaxSizeValid = maxSize > 0;
292 if (m_streamMaxSizeValid)
293 m_streamMaxSize = maxSize;
294 appendStreamInternal(stream, exceptionState);
297 void SourceBuffer::abort(ExceptionState& exceptionState)
299 // Section 3.2 abort() method steps.
300 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-abort-void
301 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source
302 // then throw an InvalidStateError exception and abort these steps.
303 // 2. If the readyState attribute of the parent media source is not in the "open" state
304 // then throw an InvalidStateError exception and abort these steps.
305 if (isRemoved() || !m_source->isOpen()) {
306 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
310 // 3. If the sourceBuffer.updating attribute equals true, then run the following steps: ...
313 // 4. Run the reset parser state algorithm.
314 m_webSourceBuffer->abort();
316 // 5. Set appendWindowStart to 0.
317 setAppendWindowStart(0, exceptionState);
319 // 6. Set appendWindowEnd to positive Infinity.
320 setAppendWindowEnd(std::numeric_limits<double>::infinity(), exceptionState);
323 void SourceBuffer::remove(double start, double end, ExceptionState& exceptionState)
325 // Section 3.2 remove() method steps.
326 // 1. If start is negative or greater than duration, then throw an InvalidAccessError exception and abort these steps.
327 // 2. If end is less than or equal to start, then throw an InvalidAccessError exception and abort these steps.
328 if (start < 0 || (m_source && (std::isnan(m_source->duration()) || start > m_source->duration())) || end <= start) {
329 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessError);
333 // 3. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an
334 // InvalidStateError exception and abort these steps.
335 // 4. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
336 if (isRemoved() || m_updating) {
337 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
341 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::remove", this);
343 // 5. If the readyState attribute of the parent media source is in the "ended" state then run the following steps:
344 // 5.1. Set the readyState attribute of the parent media source to "open"
345 // 5.2. Queue a task to fire a simple event named sourceopen at the parent media source .
346 m_source->openIfInEndedState();
348 // 6. Set the updating attribute to true.
351 // 7. Queue a task to fire a simple event named updatestart at this SourceBuffer object.
352 scheduleEvent(EventTypeNames::updatestart);
354 // 8. Return control to the caller and run the rest of the steps asynchronously.
355 m_pendingRemoveStart = start;
356 m_pendingRemoveEnd = end;
357 m_removeAsyncPartRunner.runAsync();
360 void SourceBuffer::abortIfUpdating()
362 // Section 3.2 abort() method step 3 substeps.
363 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-abort-void
368 const char* traceEventName = 0;
369 if (!m_pendingAppendData.isEmpty()) {
370 traceEventName = "SourceBuffer::appendBuffer";
371 } else if (m_stream) {
372 traceEventName = "SourceBuffer::appendStream";
373 } else if (m_pendingRemoveStart != -1) {
374 traceEventName = "SourceBuffer::remove";
376 ASSERT_NOT_REACHED();
379 // 3.1. Abort the buffer append and stream append loop algorithms if they are running.
380 m_appendBufferAsyncPartRunner.stop();
381 m_pendingAppendData.clear();
383 m_removeAsyncPartRunner.stop();
384 m_pendingRemoveStart = -1;
385 m_pendingRemoveEnd = -1;
387 m_appendStreamAsyncPartRunner.stop();
388 clearAppendStreamState();
390 // 3.2. Set the updating attribute to false.
393 // 3.3. Queue a task to fire a simple event named abort at this SourceBuffer object.
394 scheduleEvent(EventTypeNames::abort);
396 // 3.4. Queue a task to fire a simple event named updateend at this SourceBuffer object.
397 scheduleEvent(EventTypeNames::updateend);
399 TRACE_EVENT_ASYNC_END0("media", traceEventName, this);
402 void SourceBuffer::removedFromMediaSource()
409 m_webSourceBuffer->removedFromMediaSource();
410 m_webSourceBuffer.clear();
412 m_asyncEventQueue = 0;
415 bool SourceBuffer::hasPendingActivity() const
420 void SourceBuffer::suspend()
422 m_appendBufferAsyncPartRunner.suspend();
423 m_removeAsyncPartRunner.suspend();
424 m_appendStreamAsyncPartRunner.suspend();
427 void SourceBuffer::resume()
429 m_appendBufferAsyncPartRunner.resume();
430 m_removeAsyncPartRunner.resume();
431 m_appendStreamAsyncPartRunner.resume();
434 void SourceBuffer::stop()
436 m_appendBufferAsyncPartRunner.stop();
437 m_removeAsyncPartRunner.stop();
438 m_appendStreamAsyncPartRunner.stop();
441 ExecutionContext* SourceBuffer::executionContext() const
443 return ActiveDOMObject::executionContext();
446 const AtomicString& SourceBuffer::interfaceName() const
448 return EventTargetNames::SourceBuffer;
451 bool SourceBuffer::isRemoved() const
456 void SourceBuffer::scheduleEvent(const AtomicString& eventName)
458 ASSERT(m_asyncEventQueue);
460 RefPtr<Event> event = Event::create(eventName);
461 event->setTarget(this);
463 m_asyncEventQueue->enqueueEvent(event.release());
466 void SourceBuffer::appendBufferInternal(const unsigned char* data, unsigned size, ExceptionState& exceptionState)
468 // Section 3.2 appendBuffer()
469 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data
471 // Step 1 is enforced by the caller.
472 // 2. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an InvalidStateError exception and abort these steps.
473 // 3. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
474 if (isRemoved() || m_updating) {
475 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
479 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendBuffer", this);
481 // 4. If the readyState attribute of the parent media source is in the "ended" state then run the following steps: ...
482 m_source->openIfInEndedState();
486 // 7. Add data to the end of the input buffer.
487 m_pendingAppendData.append(data, size);
489 // 8. Set the updating attribute to true.
492 // 9. Queue a task to fire a simple event named updatestart at this SourceBuffer object.
493 scheduleEvent(EventTypeNames::updatestart);
495 // 10. Asynchronously run the buffer append algorithm.
496 m_appendBufferAsyncPartRunner.runAsync();
498 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, "waiting");
501 void SourceBuffer::appendBufferAsyncPart()
505 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, "appending");
507 // Section 3.5.4 Buffer Append Algorithm
508 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#sourcebuffer-buffer-append
510 // 1. Run the segment parser loop algorithm.
511 // Step 2 doesn't apply since we run Step 1 synchronously here.
512 size_t appendSize = m_pendingAppendData.size();
514 // Resize buffer for 0 byte appends so we always have a valid pointer.
515 // We need to convey all appends, even 0 byte ones to |m_webSourceBuffer|
516 // so that it can clear its end of stream state if necessary.
517 m_pendingAppendData.resize(1);
519 m_webSourceBuffer->append(m_pendingAppendData.data(), appendSize);
521 // 3. Set the updating attribute to false.
523 m_pendingAppendData.clear();
525 // 4. Queue a task to fire a simple event named update at this SourceBuffer object.
526 scheduleEvent(EventTypeNames::update);
528 // 5. Queue a task to fire a simple event named updateend at this SourceBuffer object.
529 scheduleEvent(EventTypeNames::updateend);
530 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendBuffer", this);
533 void SourceBuffer::removeAsyncPart()
536 ASSERT(m_pendingRemoveStart >= 0);
537 ASSERT(m_pendingRemoveStart < m_pendingRemoveEnd);
539 // Section 3.2 remove() method steps
540 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-remove-void-double-start-double-end
542 // 9. Run the coded frame removal algorithm with start and end as the start and end of the removal range.
543 m_webSourceBuffer->remove(m_pendingRemoveStart, m_pendingRemoveEnd);
545 // 10. Set the updating attribute to false.
547 m_pendingRemoveStart = -1;
548 m_pendingRemoveEnd = -1;
550 // 11. Queue a task to fire a simple event named update at this SourceBuffer object.
551 scheduleEvent(EventTypeNames::update);
553 // 12. Queue a task to fire a simple event named updateend at this SourceBuffer object.
554 scheduleEvent(EventTypeNames::updateend);
557 void SourceBuffer::appendStreamInternal(PassRefPtr<Stream> stream, ExceptionState& exceptionState)
559 // Section 3.2 appendStream()
560 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-SourceBuffer-appendStream-void-Stream-stream-unsigned-long-long-maxSize
561 // 1. If stream is null then throw an InvalidAccessError exception and abort these steps.
562 if (!stream || stream->isNeutered()) {
563 exceptionState.throwUninformativeAndGenericDOMException(InvalidAccessError);
567 // 2. Run the prepare append algorithm.
568 // Section 3.5.4 Prepare Append Algorithm.
569 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#sourcebuffer-prepare-append
570 // 1. If this object has been removed from the sourceBuffers attribute of the parent media source then throw an InvalidStateError exception and abort these steps.
571 // 2. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps.
572 if (isRemoved() || m_updating) {
573 exceptionState.throwUninformativeAndGenericDOMException(InvalidStateError);
577 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this);
579 // 3. If the readyState attribute of the parent media source is in the "ended" state then run the following steps: ...
580 m_source->openIfInEndedState();
582 // Steps 4-5 of the prepare append algorithm are handled by m_webSourceBuffer.
584 // 3. Set the updating attribute to true.
587 // 4. Queue a task to fire a simple event named updatestart at this SourceBuffer object.
588 scheduleEvent(EventTypeNames::updatestart);
590 // 5. Asynchronously run the stream append loop algorithm with stream and maxSize.
593 m_loader = adoptPtr(new FileReaderLoader(FileReaderLoader::ReadByClient, this));
595 m_appendStreamAsyncPartRunner.runAsync();
598 void SourceBuffer::appendStreamAsyncPart()
604 // Section 3.5.6 Stream Append Loop
605 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#sourcebuffer-stream-append-loop
607 // 1. If maxSize is set, then let bytesLeft equal maxSize.
608 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the loop done step below.
609 if (m_streamMaxSizeValid && !m_streamMaxSize) {
610 appendStreamDone(true);
614 // Steps 3-11 are handled by m_loader.
615 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the data in the stream).
616 m_loader->start(executionContext(), *m_stream, m_streamMaxSizeValid ? m_streamMaxSize : 0);
619 void SourceBuffer::appendStreamDone(bool success)
625 clearAppendStreamState();
628 // Section 3.5.3 Append Error Algorithm
629 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#sourcebuffer-append-error
631 // 1. Run the reset parser state algorithm. (Handled by caller)
632 // 2. Set the updating attribute to false.
635 // 3. Queue a task to fire a simple event named error at this SourceBuffer object.
636 scheduleEvent(EventTypeNames::error);
638 // 4. Queue a task to fire a simple event named updateend at this SourceBuffer object.
639 scheduleEvent(EventTypeNames::updateend);
640 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
644 // Section 3.5.6 Stream Append Loop
645 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_webSourceBuffer|.
646 // 12. Loop Done: Set the updating attribute to false.
649 // 13. Queue a task to fire a simple event named update at this SourceBuffer object.
650 scheduleEvent(EventTypeNames::update);
652 // 14. Queue a task to fire a simple event named updateend at this SourceBuffer object.
653 scheduleEvent(EventTypeNames::updateend);
654 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
657 void SourceBuffer::clearAppendStreamState()
659 m_streamMaxSizeValid = false;
665 void SourceBuffer::didStartLoading()
667 WTF_LOG(Media, "SourceBuffer::didStartLoading() %p", this);
670 void SourceBuffer::didReceiveDataForClient(const char* data, unsigned dataLength)
672 WTF_LOG(Media, "SourceBuffer::didReceiveDataForClient(%d) %p", dataLength, this);
676 m_webSourceBuffer->append(reinterpret_cast<const unsigned char*>(data), dataLength);
679 void SourceBuffer::didFinishLoading()
681 WTF_LOG(Media, "SourceBuffer::didFinishLoading() %p", this);
682 appendStreamDone(true);
685 void SourceBuffer::didFail(FileError::ErrorCode errorCode)
687 WTF_LOG(Media, "SourceBuffer::didFail(%d) %p", errorCode, this);
688 appendStreamDone(false);
691 } // namespace WebCore