[GStreamer] HRTFDatabaseLoader conflicts with AudioFileReader
authorphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Apr 2012 17:14:12 +0000 (17:14 +0000)
committerphiln@webkit.org <philn@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 16 Apr 2012 17:14:12 +0000 (17:14 +0000)
https://bugs.webkit.org/show_bug.cgi?id=78095

Reviewed by Martin Robinson.

Moved the GStreamer initialization logic to a new
GStreamerUtilities module, used by the MediaPlayer and the
AudioContext. I also removed the static variables as
gst_init_check already handles cases where it's called multiple
times.

* GNUmakefile.list.am:
* Modules/webaudio/AudioContext.cpp:
(WebCore::AudioContext::constructCommon):
* platform/audio/gstreamer/AudioDestinationGStreamer.cpp:
(WebCore::AudioDestinationGStreamer::AudioDestinationGStreamer):
* platform/audio/gstreamer/AudioFileReaderGStreamer.cpp:
(WebCore::AudioFileReader::createBus):
* platform/graphics/gstreamer/GRefPtrGStreamer.cpp:
(WTF::adoptGRef):
(WTF):
(WTF::GstElementFactory):
* platform/graphics/gstreamer/GRefPtrGStreamer.h:
(WTF):
* platform/graphics/gstreamer/GStreamerUtilities.cpp: Added.
(WebCore):
(WebCore::initializeGStreamer):
* platform/graphics/gstreamer/GStreamerUtilities.h: Added.
(WebCore):
* platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::doGstInit):

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

12 files changed:
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/webaudio/AudioContext.cpp
Source/WebCore/PlatformEfl.cmake
Source/WebCore/Target.pri
Source/WebCore/platform/audio/gstreamer/AudioDestinationGStreamer.cpp
Source/WebCore/platform/audio/gstreamer/AudioFileReaderGStreamer.cpp
Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp
Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h
Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.h [new file with mode: 0644]
Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp

index 0503aa8..be3c54b 100644 (file)
@@ -1,3 +1,37 @@
+2012-04-11  Philippe Normand  <pnormand@igalia.com>
+
+        [GStreamer] HRTFDatabaseLoader conflicts with AudioFileReader
+        https://bugs.webkit.org/show_bug.cgi?id=78095
+
+        Reviewed by Martin Robinson.
+
+        Moved the GStreamer initialization logic to a new
+        GStreamerUtilities module, used by the MediaPlayer and the
+        AudioContext. I also removed the static variables as
+        gst_init_check already handles cases where it's called multiple
+        times.
+
+        * GNUmakefile.list.am:
+        * Modules/webaudio/AudioContext.cpp:
+        (WebCore::AudioContext::constructCommon):
+        * platform/audio/gstreamer/AudioDestinationGStreamer.cpp:
+        (WebCore::AudioDestinationGStreamer::AudioDestinationGStreamer):
+        * platform/audio/gstreamer/AudioFileReaderGStreamer.cpp:
+        (WebCore::AudioFileReader::createBus):
+        * platform/graphics/gstreamer/GRefPtrGStreamer.cpp:
+        (WTF::adoptGRef):
+        (WTF):
+        (WTF::GstElementFactory):
+        * platform/graphics/gstreamer/GRefPtrGStreamer.h:
+        (WTF):
+        * platform/graphics/gstreamer/GStreamerUtilities.cpp: Added.
+        (WebCore):
+        (WebCore::initializeGStreamer):
+        * platform/graphics/gstreamer/GStreamerUtilities.h: Added.
+        (WebCore):
+        * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+        (WebCore::doGstInit):
+
 2012-04-16  ChangSeok Oh  <shivamidow@gmail.com>
 
         Update GraphicsContext3DOpenGLES.cpp and fix some issues to build with GLES.
index 574bb04..7849e1f 100644 (file)
@@ -4637,12 +4637,8 @@ webcoregtk_sources += \
        Source/WebCore/platform/cairo/WidgetBackingStore.h \
        Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp \
        Source/WebCore/platform/graphics/cairo/GraphicsContextPlatformPrivateCairo.h \
-       Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp \
-       Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h \
        Source/WebCore/platform/graphics/gstreamer/GStreamerGWorld.cpp \
        Source/WebCore/platform/graphics/gstreamer/GStreamerGWorld.h \
-       Source/WebCore/platform/graphics/gstreamer/GStreamerVersioning.cpp \
-       Source/WebCore/platform/graphics/gstreamer/GStreamerVersioning.h \
        Source/WebCore/platform/graphics/gstreamer/ImageGStreamerCairo.cpp \
        Source/WebCore/platform/graphics/gstreamer/ImageGStreamer.h \
        Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp \
@@ -5673,6 +5669,15 @@ dom_binding_idls += \
     $(WebCore)/Modules/webaudio/WaveTable.idl
 endif
 
