Diff
Modified: trunk/Source/WebCore/ChangeLog (191947 => 191948)
--- trunk/Source/WebCore/ChangeLog 2015-11-03 10:40:06 UTC (rev 191947)
+++ trunk/Source/WebCore/ChangeLog 2015-11-03 10:43:52 UTC (rev 191948)
@@ -1,5 +1,44 @@
2015-11-03 Carlos Garcia Campos <cgar...@igalia.com>
+ [GStreamer] Use GstBus sync message handler and schedule tasks to the main thread with RunLoop::dispatch
+ https://bugs.webkit.org/show_bug.cgi?id=150800
+
+ Reviewed by Philippe Normand.
+
+ This way we would avoid all the GScource + polling mechanism that
+ GST uses internally to handle messages asynchronously in the main thread.
+
+ * platform/graphics/gstreamer/GRefPtrGStreamer.cpp:
+ (WTF::adoptGRef):
+ (WTF::refGPtr<GstMessage>):
+ (WTF::derefGPtr<GstMessage>):
+ * platform/graphics/gstreamer/GRefPtrGStreamer.h:
+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
+ (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer):
+ Initialize the WeakPtr factory.
+ (WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer):
+ reset the GstBus sync handler.
+ (WebCore::MediaPlayerPrivateGStreamer::handleMessage): Make it void.
+ (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Add a
+ GstBus sync message handler and schedule the messages to the main
+ thread with RunLoop::main().dispatch().
+ (WebCore::mediaPlayerPrivateMessageCallback): Deleted.
+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
+ (WebCore::MediaPlayerPrivateGStreamer::createWeakPtr): Create a WeakPtr.
+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp:
+ (WebCore::MediaPlayerPrivateGStreamerBase::handleSyncMessage):
+ Handle the need context message that needs to be handled in the
+ caller thread.
+ (WebCore::mediaPlayerPrivateNeedContextMessageCallback): Deleted.
+ (WebCore::MediaPlayerPrivateGStreamerBase::~MediaPlayerPrivateGStreamerBase):
+ (WebCore::MediaPlayerPrivateGStreamerBase::setPipeline): Do not
+ connect to sync-message signal, handleSyncMessage() will be called
+ to handled messages synchronously.
+ (WebCore::MediaPlayerPrivateGStreamerBase::handleNeedContextMessage): Deleted.
+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h:
+
+2015-11-03 Carlos Garcia Campos <cgar...@igalia.com>
+
[GStreamer] Cleanup the iradio properties
https://bugs.webkit.org/show_bug.cgi?id=148522
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp (191947 => 191948)
--- trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp 2015-11-03 10:40:06 UTC (rev 191947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp 2015-11-03 10:43:52 UTC (rev 191948)
@@ -259,6 +259,25 @@
gst_toc_unref(ptr);
}
+template<> GRefPtr<GstMessage> adoptGRef(GstMessage* ptr)
+{
+ return GRefPtr<GstMessage>(ptr, GRefPtrAdopt);
+}
+
+template<> GstMessage* refGPtr<GstMessage>(GstMessage* ptr)
+{
+ if (ptr)
+ return gst_message_ref(ptr);
+
+ return ptr;
+}
+
+template<> void derefGPtr<GstMessage>(GstMessage* ptr)
+{
+ if (ptr)
+ gst_message_unref(ptr);
+}
+
template <> GRefPtr<WebKitVideoSink> adoptGRef(WebKitVideoSink* ptr)
{
ASSERT(!ptr || !g_object_is_floating(G_OBJECT(ptr)));
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h (191947 => 191948)
--- trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h 2015-11-03 10:40:06 UTC (rev 191947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h 2015-11-03 10:43:52 UTC (rev 191948)
@@ -35,6 +35,7 @@
typedef struct _GstTagList GstTagList;
typedef struct _GstEvent GstEvent;
typedef struct _GstToc GstToc;
+typedef struct _GstMessage GstMessage;
typedef struct _WebKitVideoSink WebKitVideoSink;
typedef struct _WebKitWebSrc WebKitWebSrc;
@@ -88,6 +89,10 @@
template<> GstToc* refGPtr<GstToc>(GstToc* ptr);
template<> void derefGPtr<GstToc>(GstToc* ptr);
+template<> GRefPtr<GstMessage> adoptGRef(GstMessage*);
+template<> GstMessage* refGPtr<GstMessage>(GstMessage*);
+template<> void derefGPtr<GstMessage>(GstMessage*);
+
template<> GRefPtr<WebKitVideoSink> adoptGRef(WebKitVideoSink* ptr);
template<> WebKitVideoSink* refGPtr<WebKitVideoSink>(WebKitVideoSink* ptr);
template<> void derefGPtr<WebKitVideoSink>(WebKitVideoSink* ptr);
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp (191947 => 191948)
--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp 2015-11-03 10:40:06 UTC (rev 191947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp 2015-11-03 10:43:52 UTC (rev 191948)
@@ -41,6 +41,7 @@
#include <limits>
#include <wtf/HexNumber.h>
#include <wtf/MediaTime.h>
+#include <wtf/RunLoop.h>
#include <wtf/glib/GUniquePtr.h>
#include <wtf/text/CString.h>
@@ -80,11 +81,6 @@
namespace WebCore {
-static gboolean mediaPlayerPrivateMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamer* player)
-{
- return player->handleMessage(message);
-}
-
static void mediaPlayerPrivateSourceChangedCallback(GObject*, GParamSpec*, MediaPlayerPrivateGStreamer* player)
{
player->sourceChanged();
@@ -174,6 +170,7 @@
MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
: MediaPlayerPrivateGStreamerBase(player)
+ , m_weakPtrFactory(this)
, m_source(0)
, m_seekTime(0)
, m_changingRate(false)
@@ -247,8 +244,7 @@
if (m_pipeline) {
GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
ASSERT(bus);
- g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast<gpointer>(mediaPlayerPrivateMessageCallback), this);
- gst_bus_remove_signal_watch(bus.get());
+ gst_bus_set_sync_handler(bus.get(), nullptr, nullptr, nullptr);
g_signal_handlers_disconnect_by_func(m_pipeline.get(), reinterpret_cast<gpointer>(mediaPlayerPrivateSourceChangedCallback), this);
g_signal_handlers_disconnect_by_func(m_pipeline.get(), reinterpret_cast<gpointer>(mediaPlayerPrivateVideoChangedCallback), this);
@@ -905,7 +901,7 @@
return timeRanges;
}
-gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
+void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
{
GUniqueOutPtr<GError> err;
GUniqueOutPtr<gchar> debug;
@@ -924,7 +920,7 @@
// notify of the new location(s) of the media.
if (!g_strcmp0(messageTypeName, "redirect")) {
mediaLocationChanged(message);
- return TRUE;
+ return;
}
}
@@ -1065,7 +1061,7 @@
GST_MESSAGE_TYPE_NAME(message));
break;
}
- return TRUE;
+ return;
}
void MediaPlayerPrivateGStreamer::processBufferingStats(GstMessage* message)
@@ -1938,9 +1934,25 @@
setStreamVolumeElement(GST_STREAM_VOLUME(m_pipeline.get()));
GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
- gst_bus_add_signal_watch(bus.get());
- g_signal_connect(bus.get(), "message", G_CALLBACK(mediaPlayerPrivateMessageCallback), this);
+ gst_bus_set_sync_handler(bus.get(), [](GstBus*, GstMessage* message, gpointer userData) {
+ auto& player = *static_cast<MediaPlayerPrivateGStreamer*>(userData);
+ if (!player.handleSyncMessage(message)) {
+ if (isMainThread())
+ player.handleMessage(message);
+ else {
+ GRefPtr<GstMessage> protectMessage(message);
+ auto weakThis = player.createWeakPtr();
+ RunLoop::main().dispatch([weakThis, protectMessage] {
+ if (weakThis)
+ weakThis->handleMessage(protectMessage.get());
+ });
+ }
+ }
+ gst_message_unref(message);
+ return GST_BUS_DROP;
+ }, this, nullptr);
+
g_object_set(m_pipeline.get(), "mute", m_player->muted(), nullptr);
g_signal_connect(m_pipeline.get(), "notify::source", G_CALLBACK(mediaPlayerPrivateSourceChangedCallback), this);
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h (191947 => 191948)
--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h 2015-11-03 10:40:06 UTC (rev 191947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h 2015-11-03 10:43:52 UTC (rev 191948)
@@ -33,6 +33,7 @@
#include <gst/gst.h>
#include <gst/pbutils/install-plugins.h>
#include <wtf/Forward.h>
+#include <wtf/WeakPtr.h>
#include <wtf/glib/GThreadSafeMainLoopSource.h>
#if ENABLE(VIDEO_TRACK) && USE(GSTREAMER_MPEGTS)
@@ -67,7 +68,7 @@
~MediaPlayerPrivateGStreamer();
static void registerMediaEngine(MediaEngineRegistrar);
- gboolean handleMessage(GstMessage*);
+ void handleMessage(GstMessage*);
void handlePluginInstallerResult(GstInstallPluginsReturn);
bool hasVideo() const override { return m_hasVideo; }
@@ -147,6 +148,8 @@
static bool isAvailable();
+ WeakPtr<MediaPlayerPrivateGStreamer> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
+
GstElement* createAudioSink() override;
float playbackPosition() const;
@@ -172,7 +175,6 @@
bool doSeek(gint64 position, float rate, GstSeekFlags seekType);
void updatePlaybackRate();
-
String engineDescription() const override { return "GStreamer"; }
bool isLiveStream() const override { return m_isStreaming; }
bool didPassCORSAccessCheck() const override;
@@ -186,7 +188,8 @@
MediaTime totalFrameDelay() override { return MediaTime::zeroTime(); }
#endif
-private:
+ WeakPtrFactory<MediaPlayerPrivateGStreamer> m_weakPtrFactory;
+
GRefPtr<GstElement> m_source;
#if ENABLE(VIDEO_TRACK)
GRefPtr<GstElement> m_textAppSink;
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp (191947 => 191948)
--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp 2015-11-03 10:40:06 UTC (rev 191947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp 2015-11-03 10:43:52 UTC (rev 191948)
@@ -128,11 +128,6 @@
}
#endif
-static void mediaPlayerPrivateNeedContextMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamerBase* player)
-{
- player->handleNeedContextMessage(message);
-}
-
MediaPlayerPrivateGStreamerBase::MediaPlayerPrivateGStreamerBase(MediaPlayer* player)
: m_player(player)
, m_fpsSink(0)
@@ -179,8 +174,6 @@
if (m_pipeline) {
GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
ASSERT(bus);
- g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast<gpointer>(mediaPlayerPrivateNeedContextMessageCallback), this);
- gst_bus_disable_sync_message_emission(bus.get());
m_pipeline.clear();
}
@@ -193,26 +186,25 @@
void MediaPlayerPrivateGStreamerBase::setPipeline(GstElement* pipeline)
{
m_pipeline = pipeline;
-
- GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
- gst_bus_enable_sync_message_emission(bus.get());
- g_signal_connect(bus.get(), "sync-message::need-context", G_CALLBACK(mediaPlayerPrivateNeedContextMessageCallback), this);
}
-void MediaPlayerPrivateGStreamerBase::handleNeedContextMessage(GstMessage* message)
+bool MediaPlayerPrivateGStreamerBase::handleSyncMessage(GstMessage* message)
{
#if USE(GSTREAMER_GL)
+ if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_NEED_CONTEXT)
+ return false;
+
const gchar* contextType;
gst_message_parse_context_type(message, &contextType);
if (!ensureGstGLContext())
- return;
+ return false;
if (!g_strcmp0(contextType, GST_GL_DISPLAY_CONTEXT_TYPE)) {
GstContext* displayContext = gst_context_new(GST_GL_DISPLAY_CONTEXT_TYPE, TRUE);
gst_context_set_gl_display(displayContext, m_glDisplay.get());
gst_element_set_context(GST_ELEMENT(message->src), displayContext);
- return;
+ return true;
}
if (!g_strcmp0(contextType, "gst.gl.app_context")) {
@@ -220,11 +212,13 @@
GstStructure* structure = gst_context_writable_structure(appContext);
gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_glContext.get(), nullptr);
gst_element_set_context(GST_ELEMENT(message->src), appContext);
- return;
+ return true;
}
#else
UNUSED_PARAM(message);
#endif // USE(GSTREAMER_GL)
+
+ return false;
}
#if USE(GSTREAMER_GL)
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h (191947 => 191948)
--- trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h 2015-11-03 10:40:06 UTC (rev 191947)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h 2015-11-03 10:43:52 UTC (rev 191948)
@@ -66,7 +66,6 @@
#if USE(GSTREAMER_GL)
bool ensureGstGLContext();
#endif
- void handleNeedContextMessage(GstMessage*);
bool supportsMuting() const { return true; }
void setMuted(bool);
@@ -121,6 +120,8 @@
void setPipeline(GstElement*);
+ virtual bool handleSyncMessage(GstMessage*);
+
MediaPlayer* m_player;
GRefPtr<GstElement> m_pipeline;
GRefPtr<GstStreamVolume> m_volumeElement;