Skip to content

Commit 1485471

Browse files
philncadubentzen
authored andcommitted
[GStreamer][WebRTC] Apply platform-specific quirks for incoming tracks
https://bugs.webkit.org/show_bug.cgi?id=276769 Reviewed by Xabier Rodriguez-Calvar. On platforms where quirks are required, keep hardware-accelerated parsers out of the WebRTC pipeline. They are instead used from the playback pipeline. The LibWebRTC backend had support for this already, this patch brings the same feature to the GstWebRTC backend. * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp: (WebCore::gstGetAutoplugSelectResult): * Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h: * Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp: (WebCore::GStreamerIncomingTrackProcessor::createParser): * Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp: (WebCore::GStreamerWebRTCVideoDecoder::getGstAutoplugSelectResult): Deleted. Canonical link: https://commits.webkit.org/281292@main
1 parent 7256789 commit 1485471

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,18 @@ bool gstObjectHasProperty(GstPad* pad, const char* name)
10051005
return gstObjectHasProperty(GST_OBJECT_CAST(pad), name);
10061006
}
10071007

1008+
std::optional<unsigned> gstGetAutoplugSelectResult(ASCIILiteral nick)
1009+
{
1010+
static auto enumClass = static_cast<GEnumClass*>(g_type_class_ref(g_type_from_name("GstAutoplugSelectResult")));
1011+
RELEASE_ASSERT(enumClass);
1012+
auto enumValue = g_enum_get_value_by_nick(enumClass, nick.characters());
1013+
if (!enumValue)
1014+
return std::nullopt;
1015+
return enumValue->value;
1016+
}
1017+
1018+
#undef GST_CAT_DEFAULT
1019+
10081020
} // namespace WebCore
10091021

10101022
#if !GST_CHECK_VERSION(1, 20, 0)

Source/WebCore/platform/graphics/gstreamer/GStreamerCommon.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ void configureVideoRTPDepayloader(GstElement*);
409409
bool gstObjectHasProperty(GstElement*, const char* name);
410410
bool gstObjectHasProperty(GstPad*, const char* name);
411411

412+
std::optional<unsigned> gstGetAutoplugSelectResult(ASCIILiteral);
413+
412414
void registerActivePipeline(const GRefPtr<GstElement>&);
413415
void unregisterPipeline(const GRefPtr<GstElement>&);
414416

Source/WebCore/platform/mediastream/gstreamer/GStreamerIncomingTrackProcessor.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#if USE(GSTREAMER_WEBRTC)
2323

2424
#include "GStreamerCommon.h"
25+
#include "GStreamerQuirks.h"
2526
#include "GStreamerRegistryScanner.h"
2627

2728
GST_DEBUG_CATEGORY(webkit_webrtc_incoming_track_processor_debug);
@@ -244,6 +245,22 @@ GRefPtr<GstElement> GStreamerIncomingTrackProcessor::createParser()
244245
configureVideoRTPDepayloader(element);
245246
}), nullptr);
246247

248+
auto& quirksManager = GStreamerQuirksManager::singleton();
249+
if (quirksManager.isEnabled()) {
250+
// Prevent auto-plugging of hardware-accelerated elements. Those will be used in the playback pipeline.
251+
g_signal_connect(parsebin.get(), "autoplug-select", G_CALLBACK(+[](GstElement*, GstPad*, GstCaps*, GstElementFactory* factory, gpointer) -> unsigned {
252+
static auto skipAutoPlug = gstGetAutoplugSelectResult("skip"_s);
253+
static auto tryAutoPlug = gstGetAutoplugSelectResult("try"_s);
254+
RELEASE_ASSERT(skipAutoPlug);
255+
RELEASE_ASSERT(tryAutoPlug);
256+
auto& quirksManager = GStreamerQuirksManager::singleton();
257+
auto isHardwareAccelerated = quirksManager.isHardwareAccelerated(factory).value_or(false);
258+
if (isHardwareAccelerated)
259+
return *skipAutoPlug;
260+
return *tryAutoPlug;
261+
}), nullptr);
262+
}
263+
247264
g_signal_connect_swapped(parsebin.get(), "pad-added", G_CALLBACK(+[](GStreamerIncomingTrackProcessor* self, GstPad* pad) {
248265
auto queue = adoptGRef(gst_bin_get_by_name(GST_BIN_CAST(self->m_bin.get()), "queue"));
249266
auto sinkPad = adoptGRef(gst_element_get_static_pad(queue.get(), "sink"));

Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
8383
m_needsKeyframe = true;
8484
}
8585

86-
static unsigned getGstAutoplugSelectResult(const char* nick)
87-
{
88-
static GEnumClass* enumClass = static_cast<GEnumClass*>(g_type_class_ref(g_type_from_name("GstAutoplugSelectResult")));
89-
ASSERT(enumClass);
90-
GEnumValue* ev = g_enum_get_value_by_nick(enumClass, nick);
91-
if (!ev)
92-
return 0;
93-
return ev->value;
94-
}
95-
9686
bool Configure(const webrtc::VideoDecoder::Settings& codecSettings) override
9787
{
9888
m_src = makeElement("appsrc");
@@ -112,12 +102,17 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
112102

113103
auto& quirksManager = GStreamerQuirksManager::singleton();
114104
if (quirksManager.isEnabled()) {
105+
// Prevent auto-plugging of hardware-accelerated elements. Those will be used in the playback pipeline.
115106
g_signal_connect(decoder, "autoplug-select", G_CALLBACK(+[](GstElement*, GstPad*, GstCaps*, GstElementFactory* factory, gpointer) -> unsigned {
107+
static auto skipAutoPlug = gstGetAutoplugSelectResult("skip"_s);
108+
static auto tryAutoPlug = gstGetAutoplugSelectResult("try"_s);
109+
RELEASE_ASSERT(skipAutoPlug);
110+
RELEASE_ASSERT(tryAutoPlug);
116111
auto& quirksManager = GStreamerQuirksManager::singleton();
117112
auto isHardwareAccelerated = quirksManager.isHardwareAccelerated(factory).value_or(false);
118113
if (isHardwareAccelerated)
119-
return getGstAutoplugSelectResult("skip");
120-
return getGstAutoplugSelectResult("try");
114+
return *skipAutoPlug;
115+
return *tryAutoPlug;
121116
}), nullptr);
122117
}
123118

0 commit comments

Comments
 (0)