From e4c82f450da7ecae1772786d156ddf21aaea1fd2 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Fri, 28 May 2021 17:36:15 -0400 Subject: [PATCH] openh264: Respect level set downstream 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: --- ext/openh264/gstopenh264enc.cpp | 15 +++++++++++++++ ext/openh264/meson.build | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ext/openh264/gstopenh264enc.cpp b/ext/openh264/gstopenh264enc.cpp index dff3db6dd9..b8b80c4919 100644 --- a/ext/openh264/gstopenh264enc.cpp +++ b/ext/openh264/gstopenh264enc.cpp @@ -30,6 +30,7 @@ #include "gstopenh264elements.h" #include "gstopenh264enc.h" +#include #include #include #include @@ -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; diff --git a/ext/openh264/meson.build b/ext/openh264/meson.build index 6147f9e3da..90005de67f 100644 --- a/ext/openh264/meson.build +++ b/ext/openh264/meson.build @@ -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, )