Title: [177225] trunk
Revision
177225
Author
jer.no...@apple.com
Date
2014-12-12 11:27:51 -0800 (Fri, 12 Dec 2014)

Log Message

[MSE] Add support for SourceBuffer.mode.
https://bugs.webkit.org/show_bug.cgi?id=139265

Reviewed by Eric Carlson.

Source/WebCore:

Support setting SourceBuffer's mode property, and add support for "sequence" mode. Prior
to this change, "segments" mode was implied.

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::addSourceBuffer):
(WebCore::MediaSource::regenerateActiveSourceBuffers):
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::segmentsKeyword):
(WebCore::SourceBuffer::sequenceKeyword):
(WebCore::SourceBuffer::SourceBuffer):
(WebCore::SourceBuffer::setTimestampOffset):
(WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample):
(WebCore::SourceBuffer::setMode):
* Modules/mediasource/SourceBuffer.h:
* Modules/mediasource/SourceBuffer.idl:

LayoutTests:

* http/tests/media/media-source/mediasource-util.js:
* platform/mac/TestExpectations:

Add an expected-failure; the test fails due to lack of support for a non-DOM-visible
algorithm variable unsupported by the Mac port.
* platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (177224 => 177225)


--- trunk/LayoutTests/ChangeLog	2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/LayoutTests/ChangeLog	2014-12-12 19:27:51 UTC (rev 177225)
@@ -1,3 +1,17 @@
+2014-12-12  Jer Noble  <jer.no...@apple.com>
+
+        [MSE] Add support for SourceBuffer.mode.
+        https://bugs.webkit.org/show_bug.cgi?id=139265
+
+        Reviewed by Eric Carlson.
+
+        * http/tests/media/media-source/mediasource-util.js:
+        * platform/mac/TestExpectations:
+
+        Add an expected-failure; the test fails due to lack of support for a non-DOM-visible
+        algorithm variable unsupported by the Mac port.
+        * platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt: Added.
+
 2014-12-12  Radu Stavila  <stav...@adobe.com>
 
         [SVG Masking] Enable the use of <mask> elements for -webkit-mask-image

Modified: trunk/LayoutTests/http/tests/media/media-source/mediasource-util.js (177224 => 177225)


--- trunk/LayoutTests/http/tests/media/media-source/mediasource-util.js	2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/LayoutTests/http/tests/media/media-source/mediasource-util.js	2014-12-12 19:27:51 UTC (rev 177225)
@@ -28,18 +28,18 @@
         },
         {
             url: 'mp4/test.mp4',
-            type: 'video/mp4; codecs="mp4a.40.2, avc1.4D401E"',
+            type: 'video/mp4; codecs="mp4a.40.2,avc1.4d400d"',
             duration: 6.0424,
             init: { offset: 0, size: 1279 },
             media: [
-                {  offset: 1406, size: 23863, timecode: 0 },
-                {  offset: 25270, size: 25435, timecode: 0.797 },
-                {  offset: 50705, size: 24796, timecode: 1.594 },
-                {  offset: 75501, size: 25167, timecode: 2.390 },
-                {  offset: 100668, size: 22976, timecode: 3.187 },
-                {  offset: 123644, size: 25030, timecode: 3.984},
-                {  offset: 148674, size: 24929, timecode: 4.781 },
-                {  offset: 173603, size: 19271, timecode: 5.578 },
+                {  offset: 1407, size: 23863, timecode: 0 },
+                {  offset: 25270, size: 25435, timecode: 0.7968 },
+                {  offset: 50705, size: 24796, timecode: 1.5936 },
+                {  offset: 75501, size: 25167, timecode: 2.3904 },
+                {  offset: 100668, size: 22976, timecode: 3.1872 },
+                {  offset: 123644, size: 25030, timecode: 3.984 },
+                {  offset: 148674, size: 24929, timecode: 4.7808 },
+                {  offset: 173603, size: 19271, timecode: 5.5776 },
             ],
         }
     ];

Modified: trunk/LayoutTests/platform/mac/TestExpectations (177224 => 177225)


