Changeset 235110 in webkit


Ignore:
Timestamp:
Aug 21, 2018 2:07:33 AM (6 years ago)
Author:
Philippe Normand
Message:

[GStreamer][MSE] Generic main thread notification support
https://bugs.webkit.org/show_bug.cgi?id=188647

Patch by Philippe Normand <philn@igalia.com> on 2018-08-21
Reviewed by Xabier Rodriguez-Calvar.

Using GstBus for main thread notifications has the side effect of "leaking" the
application messages to the media player, leading to CPU cycles wasting.

No new tests, existing MSE tests cover this change.

  • platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp:

(webkit_media_src_init):
(webKitMediaSrcFinalize):
(webKitMediaSrcSetMediaPlayerPrivate):

  • platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamerPrivate.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r235109 r235110  
     12018-08-21  Philippe Normand  <philn@igalia.com>
     2
     3        [GStreamer][MSE] Generic main thread notification support
     4        https://bugs.webkit.org/show_bug.cgi?id=188647
     5
     6        Reviewed by Xabier Rodriguez-Calvar.
     7
     8        Using GstBus for main thread notifications has the side effect of "leaking" the
     9        application messages to the media player, leading to CPU cycles wasting.
     10
     11        No new tests, existing MSE tests cover this change.
     12
     13        * platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp:
     14        (webkit_media_src_init):
     15        (webKitMediaSrcFinalize):
     16        (webKitMediaSrcSetMediaPlayerPrivate):
     17        * platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamerPrivate.h:
     18
    1192018-08-21  Philippe Normand  <philn@igalia.com>
    220
  • trunk/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamer.cpp

    r235109 r235110  
    4141#include "WebKitMediaSourceGStreamerPrivate.h"
    4242
    43 #include <gst/app/app.h>
    44 #include <gst/app/gstappsrc.h>
    45 #include <gst/gst.h>
    46 #include <gst/pbutils/missing-plugins.h>
    4743#include <gst/pbutils/pbutils.h>
    4844#include <gst/video/video.h>
    4945#include <wtf/Condition.h>
    5046#include <wtf/MainThread.h>
     47#include <wtf/RefPtr.h>
    5148#include <wtf/text/CString.h>
    5249
     
    8683
    8784static Stream* getStreamByAppsrc(WebKitMediaSrc*, GstElement*);
     85static void seekNeedsDataMainThread(WebKitMediaSrc*);
     86static void notifyReadyForMoreSamplesMainThread(WebKitMediaSrc*, Stream*);
    8887
    8988static void enabledAppsrcNeedData(GstAppSrc* appsrc, guint, gpointer userData)
     
    120119
    121120        switch (appsrcSeekDataNextAction) {
    122         case MediaSourceSeekToTime: {
    123             GstStructure* structure = gst_structure_new_empty("seek-needs-data");
    124             GstMessage* message = gst_message_new_application(GST_OBJECT(appsrc), structure);
    125             gst_bus_post(webKitMediaSrc->priv->bus.get(), message);
    126             GST_TRACE("seek-needs-data message posted to the bus");
    127             break;
    128         }
     121        case MediaSourceSeekToTime:
     122            webKitMediaSrc->priv->notifier->notify(WebKitMediaSrcMainThreadNotification::SeekNeedsData, [webKitMediaSrc] {
     123                seekNeedsDataMainThread(webKitMediaSrc);
     124            });
     125            break;
    129126        case Nothing:
    130127            break;
     
    138135        appsrcStream = getStreamByAppsrc(webKitMediaSrc, GST_ELEMENT(appsrc));
    139136
    140         if (appsrcStream && appsrcStream->type != WebCore::Invalid) {
    141             GstStructure* structure = gst_structure_new("ready-for-more-samples", "appsrc-stream", G_TYPE_POINTER, appsrcStream, nullptr);
    142             GstMessage* message = gst_message_new_application(GST_OBJECT(appsrc), structure);
    143             gst_bus_post(webKitMediaSrc->priv->bus.get(), message);
    144             GST_TRACE("ready-for-more-samples message posted to the bus");
    145         }
     137        if (appsrcStream && appsrcStream->type != WebCore::Invalid)
     138            webKitMediaSrc->priv->notifier->notify(WebKitMediaSrcMainThreadNotification::ReadyForMoreSamples, [webKitMediaSrc, appsrcStream] {
     139                notifyReadyForMoreSamplesMainThread(webKitMediaSrc, appsrcStream);
     140            });
    146141
    147142        GST_OBJECT_UNLOCK(webKitMediaSrc);
     
    265260    source->priv->appsrcSeekDataNextAction = Nothing;
    266261    source->priv->flowCombiner = GUniquePtr<GstFlowCombiner>(gst_flow_combiner_new());
     262    source->priv->notifier = WebCore::MainThreadNotifier<WebKitMediaSrcMainThreadNotification>::create();
    267263
    268264    // No need to reset Stream.appsrcNeedDataFlag because there are no Streams at this point yet.
     
    283279
    284280    priv->seekTime = MediaTime::invalidTime();
     281
     282    source->priv->notifier->invalidate();
    285283
    286284    if (priv->mediaPlayerPrivate)
     
    695693}
    696694
    697 static void applicationMessageCallback(GstBus*, GstMessage* message, WebKitMediaSrc* source)
    698 {
    699     ASSERT(WTF::isMainThread());
    700     ASSERT(GST_MESSAGE_TYPE(message) == GST_MESSAGE_APPLICATION);
    701 
    702     const GstStructure* structure = gst_message_get_structure(message);
    703 
    704     if (gst_structure_has_name(structure, "seek-needs-data")) {
    705         seekNeedsDataMainThread(source);
    706         return;
    707     }
    708 
    709     if (gst_structure_has_name(structure, "ready-for-more-samples")) {
    710         Stream* appsrcStream = nullptr;
    711         gst_structure_get(structure, "appsrc-stream", G_TYPE_POINTER, &appsrcStream, nullptr);
    712         ASSERT(appsrcStream);
    713 
    714         notifyReadyForMoreSamplesMainThread(source, appsrcStream);
    715         return;
    716     }
    717 
    718     ASSERT_NOT_REACHED();
    719 }
    720 
    721695void webKitMediaSrcSetMediaPlayerPrivate(WebKitMediaSrc* source, WebCore::MediaPlayerPrivateGStreamerMSE* mediaPlayerPrivate)
    722696{
    723697    GST_OBJECT_LOCK(source);
    724     if (source->priv->mediaPlayerPrivate && source->priv->mediaPlayerPrivate != mediaPlayerPrivate && source->priv->bus)
    725         g_signal_handlers_disconnect_by_func(source->priv->bus.get(), gpointer(applicationMessageCallback), source);
    726698
    727699    // Set to nullptr on MediaPlayerPrivateGStreamer destruction, never a dangling pointer.
    728700    source->priv->mediaPlayerPrivate = mediaPlayerPrivate;
    729     source->priv->bus = mediaPlayerPrivate ? adoptGRef(gst_pipeline_get_bus(GST_PIPELINE(mediaPlayerPrivate->pipeline()))) : nullptr;
    730     if (source->priv->bus) {
    731         // MediaPlayerPrivateGStreamer has called gst_bus_add_signal_watch() at this point, so we can subscribe.
    732         g_signal_connect(source->priv->bus.get(), "message::application", G_CALLBACK(applicationMessageCallback), source);
    733     }
    734701    GST_OBJECT_UNLOCK(source);
    735702}
  • trunk/Source/WebCore/platform/graphics/gstreamer/mse/WebKitMediaSourceGStreamerPrivate.h

    r235109 r235110  
    2525#include "AudioTrackPrivateGStreamer.h"
    2626#include "GUniquePtrGStreamer.h"
     27#include "MainThreadNotifier.h"
    2728#include "SourceBufferPrivateGStreamer.h"
    2829#include "VideoTrackPrivateGStreamer.h"
     
    3132#include <gst/app/gstappsrc.h>
    3233#include <gst/gst.h>
    33 #include <wtf/Condition.h>
    34 #include <wtf/RefPtr.h>
     34#include <wtf/Forward.h>
    3535#include <wtf/glib/GRefPtr.h>
    3636
     
    9696};
    9797
     98enum WebKitMediaSrcMainThreadNotification {
     99    ReadyForMoreSamples = 1 << 0,
     100    SeekNeedsData = 1 << 1
     101};
     102
    98103struct _WebKitMediaSrcPrivate {
    99104    // Used to coordinate the release of Stream track info.
     
    119124    int appsrcNeedDataCount;
    120125
    121     GRefPtr<GstBus> bus;
    122126    WebCore::MediaPlayerPrivateGStreamerMSE* mediaPlayerPrivate;
    123127
     128    RefPtr<WebCore::MainThreadNotifier<WebKitMediaSrcMainThreadNotification>> notifier;
    124129    GUniquePtr<GstFlowCombiner> flowCombiner;
    125130};
Note: See TracChangeset for help on using the changeset viewer.