Changeset 127675 in webkit


Ignore:
Timestamp:
Sep 5, 2012 6:58:35 PM (12 years ago)
Author:
vrk@chromium.org
Message:

Add the duration attribute to MediaSource
https://bugs.webkit.org/show_bug.cgi?id=95149

Reviewed by Eric Carlson.

Add support for the duration attribute recently added to the MediaSource spec.
http://dev.w3.org/html5/spec/media-elements.html#dom-media-duration

Source/WebCore:

Test: http/tests/media/media-source/video-media-source-duration-changed.html

  • Modules/mediasource/MediaSource.cpp:

(WebCore::MediaSource::duration): Added duration method.
(WebCore):
(WebCore::MediaSource::setDuration): Added duration setter.

  • Modules/mediasource/MediaSource.h:

(MediaSource):

  • Modules/mediasource/MediaSource.idl:
  • platform/graphics/MediaPlayer.cpp:

(WebCore::NullMediaPlayerPrivate::sourceSetDuration): Add empty definition.
(WebCore::MediaPlayer::sourceSetDuration): Forward call to m_private.
(WebCore):

  • platform/graphics/MediaPlayer.h:
  • platform/graphics/MediaPlayerPrivate.h:

(WebCore::MediaPlayerPrivateInterface::sourceSetDuration): Add empty definition.

Source/WebKit/chromium:

  • public/WebMediaPlayer.h:

(WebKit::WebMediaPlayer::sourceSetDuration): Add empty definition.

  • src/WebMediaPlayerClientImpl.cpp:

(WebKit::WebMediaPlayerClientImpl::sourceSetDuration): Forward call to m_webMediaPlayer.
(WebKit):

  • src/WebMediaPlayerClientImpl.h:

(WebMediaPlayerClientImpl):

LayoutTests:

  • http/tests/media/media-source/media-source.js:

(MediaSourceTest.SegmentHelper): Add parameter to specify whether full file should be loaded.
(MediaSourceTest.SegmentHelper.prototype.appendAllMediaSegments): Added method to append all file segments.
(MediaSourceTest.roundedEquals_): Added to see if values are equivalent after rounding.
(MediaSourceTest.expectDuration): Added to check for expected duration.
(MediaSourceTest.expectBufferedRange): Added to check for the expected buffered attribute value.

  • http/tests/media/media-source/video-media-source-duration-changed-expected.txt: Added.
  • http/tests/media/media-source/video-media-source-duration-changed.html: Added.
