mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
vaapiencode: h264: improve set_config() vmethod
First check if downstream requests ANY caps. If so, byte-stream is used and the profile will be choose by the encoder. If dowstream requests EMPTY caps, the negotiation will fail. Lately, byte-stream and profile are looked in the allowed caps. https://bugzilla.gnome.org/show_bug.cgi?id=757941
This commit is contained in:
parent
b713af42a1
commit
322fe98936
1 changed files with 47 additions and 27 deletions
|
@ -284,39 +284,59 @@ gst_vaapiencode_h264_set_config (GstVaapiEncode * base_encode)
|
||||||
GstVaapiEncodeH264 *const encode = GST_VAAPIENCODE_H264_CAST (base_encode);
|
GstVaapiEncodeH264 *const encode = GST_VAAPIENCODE_H264_CAST (base_encode);
|
||||||
GstVaapiEncoderH264 *const encoder =
|
GstVaapiEncoderH264 *const encoder =
|
||||||
GST_VAAPI_ENCODER_H264 (base_encode->encoder);
|
GST_VAAPI_ENCODER_H264 (base_encode->encoder);
|
||||||
GstCaps *allowed_caps;
|
GstCaps *template_caps, *allowed_caps;
|
||||||
GstVaapiProfile profile;
|
gboolean ret = TRUE;
|
||||||
const char *stream_format = NULL;
|
|
||||||
GstStructure *structure;
|
|
||||||
guint i, num_structures;
|
|
||||||
|
|
||||||
|
template_caps =
|
||||||
|
gst_static_pad_template_get_caps (&gst_vaapiencode_h264_src_factory);
|
||||||
allowed_caps =
|
allowed_caps =
|
||||||
gst_pad_get_allowed_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD (base_encode));
|
gst_pad_get_allowed_caps (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode));
|
||||||
if (!allowed_caps)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
/* Check whether "stream-format" is avcC mode */
|
if (allowed_caps == template_caps) {
|
||||||
num_structures = gst_caps_get_size (allowed_caps);
|
GST_INFO_OBJECT (encode, "downstream has ANY caps, outputting byte-stream");
|
||||||
for (i = 0; !stream_format && i < num_structures; i++) {
|
encode->is_avc = FALSE;
|
||||||
structure = gst_caps_get_structure (allowed_caps, i);
|
gst_caps_unref (allowed_caps);
|
||||||
if (!gst_structure_has_field_typed (structure, "stream-format",
|
} else if (!allowed_caps) {
|
||||||
G_TYPE_STRING))
|
GST_INFO_OBJECT (encode,
|
||||||
continue;
|
"downstream has NULL caps, outputting byte-stream");
|
||||||
stream_format = gst_structure_get_string (structure, "stream-format");
|
encode->is_avc = FALSE;
|
||||||
|
} else if (gst_caps_is_empty (allowed_caps)) {
|
||||||
|
GST_INFO_OBJECT (encode, "downstream has EMPTY caps");
|
||||||
|
gst_caps_unref (template_caps);
|
||||||
|
gst_caps_unref (allowed_caps);
|
||||||
|
return FALSE;
|
||||||
|
} else {
|
||||||
|
const char *stream_format = NULL;
|
||||||
|
GstStructure *structure;
|
||||||
|
guint i, num_structures;
|
||||||
|
GstVaapiProfile profile;
|
||||||
|
|
||||||
|
/* Check whether "stream-format" is avcC mode */
|
||||||
|
num_structures = gst_caps_get_size (allowed_caps);
|
||||||
|
for (i = 0; !stream_format && i < num_structures; i++) {
|
||||||
|
structure = gst_caps_get_structure (allowed_caps, i);
|
||||||
|
if (!gst_structure_has_field_typed (structure, "stream-format",
|
||||||
|
G_TYPE_STRING))
|
||||||
|
continue;
|
||||||
|
stream_format = gst_structure_get_string (structure, "stream-format");
|
||||||
|
}
|
||||||
|
encode->is_avc = stream_format && strcmp (stream_format, "avc") == 0;
|
||||||
|
|
||||||
|
/* Check for the largest profile that is supported */
|
||||||
|
profile = find_best_profile (allowed_caps);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_caps_unref (allowed_caps);
|
||||||
}
|
}
|
||||||
encode->is_avc = stream_format && strcmp (stream_format, "avc") == 0;
|
gst_caps_unref (template_caps);
|
||||||
|
|
||||||
base_encode->need_codec_data = encode->is_avc;
|
base_encode->need_codec_data = encode->is_avc;
|
||||||
|
|
||||||
/* Check for the largest profile that is supported */
|
return ret;
|
||||||
profile = find_best_profile (allowed_caps);
|
|
||||||
gst_caps_unref (allowed_caps);
|
|
||||||
if (profile) {
|
|
||||||
GST_INFO ("using %s profile as target decoder constraints",
|
|
||||||
gst_vaapi_utils_h264_get_profile_string (profile));
|
|
||||||
if (!gst_vaapi_encoder_h264_set_max_profile (encoder, profile))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
|
|
Loading…
Reference in a new issue