Skip to content

Commit 99973c6

Browse files
committed
[GStreamer][LibWebRTC] Add quirks in decoder factory
https://bugs.webkit.org/show_bug.cgi?id=271751 Reviewed by NOBODY (OOPS!). Allow the decoder pipeline to skip auto-plugging of hardware-accelerated decoders and also to disable parsing, both for Broadcom and Realtek quirks. * Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcom.h: * Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.h: * Source/WebCore/platform/gstreamer/GStreamerQuirks.cpp: (WebCore::GStreamerQuirksManager::shouldParseIncomingLibWebRTCBitStream const): * Source/WebCore/platform/gstreamer/GStreamerQuirks.h: (WebCore::GStreamerQuirk::shouldParseIncomingLibWebRTCBitStream const): * Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp: (WebCore::GStreamerWebRTCVideoDecoder::getGstAutoplugSelectResult): (WebCore::H264Decoder::H264Decoder):
1 parent cb45611 commit 99973c6

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed

Source/WebCore/platform/gstreamer/GStreamerQuirkBroadcom.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class GStreamerQuirkBroadcom final : public GStreamerQuirk {
3737
std::optional<GstElementFactoryListType> audioVideoDecoderFactoryListType() const final { return GST_ELEMENT_FACTORY_TYPE_PARSER; }
3838
Vector<String> disallowedWebAudioDecoders() const final { return m_disallowedWebAudioDecoders; }
3939
unsigned getAdditionalPlaybinFlags() const final { return getGstPlayFlag("text") | getGstPlayFlag("native-audio"); }
40+
bool shouldParseIncomingLibWebRTCBitStream() const final { return false; }
4041

4142
private:
4243
Vector<String> m_disallowedWebAudioDecoders;

Source/WebCore/platform/gstreamer/GStreamerQuirkRealtek.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class GStreamerQuirkRealtek final : public GStreamerQuirk {
3535
void configureElement(GstElement*, const OptionSet<ElementRuntimeCharacteristics>&) final;
3636
std::optional<bool> isHardwareAccelerated(GstElementFactory*) final;
3737
Vector<String> disallowedWebAudioDecoders() const final { return m_disallowedWebAudioDecoders; }
38+
bool shouldParseIncomingLibWebRTCBitStream() const final { return false; }
3839

3940
private:
4041
Vector<String> m_disallowedWebAudioDecoders;

Source/WebCore/platform/gstreamer/GStreamerQuirks.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ unsigned GStreamerQuirksManager::getAdditionalPlaybinFlags() const
281281
return flags;
282282
}
283283

284+
bool GStreamerQuirksManager::shouldParseIncomingLibWebRTCBitStream() const
285+
{
286+
for (auto& quirk : m_quirks) {
287+
if (!quirk->shouldParseIncomingLibWebRTCBitStream())
288+
return false;
289+
}
290+
return true;
291+
}
292+
284293
#undef GST_CAT_DEFAULT
285294

286295
} // namespace WebCore

Source/WebCore/platform/gstreamer/GStreamerQuirks.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class GStreamerQuirk : public GStreamerQuirkBase {
5959
virtual std::optional<bool> isHardwareAccelerated(GstElementFactory*) { return std::nullopt; }
6060
virtual std::optional<GstElementFactoryListType> audioVideoDecoderFactoryListType() const { return std::nullopt; }
6161
virtual Vector<String> disallowedWebAudioDecoders() const { return { }; }
62-
virtual unsigned getAdditionalPlaybinFlags() const { return 0; }
62+
virtual unsigned getAdditionalPlaybinFlags() const { return getGstPlayFlag("text") | getGstPlayFlag("soft-colorbalance"); }
63+
virtual bool shouldParseIncomingLibWebRTCBitStream() const { return true; }
6364
};
6465

6566
class GStreamerHolePunchQuirk : public GStreamerQuirkBase {
@@ -102,6 +103,8 @@ class GStreamerQuirksManager : public RefCounted<GStreamerQuirksManager> {
102103

103104
unsigned getAdditionalPlaybinFlags() const;
104105

106+
bool shouldParseIncomingLibWebRTCBitStream() const;
107+
105108
private:
106109
GStreamerQuirksManager(bool, bool);
107110

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#if ENABLE(VIDEO) && ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER)
2424
#include "GStreamerVideoDecoderFactory.h"
2525

26+
#include "GStreamerQuirks.h"
2627
#include "GStreamerVideoCommon.h"
2728
#include "GStreamerRegistryScanner.h"
2829
#include "GStreamerVideoFrameLibWebRTC.h"
@@ -112,6 +113,16 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
112113
m_needsKeyframe = true;
113114
}
114115

116+
static unsigned getGstAutoplugSelectResult(const char* nick)
117+
{
118+
static GEnumClass* enumClass = static_cast<GEnumClass*>(g_type_class_ref(g_type_from_name("GstAutoplugSelectResult")));
119+
ASSERT(enumClass);
120+
GEnumValue* ev = g_enum_get_value_by_nick(enumClass, nick);
121+
if (!ev)
122+
return 0;
123+
return ev->value;
124+
}
125+
115126
bool Configure(const webrtc::VideoDecoder::Settings& codecSettings) override
116127
{
117128
m_src = makeElement("appsrc");
@@ -128,9 +139,17 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
128139

129140
auto sinkpad = adoptGRef(gst_element_get_static_pad(capsfilter, "sink"));
130141
g_signal_connect(decoder, "pad-added", G_CALLBACK(decodebinPadAddedCb), sinkpad.get());
131-
#if PLATFORM(BROADCOM) || PLATFORM(REALTEK)
132-
g_signal_connect(decoder, "autoplug-select", G_CALLBACK(decodebinAutoplugSelect), nullptr);
133-
#endif
142+
143+
auto& quirksManager = GStreamerQuirksManager::singleton();
144+
if (quirksManager.isEnabled()) {
145+
g_signal_connect(decoder, "autoplug-select", G_CALLBACK(+[](GstElement*, GstPad*, GstCaps*, GstElementFactory* factory, gpointer) -> unsigned {
146+
auto& quirksManager = GStreamerQuirksManager::singleton();
147+
auto isHardwareAccelerated = quirksManager.isHardwareAccelerated(factory).value_or(false);
148+
if (isHardwareAccelerated)
149+
return getGstAutoplugSelectResult("skip");
150+
return getGstAutoplugSelectResult("try");
151+
}), nullptr);
152+
}
134153

135154
// Make the decoder output "parsed" frames only and let the main decodebin
136155
// do the real decoding. This allows us to have optimized decoding/rendering
@@ -350,10 +369,13 @@ class GStreamerWebRTCVideoDecoder : public webrtc::VideoDecoder {
350369

351370
class H264Decoder : public GStreamerWebRTCVideoDecoder {
352371
public:
353-
H264Decoder() {
354-
#if !PLATFORM(REALTEK) && !PLATFORM(BROADCOM)
372+
H264Decoder()
373+
{
355374
m_requireParse = true;
356-
#endif
375+
376+
auto& quirksManager = GStreamerQuirksManager::singleton();
377+
if (quirksManager.isEnabled())
378+
m_requireParse = quirksManager.shouldParseIncomingLibWebRTCBitStream();
357379
}
358380

359381
bool Configure(const webrtc::VideoDecoder::Settings& codecSettings) final

0 commit comments

Comments
 (0)