| 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 20 matching lines...) Expand all Loading... |
| 31 #include "modules/mediasource/SourceBuffer.h" | 31 #include "modules/mediasource/SourceBuffer.h" |
| 32 | 32 |
| 33 #include "bindings/core/v8/ExceptionMessages.h" | 33 #include "bindings/core/v8/ExceptionMessages.h" |
| 34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
| 35 #include "core/dom/DOMArrayBuffer.h" | 35 #include "core/dom/DOMArrayBuffer.h" |
| 36 #include "core/dom/DOMArrayBufferView.h" | 36 #include "core/dom/DOMArrayBufferView.h" |
| 37 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
| 38 #include "core/dom/ExecutionContext.h" | 38 #include "core/dom/ExecutionContext.h" |
| 39 #include "core/events/Event.h" | 39 #include "core/events/Event.h" |
| 40 #include "core/events/GenericEventQueue.h" | 40 #include "core/events/GenericEventQueue.h" |
| 41 #include "core/fileapi/FileReaderLoader.h" | |
| 42 #include "core/frame/Deprecation.h" | 41 #include "core/frame/Deprecation.h" |
| 43 #include "core/frame/UseCounter.h" | 42 #include "core/frame/UseCounter.h" |
| 44 #include "core/html/HTMLMediaElement.h" | 43 #include "core/html/HTMLMediaElement.h" |
| 45 #include "core/html/MediaError.h" | 44 #include "core/html/MediaError.h" |
| 46 #include "core/html/TimeRanges.h" | 45 #include "core/html/TimeRanges.h" |
| 47 #include "core/html/track/AudioTrack.h" | 46 #include "core/html/track/AudioTrack.h" |
| 48 #include "core/html/track/AudioTrackList.h" | 47 #include "core/html/track/AudioTrackList.h" |
| 49 #include "core/html/track/VideoTrack.h" | 48 #include "core/html/track/VideoTrack.h" |
| 50 #include "core/html/track/VideoTrackList.h" | 49 #include "core/html/track/VideoTrackList.h" |
| 51 #include "core/streams/Stream.h" | |
| 52 #include "modules/mediasource/MediaSource.h" | 50 #include "modules/mediasource/MediaSource.h" |
| 53 #include "modules/mediasource/SourceBufferTrackBaseSupplement.h" | 51 #include "modules/mediasource/SourceBufferTrackBaseSupplement.h" |
| 54 #include "platform/RuntimeEnabledFeatures.h" | 52 #include "platform/RuntimeEnabledFeatures.h" |
| 55 #include "platform/tracing/TraceEvent.h" | 53 #include "platform/tracing/TraceEvent.h" |
| 56 #include "public/platform/WebSourceBuffer.h" | 54 #include "public/platform/WebSourceBuffer.h" |
| 57 #include "wtf/MathExtras.h" | 55 #include "wtf/MathExtras.h" |
| 58 #include <limits> | 56 #include <limits> |
| 59 #include <memory> | 57 #include <memory> |
| 60 #include <sstream> | 58 #include <sstream> |
| 61 | 59 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 74 ExceptionState& exceptionState) { | 72 ExceptionState& exceptionState) { |
| 75 if (isRemoved) { | 73 if (isRemoved) { |
| 76 MediaSource::logAndThrowDOMException( | 74 MediaSource::logAndThrowDOMException( |
| 77 exceptionState, InvalidStateError, | 75 exceptionState, InvalidStateError, |
| 78 "This SourceBuffer has been removed from the parent media source."); | 76 "This SourceBuffer has been removed from the parent media source."); |
| 79 return true; | 77 return true; |
| 80 } | 78 } |
| 81 if (isUpdating) { | 79 if (isUpdating) { |
| 82 MediaSource::logAndThrowDOMException( | 80 MediaSource::logAndThrowDOMException( |
| 83 exceptionState, InvalidStateError, | 81 exceptionState, InvalidStateError, |
| 84 "This SourceBuffer is still processing an 'appendBuffer', " | 82 "This SourceBuffer is still processing an 'appendBuffer' or " |
| 85 "'appendStream', or 'remove' operation."); | 83 "'remove' operation."); |
| 86 return true; | 84 return true; |
| 87 } | 85 } |
| 88 | 86 |
| 89 return false; | 87 return false; |
| 90 } | 88 } |
| 91 | 89 |
| 92 WTF::String webTimeRangesToString(const WebTimeRanges& ranges) { | 90 WTF::String webTimeRangesToString(const WebTimeRanges& ranges) { |
| 93 StringBuilder stringBuilder; | 91 StringBuilder stringBuilder; |
| 94 stringBuilder.append('{'); | 92 stringBuilder.append('{'); |
| 95 for (auto& r : ranges) { | 93 for (auto& r : ranges) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 m_appendWindowEnd(std::numeric_limits<double>::infinity()), | 129 m_appendWindowEnd(std::numeric_limits<double>::infinity()), |
| 132 m_firstInitializationSegmentReceived(false), | 130 m_firstInitializationSegmentReceived(false), |
| 133 m_pendingAppendDataOffset(0), | 131 m_pendingAppendDataOffset(0), |
| 134 m_appendBufferAsyncPartRunner(AsyncMethodRunner<SourceBuffer>::create( | 132 m_appendBufferAsyncPartRunner(AsyncMethodRunner<SourceBuffer>::create( |
| 135 this, | 133 this, |
| 136 &SourceBuffer::appendBufferAsyncPart)), | 134 &SourceBuffer::appendBufferAsyncPart)), |
| 137 m_pendingRemoveStart(-1), | 135 m_pendingRemoveStart(-1), |
| 138 m_pendingRemoveEnd(-1), | 136 m_pendingRemoveEnd(-1), |
| 139 m_removeAsyncPartRunner(AsyncMethodRunner<SourceBuffer>::create( | 137 m_removeAsyncPartRunner(AsyncMethodRunner<SourceBuffer>::create( |
| 140 this, | 138 this, |
| 141 &SourceBuffer::removeAsyncPart)), | 139 &SourceBuffer::removeAsyncPart)) { |
| 142 m_streamMaxSizeValid(false), | |
| 143 m_streamMaxSize(0), | |
| 144 m_appendStreamAsyncPartRunner(AsyncMethodRunner<SourceBuffer>::create( | |
| 145 this, | |
| 146 &SourceBuffer::appendStreamAsyncPart)) { | |
| 147 BLINK_SBLOG << __func__ << " this=" << this; | 140 BLINK_SBLOG << __func__ << " this=" << this; |
| 148 | 141 |
| 149 DCHECK(m_webSourceBuffer); | 142 DCHECK(m_webSourceBuffer); |
| 150 DCHECK(m_source); | 143 DCHECK(m_source); |
| 151 DCHECK(m_source->mediaElement()); | 144 DCHECK(m_source->mediaElement()); |
| 152 ThreadState::current()->registerPreFinalizer(this); | 145 ThreadState::current()->registerPreFinalizer(this); |
| 153 m_audioTracks = AudioTrackList::create(*m_source->mediaElement()); | 146 m_audioTracks = AudioTrackList::create(*m_source->mediaElement()); |
| 154 m_videoTracks = VideoTrackList::create(*m_source->mediaElement()); | 147 m_videoTracks = VideoTrackList::create(*m_source->mediaElement()); |
| 155 m_webSourceBuffer->setClient(this); | 148 m_webSourceBuffer->setClient(this); |
| 156 } | 149 } |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 364 |
| 372 void SourceBuffer::appendBuffer(DOMArrayBufferView* data, | 365 void SourceBuffer::appendBuffer(DOMArrayBufferView* data, |
| 373 ExceptionState& exceptionState) { | 366 ExceptionState& exceptionState) { |
| 374 BLINK_SBLOG << __func__ << " this=" << this << " size=" << data->byteLength(); | 367 BLINK_SBLOG << __func__ << " this=" << this << " size=" << data->byteLength(); |
| 375 // Section 3.2 appendBuffer() | 368 // Section 3.2 appendBuffer() |
| 376 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc
e.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data | 369 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc
e.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data |
| 377 appendBufferInternal(static_cast<const unsigned char*>(data->baseAddress()), | 370 appendBufferInternal(static_cast<const unsigned char*>(data->baseAddress()), |
| 378 data->byteLength(), exceptionState); | 371 data->byteLength(), exceptionState); |
| 379 } | 372 } |
| 380 | 373 |
| 381 void SourceBuffer::appendStream(Stream* stream, | |
| 382 ExceptionState& exceptionState) { | |
| 383 m_streamMaxSizeValid = false; | |
| 384 appendStreamInternal(stream, exceptionState); | |
| 385 } | |
| 386 | |
| 387 void SourceBuffer::appendStream(Stream* stream, | |
| 388 unsigned long long maxSize, | |
| 389 ExceptionState& exceptionState) { | |
| 390 BLINK_SBLOG << __func__ << " this=" << this << " maxSize=" << maxSize; | |
| 391 m_streamMaxSizeValid = maxSize > 0; | |
| 392 if (m_streamMaxSizeValid) | |
| 393 m_streamMaxSize = maxSize; | |
| 394 appendStreamInternal(stream, exceptionState); | |
| 395 } | |
| 396 | |
| 397 void SourceBuffer::abort(ExceptionState& exceptionState) { | 374 void SourceBuffer::abort(ExceptionState& exceptionState) { |
| 398 BLINK_SBLOG << __func__ << " this=" << this; | 375 BLINK_SBLOG << __func__ << " this=" << this; |
| 399 // http://w3c.github.io/media-source/#widl-SourceBuffer-abort-void | 376 // http://w3c.github.io/media-source/#widl-SourceBuffer-abort-void |
| 400 // 1. If this object has been removed from the sourceBuffers attribute of the | 377 // 1. If this object has been removed from the sourceBuffers attribute of the |
| 401 // parent media source then throw an InvalidStateError exception and abort | 378 // parent media source then throw an InvalidStateError exception and abort |
| 402 // these steps. | 379 // these steps. |
| 403 // 2. If the readyState attribute of the parent media source is not in the | 380 // 2. If the readyState attribute of the parent media source is not in the |
| 404 // "open" state then throw an InvalidStateError exception and abort these | 381 // "open" state then throw an InvalidStateError exception and abort these |
| 405 // steps. | 382 // steps. |
| 406 if (isRemoved()) { | 383 if (isRemoved()) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 529 |
| 553 void SourceBuffer::abortIfUpdating() { | 530 void SourceBuffer::abortIfUpdating() { |
| 554 // Section 3.2 abort() method step 4 substeps. | 531 // Section 3.2 abort() method step 4 substeps. |
| 555 // http://w3c.github.io/media-source/#widl-SourceBuffer-abort-void | 532 // http://w3c.github.io/media-source/#widl-SourceBuffer-abort-void |
| 556 | 533 |
| 557 if (!m_updating) | 534 if (!m_updating) |
| 558 return; | 535 return; |
| 559 | 536 |
| 560 DCHECK_EQ(m_pendingRemoveStart, -1); | 537 DCHECK_EQ(m_pendingRemoveStart, -1); |
| 561 | 538 |
| 562 const char* traceEventName = 0; | 539 const char* traceEventName = "SourceBuffer::appendBuffer"; |
| 563 if (m_stream) { | |
| 564 traceEventName = "SourceBuffer::appendStream"; | |
| 565 } else { | |
| 566 traceEventName = "SourceBuffer::appendBuffer"; | |
| 567 } | |
| 568 | 540 |
| 569 // 4.1. Abort the buffer append and stream append loop algorithms if they are | 541 // 4.1. Abort the buffer append and stream append loop algorithms if they are |
| 570 // running. | 542 // running. |
| 571 m_appendBufferAsyncPartRunner->stop(); | 543 m_appendBufferAsyncPartRunner->stop(); |
| 572 m_pendingAppendData.clear(); | 544 m_pendingAppendData.clear(); |
| 573 m_pendingAppendDataOffset = 0; | 545 m_pendingAppendDataOffset = 0; |
| 574 | 546 |
| 575 m_appendStreamAsyncPartRunner->stop(); | |
| 576 clearAppendStreamState(); | |
| 577 | |
| 578 // 4.2. Set the updating attribute to false. | 547 // 4.2. Set the updating attribute to false. |
| 579 m_updating = false; | 548 m_updating = false; |
| 580 | 549 |
| 581 // 4.3. Queue a task to fire a simple event named abort at this SourceBuffer | 550 // 4.3. Queue a task to fire a simple event named abort at this SourceBuffer |
| 582 // object. | 551 // object. |
| 583 scheduleEvent(EventTypeNames::abort); | 552 scheduleEvent(EventTypeNames::abort); |
| 584 | 553 |
| 585 // 4.4. Queue a task to fire a simple event named updateend at this | 554 // 4.4. Queue a task to fire a simple event named updateend at this |
| 586 // SourceBuffer object. | 555 // SourceBuffer object. |
| 587 scheduleEvent(EventTypeNames::updateend); | 556 scheduleEvent(EventTypeNames::updateend); |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 return true; | 1027 return true; |
| 1059 } | 1028 } |
| 1060 | 1029 |
| 1061 bool SourceBuffer::hasPendingActivity() const { | 1030 bool SourceBuffer::hasPendingActivity() const { |
| 1062 return m_source; | 1031 return m_source; |
| 1063 } | 1032 } |
| 1064 | 1033 |
| 1065 void SourceBuffer::suspend() { | 1034 void SourceBuffer::suspend() { |
| 1066 m_appendBufferAsyncPartRunner->suspend(); | 1035 m_appendBufferAsyncPartRunner->suspend(); |
| 1067 m_removeAsyncPartRunner->suspend(); | 1036 m_removeAsyncPartRunner->suspend(); |
| 1068 m_appendStreamAsyncPartRunner->suspend(); | |
| 1069 } | 1037 } |
| 1070 | 1038 |
| 1071 void SourceBuffer::resume() { | 1039 void SourceBuffer::resume() { |
| 1072 m_appendBufferAsyncPartRunner->resume(); | 1040 m_appendBufferAsyncPartRunner->resume(); |
| 1073 m_removeAsyncPartRunner->resume(); | 1041 m_removeAsyncPartRunner->resume(); |
| 1074 m_appendStreamAsyncPartRunner->resume(); | |
| 1075 } | 1042 } |
| 1076 | 1043 |
| 1077 void SourceBuffer::contextDestroyed() { | 1044 void SourceBuffer::contextDestroyed() { |
| 1078 m_appendBufferAsyncPartRunner->stop(); | 1045 m_appendBufferAsyncPartRunner->stop(); |
| 1079 m_removeAsyncPartRunner->stop(); | 1046 m_removeAsyncPartRunner->stop(); |
| 1080 m_appendStreamAsyncPartRunner->stop(); | |
| 1081 } | 1047 } |
| 1082 | 1048 |
| 1083 ExecutionContext* SourceBuffer::getExecutionContext() const { | 1049 ExecutionContext* SourceBuffer::getExecutionContext() const { |
| 1084 return ActiveDOMObject::getExecutionContext(); | 1050 return ActiveDOMObject::getExecutionContext(); |
| 1085 } | 1051 } |
| 1086 | 1052 |
| 1087 const AtomicString& SourceBuffer::interfaceName() const { | 1053 const AtomicString& SourceBuffer::interfaceName() const { |
| 1088 return EventTargetNames::SourceBuffer; | 1054 return EventTargetNames::SourceBuffer; |
| 1089 } | 1055 } |
| 1090 | 1056 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 | 1264 |
| 1299 // 11. Queue a task to fire a simple event named update at this SourceBuffer | 1265 // 11. Queue a task to fire a simple event named update at this SourceBuffer |
| 1300 // object. | 1266 // object. |
| 1301 scheduleEvent(EventTypeNames::update); | 1267 scheduleEvent(EventTypeNames::update); |
| 1302 | 1268 |
| 1303 // 12. Queue a task to fire a simple event named updateend at this | 1269 // 12. Queue a task to fire a simple event named updateend at this |
| 1304 // SourceBuffer object. | 1270 // SourceBuffer object. |
| 1305 scheduleEvent(EventTypeNames::updateend); | 1271 scheduleEvent(EventTypeNames::updateend); |
| 1306 } | 1272 } |
| 1307 | 1273 |
| 1308 void SourceBuffer::appendStreamInternal(Stream* stream, | |
| 1309 ExceptionState& exceptionState) { | |
| 1310 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this); | |
| 1311 | |
| 1312 // Section 3.2 appendStream() | |
| 1313 // http://w3c.github.io/media-source/#widl-SourceBuffer-appendStream-void-Read
ableStream-stream-unsigned-long-long-maxSize | |
| 1314 // (0. If the stream has been neutered, then throw an InvalidAccessError | |
| 1315 // exception and abort these steps.) | |
| 1316 if (stream->isNeutered()) { | |
| 1317 MediaSource::logAndThrowDOMException( | |
| 1318 exceptionState, InvalidAccessError, | |
| 1319 "The stream provided has been neutered."); | |
| 1320 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | |
| 1321 return; | |
| 1322 } | |
| 1323 | |
| 1324 // 1. Run the prepare append algorithm. | |
| 1325 size_t newDataSize = m_streamMaxSizeValid ? m_streamMaxSize : 0; | |
| 1326 if (!prepareAppend(newDataSize, exceptionState)) { | |
| 1327 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | |
| 1328 return; | |
| 1329 } | |
| 1330 | |
| 1331 // 2. Set the updating attribute to true. | |
| 1332 m_updating = true; | |
| 1333 | |
| 1334 // 3. Queue a task to fire a simple event named updatestart at this | |
| 1335 // SourceBuffer object. | |
| 1336 scheduleEvent(EventTypeNames::updatestart); | |
| 1337 | |
| 1338 // 4. Asynchronously run the stream append loop algorithm with stream and | |
| 1339 // maxSize. | |
| 1340 stream->neuter(); | |
| 1341 m_loader = FileReaderLoader::create(FileReaderLoader::ReadByClient, this); | |
| 1342 m_stream = stream; | |
| 1343 m_appendStreamAsyncPartRunner->runAsync(); | |
| 1344 } | |
| 1345 | |
| 1346 void SourceBuffer::appendStreamAsyncPart() { | |
| 1347 DCHECK(m_updating); | |
| 1348 DCHECK(m_loader); | |
| 1349 DCHECK(m_stream); | |
| 1350 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendStream", this, | |
| 1351 "appendStreamAsyncPart"); | |
| 1352 | |
| 1353 // Section 3.5.6 Stream Append Loop | |
| 1354 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop | |
| 1355 | |
| 1356 // 1. If maxSize is set, then let bytesLeft equal maxSize. | |
| 1357 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the | |
| 1358 // loop done step below. | |
| 1359 if (m_streamMaxSizeValid && !m_streamMaxSize) { | |
| 1360 appendStreamDone(NoError); | |
| 1361 return; | |
| 1362 } | |
| 1363 | |
| 1364 // Steps 3-11 are handled by m_loader. | |
| 1365 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the | |
| 1366 // data in the stream). | |
| 1367 m_loader->start(getExecutionContext(), *m_stream, | |
| 1368 m_streamMaxSizeValid ? m_streamMaxSize : 0); | |
| 1369 } | |
| 1370 | |
| 1371 void SourceBuffer::appendStreamDone(AppendStreamDoneAction action) { | |
| 1372 DCHECK(m_updating); | |
| 1373 DCHECK(m_loader); | |
| 1374 DCHECK(m_stream); | |
| 1375 | |
| 1376 clearAppendStreamState(); | |
| 1377 | |
| 1378 if (action != NoError) { | |
| 1379 if (action == RunAppendErrorWithNoDecodeError) { | |
| 1380 appendError(NoDecodeError); | |
| 1381 } else { | |
| 1382 DCHECK_EQ(action, RunAppendErrorWithDecodeError); | |
| 1383 appendError(DecodeError); | |
| 1384 } | |
| 1385 | |
| 1386 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | |
| 1387 return; | |
| 1388 } | |
| 1389 | |
| 1390 // Section 3.5.6 Stream Append Loop | |
| 1391 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and | |
| 1392 // |m_webSourceBuffer|. | |
| 1393 | |
| 1394 // 12. Loop Done: Set the updating attribute to false. | |
| 1395 m_updating = false; | |
| 1396 | |
| 1397 // 13. Queue a task to fire a simple event named update at this SourceBuffer | |
| 1398 // object. | |
| 1399 scheduleEvent(EventTypeNames::update); | |
| 1400 | |
| 1401 // 14. Queue a task to fire a simple event named updateend at this | |
| 1402 // SourceBuffer object. | |
| 1403 scheduleEvent(EventTypeNames::updateend); | |
| 1404 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | |
| 1405 BLINK_SBLOG << __func__ << " ended. this=" << this << " buffered=" | |
| 1406 << webTimeRangesToString(m_webSourceBuffer->buffered()); | |
| 1407 } | |
| 1408 | |
| 1409 void SourceBuffer::clearAppendStreamState() { | |
| 1410 m_streamMaxSizeValid = false; | |
| 1411 m_streamMaxSize = 0; | |
| 1412 m_loader.reset(); | |
| 1413 m_stream = nullptr; | |
| 1414 } | |
| 1415 | |
| 1416 void SourceBuffer::appendError(AppendError err) { | 1274 void SourceBuffer::appendError(AppendError err) { |
| 1417 BLINK_SBLOG << __func__ << " this=" << this << " AppendError=" << err; | 1275 BLINK_SBLOG << __func__ << " this=" << this << " AppendError=" << err; |
| 1418 // Section 3.5.3 Append Error Algorithm | 1276 // Section 3.5.3 Append Error Algorithm |
| 1419 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc
e.html#sourcebuffer-append-error | 1277 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sourc
e.html#sourcebuffer-append-error |
| 1420 | 1278 |
| 1421 // 1. Run the reset parser state algorithm. | 1279 // 1. Run the reset parser state algorithm. |
| 1422 m_webSourceBuffer->resetParserState(); | 1280 m_webSourceBuffer->resetParserState(); |
| 1423 | 1281 |
| 1424 // 2. Set the updating attribute to false. | 1282 // 2. Set the updating attribute to false. |
| 1425 m_updating = false; | 1283 m_updating = false; |
| 1426 | 1284 |
| 1427 // 3. Queue a task to fire a simple event named error at this SourceBuffer | 1285 // 3. Queue a task to fire a simple event named error at this SourceBuffer |
| 1428 // object. | 1286 // object. |
| 1429 scheduleEvent(EventTypeNames::error); | 1287 scheduleEvent(EventTypeNames::error); |
| 1430 | 1288 |
| 1431 // 4. Queue a task to fire a simple event named updateend at this SourceBuffer | 1289 // 4. Queue a task to fire a simple event named updateend at this SourceBuffer |
| 1432 // object. | 1290 // object. |
| 1433 scheduleEvent(EventTypeNames::updateend); | 1291 scheduleEvent(EventTypeNames::updateend); |
| 1434 | 1292 |
| 1435 // 5. If decode error is true, then run the end of stream algorithm with the | 1293 // 5. If decode error is true, then run the end of stream algorithm with the |
| 1436 // error parameter set to "decode". | 1294 // error parameter set to "decode". |
| 1437 if (err == DecodeError) { | 1295 if (err == DecodeError) { |
| 1438 m_source->endOfStream("decode", ASSERT_NO_EXCEPTION); | 1296 m_source->endOfStream("decode", ASSERT_NO_EXCEPTION); |
| 1439 } else { | 1297 } else { |
| 1440 DCHECK_EQ(err, NoDecodeError); | 1298 DCHECK_EQ(err, NoDecodeError); |
| 1441 // Nothing else to do in this case. | 1299 // Nothing else to do in this case. |
| 1442 } | 1300 } |
| 1443 } | 1301 } |
| 1444 | 1302 |
| 1445 void SourceBuffer::didStartLoading() { | |
| 1446 BLINK_SBLOG << __func__ << " this=" << this; | |
| 1447 } | |
| 1448 | |
| 1449 void SourceBuffer::didReceiveDataForClient(const char* data, | |
| 1450 unsigned dataLength) { | |
| 1451 BLINK_SBLOG << __func__ << " this=" << this << " dataLength=" << dataLength; | |
| 1452 DCHECK(m_updating); | |
| 1453 DCHECK(m_loader); | |
| 1454 | |
| 1455 // Section 3.5.6 Stream Append Loop | |
| 1456 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop | |
| 1457 | |
| 1458 // 10. Run the coded frame eviction algorithm. | |
| 1459 if (!evictCodedFrames(dataLength)) { | |
| 1460 // 11. (in appendStreamDone) If the buffer full flag equals true, then run | |
| 1461 // the append error algorithm with the decode error parameter set to | |
| 1462 // false and abort this algorithm. | |
| 1463 appendStreamDone(RunAppendErrorWithNoDecodeError); | |
| 1464 return; | |
| 1465 } | |
| 1466 | |
| 1467 if (!m_webSourceBuffer->append(reinterpret_cast<const unsigned char*>(data), | |
| 1468 dataLength, &m_timestampOffset)) | |
| 1469 appendStreamDone(RunAppendErrorWithDecodeError); | |
| 1470 } | |
| 1471 | |
| 1472 void SourceBuffer::didFinishLoading() { | |
| 1473 BLINK_SBLOG << __func__ << " this=" << this; | |
| 1474 DCHECK(m_loader); | |
| 1475 appendStreamDone(NoError); | |
| 1476 } | |
| 1477 | |
| 1478 void SourceBuffer::didFail(FileError::ErrorCode errorCode) { | |
| 1479 BLINK_SBLOG << __func__ << " this=" << this << " errorCode=" << errorCode; | |
| 1480 // m_loader might be already released, in case appendStream has failed due | |
| 1481 // to evictCodedFrames or WebSourceBuffer append failing in | |
| 1482 // didReceiveDataForClient. In that case appendStreamDone will be invoked | |
| 1483 // from there, no need to repeat it here. | |
| 1484 if (m_loader) | |
| 1485 appendStreamDone(RunAppendErrorWithNoDecodeError); | |
| 1486 } | |
| 1487 | |
| 1488 DEFINE_TRACE(SourceBuffer) { | 1303 DEFINE_TRACE(SourceBuffer) { |
| 1489 visitor->trace(m_source); | 1304 visitor->trace(m_source); |
| 1490 visitor->trace(m_trackDefaults); | 1305 visitor->trace(m_trackDefaults); |
| 1491 visitor->trace(m_asyncEventQueue); | 1306 visitor->trace(m_asyncEventQueue); |
| 1492 visitor->trace(m_appendBufferAsyncPartRunner); | 1307 visitor->trace(m_appendBufferAsyncPartRunner); |
| 1493 visitor->trace(m_removeAsyncPartRunner); | 1308 visitor->trace(m_removeAsyncPartRunner); |
| 1494 visitor->trace(m_appendStreamAsyncPartRunner); | |
| 1495 visitor->trace(m_stream); | |
| 1496 visitor->trace(m_audioTracks); | 1309 visitor->trace(m_audioTracks); |
| 1497 visitor->trace(m_videoTracks); | 1310 visitor->trace(m_videoTracks); |
| 1498 EventTargetWithInlineData::trace(visitor); | 1311 EventTargetWithInlineData::trace(visitor); |
| 1499 ActiveDOMObject::trace(visitor); | 1312 ActiveDOMObject::trace(visitor); |
| 1500 } | 1313 } |
| 1501 | 1314 |
| 1502 } // namespace blink | 1315 } // namespace blink |
| OLD | NEW |