Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: Source/modules/mediasource/SourceBuffer.cpp

Issue 1013923002: Fix MSE GC, make it less aggressive, more spec-compliant (Blink CL) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Added a basic test for evict frames functionality Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/modules/mediasource/SourceBuffer.h ('k') | public/platform/WebSourceBuffer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 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.
524 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps. 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)) 525 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e))
526 return; 526 return;
527 527
528 TRACE_EVENT_ASYNC_BEGIN1("media", "SourceBuffer::appendBuffer", this, "size" , size); 528 TRACE_EVENT_ASYNC_BEGIN1("media", "SourceBuffer::appendBuffer", this, "size" , size);
529 529
530 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ... 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(); 531 m_source->openIfInEndedState();
532 532
533 // Steps 4-5 - end "prepare append" algorithm. 533 // 4. Run the coded frame eviction algorithm.
534 if (!evictCodedFrames()) {
535 // 5. If the buffer full flag equals true, then throw a QUOTA_EXCEEDED_ ERR exception and abort these steps.
536 exceptionState.throwDOMException(QuotaExceededError, "The SourceBuffer i s full, and cannot free space to append additional buffers.");
philipj_slow 2015/06/01 14:37:27 This is the new bit covered by the test.
servolk 2015/06/02 19:24:31 Acknowledged.
537 return;
538 }
534 539
535 // 2. Add data to the end of the input buffer. 540 // 2. Add data to the end of the input buffer.
536 ASSERT(data || size == 0); 541 ASSERT(data || size == 0);
537 if (data) 542 if (data)
538 m_pendingAppendData.append(data, size); 543 m_pendingAppendData.append(data, size);
539 m_pendingAppendDataOffset = 0; 544 m_pendingAppendDataOffset = 0;
540 545
541 // 3. Set the updating attribute to true. 546 // 3. Set the updating attribute to true.
542 m_updating = true; 547 m_updating = true;
543 548
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 m_pendingRemoveStart = -1; 626 m_pendingRemoveStart = -1;
622 m_pendingRemoveEnd = -1; 627 m_pendingRemoveEnd = -1;
623 628
624 // 11. Queue a task to fire a simple event named update at this SourceBuffer object. 629 // 11. Queue a task to fire a simple event named update at this SourceBuffer object.
625 scheduleEvent(EventTypeNames::update); 630 scheduleEvent(EventTypeNames::update);
626 631
627 // 12. Queue a task to fire a simple event named updateend at this SourceBuf fer object. 632 // 12. Queue a task to fire a simple event named updateend at this SourceBuf fer object.
628 scheduleEvent(EventTypeNames::updateend); 633 scheduleEvent(EventTypeNames::updateend);
629 } 634 }
630 635
636 bool SourceBuffer::evictCodedFrames()
637 {
638 return m_webSourceBuffer->evictCodedFrames();
639 }
640
631 void SourceBuffer::appendStreamInternal(Stream* stream, ExceptionState& exceptio nState) 641 void SourceBuffer::appendStreamInternal(Stream* stream, ExceptionState& exceptio nState)
632 { 642 {
633 // Section 3.2 appendStream() 643 // 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 644 // 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
635 // (0. If the stream has been neutered, then throw an InvalidAccessError exc eption and abort these steps.) 645 // (0. If the stream has been neutered, then throw an InvalidAccessError exc eption and abort these steps.)
636 if (stream->isNeutered()) { 646 if (stream->isNeutered()) {
637 exceptionState.throwDOMException(InvalidAccessError, "The stream provide d has been neutered."); 647 exceptionState.throwDOMException(InvalidAccessError, "The stream provide d has been neutered.");
638 return; 648 return;
639 } 649 }
640 650
641 // 1. Run the prepare append algorithm. 651 // 1. Run the prepare append algorithm.
642 // Section 3.5.4 Prepare Append Algorithm. 652 // Section 3.5.4 Prepare Append Algorithm.
643 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-so urce.html#sourcebuffer-prepare-append 653 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-so urce.html#sourcebuffer-prepare-append
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. 654 // 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.
645 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps. 655 // 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)) 656 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e))
647 return; 657 return;
648 658
649 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this); 659 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this);
650 660
651 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ... 661 // 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(); 662 m_source->openIfInEndedState();
653 663
654 // Steps 4-5 of the prepare append algorithm are handled by m_webSourceBuffe r. 664 // 4. Run the coded frame eviction algorithm.
665 if (!evictCodedFrames()) {
666 // 5. If the buffer full flag equals true, then throw a QUOTA_EXCEEDED_ ERR exception and abort these steps.
667 exceptionState.throwDOMException(QuotaExceededError, "The SourceBuffer i s full, and cannot free space to append stream.");
philipj_slow 2015/06/01 14:37:27 Is it possible to test the appendStream() case?
servolk 2015/06/02 19:24:31 Done. But actually I think the test is hitting the
servolk 2015/06/02 23:50:05 Actually, no, I was wrong. The new test case that
668 return;
669 }
655 670
656 // 2. Set the updating attribute to true. 671 // 2. Set the updating attribute to true.
657 m_updating = true; 672 m_updating = true;
658 673
659 // 3. Queue a task to fire a simple event named updatestart at this SourceBu ffer object. 674 // 3. Queue a task to fire a simple event named updatestart at this SourceBu ffer object.
660 scheduleEvent(EventTypeNames::updatestart); 675 scheduleEvent(EventTypeNames::updatestart);
661 676
662 // 4. Asynchronously run the stream append loop algorithm with stream and ma xSize. 677 // 4. Asynchronously run the stream append loop algorithm with stream and ma xSize.
663 678
664 stream->neuter(); 679 stream->neuter();
(...skipping 11 matching lines...) Expand all
676 // Section 3.5.6 Stream Append Loop 691 // 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 692 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-stream-append-loop
678 693
679 // 1. If maxSize is set, then let bytesLeft equal maxSize. 694 // 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. 695 // 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) { 696 if (m_streamMaxSizeValid && !m_streamMaxSize) {
682 appendStreamDone(true); 697 appendStreamDone(true);
683 return; 698 return;
684 } 699 }
685 700
686 // Steps 3-11 are handled by m_loader. 701 // Steps 3-9 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). 702 // 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); 703 m_loader->start(executionContext(), *m_stream, m_streamMaxSizeValid ? m_stre amMaxSize : 0);
689 } 704 }
690 705
691 void SourceBuffer::appendStreamDone(bool success) 706 void SourceBuffer::appendStreamDone(bool success)
692 { 707 {
693 ASSERT(m_updating); 708 ASSERT(m_updating);
694 ASSERT(m_loader); 709 ASSERT(m_loader);
695 ASSERT(m_stream); 710 ASSERT(m_stream);
696 711
697 clearAppendStreamState(); 712 clearAppendStreamState();
698 713
699 if (!success) { 714 if (!success) {
700 // Section 3.5.3 Append Error Algorithm 715 appendError();
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); 716 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
713 return; 717 return;
714 } 718 }
715 719
716 // Section 3.5.6 Stream Append Loop 720 // Section 3.5.6 Stream Append Loop
717 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_web SourceBuffer|. 721 // Steps 1-9 are handled by appendStreamAsyncPart(), |m_loader|, and |m_webS ourceBuffer|.
722
723 // 10. Run the coded frame eviction algorithm.
724 if (!evictCodedFrames()) {
725 // 11. If the buffer full flag equals true, then run the append error al gorithm with the decode error parameter set to false and abort this algorithm.
726 appendError();
philipj_slow 2015/06/01 14:37:27 Is it possible to reach this case and write a test
servolk 2015/06/02 19:24:31 See above, I think the new test that I've added is
727 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
728 return;
729 }
730
718 // 12. Loop Done: Set the updating attribute to false. 731 // 12. Loop Done: Set the updating attribute to false.
philipj_slow 2015/06/01 14:37:27 Can you also renumber the remaining steps, this on
719 m_updating = false; 732 m_updating = false;
720 733
721 // 13. Queue a task to fire a simple event named update at this SourceBuffer object. 734 // 13. Queue a task to fire a simple event named update at this SourceBuffer object.
722 scheduleEvent(EventTypeNames::update); 735 scheduleEvent(EventTypeNames::update);
723 736
724 // 14. Queue a task to fire a simple event named updateend at this SourceBuf fer object. 737 // 14. Queue a task to fire a simple event named updateend at this SourceBuf fer object.
725 scheduleEvent(EventTypeNames::updateend); 738 scheduleEvent(EventTypeNames::updateend);
726 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); 739 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
727 } 740 }
728 741
729 void SourceBuffer::clearAppendStreamState() 742 void SourceBuffer::clearAppendStreamState()
730 { 743 {
731 m_streamMaxSizeValid = false; 744 m_streamMaxSizeValid = false;
732 m_streamMaxSize = 0; 745 m_streamMaxSize = 0;
733 m_loader.clear(); 746 m_loader.clear();
734 m_stream = nullptr; 747 m_stream = nullptr;
735 } 748 }
736 749
750 void SourceBuffer::appendError()
philipj_slow 2015/06/01 14:37:27 Per spec there's a "decode error" argument that's
servolk 2015/06/02 19:24:31 You are right. I've added a decodeError parameter,
751 {
752 // Section 3.5.3 Append Error Algorithm
753 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-append-error
754 //
755 // 1. Run the reset parser state algorithm. (Handled by caller)
756 // 2. Set the updating attribute to false.
757 m_updating = false;
758
759 // 3. Queue a task to fire a simple event named error at this SourceBuffer o bject.
760 scheduleEvent(EventTypeNames::error);
761
762 // 4. Queue a task to fire a simple event named updateend at this SourceBuff er object.
763 scheduleEvent(EventTypeNames::updateend);
764 }
765
737 void SourceBuffer::didStartLoading() 766 void SourceBuffer::didStartLoading()
738 { 767 {
739 WTF_LOG(Media, "SourceBuffer::didStartLoading() %p", this); 768 WTF_LOG(Media, "SourceBuffer::didStartLoading() %p", this);
740 } 769 }
741 770
742 void SourceBuffer::didReceiveDataForClient(const char* data, unsigned dataLength ) 771 void SourceBuffer::didReceiveDataForClient(const char* data, unsigned dataLength )
743 { 772 {
744 WTF_LOG(Media, "SourceBuffer::didReceiveDataForClient(%d) %p", dataLength, t his); 773 WTF_LOG(Media, "SourceBuffer::didReceiveDataForClient(%d) %p", dataLength, t his);
745 ASSERT(m_updating); 774 ASSERT(m_updating);
746 ASSERT(m_loader); 775 ASSERT(m_loader);
(...skipping 16 matching lines...) Expand all
763 { 792 {
764 visitor->trace(m_source); 793 visitor->trace(m_source);
765 visitor->trace(m_stream); 794 visitor->trace(m_stream);
766 visitor->trace(m_trackDefaults); 795 visitor->trace(m_trackDefaults);
767 visitor->trace(m_asyncEventQueue); 796 visitor->trace(m_asyncEventQueue);
768 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor); 797 RefCountedGarbageCollectedEventTargetWithInlineData<SourceBuffer>::trace(vis itor);
769 ActiveDOMObject::trace(visitor); 798 ActiveDOMObject::trace(visitor);
770 } 799 }
771 800
772 } // namespace blink 801 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/mediasource/SourceBuffer.h ('k') | public/platform/WebSourceBuffer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698