[OpenWebRTC] RealtimeMediaSourceCenter implementation
authorphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Mar 2015 15:18:21 +0000 (15:18 +0000)
committerphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Mar 2015 15:18:21 +0000 (15:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142476

Reviewed by Eric Carlson.

The old GStreamer MediaStreamCenter is replaced by the OpenWebRTC
RealtimeMediaSourceCenter. It is not yet able to correctly assess
MediaConstraints so it selects the first audio/video sources
available through OpenWebRTC.

* PlatformEfl.cmake: Add new files to the build.
* PlatformGTK.cmake: Ditto.
* platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp: Removed.
* platform/mediastream/openwebrtc/OpenWebRTCUtilities.cpp: Added.
(WebCore::initializeOpenWebRTC): Simple function to initialize the
framework, it is going to be used by the PeerConnection backend as well.
* platform/mediastream/openwebrtc/OpenWebRTCUtilities.h: Added.
* platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.cpp: Added.
(WebCore::mediaSourcesAvailableCallback): Function invoked once
the media sources discovery succeeded within OpenWebRTC.
(WebCore::RealtimeMediaSourceCenter::platformCenter): Instantiate
the OpenWebRTC RealtimeMediaSourceCenter.
(WebCore::RealtimeMediaSourceCenterOwr::RealtimeMediaSourceCenterOwr):
(WebCore::RealtimeMediaSourceCenterOwr::~RealtimeMediaSourceCenterOwr):
(WebCore::RealtimeMediaSourceCenterOwr::validateRequestConstraints):
Schedule a discovery process for the capture sources.
(WebCore::RealtimeMediaSourceCenterOwr::createMediaStream): Pick
the first audio/video sources and create a MediaStream accordingly.
(WebCore::RealtimeMediaSourceCenterOwr::getMediaStreamTrackSources):
Not yet implemented.
(WebCore::RealtimeMediaSourceCenterOwr::mediaSourcesAvailable):
Method invoked once the capture sources process succeeded. Parse
them and create an internal cache of RealtimeMediaSources accordingly.
(WebCore::RealtimeMediaSourceCenterOwr::firstSource): Utility
function to fetch the first source of the given type from the
RealtimeMediaSources cache.
* platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.h: Renamed from Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h.
* platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h: Added.

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

Source/WebCore/ChangeLog
Source/WebCore/PlatformEfl.cmake
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp [deleted file]
Source/WebCore/platform/mediastream/openwebrtc/OpenWebRTCUtilities.cpp [new file with mode: 0644]
Source/WebCore/platform/mediastream/openwebrtc/OpenWebRTCUtilities.h [new file with mode: 0644]
Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.cpp [new file with mode: 0644]
Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.h [moved from Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h with 75% similarity]
Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h [new file with mode: 0644]

index 40b8031..4198a97 100644 (file)
@@ -1,3 +1,44 @@
+2015-03-17  Philippe Normand  <pnormand@igalia.com>
+
+        [OpenWebRTC] RealtimeMediaSourceCenter implementation
+        https://bugs.webkit.org/show_bug.cgi?id=142476
+
+        Reviewed by Eric Carlson.
+
+        The old GStreamer MediaStreamCenter is replaced by the OpenWebRTC
+        RealtimeMediaSourceCenter. It is not yet able to correctly assess
+        MediaConstraints so it selects the first audio/video sources
+        available through OpenWebRTC.
+
+        * PlatformEfl.cmake: Add new files to the build.
+        * PlatformGTK.cmake: Ditto.
+        * platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp: Removed.
+        * platform/mediastream/openwebrtc/OpenWebRTCUtilities.cpp: Added.
+        (WebCore::initializeOpenWebRTC): Simple function to initialize the
+        framework, it is going to be used by the PeerConnection backend as well.
+        * platform/mediastream/openwebrtc/OpenWebRTCUtilities.h: Added.
+        * platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.cpp: Added.
+        (WebCore::mediaSourcesAvailableCallback): Function invoked once
+        the media sources discovery succeeded within OpenWebRTC.
+        (WebCore::RealtimeMediaSourceCenter::platformCenter): Instantiate
+        the OpenWebRTC RealtimeMediaSourceCenter.
+        (WebCore::RealtimeMediaSourceCenterOwr::RealtimeMediaSourceCenterOwr):
+        (WebCore::RealtimeMediaSourceCenterOwr::~RealtimeMediaSourceCenterOwr):
+        (WebCore::RealtimeMediaSourceCenterOwr::validateRequestConstraints):
+        Schedule a discovery process for the capture sources.
+        (WebCore::RealtimeMediaSourceCenterOwr::createMediaStream): Pick
+        the first audio/video sources and create a MediaStream accordingly.
+        (WebCore::RealtimeMediaSourceCenterOwr::getMediaStreamTrackSources):
+        Not yet implemented.
+        (WebCore::RealtimeMediaSourceCenterOwr::mediaSourcesAvailable):
+        Method invoked once the capture sources process succeeded. Parse
+        them and create an internal cache of RealtimeMediaSources accordingly.
+        (WebCore::RealtimeMediaSourceCenterOwr::firstSource): Utility
+        function to fetch the first source of the given type from the
+        RealtimeMediaSources cache.
+        * platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.h: Renamed from Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.h.
+        * platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h: Added.
+
 2015-03-24  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         [EFL] Add OpenWebRTC in jhbuild
index 5bac12c..ff01479 100644 (file)
@@ -18,7 +18,7 @@ list(APPEND WebCore_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/graphics/texmap"
     "${WEBCORE_DIR}/platform/graphics/texmap/coordinated"
     "${WEBCORE_DIR}/platform/linux"
-    "${WEBCORE_DIR}/platform/mediastream/gstreamer"
+    "${WEBCORE_DIR}/platform/mediastream/openwebrtc"
     "${WEBCORE_DIR}/platform/mock/mediasource"
     "${WEBCORE_DIR}/platform/network/soup"
     "${WEBCORE_DIR}/platform/text/efl"
@@ -213,7 +213,8 @@ list(APPEND WebCore_SOURCES
     platform/linux/GamepadDeviceLinux.cpp
     platform/linux/MemoryPressureHandlerLinux.cpp
 
-    platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp
+    platform/mediastream/openwebrtc/OpenWebRTCUtilities.cpp
+    platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.cpp
 
     platform/network/efl/NetworkStateNotifierEfl.cpp
 
index dd26490..c753db7 100644 (file)
@@ -16,7 +16,7 @@ list(APPEND WebCore_INCLUDE_DIRECTORIES
     "${WEBCORE_DIR}/platform/graphics/opentype"
     "${WEBCORE_DIR}/platform/graphics/wayland"
     "${WEBCORE_DIR}/platform/linux"
-    "${WEBCORE_DIR}/platform/mediastream/gstreamer"
+    "${WEBCORE_DIR}/platform/mediastream/openwebrtc"
     "${WEBCORE_DIR}/platform/mock/mediasource"
     "${WEBCORE_DIR}/platform/network/gtk"
     "${WEBCORE_DIR}/platform/network/soup"
@@ -153,7 +153,8 @@ list(APPEND WebCore_SOURCES
     platform/linux/GamepadDeviceLinux.cpp
     platform/linux/MemoryPressureHandlerLinux.cpp
 
-    platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp
+    platform/mediastream/openwebrtc/OpenWebRTCUtilities.cpp
+    platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.cpp
 
     platform/network/soup/AuthenticationChallengeSoup.cpp
     platform/network/soup/CertificateInfo.cpp
diff --git a/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp b/Source/WebCore/platform/mediastream/gstreamer/MediaStreamCenterGStreamer.cpp
deleted file mode 100644 (file)
index 5bf104e..0000000
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2011 Ericsson AB. All rights reserved.
- * 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:
- *
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. 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.
- * 3. Neither the name of Ericsson 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"
-
-#if ENABLE(MEDIA_STREAM)
-
-#include "MediaStreamCenterGStreamer.h"
-
-#include "MediaStreamCreationClient.h"
-#include "MediaStreamPrivate.h"
-#include "MediaStreamTrackSourcesRequestClient.h"
-#include "NotImplemented.h"
-#include "RealtimeMediaSourceCapabilities.h"
-#include <wtf/MainThread.h>
-
-namespace WebCore {
-
-RealtimeMediaSourceCenter& RealtimeMediaSourceCenter::platformCenter()
-{
-    ASSERT(isMainThread());
-    DEPRECATED_DEFINE_STATIC_LOCAL(MediaStreamCenterGStreamer, center, ());
-    return center;
-}
-
-MediaStreamCenterGStreamer::MediaStreamCenterGStreamer()
-{
-}
-
-MediaStreamCenterGStreamer::~MediaStreamCenterGStreamer()
-{
-}
-
-void MediaStreamCenterGStreamer::validateRequestConstraints(PassRefPtr<MediaStreamCreationClient> prpQueryClient, PassRefPtr<MediaConstraints>, PassRefPtr<MediaConstraints>)
-{
-    RefPtr<MediaStreamCreationClient> client = prpQueryClient;
-    // FIXME: Actually do constraints validation. The MediaConstraints
-    // need to comply with the available audio/video device(s)
-    // capabilities. See bug #123345.
-    client->constraintsValidated();
-}
-    
-void MediaStreamCenterGStreamer::createMediaStream(PassRefPtr<MediaStreamCreationClient> prpQueryClient, PassRefPtr<MediaConstraints>, PassRefPtr<MediaConstraints>)
-{
-    RefPtr<MediaStreamCreationClient> client = prpQueryClient;
-    ASSERT(client);
-
-    Vector<RefPtr<RealtimeMediaSource>> audioSources;
-    Vector<RefPtr<RealtimeMediaSource>> videoSources;
-    // FIXME: fill source vectors, see bug #110150.
-    client->didCreateStream(MediaStreamPrivate::create(audioSources, videoSources));
-
-}
-
-bool MediaStreamCenterGStreamer::getMediaStreamTrackSources(PassRefPtr<MediaStreamTrackSourcesRequestClient>)
-{
-    notImplemented();
-    return false;
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
diff --git a/Source/WebCore/platform/mediastream/openwebrtc/OpenWebRTCUtilities.cpp b/Source/WebCore/platform/mediastream/openwebrtc/OpenWebRTCUtilities.cpp
new file mode 100644 (file)
index 0000000..a99195f
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 Igalia S.L
+ * Copyright (C) 2015 Metrological
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. Neither the name of the copyright holder 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
+ * HOLDER 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"
+
+#if USE(OPENWEBRTC)
+#include "OpenWebRTCUtilities.h"
+
+#include <owr/owr.h>
+
+namespace WebCore {
+
+void initializeOpenWebRTC()
+{
+    owr_init_with_main_context(g_main_context_default());
+}
+
+}
+
+#endif // USE(OPENWEBRTC)
diff --git a/Source/WebCore/platform/mediastream/openwebrtc/OpenWebRTCUtilities.h b/Source/WebCore/platform/mediastream/openwebrtc/OpenWebRTCUtilities.h
new file mode 100644 (file)
index 0000000..bed474b
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2015 Igalia S.L
+ * Copyright (C) 2015 Metrological
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. Neither the name of the copyright holder 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
+ * HOLDER 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.
+ */
+
+
+namespace WebCore {
+
+void initializeOpenWebRTC();
+
+}
diff --git a/Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.cpp b/Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceCenterOwr.cpp
new file mode 100644 (file)
index 0000000..0c37e99
--- /dev/null
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2011 Ericsson AB. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2015 Igalia S.L. All rights reserved.
+ * Copyright (C) 2015 Metrological. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. 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.
+ * 3. Neither the name of Ericsson 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"
+
+#if ENABLE(MEDIA_STREAM) && USE(OPENWEBRTC)
+#include "RealtimeMediaSourceCenterOwr.h"
+
+#include "MediaStreamCreationClient.h"
+#include "MediaStreamPrivate.h"
+#include "MediaStreamTrackSourcesRequestClient.h"
+#include "NotImplemented.h"
+#include "OpenWebRTCUtilities.h"
+#include "RealtimeMediaSource.h"
+#include "RealtimeMediaSourceCapabilities.h"
+#include "UUID.h"
+#include <owr/owr.h>
+#include <owr/owr_local.h>
+#include <owr/owr_media_source.h>
+#include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
+#include <wtf/gobject/GUniquePtr.h>
+#include <wtf/text/CString.h>
+#include <wtf/text/StringHash.h>
+
+
+namespace WebCore {
+
+RealtimeMediaSourceCenter& RealtimeMediaSourceCenter::platformCenter()
+{
+    ASSERT(isMainThread());
+    static NeverDestroyed<RealtimeMediaSourceCenterOwr> center;
+    return center;
+}
+
+static void mediaSourcesAvailableCallback(GList* sources, gpointer userData)
+{
+    RealtimeMediaSourceCenterOwr* center = reinterpret_cast<RealtimeMediaSourceCenterOwr*>(userData);
+    center->mediaSourcesAvailable(sources);
+}
+
+RealtimeMediaSourceCenterOwr::RealtimeMediaSourceCenterOwr()
+{
+    initializeOpenWebRTC();
+}
+
+RealtimeMediaSourceCenterOwr::~RealtimeMediaSourceCenterOwr()
+{
+}
+
+void RealtimeMediaSourceCenterOwr::validateRequestConstraints(PassRefPtr<MediaStreamCreationClient> prpClient, PassRefPtr<MediaConstraints> prpAudioConstraints, PassRefPtr<MediaConstraints> prpVideoConstraints)
+{
+    m_client = prpClient;
+    ASSERT(m_client);
+
+    // FIXME: Actually do constraints validation. The MediaConstraints
+    // need to comply with the available audio/video device(s)
+    // capabilities. See bug #123345.
+    RefPtr<MediaConstraints> audioConstraints = prpAudioConstraints;
+    RefPtr<MediaConstraints> videoConstraints = prpVideoConstraints;
+
+    int types;
+    if (audioConstraints)
+        types |= OWR_MEDIA_TYPE_AUDIO;
+    if (videoConstraints)
+        types |= OWR_MEDIA_TYPE_VIDEO;
+
+    owr_get_capture_sources(static_cast<OwrMediaType>(types), mediaSourcesAvailableCallback, this);
+}
+
+void RealtimeMediaSourceCenterOwr::createMediaStream(PassRefPtr<MediaStreamCreationClient> prpQueryClient, PassRefPtr<MediaConstraints> audioConstraints, PassRefPtr<MediaConstraints> videoConstraints)
+{
+    RefPtr<MediaStreamCreationClient> client = prpQueryClient;
+    ASSERT(client);
+
+    UNUSED_PARAM(audioConstraints);
+    UNUSED_PARAM(videoConstraints);
+
+    Vector<RefPtr<RealtimeMediaSource>> audioSources;
+    Vector<RefPtr<RealtimeMediaSource>> videoSources;
+
+    if (audioConstraints) {
+        // TODO: verify constraints according to registered
+        // sources. For now, unconditionally pick the first source, see bug #123345.
+        RefPtr<RealtimeMediaSource> audioSource = firstSource(RealtimeMediaSource::Audio);
+        if (audioSource) {
+            audioSource->reset();
+            audioSource->setReadyState(RealtimeMediaSource::Live);
+            audioSources.append(audioSource.release());
+        }
+    }
+
+    if (videoConstraints) {
+        // TODO: verify constraints according to registered
+        // sources. For now, unconditionally pick the first source, see bug #123345.
+        RefPtr<RealtimeMediaSource> videoSource = firstSource(RealtimeMediaSource::Video);
+        if (videoSource) {
+            videoSource->reset();
+            videoSource->setReadyState(RealtimeMediaSource::Live);
+            videoSources.append(videoSource.release());
+        }
+    }
+
+    client->didCreateStream(MediaStreamPrivate::create(audioSources, videoSources));
+}
+
+bool RealtimeMediaSourceCenterOwr::getMediaStreamTrackSources(PassRefPtr<MediaStreamTrackSourcesRequestClient>)
+{
+    notImplemented();
+    return false;
+}
+
+void RealtimeMediaSourceCenterOwr::mediaSourcesAvailable(GList* sources)
+{
+    for (auto item = sources; item; item = item->next) {
+        OwrMediaSource* source = OWR_MEDIA_SOURCE(item->data);
+
+        GUniqueOutPtr<gchar> name;
+        OwrMediaType mediaType;
+        g_object_get(source, "media-type", &mediaType, "name", &name.outPtr(), NULL);
+        String sourceName(name.get());
+        String id(createCanonicalUUIDString());
+
+        RealtimeMediaSource::Type sourceType;
+        if (mediaType & OWR_MEDIA_TYPE_AUDIO)
+            sourceType = RealtimeMediaSource::Audio;
+        else if (mediaType & OWR_MEDIA_TYPE_VIDEO)
+            sourceType = RealtimeMediaSource::Video;
+        else
+            ASSERT_NOT_REACHED();
+
+        RefPtr<RealtimeMediaSourceOwr> mediaSource = adoptRef(new RealtimeMediaSourceOwr(source, id, sourceType, sourceName));
+
+        RealtimeMediaSourceOwrMap::iterator sourceIterator = m_sourceMap.find(id);
+        if (sourceIterator == m_sourceMap.end())
+            m_sourceMap.add(id, mediaSource);
+
+    }
+
+    // TODO: Make sure contraints are actually validated by checking source types.
+    m_client->constraintsValidated();
+}
+
+PassRefPtr<RealtimeMediaSource> RealtimeMediaSourceCenterOwr::firstSource(RealtimeMediaSource::Type type)
+{
+    for (auto iter = m_sourceMap.begin(); iter != m_sourceMap.end(); ++iter) {
+        RefPtr<RealtimeMediaSource> source = iter->value;
+        if (source->type() == type)
+            return source;
+    }
+
+    return nullptr;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM) && USE(OPENWEBRTC)
@@ -1,6 +1,8 @@
 /*
  * Copyright (C) 2011 Ericsson AB. All rights reserved.
  * Copyright (C) 2012 Google Inc. All rights reserved.
+ * Copyright (C) 2015 Igalia S.L. All rights reserved.
+ * Copyright (C) 2015 Metrological. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef MediaStreamCenterGStreamer_h
-#define MediaStreamCenterGStreamer_h
+#ifndef RealtimeMediaSourceCenterOwr_h
+#define RealtimeMediaSourceCenterOwr_h
 
-#if ENABLE(MEDIA_STREAM)
+#if ENABLE(MEDIA_STREAM) && USE(OPENWEBRTC)
 
 #include "RealtimeMediaSourceCenter.h"
 
+#include "RealtimeMediaSourceOwr.h"
 #include <wtf/PassRefPtr.h>
-#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -45,18 +47,25 @@ class MediaStreamPrivate;
 class RealtimeMediaSource;
 class MediaStreamSourcesQueryClient;
 
-class MediaStreamCenterGStreamer : public RealtimeMediaSourceCenter {
+class RealtimeMediaSourceCenterOwr final : public RealtimeMediaSourceCenter {
 public:
-    MediaStreamCenterGStreamer();
-    ~MediaStreamCenterGStreamer();
+    RealtimeMediaSourceCenterOwr();
+    ~RealtimeMediaSourceCenterOwr();
 
     virtual void validateRequestConstraints(PassRefPtr<MediaStreamCreationClient>, PassRefPtr<MediaConstraints> audioConstraints, PassRefPtr<MediaConstraints> videoConstraints);
     virtual void createMediaStream(PassRefPtr<MediaStreamCreationClient>, PassRefPtr<MediaConstraints> audioConstraints, PassRefPtr<MediaConstraints> videoConstraints);
     virtual bool getMediaStreamTrackSources(PassRefPtr<MediaStreamTrackSourcesRequestClient>) override;
+
+    void mediaSourcesAvailable(GList* sources);
+
+private:
+    PassRefPtr<RealtimeMediaSource> firstSource(RealtimeMediaSource::Type);
+    RealtimeMediaSourceOwrMap m_sourceMap;
+    RefPtr<MediaStreamCreationClient> m_client;
 };
 
 } // namespace WebCore
 
-#endif // ENABLE(MEDIA_STREAM)
+#endif // ENABLE(MEDIA_STREAM) && USE(OPENWEBRTC)
 
-#endif // MediaStreamCenterGStreamer_h
+#endif // RealtimeMediaSourceCenterOwr_h
diff --git a/Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h b/Source/WebCore/platform/mediastream/openwebrtc/RealtimeMediaSourceOwr.h
new file mode 100644 (file)
index 0000000..bd74d5c
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2015 Igalia S.L
+ * Copyright (C) 2015 Metrological
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. 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.
+ *
+ * 3. Neither the name of the copyright holder 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
+ * HOLDER 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 RealtimeMediaSourceOwr_h
+#define RealtimeMediaSourceOwr_h
+
+#if ENABLE(MEDIA_STREAM) && USE(OPENWEBRTC)
+
+#include "GRefPtrGStreamer.h"
+#include "RealtimeMediaSource.h"
+#include <owr/owr_media_source.h>
+#include <wtf/HashMap.h>
+#include <wtf/RefPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+class RealtimeMediaSourceCapabilities;
+
+class RealtimeMediaSourceOwr final : public RealtimeMediaSource {
+public:
+RealtimeMediaSourceOwr(OwrMediaSource* mediaSource, const String& id, RealtimeMediaSource::Type type, const String& name)
+    : RealtimeMediaSource(id, type, name)
+    , m_mediaSource(mediaSource)
+    {
+    }
+
+    virtual ~RealtimeMediaSourceOwr() { }
+
+    virtual RefPtr<RealtimeMediaSourceCapabilities> capabilities() const { return m_capabilities; }
+    virtual const RealtimeMediaSourceStates& states() { return m_currentStates; }
+
+    OwrMediaSource* mediaSource() const { return m_mediaSource; }
+
+private:
+    RefPtr<RealtimeMediaSourceCapabilities> m_capabilities;
+    RealtimeMediaSourceStates m_currentStates;
+    OwrMediaSource* m_mediaSource;
+};
+
+typedef HashMap<String, RefPtr<RealtimeMediaSourceOwr>> RealtimeMediaSourceOwrMap;
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM) && USE(OPENWEBRTC)
+
+#endif // RealtimeMediaSourceOwr_h