Title: [288971] trunk/Source/WebCore
Revision
288971
Author
[email protected]
Date
2022-02-02 10:54:06 -0800 (Wed, 02 Feb 2022)

Log Message

[GStreamer] Generate webrtc encoder src pad template based on supported platform encoders
https://bugs.webkit.org/show_bug.cgi?id=235964

Patch by Philippe Normand <[email protected]> on 2022-02-02
Reviewed by Xabier Rodriguez-Calvar.

Without this patch there was no guarantee the encoder would setup correctly in case the
encoder matching the requested caps is not available at runtime.

* platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp:
(Encoders::registerEncoder):
(createSrcPadTemplateCaps):
(webkit_webrtc_video_encoder_class_init):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (288970 => 288971)


--- trunk/Source/WebCore/ChangeLog	2022-02-02 18:50:38 UTC (rev 288970)
+++ trunk/Source/WebCore/ChangeLog	2022-02-02 18:54:06 UTC (rev 288971)
@@ -1,3 +1,18 @@
+2022-02-02  Philippe Normand  <[email protected]>
+
+        [GStreamer] Generate webrtc encoder src pad template based on supported platform encoders
+        https://bugs.webkit.org/show_bug.cgi?id=235964
+
+        Reviewed by Xabier Rodriguez-Calvar.
+
+        Without this patch there was no guarantee the encoder would setup correctly in case the
+        encoder matching the requested caps is not available at runtime.
+
+        * platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp:
+        (Encoders::registerEncoder):
+        (createSrcPadTemplateCaps):
+        (webkit_webrtc_video_encoder_class_init):
+
 2022-02-02  Antoine Quint  <[email protected]>
 
         CSSPropertyAnimation::animatableShorthandsAffectingProperty() is unused

Modified: trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp (288970 => 288971)


--- trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp	2022-02-02 18:50:38 UTC (rev 288970)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp	2022-02-02 18:54:06 UTC (rev 288971)
@@ -71,10 +71,16 @@
     static void registerEncoder(EncoderId id, const char* name, const char* parserName, const char* caps, const char* encodedFormat,
         SetupFunc&& setupEncoder, const char* bitratePropertyName, SetBitrateFunc&& setBitrate, const char* keyframeIntervalPropertyName)
     {
-        auto feature = adoptGRef(gst_registry_lookup_feature(gst_registry_get(), name));
-        if (!feature)
+        auto encoderFactory = adoptGRef(gst_element_factory_find(name));
+        if (!encoderFactory)
             return;
 
+        if (parserName) {
+            auto parserFactory = adoptGRef(gst_element_factory_find(parserName));
+            if (!parserFactory)
+                return;
+        }
+
         singleton().emplace(std::make_pair(id, (EncoderDefinition) {
             .caps = adoptGRef(gst_caps_from_string(caps)),
             .name = name,
@@ -250,6 +256,21 @@
     g_object_set(encoder, propertyName, bitrate * KBIT_TO_BIT, nullptr);
 }
 
+static GRefPtr<GstCaps> createSrcPadTemplateCaps()
+{
+    auto* caps = gst_caps_new_empty();
+
+    for (const auto& [id, encoder] : Encoders::singleton()) {
+        if (encoder.encodedFormat)
+            caps = gst_caps_merge(caps, gst_caps_ref(encoder.encodedFormat.get()));
+        else
+            caps = gst_caps_merge(caps, gst_caps_ref(encoder.caps.get()));
+    }
+
+    GST_DEBUG("Source pad template caps: %" GST_PTR_FORMAT, caps);
+    return caps;
+}
+
 static void webrtcVideoEncoderConstructed(GObject* encoder)
 {
     auto* self = WEBKIT_WEBRTC_VIDEO_ENCODER(encoder);
@@ -268,18 +289,7 @@
     GstElementClass* elementClass = GST_ELEMENT_CLASS(klass);
     gst_element_class_set_static_metadata(elementClass, "WebKit WebRTC video encoder", "Codec/Encoder/Video", "Encodes video for streaming", "Igalia");
     gst_element_class_add_pad_template(elementClass, gst_static_pad_template_get(&sinkTemplate));
-    gst_element_class_add_pad_template(elementClass, gst_static_pad_template_get(&srcTemplate));
 
-    g_object_class_install_property(objectClass, PROP_FORMAT, g_param_spec_boxed("format", "Format as caps", "Set the caps of the format to be used.", GST_TYPE_CAPS, WEBKIT_PARAM_READWRITE));
-
-    g_object_class_install_property(objectClass, PROP_ENCODER, g_param_spec_object("encoder", "The actual encoder element", "The encoder element", GST_TYPE_ELEMENT, WEBKIT_PARAM_READABLE));
-
-    g_object_class_install_property(objectClass, PROP_BITRATE, g_param_spec_uint("bitrate", "Bitrate", "The bitrate in kbit per second", 0, G_MAXINT, 2048,
-        static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)));
-
-    g_object_class_install_property(objectClass, PROP_KEYFRAME_INTERVAL, g_param_spec_uint("keyframe-interval", "Keyframe interval", "The interval between keyframes", 0, G_MAXINT, 0,
-        static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)));
-
     Encoders::registerEncoder(OmxH264, "omxh264enc", "h264parse", "video/x-h264",
         "video/x-h264,alignment=au,stream-format=byte-stream,profile=""
         [](WebKitWebrtcVideoEncoder* self) {
@@ -305,6 +315,19 @@
         [](WebKitWebrtcVideoEncoder* self) {
             g_object_set(self->priv->encoder.get(), "threads", 4, "cpu-used", 4, "tile-rows", 2, "row-mt", true, nullptr);
         }, "target-bitrate", setBitrateBitPerSec, "keyframe-max-dist");
+
+    auto srcPadTemplateCaps = createSrcPadTemplateCaps();
+    gst_element_class_add_pad_template(elementClass, gst_pad_template_new("src", GST_PAD_SRC, GST_PAD_ALWAYS, srcPadTemplateCaps.get()));
+
+    g_object_class_install_property(objectClass, PROP_FORMAT, g_param_spec_boxed("format", "Format as caps", "Set the caps of the format to be used.", GST_TYPE_CAPS, WEBKIT_PARAM_READWRITE));
+
+    g_object_class_install_property(objectClass, PROP_ENCODER, g_param_spec_object("encoder", "The actual encoder element", "The encoder element", GST_TYPE_ELEMENT, WEBKIT_PARAM_READABLE));
+
+    g_object_class_install_property(objectClass, PROP_BITRATE, g_param_spec_uint("bitrate", "Bitrate", "The bitrate in kbit per second", 0, G_MAXINT, 2048,
+        static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)));
+
+    g_object_class_install_property(objectClass, PROP_KEYFRAME_INTERVAL, g_param_spec_uint("keyframe-interval", "Keyframe interval", "The interval between keyframes", 0, G_MAXINT, 0,
+        static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)));
 }
 
 #endif // ENABLE(VIDEO) && ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to