Add the timestampOffset attribute to SourceBuffer.
authorannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Aug 2012 16:58:02 +0000 (16:58 +0000)
committerannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Aug 2012 16:58:02 +0000 (16:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93303

Reviewed by Dimitri Glazkov.

On the 30 July 2012 version of the Media Source Extensions spec, a timestampOffset
attribute was added to the SourceBuffer object:
http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-timestampoffset

Source/WebCore:

Tests: additions to http/tests/media/media-source/video-media-source-objects.html

* Modules/mediasource/MediaSource.cpp:
(WebCore::MediaSource::setTimestampOffset): Set the timestampOffset on MediaPlayer.
(WebCore):
* Modules/mediasource/MediaSource.h:
(MediaSource):
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::SourceBuffer): Let the timestampOffset be 0 initially
(WebCore::SourceBuffer::timestampOffset): Return the last value set.
(WebCore):
(WebCore::SourceBuffer::setTimestampOffset): Forward the call onto MediaSouce.
* Modules/mediasource/SourceBuffer.h:
(SourceBuffer):
* Modules/mediasource/SourceBuffer.idl: Create the new timestampOffset attr.
* platform/graphics/MediaPlayer.cpp:
(WebCore::NullMediaPlayerPrivate::sourceSetTimestampOffset): A null media player
    should just return false (nothing to set).
(WebCore):
(WebCore::MediaPlayer::sourceSetTimestampOffset):  Forward the call.
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::sourceSetTimestampOffset):

Source/WebKit/chromium:

* public/WebMediaPlayer.h:
(WebKit::WebMediaPlayer::sourceSetTimestampOffset): Add the new method.
* src/WebMediaPlayerClientImpl.cpp:
(WebKit):
(WebKit::WebMediaPlayerClientImpl::sourceSetTimestampOffset): Forward the call.
* src/WebMediaPlayerClientImpl.h:
(WebMediaPlayerClientImpl):

LayoutTests:

* http/tests/media/media-source/video-media-source-objects-expected.txt:
* http/tests/media/media-source/video-media-source-objects.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@125682 268f45cc-cd09-0410-ab3c-d52691b4dbfc

16 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/media/media-source/video-media-source-objects-expected.txt
LayoutTests/http/tests/media/media-source/video-media-source-objects.html
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediasource/MediaSource.cpp
Source/WebCore/Modules/mediasource/MediaSource.h
Source/WebCore/Modules/mediasource/SourceBuffer.cpp
Source/WebCore/Modules/mediasource/SourceBuffer.h
Source/WebCore/Modules/mediasource/SourceBuffer.idl
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/MediaPlayerPrivate.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/public/WebMediaPlayer.h
Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp
Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h

index 584511a..c5a6edd 100644 (file)
@@ -1,3 +1,17 @@
+2012-08-15  Anna Cavender  <annacc@chromium.org>
+
+        Add the timestampOffset attribute to SourceBuffer.
+        https://bugs.webkit.org/show_bug.cgi?id=93303
+
+        Reviewed by Dimitri Glazkov.
+
+        On the 30 July 2012 version of the Media Source Extensions spec, a timestampOffset 
+        attribute was added to the SourceBuffer object:
+        http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-timestampoffset
+
+        * http/tests/media/media-source/video-media-source-objects-expected.txt:
+        * http/tests/media/media-source/video-media-source-objects.html:
+
 2012-08-15  Pavel Chadnov  <chadnov@google.com>
 
         Web Inspector: Incorrect XHR responses when two async xhrs are sent synchronously
index f308e26..8093967 100644 (file)
@@ -26,6 +26,16 @@ EXPECTED (mediaSource.sourceBuffers[0].buffered.length == '1') OK
 EXPECTED (mediaSource.sourceBuffers[0].buffered.start(0) == '0') OK
 EXPECTED (mediaSource.sourceBuffers[0].buffered.end(0) > '1') OK
 
