Skip to content

Commit 2f4fef0

Browse files
cadubentzenphiln
authored andcommitted
Reviewed by Philippe Normand. We can save some overhead by not parsing again streams that are already parsed and that the caps match the decoder's. In that case, we can skip creating a parser element in parsebin. * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivateGStreamer::configureParsebin): (WebCore::MediaPlayerPrivateGStreamer::configureElement): * Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h: Canonical link: https://commits.webkit.org/292591@main
1 parent 0cbf052 commit 2f4fef0

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,43 @@ void MediaPlayerPrivateGStreamer::processTableOfContentsEntry(GstTocEntry* entry
25062506
processTableOfContentsEntry(static_cast<GstTocEntry*>(i->data));
25072507
}
25082508

2509+
void MediaPlayerPrivateGStreamer::configureParsebin(GstElement* parsebin)
2510+
{
2511+
// We can save some overhead by not parsing again streams that are already parsed and that
2512+
// the caps match the decoder's. In that case, we can skip creating a parser element in parsebin.
2513+
g_signal_connect(parsebin, "autoplug-select",
2514+
G_CALLBACK(+[](GstElement*, GstPad*, GstCaps* caps, GstElementFactory* factory, MediaPlayerPrivateGStreamer* player) -> unsigned {
2515+
static auto tryAutoPlug = *gstGetAutoplugSelectResult("try"_s);
2516+
static auto exposeAutoPlug = *gstGetAutoplugSelectResult("expose"_s);
2517+
2518+
auto* structure = gst_caps_get_structure(caps, 0);
2519+
if (!structure)
2520+
return tryAutoPlug;
2521+
2522+
// TODO: this already works perfectly well for MediaStream, but in MSE we still plug in a parser despite having
2523+
// already parsed the stream in the append pipeline, because the caps we receive here aren't parsed yet,
2524+
// although it becomes parsed later. We can probably find a way to avoid this extra parsing in MSE too.
2525+
auto isParsed = gstStructureGet<bool>(structure, "parsed"_s);
2526+
if (!isParsed || !*isParsed)
2527+
return tryAutoPlug;
2528+
2529+
auto& scanner = GStreamerRegistryScanner::singleton();
2530+
GUniquePtr<char> gstCodecName(gst_codec_utils_caps_get_mime_codec(caps));
2531+
auto codecName = String::fromUTF8(gstCodecName.get());
2532+
auto result = scanner.isCodecSupported(GStreamerRegistryScanner::Configuration::Decoding, codecName);
2533+
if (!result.isSupported)
2534+
return tryAutoPlug;
2535+
2536+
auto decoderFactoryAcceptsCaps = gst_element_factory_can_sink_any_caps(result.factory.get(), caps);
2537+
GST_DEBUG_OBJECT(player->pipeline(), "Does %" GST_PTR_FORMAT " decoder accept caps %" GST_PTR_FORMAT "? %s", factory, caps, boolForPrinting(decoderFactoryAcceptsCaps));
2538+
2539+
if (decoderFactoryAcceptsCaps)
2540+
return exposeAutoPlug;
2541+
2542+
return tryAutoPlug;
2543+
}), this);
2544+
}
2545+
25092546
void MediaPlayerPrivateGStreamer::configureElement(GstElement* element)
25102547
{
25112548
configureElementPlatformQuirks(element);
@@ -2521,6 +2558,9 @@ void MediaPlayerPrivateGStreamer::configureElement(GstElement* element)
25212558
if (webkitGstCheckVersion(1, 22, 0) && g_str_has_prefix(elementName.get(), "urisourcebin") && (isMediaSource() || isMediaStreamPlayer()))
25222559
g_object_set(element, "use-buffering", FALSE, "parse-streams", !isMediaStreamPlayer(), nullptr);
25232560

2561+
if (nameView.startsWith("parsebin"_s))
2562+
configureParsebin(element);
2563+
25242564
// In case of playbin3 with <video ... preload="auto">, instantiate
25252565
// downloadbuffer element, otherwise the playbin3 would instantiate
25262566
// a queue element instead .

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ class MediaPlayerPrivateGStreamer
578578
void configureAudioDecoder(GstElement*);
579579
void configureVideoDecoder(GstElement*);
580580
void configureElement(GstElement*);
581+
void configureParsebin(GstElement*);
581582

582583
void configureElementPlatformQuirks(GstElement*);
583584

0 commit comments

Comments
 (0)