--- trunk/LayoutTests/platform/mac/TestExpectations	2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/LayoutTests/platform/mac/TestExpectations	2014-12-12 19:27:51 UTC (rev 177225)
@@ -1249,6 +1249,7 @@
 [ Yosemite+ ] http/tests/media/media-source/mediasource-play.html [ Pass ]
 [ Yosemite+ ] http/tests/media/media-source/mediasource-remove.html [ Pass ]
 [ Yosemite+ ] http/tests/media/media-source/mediasource-sourcebufferlist.html [ Pass ]
+[ Yosemite+ ] http/tests/media/media-source/mediasource-sourcebuffer-mode.html [ Pass ]
 
 # These two tests have "Error: InvalidStateError: DOM Exception 11" in output.
 [ Yosemite+ ] media/media-source/media-source-duplicate-seeked.html [ Failure ]

Added: trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt (0 => 177225)


--- trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/mac/http/tests/media/media-source/mediasource-sourcebuffer-mode-expected.txt	2014-12-12 19:27:51 UTC (rev 177225)
@@ -0,0 +1,14 @@
+ 
+PASS Test initial value of SourceBuffer.mode is "segments" 
+PASS Test setting SourceBuffer.mode 
+PASS Test setting a removed SourceBuffer's mode 
+PASS Test setting SourceBuffer.mode while still updating 
+PASS Test setting SourceBuffer.mode triggers parent MediaSource 'ended' to 'open' transition. 
+FAIL Test setting SourceBuffer.mode and SourceBuffer.timestampOffset while parsing media segment. assert_throws: Setting valid sourceBuffer.mode while still parsing media segment threw InvalidStateError. function "function () { sourceBuffer.mode = 'segments'; }" did not throw(stack: assert@http://127.0.0.1:8000/w3c/resources/testharness.js:2060:73
+assert_throws@http://127.0.0.1:8000/w3c/resources/testharness.js:946:19
+http://127.0.0.1:8000/media/media-source/mediasource-sourcebuffer-mode.html:114:32
+handleWaitCallback_@http://127.0.0.1:8000/media/media-source/mediasource-util.js:97:17
+[native code]
+step@http://127.0.0.1:8000/w3c/resources/testharness.js:1159:30
+http://127.0.0.1:8000/w3c/resources/testharness.js:1188:33)
+

Modified: trunk/Source/WebCore/ChangeLog (177224 => 177225)


--- trunk/Source/WebCore/ChangeLog	2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/ChangeLog	2014-12-12 19:27:51 UTC (rev 177225)
@@ -1,3 +1,26 @@
+2014-12-12  Jer Noble  <jer.no...@apple.com>
+
+        [MSE] Add support for SourceBuffer.mode.
+        https://bugs.webkit.org/show_bug.cgi?id=139265
+
+        Reviewed by Eric Carlson.
+
+        Support setting SourceBuffer's mode property, and add support for "sequence" mode. Prior
+        to this change, "segments" mode was implied.
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::addSourceBuffer):
+        (WebCore::MediaSource::regenerateActiveSourceBuffers):
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::segmentsKeyword):
+        (WebCore::SourceBuffer::sequenceKeyword):
+        (WebCore::SourceBuffer::SourceBuffer):
+        (WebCore::SourceBuffer::setTimestampOffset):
+        (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample):
+        (WebCore::SourceBuffer::setMode):
+        * Modules/mediasource/SourceBuffer.h:
+        * Modules/mediasource/SourceBuffer.idl:
+
 2014-12-12  Radu Stavila  <stav...@adobe.com>
 
         [SVG Masking] Enable the use of <mask> elements for -webkit-mask-image

Modified: trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp (177224 => 177225)


--- trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp	2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp	2014-12-12 19:27:51 UTC (rev 177225)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2013 Google Inc. All rights reserved.
+ * Copyright (C) 2013-2014 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -504,7 +505,9 @@
 {
     LOG(MediaSource, "MediaSource::addSourceBuffer(%s) %p", type.ascii().data(), this);
 
-    // 2.2 https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type
+    // 2.2 http://www.w3.org/TR/media-source/#widl-MediaSource-addSourceBuffer-SourceBuffer-DOMString-type
+    // When this method is invoked, the user agent must run the following steps:
+
     // 1. If type is null or an empty then throw an INVALID_ACCESS_ERR exception and
     // abort these steps.
     if (type.isNull() || type.isEmpty()) {
@@ -538,11 +541,25 @@
     }
 
     RefPtr<SourceBuffer> buffer = SourceBuffer::create(sourceBufferPrivate.releaseNonNull(), this);
-    // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
+
+    // 6. Set the generate timestamps flag on the new object to the value in the "Generate Timestamps Flag"
+    // column of the byte stream format registry [MSE-REGISTRY] entry that is associated with type.
+    // NOTE: In the current byte stream format registry <http://www.w3.org/2013/12/byte-stream-format-registry/>
+    // only the "MPEG Audio Byte Stream Format" has the "Generate Timestamps Flag" value set.
+    bool shouldGenerateTimestamps = contentType.type() == "audio/aac" || contentType.type() == "audio/mpeg";
+    buffer->setShouldGenerateTimestamps(shouldGenerateTimestamps);
+
+    // 7. If the generate timestamps flag equals true:
+    // ↳ Set the mode attribute on the new object to "sequence".
+    // Otherwise:
+    // ↳ Set the mode attribute on the new object to "segments".
+    buffer->setMode(shouldGenerateTimestamps ? SourceBuffer::sequenceKeyword() : SourceBuffer::segmentsKeyword(), IGNORE_EXCEPTION);
+
+    // 8. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
     m_sourceBuffers->add(buffer);
     regenerateActiveSourceBuffers();
 
-    // 7. Return the new object to the caller.
+    // 9. Return the new object to the caller.
     return buffer.get();
 }
 

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (177224 => 177225)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2014-12-12 19:27:51 UTC (rev 177225)
@@ -71,6 +71,18 @@
     return fudgeFactor;
 }
 
+const AtomicString& SourceBuffer::segmentsKeyword()
+{
+    static NeverDestroyed<AtomicString> segments("segments");
+    return segments.get();
+}
+
+const AtomicString& SourceBuffer::sequenceKeyword()
+{
+    static NeverDestroyed<AtomicString> segments("sequence");
+    return segments.get();
+}
+
 struct SourceBuffer::TrackBuffer {
     MediaTime lastDecodeTimestamp;
     MediaTime lastFrameDuration;
@@ -109,8 +121,10 @@
     , m_private(WTF::move(sourceBufferPrivate))
     , m_source(source)
     , m_asyncEventQueue(*this)
+    , m_mode(segmentsKeyword())
     , m_appendBufferTimer(*this, &SourceBuffer::appendBufferTimerFired)
-    , m_highestPresentationEndTimestamp(MediaTime::invalidTime())
+    , m_groupStartTimestamp(MediaTime::invalidTime())
+    , m_groupEndTimestamp(MediaTime::zeroTime())
     , m_buffered(TimeRanges::create())
     , m_appendState(WaitingForSegment)
     , m_timeOfBufferingMonitor(monotonicallyIncreasingTime())
@@ -124,6 +138,7 @@
     , m_receivedFirstInitializationSegment(false)
     , m_active(false)
     , m_bufferFull(false)
+    , m_shouldGenerateTimestamps(false)
 {
     ASSERT(m_source);
 
@@ -186,9 +201,14 @@
         return;
     }
 
-    // FIXME: Add step 6 text when mode attribute is implemented.
+    MediaTime newTimestampOffset = MediaTime::createWithDouble(offset);
+
+    // 6. If the mode attribute equals "sequence", then set the group start timestamp to new timestamp offset.
+    if (m_mode == sequenceKeyword())
+        m_groupStartTimestamp = newTimestampOffset;
+
     // 7. Update the attribute to the new value.
-    m_timestampOffset = MediaTime::createWithDouble(offset);
+    m_timestampOffset = newTimestampOffset;
 }
 
 void SourceBuffer::appendBuffer(PassRefPtr<ArrayBuffer> data, ExceptionCode& ec)
@@ -1197,95 +1217,126 @@
     RefPtr<MediaSample> sample = prpSample;
 
     // 3.5.8 Coded Frame Processing