+Set timestampOffset.
+EXPECTED (segmentHelper.sourceBuffer.timestampOffset == '0') OK
+RUN(segmentHelper.sourceBuffer.timestampOffset = 5)
+EXPECTED (segmentHelper.sourceBuffer.timestampOffset == '5') OK
+
+Append 1 second of data.
+EXPECTED (mediaSource.sourceBuffers[0].buffered.length == '2') OK
+EXPECTED (mediaSource.sourceBuffers[0].buffered.start(1) == '5') OK
+EXPECTED (mediaSource.sourceBuffers[0].buffered.end(1) > '1') OK
+
 Remove SourceBuffer
 RUN(mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer))
 EXPECTED (mediaSource.sourceBuffers.length == '0') OK
@@ -38,5 +48,7 @@ Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 EXPECTED (mediaSource.sourceBuffers.length == '0') OK
 Test that addSourceBuffer() throws and error when the MediaSource is not associated with a media element.
 Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
+Test that setting timestampOffset throws an error when the MediaSource is not associated with a media element.
+Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 END OF TEST
 
index 55ca78b..894b7d0 100644 (file)
                 testExpected("mediaSource.sourceBuffers[0].buffered.end(0)", 1, '>');
 
                 consoleWrite("");
+                consoleWrite("Set timestampOffset.");
+                testExpected("segmentHelper.sourceBuffer.timestampOffset", 0);
+                run("segmentHelper.sourceBuffer.timestampOffset = 5");
+                testExpected("segmentHelper.sourceBuffer.timestampOffset", 5);
+
+                // Append another 1 second of media data.
+                consoleWrite("");
+                consoleWrite("Append 1 second of data.");
+                var endIndex = segmentHelper.getMediaSegmentIndexForTimestamp(1);
+                for (var i = 0; i <= endIndex; i++)
+                    segmentHelper.appendMediaSegment(i);
+                testExpected("mediaSource.sourceBuffers[0].buffered.length", 2);
+                testExpected("mediaSource.sourceBuffers[0].buffered.start(1)", 5);
+                testExpected("mediaSource.sourceBuffers[0].buffered.end(1)", 1, '>');
+
+                consoleWrite("");
                 consoleWrite("Remove SourceBuffer");
 
                 mediaSource.sourceBuffers.addEventListener('webkitremovesourcebuffer', onSourceBufferRemoved);
                     consoleWrite("Got expected exception " + e);
                 }
 
+                consoleWrite("Test that setting timestampOffset throws an error when the MediaSource is not associated with a media element.");
+                try {
+                    segmentHelper.sourceBuffer.timestampOffset = 10;
+                } catch (e) {
+                    consoleWrite("Got expected exception " + e);
+                }
+
                 endTest();
             }
             
index 36b84e7..65649c7 100644 (file)
@@ -1,3 +1,38 @@
+2012-08-15  Anna Cavender  <annacc@chromium.org>
+
+        Add the timestampOffset attribute to SourceBuffer.
+        https://bugs.webkit.org/show_bug.cgi?id=93303
+
+        Reviewed by Dimitri Glazkov.
+
+        On the 30 July 2012 version of the Media Source Extensions spec, a timestampOffset 
+        attribute was added to the SourceBuffer object:
+        http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-timestampoffset
+
+        Tests: additions to http/tests/media/media-source/video-media-source-objects.html
+
+        * Modules/mediasource/MediaSource.cpp:
+        (WebCore::MediaSource::setTimestampOffset): Set the timestampOffset on MediaPlayer.
+        (WebCore):
+        * Modules/mediasource/MediaSource.h:
+        (MediaSource):
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::SourceBuffer): Let the timestampOffset be 0 initially
+        (WebCore::SourceBuffer::timestampOffset): Return the last value set.
+        (WebCore):
+        (WebCore::SourceBuffer::setTimestampOffset): Forward the call onto MediaSouce.
+        * Modules/mediasource/SourceBuffer.h:
+        (SourceBuffer):
+        * Modules/mediasource/SourceBuffer.idl: Create the new timestampOffset attr.
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::NullMediaPlayerPrivate::sourceSetTimestampOffset): A null media player
+            should just return false (nothing to set).
+        (WebCore):
+        (WebCore::MediaPlayer::sourceSetTimestampOffset):  Forward the call.
+        * platform/graphics/MediaPlayer.h:
+        * platform/graphics/MediaPlayerPrivate.h:
+        (WebCore::MediaPlayerPrivateInterface::sourceSetTimestampOffset):
+
 2012-08-15  Pavel Chadnov  <chadnov@google.com>
 
         Web Inspector: Incorrect XHR responses when two async xhrs are sent synchronously
