Skip to content

Commit eaa6cd6

Browse files
asurdej-comcastphiln
authored andcommitted
Avoid auto-plugging of webkitthunderparser in players other than MediaPlayerPrivateGStreamer
1 parent 71fc3fd commit eaa6cd6

2 files changed

Lines changed: 35 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,12 @@ void registerWebKitGStreamerElements()
429429
// The Thunder parser is auto-plugged by parsebin and its internal parsebin can
430430
// auto-plug the Thunder decryptor.
431431
gst_element_register(nullptr, "webkitthunder", GST_RANK_PRIMARY + 100, WEBKIT_TYPE_MEDIA_THUNDER_DECRYPT);
432-
gst_element_register(nullptr, "webkitthunderparser", GST_RANK_PRIMARY + 101, WEBKIT_TYPE_MEDIA_THUNDER_PARSER);
432+
// We don't want the webkitthunderparser to be preferred in players other than WebKit Media Player GStreamer.
433+
// Unfortunately, GstParseBin prefers "Parser" elements over eny other elements,
434+
// including higher ranked "Decryptor" elements.
435+
// So we register it with GST_RANK_NONE, so that it is not auto-plugged by parsebin at all
436+
// and inject it manually in the MediaPlayerPrivateGStreamer.
437+
gst_element_register(nullptr, "webkitthunderparser", GST_RANK_NONE, WEBKIT_TYPE_MEDIA_THUNDER_PARSER);
433438
}
434439
#endif
435440

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,11 +2516,6 @@ void MediaPlayerPrivateGStreamer::configureParsebin(GstElement* parsebin)
25162516
g_signal_connect(parsebin, "autoplug-select",
25172517
G_CALLBACK(+[](GstElement*, GstPad*, GstCaps* caps, GstElementFactory* factory, MediaPlayerPrivateGStreamer* player) -> unsigned {
25182518
static auto tryAutoPlug = *gstGetAutoplugSelectResult("try"_s);
2519-
static auto skipAutoPlug = *gstGetAutoplugSelectResult("skip"_s);
2520-
2521-
auto name = StringView::fromLatin1(gst_plugin_feature_get_name(GST_PLUGIN_FEATURE_CAST(factory)));
2522-
if (name == "webkitthunderparser"_s && player->m_url.protocolIsBlob())
2523-
return skipAutoPlug;
25242519

25252520
auto* structure = gst_caps_get_structure(caps, 0);
25262521
if (!structure)
@@ -2551,6 +2546,35 @@ void MediaPlayerPrivateGStreamer::configureParsebin(GstElement* parsebin)
25512546

25522547
return tryAutoPlug;
25532548
}), this);
2549+
2550+
// We need to ensure that the webkitthunderparser factory is preferred over other parsers.
2551+
g_signal_connect(parsebin, "autoplug-factories",
2552+
G_CALLBACK(+[](GstElement*, GstPad*, GstCaps* caps, MediaPlayerPrivateGStreamer* player) -> GValueArray* {
2553+
ALLOW_DEPRECATED_DECLARATIONS_BEGIN; // GValueArray is deprecated
2554+
GValueArray* result;
2555+
// First, build a list of all decodable factories that can handle the caps,
2556+
// similar to what parsebin does.
2557+
auto factories = gst_element_factory_list_get_elements(GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL);
2558+
// Add the webkitthunderparser factory if it exists, at the beginning of the list
2559+
// so that it is preferred over other elements.
2560+
if (!player->m_url.protocolIsBlob() && gst_element_factory_find("webkitthunderparser"_s))
2561+
factories = g_list_prepend(factories, gst_element_factory_find("webkitthunderparser"_s));
2562+
// Filter the factories based on the caps and return them as a GValueArray.
2563+
auto list = gst_element_factory_list_filter(factories, caps, GST_PAD_SINK, gst_caps_is_fixed(caps));
2564+
result = g_value_array_new(g_list_length(list));
2565+
for (GList* tmp = list; tmp; tmp = tmp->next) {
2566+
auto factory = GST_ELEMENT_FACTORY_CAST(tmp->data);
2567+
GValue value = G_VALUE_INIT;
2568+
g_value_init(&value, G_TYPE_OBJECT);
2569+
g_value_set_object(&value, factory);
2570+
g_value_array_append(result, &value);
2571+
g_value_unset(&value);
2572+
}
2573+
gst_plugin_feature_list_free(list);
2574+
gst_plugin_feature_list_free(factories);
2575+
return result;
2576+
ALLOW_DEPRECATED_DECLARATIONS_END;
2577+
}), this);
25542578
}
25552579

25562580
void MediaPlayerPrivateGStreamer::configureUriDecodebin2(GstElement* element)

0 commit comments

Comments
 (0)