Update HTMLMediaElement to the new OO MediaSource API.
authorannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Aug 2012 04:41:55 +0000 (04:41 +0000)
committerannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 7 Aug 2012 04:41:55 +0000 (04:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91775

Reviewed by Eric Carlson.

This patch rips out the old-style MediaSource API and allows a
MediaSource object to be attached to HTMLMediaElement.
http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html

Source/WebCore:

Test: http/tests/media/media-source/video-media-source-add-and-remove-buffers.html

Tests: updates to http/tests/media/media-source/*

* html/HTMLMediaElement.cpp:
(WebCore):
(WebCore::HTMLMediaElement::HTMLMediaElement): Remove old style API resources.
(WebCore::HTMLMediaElement::parseAttribute): Remove old style event attributes.
(WebCore::HTMLMediaElement::prepareForLoad): Set source state to "closed".
(WebCore::HTMLMediaElement::loadResource): Get MediaSource object from blob registry
    look up and, if found, set it's MediaPlayer pointer to the current MediaPlayer.
(WebCore::HTMLMediaElement::noneSupported): Set source state to "closed".
(WebCore::HTMLMediaElement::mediaEngineError): Set source state to "closed".
(WebCore::HTMLMediaElement::mediaPlayerSourceOpened): Set source state to "open".
(WebCore::HTMLMediaElement::mediaPlayerSourceURL): Change to new blob URL.
(WebCore::HTMLMediaElement::seek): Check if source state is "closed".
(WebCore::HTMLMediaElement::setSourceState): Helper function so that we don't have to
    keep checking for m_mediaSource.
(WebCore::HTMLMediaElement::userCancelledLoad): Set source state to "closed".
(WebCore::HTMLMediaElement::createMediaPlayer): If the current MediaPlayer is re-
    created, notify the MediaSource and reset its MediaPlayer.

* html/HTMLMediaElement.h: Remove old style API code and add a MediaSource object.
(HTMLMediaElement):
* html/HTMLMediaElement.idl: Remove old style API.

LayoutTests:

* http/tests/media/media-source/media-source.js:
(MediaSourceTest.SegmentHelper):
(MediaSourceTest.SegmentHelper.prototype.addSourceBuffer):
(MediaSourceTest.SegmentHelper.prototype.appendInitSegment):
(MediaSourceTest.SegmentHelper.prototype.appendMediaSegment):
(MediaSourceTest.SegmentHelper.prototype.appendUntilEndOfStream):
(MediaSourceTest.setSrcToMediaSourceTestURL):
(MediaSourceTest.defaultOnErrorChecks):
(MediaSourceTest.runOnSourceOpen.eventHandlerFunction):
(MediaSourceTest.runOnSourceOpen):
(MediaSourceTest.logSourceState):
(MediaSourceTest.expectSourceState):
* http/tests/media/media-source/video-media-source-abort-expected.txt:
* http/tests/media/media-source/video-media-source-abort.html:
* http/tests/media/media-source/video-media-source-add-and-remove-buffers-expected.txt: Renamed from LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-ids-expected.txt.
* http/tests/media/media-source/video-media-source-add-and-remove-buffers.html: Added.
* http/tests/media/media-source/video-media-source-add-and-remove-ids.html: Removed.
* http/tests/media/media-source/video-media-source-errors-expected.txt:
* http/tests/media/media-source/video-media-source-errors.html:
* http/tests/media/media-source/video-media-source-event-attributes-expected.txt:
* http/tests/media/media-source/video-media-source-event-attributes.html:
* http/tests/media/media-source/video-media-source-play-expected.txt:
* http/tests/media/media-source/video-media-source-play.html:
* http/tests/media/media-source/video-media-source-seek-expected.txt:
* http/tests/media/media-source/video-media-source-seek.html:
* http/tests/media/media-source/video-media-source-state-changes-expected.txt:
* http/tests/media/media-source/video-media-source-state-changes.html:

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

21 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/media/media-source/media-source.js
LayoutTests/http/tests/media/media-source/video-media-source-abort-expected.txt
LayoutTests/http/tests/media/media-source/video-media-source-abort.html
LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-buffers-expected.txt [moved from LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-ids-expected.txt with 50% similarity]
LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-buffers.html [new file with mode: 0644]
LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-ids.html [deleted file]
LayoutTests/http/tests/media/media-source/video-media-source-errors-expected.txt
LayoutTests/http/tests/media/media-source/video-media-source-errors.html
LayoutTests/http/tests/media/media-source/video-media-source-event-attributes-expected.txt
LayoutTests/http/tests/media/media-source/video-media-source-event-attributes.html
LayoutTests/http/tests/media/media-source/video-media-source-play-expected.txt
LayoutTests/http/tests/media/media-source/video-media-source-play.html
LayoutTests/http/tests/media/media-source/video-media-source-seek-expected.txt
LayoutTests/http/tests/media/media-source/video-media-source-seek.html
LayoutTests/http/tests/media/media-source/video-media-source-state-changes-expected.txt
LayoutTests/http/tests/media/media-source/video-media-source-state-changes.html
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/html/HTMLMediaElement.idl

index ef79389..e09534a 100644 (file)
@@ -1,3 +1,42 @@
+2012-08-06  Anna Cavender  <annacc@chromium.org>
+
+        Update HTMLMediaElement to the new OO MediaSource API.
+        https://bugs.webkit.org/show_bug.cgi?id=91775
+
+        Reviewed by Eric Carlson.
+
+        This patch rips out the old-style MediaSource API and allows a
+        MediaSource object to be attached to HTMLMediaElement.
+        http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html
+
+        * http/tests/media/media-source/media-source.js:
+        (MediaSourceTest.SegmentHelper):
+        (MediaSourceTest.SegmentHelper.prototype.addSourceBuffer):
+        (MediaSourceTest.SegmentHelper.prototype.appendInitSegment):
+        (MediaSourceTest.SegmentHelper.prototype.appendMediaSegment):
+        (MediaSourceTest.SegmentHelper.prototype.appendUntilEndOfStream):
+        (MediaSourceTest.setSrcToMediaSourceTestURL):
+        (MediaSourceTest.defaultOnErrorChecks):
+        (MediaSourceTest.runOnSourceOpen.eventHandlerFunction):
+        (MediaSourceTest.runOnSourceOpen):
+        (MediaSourceTest.logSourceState):
+        (MediaSourceTest.expectSourceState):
+        * http/tests/media/media-source/video-media-source-abort-expected.txt:
+        * http/tests/media/media-source/video-media-source-abort.html:
+        * http/tests/media/media-source/video-media-source-add-and-remove-buffers-expected.txt: Renamed from LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-ids-expected.txt.
+        * http/tests/media/media-source/video-media-source-add-and-remove-buffers.html: Added.
+        * http/tests/media/media-source/video-media-source-add-and-remove-ids.html: Removed.
+        * http/tests/media/media-source/video-media-source-errors-expected.txt:
+        * http/tests/media/media-source/video-media-source-errors.html:
+        * http/tests/media/media-source/video-media-source-event-attributes-expected.txt:
+        * http/tests/media/media-source/video-media-source-event-attributes.html:
+        * http/tests/media/media-source/video-media-source-play-expected.txt:
+        * http/tests/media/media-source/video-media-source-play.html:
+        * http/tests/media/media-source/video-media-source-seek-expected.txt:
+        * http/tests/media/media-source/video-media-source-seek.html:
+        * http/tests/media/media-source/video-media-source-state-changes-expected.txt:
+        * http/tests/media/media-source/video-media-source-state-changes.html:
+
 2012-08-06  Yuta Kitamura  <yutak@chromium.org>
 
         WebSocket.send() should accept ArrayBufferView
index 6dbb7ca..95d3b34 100644 (file)
@@ -1,9 +1,10 @@
 var MediaSourceTest = {};
+var mediaSource = new MediaSource();
 
 MediaSourceTest.SegmentHelper = function(segmentInfo)
 {
     this.MediaSegmentsToLoad = 0;
-    this.SourceID = 'sourceId';
+    this.sourceBuffer = null;
 
     this.videoTag = null;
     this.segmentInfo = segmentInfo;
@@ -121,32 +122,32 @@ MediaSourceTest.SegmentHelper.prototype.getData_ = function (url, start, length,
     request.send();
 };
 
-MediaSourceTest.SegmentHelper.prototype.addSourceId = function()
+MediaSourceTest.SegmentHelper.prototype.addSourceBuffer = function()
 {
-    this.videoTag.webkitSourceAddId(this.SourceID, this.segmentInfo.type);
+    this.sourceBuffer = mediaSource.addSourceBuffer(this.segmentInfo.type);
 };
 
 MediaSourceTest.SegmentHelper.prototype.appendInitSegment = function()
 {
-    this.videoTag.webkitSourceAppend(this.SourceID, this.initSegment);
+    this.sourceBuffer.append(this.initSegment);
 };
 
 MediaSourceTest.SegmentHelper.prototype.appendMediaSegment = function(index)
 {
-    this.videoTag.webkitSourceAppend(this.SourceID, this.mediaSegments[index]);
+    this.sourceBuffer.append(this.mediaSegments[index]);
 };
 
 MediaSourceTest.SegmentHelper.prototype.appendUntilEndOfStream = function(startIndex)
 {
-    if (!this.videoTag.webkitSourceAppend) {
-        failTest("webkitSourceAppend() is not available");
+    if (!this.sourceBuffer) {
+        failTest("MediaSource API is not available");
         return;
     }
 
     for (var index = startIndex; index < this.mediaSegments.length; index++)
         this.appendMediaSegment(index);
 
-    this.videoTag.webkitSourceEndOfStream(this.videoTag.EOS_NO_ERROR);
+    mediaSource.endOfStream();
 };
 
 MediaSourceTest.SegmentHelper.prototype.getTimeForMediaSegment = function(index)
@@ -176,7 +177,7 @@ MediaSourceTest.setSrcToMediaSourceTestURL = function(videoTag)
         return;
     }
 
-    videoTag.src = videoTag.webkitMediaSourceURL;
+    videoTag.src = webkitURL.createObjectURL(mediaSource);
 };
 
 MediaSourceTest.mediaErrorString = function(videoTag)
@@ -206,9 +207,9 @@ MediaSourceTest.defaultOnErrorChecks = function(event)
 
     consoleWrite("EVENT(error) : " + MediaSourceTest.mediaErrorString(videoTag));
 
-    if (videoTag.webkitSourceState != HTMLMediaElement.SOURCE_CLOSED) {
-        consoleWrite("Unexpected source state. Expected SOURCE_CLOSED" +
-                     " got " + getSourceStateName(videoTag.webkitSourceState));
+    if (mediaSource.readyState != "closed") {
+        consoleWrite("Unexpected source state. Expected 'closed'" +
+                     " got " + mediaSource.readyState);
     }
 };
 
@@ -270,42 +271,32 @@ MediaSourceTest.runOnSourceOpen = function(videoTag, onOpenFunction)
 {
     var eventHandlerFunction = function (event)
     {
+        if (videoTag.networkState != HTMLMediaElement.NETWORK_LOADING &&
+            videoTag.networkState != HTMLMediaElement.NETWORK_IDLE) {
+            failTest("Unexpected network state. Expected " +
+                     HTMLMediaElement.NETWORK_LOADING + " or " +
+                     HTMLMediaElement.NETWORK_IDLE +
+                     " got " + videoTag.readyState);
+        }
         event.target.removeEventListener('webkitsourceopen', eventHandlerFunction);
         onOpenFunction();
     };
-    videoTag.addEventListener('webkitsourceopen', eventHandlerFunction);
-    MediaSourceTest.setSrcToMediaSourceTestURL(videoTag);
-};
 
-MediaSourceTest.logSourceState = function(videoTag)
-{
-    consoleWrite("webkitSourceState : " + MediaSourceTest.getSourceStateName(videoTag.webkitSourceState));
+    mediaSource.addEventListener('webkitsourceopen', eventHandlerFunction);
+    MediaSourceTest.setSrcToMediaSourceTestURL(videoTag);
 };
 
-MediaSourceTest.expectSourceState = function(videoTag, expected)
+MediaSourceTest.logSourceState = function(mediaSource)
 {
-    if (videoTag.webkitSourceState != expected) {
-        failTest("Unexpected source state. Expected " +
-                 MediaSourceTest.getSourceStateName(expected) +
-                 " got " + MediaSourceTest.getSourceStateName(videoTag.webkitSourceState));
-    }
+    consoleWrite("webkitSourceState : " + mediaSource.readyState);
 };
 
-MediaSourceTest.getSourceStateName = function(state)
+MediaSourceTest.expectSourceState = function(mediaSource, expected)
 {
-    var stateName = "UNKNOWN";
-    switch (state) {
-        case HTMLMediaElement.SOURCE_CLOSED:
-            stateName = "SOURCE_CLOSED";
-            break;
-        case HTMLMediaElement.SOURCE_OPEN:
-            stateName = "SOURCE_OPEN";
-            break;
-        case HTMLMediaElement.SOURCE_ENDED:
-            stateName = "SOURCE_ENDED";
-            break;
+    if (mediaSource.readyState != expected) {
+        failTest("Unexpected source state. Expected " + expected +
+                 " got " + mediaSource.readyState);
     }
-    return stateName;
 };
 
 MediaSourceTest.expectReadyState = function(videoTag, expected)
index 658ff71..c5d28bf 100644 (file)
@@ -2,7 +2,6 @@ Tests webkitSourceAbort() functionality
 
 
 running abortDuringInitSegment
-EVENT(loadstart)
 EVENT(webkitsourceopen)
 Test aborting during initialization segment.
 Appending partial initialization segment.
@@ -13,7 +12,6 @@ EVENT(loadeddata)
 
 running abortDuringMediaSegment
 EVENT(emptied)
-EVENT(loadstart)
 EVENT(webkitsourceopen)
 Test aborting in the middle of a media segment.
 Appending partial media segment.
index 489c95a..3181456 100644 (file)
@@ -9,7 +9,7 @@
 
             function abortDuringInitSegment(runNextTestCase, videoTag)
             {
-                segmentHelper.addSourceId();
+                segmentHelper.addSourceBuffer();
 
                 consoleWrite("Test aborting during initialization segment.");
                 try {
                     var partialInitSegment = initSegment.subarray(0, initSegment.length / 2);
 
                     consoleWrite("Appending partial initialization segment.");
-                    videoTag.webkitSourceAppend(segmentHelper.SourceID, partialInitSegment);
+                    segmentHelper.sourceBuffer.append(partialInitSegment);
 
                     consoleWrite("Aborting append.");
-                    videoTag.webkitSourceAbort(segmentHelper.SourceID);
+                    segmentHelper.sourceBuffer.abort();
 
                     consoleWrite("Appending full initialization segment.");
                     segmentHelper.appendInitSegment();
@@ -42,7 +42,7 @@
 
             function abortDuringMediaSegment(runNextTestCase, videoTag)
             {
-                segmentHelper.addSourceId();
+                segmentHelper.addSourceBuffer();
 
                 consoleWrite("Test aborting in the middle of a media segment.");
                 try {
                     var partialMediaSegment = mediaSegment.subarray(0, mediaSegment.length / 2);
 
                     consoleWrite("Appending partial media segment.");
-                    videoTag.webkitSourceAppend(segmentHelper.SourceID, partialMediaSegment);
+                    segmentHelper.sourceBuffer.append(partialMediaSegment);
 
                     consoleWrite("Aborting append.");
-                    videoTag.webkitSourceAbort(segmentHelper.SourceID);
+                    segmentHelper.sourceBuffer.abort();
 
                     consoleWrite("Appending full media segment.");
                     segmentHelper.appendMediaSegment(0);
             {
                 findMediaElement();
 
-                waitForEvent('loadstart');
                 waitForEvent('loadeddata');
-                waitForEvent('webkitsourceopen');
+                waitForEvent('webkitsourceopen', "", false, false, mediaSource);
                 waitForEvent('playing');
-                waitForEvent('webkitsourceended');
+                waitForEvent('webkitsourceended', "", false, false, mediaSource);
                 waitForEvent('ended');
                 waitForEvent('emptied');
 
@@ -3,13 +3,8 @@ Tests webkitSourceAddId() & webkitSourceRemoveId() methods
 Test adding an ID while closed.
 Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 
-running testAddIdFailureCases
-EVENT(loadstart)
+running testAddBufferFailureCases
 EVENT(webkitsourceopen)
-Test empty ID case
-Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
-Test adding the same ID again.
-Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 Test empty type.
 Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
 Test an unsupported type.
@@ -17,48 +12,36 @@ Got expected exception Error: NOT_SUPPORTED_ERR: DOM Exception 9
 Test a supported type with an unsupported codec.
 Got expected exception Error: NOT_SUPPORTED_ERR: DOM Exception 9
 Test reaching sourceID limit.
-Test that SourceIDs can't be added while in the ended state.
+Test that SourceBuffers can't be added while in the ended state.
 Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 
-running testRemoveEmptyId
-EVENT(loadstart)
+running testRemoveNullBuffer
 EVENT(webkitsourceopen)
-Test empty ID case
+Test null buffer case
 Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
 
-running testRemoveNonexistentId
-EVENT(loadstart)
-EVENT(webkitsourceopen)
-Test removing an ID that was never added.
-Got expected exception Error: SYNTAX_ERR: DOM Exception 12
-
 running testRemoveAgain
-EVENT(loadstart)
 EVENT(webkitsourceopen)
-Test removing an ID that was already removed.
-Got expected exception Error: SYNTAX_ERR: DOM Exception 12
+Test removing a buffer that was already removed.
+Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 
-running testRemoveIdAfterEnded
-EVENT(loadstart)
+running testRemoveBufferAfterEnded
 EVENT(webkitsourceopen)
-Test that an ID can be removed while in the ended state.
+Test that a buffer can be removed while in the ended state.
 
-running testAddIdAfterRemoving
-EVENT(loadstart)
+running testAddBufferAfterRemoving
 EVENT(webkitsourceopen)
-Test that an ID can be added again after it is removed.
+Test that a buffer can be added again after it is removed.
 Unexpected exception: Error: QUOTA_EXCEEDED_ERR: DOM Exception 22
 
 running testAppendFailureCases
-EVENT(loadstart)
 EVENT(webkitsourceopen)
-Test append with empty ID.
-Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
-Test append with an invalid ID
-Got expected exception Error: SYNTAX_ERR: DOM Exception 12
+Test a successful append.
 Test append with a null buffer.
 Got expected exception Error: INVALID_ACCESS_ERR: DOM Exception 15
-Test a successful append.
-Got expected exception Error: SYNTAX_ERR: DOM Exception 12
+Test append after ended.
+Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
+Test append after buffer has been removed.
+Got expected exception Error: INVALID_STATE_ERR: DOM Exception 11
 END OF TEST
 
diff --git a/LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-buffers.html b/LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-buffers.html
new file mode 100644 (file)
index 0000000..390fd45
--- /dev/null
@@ -0,0 +1,201 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src="/media-resources/video-test.js"></script>
+        <script src="/media/resources/media-source/webm/segment-info.js"></script>
+        <script src="media-source.js"></script>
+        <script>
+            var segmentHelper = new MediaSourceTest.SegmentHelper(WebMSegmentInfo.testWebM);
+            var defaultSourceMimetype = segmentHelper.segmentInfo.type;
+
+            function expectExceptionOnAddBuffer(type, error)
+            {
+                try {
+                    segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(type);
+                    failTest("Expected an exception");
+                } catch (e) {
+                    if (!(e.code == error)) {
+                        failTest("Unexpected exception " + e);
+                        throw e;
+                    }
+                    consoleWrite("Got expected exception " + e);
+                }
+            }
+
+            function expectExceptionOnRemoveBuffer(buffer, error)
+            {
+                try {
+                    mediaSource.removeSourceBuffer(buffer);
+                    failTest("Expected an exception");
+                } catch (e) {
+                    if (!(e.code == error)) {
+                        failTest("Unexpected exception " + e);
+                        throw e;
+                    }
+                    consoleWrite("Got expected exception " + e);
+                }
+            }
+
+            function expectExceptionOnAppend(buf, error)
+            {
+                try {
+                    segmentHelper.sourceBuffer.append(buf);
+                    failTest("Expected an exception");
+                } catch (e) {
+                    if (!(e.code == error)) {
+                        failTest("Unexpected exception " + e);
+                        throw e;
+                    }
+                    consoleWrite("Got expected exception " + e);
+                }
+            }
+
+            function testAddBufferWhileClosed(videoTag)
+            {
+                consoleWrite("Test adding an ID while closed.");
+                expectExceptionOnAddBuffer(defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
+            }
+
+            function testAddBufferFailureCases(runNextTestCase, videoTag)
+            {
+                consoleWrite("Test empty type.");
+                expectExceptionOnAddBuffer("", DOMException.INVALID_ACCESS_ERR);
+
+                consoleWrite("Test an unsupported type.");
+                expectExceptionOnAddBuffer("audio/x-unsupported-format", DOMException.NOT_SUPPORTED_ERR);
+
+                consoleWrite("Test a supported type with an unsupported codec.");
+                expectExceptionOnAddBuffer("video/webm; codecs=\"vp8, speex\"", DOMException.NOT_SUPPORTED_ERR);
+
+                consoleWrite("Test reaching sourceID limit.");
+                var reachedIdLimit = false;
+
+                // The 20 here is an arbitrary upper limit to make sure the test terminates. This test
+                // assumes that implementations won't support more than 20 sourceID's simultaneously.
+                for (var i = 0; i < 20; ++i) {
+                    try {
+                        mediaSource.addSourceBuffer(defaultSourceMimetype);
+                    } catch(e) {
+                        if (e.code != DOMException.QUOTA_EXCEEDED_ERR) {
+                            failTest("Unexpected exception " + e);
+                            throw e;
+                        }
+                        reachedIdLimit = true;
+                        break;
+                    }
+                }
+
+                if (!reachedIdLimit) {
+                    failTest("Failed to reach SourceID limit.");
+                    return;
+                }
+
+                consoleWrite("Test that SourceBuffers can't be added while in the ended state.");
+                mediaSource.endOfStream();
+                expectExceptionOnAddBuffer(defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
+
+                runNextTestCase();
+            }
+
+            function testRemoveNullBuffer(runNextTestCase, videoTag)
+            {
+                consoleWrite("Test null buffer case");
+                expectExceptionOnRemoveBuffer(null, DOMException.INVALID_ACCESS_ERR);
+
+                runNextTestCase();
+            }
+
+            function testRemoveAgain(runNextTestCase, videoTag)
+            {
+                consoleWrite("Test removing a buffer that was already removed.");
+                segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
+                mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer);
+                expectExceptionOnRemoveBuffer(segmentHelper.sourceBuffer, DOMException.INVALID_STATE_ERR);
+
+                runNextTestCase();
+            }
+
+            function testRemoveBufferAfterEnded(runNextTestCase, videoTag)
+            {
+                consoleWrite("Test that a buffer can be removed while in the ended state.");
+                segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
+                mediaSource.endOfStream();
+                mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer);
+
+                runNextTestCase();
+            }
+
+            function testAddBufferAfterRemoving(runNextTestCase, videoTag)
+            {
+                consoleWrite("Test that a buffer can be added again after it is removed.");
+                segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
+                mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer);
+
+                try {
+                    segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
+                } catch (e) {
+                    consoleWrite("Unexpected exception: " + e);
+                }
+
+                runNextTestCase();
+            }
+
+            function testAppendFailureCases(runNextTestCase, videoTag)
+            {
+                var initSegment = segmentHelper.initSegment;
+                var mediaSegment = segmentHelper.mediaSegments[0];
+
+                segmentHelper.sourceBuffer = mediaSource.addSourceBuffer(defaultSourceMimetype);
+
+                consoleWrite("Test a successful append.");
+                segmentHelper.sourceBuffer.append(initSegment);
+
+                consoleWrite("Test append with a null buffer.");
+                expectExceptionOnAppend(null, DOMException.INVALID_ACCESS_ERR);
+
+                consoleWrite("Test append after ended.");
+                mediaSource.endOfStream();
+                expectExceptionOnAppend(initSegment, DOMException.INVALID_STATE_ERR);
+
+                consoleWrite("Test append after buffer has been removed.");
+                mediaSource.removeSourceBuffer(segmentHelper.sourceBuffer);
+                expectExceptionOnAppend(initSegment, DOMException.INVALID_STATE_ERR);
+
+                runNextTestCase();
+            }
+
+            function onLoad()
+            {
+                findMediaElement();
+
+                mediaSource = new MediaSource();
+                waitForEvent('webkitsourceopen', "", false, false, mediaSource);
+
+                segmentHelper.init(video, function(success)
+                {
+                    if (!success) {
+                        failTest("Failed to load segment data");
+                        return;
+                    }
+
+                    testAddBufferWhileClosed(video);
+
+                    var testCases = [
+                        testAddBufferFailureCases,
+                        testRemoveNullBuffer,
+                        testRemoveAgain,
+                        testRemoveBufferAfterEnded,
+                        testAddBufferAfterRemoving,
+                        testAppendFailureCases,
+                    ];
+
+                    MediaSourceTest.startSourceOpenTesting(video, testCases);
+                });
+            }
+        </script>
+    </head>
+    <body onload="onLoad()">
+        <video> </video>
+        <p>Tests webkitSourceAddId() &amp; webkitSourceRemoveId() methods</p>
+    </body>
+</html>
diff --git a/LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-ids.html b/LayoutTests/http/tests/media/media-source/video-media-source-add-and-remove-ids.html
deleted file mode 100644 (file)
index 82379f5..0000000
+++ /dev/null
@@ -1,221 +0,0 @@
-<!DOCTYPE html>
-<html>
-    <head>
-        <script src="/media-resources/video-test.js"></script>
-        <script src="/media/resources/media-source/webm/segment-info.js"></script>
-        <script src="media-source.js"></script>
-        <script>
-            var segmentHelper = new MediaSourceTest.SegmentHelper(WebMSegmentInfo.testWebM);
-            var defaultSourceMimetype = segmentHelper.segmentInfo.type;
-
-            function expectExceptionOnAddId(videoTag, id, type, error)
-            {
-                try {
-                    videoTag.webkitSourceAddId(id, type);
-                    failTest("Expected an exception");
-                } catch (e) {
-                    if (!(e.code == error)) {
-                        failTest("Unexpected exception " + e);
-                        throw e;
-                    }
-                    consoleWrite("Got expected exception " + e);
-                }
-            }
-
-            function expectExceptionOnRemoveId(videoTag, id, error)
-            {
-                try {
-                    videoTag.webkitSourceRemoveId(id);
-                    failTest("Expected an exception");
-                } catch (e) {
-                    if (!(e.code == error)) {
-                        failTest("Unexpected exception " + e);
-                        throw e;
-                    }
-                    consoleWrite("Got expected exception " + e);
-                }
-            }
-
-            function expectExceptionOnAppend(videoTag, id, buf, error)
-            {
-                try {
-                    videoTag.webkitSourceAppend(id, buf);
-                    failTest("Expected an exception");
-                } catch (e) {
-                    if (!(e.code == error)) {
-                        failTest("Unexpected exception " + e);
-                        throw e;
-                    }
-                    consoleWrite("Got expected exception " + e);
-                }
-            }
-
-            function testAddIdWhileClosed(videoTag)
-            {
-                consoleWrite("Test adding an ID while closed.");
-                expectExceptionOnAddId(videoTag, "123", defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
-            }
-
-            function testAddIdFailureCases(runNextTestCase, videoTag)
-            {
-                consoleWrite("Test empty ID case");
-                expectExceptionOnAddId(videoTag, "", defaultSourceMimetype, DOMException.INVALID_ACCESS_ERR);
-
-                videoTag.webkitSourceAddId("123", defaultSourceMimetype);
-
-                consoleWrite("Test adding the same ID again.");
-                expectExceptionOnAddId(videoTag, "123", defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
-                videoTag.webkitSourceRemoveId("123");
-
-                consoleWrite("Test empty type.");
-                expectExceptionOnAddId(videoTag, "234", "", DOMException.INVALID_ACCESS_ERR);
-
-                consoleWrite("Test an unsupported type.");
-                expectExceptionOnAddId(videoTag, "234", "audio/x-unsupported-format", DOMException.NOT_SUPPORTED_ERR);
-
-                consoleWrite("Test a supported type with an unsupported codec.");
-                expectExceptionOnAddId(videoTag, "234", "video/webm; codecs=\"vp8, speex\"", DOMException.NOT_SUPPORTED_ERR);
-
-                consoleWrite("Test reaching sourceID limit.");
-                var reachedIdLimit = false;
-
-                // The 20 here is an arbitrary upper limit to make sure the test terminates. This test
-                // assumes that implementations won't support more than 20 sourceID's simultaneously.
-                for (var i = 0; i < 20; ++i) {
-                    var sourceID = "sourceID-" + i;
-                    try {
-                        videoTag.webkitSourceAddId(sourceID, defaultSourceMimetype);
-                    } catch(e) {
-                        if (e.code != DOMException.QUOTA_EXCEEDED_ERR) {
-                            failTest("Unexpected exception " + e);
-                            throw e;
-                        }
-                        reachedIdLimit = true;
-                        break;
-                    }
-                }
-
-                if (!reachedIdLimit) {
-                    failTest("Failed to reach SourceID limit.");
-                    return;
-                }
-
-                consoleWrite("Test that SourceIDs can't be added while in the ended state.");
-                videoTag.webkitSourceEndOfStream(videoTag.EOS_NO_ERROR);
-                expectExceptionOnAddId(videoTag, "123", defaultSourceMimetype, DOMException.INVALID_STATE_ERR);
-
-                runNextTestCase();
-            }
-
-            function testRemoveEmptyId(runNextTestCase, videoTag)
-            {
-                consoleWrite("Test empty ID case");
-                expectExceptionOnRemoveId(videoTag, "", DOMException.INVALID_ACCESS_ERR);
-
-                runNextTestCase();
-            }
-
-            function testRemoveNonexistentId(runNextTestCase, videoTag)
-            {
-                consoleWrite("Test removing an ID that was never added.");
-                expectExceptionOnRemoveId(videoTag, "345", DOMException.SYNTAX_ERR);
-
-                runNextTestCase();
-            }
-
-            function testRemoveAgain(runNextTestCase, videoTag)
-            {
-                consoleWrite("Test removing an ID that was already removed.");
-                videoTag.webkitSourceAddId("123", defaultSourceMimetype);
-                videoTag.webkitSourceRemoveId("123");
-                expectExceptionOnRemoveId(videoTag, "123", DOMException.SYNTAX_ERR);
-
-                runNextTestCase();
-            }
-
-            function testRemoveIdAfterEnded(runNextTestCase, videoTag)
-            {
-                consoleWrite("Test that an ID can be removed while in the ended state.");
-                videoTag.webkitSourceAddId("123", defaultSourceMimetype);
-                videoTag.webkitSourceEndOfStream(videoTag.EOS_NO_ERROR);
-                videoTag.webkitSourceRemoveId("123");
-
-                runNextTestCase();
-            }
-
-            function testAddIdAfterRemoving(runNextTestCase, videoTag)
-            {
-                consoleWrite("Test that an ID can be added again after it is removed.");
-                videoTag.webkitSourceAddId("123", defaultSourceMimetype);
-                videoTag.webkitSourceRemoveId("123");
-
-                try {
-                    videoTag.webkitSourceAddId("123", defaultSourceMimetype);
-                } catch (e) {
-                    consoleWrite("Unexpected exception: " + e);
-                }
-
-                runNextTestCase();
-            }
-
-            function testAppendFailureCases(runNextTestCase, videoTag)
-            {
-                var initSegment = segmentHelper.initSegment;
-                var mediaSegment = segmentHelper.mediaSegments[0];
-
-                videoTag.webkitSourceAddId("123", defaultSourceMimetype);
-
-                consoleWrite("Test append with empty ID.");
-                expectExceptionOnAppend(videoTag, "", initSegment, DOMException.INVALID_ACCESS_ERR);
-
-                consoleWrite("Test append with an invalid ID");
-                expectExceptionOnAppend(videoTag, "234", initSegment, DOMException.SYNTAX_ERR);
-
-                consoleWrite("Test append with a null buffer.");
-                expectExceptionOnAppend(videoTag, "123", null, DOMException.INVALID_ACCESS_ERR);
-
-                consoleWrite("Test a successful append.");
-                videoTag.webkitSourceAppend("123", initSegment);
-
-                videoTag.webkitSourceRemoveId("123");
-                expectExceptionOnAppend(videoTag, "123", mediaSegment, DOMException.SYNTAX_ERR);
-
-                runNextTestCase();
-            }
-
-            function onLoad()
-            {
-                findMediaElement();
-
-                waitForEvent('loadstart');
-                waitForEvent('webkitsourceopen');
-
-                segmentHelper.init(video, function(success)
-                {
-                    if (!success) {
-                        failTest("Failed to load segment data");
-                        return;
-                    }
-
-                    testAddIdWhileClosed(video);
-
-                    var testCases = [
-                        testAddIdFailureCases,
-                        testRemoveEmptyId,
-                        testRemoveNonexistentId,
-                        testRemoveAgain,
-                        testRemoveIdAfterEnded,
-                        testAddIdAfterRemoving,
-                        testAppendFailureCases,
-                    ];
-
-                    MediaSourceTest.startSourceOpenTesting(video, testCases);
-                });
-            }
-        </script>
-    </head>
-    <body onload="onLoad()">
-        <video> </video>
-        <p>Tests webkitSourceAddId() &amp; webkitSourceRemoveId() methods</p>
-    </body>
-</html>
index 55f20bb..2e6b340 100644 (file)
@@ -2,41 +2,36 @@ Tests error cases with MediaSource API
 
 
 running didNotSendInitSegmentFirst
-EVENT(loadstart)
 EVENT(webkitsourceopen)
 Test appending a media segment before sending the initialization segment.
 EVENT(error) : MEDIA_ERR_SRC_NOT_SUPPORTED
 
 running immediateDecodeErrorViaEndOfStream
 EVENT(emptied)
-EVENT(loadstart)
 EVENT(webkitsourceopen)
-Test signalling a decode error with webkitSourceEndOfStream.
+Test signalling a decode error with MediaSource.endOfStream.
 EVENT(webkitsourceended)
 EVENT(error) : MEDIA_ERR_SRC_NOT_SUPPORTED
 
 running immediateNetworkErrorViaEndOfStream
 EVENT(emptied)
-EVENT(loadstart)
 EVENT(webkitsourceopen)
-Test signalling a network error with webkitSourceEndOfStream.
+Test signalling a network error with MediaSource.endOfStream.
 EVENT(webkitsourceended)
 EVENT(error) : MEDIA_ERR_SRC_NOT_SUPPORTED
 
 running decodeErrorAfterHaveMetadata
 EVENT(emptied)
-EVENT(loadstart)
 EVENT(webkitsourceopen)
-Test signalling a decode error with webkitSourceEndOfStream after we have appended enough data to get to the HAVE_METADATA state.
+Test signalling a decode error with MediaSource.endOfStream after we have appended enough data to get to the HAVE_METADATA state.
 EVENT(loadedmetadata)
 EVENT(webkitsourceended)
 EVENT(error) : MEDIA_ERR_DECODE
 
 running networkErrorAfterHaveMetadata
 EVENT(emptied)
-EVENT(loadstart)
 EVENT(webkitsourceopen)
-Test signalling a network error with webkitSourceEndOfStream after we have appended enough data to get to the HAVE_METADATA state.
+Test signalling a network error with MediaSource.endOfStream after we have appended enough data to get to the HAVE_METADATA state.
 EVENT(loadedmetadata)
 EVENT(webkitsourceended)
 EVENT(error) : MEDIA_ERR_NETWORK
index fe9ceaa..09aae57 100644 (file)
             function didNotSendInitSegmentFirst(runNextTestCase, videoTag)
             {
                 consoleWrite("Test appending a media segment before sending the initialization segment.");
-                segmentHelper.addSourceId();
+                segmentHelper.addSourceBuffer();
                 segmentHelper.appendMediaSegment(0);
             }
 
             function immediateDecodeErrorViaEndOfStream(runNextTestCase, videoTag)
             {
-                 consoleWrite("Test signalling a decode error with webkitSourceEndOfStream.");
-                 var videoTag = event.target;
-                 videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_DECODE_ERR);
+                 consoleWrite("Test signalling a decode error with MediaSource.endOfStream.");
+                 mediaSource = event.target;
+                 mediaSource.endOfStream("decode");
             }
 
             function immediateNetworkErrorViaEndOfStream(runNextTestCase, videoTag)
             {
-                consoleWrite("Test signalling a network error with webkitSourceEndOfStream.");
-                var videoTag = event.target;
-                videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_NETWORK_ERR);
+                consoleWrite("Test signalling a network error with MediaSource.endOfStream.");
+                mediaSource = event.target;
+                mediaSource.endOfStream("network");
             }
 
             function decodeErrorAfterHaveMetadata(runNextTestCase, videoTag)
             {
-                consoleWrite("Test signalling a decode error with webkitSourceEndOfStream after we have appended enough data to get to the HAVE_METADATA state.");
-                var videoTag = event.target;
-                segmentHelper.addSourceId();
+                consoleWrite("Test signalling a decode error with MediaSource.endOfStream after we have appended enough data to get to the HAVE_METADATA state.");
+                mediaSource = event.target;
+                segmentHelper.addSourceBuffer();
                 segmentHelper.appendInitSegment();
 
                 appendUntilMetadataLoaded(videoTag, function()
                 {
-                    videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_DECODE_ERR);
+                    mediaSource.endOfStream("decode");
                 });
             }
 
             function networkErrorAfterHaveMetadata(runNextTestCase, videoTag)
             {
-                consoleWrite("Test signalling a network error with webkitSourceEndOfStream after we have appended enough data to get to the HAVE_METADATA state.");
-                var videoTag = event.target;
-                segmentHelper.addSourceId();
+                consoleWrite("Test signalling a network error with MediaSource.endOfStream after we have appended enough data to get to the HAVE_METADATA state.");
+                mediaSource = event.target;
+                segmentHelper.addSourceBuffer();
                 segmentHelper.appendInitSegment();
                 appendUntilMetadataLoaded(videoTag, function()
                 {
-                    videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_NETWORK_ERR);
+                    mediaSource.endOfStream("network");
                 });
             }
 
             {
                 findMediaElement();
 
-                waitForEvent('loadstart');
                 waitForEvent('loadedmetadata');
-                waitForEvent('webkitsourceopen');
+                waitForEvent('webkitsourceopen', "", false, false, mediaSource);                          
                 waitForEvent('playing');
-                waitForEvent('webkitsourceended');
+                waitForEvent('webkitsourceended', "", false, false, mediaSource);
                 waitForEvent('ended');
                 waitForEvent('emptied');
 
index 1e7875c..e27fad9 100644 (file)
@@ -2,7 +2,7 @@ Test Media Source event handler attributes
 
 onLoad()
 onSourceOpen()
-Calling webkitSourceEndOfStream to trigger a webkitsourceended event.
+Calling MediaSource.endOfStream to trigger a webkitsourceended event.
 onSourceEnded()
 Setting src attribute to "" to trigger a webkitsourceclosed event.
 onSourceClose()
index ff2f7c8..52c0ac9 100644 (file)
@@ -3,22 +3,26 @@
    <head>
        <script src="/media-resources/video-test.js"></script>
        <script type="text/javascript">
-           function onSourceOpen(video)
+
+           var video = null;
+           var mediaSource = null;
+
+           function onSourceOpen()
            {
                consoleWrite("onSourceOpen()");
-
-               consoleWrite("Calling webkitSourceEndOfStream to trigger a webkitsourceended event.");
-               video.webkitSourceEndOfStream(HTMLMediaElement.EOS_NO_ERROR);
+               consoleWrite("Calling MediaSource.endOfStream to trigger a webkitsourceended event.");
+               mediaSource.endOfStream();
            }
 
-           function onSourceEnded(video)
+           function onSourceEnded()
            {
                consoleWrite("onSourceEnded()");
                consoleWrite("Setting src attribute to \"\" to trigger a webkitsourceclosed event.");
                video.src = "";
+               endTest();
            }
 
-           function onSourceClose(video)
+           function onSourceClose()
            {
                consoleWrite("onSourceClose()");
                endTest();
            function onLoad(e)
            {
                consoleWrite("onLoad()");
-               var video = document.getElementById('v');
-               video.src = video.webkitMediaSourceURL;
+               video = document.getElementById('v');
+               mediaSource = new MediaSource();
+               mediaSource.addEventListener('webkitsourceopen', onSourceOpen);
+               mediaSource.addEventListener('webkitsourceended', onSourceEnded);
+               mediaSource.addEventListener('webkitsourceclose', onSourceClose);
+               video.src = webkitURL.createObjectURL(mediaSource);
            }
        </script>
    </head>
    <body onload="onLoad()">
        <p>Test Media Source event handler attributes</p>
-       <video id='v' onwebkitsourceopen='onSourceOpen(this)' onwebkitsourceended='onSourceEnded(this);' onwebkitsourceclose='onSourceClose(this);'></video>
+       <video id='v'></video>
    </body>
 </html>
index 3ab8e45..d5679eb 100644 (file)
@@ -9,28 +9,29 @@
 
             function onSourceOpen(event)
             {
-                segmentHelper.addSourceId();
+                segmentHelper.addSourceBuffer();
                 segmentHelper.appendInitSegment();
 
                 // Append just enough segments to include at least 1 second of media data.
                 var endIndex = segmentHelper.getMediaSegmentIndexForTimestamp(1);
                 for (var i = 0; i <= endIndex; i++)
                     segmentHelper.appendMediaSegment(i);
-                event.target.webkitSourceEndOfStream(HTMLMediaElement.EOS_NO_ERROR);
+                event.target.endOfStream();
             }
 
             function onLoad()
             {
                 findMediaElement();
 
+                mediaSource = new MediaSource();
+
                 waitForEventAndFail('error');
-                waitForEvent('loadstart');
-                waitForEvent('webkitsourceopen');
+                waitForEvent('webkitsourceopen', "", false, false, mediaSource);
                 waitForEvent('playing');
-                waitForEvent('webkitsourceended');
+                waitForEvent('webkitsourceended', "", false, false, mediaSource);
                 waitForEventAndEnd('ended');
 
-                video.addEventListener('webkitsourceopen', onSourceOpen);
+                mediaSource.addEventListener('webkitsourceopen', onSourceOpen);
 
                 segmentHelper.init(video, function(success)
                 {
index a60ecba..cccd526 100644 (file)
@@ -16,7 +16,7 @@
                 if (firstOpen) {
                     firstOpen = false;
 
-                    segmentHelper.addSourceId();
+                    segmentHelper.addSourceBuffer();
                     segmentHelper.appendInitSegment();
                     segmentHelper.appendUntilEndOfStream(0);
                 }
@@ -38,7 +38,7 @@
                 var videoTag = event.target;
 
                 // Call abort to make sure the source buffer is in a state where it can accept new segments.
-                videoTag.webkitSourceAbort(segmentHelper.SourceID);
+                segmentHelper.sourceBuffer.abort();
 
                 var startIndex = segmentHelper.getMediaSegmentIndexForTimestamp(videoTag.currentTime);
                 segmentHelper.appendUntilEndOfStream(startIndex);
                 findMediaElement();
 
                 waitForEventAndFail('error');
-                waitForEvent('loadstart');
-                waitForEvent('webkitsourceopen');
-                waitForEvent('webkitsourceended');
+                waitForEvent('webkitsourceopen', "", false, false, mediaSource);
+                waitForEvent('webkitsourceended', "", false, false, mediaSource);
                 waitForEvent('playing');
                 waitForEvent('seeking');
                 waitForEventAndEnd('ended');
 
-                video.addEventListener('webkitsourceopen', onSourceOpen);
+                mediaSource.addEventListener('webkitsourceopen', onSourceOpen);
                 video.addEventListener('timeupdate', onTimeUpdate);
                 video.addEventListener('seeking', onSeeking);
                 video.addEventListener('seeked', onSeeked);
index a795d98..37905e2 100644 (file)
@@ -1,14 +1,13 @@
 Tests MediaSource API state transitions.
 
-webkitSourceState : SOURCE_CLOSED
-EVENT(loadstart)
-EVENT(webkitsourceopen) : SOURCE_OPEN
+webkitSourceState : closed
+EVENT(webkitsourceopen) : open
 onFirstSourceOpen
-EVENT(webkitsourceended) : SOURCE_ENDED
+EVENT(webkitsourceended) : ended
 onFirstSourceEnded
 EVENT(playing)
 triggerFirstSeek
-EVENT(webkitsourceopen) : SOURCE_OPEN
+EVENT(webkitsourceopen) : open
 EVENT(seeking)
 onFirstSeeking
 EVENT(seeked)
@@ -17,21 +16,19 @@ EVENT(seeking)
 onSecondSeeking
 EVENT(seeked)
 onSecondSeeked
-EVENT(webkitsourceclose) : SOURCE_CLOSED
+EVENT(webkitsourceclose) : closed
 onFirstSourceClose
 EVENT(emptied)
-EVENT(loadstart)
-EVENT(webkitsourceopen) : SOURCE_OPEN
+EVENT(webkitsourceopen) : open
 onSecondSourceOpen
-EVENT(webkitsourceended) : SOURCE_ENDED
+EVENT(webkitsourceended) : ended
 onSecondSourceEnded
 EVENT(playing)
 triggerSecondSourceClose
-EVENT(webkitsourceclose) : SOURCE_CLOSED
+EVENT(webkitsourceclose) : closed
 onSecondSourceClose
 EVENT(emptied)
-EVENT(loadstart)
-EVENT(webkitsourceopen) : SOURCE_OPEN
+EVENT(webkitsourceopen) : open
 onThirdSourceOpen
 END OF TEST
 
index 9a54dcd..f26cd52 100644 (file)
@@ -8,7 +8,7 @@
             var segmentHelper = new MediaSourceTest.SegmentHelper(WebMSegmentInfo.testWebM);
             var seekTime;
 
-            function appendMediaSegmentsForSeek(videoTag, segmentSeekTime)
+            function appendMediaSegmentsForSeek(segmentSeekTime)
             {
                 var index = segmentHelper.getMediaSegmentIndexForTimestamp(segmentSeekTime);
                 var endIndex = index + 2;
                 }
 
                 if (index >= totalMediaSegments) {
-                    videoTag.webkitSourceEndOfStream(HTMLMediaElement.EOS_NO_ERROR);
+                    mediaSource.endOfStream();
                     return;
                 }
             }
 
             function onSourceEvent(event)
             {
-                consoleWrite('EVENT(' + event.type + ') : ' + MediaSourceTest.getSourceStateName(event.target.webkitSourceState));
+                consoleWrite('EVENT(' + event.type + ') : ' + event.target.readyState);
             }
 
             function onFirstSourceOpen(event)
                 // This is the first time the source is opened. We just want to append
                 // the initialization segment and all media segments until the end of stream.
                 // This is testing the
-                // SOURCE_CLOSED -> SOURCE_OPEN -> SOURCE_ENDED transition path.
+                // "closed" -> "open" -> "ended" transition path.
 
-                var videoTag = event.target;
-                videoTag.removeEventListener('webkitsourceopen', onFirstSourceOpen);
-                segmentHelper.addSourceId();
+                var mediaSource = event.target;
+                mediaSource.removeEventListener('webkitsourceopen', onFirstSourceOpen);
+                segmentHelper.addSourceBuffer();
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
+                MediaSourceTest.expectSourceState(mediaSource, "open");
 
                 segmentHelper.appendInitSegment();
 
-                videoTag.addEventListener('webkitsourceended', onFirstSourceEnded);
+                mediaSource.addEventListener('webkitsourceended', onFirstSourceEnded);
 
                 // Start appending media segments.
                 segmentHelper.appendUntilEndOfStream(0);
             function onFirstSourceEnded(event)
             {
                 consoleWrite("onFirstSourceEnded");
-                var videoTag = event.target;
-                videoTag.removeEventListener('webkitsourceended', onFirstSourceEnded);
 
-                MediaSourceTest.expectSourceState(videoTag, videoTag.SOURCE_ENDED);
+                var mediaSource = event.target;
+                mediaSource.removeEventListener('webkitsourceended', onFirstSourceEnded);
+
+                MediaSourceTest.expectSourceState(mediaSource, "ended");
 
-                videoTag.addEventListener('playing', triggerFirstSeek);
+                video.addEventListener('playing', triggerFirstSeek);
             }
 
             function triggerFirstSeek(event)
@@ -71,7 +72,7 @@
                 videoTag.removeEventListener('playing', triggerFirstSeek);
 
                 // Now that we have appended all of the media segments and ended the stream,
-                // lets do a seek to test the SOURCE_ENDED -> SOURCE_OPEN transition.
+                // lets do a seek to test the "ended" -> "open" transition.
                 videoTag.addEventListener('seeking', onFirstSeeking);
                 videoTag.addEventListener('seeked', onFirstSeeked);
                 videoTag.currentTime = seekTime;
                 var videoTag = event.target;
                 videoTag.removeEventListener('seeking', onFirstSeeking);
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
+                MediaSourceTest.expectSourceState(mediaSource, "open");
 
                 // Start appending media segments.
-                appendMediaSegmentsForSeek(videoTag, videoTag.currentTime);
+                appendMediaSegmentsForSeek(videoTag.currentTime);
             }
 
             function onFirstSeeked(event)
@@ -97,9 +98,9 @@
                 var videoTag = event.target;
                 videoTag.removeEventListener('seeked', onFirstSeeked);
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
+                MediaSourceTest.expectSourceState(mediaSource, "open");
 
-                // Now it is time to test seeking while still in SOURCE_OPEN.
+                // Now it is time to test seeking while still in "open".
                 videoTag.addEventListener('seeking', onSecondSeeking);
                 videoTag.addEventListener('seeked', onSecondSeeked);
                 videoTag.currentTime = seekTime;
                 var videoTag = event.target;
                 videoTag.removeEventListener('seeking', onSecondSeeking);
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
+                MediaSourceTest.expectSourceState(mediaSource, "open");
 
                 // Start appending media segments.
-                appendMediaSegmentsForSeek(videoTag, videoTag.currentTime);
+                appendMediaSegmentsForSeek(videoTag.currentTime);
             }
 
             function onSecondSeeked(event)
             {
                 consoleWrite("onSecondSeeked");
+
                 var videoTag = event.target;
                 videoTag.removeEventListener('seeked', onSecondSeeked);
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
+                MediaSourceTest.expectSourceState(mediaSource, "open");
 
-                // Test SOURCE_OPEN -> SOURCE_CLOSED -> SOURCE_OPEN transition path.
-                videoTag.addEventListener('webkitsourceclose', onFirstSourceClose);
+                // Test "open" -> "closed" -> "open" transition path.
+                mediaSource.addEventListener('webkitsourceclose', onFirstSourceClose);
                 MediaSourceTest.setSrcToMediaSourceTestURL(videoTag);
             }
 
             {
                 consoleWrite("onFirstSourceClose");
 
-                var videoTag = event.target;
-                videoTag.removeEventListener('webkitsourceclose', onFirstSourceClose);
+                var mediaSource = event.target;
+                mediaSource.removeEventListener('webkitsourceclose', onFirstSourceClose);
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_CLOSED);
+                MediaSourceTest.expectSourceState(mediaSource, "closed");
 
-                videoTag.addEventListener('webkitsourceopen', onSecondSourceOpen);
+                mediaSource.addEventListener('webkitsourceopen', onSecondSourceOpen);
             }
 
             function onSecondSourceOpen(event)
             {
                 consoleWrite("onSecondSourceOpen");
 
-                var videoTag = event.target;
-                videoTag.removeEventListener('webkitsourceopen', onSecondSourceOpen);
-                segmentHelper.addSourceId();
+                var mediaSource = event.target;
+                mediaSource.removeEventListener('webkitsourceopen', onSecondSourceOpen);
+                segmentHelper.addSourceBuffer();
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
+                MediaSourceTest.expectSourceState(mediaSource, "open");
 
                 segmentHelper.appendInitSegment();
 
-                videoTag.addEventListener('webkitsourceended', onSecondSourceEnded);
+                mediaSource.addEventListener('webkitsourceended', onSecondSourceEnded);
 
                 // Start appending media segments.
                 segmentHelper.appendUntilEndOfStream(0);
             {
                 consoleWrite("onSecondSourceEnded");
 
-                var videoTag = event.target;
-                videoTag.removeEventListener('webkitsourceended', onSecondSourceEnded);
+                var mediaSource = event.target;
+                mediaSource.removeEventListener('webkitsourceended', onSecondSourceEnded);
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_ENDED);
+                MediaSourceTest.expectSourceState(mediaSource, "ended");
                 //MediaSourceTest.expectReadyState(videoTag, HTMLMediaElement.HAVE_NOTHING);
 
-                videoTag.addEventListener('playing', triggerSecondSourceClose);
+                video.addEventListener('playing', triggerSecondSourceClose);
             }
 
             function triggerSecondSourceClose(event)
                 var videoTag = event.target;
                 videoTag.removeEventListener('playing', triggerSecondSourceClose);
 
-                // Test SOURCE_ENDED -> SOURCE_CLOSED -> SOURCE_OPEN transition path.
-                videoTag.addEventListener('webkitsourceclose', onSecondSourceClose);
+                // Test "ended" -> "closed" -> "open" transition path.
+                mediaSource.addEventListener('webkitsourceclose', onSecondSourceClose);
                 MediaSourceTest.setSrcToMediaSourceTestURL(videoTag);
             }
 
             {
                 consoleWrite("onSecondSourceClose");
 
-                var videoTag = event.target;
-                videoTag.removeEventListener('webkitsourceclose', onSecondSourceClose);
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_CLOSED);
+                var mediaSource = event.target;
+                mediaSource.removeEventListener('webkitsourceclose', onSecondSourceClose);
+                MediaSourceTest.expectSourceState(mediaSource, "closed");
 
-                videoTag.addEventListener('webkitsourceopen', onThirdSourceOpen);
+                mediaSource.addEventListener('webkitsourceopen', onThirdSourceOpen);
             }
 
             function onThirdSourceOpen(event)
             {
                 consoleWrite("onThirdSourceOpen");
 
-                var videoTag = event.target;
-                videoTag.removeEventListener('webkitsourceopen', onThirdSourceOpen);
-                segmentHelper.addSourceId();
+                var mediaSource = event.target;
+                mediaSource.removeEventListener('webkitsourceopen', onThirdSourceOpen);
+                segmentHelper.addSourceBuffer();
 
-                MediaSourceTest.expectSourceState(videoTag, HTMLMediaElement.SOURCE_OPEN);
+                MediaSourceTest.expectSourceState(mediaSource, "open");
 
                 endTest();
             }
             {
                 findMediaElement();
 
+                mediaSource = new MediaSource();
+
                 waitForEventAndFail('error');
-                waitForEvent('loadstart');
                 waitForEvent('playing');
                 waitForEvent('seeking');
                 waitForEvent('seeked');
                 waitForEvent('ended');
                 waitForEvent('emptied');
 
-                video.addEventListener('webkitsourceopen', onSourceEvent);
-                video.addEventListener('webkitsourceended', onSourceEvent);
-                video.addEventListener('webkitsourceclose', onSourceEvent);
+                mediaSource.addEventListener('webkitsourceopen', onSourceEvent);
+                mediaSource.addEventListener('webkitsourceended', onSourceEvent);
+                mediaSource.addEventListener('webkitsourceclose', onSourceEvent);
 
-                video.addEventListener('webkitsourceopen', onFirstSourceOpen);
+                mediaSource.addEventListener('webkitsourceopen', onFirstSourceOpen);
 
-                MediaSourceTest.logSourceState(video);
+                MediaSourceTest.logSourceState(mediaSource);
                 segmentHelper.init(video, function(success)
                 {
                     if (!success) {
index 44e130f..150b49a 100644 (file)
@@ -1,3 +1,40 @@
+2012-08-06  Anna Cavender  <annacc@chromium.org>
+
+        Update HTMLMediaElement to the new OO MediaSource API.
+        https://bugs.webkit.org/show_bug.cgi?id=91775
+
+        Reviewed by Eric Carlson.
+
+        This patch rips out the old-style MediaSource API and allows a
+        MediaSource object to be attached to HTMLMediaElement.
+        http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html
+
+        Test: http/tests/media/media-source/video-media-source-add-and-remove-buffers.html
+
+        Tests: updates to http/tests/media/media-source/*
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore):
+        (WebCore::HTMLMediaElement::HTMLMediaElement): Remove old style API resources.
+        (WebCore::HTMLMediaElement::parseAttribute): Remove old style event attributes.
+        (WebCore::HTMLMediaElement::prepareForLoad): Set source state to "closed".
+        (WebCore::HTMLMediaElement::loadResource): Get MediaSource object from blob registry
+            look up and, if found, set it's MediaPlayer pointer to the current MediaPlayer.
+        (WebCore::HTMLMediaElement::noneSupported): Set source state to "closed".
+        (WebCore::HTMLMediaElement::mediaEngineError): Set source state to "closed".
+        (WebCore::HTMLMediaElement::mediaPlayerSourceOpened): Set source state to "open".
+        (WebCore::HTMLMediaElement::mediaPlayerSourceURL): Change to new blob URL.
+        (WebCore::HTMLMediaElement::seek): Check if source state is "closed".
+        (WebCore::HTMLMediaElement::setSourceState): Helper function so that we don't have to
+            keep checking for m_mediaSource.
+        (WebCore::HTMLMediaElement::userCancelledLoad): Set source state to "closed".
+        (WebCore::HTMLMediaElement::createMediaPlayer): If the current MediaPlayer is re-
+            created, notify the MediaSource and reset its MediaPlayer.
+
+        * html/HTMLMediaElement.h: Remove old style API code and add a MediaSource object.
+        (HTMLMediaElement):
+        * html/HTMLMediaElement.idl: Remove old style API.
+
 2012-08-06  Adam Barth  <abarth@webkit.org>
 
         BindingSecurity::shouldAllowAccessToFrame shouldn't use a raw boolean parameter
index a648e69..7483555 100644 (file)
 #include "DisplaySleepDisabler.h"
 #endif
 
+#if ENABLE(MEDIA_SOURCE)
+#include "MediaSource.h"
+#include "MediaSourceRegistry.h"
+#endif
+
 using namespace std;
 
 namespace WebCore {
@@ -145,7 +150,7 @@ static const char* boolString(bool val)
 
 #if ENABLE(MEDIA_SOURCE)
 // URL protocol used to signal that the media source API is being used.
-static const char* mediaSourceURLProtocol = "x-media-source";
+static const char* mediaSourceBlobProtocol = "blob";
 #endif
 
 using namespace HTMLNames;
@@ -219,9 +224,6 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
     , m_preload(MediaPlayer::Auto)
     , m_displayMode(Unknown)
     , m_processingMediaPlayerCallback(0)
-#if ENABLE(MEDIA_SOURCE)      
-    , m_sourceState(SOURCE_CLOSED)
-#endif
     , m_cachedTime(MediaPlayer::invalidTime())
     , m_cachedTimeWallClockUpdateTime(0)
     , m_minimumWallClockTimeToCacheMediaTime(0)
@@ -272,7 +274,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
     }
 
 #if ENABLE(MEDIA_SOURCE)
-    m_mediaSourceURL.setProtocol(mediaSourceURLProtocol);
+    m_mediaSourceURL.setProtocol(mediaSourceBlobProtocol);
     m_mediaSourceURL.setPath(createCanonicalUUIDString());
 #endif
 
@@ -421,14 +423,6 @@ void HTMLMediaElement::parseAttribute(const Attribute& attribute)
         setAttributeEventListener(eventNames().webkitbeginfullscreenEvent, createAttributeEventListener(this, attribute));
     else if (attribute.name() == onwebkitendfullscreenAttr)
         setAttributeEventListener(eventNames().webkitendfullscreenEvent, createAttributeEventListener(this, attribute));
-#if ENABLE(MEDIA_SOURCE)
-    else if (attribute.name() == onwebkitsourcecloseAttr)
-        setAttributeEventListener(eventNames().webkitsourcecloseEvent, createAttributeEventListener(this, attribute));
-    else if (attribute.name() == onwebkitsourceendedAttr)
-        setAttributeEventListener(eventNames().webkitsourceendedEvent, createAttributeEventListener(this, attribute));
-    else if (attribute.name() == onwebkitsourceopenAttr)
-        setAttributeEventListener(eventNames().webkitsourceopenEvent, createAttributeEventListener(this, attribute));
-#endif
     else
         HTMLElement::parseAttribute(attribute);
 }
@@ -693,6 +687,10 @@ void HTMLMediaElement::prepareForLoad()
     if (m_networkState == NETWORK_LOADING || m_networkState == NETWORK_IDLE)
         scheduleEvent(eventNames().abortEvent);
 
+#if ENABLE(MEDIA_SOURCE)
+    setSourceState(MediaSource::closedKeyword());
+#endif
+
 #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO)
     createMediaPlayer();
 #else
@@ -702,11 +700,6 @@ void HTMLMediaElement::prepareForLoad()
         createMediaPlayerProxy();
 #endif
 
-#if ENABLE(MEDIA_SOURCE)
-    if (m_sourceState != SOURCE_CLOSED)
-        setSourceState(SOURCE_CLOSED);
-#endif
-
     // 4 - If the media element's networkState is not set to NETWORK_EMPTY, then run these substeps
     if (m_networkState != NETWORK_EMPTY) {
         m_networkState = NETWORK_EMPTY;
@@ -927,10 +920,16 @@ void HTMLMediaElement::loadResource(const KURL& initialURL, ContentType& content
     }
     
 #if ENABLE(MEDIA_SOURCE)
-    // If this is a media source URL, make sure it is the one for this media element.
-    if (url.protocolIs(mediaSourceURLProtocol) && url != m_mediaSourceURL) {
-        mediaLoadingFailed(MediaPlayer::FormatError);
-        return;
+    if (url.protocolIs(mediaSourceBlobProtocol)) {
+        if (m_mediaSource)
+            m_mediaSource->setReadyState(MediaSource::closedKeyword());
+
+        m_mediaSource = adoptRef(MediaSourceRegistry::registry().lookupMediaSource(url.string()));
+
+        if (m_mediaSource) {
+            m_mediaSource->setMediaPlayer(m_player.get());
+            m_mediaSourceURL = url;
+        }
     }
 #endif
 
@@ -1432,8 +1431,7 @@ void HTMLMediaElement::noneSupported()
     scheduleEvent(eventNames().errorEvent);
 
 #if ENABLE(MEDIA_SOURCE)
-    if (m_sourceState != SOURCE_CLOSED)
-        setSourceState(SOURCE_CLOSED);
+    setSourceState(MediaSource::closedKeyword());
 #endif
 
     // 8 - Set the element's delaying-the-load-event flag to false. This stops delaying the load event.
@@ -1464,8 +1462,7 @@ void HTMLMediaElement::mediaEngineError(PassRefPtr<MediaError> err)
     scheduleEvent(eventNames().errorEvent);
 
 #if ENABLE(MEDIA_SOURCE)
-    if (m_sourceState != SOURCE_CLOSED)
-        setSourceState(SOURCE_CLOSED);
+    setSourceState(MediaSource::closedKeyword());
 #endif
 
     // 4 - Set the element's networkState attribute to the NETWORK_EMPTY value and queue a
@@ -1750,7 +1747,7 @@ void HTMLMediaElement::mediaPlayerSourceOpened()
 {
     beginProcessingMediaPlayerCallback();
 
-    setSourceState(SOURCE_OPEN);
+    setSourceState(MediaSource::openKeyword());
 
     endProcessingMediaPlayerCallback();
 }
@@ -1759,22 +1756,6 @@ String HTMLMediaElement::mediaPlayerSourceURL() const
 {
     return m_mediaSourceURL.string();
 }
-
-bool HTMLMediaElement::isValidSourceId(const String& id, ExceptionCode& ec) const
-{
-    if (id.isNull() || id.isEmpty()) {
-        ec = INVALID_ACCESS_ERR;
-        return false;
-    }
-
-    if (!m_sourceIDs.contains(id)) {
-        ec = SYNTAX_ERR;
-        return false;
-    }
-
-    return true;
-}
-
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
@@ -1998,8 +1979,8 @@ void HTMLMediaElement::seek(float time, ExceptionCode& ec)
 #if ENABLE(MEDIA_SOURCE)
     // Always notify the media engine of a seek if the source is not closed. This ensures that the source is
     // always in a flushed state when the 'seeking' event fires.
-    if (m_sourceState != SOURCE_CLOSED)
-      noSeekRequired = false;
+    if (m_mediaSource && m_mediaSource->readyState() != MediaSource::closedKeyword())
+        noSeekRequired = false;
 #endif
 
     if (noSeekRequired) {
@@ -2021,8 +2002,8 @@ void HTMLMediaElement::seek(float time, ExceptionCode& ec)
     m_sentEndEvent = false;
 
 #if ENABLE(MEDIA_SOURCE)
-    if (m_sourceState == SOURCE_ENDED)
-        setSourceState(SOURCE_OPEN);
+    if (m_mediaSource && m_mediaSource->readyState() == MediaSource::endedKeyword())
+        setSourceState(MediaSource::openKeyword());
 #endif
 
     // 8 - Set the current playback position to the given new playback position
@@ -2370,175 +2351,12 @@ void HTMLMediaElement::pauseInternal()
 }
 
 #if ENABLE(MEDIA_SOURCE)
-
-void HTMLMediaElement::webkitSourceAddId(const String& id, const String& type, ExceptionCode& ec)
+void HTMLMediaElement::setSourceState(const String& state)
 {
-    if (id.isNull() || id.isEmpty()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
+    if (!m_mediaSource)
+         return;
 
-    if (m_sourceIDs.contains(id)) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
-
-    if (type.isNull() || type.isEmpty()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
-
-    if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState != SOURCE_OPEN) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
-
-    ContentType contentType(type);
-    Vector<String> codecs = contentType.codecs();
-
-    if (!codecs.size()) {
-        ec = NOT_SUPPORTED_ERR;
-        return;
-    }
-
-    switch (m_player->sourceAddId(id, contentType.type(), codecs)) {
-    case MediaPlayer::Ok:
-        m_sourceIDs.add(id);
-        return;
-    case MediaPlayer::NotSupported:
-        ec = NOT_SUPPORTED_ERR;
-        return;
-    case MediaPlayer::ReachedIdLimit:
-        ec = QUOTA_EXCEEDED_ERR;
-        return;
-    }
-
-    ASSERT_NOT_REACHED();
-}
-
-void HTMLMediaElement::webkitSourceRemoveId(const String& id, ExceptionCode& ec)
-{
-    if (!isValidSourceId(id, ec))
-        return;
-
-    if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState == SOURCE_CLOSED) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
-
-    if (!m_player->sourceRemoveId(id))
-        ASSERT_NOT_REACHED();
-
-    m_sourceIDs.remove(id);
-}
-
-PassRefPtr<TimeRanges> HTMLMediaElement::webkitSourceBuffered(const String& id, ExceptionCode& ec)
-{
-    if (!isValidSourceId(id, ec))
-        return 0;
-
-    if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState == SOURCE_CLOSED) {
-        ec = INVALID_STATE_ERR;
-        return 0;
-    }
-
-    return m_player->sourceBuffered(id);
-}
-
-void HTMLMediaElement::webkitSourceAppend(const String& id, PassRefPtr<Uint8Array> data, ExceptionCode& ec)
-{
-    if (!isValidSourceId(id, ec))
-        return;
-
-    if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState != SOURCE_OPEN) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
-
-    if (!data.get()) {
-        ec = INVALID_ACCESS_ERR;
-        return;
-    }
-
-    if (!data->length())
-        return;
-
-    if (!m_player->sourceAppend(id, data->data(), data->length())) {
-        ec = SYNTAX_ERR;
-        return;
-    }
-}
-
-void HTMLMediaElement::webkitSourceAbort(const String& id, ExceptionCode& ec)
-{
-    if (!isValidSourceId(id, ec))
-        return;
-
-    if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState != SOURCE_OPEN) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
-
-    if (!m_player->sourceAbort(id))
-        ASSERT_NOT_REACHED();
-}
-
-void HTMLMediaElement::webkitSourceEndOfStream(unsigned short status, ExceptionCode& ec)
-{
-    if (!m_player || m_currentSrc != m_mediaSourceURL || m_sourceState != SOURCE_OPEN) {
-        ec = INVALID_STATE_ERR;
-        return;
-    }
-
-    MediaPlayer::EndOfStreamStatus eosStatus = MediaPlayer::EosNoError;
-
-    switch (status) {
-    case EOS_NO_ERROR:
-        eosStatus = MediaPlayer::EosNoError;
-        break;
-    case EOS_NETWORK_ERR:
-        eosStatus = MediaPlayer::EosNetworkError;
-        break;
-    case EOS_DECODE_ERR:
-        eosStatus = MediaPlayer::EosDecodeError;
-        break;
-    default:
-        ec = SYNTAX_ERR;
-        return;
-    }
-
-    setSourceState(SOURCE_ENDED);
-    m_player->sourceEndOfStream(eosStatus);
-}
-
-HTMLMediaElement::SourceState HTMLMediaElement::webkitSourceState() const
-{
-    return m_sourceState;
-}
-
-void HTMLMediaElement::setSourceState(SourceState state)
-{
-    SourceState oldState = m_sourceState;
-    m_sourceState = static_cast<SourceState>(state);
-
-    if (m_sourceState == oldState)
-        return;
-
-    if (m_sourceState == SOURCE_CLOSED) {
-        m_sourceIDs.clear();
-        scheduleEvent(eventNames().webkitsourcecloseEvent);
-        return;
-    }
-
-    if (oldState == SOURCE_OPEN && m_sourceState == SOURCE_ENDED) {
-        scheduleEvent(eventNames().webkitsourceendedEvent);
-        return;
-    }
-
-    if (m_sourceState == SOURCE_OPEN) {
-        scheduleEvent(eventNames().webkitsourceopenEvent);
-        return;
-    }
+    m_mediaSource->setReadyState(state);
 }
 #endif
 
@@ -3793,8 +3611,7 @@ void HTMLMediaElement::userCancelledLoad()
     scheduleEvent(eventNames().abortEvent);
 
 #if ENABLE(MEDIA_SOURCE)
-    if (m_sourceState != SOURCE_CLOSED)
-        setSourceState(SOURCE_CLOSED);
+    setSourceState(MediaSource::closedKeyword());
 #endif
 
     // 4 - If the media element's readyState attribute has a value equal to HAVE_NOTHING, set the 
@@ -4307,6 +4124,11 @@ void HTMLMediaElement::createMediaPlayer()
         
     m_player = MediaPlayer::create(this);
 
+#if ENABLE(MEDIA_SOURCE)
+    if (m_mediaSource)
+        m_mediaSource->setMediaPlayer(m_player.get());
+#endif
+
 #if ENABLE(WEB_AUDIO)
     if (m_audioSourceNode) {
         // When creating the player, make sure its AudioSourceProvider knows about the MediaElementAudioSourceNode.
index fe71f13..bdc6149 100644 (file)
@@ -175,20 +175,7 @@ public:
 #if ENABLE(MEDIA_SOURCE)
 //  Media Source.
     const KURL& webkitMediaSourceURL() const { return m_mediaSourceURL; }
-    void webkitSourceAddId(const String&, const String&, ExceptionCode&);
-    void webkitSourceRemoveId(const String&, ExceptionCode&);
-    PassRefPtr<TimeRanges> webkitSourceBuffered(const String&, ExceptionCode&);
-    void webkitSourceAppend(const String&, PassRefPtr<Uint8Array> data, ExceptionCode&);
-    void webkitSourceAbort(const String&, ExceptionCode&);
-    enum EndOfStreamStatus { EOS_NO_ERROR, EOS_NETWORK_ERR, EOS_DECODE_ERR };
-    void webkitSourceEndOfStream(unsigned short, ExceptionCode&);
-    enum SourceState { SOURCE_CLOSED, SOURCE_OPEN, SOURCE_ENDED };
-    SourceState webkitSourceState() const;
-    void setSourceState(SourceState);
-
-    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceopen);
-    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceended);
-    DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitsourceclose);
+    void setSourceState(const String&);
 #endif 
 
 #if ENABLE(ENCRYPTED_MEDIA)
@@ -420,7 +407,6 @@ private:
 #if ENABLE(MEDIA_SOURCE)
     virtual void mediaPlayerSourceOpened();
     virtual String mediaPlayerSourceURL() const;
-    bool isValidSourceId(const String&, ExceptionCode&) const;
 #endif
 
 #if ENABLE(ENCRYPTED_MEDIA)
@@ -598,8 +584,7 @@ private:
 
 #if ENABLE(MEDIA_SOURCE)
     KURL m_mediaSourceURL;
-    SourceState m_sourceState;
-    HashSet<String> m_sourceIDs;
+    RefPtr<MediaSource> m_mediaSource;
 #endif
 
     mutable float m_cachedTime;
index ac0fa46..9d0ae8a 100644 (file)
@@ -98,35 +98,6 @@ module html {
 #if defined(ENABLE_MEDIA_SOURCE) && ENABLE_MEDIA_SOURCE
     // URL passed to src attribute to enable the media source logic.
     readonly attribute [V8EnabledAtRuntime=mediaSource, URL] DOMString webkitMediaSourceURL;
-
-    // Manages IDs for appending media to the source.
-    [V8EnabledAtRuntime=mediaSource] void webkitSourceAddId(in DOMString id, in DOMString type) raises (DOMException);
-    [V8EnabledAtRuntime=mediaSource] void webkitSourceRemoveId(in DOMString id) raises (DOMException);
-
-    // Returns the time ranges buffered for a specific source ID.
-    [V8EnabledAtRuntime=mediaSource] TimeRanges webkitSourceBuffered(in DOMString id) raises (DOMException);
-    
-    // Appends segment data.
-    [V8EnabledAtRuntime=mediaSource] void webkitSourceAppend(in DOMString id, in Uint8Array data) raises (DOMException);
-
-    // Aborts the current segment.
-    [V8EnabledAtRuntime=mediaSource] void webkitSourceAbort(in DOMString id) raises (DOMException);
-
-    // Signals the end of stream.
-    [V8EnabledAtRuntime=mediaSource] const unsigned short EOS_NO_ERROR = 0; // End of stream reached w/o error.
-    [V8EnabledAtRuntime=mediaSource] const unsigned short EOS_NETWORK_ERR = 1; // A network error triggered end of stream.
-    [V8EnabledAtRuntime=mediaSource] const unsigned short EOS_DECODE_ERR = 2; // A decode error triggered end of stream.
-    [V8EnabledAtRuntime=mediaSource] void webkitSourceEndOfStream(in unsigned short status) raises (DOMException);
-
-    // Indicates the current state of the media source.
-    [V8EnabledAtRuntime=mediaSource] const unsigned short SOURCE_CLOSED = 0;
-    [V8EnabledAtRuntime=mediaSource] const unsigned short SOURCE_OPEN = 1;
-    [V8EnabledAtRuntime=mediaSource] const unsigned short SOURCE_ENDED = 2;
-    readonly attribute [V8EnabledAtRuntime=mediaSource] unsigned short webkitSourceState;
-
-    attribute [V8EnabledAtRuntime=mediaSource] EventListener onwebkitsourceopen;
-    attribute [V8EnabledAtRuntime=mediaSource] EventListener onwebkitsourceended;
-    attribute [V8EnabledAtRuntime=mediaSource] EventListener onwebkitsourceclose;
 #endif
 
 #if defined(ENABLE_ENCRYPTED_MEDIA) && ENABLE_ENCRYPTED_MEDIA