+if USE_GSTREAMER
+webcore_sources += \
+       Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp \
+       Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h \
+       Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.cpp \
+       Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.h \
+       Source/WebCore/platform/graphics/gstreamer/GStreamerVersioning.cpp \
+       Source/WebCore/platform/graphics/gstreamer/GStreamerVersioning.h
+endif
 
 # ----
 # Web Sockets Support
index a2b63bf..f78905b 100644 (file)
 #include <stdio.h>
 #endif
 
+#if USE(GSTREAMER)
+#include "GStreamerUtilities.h"
+#endif
+
 #include <wtf/ArrayBuffer.h>
 #include <wtf/Atomics.h>
 #include <wtf/MainThread.h>
@@ -178,6 +182,10 @@ AudioContext::AudioContext(Document* document, unsigned numberOfChannels, size_t
 
 void AudioContext::constructCommon()
 {
+#if USE(GSTREAMER)
+    initializeGStreamer();
+#endif
+
     FFTFrame::initialize();
     
     m_listener = AudioListener::create();
index 79a5013..0f3ee3a 100644 (file)
@@ -188,6 +188,7 @@ IF (ENABLE_VIDEO)
   LIST(APPEND WebCore_SOURCES
     platform/graphics/gstreamer/GRefPtrGStreamer.cpp
     platform/graphics/gstreamer/GStreamerGWorld.cpp
+    platform/graphics/gstreamer/GStreamerUtilities.cpp
     platform/graphics/gstreamer/GStreamerVersioning.cpp
     platform/graphics/gstreamer/ImageGStreamerCairo.cpp
     platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
index a4172c6..e567a3d 100644 (file)
@@ -3268,6 +3268,7 @@ contains(DEFINES, ENABLE_VIDEO=1) {
         HEADERS += \
             platform/graphics/gstreamer/GRefPtrGStreamer.h \
             platform/graphics/gstreamer/GStreamerGWorld.h \
+            platform/graphics/gstreamer/GStreamerUtilities.h \
             platform/graphics/gstreamer/GStreamerVersioning.h \
             platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h \
             platform/graphics/gstreamer/VideoSinkGStreamer.h \
@@ -3278,6 +3279,7 @@ contains(DEFINES, ENABLE_VIDEO=1) {
         SOURCES += \
             platform/graphics/gstreamer/GRefPtrGStreamer.cpp \
             platform/graphics/gstreamer/GStreamerGWorld.cpp \
+            platform/graphics/gstreamer/GStreamerUtilities.cpp \
             platform/graphics/gstreamer/GStreamerVersioning.cpp \
             platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp \
             platform/graphics/gstreamer/VideoSinkGStreamer.cpp \
index b606a33..5611bdb 100644 (file)
@@ -57,11 +57,6 @@ AudioDestinationGStreamer::AudioDestinationGStreamer(AudioSourceProvider& provid
     , m_sampleRate(sampleRate)
     , m_isPlaying(false)
 {
-    static bool gstInitialized = false;
-    if (!gstInitialized)
-        gstInitialized = gst_init_check(0, 0, 0);
-    ASSERT_WITH_MESSAGE(gstInitialized, "GStreamer initialization failed");
-
     m_pipeline = gst_pipeline_new("play");
 
     GstElement* webkitAudioSrc = reinterpret_cast<GstElement*>(g_object_new(WEBKIT_TYPE_WEB_AUDIO_SRC,
index a7a5c71..5b92eb7 100644 (file)
@@ -324,13 +324,6 @@ PassOwnPtr<AudioBus> AudioFileReader::createBus(float sampleRate, bool mixToMono
 {
     m_sampleRate = sampleRate;
 
-    static bool gstInitialized = false;
-    if (!gstInitialized)
-        gstInitialized = gst_init_check(0, 0, 0);
-
-    if (!gstInitialized)
-        return nullptr;
-
     m_frontLeftBuffers = gst_buffer_list_new();
     m_frontLeftBuffersIterator = gst_buffer_list_iterate(m_frontLeftBuffers);
     gst_buffer_list_iterator_add_group(m_frontLeftBuffersIterator);
index 5306974..062e3fc 100644 (file)
@@ -140,5 +140,25 @@ template <> void derefGPtr<GstBus>(GstBus* ptr)
         gst_object_unref(ptr);
 }
 
+template <> GRefPtr<GstElementFactory> adoptGRef(GstElementFactory* ptr)
+{
+    ASSERT(!GST_OBJECT_IS_FLOATING(GST_OBJECT(ptr)));
+    return GRefPtr<GstElementFactory>(ptr, GRefPtrAdopt);
+}
+
+template <> GstElementFactory* refGPtr<GstElementFactory>(GstElementFactory* ptr)
+{
+    if (ptr)
+        webkitGstObjectRefSink(GST_OBJECT(ptr));
+
+    return ptr;
+}
+
+template <> void derefGPtr<GstElementFactory>(GstElementFactory* ptr)
+{
+    if (ptr)
+        gst_object_unref(ptr);
+}
+
 }
 #endif // USE(GSTREAMER)
index 940470a..a3dcda8 100644 (file)
@@ -29,6 +29,7 @@ typedef struct _GstPadTemplate GstPadTemplate;
 typedef struct _GstCaps GstCaps;
 typedef struct _GstTask GstTask;
 typedef struct _GstBus GstBus;
+typedef struct _GstElementFactory GstElementFactory;
 
 namespace WTF {
 
@@ -55,6 +56,10 @@ template<> GRefPtr<GstBus> adoptGRef(GstBus* ptr);
 template<> GstBus* refGPtr<GstBus>(GstBus* ptr);
 template<> void derefGPtr<GstBus>(GstBus* ptr);
 
+template<> GRefPtr<GstElementFactory> adoptGRef(GstElementFactory* ptr);
+template<> GstElementFactory* refGPtr<GstElementFactory>(GstElementFactory* ptr);
+template<> void derefGPtr<GstElementFactory>(GstElementFactory* ptr);
+
 }
 
 #endif // USE(GSTREAMER)
diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.cpp b/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.cpp
new file mode 100644 (file)
index 0000000..ac363a7
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ *  Copyright (C) 2012 Igalia S.L
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+#include "config.h"
+#include "GStreamerUtilities.h"
+
+#include <gst/gst.h>
+#include <wtf/gobject/GOwnPtr.h>
+
+#if USE(GSTREAMER)
+
+namespace WebCore {
+
+bool initializeGStreamer()
+{
+    GOwnPtr<GError> error;
+    // FIXME: We should probably pass the arguments from the command line.
+    bool gstInitialized = gst_init_check(0, 0, &error.outPtr());
+    ASSERT_WITH_MESSAGE(gstInitialized, "GStreamer initialization failed: %s", error ? error->message : "unknown error occurred");
+    return gstInitialized;
+}
+
+}
+
+#endif // ENABLE(WEB_AUDIO) && USE(GSTREAMER)
diff --git a/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.h b/Source/WebCore/platform/graphics/gstreamer/GStreamerUtilities.h
new file mode 100644 (file)
index 0000000..b9eb165
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ *  Copyright (C) 2012 Igalia S.L
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+
+namespace WebCore {
+bool initializeGStreamer();
+}
index ea49d0e..d0993c2 100644 (file)
@@ -31,6 +31,7 @@
 #include "Frame.h"
 #include "FrameView.h"
 #include "GStreamerGWorld.h"
+#include "GStreamerUtilities.h"
 #include "GStreamerVersioning.h"
 #include "GraphicsContext.h"
 #include "GraphicsTypes.h"
@@ -175,35 +176,25 @@ void MediaPlayerPrivateGStreamer::registerMediaEngine(MediaEngineRegistrar regis
         registrar(create, getSupportedTypes, supportsType, 0, 0, 0);
 }
 
-static bool gstInitialized = false;
-
-static bool doGstInit()
+bool initializeGStreamerAndRegisterWebKitElements()
 {
-    // FIXME: We should pass the arguments from the command line
-    if (!gstInitialized) {
-        GOwnPtr<GError> error;
-        gstInitialized = gst_init_check(0, 0, &error.outPtr());
-        if (!gstInitialized)
-            LOG_VERBOSE(Media, "Could not initialize GStreamer: %s",
-                        error ? error->message : "unknown error occurred");
-        else
-            gst_element_register(0, "webkitwebsrc", GST_RANK_PRIMARY + 100,
-                                 WEBKIT_TYPE_WEB_SRC);
-    }
-    return gstInitialized;
+    if (!initializeGStreamer())
+        return false;
+
+    GRefPtr<GstElementFactory> srcFactory = gst_element_factory_find("webkitwebsrc");
+    if (!srcFactory)
+        return gst_element_register(0, "webkitwebsrc", GST_RANK_PRIMARY + 100, WEBKIT_TYPE_WEB_SRC);
+
+    return true;
 }
 
 bool MediaPlayerPrivateGStreamer::isAvailable()
 {
-    if (!doGstInit())
+    if (!initializeGStreamerAndRegisterWebKitElements())
         return false;
 
-    GstElementFactory* factory = gst_element_factory_find(gPlaybinName);
-    if (factory) {
-        gst_object_unref(GST_OBJECT(factory));
-        return true;
-    }
-    return false;
+    GRefPtr<GstElementFactory> factory = gst_element_factory_find(gPlaybinName);
+    return factory;
 }
 
 MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
@@ -244,7 +235,7 @@ MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
     , m_videoTimerHandler(0)
     , m_webkitAudioSink(0)
 {
-    if (doGstInit())
+    if (initializeGStreamerAndRegisterWebKitElements())
         createGSTPlayBin();
 }
 
@@ -1504,7 +1495,7 @@ void MediaPlayerPrivateGStreamer::paint(GraphicsContext* context, const IntRect&
 static HashSet<String> mimeTypeCache()
 {
 
-    doGstInit();
+    initializeGStreamerAndRegisterWebKitElements();
 
     DEFINE_STATIC_LOCAL(HashSet<String>, cache, ());
     static bool typeListInitialized = false;