+    // http://www.w3.org/TR/media-source/#sourcebuffer-coded-frame-processing
+
     // When complete coded frames have been parsed by the segment parser loop then the following steps
     // are run:
     // 1. For each coded frame in the media segment run the following steps:
     // 1.1. Loop Top
     do {
-        // 1.1 (ctd) Let presentation timestamp be a double precision floating point representation of
-        // the coded frame's presentation timestamp in seconds.
-        MediaTime presentationTimestamp = sample->presentationTime();
+        MediaTime presentationTimestamp;
+        MediaTime decodeTimestamp;
 
-        // 1.2 Let decode timestamp be a double precision floating point representation of the coded frame's
-        // decode timestamp in seconds.
-        MediaTime decodeTimestamp = sample->decodeTime();
+        if (m_shouldGenerateTimestamps) {
+            // ↳ If generate timestamps flag equals true:
+            // 1. Let presentation timestamp equal 0.
+            presentationTimestamp = MediaTime::zeroTime();
 
-        // 1.3 Let frame duration be a double precision floating point representation of the coded frame's
+            // 2. Let decode timestamp equal 0.
+            decodeTimestamp = MediaTime::zeroTime();
+        } else {
+            // ↳ Otherwise:
+            // 1. Let presentation timestamp be a double precision floating point representation of
+            // the coded frame's presentation timestamp in seconds.
+            presentationTimestamp = sample->presentationTime();
+
+            // 2. Let decode timestamp be a double precision floating point representation of the coded frame's
+            // decode timestamp in seconds.
+            decodeTimestamp = sample->decodeTime();
+        }
+
+        // 1.2 Let frame duration be a double precision floating point representation of the coded frame's
         // duration in seconds.
         MediaTime frameDuration = sample->duration();
 
-        // 1.4 If mode equals "sequence" and group start timestamp is set, then run the following steps:
-        // FIXME: add support for "sequence" mode
+        // 1.3 If mode equals "sequence" and group start timestamp is set, then run the following steps:
+        if (m_mode == sequenceKeyword()) {
+            // 1.3.1 Set timestampOffset equal to group start timestamp - presentation timestamp.
+            m_timestampOffset = m_groupStartTimestamp;
 
-        // 1.5 If timestampOffset is not 0, then run the following steps:
+            // 1.3.2 Set group end timestamp equal to group start timestamp.
+            m_groupEndTimestamp = m_groupStartTimestamp;
+
+            // 1.3.3 Set the need random access point flag on all track buffers to true.
+            for (auto& trackBuffer : m_trackBufferMap.values())
+                trackBuffer.needRandomAccessFlag = true;
+
+            // 1.3.4 Unset group start timestamp.
+            m_groupStartTimestamp = MediaTime::invalidTime();
+        }
+
+        // 1.4 If timestampOffset is not 0, then run the following steps:
         if (m_timestampOffset) {
-            // 1.5.1 Add timestampOffset to the presentation timestamp.
+            // 1.4.1 Add timestampOffset to the presentation timestamp.
             presentationTimestamp += m_timestampOffset;
 
-            // 1.5.2 Add timestampOffset to the decode timestamp.
+            // 1.4.2 Add timestampOffset to the decode timestamp.
             decodeTimestamp += m_timestampOffset;
-
-            // 1.5.3 If the presentation timestamp or decode timestamp is less than the presentation start
-            // time, then run the end of stream algorithm with the error parameter set to "decode", and
-            // abort these steps.
-            MediaTime presentationStartTime = MediaTime::zeroTime();
-            if (presentationTimestamp < presentationStartTime || decodeTimestamp < presentationStartTime) {
-#if !LOG_DISABLED
-                LOG(MediaSource, "SourceBuffer::sourceBufferPrivateDidReceiveSample(%p) - failing because %s", this, presentationTimestamp < presentationStartTime ? "presentationTimestamp < presentationStartTime" : "decodeTimestamp < presentationStartTime");
-#endif
-                m_source->streamEndedWithError(decodeError(), IgnorableExceptionCode());
-                return;
-            }
         }
 
-        // 1.6 Let track buffer equal the track buffer that the coded frame will be added to.
+        // 1.5 Let track buffer equal the track buffer that the coded frame will be added to.
         AtomicString trackID = sample->trackID();
         auto it = m_trackBufferMap.find(trackID);
         if (it == m_trackBufferMap.end())
             it = m_trackBufferMap.add(trackID, TrackBuffer()).iterator;
         TrackBuffer& trackBuffer = it->value;
 
-        // 1.7 If last decode timestamp for track buffer is set and decode timestamp is less than last
+        // 1.6 ↳ If last decode timestamp for track buffer is set and decode timestamp is less than last
         // decode timestamp:
         // OR
-        // If last decode timestamp for track buffer is set and the difference between decode timestamp and
+        // ↳ If last decode timestamp for track buffer is set and the difference between decode timestamp and
         // last decode timestamp is greater than 2 times last frame duration:
         if (trackBuffer.lastDecodeTimestamp.isValid() && (decodeTimestamp < trackBuffer.lastDecodeTimestamp
             || abs(decodeTimestamp - trackBuffer.lastDecodeTimestamp) > (trackBuffer.lastFrameDuration * 2))) {
-            // 1.7.1 If mode equals "segments":
-            // Set highest presentation end timestamp to presentation timestamp.
-            m_highestPresentationEndTimestamp = presentationTimestamp;
 
-            // If mode equals "sequence":
-            // Set group start timestamp equal to the highest presentation end timestamp.
-            // FIXME: Add support for "sequence" mode.
+            // 1.6.1:
+            if (m_mode == segmentsKeyword()) {
+                // ↳ If mode equals "segments":
+                // Set group end timestamp to presentation timestamp.
+                m_groupEndTimestamp = presentationTimestamp;
+            } else if (m_mode == sequenceKeyword()) {
+                // ↳ If mode equals "sequence":
+                // Set group start timestamp equal to the group end timestamp.
+                m_groupStartTimestamp = m_groupEndTimestamp;
+            }
 
             for (auto& trackBuffer : m_trackBufferMap.values()) {
-                // 1.7.2 Unset the last decode timestamp on all track buffers.
+                // 1.6.2 Unset the last decode timestamp on all track buffers.
                 trackBuffer.lastDecodeTimestamp = MediaTime::invalidTime();
-                // 1.7.3 Unset the last frame duration on all track buffers.
+                // 1.6.3 Unset the last frame duration on all track buffers.
                 trackBuffer.lastFrameDuration = MediaTime::invalidTime();
-                // 1.7.4 Unset the highest presentation timestamp on all track buffers.
+                // 1.6.4 Unset the highest presentation timestamp on all track buffers.
                 trackBuffer.highestPresentationTimestamp = MediaTime::invalidTime();
-                // 1.7.5 Set the need random access point flag on all track buffers to true.
+                // 1.6.5 Set the need random access point flag on all track buffers to true.
                 trackBuffer.needRandomAccessFlag = true;
             }
 
-            // 1.7.6 Jump to the Loop Top step above to restart processing of the current coded frame.
+            // 1.6.6 Jump to the Loop Top step above to restart processing of the current coded frame.
             continue;
         }
 
-        // 1.8 Let frame end timestamp equal the sum of presentation timestamp and frame duration.
+        // 1.7 Let frame end timestamp equal the sum of presentation timestamp and frame duration.
         MediaTime frameEndTimestamp = presentationTimestamp + frameDuration;
 
-        // 1.9 If presentation timestamp is less than appendWindowStart, then set the need random access
+        // 1.8 If presentation timestamp is less than appendWindowStart, then set the need random access
         // point flag to true, drop the coded frame, and jump to the top of the loop to start processing
         // the next coded frame.
-        // 1.10 If frame end timestamp is greater than appendWindowEnd, then set the need random access
+        // 1.9 If frame end timestamp is greater than appendWindowEnd, then set the need random access
         // point flag to true, drop the coded frame, and jump to the top of the loop to start processing
         // the next coded frame.
         // FIXME: implement append windows
 
+        // 1.10 If the decode timestamp is less than the presentation start time, then run the end of stream
+        // algorithm with the error parameter set to "decode", and abort these steps.
+        // NOTE: Until <https://www.w3.org/Bugs/Public/show_bug.cgi?id=27487> is resolved, we will only check
+        // the presentation timestamp.
+        MediaTime presentationStartTime = MediaTime::zeroTime();
+        if (presentationTimestamp < presentationStartTime) {
+            LOG(MediaSource, "SourceBuffer::sourceBufferPrivateDidReceiveSample(%p) - failing because presentationTimestamp < presentationStartTime", this);
+            m_source->streamEndedWithError(decodeError(), IgnorableExceptionCode());
+            return;
+        }
+
         // 1.11 If the need random access point flag on track buffer equals true, then run the following steps:
         if (trackBuffer.needRandomAccessFlag) {
             // 1.11.1 If the coded frame is not a random access point, then drop the coded frame and jump
@@ -1352,7 +1403,7 @@
                 erasedSamples.addRange(iter_pair.first, iter_pair.second);
         }
 
-        // If highest presentation timestamp for track buffer is set and less than presentation timestamp
+        // If highest presentation timestamp for track buffer is set and less than or equal to presentation timestamp
         if (trackBuffer.highestPresentationTimestamp.isValid() && trackBuffer.highestPresentationTimestamp <= presentationTimestamp) {
             // Remove all coded frames from track buffer that have a presentation timestamp greater than highest
             // presentation timestamp and less than or equal to frame end timestamp.
@@ -1367,8 +1418,7 @@
                 if (!bufferedLength)
                     break;
 
-                bool ignoreValid;
-                MediaTime highestBufferedTime = m_buffered->ranges().end(bufferedLength - 1, ignoreValid);
+                MediaTime highestBufferedTime = m_buffered->ranges().maximumBufferedTime();
 
                 PresentationOrderSampleMap::iterator_range range;
                 if (highestBufferedTime - trackBuffer.highestPresentationTimestamp < trackBuffer.lastFrameDuration)
@@ -1437,11 +1487,15 @@
         if (trackBuffer.highestPresentationTimestamp.isInvalid() || frameEndTimestamp > trackBuffer.highestPresentationTimestamp)
             trackBuffer.highestPresentationTimestamp = frameEndTimestamp;
 
-        // 1.21 If highest presentation end timestamp is unset or frame end timestamp is greater than highest
-        // presentation end timestamp, then set highest presentation end timestamp equal to frame end timestamp.
-        if (m_highestPresentationEndTimestamp.isInvalid() || frameEndTimestamp > m_highestPresentationEndTimestamp)
-            m_highestPresentationEndTimestamp = frameEndTimestamp;
+        // 1.21 If frame end timestamp is greater than group end timestamp, then set group end timestamp equal
+        // to frame end timestamp.
+        if (m_groupEndTimestamp.isInvalid() || frameEndTimestamp > m_groupEndTimestamp)
+            m_groupEndTimestamp = frameEndTimestamp;
 
+        // 1.22 If generate timestamps flag equals true, then set timestampOffset equal to frame end timestamp.
+        if (m_shouldGenerateTimestamps)
+            m_timestampOffset = frameEndTimestamp;
+
         m_buffered->add(presentationTimestamp.toDouble(), (presentationTimestamp + frameDuration + microsecond).toDouble());
         m_bufferedSinceLastMonitor += frameDuration.toDouble();
 
@@ -1451,9 +1505,9 @@
     // Steps 2-4 will be handled by MediaSource::monitorSourceBuffers()
 
     // 5. If the media segment contains data beyond the current duration, then run the duration change algorithm with new
-    // duration set to the maximum of the current duration and the highest end timestamp reported by HTMLMediaElement.buffered.
-    if (highestPresentationEndTimestamp() > m_source->duration())
-        m_source->setDurationInternal(highestPresentationEndTimestamp());
+    // duration set to the maximum of the current duration and the group end timestamp.
+    if (m_groupEndTimestamp > m_source->duration())
+        m_source->setDurationInternal(m_groupEndTimestamp);
 }
 
 bool SourceBuffer::hasAudio() const
@@ -1826,6 +1880,48 @@
     return downcast<Document>(*scriptExecutionContext());
 }
 
