Create a MediaSource object.
authorannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Aug 2012 00:46:26 +0000 (00:46 +0000)
committerannacc@chromium.org <annacc@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 8 Aug 2012 00:46:26 +0000 (00:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=91773

Reviewed by Eric Carlson.

MediaSource object is needed in order to implement the new
object-oriented MediaSource API:
http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html

No new tests - will be able to test after landing:
https://bugs.webkit.org/show_bug.cgi?id=91775

Adding new files to build files:
* CMakeLists.txt:
* DerivedSources.cpp:
* DerivedSources.make:
* DerivedSources.pri:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:

New MediaSource object:
* Modules/mediasource/MediaSource.cpp: Added.
* Modules/mediasource/MediaSource.h: Added.
* Modules/mediasource/MediaSource.idl: Added.

Create a registry for the blob storage and lookup:
* Modules/mediasource/MediaSourceRegistry.cpp: Added.
* Modules/mediasource/MediaSourceRegistry.h: Added.

Connect SourceBuffer to MediaSource:
* Modules/mediasource/SourceBuffer.cpp:
(WebCore::SourceBuffer::SourceBuffer):
(WebCore::SourceBuffer::buffered): Forward call to MediaSource.
(WebCore::SourceBuffer::append): Ditto.
(WebCore::SourceBuffer::abort): Ditto.
* Modules/mediasource/SourceBuffer.h:
(WebCore::SourceBuffer::create): Add a MediaSource to the constructor.
(WebCore::SourceBuffer::clear): Clear the MediaSource.
(SourceBuffer):
* Modules/mediasource/SourceBufferList.cpp: include SourceBuffer.h
* Modules/mediasource/SourceBufferList.h:

Make MediaSource an EventTarget:
* dom/EventTarget.h:
(WebCore):
* dom/EventTargetFactory.in:

Enable creation of MediaSource object URL from JavaScript:
* html/DOMURL.cpp:
(WebCore):
(WebCore::DOMURL::createObjectURL):
(WebCore::DOMURL::revokeObjectURL):
* html/DOMURL.h:
(WebCore):
(DOMURL):
* html/DOMURL.idl:
* html/PublicURLManager.h: create a new sourceURLs list for storing
    reigstered MediaSource URLS.
(WebCore::PublicURLManager::contextDestroyed): make sure everything is
    removed from the sourceURLs list upon destruction.
(PublicURLManager):
(WebCore::PublicURLManager::sourceURLs): getter for the sourceURLs list.

New MediaSource constructor:
* page/DOMWindow.idl:

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

27 files changed:
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.cpp
Source/WebCore/DerivedSources.make
Source/WebCore/DerivedSources.pri
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/mediasource/MediaSource.cpp [new file with mode: 0644]
Source/WebCore/Modules/mediasource/MediaSource.h [new file with mode: 0644]
Source/WebCore/Modules/mediasource/MediaSource.idl [new file with mode: 0644]
Source/WebCore/Modules/mediasource/MediaSourceRegistry.cpp [new file with mode: 0644]
Source/WebCore/Modules/mediasource/MediaSourceRegistry.h [new file with mode: 0644]
Source/WebCore/Modules/mediasource/SourceBuffer.cpp
Source/WebCore/Modules/mediasource/SourceBuffer.h
Source/WebCore/Modules/mediasource/SourceBufferList.cpp
Source/WebCore/Modules/mediasource/SourceBufferList.h
Source/WebCore/Modules/mediastream/MediaStreamRegistry.cpp
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/dom/EventTarget.h
Source/WebCore/dom/EventTargetFactory.in
Source/WebCore/html/DOMURL.cpp
Source/WebCore/html/DOMURL.h
Source/WebCore/html/DOMURL.idl
Source/WebCore/html/PublicURLManager.h
Source/WebCore/page/DOMWindow.idl

index c28e903..9aca4dc 100644 (file)
@@ -194,6 +194,7 @@ SET(WebCore_IDL_FILES
     Modules/intents/IntentResultCallback.idl
     Modules/intents/NavigatorIntents.idl
 
+    Modules/mediasource/MediaSource.idl
     Modules/mediasource/SourceBuffer.idl
     Modules/mediasource/SourceBufferList.idl
 
@@ -824,6 +825,7 @@ SET(WebCore_SOURCES
     Modules/intents/IntentRequest.cpp
     Modules/intents/NavigatorIntents.cpp
 
+    Modules/mediasource/MediaSource.cpp
     Modules/mediasource/SourceBuffer.cpp
     Modules/mediasource/SourceBufferList.cpp
 
index 62a4549..82b6e2e 100644 (file)
@@ -1,3 +1,74 @@
+2012-08-07  Anna Cavender  <annacc@chromium.org>
+
+        Create a MediaSource object.
+        https://bugs.webkit.org/show_bug.cgi?id=91773
+
+        Reviewed by Eric Carlson.
+
+        MediaSource object is needed in order to implement the new
+        object-oriented MediaSource API:
+        http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html
+
+        No new tests - will be able to test after landing:
+        https://bugs.webkit.org/show_bug.cgi?id=91775
+
+        Adding new files to build files:
+        * CMakeLists.txt:
+        * DerivedSources.cpp:
+        * DerivedSources.make:
+        * DerivedSources.pri:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+
+        New MediaSource object:
+        * Modules/mediasource/MediaSource.cpp: Added.
+        * Modules/mediasource/MediaSource.h: Added.
+        * Modules/mediasource/MediaSource.idl: Added.
+
+        Create a registry for the blob storage and lookup:
+        * Modules/mediasource/MediaSourceRegistry.cpp: Added.
+        * Modules/mediasource/MediaSourceRegistry.h: Added.
+
+        Connect SourceBuffer to MediaSource:
+        * Modules/mediasource/SourceBuffer.cpp:
+        (WebCore::SourceBuffer::SourceBuffer):
+        (WebCore::SourceBuffer::buffered): Forward call to MediaSource.
+        (WebCore::SourceBuffer::append): Ditto.
+        (WebCore::SourceBuffer::abort): Ditto.
+        * Modules/mediasource/SourceBuffer.h:
+        (WebCore::SourceBuffer::create): Add a MediaSource to the constructor.
+        (WebCore::SourceBuffer::clear): Clear the MediaSource.
+        (SourceBuffer):
+        * Modules/mediasource/SourceBufferList.cpp: include SourceBuffer.h
+        * Modules/mediasource/SourceBufferList.h:
+
+        Make MediaSource an EventTarget:
+        * dom/EventTarget.h:
+        (WebCore):
+        * dom/EventTargetFactory.in:
+
+        Enable creation of MediaSource object URL from JavaScript:
+        * html/DOMURL.cpp:
+        (WebCore):
+        (WebCore::DOMURL::createObjectURL):
+        (WebCore::DOMURL::revokeObjectURL):
+        * html/DOMURL.h:
+        (WebCore):
+        (DOMURL):
+        * html/DOMURL.idl:
+        * html/PublicURLManager.h: create a new sourceURLs list for storing
+            reigstered MediaSource URLS.
+        (WebCore::PublicURLManager::contextDestroyed): make sure everything is
+            removed from the sourceURLs list upon destruction.
+        (PublicURLManager):
+        (WebCore::PublicURLManager::sourceURLs): getter for the sourceURLs list.
+
+        New MediaSource constructor:
+        * page/DOMWindow.idl:
+
 2012-08-07  Kentaro Hara  <haraken@chromium.org>
 
         [V8] Implement V8Proxy::registerExtensionIfNeeded() and remove redundant methods
index f80a9e2..0fa8acc 100644 (file)
 #include "JSMediaError.cpp"
 #include "JSMediaList.cpp"
 #include "JSMediaQueryList.cpp"
+#if ENABLE(MEDIA_SOURCE)
+#include "JSMediaSource.cpp"
+#endif
 #include "JSMemoryInfo.cpp"
 #include "JSMessageChannel.cpp"
 #include "JSMessageEvent.cpp"
index 0cf29be..74dd4f3 100644 (file)
@@ -106,6 +106,7 @@ BINDING_IDLS = \
     $(WebCore)/Modules/indexeddb/IDBVersionChangeEvent.idl \
     $(WebCore)/Modules/indexeddb/IDBVersionChangeRequest.idl \
     $(WebCore)/Modules/indexeddb/WorkerContextIndexedDatabase.idl \
+    $(WebCore)/Modules/mediasource/MediaSource.idl \
     $(WebCore)/Modules/mediasource/SourceBuffer.idl \
     $(WebCore)/Modules/mediasource/SourceBufferList.idl \
     $(WebCore)/Modules/notifications/DOMWindowNotifications.idl \
index 0726c6b..52ec6a8 100644 (file)
@@ -631,6 +631,7 @@ contains(DEFINES, ENABLE_VIDEO_TRACK=1) {
 
 contains(DEFINES, ENABLE_MEDIA_SOURCE=1) {
   IDL_BINDINGS += \
+    $$PWD/Modules/mediasource/MediaSource.idl \
     $$PWD/Modules/mediasource/SourceBuffer.idl \
     $$PWD/Modules/mediasource/SourceBufferList.idl
 }
index 6c76381..b77e0cb 100644 (file)
@@ -383,6 +383,8 @@ webcore_built_sources += \
        DerivedSources/WebCore/JSMediaError.h \
        DerivedSources/WebCore/JSMediaList.cpp \
        DerivedSources/WebCore/JSMediaList.h \
+       DerivedSources/WebCore/JSMediaSource.cpp \
+       DerivedSources/WebCore/JSMediaSource.h \
        DerivedSources/WebCore/JSMediaStream.cpp \
        DerivedSources/WebCore/JSMediaStream.h \
        DerivedSources/WebCore/JSMediaStreamEvent.cpp \
@@ -700,6 +702,7 @@ dom_binding_idls += \
        $(WebCore)/Modules/geolocation/PositionCallback.idl \
        $(WebCore)/Modules/geolocation/PositionError.idl \
        $(WebCore)/Modules/geolocation/PositionErrorCallback.idl \
+       $(WebCore)/Modules/mediasource/MediaSource.idl \
        $(WebCore)/Modules/mediasource/SourceBuffer.idl \
        $(WebCore)/Modules/mediasource/SourceBufferList.idl \
        $(WebCore)/Modules/mediastream/DOMWindowMediaStream.idl \
@@ -1172,6 +1175,10 @@ webcore_modules_sources += \
        Source/WebCore/Modules/indexeddb/PageGroupIndexedDatabase.h \
        Source/WebCore/Modules/indexeddb/WorkerContextIndexedDatabase.cpp \
        Source/WebCore/Modules/indexeddb/WorkerContextIndexedDatabase.h \
+       Source/WebCore/Modules/mediasource/MediaSource.cpp \
+       Source/WebCore/Modules/mediasource/MediaSource.h \
+       Source/WebCore/Modules/mediasource/MediaSourceRegistry.cpp \
+       Source/WebCore/Modules/mediasource/MediaSourceRegistry.h \
        Source/WebCore/Modules/mediasource/SourceBuffer.cpp \
        Source/WebCore/Modules/mediasource/SourceBuffer.h \
        Source/WebCore/Modules/mediasource/SourceBufferList.cpp \
diff --git a/Source/WebCore/Modules/mediasource/MediaSource.cpp b/Source/WebCore/Modules/mediasource/MediaSource.cpp
new file mode 100644 (file)
index 0000000..6f84d94
--- /dev/null
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MediaSource.h"
+
+#if ENABLE(MEDIA_SOURCE)
+
+#include "ContentType.h"
+#include "Event.h"
+#include "TimeRanges.h"
+#include <wtf/Uint8Array.h>
+
+namespace WebCore {
+
+PassRefPtr<MediaSource> MediaSource::create(ScriptExecutionContext* context)
+{
+    return adoptRef(new MediaSource(context));
+}
+
+MediaSource::MediaSource(ScriptExecutionContext* context)
+    : ContextDestructionObserver(context)
+    , m_readyState(closedKeyword())
+    , m_player(0)
+    , m_nextSourceBufferId(0)
+{
+    m_sourceBuffers = SourceBufferList::create(scriptExecutionContext());
+    m_activeSourceBuffers = SourceBufferList::create(scriptExecutionContext());
+}
+
+SourceBufferList* MediaSource::sourceBuffers()
+{
+    return m_sourceBuffers.get();
+}
+
+SourceBufferList* MediaSource::activeSourceBuffers()
+{
+    // FIXME(91649): support track selection
+    return m_activeSourceBuffers.get();
+}
+
+SourceBuffer* MediaSource::addSourceBuffer(const String& type, ExceptionCode& ec)
+{
+    // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-addsourcebuffer
+    // 1. If type is null or an empty then throw an INVALID_ACCESS_ERR exception and
+    // abort these steps.
+    if (type.isNull() || type.isEmpty()) {
+        ec = INVALID_ACCESS_ERR;
+        return 0;
+    }
+
+    // 2. If type contains a MIME type that is not supported ..., then throw a
+    // NOT_SUPPORTED_ERR exception and abort these steps.
+    ContentType contentType(type);
+    Vector<String> codecs = contentType.codecs();
+
+    if (!codecs.size()) {
+        ec = NOT_SUPPORTED_ERR;
+        return 0;
+    }
+    
+    // 4. If the readyState attribute is not in the "open" state then throw an
+    // INVALID_STATE_ERR exception and abort these steps.
+    if (!m_player || m_readyState != openKeyword()) {
+        ec = INVALID_STATE_ERR;
+        return 0;
+    }
+
+    // 5. Create a new SourceBuffer object and associated resources.
+    RefPtr<SourceBuffer> buffer = SourceBuffer::create(String::number(++m_nextSourceBufferId), this);
+
+    switch (m_player->sourceAddId(buffer->id(), contentType.type(), codecs)) {
+    case MediaPlayer::Ok:
+        // 6. Add the new object to sourceBuffers and fire a addsourcebuffer on that object.
+        m_sourceBuffers->add(buffer);
+        m_activeSourceBuffers->add(buffer);
+        // 7. Return the new object to the caller.
+        return buffer.get();
+    case MediaPlayer::NotSupported:
+        // 2 (cont). If type contains a MIME type ... that is not supported with the types 
+        // specified for the other SourceBuffer objects in sourceBuffers, then throw
+        // a NOT_SUPPORTED_ERR exception and abort these steps.
+        ec = NOT_SUPPORTED_ERR;
+        return 0;
+    case MediaPlayer::ReachedIdLimit:
+        // 3 (cont). If the user agent can't handle any more SourceBuffer objects then throw 
+        // a QUOTA_EXCEEDED_ERR exception and abort these steps.
+        ec = QUOTA_EXCEEDED_ERR;
+        return 0;
+    }
+
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+void MediaSource::removeSourceBuffer(SourceBuffer* buffer, ExceptionCode& ec)
+{
+    // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-removesourcebuffer
+    // 1. If sourceBuffer is null then throw an INVALID_ACCESS_ERR exception and
+    // abort these steps.
+    if (!buffer) {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+    // 2. If sourceBuffers is empty then throw an INVALID_STATE_ERR exception and
+    // abort these steps.
+    if (!m_player || !m_sourceBuffers->length()) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    // 3. If sourceBuffer specifies an object that is not in sourceBuffers then
+    // throw a NOT_FOUND_ERR exception and abort these steps.
+    // 6. Remove sourceBuffer from sourceBuffers and fire a removesourcebuffer event
+    // on that object.
+    if (!m_sourceBuffers->remove(buffer)) {
+        ec = NOT_FOUND_ERR;
+        return;
+    }
+
+    // 7. Destroy all resources for sourceBuffer.
+    m_activeSourceBuffers->remove(buffer);
+    m_player->sourceRemoveId(buffer->id());
+
+    // 4. Remove track information from audioTracks, videoTracks, and textTracks for all tracks 
+    // associated with sourceBuffer and fire a simple event named change on the modified lists.
+    // FIXME(91649): support track selection
+
+    // 5. If sourceBuffer is in activeSourceBuffers, then remove it from that list and fire a
+    // removesourcebuffer event on that object.
+    // FIXME(91649): support track selection
+}
+
+const String& MediaSource::readyState() const
+{
+    return m_readyState;
+}
+
+void MediaSource::setReadyState(const String& state)
+{
+    ASSERT(state == openKeyword() || state == closedKeyword() || state == endedKeyword());
+    if (m_readyState == state)
+        return;
+
+    String oldState = m_readyState;
+    m_readyState = state;
+
+    if (m_readyState == closedKeyword()) {
+        m_sourceBuffers->clear();
+        m_activeSourceBuffers->clear();
+        m_player = 0;
+        dispatchEvent(Event::create(eventNames().webkitsourcecloseEvent, false, false));
+        return;
+    }
+    
+    if (oldState == openKeyword() && m_readyState == endedKeyword()) {
+        dispatchEvent(Event::create(eventNames().webkitsourceendedEvent, false, false));
+        return;
+    }
+
+    if (m_readyState == openKeyword()) {
+        dispatchEvent(Event::create(eventNames().webkitsourceopenEvent, false, false));
+        return;
+    }
+}
+
+void MediaSource::endOfStream(const String& error, ExceptionCode& ec)
+{
+    // 3.1 http://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html#dom-endofstream
+    // 1. If the readyState attribute is not in the "open" state then throw an
+    // INVALID_STATE_ERR exception and abort these steps.
+    if (!m_player || m_readyState != openKeyword()) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    MediaPlayer::EndOfStreamStatus eosStatus = MediaPlayer::EosNoError;
+
+    if (error.isNull() || error.isEmpty())
+        eosStatus = MediaPlayer::EosNoError;
+    else if (error == "network")
+        eosStatus = MediaPlayer::EosNetworkError;
+    else if (error == "decode")
+        eosStatus = MediaPlayer::EosDecodeError;
+    else {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+    // 2. Change the readyState attribute value to "ended".
+    setReadyState(endedKeyword());
+    m_player->sourceEndOfStream(eosStatus);
+}
+
+PassRefPtr<TimeRanges> MediaSource::buffered(const String& id, ExceptionCode& ec) const
+{
+    if (!m_player || m_readyState == closedKeyword()) {
+        ec = INVALID_STATE_ERR;
+        return 0;
+    }
+
+    return m_player->sourceBuffered(id);
+}
+
+void MediaSource::append(const String& id, PassRefPtr<Uint8Array> data, ExceptionCode& ec)
+{
+    if (!data.get()) {
+        ec = INVALID_ACCESS_ERR;
+        return;
+    }
+
+    if (!m_player || m_readyState != openKeyword()) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    if (!data->length())
+        return;
+
+    if (!m_player->sourceAppend(id, data->data(), data->length())) {
+        ec = SYNTAX_ERR;
+        return;
+    }
+}
+
+void MediaSource::abort(const String& id, ExceptionCode& ec)
+{
+    if (!m_player || m_readyState != openKeyword()) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    if (!m_player->sourceAbort(id))
+        ASSERT_NOT_REACHED();
+}
+
+const AtomicString& MediaSource::interfaceName() const
+{
+    return eventNames().interfaceForMediaSource;
+}
+
+ScriptExecutionContext* MediaSource::scriptExecutionContext() const
+{
+    return ContextDestructionObserver::scriptExecutionContext();
+}
+
+EventTargetData* MediaSource::eventTargetData()
+{
+    return &m_eventTargetData;
+}
+
+EventTargetData* MediaSource::ensureEventTargetData()
+{
+    return &m_eventTargetData;
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/Modules/mediasource/MediaSource.h b/Source/WebCore/Modules/mediasource/MediaSource.h
new file mode 100644 (file)
index 0000000..646ac3a
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MediaSource_h
+#define MediaSource_h
+
+#if ENABLE(MEDIA_SOURCE)
+
+#include "ContextDestructionObserver.h"
+#include "MediaPlayer.h"
+#include "SourceBuffer.h"
+#include "SourceBufferList.h"
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+class MediaSource : public RefCounted<MediaSource>, public EventTarget, public ContextDestructionObserver {
+public:
+    static const String& openKeyword()
+    {
+        DEFINE_STATIC_LOCAL(const String, open, ("open"));
+        return open;
+    }
+
+    static const String& closedKeyword()
+    {
+        DEFINE_STATIC_LOCAL(const String, closed, ("closed"));
+        return closed;
+    }
+
+    static const String& endedKeyword()
+    {
+        DEFINE_STATIC_LOCAL(const String, ended, ("ended"));
+        return ended;
+    }
+
+    static PassRefPtr<MediaSource> create(ScriptExecutionContext*);
+    virtual ~MediaSource() { }
+
+    SourceBufferList* sourceBuffers();
+    SourceBufferList* activeSourceBuffers();
+
+    SourceBuffer* addSourceBuffer(const String& type, ExceptionCode&);
+    void removeSourceBuffer(SourceBuffer*, ExceptionCode&);
+
+    const String& readyState() const;
+    void setReadyState(const String&);
+
+    void endOfStream(const String& error, ExceptionCode&);
+
+    void setMediaPlayer(MediaPlayer* player) { m_player = player; }
+    
+    PassRefPtr<TimeRanges> buffered(const String& id, ExceptionCode&) const;
+    void append(const String& id, PassRefPtr<Uint8Array> data, ExceptionCode&);
+    void abort(const String& id, ExceptionCode&);
+
+    // EventTarget interface
+    virtual const AtomicString& interfaceName() const OVERRIDE;
+    virtual ScriptExecutionContext* scriptExecutionContext() const OVERRIDE;
+
+    using RefCounted<MediaSource>::ref;
+    using RefCounted<MediaSource>::deref;
+
+private:
+    explicit MediaSource(ScriptExecutionContext*);
+
+    virtual EventTargetData* eventTargetData() OVERRIDE;
+    virtual EventTargetData* ensureEventTargetData() OVERRIDE;
+
+    virtual void refEventTarget() OVERRIDE { ref(); }
+    virtual void derefEventTarget() OVERRIDE { deref(); }
+
+    EventTargetData m_eventTargetData;
+
+    String m_readyState;
+    MediaPlayer* m_player;
+
+    RefPtr<SourceBufferList> m_sourceBuffers;
+    RefPtr<SourceBufferList> m_activeSourceBuffers;
+    int m_nextSourceBufferId;
+};
+
+} // namespace WebCore
+
+#endif
+#endif
diff --git a/Source/WebCore/Modules/mediasource/MediaSource.idl b/Source/WebCore/Modules/mediasource/MediaSource.idl
new file mode 100644 (file)
index 0000000..25f7dec
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+module html {
+
+    interface [
+        Conditional=MEDIA_SOURCE,
+        V8EnabledAtRuntime=mediaSource,
+        EventTarget,
+        Constructor,
+        CallWith=ScriptExecutionContext
+    ] MediaSource {
+        // All the source buffers created by this object.
+        readonly attribute SourceBufferList sourceBuffers;
+
+        // Subset of sourceBuffers that provide data for the selected/enabled tracks.
+        readonly attribute SourceBufferList activeSourceBuffers;
+
+        SourceBuffer addSourceBuffer(in DOMString type) raises (DOMException);
+        void removeSourceBuffer(in SourceBuffer buffer) raises (DOMException);
+
+        readonly attribute DOMString readyState;
+        
+        void endOfStream(in [Optional=DefaultIsNullString] DOMString error)
+            raises (DOMException);
+        
+        // EventTarget interface
+        void addEventListener(in DOMString type,
+                              in EventListener listener,
+                              in [Optional] boolean useCapture);
+        void removeEventListener(in DOMString type,
+                                 in EventListener listener,
+                                 in [Optional] boolean useCapture);
+        boolean dispatchEvent(in Event event)
+            raises(EventException);
+    };
+
+}
diff --git a/Source/WebCore/Modules/mediasource/MediaSourceRegistry.cpp b/Source/WebCore/Modules/mediasource/MediaSourceRegistry.cpp
new file mode 100644 (file)
index 0000000..0fb8ceb
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "MediaSourceRegistry.h"
+
+#if ENABLE(MEDIA_SOURCE)
+
+#include "KURL.h"
+#include "MediaSource.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+MediaSourceRegistry& MediaSourceRegistry::registry()
+{
+    ASSERT(isMainThread());
+    DEFINE_STATIC_LOCAL(MediaSourceRegistry, instance, ());
+    return instance;
+}
+
+void MediaSourceRegistry::registerMediaSourceURL(const KURL& url, PassRefPtr<MediaSource> source)
+{
+    ASSERT(isMainThread());
+    m_mediaSources.set(url.string(), source);
+}
+
+void MediaSourceRegistry::unregisterMediaSourceURL(const KURL& url)
+{
+    ASSERT(isMainThread());
+    m_mediaSources.remove(url.string());
+}
+
+MediaSource* MediaSourceRegistry::lookupMediaSource(const String& url)
+{
+    ASSERT(isMainThread());
+    return m_mediaSources.get(url).get();
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/Modules/mediasource/MediaSourceRegistry.h b/Source/WebCore/Modules/mediasource/MediaSourceRegistry.h
new file mode 100644 (file)
index 0000000..96da6b3
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MediaSourceRegistry_h
+#define MediaSourceRegistry_h
+
+#if ENABLE(MEDIA_SOURCE)
+
+#include <wtf/HashMap.h>
+#include <wtf/PassRefPtr.h>
+#include <wtf/text/StringHash.h>
+
+namespace WebCore {
+
+class KURL;
+class MediaSource;
+
+class MediaSourceRegistry {
+public:
+    // Returns a single instance of MediaSourceRegistry.
+    static MediaSourceRegistry& registry();
+
+    // Registers a blob URL referring to the specified media source.
+    void registerMediaSourceURL(const KURL&, PassRefPtr<MediaSource>);
+    void unregisterMediaSourceURL(const KURL&);
+
+    MediaSource* lookupMediaSource(const String& url);
+
+private:
+    HashMap<String, RefPtr<MediaSource> > m_mediaSources;
+};
+
+} // namespace WebCore
+
+#endif
+#endif
index 7b36821..5919108 100644 (file)
@@ -38,8 +38,9 @@
 
 namespace WebCore {
 
-SourceBuffer::SourceBuffer(const String& id)
+SourceBuffer::SourceBuffer(const String& id, PassRefPtr<MediaSource> source)
     : m_id(id)
+    , m_source(source)
 {
 }
 
@@ -47,20 +48,34 @@ SourceBuffer::~SourceBuffer()
 {
 }
 
-PassRefPtr<TimeRanges> SourceBuffer::buffered(ExceptionCode&) const
+PassRefPtr<TimeRanges> SourceBuffer::buffered(ExceptionCode& ec) const
 {
-    // FIXME(91773): return buffered data from media source.
-    return 0;
+    if (!m_source) {
+        ec = INVALID_STATE_ERR;
+        return 0;
+    }
+
+    return m_source->buffered(id(), ec);
 }
 
-void SourceBuffer::append(PassRefPtr<Uint8Array>, ExceptionCode&)
+void SourceBuffer::append(PassRefPtr<Uint8Array> data, ExceptionCode& ec)
 {
-    // FIXME(91773): append the data to the media source.
+    if (!m_source) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    m_source->append(id(), data, ec);
 }
 
-void SourceBuffer::abort(ExceptionCode&)
+void SourceBuffer::abort(ExceptionCode& ec)
 {
-    // FIXME(91773): signal the media source to abort this source buffer.
+    if (!m_source) {
+        ec = INVALID_STATE_ERR;
+        return;
+    }
+
+    m_source->abort(id(), ec);
 }
 
 } // namespace WebCore
index 0cbff3e..d180dd4 100644 (file)
@@ -34,6 +34,7 @@
 #if ENABLE(MEDIA_SOURCE)
 
 #include "ExceptionCode.h"
+#include "MediaSource.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
@@ -44,9 +45,9 @@ class TimeRanges;
 
 class SourceBuffer : public RefCounted<SourceBuffer> {
 public:
-    static PassRefPtr<SourceBuffer> create(const String& id)
+    static PassRefPtr<SourceBuffer> create(const String& id, PassRefPtr<MediaSource> source)
     {
-        return adoptRef(new SourceBuffer(id));
+        return adoptRef(new SourceBuffer(id, source));
     }
 
     virtual ~SourceBuffer();
@@ -59,12 +60,13 @@ public:
     
     const String& id() const { return m_id; }
 
-    void clear() { }
+    void clear() { m_source.clear(); }
 
 private:
-    explicit SourceBuffer(const String& id);
+    explicit SourceBuffer(const String& id, PassRefPtr<MediaSource>);
 
     String m_id;
+    RefPtr<MediaSource> m_source;
 };
 
 } // namespace WebCore
index 3cc4678..662b46f 100644 (file)
@@ -34,6 +34,7 @@
 #if ENABLE(MEDIA_SOURCE)
 
 #include "Event.h"
+#include "SourceBuffer.h"
 
 namespace WebCore {
 
index 7e9f831..6f7f9a7 100644 (file)
 #if ENABLE(MEDIA_SOURCE)
 
 #include "EventTarget.h"
-#include "SourceBuffer.h"
 #include <wtf/RefCounted.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
+class SourceBuffer;
+
 class SourceBufferList : public RefCounted<SourceBufferList>, public EventTarget {
 public:
     static PassRefPtr<SourceBufferList> create(ScriptExecutionContext* context)
index eb9fdbb..843eaab 100644 (file)
@@ -35,6 +35,7 @@ namespace WebCore {
 
 MediaStreamRegistry& MediaStreamRegistry::registry()
 {
+    // Since WebWorkers cannot obtain MediaSource objects, we should be on the main thread.
     ASSERT(isMainThread());
     DEFINE_STATIC_LOCAL(MediaStreamRegistry, instance, ());
     return instance;
index 304c4b7..d049586 100644 (file)
@@ -3010,9 +3010,13 @@ contains(DEFINES, ENABLE_FILE_SYSTEM=1) {
 
 contains(DEFINES, ENABLE_MEDIA_SOURCE=1) {
     HEADERS += \
+        Modules/mediasource/MediaSource.h \
+        Modules/mediasource/MediaSourceRegistry.h \
         Modules/mediasource/SourceBuffer.h \
         Modules/mediasource/SourceBufferList.h
     SOURCES += \
+        Modules/mediasource/MediaSource.cpp \
+        Modules/mediasource/MediaSourceRegistry.cpp \
         Modules/mediasource/SourceBuffer.cpp \
         Modules/mediasource/SourceBufferList.cpp
 }
index e961ef8..b90297d 100644 (file)
             'Modules/intents/Intent.idl',
             'Modules/intents/IntentResultCallback.idl',
             'Modules/intents/NavigatorIntents.idl',
+            'Modules/mediasource/MediaSource.idl',
             'Modules/mediasource/SourceBuffer.idl',
             'Modules/mediasource/SourceBufferList.idl',
             'Modules/mediastream/DOMWindowMediaStream.idl',
             'Modules/intents/IntentResultCallback.h',
             'Modules/intents/NavigatorIntents.cpp',
             'Modules/intents/NavigatorIntents.h',
+            'Modules/mediasource/MediaSource.cpp',
+            'Modules/mediasource/MediaSource.h',
+            'Modules/mediasource/MediaSourceRegistry.cpp',
+            'Modules/mediasource/MediaSourceRegistry.h',
             'Modules/mediasource/SourceBuffer.cpp',
             'Modules/mediasource/SourceBuffer.h',
             'Modules/mediasource/SourceBufferList.cpp',
index 1e8dd67..2ba1fa1 100755 (executable)
                                Name="mediasource"
                                >
                                <File
+                                       RelativePath="..\Modules\mediasource\MediaSource.cpp"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\Modules\mediasource\MediaSource.h"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\Modules\mediasource\MediaSourceRegistry.cpp"
+                                       >
+                               </File>
+                               <File
+                                       RelativePath="..\Modules\mediasource\MediaSourceRegistry.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\Modules\mediasource\SourceBuffer.cpp"
                                        >
                                </File>
index def69b9..84b947d 100644 (file)
                B10B697E140C174000BC1C26 /* WebVTTTokenizer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebVTTTokenizer.cpp; sourceTree = "<group>"; };
                B10B697F140C174000BC1C26 /* WebVTTTokenizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebVTTTokenizer.h; sourceTree = "<group>"; };
                B1827492134CA4C100B98C2D /* CallbackFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CallbackFunction.cpp; sourceTree = "<group>"; };
+               B1A942DE15B5CE2200D525D1 /* MediaSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaSource.cpp; sourceTree = "<group>"; };
+               B1A942DF15B5CE2200D525D1 /* MediaSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSource.h; sourceTree = "<group>"; };
+               B1A942E015B5CE2200D525D1 /* MediaSource.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MediaSource.idl; sourceTree = "<group>"; };
+               B1A942E115B5CE2200D525D1 /* MediaSourceRegistry.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaSourceRegistry.cpp; sourceTree = "<group>"; };
+               B1A942E215B5CE2200D525D1 /* MediaSourceRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MediaSourceRegistry.h; sourceTree = "<group>"; };
                B1A942E315B5CE2200D525D1 /* SourceBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SourceBuffer.cpp; sourceTree = "<group>"; };
                B1A942E415B5CE2200D525D1 /* SourceBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceBuffer.h; sourceTree = "<group>"; };
                B1A942E515B5CE2200D525D1 /* SourceBuffer.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SourceBuffer.idl; sourceTree = "<group>"; };
                B1A942DD15B5CE2200D525D1 /* mediasource */ = {
                        isa = PBXGroup;
                        children = (
+                               B1A942DE15B5CE2200D525D1 /* MediaSource.cpp */,
+                               B1A942DF15B5CE2200D525D1 /* MediaSource.h */,
+                               B1A942E015B5CE2200D525D1 /* MediaSource.idl */,
+                               B1A942E115B5CE2200D525D1 /* MediaSourceRegistry.cpp */,
+                               B1A942E215B5CE2200D525D1 /* MediaSourceRegistry.h */,
                                B1A942E315B5CE2200D525D1 /* SourceBuffer.cpp */,
                                B1A942E415B5CE2200D525D1 /* SourceBuffer.h */,
                                B1A942E515B5CE2200D525D1 /* SourceBuffer.idl */,
index d34a265..d85a8c4 100644 (file)
@@ -56,6 +56,7 @@ namespace WebCore {
     class JavaScriptAudioNode;
     class LocalMediaStream;
     class MediaController;
+    class MediaSource;
     class MediaStream;
     class MessagePort;
     class Node;
index 0a49ece..6d972c3 100644 (file)
@@ -15,6 +15,7 @@ IDBVersionChangeRequest conditional=INDEXED_DATABASE
 JavaScriptAudioNode conditional=WEB_AUDIO
 LocalMediaStream conditional=MEDIA_STREAM
 MediaController conditional=VIDEO
+MediaSource conditional=MEDIA_SOURCE
 MediaStream conditional=MEDIA_STREAM
 MediaStreamTrack conditional=MEDIA_STREAM
 MediaStreamTrackList conditional=MEDIA_STREAM
index 4f9780d..f658626 100644 (file)
 #include <wtf/PassOwnPtr.h>
 #include <wtf/MainThread.h>
 
+#if ENABLE(MEDIA_SOURCE)
+#include "MediaSource.h"
+#include "MediaSourceRegistry.h"
+#endif
+
 #if ENABLE(MEDIA_STREAM)
 #include "MediaStream.h"
 #include "MediaStreamRegistry.h"
 
 namespace WebCore {
 
+#if ENABLE(MEDIA_SOURCE)
+String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, MediaSource* source)
+{
+    // Since WebWorkers cannot obtain MediaSource objects, we should be on the main thread.
+    ASSERT(isMainThread());
+
+    if (!scriptExecutionContext || !source)
+        return String();
+
+    KURL publicURL = BlobURL::createPublicURL(scriptExecutionContext->securityOrigin());
+    if (publicURL.isEmpty())
+        return String();
+
+    MediaSourceRegistry::registry().registerMediaSourceURL(publicURL, source);
+    scriptExecutionContext->publicURLManager().sourceURLs().add(publicURL.string());
+
+    return publicURL.string();
+}
+#endif
+
 #if ENABLE(MEDIA_STREAM)
 String DOMURL::createObjectURL(ScriptExecutionContext* scriptExecutionContext, MediaStream* stream)
 {
@@ -98,6 +123,13 @@ void DOMURL::revokeObjectURL(ScriptExecutionContext* scriptExecutionContext, con
         blobURLs.remove(url.string());
     }
 
+#if ENABLE(MEDIA_SOURCE)
+    HashSet<String>& sourceURLs = scriptExecutionContext->publicURLManager().sourceURLs();
+    if (sourceURLs.contains(url.string())) {
+        MediaSourceRegistry::registry().unregisterMediaSourceURL(url);
+        sourceURLs.remove(url.string());
+    }
+#endif
 #if ENABLE(MEDIA_STREAM)
     HashSet<String>& streamURLs = scriptExecutionContext->publicURLManager().streamURLs();
     if (streamURLs.contains(url.string())) {
index 25ae013..d71fb93 100644 (file)
@@ -36,6 +36,7 @@
 namespace WebCore {
 
 class Blob;
+class MediaSource;
 class MediaStream;
 class ScriptExecutionContext;
 
@@ -49,6 +50,9 @@ public:
 
     static String createObjectURL(ScriptExecutionContext*, Blob*);
     static void revokeObjectURL(ScriptExecutionContext*, const String&);
+#if ENABLE(MEDIA_SOURCE)
+    static String createObjectURL(ScriptExecutionContext*, MediaSource*);
+#endif
 #if ENABLE(MEDIA_STREAM)
     static String createObjectURL(ScriptExecutionContext*, MediaStream*);
 #endif
index ed04c23..b36e8f7 100644 (file)
@@ -33,6 +33,9 @@ module html {
         JSNoStaticTables,
         InterfaceName=URL
     ] DOMURL {
+#if defined(ENABLE_MEDIA_SOURCE) && ENABLE_MEDIA_SOURCE
+        [CallWith=ScriptExecutionContext,TreatReturnedNullStringAs=Null] static DOMString createObjectURL(in MediaSource? source);
+#endif
 #if defined(ENABLE_MEDIA_STREAM) && ENABLE_MEDIA_STREAM
         [CallWith=ScriptExecutionContext,TreatReturnedNullStringAs=Null] static DOMString createObjectURL(in MediaStream? stream);
 #endif
index 258ac06..f5e7b20 100644 (file)
 #include "MediaStreamRegistry.h"
 #endif
 
+#if ENABLE(MEDIA_SOURCE)
+#include "MediaSource.h"
+#include "MediaSourceRegistry.h"
+#endif
+
 namespace WebCore {
 
 class ScriptExecutionContext;
@@ -56,18 +61,29 @@ public:
         for (HashSet<String>::iterator iter = m_streamURLs.begin(); iter != streamURLsEnd; ++iter)
             MediaStreamRegistry::registry().unregisterMediaStreamURL(KURL(ParsedURLString, *iter));
 #endif
+#if ENABLE(MEDIA_SOURCE)
+        HashSet<String>::iterator sourceURLsEnd = m_sourceURLs.end();
+        for (HashSet<String>::iterator iter = m_sourceURLs.begin(); iter != sourceURLsEnd; ++iter)
+            MediaSourceRegistry::registry().unregisterMediaSourceURL(KURL(ParsedURLString, *iter));
+#endif
     }
 
     HashSet<String>& blobURLs() { return m_blobURLs; }
 #if ENABLE(MEDIA_STREAM)
     HashSet<String>& streamURLs() { return m_streamURLs; }
 #endif
+#if ENABLE(MEDIA_SOURCE)
+    HashSet<String>& sourceURLs() { return m_sourceURLs; }
+#endif
 
 private:
     HashSet<String> m_blobURLs;
 #if ENABLE(MEDIA_STREAM)
     HashSet<String> m_streamURLs;
 #endif
+#if ENABLE(MEDIA_SOURCE)
+    HashSet<String> m_sourceURLs;
+#endif
 };
 
 } // namespace WebCore
index f1a3474..6d1957b 100644 (file)
@@ -785,6 +785,7 @@ module window {
 
         attribute [Conditional=MUTATION_OBSERVERS] MutationObserverConstructor WebKitMutationObserver;
 
+        attribute [Conditional=MEDIA_SOURCE, V8EnabledAtRuntime=mediaSource] MediaSourceConstructor MediaSource;
         attribute [Conditional=MEDIA_SOURCE, V8EnabledAtRuntime=mediaSource] SourceBufferConstructor SourceBuffer;
         attribute [Conditional=MEDIA_SOURCE, V8EnabledAtRuntime=mediaSource] SourceBufferListConstructor SourceBufferList;