vaapih264enc: update level in src caps
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Fri, 17 Jan 2020 13:24:37 +0000 (14:24 +0100)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Sun, 19 Jan 2020 14:26:18 +0000 (14:26 +0000)
And, if downstream requests a specific level, the caps are not
negotiated, because there is no mechanism right now to specify a
custom level in the internal encoder.

gst/vaapi/gstvaapiencode_h264.c

index 4a3b4ac..98badf4 100644 (file)
@@ -319,7 +319,12 @@ gst_vaapiencode_h264_set_config (GstVaapiEncode * base_encode)
     stream_format = gst_structure_get_string (structure, "stream-format");
     encode->is_avc = (g_strcmp0 (stream_format, "avc") == 0);
 
-    if (profile != GST_VAAPI_PROFILE_UNKNOWN) {
+    if (gst_structure_has_field (structure, "level")) {
+      /* @TODO(victor): add a mechansim for user set a specific
+       * level */
+      GST_WARNING_OBJECT (encode, "cannot set level configuration");
+      ret = FALSE;
+    } else if (profile != GST_VAAPI_PROFILE_UNKNOWN) {
       GST_INFO ("using %s profile as target decoder constraints",
           gst_vaapi_utils_h264_get_profile_string (profile));
       ret = gst_vaapi_encoder_h264_set_max_profile (encoder, profile);
@@ -346,7 +351,7 @@ fail:
 
 static void
 set_compatible_profile (GstVaapiEncodeH264 * encode, GstCaps * caps,
-    GstVaapiProfile profile)
+    GstVaapiProfile profile, GstVaapiLevelH264 level)
 {
   GstCaps *allowed_caps, *tmp_caps;
   gboolean ret = FALSE;
@@ -380,7 +385,9 @@ retry:
     }
   } else {
     gst_caps_set_simple (caps, "profile", G_TYPE_STRING,
-        gst_vaapi_utils_h264_get_profile_string (profile), NULL);
+        gst_vaapi_utils_h264_get_profile_string (profile),
+        "level", G_TYPE_STRING, gst_vaapi_utils_h264_get_level_string (level),
+        NULL);
     ret = TRUE;
   }
 
@@ -399,6 +406,7 @@ gst_vaapiencode_h264_get_caps (GstVaapiEncode * base_encode)
   GstVaapiEncoderH264 *const encoder =
       GST_VAAPI_ENCODER_H264 (base_encode->encoder);
   GstVaapiProfile profile;
+  GstVaapiLevelH264 level;
   GstCaps *caps;
 
   caps = gst_caps_from_string (GST_CODEC_CAPS);
@@ -407,13 +415,11 @@ gst_vaapiencode_h264_get_caps (GstVaapiEncode * base_encode)
       encode->is_avc ? "avc" : "byte-stream", NULL);
 
   /* Update profile determined by encoder */
-  gst_vaapi_encoder_h264_get_profile_and_level (encoder, &profile, NULL);
+  gst_vaapi_encoder_h264_get_profile_and_level (encoder, &profile, &level);
   if (profile != GST_VAAPI_PROFILE_UNKNOWN)
-    set_compatible_profile (encode, caps, profile);
+    set_compatible_profile (encode, caps, profile, level);
 
   GST_INFO_OBJECT (base_encode, "out caps %" GST_PTR_FORMAT, caps);
-
-  /* XXX: update level information */
   return caps;
 }