+void SourceBuffer::setMode(const AtomicString& newMode, ExceptionCode& ec)
+{
+    // 3.1 Attributes - mode
+    // http://www.w3.org/TR/media-source/#widl-SourceBuffer-mode
+
+    // On setting, run the following steps:
+
+    // 1. Let new mode equal the new value being assigned to this attribute.
+    // 2. If generate timestamps flag equals true and new mode equals "segments", then throw an INVALID_ACCESS_ERR exception and abort these steps.
+    if (m_shouldGenerateTimestamps && newMode == segmentsKeyword()) {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+    // 3. If this object has been removed from the sourceBuffers attribute of the parent media source, then throw an INVALID_STATE_ERR exception and abort these steps.
+    // 4. If the updating attribute equals true, then throw an INVALID_STATE_ERR exception and abort these steps.
+    if (isRemoved() || m_updating) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    // 5. If the readyState attribute of the parent media source is in the "ended" state then run the following steps:
+    if (m_source->readyState() == MediaSource::endedKeyword()) {
+        // 5.1. Set the readyState attribute of the parent media source to "open"
+        // 5.2. Queue a task to fire a simple event named sourceopen at the parent media source.
+        m_source->openIfInEndedState();
+    }
+
+    // 6. If the append state equals PARSING_MEDIA_SEGMENT, then throw an INVALID_STATE_ERR and abort these steps.
+    if (m_appendState == ParsingMediaSegment) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    // 7. If the new mode equals "sequence", then set the group start timestamp to the group end timestamp.
+    if (newMode == sequenceKeyword())
+        m_groupStartTimestamp = m_groupEndTimestamp;
+
+    // 8. Update the attribute to new mode.
+    m_mode = newMode;
+}
+
 } // namespace WebCore
 
 #endif

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h (177224 => 177225)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h	2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.h	2014-12-12 19:27:51 UTC (rev 177225)
@@ -63,6 +63,9 @@
 public:
     static PassRef<SourceBuffer> create(PassRef<SourceBufferPrivate>, MediaSource*);
 
