Changeset 191948 in webkit


Ignore:
Timestamp:
Nov 3, 2015 2:43:52 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

[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:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r191947 r191948  
     12015-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
    1402015-11-03  Carlos Garcia Campos  <cgarcia@igalia.com>
    241
  • trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.cpp

    r190562 r191948  
    260260}
    261261
     262template<> GRefPtr<GstMessage> adoptGRef(GstMessage* ptr)
     263{
     264    return GRefPtr<GstMessage>(ptr, GRefPtrAdopt);
     265}
     266
     267template<> GstMessage* refGPtr<GstMessage>(GstMessage* ptr)
     268{
     269    if (ptr)
     270        return gst_message_ref(ptr);
     271
     272    return ptr;
     273}
     274
     275template<> void derefGPtr<GstMessage>(GstMessage* ptr)
     276{
     277    if (ptr)
     278        gst_message_unref(ptr);
     279}
     280
    262281template <> GRefPtr<WebKitVideoSink> adoptGRef(WebKitVideoSink* ptr)
    263282{
  • trunk/Source/WebCore/platform/graphics/gstreamer/GRefPtrGStreamer.h

    r190562 r191948  
    3636typedef struct _GstEvent GstEvent;
    3737typedef struct _GstToc GstToc;
     38typedef struct _GstMessage GstMessage;
    3839typedef struct _WebKitVideoSink WebKitVideoSink;
    3940typedef struct _WebKitWebSrc WebKitWebSrc;
     
    8990template<> void derefGPtr<GstToc>(GstToc* ptr);
    9091
     92template<> GRefPtr<GstMessage> adoptGRef(GstMessage*);
     93template<> GstMessage* refGPtr<GstMessage>(GstMessage*);
     94template<> void derefGPtr<GstMessage>(GstMessage*);
     95
    9196template<> GRefPtr<WebKitVideoSink> adoptGRef(WebKitVideoSink* ptr);
    9297template<> WebKitVideoSink* refGPtr<WebKitVideoSink>(WebKitVideoSink* ptr);
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp

    r190852 r191948  
    4242#include <wtf/HexNumber.h>
    4343#include <wtf/MediaTime.h>
     44#include <wtf/RunLoop.h>
    4445#include <wtf/glib/GUniquePtr.h>
    4546#include <wtf/text/CString.h>
     
    8182namespace WebCore {
    8283
    83 static gboolean mediaPlayerPrivateMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamer* player)
    84 {
    85     return player->handleMessage(message);
    86 }
    87 
    8884static void mediaPlayerPrivateSourceChangedCallback(GObject*, GParamSpec*, MediaPlayerPrivateGStreamer* player)
    8985{
     
    175171MediaPlayerPrivateGStreamer::MediaPlayerPrivateGStreamer(MediaPlayer* player)
    176172    : MediaPlayerPrivateGStreamerBase(player)
     173    , m_weakPtrFactory(this)
    177174    , m_source(0)
    178175    , m_seekTime(0)
     
    248245        GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
    249246        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);
    252248
    253249        g_signal_handlers_disconnect_by_func(m_pipeline.get(), reinterpret_cast<gpointer>(mediaPlayerPrivateSourceChangedCallback), this);
     
    906902}
    907903
    908 gboolean MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
     904void MediaPlayerPrivateGStreamer::handleMessage(GstMessage* message)
    909905{
    910906    GUniqueOutPtr<GError> err;
     
    925921        if (!g_strcmp0(messageTypeName, "redirect")) {
    926922            mediaLocationChanged(message);
    927             return TRUE;
     923            return;
    928924        }
    929925    }
     
    10661062        break;
    10671063    }
    1068     return TRUE;
     1064    return;
    10691065}
    10701066
     
    19391935
    19401936    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);
    19431955
    19441956    g_object_set(m_pipeline.get(), "mute", m_player->muted(), nullptr);
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h

    r187338 r191948  
    3434#include <gst/pbutils/install-plugins.h>
    3535#include <wtf/Forward.h>
     36#include <wtf/WeakPtr.h>
    3637#include <wtf/glib/GThreadSafeMainLoopSource.h>
    3738
     
    6869
    6970    static void registerMediaEngine(MediaEngineRegistrar);
    70     gboolean handleMessage(GstMessage*);
     71    void handleMessage(GstMessage*);
    7172    void handlePluginInstallerResult(GstInstallPluginsReturn);
    7273
     
    148149    static bool isAvailable();
    149150
     151    WeakPtr<MediaPlayerPrivateGStreamer> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
     152
    150153    GstElement* createAudioSink() override;
    151154
     
    172175    bool doSeek(gint64 position, float rate, GstSeekFlags seekType);
    173176    void updatePlaybackRate();
    174 
    175177
    176178    String engineDescription() const override { return "GStreamer"; }
     
    187189#endif
    188190
    189 private:
     191    WeakPtrFactory<MediaPlayerPrivateGStreamer> m_weakPtrFactory;
     192
    190193    GRefPtr<GstElement> m_source;
    191194#if ENABLE(VIDEO_TRACK)
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp

    r191549 r191948  
    129129#endif
    130130
    131 static void mediaPlayerPrivateNeedContextMessageCallback(GstBus*, GstMessage* message, MediaPlayerPrivateGStreamerBase* player)
    132 {
    133     player->handleNeedContextMessage(message);
    134 }
    135 
    136131MediaPlayerPrivateGStreamerBase::MediaPlayerPrivateGStreamerBase(MediaPlayer* player)
    137132    : m_player(player)
     
    180175        GRefPtr<GstBus> bus = adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(m_pipeline.get())));
    181176        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());
    184177        m_pipeline.clear();
    185178    }
     
    194187{
    195188    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
     191bool MediaPlayerPrivateGStreamerBase::handleSyncMessage(GstMessage* message)
     192{
     193#if USE(GSTREAMER_GL)
     194    if (GST_MESSAGE_TYPE(message) != GST_MESSAGE_NEED_CONTEXT)
     195        return false;
     196
    205197    const gchar* contextType;
    206198    gst_message_parse_context_type(message, &contextType);
    207199
    208200    if (!ensureGstGLContext())
    209         return;
     201        return false;
    210202
    211203    if (!g_strcmp0(contextType, GST_GL_DISPLAY_CONTEXT_TYPE)) {
     
    213205        gst_context_set_gl_display(displayContext, m_glDisplay.get());
    214206        gst_element_set_context(GST_ELEMENT(message->src), displayContext);
    215         return;
     207        return true;
    216208    }
    217209
     
    221213        gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_glContext.get(), nullptr);
    222214        gst_element_set_context(GST_ELEMENT(message->src), appContext);
    223         return;
     215        return true;
    224216    }
    225217#else
    226218    UNUSED_PARAM(message);
    227219#endif // USE(GSTREAMER_GL)
     220
     221    return false;
    228222}
    229223
  • trunk/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h

    r189144 r191948  
    6767    bool ensureGstGLContext();
    6868#endif
    69     void handleNeedContextMessage(GstMessage*);
    7069
    7170    bool supportsMuting() const { return true; }
     
    122121    void setPipeline(GstElement*);
    123122
     123    virtual bool handleSyncMessage(GstMessage*);
     124
    124125    MediaPlayer* m_player;
    125126    GRefPtr<GstElement> m_pipeline;
Note: See TracChangeset for help on using the changeset viewer.