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

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

Issue 2076673005: MSE: Plumb ChunkDemuxer appendData failures into append Error algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the layout test Created 4 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
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 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 TRACE_EVENT_ASYNC_STEP_INTO1("media", "SourceBuffer::appendBuffer", this, "a ppending", "appendSize", static_cast<unsigned>(appendSize)); 807 TRACE_EVENT_ASYNC_STEP_INTO1("media", "SourceBuffer::appendBuffer", this, "a ppending", "appendSize", static_cast<unsigned>(appendSize));
808 808
809 // |zero| is used for 0 byte appends so we always have a valid pointer. 809 // |zero| is used for 0 byte appends so we always have a valid pointer.
810 // We need to convey all appends, even 0 byte ones to |m_webSourceBuffer| 810 // We need to convey all appends, even 0 byte ones to |m_webSourceBuffer|
811 // so that it can clear its end of stream state if necessary. 811 // so that it can clear its end of stream state if necessary.
812 unsigned char zero = 0; 812 unsigned char zero = 0;
813 unsigned char* appendData = &zero; 813 unsigned char* appendData = &zero;
814 if (appendSize) 814 if (appendSize)
815 appendData = m_pendingAppendData.data() + m_pendingAppendDataOffset; 815 appendData = m_pendingAppendData.data() + m_pendingAppendDataOffset;
816 816
817 m_webSourceBuffer->append(appendData, appendSize, &m_timestampOffset); 817 bool appendSuccess = m_webSourceBuffer->append(appendData, appendSize, &m_ti mestampOffset);
818 818
819 m_pendingAppendDataOffset += appendSize; 819 if (!appendSuccess) {
820 m_pendingAppendData.clear();
821 m_pendingAppendDataOffset = 0;
822 appendError(true);
823 } else {
824 m_pendingAppendDataOffset += appendSize;
820 825
821 if (m_pendingAppendDataOffset < m_pendingAppendData.size()) { 826 if (m_pendingAppendDataOffset < m_pendingAppendData.size()) {
822 m_appendBufferAsyncPartRunner->runAsync(); 827 m_appendBufferAsyncPartRunner->runAsync();
823 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this , "nextPieceDelay"); 828 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendBuffer", this, "nextPieceDelay");
824 return; 829 return;
830 }
831
832 // 3. Set the updating attribute to false.
833 m_updating = false;
834 m_pendingAppendData.clear();
835 m_pendingAppendDataOffset = 0;
836
837 // 4. Queue a task to fire a simple event named update at this SourceBuf fer object.
838 scheduleEvent(EventTypeNames::update);
839
840 // 5. Queue a task to fire a simple event named updateend at this Source Buffer object.
841 scheduleEvent(EventTypeNames::updateend);
825 } 842 }
826 843
827 // 3. Set the updating attribute to false.
828 m_updating = false;
829 m_pendingAppendData.clear();
830 m_pendingAppendDataOffset = 0;
831
832 // 4. Queue a task to fire a simple event named update at this SourceBuffer object.
833 scheduleEvent(EventTypeNames::update);
834
835 // 5. Queue a task to fire a simple event named updateend at this SourceBuff er object.
836 scheduleEvent(EventTypeNames::updateend);
837 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendBuffer", this); 844 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendBuffer", this);
838 SBLOG << __FUNCTION__ << " done. this=" << this << " buffered=" << webTimeRa ngesToString(m_webSourceBuffer->buffered()); 845 SBLOG << __FUNCTION__ << " done. this=" << this << " buffered=" << webTimeRa ngesToString(m_webSourceBuffer->buffered());
839 } 846 }
840 847
841 void SourceBuffer::removeAsyncPart() 848 void SourceBuffer::removeAsyncPart()
842 { 849 {
843 DCHECK(m_updating); 850 DCHECK(m_updating);
844 DCHECK_GE(m_pendingRemoveStart, 0); 851 DCHECK_GE(m_pendingRemoveStart, 0);
845 DCHECK_LT(m_pendingRemoveStart, m_pendingRemoveEnd); 852 DCHECK_LT(m_pendingRemoveStart, m_pendingRemoveEnd);
846 853
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 DCHECK(m_loader); 908 DCHECK(m_loader);
902 DCHECK(m_stream); 909 DCHECK(m_stream);
903 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendStream", this, "a ppendStreamAsyncPart"); 910 TRACE_EVENT_ASYNC_STEP_INTO0("media", "SourceBuffer::appendStream", this, "a ppendStreamAsyncPart");
904 911
905 // Section 3.5.6 Stream Append Loop 912 // Section 3.5.6 Stream Append Loop
906 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop 913 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop
907 914
908 // 1. If maxSize is set, then let bytesLeft equal maxSize. 915 // 1. If maxSize is set, then let bytesLeft equal maxSize.
909 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the l oop done step below. 916 // 2. Loop Top: If maxSize is set and bytesLeft equals 0, then jump to the l oop done step below.
910 if (m_streamMaxSizeValid && !m_streamMaxSize) { 917 if (m_streamMaxSizeValid && !m_streamMaxSize) {
911 appendStreamDone(true); 918 appendStreamDone(false, false);
912 return; 919 return;
913 } 920 }
914 921
915 // Steps 3-11 are handled by m_loader. 922 // Steps 3-11 are handled by m_loader.
916 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the data in the stream). 923 // Note: Passing 0 here signals that maxSize was not set. (i.e. Read all the data in the stream).
917 m_loader->start(getExecutionContext(), *m_stream, m_streamMaxSizeValid ? m_s treamMaxSize : 0); 924 m_loader->start(getExecutionContext(), *m_stream, m_streamMaxSizeValid ? m_s treamMaxSize : 0);
918 } 925 }
919 926
920 void SourceBuffer::appendStreamDone(bool success) 927 void SourceBuffer::appendStreamDone(bool runAppendError, bool decodeError)
921 { 928 {
922 DCHECK(m_updating); 929 DCHECK(m_updating);
923 DCHECK(m_loader); 930 DCHECK(m_loader);
924 DCHECK(m_stream); 931 DCHECK(m_stream);
925 932
926 clearAppendStreamState(); 933 clearAppendStreamState();
927 934
928 if (!success) { 935 if (runAppendError) {
929 appendError(false); 936 appendError(decodeError);
930 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this); 937 TRACE_EVENT_ASYNC_END0("media", "SourceBuffer::appendStream", this);
931 return; 938 return;
932 } 939 }
933 940
934 // Section 3.5.6 Stream Append Loop 941 // Section 3.5.6 Stream Append Loop
935 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_web SourceBuffer|. 942 // Steps 1-11 are handled by appendStreamAsyncPart(), |m_loader|, and |m_web SourceBuffer|.
936 943
937 // 12. Loop Done: Set the updating attribute to false. 944 // 12. Loop Done: Set the updating attribute to false.
938 m_updating = false; 945 m_updating = false;
939 946
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 SBLOG << __FUNCTION__ << " this=" << this << " dataLength=" << dataLength; 995 SBLOG << __FUNCTION__ << " this=" << this << " dataLength=" << dataLength;
989 DCHECK(m_updating); 996 DCHECK(m_updating);
990 DCHECK(m_loader); 997 DCHECK(m_loader);
991 998
992 // Section 3.5.6 Stream Append Loop 999 // Section 3.5.6 Stream Append Loop
993 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop 1000 // http://w3c.github.io/media-source/#sourcebuffer-stream-append-loop
994 1001
995 // 10. Run the coded frame eviction algorithm. 1002 // 10. Run the coded frame eviction algorithm.
996 if (!evictCodedFrames(dataLength)) { 1003 if (!evictCodedFrames(dataLength)) {
997 // 11. (in appendStreamDone) If the buffer full flag equals true, then r un the append error algorithm with the decode error parameter set to false and a bort this algorithm. 1004 // 11. (in appendStreamDone) If the buffer full flag equals true, then r un the append error algorithm with the decode error parameter set to false and a bort this algorithm.
998 appendStreamDone(false); 1005 appendStreamDone(true, false);
999 return; 1006 return;
1000 } 1007 }
1001 1008
1002 m_webSourceBuffer->append(reinterpret_cast<const unsigned char*>(data), data Length, &m_timestampOffset); 1009 if (!m_webSourceBuffer->append(reinterpret_cast<const unsigned char*>(data), dataLength, &m_timestampOffset))
1010 appendStreamDone(true, true);
1003 } 1011 }
1004 1012
1005 void SourceBuffer::didFinishLoading() 1013 void SourceBuffer::didFinishLoading()
1006 { 1014 {
1007 SBLOG << __FUNCTION__ << " this=" << this; 1015 SBLOG << __FUNCTION__ << " this=" << this;
1008 DCHECK(m_loader); 1016 DCHECK(m_loader);
1009 appendStreamDone(true); 1017 appendStreamDone(false, false);
1010 } 1018 }
1011 1019
1012 void SourceBuffer::didFail(FileError::ErrorCode errorCode) 1020 void SourceBuffer::didFail(FileError::ErrorCode errorCode)
1013 { 1021 {
1014 SBLOG << __FUNCTION__ << " this=" << this << " errorCode=" << errorCode; 1022 SBLOG << __FUNCTION__ << " this=" << this << " errorCode=" << errorCode;
1015 // m_loader might be already released, in case appendStream has failed due 1023 // m_loader might be already released, in case appendStream has failed due
1016 // to evictCodedFrames failing in didReceiveDataForClient. In that case 1024 // to evictCodedFrames or WebSourceBuffer append failing in
1017 // appendStreamDone will be invoked from there, no need to repeat it here. 1025 // didReceiveDataForClient. In that case appendStreamDone will be invoked
1026 // from there, no need to repeat it here.
1018 if (m_loader) 1027 if (m_loader)
1019 appendStreamDone(false); 1028 appendStreamDone(true, false);
1020 } 1029 }
1021 1030
1022 DEFINE_TRACE(SourceBuffer) 1031 DEFINE_TRACE(SourceBuffer)
1023 { 1032 {
1024 visitor->trace(m_source); 1033 visitor->trace(m_source);
1025 visitor->trace(m_trackDefaults); 1034 visitor->trace(m_trackDefaults);
1026 visitor->trace(m_asyncEventQueue); 1035 visitor->trace(m_asyncEventQueue);
1027 visitor->trace(m_appendBufferAsyncPartRunner); 1036 visitor->trace(m_appendBufferAsyncPartRunner);
1028 visitor->trace(m_removeAsyncPartRunner); 1037 visitor->trace(m_removeAsyncPartRunner);
1029 visitor->trace(m_appendStreamAsyncPartRunner); 1038 visitor->trace(m_appendStreamAsyncPartRunner);
1030 visitor->trace(m_stream); 1039 visitor->trace(m_stream);
1031 visitor->trace(m_audioTracks); 1040 visitor->trace(m_audioTracks);
1032 visitor->trace(m_videoTracks); 1041 visitor->trace(m_videoTracks);
1033 EventTargetWithInlineData::trace(visitor); 1042 EventTargetWithInlineData::trace(visitor);
1034 ActiveDOMObject::trace(visitor); 1043 ActiveDOMObject::trace(visitor);
1035 } 1044 }
1036 1045
1037 } // namespace blink 1046 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698