+    static const AtomicString& segmentsKeyword();
+    static const AtomicString& sequenceKeyword();
+
     virtual ~SourceBuffer();
 
     // SourceBuffer.idl methods
@@ -79,7 +82,6 @@
 
     void abortIfUpdating();
     void removedFromMediaSource();
-    const MediaTime& highestPresentationEndTimestamp() const { return m_highestPresentationEndTimestamp; }
     void seekToTime(const MediaTime&);
 
 #if ENABLE(VIDEO_TRACK)
@@ -112,6 +114,12 @@
 
     Document& document() const;
 
+    const AtomicString& mode() const { return m_mode; }
+    void setMode(const AtomicString&, ExceptionCode&);
+
+    bool shouldGenerateTimestamps() const { return m_shouldGenerateTimestamps; }
+    void setShouldGenerateTimestamps(bool flag) { m_shouldGenerateTimestamps = flag; }
+
 protected:
     // EventTarget interface
     virtual void refEventTarget() override { ref(); }
@@ -182,6 +190,7 @@
     Ref<SourceBufferPrivate> m_private;
     MediaSource* m_source;
     GenericEventQueue m_asyncEventQueue;
+    AtomicString m_mode;
 
     Vector<unsigned char> m_pendingAppendData;
     Timer m_appendBufferTimer;
