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

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

Issue 785343002: Added function to implement Coded Frame Eviction Algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years 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 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 // 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. 506 // 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.
507 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps. 507 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps.
508 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) 508 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e))
509 return; 509 return;
510 510
511 TRACE_EVENT_ASYNC_BEGIN1("media", "SourceBuffer::appendBuffer", this, "size" , size); 511 TRACE_EVENT_ASYNC_BEGIN1("media", "SourceBuffer::appendBuffer", this, "size" , size);
512 512
513 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ... 513 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ...
514 m_source->openIfInEndedState(); 514 m_source->openIfInEndedState();
515 515
516 // Steps 4-5 - end "prepare append" algorithm. 516 // 4. Run the coded frame eviction algorithm.
517 if (!evictCodedFrames()) {
518 // 5. If the buffer full flag equals true, then throw a QUOTA_EXCEEDED_ ERR exception and abort these steps.
519 exceptionState.throwDOMException(QuotaExceededError, "The SourceBuffer i s full, and cannot free space to append additional buffers.");
520 return;
521 }
517 522
518 // 2. Add data to the end of the input buffer. 523 // 2. Add data to the end of the input buffer.
519 ASSERT(data || size == 0); 524 ASSERT(data || size == 0);
520 if (data) 525 if (data)
521 m_pendingAppendData.append(data, size); 526 m_pendingAppendData.append(data, size);
522 m_pendingAppendDataOffset = 0; 527 m_pendingAppendDataOffset = 0;
523 528
524 // 3. Set the updating attribute to true. 529 // 3. Set the updating attribute to true.
525 m_updating = true; 530 m_updating = true;
526 531
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 m_pendingRemoveStart = -1; 609 m_pendingRemoveStart = -1;
605 m_pendingRemoveEnd = -1; 610 m_pendingRemoveEnd = -1;
606 611
607 // 11. Queue a task to fire a simple event named update at this SourceBuffer object. 612 // 11. Queue a task to fire a simple event named update at this SourceBuffer object.
608 scheduleEvent(EventTypeNames::update); 613 scheduleEvent(EventTypeNames::update);
609 614
610 // 12. Queue a task to fire a simple event named updateend at this SourceBuf fer object. 615 // 12. Queue a task to fire a simple event named updateend at this SourceBuf fer object.
611 scheduleEvent(EventTypeNames::updateend); 616 scheduleEvent(EventTypeNames::updateend);
612 } 617 }
613 618
619 bool SourceBuffer::evictCodedFrames()
620 {
621 return m_webSourceBuffer->evictCodedFrames();
622 }
623
614 void SourceBuffer::appendStreamInternal(PassRefPtrWillBeRawPtr<Stream> stream, E xceptionState& exceptionState) 624 void SourceBuffer::appendStreamInternal(PassRefPtrWillBeRawPtr<Stream> stream, E xceptionState& exceptionState)
615 { 625 {
616 // Section 3.2 appendStream() 626 // Section 3.2 appendStream()
617 // 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 627 // 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
618 // (0. If the stream has been neutered, then throw an InvalidAccessError exc eption and abort these steps.) 628 // (0. If the stream has been neutered, then throw an InvalidAccessError exc eption and abort these steps.)
619 if (stream->isNeutered()) { 629 if (stream->isNeutered()) {
620 exceptionState.throwDOMException(InvalidAccessError, "The stream provide d has been neutered."); 630 exceptionState.throwDOMException(InvalidAccessError, "The stream provide d has been neutered.");
621 return; 631 return;
622 } 632 }
623 633
624 // 1. Run the prepare append algorithm. 634 // 1. Run the prepare append algorithm.
625 // Section 3.5.4 Prepare Append Algorithm. 635 // Section 3.5.4 Prepare Append Algorithm.
626 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-so urce.html#sourcebuffer-prepare-append 636 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-so urce.html#sourcebuffer-prepare-append
627 // 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. 637 // 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.
628 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps. 638 // 2. If the updating attribute equals true, then throw an InvalidStateErro r exception and abort these steps.
629 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e)) 639 if (throwExceptionIfRemovedOrUpdating(isRemoved(), m_updating, exceptionStat e))
630 return; 640 return;
631 641
632 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this); 642 TRACE_EVENT_ASYNC_BEGIN0("media", "SourceBuffer::appendStream", this);
633 643
634 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ... 644 // 3. If the readyState attribute of the parent media source is in the "end ed" state then run the following steps: ...
635 m_source->openIfInEndedState(); 645 m_source->openIfInEndedState();
636 646
637 // Steps 4-5 of the prepare append algorithm are handled by m_webSourceBuffe r. 647 // 4. Run the coded frame eviction algorithm.
648 if (!evictCodedFrames()) {
649 // 5. If the buffer full flag equals true, then throw a QUOTA_EXCEEDED_ ERR exception and abort these steps.
650 exceptionState.throwDOMException(QuotaExceededError, "The SourceBuffer i s full, and cannot free space to append stream.");
651 return;
652 }
638 653
639 // 2. Set the updating attribute to true. 654 // 2. Set the updating attribute to true.
640 m_updating = true; 655 m_updating = true;
641 656
642 // 3. Queue a task to fire a simple event named updatestart at this SourceBu ffer object. 657 // 3. Queue a task to fire a simple event named updatestart at this SourceBu ffer object.
643 scheduleEvent(EventTypeNames::updatestart); 658 scheduleEvent(EventTypeNames::updatestart);
644 659
645 // 4. Asynchronously run the stream append loop algorithm with stream and ma xSize. 660 // 4. Asynchronously run the stream append loop algorithm with stream and ma xSize.
646 661
647 stream->neuter(); 662 stream->neuter();
(...skipping 11 matching lines...) Expand all
659 // Section 3.5.6 Stream Append Loop 674 // Section 3.5.6 Stream Append Loop
660 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-stream-append-loop 675 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-stream-append-loop
661 676
662 // 1. If maxSize is set, then let bytesLeft equal maxSize. 677 // 1. If maxSize is set, then let bytesLeft equal maxSize.
663 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the l oop done step below. 678 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the l oop done step below.
664 if (m_streamMaxSizeValid && !m_streamMaxSize) { 679 if (m_streamMaxSizeValid && !m_streamMaxSize) {
665 appendStreamDone(true); 680 appendStreamDone(true);
666 return; 681 return;
667 } 682 }
668 683
669 // Steps 3-11 are handled by m_loader. 684 // Steps 3-9 are handled by m_loader.
670 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the data in the stream). 685 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the data in the stream).
671 m_loader->start(executionContext(), *m_stream, m_streamMaxSizeValid ? m_stre amMaxSize : 0); 686 m_loader->start(executionContext(), *m_stream, m_streamMaxSizeValid ? m_stre amMaxSize : 0);
672 } 687 }
673 688
674 void SourceBuffer::appendStreamDone(bool success) 689 void SourceBuffer::appendStreamDone(bool success)
675 { 690 {
676 ASSERT(m_updating); 691 ASSERT(m_updating);
677 ASSERT(m_loader); 692 ASSERT(m_loader);
678 ASSERT(m_stream); 693 ASSERT(m_stream);
679 694
680 clearAppendStreamState(); 695 clearAppendStreamState();
681 696
682 if (!success) { 697 if (!success) {
683 // Section 3.5.3 Append Error Algorithm 698 appendError();
684 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media -source.html#sourcebuffer-append-error
685 //
686 // 1. Run the reset parser state algorithm. (Handled by caller)
687 // 2. Set the updating attribute to false.
688 m_updating = false;
689
690 // 3. Queue a task to fire a simple event named error at this SourceBuff er object.
691 scheduleEvent(EventTypeNames::error);
692
693 // 4. Queue a task to fire a simple event named updateend at this Source Buffer object.
694 scheduleEvent(EventTypeNames::updateend);
695 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); 699 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
696 return; 700 return;
697 } 701 }
698 702
699 // Section 3.5.6 Stream Append Loop 703 // Section 3.5.6 Stream Append Loop
700 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_web SourceBuffer|. 704 // Steps 1-9 are handled by appendStreamAsyncPart(), |m_loader|, and |m_webS ourceBuffer|.
705
706 // 10. Run the coded frame eviction algorithm.
707 if (!evictCodedFrames()) {
708 // 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.
709 appendError();
710 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
711 return;
712 }
713
701 // 12. Loop Done: Set the updating attribute to false. 714 // 12. Loop Done: Set the updating attribute to false.
702 m_updating = false; 715 m_updating = false;
703 716
704 // 13. Queue a task to fire a simple event named update at this SourceBuffer object. 717 // 13. Queue a task to fire a simple event named update at this SourceBuffer object.
705 scheduleEvent(EventTypeNames::update); 718 scheduleEvent(EventTypeNames::update);
706 719
707 // 14. Queue a task to fire a simple event named updateend at this SourceBuf fer object. 720 // 14. Queue a task to fire a simple event named updateend at this SourceBuf fer object.
708 scheduleEvent(EventTypeNames::updateend); 721 scheduleEvent(EventTypeNames::updateend);
709 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); 722 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
710 } 723 }
711 724
712 void SourceBuffer::clearAppendStreamState() 725 void SourceBuffer::clearAppendStreamState()
713 { 726 {
714 m_streamMaxSizeValid = false; 727 m_streamMaxSizeValid = false;
715 m_streamMaxSize = 0; 728 m_streamMaxSize = 0;
716 m_loader.clear(); 729 m_loader.clear();
717 m_stream = nullptr; 730 m_stream = nullptr;
718 } 731 }
719 732
733 void SourceBuffer::appendError()
734 {
735 // Section 3.5.3 Append Error Algorithm
736 // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-sou rce.html#sourcebuffer-append-error
737 //
738 // 1. Run the reset parser state algorithm. (Handled by caller)
739 // 2. Set the updating attribute to false.
740 m_updating = false;
741
742 // 3. Queue a task to fire a simple event named error at this SourceBuffer o bject.
743 scheduleEvent(EventTypeNames::error);
744
745 // 4. Queue a task to fire a simple event named updateend at this SourceBuff er object.
746 scheduleEvent(EventTypeNames::updateend);
747 }
748
720 void SourceBuffer::didStartLoading() 749 void SourceBuffer::didStartLoading()
721 { 750 {
722 WTF_LOG(Media, "SourceBuffer::didStartLoading() %p", this); 751 WTF_LOG(Media, "SourceBuffer::didStartLoading() %p", this);
723 } 752 }
724 753
725 void SourceBuffer::didReceiveDataForClient(const char* data, unsigned dataLength ) 754 void SourceBuffer::didReceiveDataForClient(const char* data, unsigned dataLength )
726 { 755 {
727 WTF_LOG(Media, "SourceBuffer::didReceiveDataForClient(%d) %p", dataLength, t his); 756 WTF_LOG(Media, "SourceBuffer::didReceiveDataForClient(%d) %p", dataLength, t his);
728 ASSERT(m_updating); 757 ASSERT(m_updating);
729 ASSERT(m_loader); 758 ASSERT(m_loader);
(...skipping 14 matching lines...) Expand all
744 773
745 void SourceBuffer::trace(Visitor* visitor) 774 void SourceBuffer::trace(Visitor* visitor)
746 { 775 {
747 visitor->trace(m_source); 776 visitor->trace(m_source);
748 visitor->trace(m_stream); 777 visitor->trace(m_stream);
749 visitor->trace(m_asyncEventQueue); 778 visitor->trace(m_asyncEventQueue);
750 EventTargetWithInlineData::trace(visitor); 779 EventTargetWithInlineData::trace(visitor);
751 } 780 }
752 781
753 } // namespace blink 782 } // 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