Changeset 191948 in webkit
- Timestamp:
- Nov 3, 2015 2:43:52 AM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r191947 r191948 1 2015-11-03 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 [GStreamer] Use GstBus sync message handler and schedule tasks to the main thread with RunLoop::dispatch 4 https://bugs.webkit.org/show_bug.cgi?id=150800 5 6 Reviewed by Philippe Normand. 7 8 This way we would avoid all the GScource + polling mechanism that 9 GST uses internally to handle messages asynchronously in the main thread. 10 11 * platform/graphics/gstreamer/GRefPtrGStreamer.cpp: 12 (WTF::adoptGRef): 13 (WTF::refGPtr<GstMessage>): 14 (WTF::derefGPtr<GstMessage>): 15 * platform/graphics/gstreamer/GRefPtrGStreamer.h: 16 * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: 17 (WebCore::MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer): 18 Initialize the WeakPtr factory. 19 (WebCore::MediaPlayerPrivateGStreamer::~MediaPlayerPrivateGStreamer): 20 reset the GstBus sync handler. 21 (WebCore::MediaPlayerPrivateGStreamer::handleMessage): Make it void. 22 (WebCore::MediaPlayerPrivateGStreamer::createGSTPlayBin): Add a 23 GstBus sync message handler and schedule the messages to the main 24 thread with RunLoop::main().dispatch(). 25 (WebCore::mediaPlayerPrivateMessageCallback): Deleted. 26 * platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: 27 (WebCore::MediaPlayerPrivateGStreamer::createWeakPtr): Create a WeakPtr. 28 * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: 29 (WebCore::MediaPlayerPrivateGStreamerBase::handleSyncMessage): 30 Handle the need context message that needs to be handled in the 31 caller thread. 32 (WebCore::mediaPlayerPrivateNeedContextMessageCallback): Deleted. 33 (WebCore::MediaPlayerPrivateGStreamerBase::~MediaPlayerPrivateGStreamerBase): 34 (WebCore::MediaPlayerPrivateGStreamerBase::setPipeline): Do not 35 connect to sync-message signal, handleSyncMessage() will be called 36 to handled messages synchronously. 37 (WebCore::MediaPlayerPrivateGStreamerBase::handleNeedContextMessage): Deleted. 38 * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: 39 1 40 2015-11-03 Carlos Garcia Campos <cgarcia@igalia.com> 2 41 -
trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp
r190562 r191948 260 260 } 261 261 262 template<> GRefPtr<GstMessage> adoptGRef(GstMessage* ptr) 263 { 264 return GRefPtr<GstMessage>(ptr, GRefPtrAdopt); 265 } 266 267 template<> GstMessage* refGPtr<GstMessage>(GstMessage* ptr) 268 { 269 if (ptr) 270 return gst_message_ref(ptr); 271 272 return ptr; 273 } 274 275 template<> void derefGPtr<GstMessage>(GstMessage* ptr) 276 { 277 if (ptr) 278 gst_message_unref(ptr); 279 } 280 262 281 template <> GRefPtr<WebKitVideoSink> adoptGRef(WebKitVideoSink* ptr) 263 282 { -
trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h
r190562 r191948 36 36 typedef struct _GstEvent GstEvent; 37 37 typedef struct _GstToc GstToc; 38 typedef struct _GstMessage GstMessage; 38 39 typedef struct _WebKitVideoSink WebKitVideoSink; 39 40 typedef struct _WebKitWebSrc WebKitWebSrc; … … 89 90 template<> void derefGPtr<GstToc>(GstToc* ptr); 90 91 92 template<> GRefPtr<GstMessage> adoptGRef(GstMessage*); 93 template<> GstMessage* refGPtr<GstMessage>(GstMessage*); 94 template<> void derefGPtr<GstMessage>(GstMessage*); 95 91 96 template<> GRefPtr<WebKitVideoSink> adoptGRef(WebKitVideoSink* ptr); 92 97 template<> WebKitVideoSink* refGPtr<WebKitVideoSink>(WebKitVideoSink* ptr); -
trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp
r190852 r191948 42 42 #include <wtf/HexNumber.h> 43 43 #include <wtf/MediaTime.h> 44 #include <wtf/RunLoop.h> 44 45 #include <wtf/glib/GUniquePtr.h> 45 46 #include <wtf/text/CString.h> … … 81 82 namespace WebCore { 82 83 83 static gboolean mediaPlayerPrivateMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamer* player)84 {85 return player->handleMessage(message);86 }87 88 84 static void mediaPlayerPrivateSourceChangedCallback(GObject*, GParamSpec*, MediaPlayerPrivateGStreamer* player) 89 85 { … … 175 171 MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player) 176 172 : MediaPlayerPrivateGStreamerBase(player) 173 , m_weakPtrFactory(this) 177 174 , m_source(0) 178 175 , m_seekTime(0) … … 248 245 GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get()))); 249 246 ASSERT(bus); 250 g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast<gpointer>(mediaPlayerPrivateMessageCallback), this); 251 gst_bus_remove_signal_watch(bus.get()); 247 gst_bus_set_sync_handler(bus.get(), nullptr, nullptr, nullptr); 252 248 253 249 g_signal_handlers_disconnect_by_func(m_pipeline.get(), reinterpret_cast<gpointer>(mediaPlayerPrivateSourceChangedCallback), this); … … 906 902 } 907 903 908 gbooleanMediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)904 void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message) 909 905 { 910 906 GUniqueOutPtr<GError> err; … … 925 921 if (!g_strcmp0(messageTypeName, "redirect")) { 926 922 mediaLocationChanged(message); 927 return TRUE;923 return; 928 924 } 929 925 } … … 1066 1062 break; 1067 1063 } 1068 return TRUE;1064 return; 1069 1065 } 1070 1066 … … 1939 1935 1940 1936 GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get()))); 1941 gst_bus_add_signal_watch(bus.get()); 1942 g_signal_connect(bus.get(), "message", G_CALLBACK(mediaPlayerPrivateMessageCallback), this); 1937 gst_bus_set_sync_handler(bus.get(), [](GstBus*, GstMessage* message, gpointer userData) { 1938 auto& player = *static_cast<MediaPlayerPrivateGStreamer*>(userData); 1939 1940 if (!player.handleSyncMessage(message)) { 1941 if (isMainThread()) 1942 player.handleMessage(message); 1943 else { 1944 GRefPtr<GstMessage> protectMessage(message); 1945 auto weakThis = player.createWeakPtr(); 1946 RunLoop::main().dispatch([weakThis, protectMessage] { 1947 if (weakThis) 1948 weakThis->handleMessage(protectMessage.get()); 1949 }); 1950 } 1951 } 1952 gst_message_unref(message); 1953 return GST_BUS_DROP; 1954 }, this, nullptr); 1943 1955 1944 1956 g_object_set(m_pipeline.get(), "mute", m_player->muted(), nullptr); -
trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h
r187338 r191948 34 34 #include <gst/pbutils/install-plugins.h> 35 35 #include <wtf/Forward.h> 36 #include <wtf/WeakPtr.h> 36 37 #include <wtf/glib/GThreadSafeMainLoopSource.h> 37 38 … … 68 69 69 70 static void registerMediaEngine(MediaEngineRegistrar); 70 gbooleanhandleMessage(GstMessage*);71 void handleMessage(GstMessage*); 71 72 void handlePluginInstallerResult(GstInstallPluginsReturn); 72 73 … … 148 149 static bool isAvailable(); 149 150 151 WeakPtr<MediaPlayerPrivateGStreamer> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); } 152 150 153 GstElement* createAudioSink() override; 151 154 … … 172 175 bool doSeek(gint64 position, float rate, GstSeekFlags seekType); 173 176 void updatePlaybackRate(); 174 175 177 176 178 String engineDescription() const override { return "GStreamer"; } … … 187 189 #endif 188 190 189 private: 191 WeakPtrFactory<MediaPlayerPrivateGStreamer> m_weakPtrFactory; 192 190 193 GRefPtr<GstElement> m_source; 191 194 #if ENABLE(VIDEO_TRACK) -
trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp
r191549 r191948 129 129 #endif 130 130 131 static void mediaPlayerPrivateNeedContextMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamerBase* player)132 {133 player->handleNeedContextMessage(message);134 }135 136 131 MediaPlayerPrivateGStreamerBase::MediaPlayerPrivateGStreamerBase(MediaPlayer* player) 137 132 : m_player(player) … … 180 175 GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get()))); 181 176 ASSERT(bus); 182 g_signal_handlers_disconnect_by_func(bus.get(), reinterpret_cast<gpointer>(mediaPlayerPrivateNeedContextMessageCallback), this);183 gst_bus_disable_sync_message_emission(bus.get());184 177 m_pipeline.clear(); 185 178 } … … 194 187 { 195 188 m_pipeline = pipeline; 196 197 GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get()))); 198 gst_bus_enable_sync_message_emission(bus.get()); 199 g_signal_connect(bus.get(), "sync-message::need-context", G_CALLBACK(mediaPlayerPrivateNeedContextMessageCallback), this); 200 } 201 202 void MediaPlayerPrivateGStreamerBase::handleNeedContextMessage(GstMessage* message) 203 { 204 #if USE(GSTREAMER_GL) 189 } 190 191 bool MediaPlayerPrivateGStreamerBase::handleSyncMessage(GstMessage* message) 192 { 193 #if USE(GSTREAMER_GL) 194 if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_NEED_CONTEXT) 195 return false; 196 205 197 const gchar* contextType; 206 198 gst_message_parse_context_type(message, &contextType); 207 199 208 200 if (!ensureGstGLContext()) 209 return ;201 return false; 210 202 211 203 if (!g_strcmp0(contextType, GST_GL_DISPLAY_CONTEXT_TYPE)) { … … 213 205 gst_context_set_gl_display(displayContext, m_glDisplay.get()); 214 206 gst_element_set_context(GST_ELEMENT(message->src), displayContext); 215 return ;207 return true; 216 208 } 217 209 … … 221 213 gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_glContext.get(), nullptr); 222 214 gst_element_set_context(GST_ELEMENT(message->src), appContext); 223 return ;215 return true; 224 216 } 225 217 #else 226 218 UNUSED_PARAM(message); 227 219 #endif // USE(GSTREAMER_GL) 220 221 return false; 228 222 } 229 223 -
trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h
r189144 r191948 67 67 bool ensureGstGLContext(); 68 68 #endif 69 void handleNeedContextMessage(GstMessage*);70 69 71 70 bool supportsMuting() const { return true; } … … 122 121 void setPipeline(GstElement*); 123 122 123 virtual bool handleSyncMessage(GstMessage*); 124 124 125 MediaPlayer* m_player; 125 126 GRefPtr<GstElement> m_pipeline;
Note: See TracChangeset
for help on using the changeset viewer.