Title: [187377] trunk
Revision
187377
Author
[email protected]
Date
2015-07-24 19:37:39 -0700 (Fri, 24 Jul 2015)

Log Message

[MSE] Incorrect sample timestamps when using "sequence" mode
https://bugs.webkit.org/show_bug.cgi?id=147252

Patch by Sajid Anwar <[email protected]> on 2015-07-24
Reviewed by Jer Noble.

Source/WebCore:

Test: media/media-source/media-source-sequence-timestamps.html

According to the specification, the "sequence" mode indicates that the samples in the buffer will use generated timestamps
instead of the presentation/decode timestamps already present in the sample. The current implementation always adds
the current timestamp offset to the samples' timestamps, as expected for "segments" mode.

Add a method to media samples to allow their presentation and decode timestamps to be set to specific values.

* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample): Fix an algorithm condition to align with the specification, and
    correctly set the presentation and decode timestamps of samples when in "sequence" mode.
* platform/MediaSample.h:
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::MediaSampleAVFObjC::setTimestamps): Add a new method to set the values of a sample's presentation and decode timestamps.
* platform/mock/mediasource/MockBox.h:
(WebCore::MockBox::setTimestamps): Set m_presentationTimestamp and m_decodeTimestamp.
* platform/mock/mediasource/MockSourceBufferPrivate.cpp:
(WebCore::MockMediaSample::offsetTimestampsBy): Pass to MockBox.
* testing/Internals.cpp:
(WebCore::Internals::setShouldGenerateTimestamps): Expose the internal `setShouldGenerateTimestamps` method of SourceBuffer.
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* media/media-source/media-source-sequence-timestamps-expected.txt: Added.
* media/media-source/media-source-sequence-timestamps.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (187376 => 187377)


--- trunk/LayoutTests/ChangeLog	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/LayoutTests/ChangeLog	2015-07-25 02:37:39 UTC (rev 187377)
@@ -1,3 +1,13 @@
+2015-07-24  Sajid Anwar  <[email protected]>
+
+        [MSE] Incorrect sample timestamps when using "sequence" mode
+        https://bugs.webkit.org/show_bug.cgi?id=147252
+
+        Reviewed by Jer Noble.
+
+        * media/media-source/media-source-sequence-timestamps-expected.txt: Added.
+        * media/media-source/media-source-sequence-timestamps.html: Added.
+
 2015-07-24  Chris Fleizach  <[email protected]>
 
         AX: scrollable elements do not allow 3-finger swipe

Added: trunk/LayoutTests/media/media-source/media-source-sequence-timestamps-expected.txt (0 => 187377)


