Chromium Code Reviews| 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 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 #include "bindings/core/v8/ExceptionMessages.h" | 34 #include "bindings/core/v8/ExceptionMessages.h" |
| 35 #include "bindings/core/v8/ExceptionState.h" | 35 #include "bindings/core/v8/ExceptionState.h" |
| 36 #include "core/dom/DOMArrayBuffer.h" | 36 #include "core/dom/DOMArrayBuffer.h" |
| 37 #include "core/dom/DOMArrayBufferView.h" | 37 #include "core/dom/DOMArrayBufferView.h" |
| 38 #include "core/dom/ExceptionCode.h" | 38 #include "core/dom/ExceptionCode.h" |
| 39 #include "core/dom/ExecutionContext.h" | 39 #include "core/dom/ExecutionContext.h" |
| 40 #include "core/events/Event.h" | 40 #include "core/events/Event.h" |
| 41 #include "core/events/GenericEventQueue.h" | 41 #include "core/events/GenericEventQueue.h" |
| 42 #include "core/fileapi/FileReaderLoader.h" | 42 #include "core/fileapi/FileReaderLoader.h" |
| 43 #include "core/html/HTMLMediaElement.h" | |
| 44 #include "core/html/MediaError.h" | |
| 43 #include "core/html/TimeRanges.h" | 45 #include "core/html/TimeRanges.h" |
| 44 #include "core/streams/Stream.h" | 46 #include "core/streams/Stream.h" |
| 45 #include "modules/mediasource/MediaSource.h" | 47 #include "modules/mediasource/MediaSource.h" |
| 46 #include "platform/Logging.h" | 48 #include "platform/Logging.h" |
| 47 #include "platform/TraceEvent.h" | 49 #include "platform/TraceEvent.h" |
| 48 #include "public/platform/WebSourceBuffer.h" | 50 #include "public/platform/WebSourceBuffer.h" |
| 49 #include "wtf/MathExtras.h" | 51 #include "wtf/MathExtras.h" |
| 50 | 52 |
| 51 #include <limits> | 53 #include <limits> |
| 52 | 54 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 } | 263 } |
| 262 | 264 |
| 263 m_webSourceBuffer->setAppendWindowEnd(end); | 265 m_webSourceBuffer->setAppendWindowEnd(end); |
| 264 | 266 |
| 265 // 5. Update the attribute to the new value. | 267 // 5. Update the attribute to the new value. |
| 266 m_appendWindowEnd = end; | 268 m_appendWindowEnd = end; |
| 267 } | 269 } |
| 268 | 270 |
| 269 void SourceBuffer::appendBuffer(PassRefPtr<DOMArrayBuffer> data, ExceptionState& exceptionState) | 271 void SourceBuffer::appendBuffer(PassRefPtr<DOMArrayBuffer> data, ExceptionState& exceptionState) |
| 270 { | 272 { |
| 273 WTF_LOG(Media, "SourceBuffer::appendBuffer %p size=%u", this, data->byteLeng th()); | |
| 271 // Section 3.2 appendBuffer() | 274 // Section 3.2 appendBuffer() |
| 272 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data | 275 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data |
| 273 appendBufferInternal(static_cast<const unsigned char*>(data->data()), data-> byteLength(), exceptionState); | 276 appendBufferInternal(static_cast<const unsigned char*>(data->data()), data-> byteLength(), exceptionState); |
| 274 } | 277 } |
| 275 | 278 |
| 276 void SourceBuffer::appendBuffer(PassRefPtr<DOMArrayBufferView> data, ExceptionSt ate& exceptionState) | 279 void SourceBuffer::appendBuffer(PassRefPtr<DOMArrayBufferView> data, ExceptionSt ate& exceptionState) |
| 277 { | 280 { |
| 281 WTF_LOG(Media, "SourceBuffer::appendBuffer %p size=%u", this, data->byteLeng th()); | |
| 278 // Section 3.2 appendBuffer() | 282 // Section 3.2 appendBuffer() |
| 279 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data | 283 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data |
| 280 appendBufferInternal(static_cast<const unsigned char*>(data->baseAddress()), data->byteLength(), exceptionState); | 284 appendBufferInternal(static_cast<const unsigned char*>(data->baseAddress()), data->byteLength(), exceptionState); |
| 281 } | 285 } |
| 282 | 286 |
| 283 void SourceBuffer::appendStream(Stream* stream, ExceptionState& exceptionState) | 287 void SourceBuffer::appendStream(Stream* stream, ExceptionState& exceptionState) |
| 284 { | 288 { |
| 285 m_streamMaxSizeValid = false; | 289 m_streamMaxSizeValid = false; |
| 286 appendStreamInternal(stream, exceptionState); | 290 appendStreamInternal(stream, exceptionState); |
| 287 } | 291 } |
| 288 | 292 |
| 289 void SourceBuffer::appendStream(Stream* stream, unsigned long long maxSize, Exce ptionState& exceptionState) | 293 void SourceBuffer::appendStream(Stream* stream, unsigned long long maxSize, Exce ptionState& exceptionState) |
| 290 { | 294 { |
| 295 WTF_LOG(Media, "SourceBuffer::appendStream %p maxSize=%llu", this, maxSize); | |
| 291 m_streamMaxSizeValid = maxSize > 0; | 296 m_streamMaxSizeValid = maxSize > 0; |
| 292 if (m_streamMaxSizeValid) | 297 if (m_streamMaxSizeValid) |
| 293 m_streamMaxSize = maxSize; | 298 m_streamMaxSize = maxSize; |
| 294 appendStreamInternal(stream, exceptionState); | 299 appendStreamInternal(stream, exceptionState); |
| 295 } | 300 } |
| 296 | 301 |
| 297 void SourceBuffer::abort(ExceptionState& exceptionState) | 302 void SourceBuffer::abort(ExceptionState& exceptionState) |
| 298 { | 303 { |
| 299 // Section 3.2 abort() method steps. | 304 // Section 3.2 abort() method steps. |
| 300 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-abort-void | 305 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-abort-void |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 319 | 324 |
| 320 // 5. Set appendWindowStart to 0. | 325 // 5. Set appendWindowStart to 0. |
| 321 setAppendWindowStart(0, exceptionState); | 326 setAppendWindowStart(0, exceptionState); |
| 322 | 327 |
| 323 // 6. Set appendWindowEnd to positive Infinity. | 328 // 6. Set appendWindowEnd to positive Infinity. |
| 324 setAppendWindowEnd(std::numeric_limits<double>::infinity(), exceptionState); | 329 setAppendWindowEnd(std::numeric_limits<double>::infinity(), exceptionState); |
| 325 } | 330 } |
| 326 | 331 |
| 327 void SourceBuffer::remove(double start, double end, ExceptionState& exceptionSta te) | 332 void SourceBuffer::remove(double start, double end, ExceptionState& exceptionSta te) |
| 328 { | 333 { |
| 334 WTF_LOG(Media, "SourceBuffer::remove %p start=%f end=%f", this, start, end); | |
| 335 | |
| 329 // Section 3.2 remove() method steps. | 336 // Section 3.2 remove() method steps. |
| 330 // 1. If duration equals NaN, then throw an InvalidAccessError exception and abort these steps. | 337 // 1. If duration equals NaN, then throw an InvalidAccessError exception and abort these steps. |
| 331 // 2. If start is negative or greater than duration, then throw an InvalidAc cessError exception and abort these steps. | 338 // 2. If start is negative or greater than duration, then throw an InvalidAc cessError exception and abort these steps. |
| 332 | 339 |
| 333 if (start < 0 || (m_source && (std::isnan(m_source->duration()) || start > m _source->duration()))) { | 340 if (start < 0 || (m_source && (std::isnan(m_source->duration()) || start > m _source->duration()))) { |
| 334 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: indexOutsideRange("start", start, 0.0, ExceptionMessages::ExclusiveBound, !m_sou rce || std::isnan(m_source->duration()) ? 0 : m_source->duration(), ExceptionMes sages::ExclusiveBound)); | 341 exceptionState.throwDOMException(InvalidAccessError, ExceptionMessages:: indexOutsideRange("start", start, 0.0, ExceptionMessages::ExclusiveBound, !m_sou rce || std::isnan(m_source->duration()) ? 0 : m_source->duration(), ExceptionMes sages::ExclusiveBound)); |
| 335 return; | 342 return; |
| 336 } | 343 } |
| 337 | 344 |
| 338 // 3. If end is less than or equal to start or end equals NaN, then throw an InvalidAccessError exception and abort these steps. | 345 // 3. If end is less than or equal to start or end equals NaN, then throw an InvalidAccessError exception and abort these steps. |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 506 void SourceBuffer::scheduleEvent(const AtomicString& eventName) | 513 void SourceBuffer::scheduleEvent(const AtomicString& eventName) |
| 507 { | 514 { |
| 508 ASSERT(m_asyncEventQueue); | 515 ASSERT(m_asyncEventQueue); |
| 509 | 516 |
| 510 RefPtrWillBeRawPtr<Event> event = Event::create(eventName); | 517 RefPtrWillBeRawPtr<Event> event = Event::create(eventName); |
| 511 event->setTarget(this); | 518 event->setTarget(this); |
| 512 | 519 |
| 513 m_asyncEventQueue->enqueueEvent(event.release()); | 520 m_asyncEventQueue->enqueueEvent(event.release()); |
| 514 } | 521 } |
| 515 | 522 |
| 523 bool SourceBuffer::prepareAppend(size_t newDataSize, ExceptionState& exceptionSt ate) | |
| 524 { | |
| 525 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::prepareAppend", this); | |
| 526 // http://w3c.github.io/media-source/#sourcebuffer-prepare-append | |
| 527 // 3.5.4 Prepare Append Algorithm | |
| 528 // 1. If the SourceBuffer has been removed from the sourceBuffers attribute of the parent media source then throw an InvalidStateError exception and abort t hese steps. | |
| 529 // 2. If the updating attribute equals true, then throw an InvalidStateError exception and abort these steps. | |
| 530 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) { | |
| 531 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this); | |
| 532 return false; | |
| 533 } | |
| 534 | |
| 535 // 3. If the HTMLMediaElement.error attribute is not null, then throw an Inv alidStateError exception and abort these steps. | |
| 536 ASSERT(m_source); | |
| 537 ASSERT(m_source->mediaElement()); | |
| 538 if (m_source->mediaElement()->error()) { | |
| 539 exceptionState.throwDOMException(InvalidStateError, "The HTMLMediaElemen t.error attribute is not null."); | |
| 540 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this); | |
| 541 return false; | |
| 542 } | |
| 543 | |
| 544 // 4. If the readyState attribute of the parent media source is in the "ende d" state then run the following steps: | |
| 545 // 1. Set the readyState attribute of the parent media source to "open" | |
| 546 // 2. Queue a task to fire a simple event named sourceopen at the parent media source. | |
| 547 m_source->openIfInEndedState(); | |
| 548 | |
| 549 // 5. Run the coded frame eviction algorithm. | |
| 550 if (!evictCodedFrames(newDataSize)) { | |
| 551 // 6. If the buffer full flag equals true, then throw a QUOTA_EXCEEDED_E RR exception and abort these steps. | |
| 552 WTF_LOG(Media, "SourceBuffer::prepareAppend %p -> throw QuotaExceededErr or", this); | |
| 553 exceptionState.throwDOMException(QuotaExceededError, "The SourceBuffer i s full, and cannot free space to append additional buffers."); | |
| 554 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this); | |
| 555 return false; | |
| 556 } | |
| 557 | |
| 558 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::prepareAppend", this); | |
| 559 return true; | |
| 560 } | |
| 561 | |
| 562 bool SourceBuffer::evictCodedFrames(size_t newDataSize) | |
| 563 { | |
| 564 ASSERT(m_source); | |
| 565 ASSERT(m_source->mediaElement()); | |
| 566 double currentTime = m_source->mediaElement()->currentTime(); | |
| 567 return m_webSourceBuffer->evictCodedFrames(currentTime, newDataSize); | |
| 568 } | |
| 569 | |
| 516 void SourceBuffer::appendBufferInternal(const unsigned char* data, unsigned size , ExceptionState& exceptionState) | 570 void SourceBuffer::appendBufferInternal(const unsigned char* data, unsigned size , ExceptionState& exceptionState) |
| 517 { | 571 { |
| 572 TRACE_EVENT_ASYNC_BEGIN1("media", "SourceBuffer::appendBuffer", this, "size" , size); | |
| 518 // Section 3.2 appendBuffer() | 573 // Section 3.2 appendBuffer() |
| 519 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data | 574 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendBuffer-void-ArrayBufferView-data |
| 520 | 575 |
| 521 // 1. Run the prepare append algorithm. | 576 // 1. Run the prepare append algorithm. |
| 522 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-prepare-append | 577 if (!prepareAppend(size, exceptionState)) { |
| 523 // 1. If this object has been removed from the sourceBuffers attribute of t he parent media source then throw an InvalidStateError exception and abort these steps. | 578 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendBuffer", this); |
| 524 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps. | |
| 525 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) | |
| 526 return; | 579 return; |
| 527 | 580 } |
| 528 TRACE_EVENT_ASYNC_BEGIN1("media", "SourceBuffer::appendBuffer", this, "size" , size); | 581 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, "p repareAppend"); |
| 529 | |
| 530 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ... | |
| 531 m_source->openIfInEndedState(); | |
| 532 | |
| 533 // Steps 4-5 - end "prepare append" algorithm. | |
| 534 | 582 |
| 535 // 2. Add data to the end of the input buffer. | 583 // 2. Add data to the end of the input buffer. |
| 536 ASSERT(data || size == 0); | 584 ASSERT(data || size == 0); |
| 537 if (data) | 585 if (data) |
| 538 m_pendingAppendData.append(data, size); | 586 m_pendingAppendData.append(data, size); |
| 539 m_pendingAppendDataOffset = 0; | 587 m_pendingAppendDataOffset = 0; |
| 540 | 588 |
| 541 // 3. Set the updating attribute to true. | 589 // 3. Set the updating attribute to true. |
| 542 m_updating = true; | 590 m_updating = true; |
| 543 | 591 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 | 671 |
| 624 // 11. Queue a task to fire a simple event named update at this SourceBuffer object. | 672 // 11. Queue a task to fire a simple event named update at this SourceBuffer object. |
| 625 scheduleEvent(EventTypeNames::update); | 673 scheduleEvent(EventTypeNames::update); |
| 626 | 674 |
| 627 // 12. Queue a task to fire a simple event named updateend at this SourceBuf fer object. | 675 // 12. Queue a task to fire a simple event named updateend at this SourceBuf fer object. |
| 628 scheduleEvent(EventTypeNames::updateend); | 676 scheduleEvent(EventTypeNames::updateend); |
| 629 } | 677 } |
| 630 | 678 |
| 631 void SourceBuffer::appendStreamInternal(Stream* stream, ExceptionState& exceptio nState) | 679 void SourceBuffer::appendStreamInternal(Stream* stream, ExceptionState& exceptio nState) |
| 632 { | 680 { |
| 681 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this); | |
| 682 | |
| 633 // Section 3.2 appendStream() | 683 // Section 3.2 appendStream() |
| 634 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#widl-SourceBuffer-appendStream-void-Stream-stream-unsigned-long-long-ma xSize | 684 // http://w3c.github.io/media-source/#widl-SourceBuffer-appendStream-void-Re adableStream-stream-unsigned-long-long-maxSize |
| 635 // (0. If the stream has been neutered, then throw an InvalidAccessError exc eption and abort these steps.) | 685 // (0. If the stream has been neutered, then throw an InvalidAccessError exc eption and abort these steps.) |
| 636 if (stream->isNeutered()) { | 686 if (stream->isNeutered()) { |
| 637 exceptionState.throwDOMException(InvalidAccessError, "The stream provide d has been neutered."); | 687 exceptionState.throwDOMException(InvalidAccessError, "The stream provide d has been neutered."); |
| 688 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | |
| 638 return; | 689 return; |
| 639 } | 690 } |
| 640 | 691 |
| 641 // 1. Run the prepare append algorithm. | 692 // 1. Run the prepare append algorithm. |
| 642 // Section 3.5.4 Prepare Append Algorithm. | 693 size_t newDataSize = m_streamMaxSizeValid ? m_streamMaxSize : 0; |
| 643 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-so urce.html#sourcebuffer-prepare-append | 694 if (!prepareAppend(newDataSize, exceptionState)) { |
| 644 // 1. If this object has been removed from the sourceBuffers attribute of t he parent media source then throw an InvalidStateError exception and abort these steps. | 695 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); |
| 645 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps. | |
| 646 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) | |
| 647 return; | 696 return; |
| 648 | 697 } |
| 649 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this); | |
| 650 | |
| 651 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ... | |
| 652 m_source->openIfInEndedState(); | |
| 653 | |
| 654 // Steps 4-5 of the prepare append algorithm are handled by m_webSourceBuffe r. | |
| 655 | 698 |
| 656 // 2. Set the updating attribute to true. | 699 // 2. Set the updating attribute to true. |
| 657 m_updating = true; | 700 m_updating = true; |
| 658 | 701 |
| 659 // 3. Queue a task to fire a simple event named updatestart at this SourceBu ffer object. | 702 // 3. Queue a task to fire a simple event named updatestart at this SourceBu ffer object. |
| 660 scheduleEvent(EventTypeNames::updatestart); | 703 scheduleEvent(EventTypeNames::updatestart); |
| 661 | 704 |
| 662 // 4. Asynchronously run the stream append loop algorithm with stream and ma xSize. | 705 // 4. Asynchronously run the stream append loop algorithm with stream and ma xSize. |
| 663 | |
| 664 stream->neuter(); | 706 stream->neuter(); |
| 665 m_loader = FileReaderLoader::create(FileReaderLoader::ReadByClient, this); | 707 m_loader = FileReaderLoader::create(FileReaderLoader::ReadByClient, this); |
| 666 m_stream = stream; | 708 m_stream = stream; |
| 667 m_appendStreamAsyncPartRunner.runAsync(); | 709 m_appendStreamAsyncPartRunner.runAsync(); |
| 668 } | 710 } |
| 669 | 711 |
| 670 void SourceBuffer::appendStreamAsyncPart() | 712 void SourceBuffer::appendStreamAsyncPart() |
| 671 { | 713 { |
| 672 ASSERT(m_updating); | 714 ASSERT(m_updating); |
| 673 ASSERT(m_loader); | 715 ASSERT(m_loader); |
| 674 ASSERT(m_stream); | 716 ASSERT(m_stream); |
| 717 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendStream", this, "a ppendStreamAsyncPart"); | |
| 675 | 718 |
| 676 // Section 3.5.6 Stream Append Loop | 719 // Section 3.5.6 Stream Append Loop |
| 677 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-stream-append-loop | 720 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop |
| 678 | 721 |
| 679 // 1. If maxSize is set, then let bytesLeft equal maxSize. | 722 // 1. If maxSize is set, then let bytesLeft equal maxSize. |
| 680 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the l oop done step below. | 723 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the l oop done step below. |
| 681 if (m_streamMaxSizeValid && !m_streamMaxSize) { | 724 if (m_streamMaxSizeValid && !m_streamMaxSize) { |
| 682 appendStreamDone(true); | 725 appendStreamDone(true); |
| 683 return; | 726 return; |
| 684 } | 727 } |
| 685 | 728 |
| 686 // Steps 3-11 are handled by m_loader. | 729 // Steps 3-11 are handled by m_loader. |
| 687 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the data in the stream). | 730 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the data in the stream). |
| 688 m_loader->start(executionContext(), *m_stream, m_streamMaxSizeValid ? m_stre amMaxSize : 0); | 731 m_loader->start(executionContext(), *m_stream, m_streamMaxSizeValid ? m_stre amMaxSize : 0); |
| 689 } | 732 } |
| 690 | 733 |
| 691 void SourceBuffer::appendStreamDone(bool success) | 734 void SourceBuffer::appendStreamDone(bool success) |
| 692 { | 735 { |
| 693 ASSERT(m_updating); | 736 ASSERT(m_updating); |
| 694 ASSERT(m_loader); | 737 ASSERT(m_loader); |
| 695 ASSERT(m_stream); | 738 ASSERT(m_stream); |
| 696 | 739 |
| 697 clearAppendStreamState(); | 740 clearAppendStreamState(); |
| 698 | 741 |
| 699 if (!success) { | 742 if (!success) { |
| 700 // Section 3.5.3 Append Error Algorithm | 743 appendError(false); |
| 701 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media -source.html#sourcebuffer-append-error | |
| 702 // | |
| 703 // 1. Run the reset parser state algorithm. (Handled by caller) | |
| 704 // 2. Set the updating attribute to false. | |
| 705 m_updating = false; | |
| 706 | |
| 707 // 3. Queue a task to fire a simple event named error at this SourceBuff er object. | |
| 708 scheduleEvent(EventTypeNames::error); | |
| 709 | |
| 710 // 4. Queue a task to fire a simple event named updateend at this Source Buffer object. | |
| 711 scheduleEvent(EventTypeNames::updateend); | |
| 712 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | 744 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); |
| 713 return; | 745 return; |
| 714 } | 746 } |
| 715 | 747 |
| 716 // Section 3.5.6 Stream Append Loop | 748 // Section 3.5.6 Stream Append Loop |
| 717 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_web SourceBuffer|. | 749 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_web SourceBuffer|. |
| 750 | |
| 718 // 12. Loop Done: Set the updating attribute to false. | 751 // 12. Loop Done: Set the updating attribute to false. |
| 719 m_updating = false; | 752 m_updating = false; |
| 720 | 753 |
| 721 // 13. Queue a task to fire a simple event named update at this SourceBuffer object. | 754 // 13. Queue a task to fire a simple event named update at this SourceBuffer object. |
| 722 scheduleEvent(EventTypeNames::update); | 755 scheduleEvent(EventTypeNames::update); |
| 723 | 756 |
| 724 // 14. Queue a task to fire a simple event named updateend at this SourceBuf fer object. | 757 // 14. Queue a task to fire a simple event named updateend at this SourceBuf fer object. |
| 725 scheduleEvent(EventTypeNames::updateend); | 758 scheduleEvent(EventTypeNames::updateend); |
| 726 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); | 759 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); |
| 727 } | 760 } |
| 728 | 761 |
| 729 void SourceBuffer::clearAppendStreamState() | 762 void SourceBuffer::clearAppendStreamState() |
| 730 { | 763 { |
| 731 m_streamMaxSizeValid = false; | 764 m_streamMaxSizeValid = false; |
| 732 m_streamMaxSize = 0; | 765 m_streamMaxSize = 0; |
| 733 m_loader.clear(); | 766 m_loader.clear(); |
| 734 m_stream = nullptr; | 767 m_stream = nullptr; |
| 735 } | 768 } |
| 736 | 769 |
| 770 void SourceBuffer::appendError(bool decodeError) | |
| 771 { | |
| 772 // Section 3.5.3 Append Error Algorithm | |
| 773 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-append-error | |
| 774 | |
| 775 // 1. Run the reset parser state algorithm. | |
| 776 m_webSourceBuffer->abort(); | |
| 777 | |
| 778 // 2. Set the updating attribute to false. | |
| 779 m_updating = false; | |
| 780 | |
| 781 // 3. Queue a task to fire a simple event named error at this SourceBuffer o bject. | |
| 782 scheduleEvent(EventTypeNames::error); | |
| 783 | |
| 784 // 4. Queue a task to fire a simple event named updateend at this SourceBuff er object. | |
| 785 scheduleEvent(EventTypeNames::updateend); | |
| 786 | |
| 787 // 5. If decode error is true, then run the end of stream algorithm with the | |
| 788 // error parameter set to "decode". | |
| 789 if (decodeError) | |
|
wolenetz
2015/08/12 22:42:04
This is interesting that Blink didn't do this prev
servolk
2015/08/21 02:51:25
This is a new method that was introduced in this C
wolenetz
2015/08/21 19:33:02
Acknowledged.
| |
| 790 m_source->endOfStream("decode", ASSERT_NO_EXCEPTION); | |
| 791 } | |
| 792 | |
| 737 void SourceBuffer::didStartLoading() | 793 void SourceBuffer::didStartLoading() |
| 738 { | 794 { |
| 739 WTF_LOG(Media, "SourceBuffer::didStartLoading() %p", this); | 795 WTF_LOG(Media, "SourceBuffer::didStartLoading() %p", this); |
| 740 } | 796 } |
| 741 | 797 |
| 742 void SourceBuffer::didReceiveDataForClient(const char* data, unsigned dataLength ) | 798 void SourceBuffer::didReceiveDataForClient(const char* data, unsigned dataLength ) |
| 743 { | 799 { |
| 744 WTF_LOG(Media, "SourceBuffer::didReceiveDataForClient(%d) %p", dataLength, t his); | 800 WTF_LOG(Media, "SourceBuffer::didReceiveDataForClient(%d) %p", dataLength, t his); |
| 745 ASSERT(m_updating); | 801 ASSERT(m_updating); |
| 746 ASSERT(m_loader); | 802 ASSERT(m_loader); |
| 747 m_webSourceBuffer->append(reinterpret_cast<const unsigned char*>(data), data Length, &m_timestampOffset); | 803 m_webSourceBuffer->append(reinterpret_cast<const unsigned char*>(data), data Length, &m_timestampOffset); |
| 748 } | 804 } |
| 749 | 805 |
| 750 void SourceBuffer::didFinishLoading() | 806 void SourceBuffer::didFinishLoading() |
| 751 { | 807 { |
| 752 WTF_LOG(Media, "SourceBuffer::didFinishLoading() %p", this); | 808 WTF_LOG(Media, "SourceBuffer::didFinishLoading() %p", this); |
| 753 appendStreamDone(true); | 809 // Section 3.5.6 Stream Append Loop |
| 810 // Steps 1-9 are handled by appendStreamAsyncPart(), |m_loader|, and |m_webS ourceBuffer|. | |
| 811 | |
| 812 // 10. Run the coded frame eviction algorithm. | |
| 813 bool evictCodedFramesResult = evictCodedFrames(0); | |
|
wolenetz
2015/08/12 22:42:04
This needs to be done, instead of here, within the
servolk
2015/08/21 02:51:25
Yeah, you are right, it's actually cleaner to do i
| |
| 814 | |
| 815 // (will be done inside appendStreamDone) | |
| 816 // 11. If the buffer full flag equals true, then run the append error algori thm with the decode error parameter set to false and abort this algorithm. | |
| 817 appendStreamDone(evictCodedFramesResult); | |
| 754 } | 818 } |
| 755 | 819 |
| 756 void SourceBuffer::didFail(FileError::ErrorCode errorCode) | 820 void SourceBuffer::didFail(FileError::ErrorCode errorCode) |
| 757 { | 821 { |
| 758 WTF_LOG(Media, "SourceBuffer::didFail(%d) %p", errorCode, this); | 822 WTF_LOG(Media, "SourceBuffer::didFail(%d) %p", errorCode, this); |
| 759 appendStreamDone(false); | 823 appendStreamDone(false); |
| 760 } | 824 } |
| 761 | 825 |
| 762 DEFINE_TRACE(SourceBuffer) | 826 DEFINE_TRACE(SourceBuffer) |
| 763 { | 827 { |
| 764 visitor->trace(m_source); | 828 visitor->trace(m_source); |
| 765 visitor->trace(m_stream); | 829 visitor->trace(m_stream); |
| 766 visitor->trace(m_trackDefaults); | 830 visitor->trace(m_trackDefaults); |
| 767 visitor->trace(m_asyncEventQueue); | 831 visitor->trace(m_asyncEventQueue); |
| 768 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor); | 832 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor); |
| 769 ActiveDOMObject::trace(visitor); | 833 ActiveDOMObject::trace(visitor); |
| 770 } | 834 } |
| 771 | 835 |
| 772 } // namespace blink | 836 } // namespace blink |
| OLD | NEW |