index e1317f5..cc4f9d7 100644 (file)
@@ -267,6 +267,20 @@ void MediaSource::abort(const String& id, ExceptionCode& ec)
         ASSERT_NOT_REACHED();
 }
 
+bool MediaSource::setTimestampOffset(const String& id, double offset, ExceptionCode& ec)
+{
+    if (!m_player || m_readyState != openKeyword()) {
+        ec = INVALID_STATE_ERR;
+        return false;
+    }
+
+    if (!m_player->sourceSetTimestampOffset(id, offset)) {
+        ec = INVALID_STATE_ERR;
+        return false;
+    }
+    return true;
+}
+
 const AtomicString& MediaSource::interfaceName() const
 {
     return eventNames().interfaceForMediaSource;
index 2c85fd0..b638333 100644 (file)
@@ -80,6 +80,7 @@ public:
     PassRefPtr<TimeRanges> buffered(const String& id, ExceptionCode&) const;
     void append(const String& id, PassRefPtr<Uint8Array> data, ExceptionCode&);
     void abort(const String& id, ExceptionCode&);
+    bool setTimestampOffset(const String& id, double, ExceptionCode&);
 
     // EventTarget interface
     virtual const AtomicString& interfaceName() const OVERRIDE;
index 5919108..1d6e606 100644 (file)
@@ -41,6 +41,7 @@ namespace WebCore {
 SourceBuffer::SourceBuffer(const String& id, PassRefPtr<MediaSource> source)
     : m_id(id)
     , m_source(source)
+    , m_timestampOffset(0)
 {
 }
 
@@ -58,6 +59,22 @@ PassRefPtr<TimeRanges> SourceBuffer::buffered(ExceptionCode& ec) const
     return m_source->buffered(id(), ec);
 }
 
+double SourceBuffer::timestampOffset() const
+{
+    return m_timestampOffset;
+}
+
+void SourceBuffer::setTimestampOffset(double offset, ExceptionCode& ec)
+{
+    if (!m_source) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    if (m_source->setTimestampOffset(id(), offset, ec))
+        m_timestampOffset = offset;
+}
+
 void SourceBuffer::append(PassRefPtr<Uint8Array> data, ExceptionCode& ec)
 {
     if (!m_source) {
index d180dd4..7d1e586 100644 (file)
@@ -54,6 +54,9 @@ public:
 
     PassRefPtr<TimeRanges> buffered(ExceptionCode&) const;
 
+    double timestampOffset() const;
+    void setTimestampOffset(double, ExceptionCode&);
+
     void append(PassRefPtr<Uint8Array> data, ExceptionCode&);
 
     void abort(ExceptionCode&);
@@ -67,6 +70,8 @@ private:
 
     String m_id;
     RefPtr<MediaSource> m_source;
+    
+    double m_timestampOffset;
 };
 
 } // namespace WebCore
index 412b9cb..c7c6eb3 100644 (file)
@@ -39,6 +39,10 @@ module html {
         readonly attribute TimeRanges buffered
             getter raises(DOMException);
 
+        // Applies an offset to media segment timestamps.
+        attribute double timestampOffset
+            setter raises(DOMException);
+
         // Append segment data.
         void append(in Uint8Array data) raises (DOMException);
 
index 28c784c..42e308b 100644 (file)
@@ -155,6 +155,7 @@ public:
     virtual bool sourceAppend(const String&, const unsigned char*, unsigned) { return false; }
     virtual bool sourceAbort(const String&) { return false; }
     virtual void sourceEndOfStream(MediaPlayer::EndOfStreamStatus) { }
+    virtual bool sourceSetTimestampOffset(const String&, double) { return false; }
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
@@ -492,6 +493,11 @@ void MediaPlayer::sourceEndOfStream(MediaPlayer::EndOfStreamStatus status)
 {
     return m_private->sourceEndOfStream(status);
 }
+
+bool MediaPlayer::sourceSetTimestampOffset(const String& id, double offset)
+{
+    return m_private->sourceSetTimestampOffset(id, offset);
+}
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
index c86827b..de69222 100644 (file)
@@ -256,6 +256,7 @@ public:
     bool sourceAbort(const String& id);
     enum EndOfStreamStatus { EosNoError, EosNetworkError, EosDecodeError };
     void sourceEndOfStream(EndOfStreamStatus);
+    bool sourceSetTimestampOffset(const String& id, double offset);
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
index 58f1606..28d2d9e 100644 (file)
@@ -174,6 +174,7 @@ public:
     virtual bool sourceAppend(const String& id, const unsigned char* data, unsigned length) { return false; }
     virtual bool sourceAbort(const String& id) { return false; }
     virtual void sourceEndOfStream(MediaPlayer::EndOfStreamStatus) { };
+    virtual bool sourceSetTimestampOffset(const String& id, double offset) { return false; }
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
index f440f7a..a1b8eea 100644 (file)
@@ -1,3 +1,22 @@
+2012-08-15  Anna Cavender  <annacc@chromium.org>
+
+        Add the timestampOffset attribute to SourceBuffer.
+        https://bugs.webkit.org/show_bug.cgi?id=93303
+
+        Reviewed by Dimitri Glazkov.
+
+        On the 30 July 2012 version of the Media Source Extensions spec, a timestampOffset 
+        attribute was added to the SourceBuffer object:
+        http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-timestampoffset
+
+        * public/WebMediaPlayer.h:
+        (WebKit::WebMediaPlayer::sourceSetTimestampOffset): Add the new method.
+        * src/WebMediaPlayerClientImpl.cpp:
+        (WebKit):
+        (WebKit::WebMediaPlayerClientImpl::sourceSetTimestampOffset): Forward the call.
+        * src/WebMediaPlayerClientImpl.h:
+        (WebMediaPlayerClientImpl):
+
 2012-08-15  Peter Beverloo  <peter@chromium.org>
 
         [Chromium] Roll WebKit Chromium DEPS to r151672
index 3b8ef64..ed62754 100644 (file)
@@ -187,6 +187,7 @@ public:
     virtual bool sourceAppend(const WebString& id, const unsigned char* data, unsigned length) { return false; }
     virtual bool sourceAbort(const WebString& id) { return false; }
     virtual void sourceEndOfStream(EndOfStreamStatus)  { }
+    virtual bool sourceSetTimestampOffset(const WebString& id, double offset) { return false; }
 
     // Returns whether keySystem is supported. If true, the result will be
     // reported by an event.
index c48aa89..4a90a98 100644 (file)
@@ -435,6 +435,13 @@ void WebMediaPlayerClientImpl::sourceEndOfStream(WebCore::MediaPlayer::EndOfStre
     if (m_webMediaPlayer)
         m_webMediaPlayer->sourceEndOfStream(static_cast<WebMediaPlayer::EndOfStreamStatus>(status));
 }
+
+bool WebMediaPlayerClientImpl::sourceSetTimestampOffset(const String& id, double offset)
+{
+    if (!m_webMediaPlayer)
+        return false;
+    return m_webMediaPlayer->sourceSetTimestampOffset(id, offset);
+}
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
index 2df54cd..373015e 100644 (file)
@@ -164,6 +164,7 @@ public:
     virtual bool sourceAppend(const String&, const unsigned char* data, unsigned length);
     virtual bool sourceAbort(const String&);
     virtual void sourceEndOfStream(WebCore::MediaPlayer::EndOfStreamStatus);
+    virtual bool sourceSetTimestampOffset(const String&, double offset);
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)