--- trunk/LayoutTests/media/media-source/media-source-sequence-timestamps-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/media-source/media-source-sequence-timestamps-expected.txt	2015-07-25 02:37:39 UTC (rev 187377)
@@ -0,0 +1,17 @@
+RUN(audio.src = ""
+EVENT(sourceopen)
+RUN(sourceBuffer = source.addSourceBuffer("audio/mock; codecs=mock"))
+RUN(sourceBuffer.mode = "sequence")
+RUN(sourceBuffer.appendBuffer(initSegment))
+EVENT(updateend)
+RUN(sourceBuffer.appendBuffer(samples))
+EVENT(updateend)
+EXPECTED (bufferedSamples.length == '6') OK
+{PTS({0/1, 0.000000}), DTS({0/1, 0.000000}), duration({1000/1000, 1.000000}), flags(1), generation(0)}
+{PTS({1000/1000, 1.000000}), DTS({1000/1000, 1.000000}), duration({1000/1000, 1.000000}), flags(0), generation(0)}
+{PTS({2000/1000, 2.000000}), DTS({2000/1000, 2.000000}), duration({1000/1000, 1.000000}), flags(0), generation(0)}
+{PTS({3000/1000, 3.000000}), DTS({3000/1000, 3.000000}), duration({1000/1000, 1.000000}), flags(1), generation(0)}
+{PTS({4000/1000, 4.000000}), DTS({4000/1000, 4.000000}), duration({1000/1000, 1.000000}), flags(0), generation(0)}
+{PTS({5000/1000, 5.000000}), DTS({5000/1000, 5.000000}), duration({1000/1000, 1.000000}), flags(0), generation(0)}
+END OF TEST
+

Added: trunk/LayoutTests/media/media-source/media-source-sequence-timestamps.html (0 => 187377)


--- trunk/LayoutTests/media/media-source/media-source-sequence-timestamps.html	                        (rev 0)
+++ trunk/LayoutTests/media/media-source/media-source-sequence-timestamps.html	2015-07-25 02:37:39 UTC (rev 187377)
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>media-source-sequence-timestamps</title>
+    <script src=""
+    <script src=""
+    <script>
+    var source;
+    var sourceBuffer;
+    var initSegment;
+    var samples;
+    var bufferedSamples;
+    
+    var audio;
+
+    if (window.internals)
+        internals.initializeMockMediaSource();
+
+    function runTest()
+    {
+        audio = document.getElementsByTagName('audio')[0];
+
+        source = new MediaSource();
+        waitForEventOn(source, 'sourceopen', sourceOpen);
+        run('audio.src = ""
+    }
+
+    function sourceOpen()
+    {
+        run('sourceBuffer = source.addSourceBuffer("audio/mock; codecs=mock")');
+        run('sourceBuffer.mode = "sequence"');
+        internals.setShouldGenerateTimestamps(sourceBuffer, true);
+        waitForEventOn(sourceBuffer, 'updateend', loadSamples, false, true);
+        initSegment = makeAInit(8, [makeATrack(1, 'mock', TRACK_KIND.AUDIO)]);
+        run('sourceBuffer.appendBuffer(initSegment)');
+    }
+
+    function loadSamples()
+    {
+        // In "sequence" mode, the samples' timestamps are not used
+        samples = concatenateSamples([
+            makeASample(0, 0, 1, 1, SAMPLE_FLAG.SYNC, 0),
+            makeASample(2, 2, 1, 1, SAMPLE_FLAG.NONE, 0),
+            makeASample(4, 4, 1, 1, SAMPLE_FLAG.NONE, 0),
+            makeASample(6, 6, 1, 1, SAMPLE_FLAG.SYNC, 0),
+            makeASample(8, 8, 1, 1, SAMPLE_FLAG.NONE, 0),
+            makeASample(10, 10, 1, 1, SAMPLE_FLAG.NONE, 0),
+        ]);
+        waitForEventOn(sourceBuffer, 'updateend', samplesAdded, false, true);
+        run('sourceBuffer.appendBuffer(samples)');
+    }
+
+    function samplesAdded()
+    {
+        bufferedSamples = internals.bufferedSamplesForTrackID(sourceBuffer, 1);
+        testExpected("bufferedSamples.length", 6);
+        bufferedSamples.forEach(consoleWrite);
+
+        endTest();
+    }
+    </script>
+</head>
+<body _onload_="runTest()">
+    <audio></audio>
+</body>

Modified: trunk/Source/WebCore/ChangeLog (187376 => 187377)


--- trunk/Source/WebCore/ChangeLog	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/ChangeLog	2015-07-25 02:37:39 UTC (rev 187377)
@@ -1,3 +1,33 @@
+2015-07-24  Sajid Anwar  <[email protected]>
+
+        [MSE] Incorrect sample timestamps when using "sequence" mode
+        https://bugs.webkit.org/show_bug.cgi?id=147252
+
+        Reviewed by Jer Noble.
+
+        Test: media/media-source/media-source-sequence-timestamps.html
+
+        According to the specification, the "sequence" mode indicates that the samples in the buffer will use generated timestamps
+        instead of the presentation/decode timestamps already present in the sample. The current implementation always adds
+        the current timestamp offset to the samples' timestamps, as expected for "segments" mode.
+
+        Add a method to media samples to allow their presentation and decode timestamps to be set to specific values.
+
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::sourceBufferPrivateDidReceiveSample): Fix an algorithm condition to align with the specification, and
+            correctly set the presentation and decode timestamps of samples when in "sequence" mode.
+        * platform/MediaSample.h:
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (WebCore::MediaSampleAVFObjC::setTimestamps): Add a new method to set the values of a sample's presentation and decode timestamps.
+        * platform/mock/mediasource/MockBox.h:
+        (WebCore::MockBox::setTimestamps): Set m_presentationTimestamp and m_decodeTimestamp.
+        * platform/mock/mediasource/MockSourceBufferPrivate.cpp:
+        (WebCore::MockMediaSample::offsetTimestampsBy): Pass to MockBox.
+        * testing/Internals.cpp:
+        (WebCore::Internals::setShouldGenerateTimestamps): Expose the internal `setShouldGenerateTimestamps` method of SourceBuffer.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2015-07-24  Anders Carlsson  <[email protected]>
 
         WKWebsiteDataStore remove methods don't properly delete cookies

Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (187376 => 187377)


--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp	2015-07-25 02:37:39 UTC (rev 187377)
@@ -1382,7 +1382,7 @@
         MediaTime frameDuration = sample->duration();
 
         // 1.3 If mode equals "sequence" and group start timestamp is set, then run the following steps:
-        if (m_mode == sequenceKeyword()) {
+        if (m_mode == sequenceKeyword() && m_groupStartTimestamp.isValid()) {
             // 1.3.1 Set timestampOffset equal to group start timestamp - presentation timestamp.
             m_timestampOffset = m_groupStartTimestamp;
 
@@ -1447,8 +1447,11 @@
             continue;
         }
 
-        if (m_timestampOffset) {
-            // Reflect the new timestamps back into the sample.
+        if (m_mode == sequenceKeyword()) {
+            // Use the generated timestamps instead of the sample's timestamps.
+            sample->setTimestamps(presentationTimestamp, decodeTimestamp);
+        } else if (m_timestampOffset) {
+            // Reflect the timestamp offset into the sample.
             sample->offsetTimestampsBy(m_timestampOffset);
         }
 

Modified: trunk/Source/WebCore/platform/MediaSample.h (187376 => 187377)


--- trunk/Source/WebCore/platform/MediaSample.h	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/platform/MediaSample.h	2015-07-25 02:37:39 UTC (rev 187377)
@@ -59,6 +59,7 @@
     virtual size_t sizeInBytes() const = 0;
     virtual FloatSize presentationSize() const = 0;
     virtual void offsetTimestampsBy(const MediaTime&) = 0;
+    virtual void setTimestamps(const MediaTime&, const MediaTime&) = 0;
 
     enum SampleFlags {
         None = 0,

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm (187376 => 187377)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm	2015-07-25 02:37:39 UTC (rev 187377)
@@ -459,6 +459,7 @@
     virtual PlatformSample platformSample() override;
     virtual void dump(PrintStream&) const override;
     virtual void offsetTimestampsBy(const MediaTime&) override;
+    virtual void setTimestamps(const MediaTime&, const MediaTime&) override;
 
     RetainPtr<CMSampleBufferRef> m_sample;
     AtomicString m_id;
@@ -531,6 +532,29 @@
     m_sample = adoptCF(newSample);
 }
 
+void MediaSampleAVFObjC::setTimestamps(const WTF::MediaTime &presentationTimestamp, const WTF::MediaTime &decodeTimestamp)
+{
+    CMItemCount itemCount = 0;
+    if (noErr != CMSampleBufferGetSampleTimingInfoArray(m_sample.get(), 0, nullptr, &itemCount))
+        return;
+
+    Vector<CMSampleTimingInfo> timingInfoArray;
+    timingInfoArray.grow(itemCount);
+    if (noErr != CMSampleBufferGetSampleTimingInfoArray(m_sample.get(), itemCount, timingInfoArray.data(), nullptr))
+        return;
+
+    for (auto& timing : timingInfoArray) {
+        timing.presentationTimeStamp = toCMTime(presentationTimestamp);
+        timing.decodeTimeStamp = toCMTime(decodeTimestamp);
+    }
+
+    CMSampleBufferRef newSample;
+    if (noErr != CMSampleBufferCreateCopyWithNewTiming(kCFAllocatorDefault, m_sample.get(), itemCount, timingInfoArray.data(), &newSample))
+        return;
+
+    m_sample = adoptCF(newSample);
+}
+
 #pragma mark -
 #pragma mark MediaDescriptionAVFObjC
 

Modified: trunk/Source/WebCore/platform/mock/mediasource/MockBox.h (187376 => 187377)


--- trunk/Source/WebCore/platform/mock/mediasource/MockBox.h	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockBox.h	2015-07-25 02:37:39 UTC (rev 187377)
@@ -135,6 +135,11 @@
         m_presentationTimestamp += offset;
         m_decodeTimestamp += offset;
     }
+    void setTimestamps(const MediaTime& presentationTimestamp, const MediaTime& decodeTimestamp)
+    {
+        m_presentationTimestamp = presentationTimestamp;
+        m_decodeTimestamp = decodeTimestamp;
+    }
 
     enum {
         IsSync = 1 << 0,

Modified: trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp (187376 => 187377)


--- trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/platform/mock/mediasource/MockSourceBufferPrivate.cpp	2015-07-25 02:37:39 UTC (rev 187377)
@@ -64,6 +64,7 @@
     virtual FloatSize presentationSize() const override { return FloatSize(); }
     virtual void dump(PrintStream&) const override;
     virtual void offsetTimestampsBy(const MediaTime& offset) override { m_box.offsetTimestampsBy(offset); }
+    virtual void setTimestamps(const MediaTime& presentationTimestamp, const MediaTime& decodeTimestamp) override { m_box.setTimestamps(presentationTimestamp, decodeTimestamp); }
 
     unsigned generation() const { return m_box.generation(); }
 

Modified: trunk/Source/WebCore/testing/Internals.cpp (187376 => 187377)


--- trunk/Source/WebCore/testing/Internals.cpp	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/testing/Internals.cpp	2015-07-25 02:37:39 UTC (rev 187377)
@@ -2633,6 +2633,12 @@
 
     return buffer->bufferedSamplesForTrackID(trackID);
 }
+    
+void Internals::setShouldGenerateTimestamps(SourceBuffer* buffer, bool flag)
+{
+    if (buffer)
+        buffer->setShouldGenerateTimestamps(flag);
+}
 #endif
 
 #if ENABLE(VIDEO)

Modified: trunk/Source/WebCore/testing/Internals.h (187376 => 187377)


--- trunk/Source/WebCore/testing/Internals.h	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/testing/Internals.h	2015-07-25 02:37:39 UTC (rev 187377)
@@ -381,6 +381,7 @@
 #if ENABLE(MEDIA_SOURCE)
     WEBCORE_TESTSUPPORT_EXPORT void initializeMockMediaSource();
     Vector<String> bufferedSamplesForTrackID(SourceBuffer*, const AtomicString&);
+    void setShouldGenerateTimestamps(SourceBuffer*, bool);
 #endif
 
 #if ENABLE(VIDEO)

Modified: trunk/Source/WebCore/testing/Internals.idl (187376 => 187377)


--- trunk/Source/WebCore/testing/Internals.idl	2015-07-25 01:08:19 UTC (rev 187376)
+++ trunk/Source/WebCore/testing/Internals.idl	2015-07-25 02:37:39 UTC (rev 187377)
@@ -355,6 +355,7 @@
 
     [Conditional=MEDIA_SOURCE] void initializeMockMediaSource();
     [Conditional=MEDIA_SOURCE] DOMString[] bufferedSamplesForTrackID(SourceBuffer buffer, DOMString trackID);
+    [Conditional=MEDIA_SOURCE] void setShouldGenerateTimestamps(SourceBuffer buffer, boolean flag);
 
     [Conditional=VIDEO] void beginMediaSessionInterruption();
     [Conditional=VIDEO] void endMediaSessionInterruption(DOMString flags);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to