Location:
trunk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r127673 r127675  
     12012-09-05  Victoria Kirst  <vrk@chromium.org>
     2
     3        Add the duration attribute to MediaSource
     4        https://bugs.webkit.org/show_bug.cgi?id=95149
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add support for the duration attribute recently added to the MediaSource spec.
     9        http://dev.w3.org/html5/spec/media-elements.html#dom-media-duration
     10
     11        * http/tests/media/media-source/media-source.js:
     12        (MediaSourceTest.SegmentHelper): Add parameter to specify whether full file should be loaded.
     13        (MediaSourceTest.SegmentHelper.prototype.appendAllMediaSegments): Added method to append all file segments.
     14        (MediaSourceTest.roundedEquals_): Added to see if values are equivalent after rounding.
     15        (MediaSourceTest.expectDuration): Added to check for expected duration.
     16        (MediaSourceTest.expectBufferedRange): Added to check for the expected buffered attribute value.
     17        * http/tests/media/media-source/video-media-source-duration-changed-expected.txt: Added.
     18        * http/tests/media/media-source/video-media-source-duration-changed.html: Added.
     19
    1202012-09-05  Kenichi Ishibashi  <bashi@chromium.org>
    221
  • trunk/LayoutTests/http/tests/media/media-source/media-source.js

    r127088 r127675  
    22var mediaSource = new WebKitMediaSource();
    33
    4 MediaSourceTest.SegmentHelper = function(segmentInfo)
     4MediaSourceTest.SegmentHelper = function(segmentInfo, fullDuration)
    55{
    66    this.MediaSegmentsToLoad = 0;
     
    1515    var maxDuration = 3;
    1616    for (var i in this.segmentInfo.media) {
    17         if (this.segmentInfo.media[i].timecode > maxDuration)
     17        if (!fullDuration && this.segmentInfo.media[i].timecode > maxDuration)
    1818            break;
    1919        this.MediaSegmentsToLoad++;
     
    138138};
    139139
     140MediaSourceTest.SegmentHelper.prototype.appendAllMediaSegments = function()
     141{
     142    for (var i = 0; i < this.mediaSegments.length; i++)
     143        this.appendMediaSegment(i);
     144};
     145
    140146MediaSourceTest.SegmentHelper.prototype.appendUntilEndOfStream = function(startIndex)
    141147{
     
    309315};
    310316
     317MediaSourceTest.roundedEquals_ = function(expected, actual)
     318{
     319    return expected.toFixed(3) == actual.toFixed(3);
     320};
     321
     322MediaSourceTest.expectDuration = function(videoTag, mediaSource, expected)
     323{
     324    if (!this.roundedEquals_(expected, videoTag.duration))
     325        failTest("Unexpected duration. Expected " + expected + " got " + videoTag.duration);
     326    if (!this.roundedEquals_(expected, mediaSource.duration))
     327        failTest("Unexpected duration. Expected " + expected + " got " + mediaSource.duration);
     328};
     329
     330MediaSourceTest.expectBufferedRange = function(sourceBuffer, expected)
     331{
     332    if (sourceBuffer.buffered.length != expected.length)
     333        failTest("Unexpected number of buffered regions. Expected " + expected.length + " got " + sourceBuffer.buffered.length);
     334
     335    for (var i = 0; i < expected.length; i++) {
     336        var expectedStart = expected[i][0];
     337        var expectedEnd = expected[i][1];
     338        var actualStart = sourceBuffer.buffered.start(i);
     339        var actualEnd = sourceBuffer.buffered.end(i);
     340        if (!this.roundedEquals_(expectedStart, actualStart) ||
     341            !this.roundedEquals_(expectedEnd, actualEnd)) {
     342            failTest("Unexpected buffered region. Expected (" + expectedStart + ", " + expectedEnd + ") got ("
     343                     + actualStart + ", " + actualEnd +")");
     344        }
     345    }
     346};
     347
    311348MediaSourceTest.getReadyStateName = function(state)
    312349{
  • trunk/Source/WebCore/ChangeLog

    r127674 r127675  
     12012-09-05  Victoria Kirst  <vrk@chromium.org>
     2
     3        Add the duration attribute to MediaSource
     4        https://bugs.webkit.org/show_bug.cgi?id=95149
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add support for the duration attribute recently added to the MediaSource spec.
     9        http://dev.w3.org/html5/spec/media-elements.html#dom-media-duration
     10
     11        Test: http/tests/media/media-source/video-media-source-duration-changed.html
     12
     13        * Modules/mediasource/MediaSource.cpp:
     14        (WebCore::MediaSource::duration): Added duration method.
     15        (WebCore):
     16        (WebCore::MediaSource::setDuration): Added duration setter.
     17        * Modules/mediasource/MediaSource.h:
     18        (MediaSource):
     19        * Modules/mediasource/MediaSource.idl:
     20        * platform/graphics/MediaPlayer.cpp:
     21        (WebCore::NullMediaPlayerPrivate::sourceSetDuration): Add empty definition.
     22        (WebCore::MediaPlayer::sourceSetDuration): Forward call to m_private.
     23        (WebCore):
     24        * platform/graphics/MediaPlayer.h:
     25        * platform/graphics/MediaPlayerPrivate.h:
     26        (WebCore::MediaPlayerPrivateInterface::sourceSetDuration): Add empty definition.
     27
    1282012-09-05  Mihai Parparita  <mihaip@chromium.org>
    229
  • trunk/Source/WebCore/Modules/mediasource/MediaSource.cpp

    r127062 r127675  
    8585}
    8686
     87double MediaSource::duration() const
     88{
     89    return m_readyState == closedKeyword() ? std::numeric_limits<float>::quiet_NaN() : m_player->duration();
     90}
     91
     92void MediaSource::setDuration(double duration, ExceptionCode& ec)
     93{
     94    if (duration < 0.0 || isnan(duration)) {
     95        ec = INVALID_ACCESS_ERR;
     96        return;
     97    }
     98    if (m_readyState != openKeyword()) {
     99        ec = INVALID_STATE_ERR;
     100        return;
     101    }
     102    m_player->sourceSetDuration(duration);
     103}
     104
    87105SourceBuffer* MediaSource::addSourceBuffer(const String& type, ExceptionCode& ec)
    88106{
  • trunk/Source/WebCore/Modules/mediasource/MediaSource.h

    r127062 r127675  
    5555    SourceBufferList* activeSourceBuffers();
    5656
     57    double duration() const;
     58    void setDuration(double, ExceptionCode&);
     59
    5760    SourceBuffer* addSourceBuffer(const String& type, ExceptionCode&);
    5861    void removeSourceBuffer(SourceBuffer*, ExceptionCode&);
  • trunk/Source/WebCore/Modules/mediasource/MediaSource.idl

    r124953 r127675  
    4444        readonly attribute SourceBufferList activeSourceBuffers;
    4545
     46        attribute double duration setter raises (DOMException);
     47
    4648        SourceBuffer addSourceBuffer(in DOMString type) raises (DOMException);
    4749        void removeSourceBuffer(in SourceBuffer buffer) raises (DOMException);
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp

    r126157 r127675  
    155155    virtual bool sourceAppend(const String&, const unsigned char*, unsigned) { return false; }
    156156    virtual bool sourceAbort(const String&) { return false; }
     157    virtual void sourceSetDuration(double) { }
    157158    virtual void sourceEndOfStream(MediaPlayer::EndOfStreamStatus) { }
    158159    virtual bool sourceSetTimestampOffset(const String&, double) { return false; }
     
    491492}
    492493
     494void MediaPlayer::sourceSetDuration(double duration)
     495{
     496    m_private->sourceSetDuration(duration);
     497}
     498
    493499void MediaPlayer::sourceEndOfStream(MediaPlayer::EndOfStreamStatus status)
    494500{
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.h

    r127300 r127675  
    267267    PassRefPtr<TimeRanges> sourceBuffered(const String& id);
    268268    bool sourceAppend(const String& id, const unsigned char* data, unsigned length);
     269    void sourceSetDuration(double);
    269270    bool sourceAbort(const String& id);
    270271    enum EndOfStreamStatus { EosNoError, EosNetworkError, EosDecodeError };
  • trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h

    r125682 r127675  
    174174    virtual bool sourceAppend(const String& id, const unsigned char* data, unsigned length) { return false; }
    175175    virtual bool sourceAbort(const String& id) { return false; }
     176    virtual void sourceSetDuration(double) { }
    176177    virtual void sourceEndOfStream(MediaPlayer::EndOfStreamStatus) { };
    177178    virtual bool sourceSetTimestampOffset(const String& id, double offset) { return false; }
  • trunk/Source/WebKit/chromium/ChangeLog

    r127674 r127675  
     12012-09-05  Victoria Kirst  <vrk@chromium.org>
     2
     3        Add the duration attribute to MediaSource
     4        https://bugs.webkit.org/show_bug.cgi?id=95149
     5
     6        Reviewed by Eric Carlson.
     7
     8        Add support for the duration attribute recently added to the MediaSource spec.
     9        http://dev.w3.org/html5/spec/media-elements.html#dom-media-duration
     10
     11        * public/WebMediaPlayer.h:
     12        (WebKit::WebMediaPlayer::sourceSetDuration): Add empty definition.
     13        * src/WebMediaPlayerClientImpl.cpp:
     14        (WebKit::WebMediaPlayerClientImpl::sourceSetDuration): Forward call to m_webMediaPlayer.
     15        (WebKit):
     16        * src/WebMediaPlayerClientImpl.h:
     17        (WebMediaPlayerClientImpl):
     18
    1192012-09-05  Mihai Parparita  <mihaip@chromium.org>
    220
  • trunk/Source/WebKit/chromium/public/WebMediaPlayer.h

    r125682 r127675  
    187187    virtual bool sourceAppend(const WebString& id, const unsigned char* data, unsigned length) { return false; }
    188188    virtual bool sourceAbort(const WebString& id) { return false; }
     189    virtual void sourceSetDuration(double) { }
    189190    virtual void sourceEndOfStream(EndOfStreamStatus)  { }
    190191    virtual bool sourceSetTimestampOffset(const WebString& id, double offset) { return false; }
  • trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.cpp

    r127225 r127675  
    444444}
    445445
     446void WebMediaPlayerClientImpl::sourceSetDuration(double duration)
     447{
     448    if (m_webMediaPlayer)
     449        m_webMediaPlayer->sourceSetDuration(duration);
     450}
     451
    446452void WebMediaPlayerClientImpl::sourceEndOfStream(WebCore::MediaPlayer::EndOfStreamStatus status)
    447453{
  • trunk/Source/WebKit/chromium/src/WebMediaPlayerClientImpl.h

    r127172 r127675  
    164164    virtual bool sourceAppend(const String&, const unsigned char* data, unsigned length);
    165165    virtual bool sourceAbort(const String&);
     166    virtual void sourceSetDuration(double);
    166167    virtual void sourceEndOfStream(WebCore::MediaPlayer::EndOfStreamStatus);
    167168    virtual bool sourceSetTimestampOffset(const String&, double offset);
Note: See TracChangeset for help on using the changeset viewer.