@@ -195,7 +204,8 @@
     Vector<AtomicString> m_textCodecs;
 
     MediaTime m_timestampOffset;
-    MediaTime m_highestPresentationEndTimestamp;
+    MediaTime m_groupStartTimestamp;
+    MediaTime m_groupEndTimestamp;
 
     HashMap<AtomicString, TrackBuffer> m_trackBufferMap;
     RefPtr<TimeRanges> m_buffered;
@@ -217,6 +227,7 @@
     bool m_receivedFirstInitializationSegment;
     bool m_active;
     bool m_bufferFull;
+    bool m_shouldGenerateTimestamps;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl (177224 => 177225)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl	2014-12-12 16:59:16 UTC (rev 177224)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.idl	2014-12-12 19:27:51 UTC (rev 177225)
@@ -28,6 +28,11 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
  
+[Conditional=MEDIA_SOURCE] enum AppendMode {
+    "segments",
+    "sequence"
+};
+
 [
     Conditional=MEDIA_SOURCE,
     NoInterfaceObject,
@@ -37,6 +42,8 @@
     JSGenerateToNativeObject,
 ] interface SourceBuffer : EventTarget {
 
+    [SetterRaisesException] attribute AppendMode mode;
+
     readonly attribute boolean updating;
   
     // Returns the time ranges buffered.
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to