openh264: Respect level set downstream
authorThibault Saunier <tsaunier@igalia.com>
Fri, 28 May 2021 21:36:15 +0000 (17:36 -0400)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Mon, 9 Aug 2021 20:17:54 +0000 (20:17 +0000)
We were not specifying the requested level to openh264  meaning that
it was choosing anything and was not respecting what was specified\
downstream

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2289>

ext/openh264/gstopenh264enc.cpp
ext/openh264/meson.build

index dff3db6..b8b80c4 100644 (file)
@@ -30,6 +30,7 @@
 #include "gstopenh264elements.h"
 #include "gstopenh264enc.h"
 
+#include <gst/pbutils/pbutils.h>
 #include <gst/gst.h>
 #include <gst/base/base.h>
 #include <gst/video/video.h>
@@ -684,6 +685,19 @@ gst_openh264enc_stop (GstVideoEncoder * encoder)
   return TRUE;
 }
 
+static guint8
+gst_openh264enc_get_level_from_caps (GstCaps *outcaps, GstCaps *allowed_caps)
+{
+  GstStructure *s = gst_caps_get_structure (outcaps, 0);
+  const gchar * level = gst_structure_get_string (gst_caps_get_structure (allowed_caps, 0), "level");
+
+  if (!level)
+    return LEVEL_UNKNOWN;
+
+  gst_structure_set (s, "level", G_TYPE_STRING, level, NULL);
+  return gst_codec_utils_h264_get_level_idc (level);
+}
+
 static EProfileIdc
 gst_openh264enc_get_profile_from_caps (GstCaps *outcaps, GstCaps *allowed_caps)
 {
@@ -790,6 +804,7 @@ gst_openh264enc_set_format (GstVideoEncoder * encoder,
   enc_params.fMaxFrameRate = fps_n * 1.0 / fps_d;
   enc_params.iLoopFilterDisableIdc = openh264enc->deblocking_mode;
   enc_params.sSpatialLayers[0].uiProfileIdc = gst_openh264enc_get_profile_from_caps (outcaps, allowed_caps);
+  enc_params.sSpatialLayers[0].uiLevelIdc = (ELevelIdc) gst_openh264enc_get_level_from_caps (outcaps, allowed_caps);
   enc_params.sSpatialLayers[0].iVideoWidth = enc_params.iPicWidth;
   enc_params.sSpatialLayers[0].iVideoHeight = enc_params.iPicHeight;
   enc_params.sSpatialLayers[0].fFrameRate = fps_n * 1.0 / fps_d;
index 6147f9e..90005de 100644 (file)
@@ -15,7 +15,7 @@ if openh264_dep.found()
     c_args : gst_plugins_bad_args,
     link_args : noseh_link_args,
     include_directories : [configinc],
-    dependencies : [gstvideo_dep, openh264_dep],
+    dependencies : [gstvideo_dep, openh264_dep, gstpbutils_dep, ],
     install : true,
     install_dir : plugins_install_dir,
   )