mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-24 16:18:16 +00:00
pbutils: descriptions: Allow smart codec tag handling
We already have internally the information on what type of stream (audio, video, container, subtitle, ...) a certain caps is. Instead of forcing callers to specify which CODEC_TAG category a certain caps is, use that information to make a smart choice. Does not break previous behaviour of gst_pb_utils_add_codec_description_to_tag_list (if tag is specified it will be used, if caps is invalid it will be rejected, ...). https://bugzilla.gnome.org/show_bug.cgi?id=702215
This commit is contained in:
parent
b81ca93de2
commit
a9e4750674
2 changed files with 80 additions and 9 deletions
|
@ -949,8 +949,9 @@ gst_pb_utils_get_element_description (const gchar * factory_name)
|
|||
/**
|
||||
* gst_pb_utils_add_codec_description_to_tag_list:
|
||||
* @taglist: a #GstTagList
|
||||
* @codec_tag: a GStreamer codec tag such as #GST_TAG_AUDIO_CODEC,
|
||||
* #GST_TAG_VIDEO_CODEC or #GST_TAG_CODEC
|
||||
* @codec_tag: (allow-none): a GStreamer codec tag such as #GST_TAG_AUDIO_CODEC,
|
||||
* #GST_TAG_VIDEO_CODEC or #GST_TAG_CODEC. If none is specified,
|
||||
* the function will attempt to detect the appropriate category.
|
||||
* @caps: the (fixed) #GstCaps for which a codec tag should be added.
|
||||
*
|
||||
* Adds a codec tag describing the format specified by @caps to @taglist.
|
||||
|
@ -966,9 +967,8 @@ gst_pb_utils_add_codec_description_to_tag_list (GstTagList * taglist,
|
|||
|
||||
g_return_val_if_fail (taglist != NULL, FALSE);
|
||||
g_return_val_if_fail (GST_IS_TAG_LIST (taglist), FALSE);
|
||||
g_return_val_if_fail (codec_tag != NULL, FALSE);
|
||||
g_return_val_if_fail (gst_tag_exists (codec_tag), FALSE);
|
||||
g_return_val_if_fail (gst_tag_get_type (codec_tag) == G_TYPE_STRING, FALSE);
|
||||
g_return_val_if_fail (codec_tag == NULL || (gst_tag_exists (codec_tag)
|
||||
&& gst_tag_get_type (codec_tag) == G_TYPE_STRING), FALSE);
|
||||
g_return_val_if_fail (caps != NULL, FALSE);
|
||||
g_return_val_if_fail (GST_IS_CAPS (caps), FALSE);
|
||||
|
||||
|
@ -976,6 +976,20 @@ gst_pb_utils_add_codec_description_to_tag_list (GstTagList * taglist,
|
|||
if (info == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* Attempt to find tag classification */
|
||||
if (codec_tag == NULL) {
|
||||
if (info->flags & FLAG_CONTAINER)
|
||||
codec_tag = GST_TAG_CONTAINER_FORMAT;
|
||||
else if (info->flags & FLAG_AUDIO)
|
||||
codec_tag = GST_TAG_AUDIO_CODEC;
|
||||
else if (info->flags & FLAG_VIDEO)
|
||||
codec_tag = GST_TAG_VIDEO_CODEC;
|
||||
else if (info->flags & FLAG_SUB)
|
||||
codec_tag = GST_TAG_SUBTITLE_CODEC;
|
||||
else
|
||||
codec_tag = GST_TAG_CODEC;
|
||||
}
|
||||
|
||||
desc = format_info_get_desc (info, caps);
|
||||
gst_tag_list_add (taglist, GST_TAG_MERGE_REPLACE, codec_tag, desc, NULL);
|
||||
g_free (desc);
|
||||
|
|
|
@ -425,7 +425,8 @@ GST_END_TEST;
|
|||
GST_START_TEST (test_pb_utils_taglist_add_codec_info)
|
||||
{
|
||||
GstTagList *list;
|
||||
GstCaps *caps;
|
||||
GstCaps *caps, *bogus_caps;
|
||||
gchar *res;
|
||||
|
||||
gst_pb_utils_init ();
|
||||
list = gst_tag_list_new_empty ();
|
||||
|
@ -433,8 +434,6 @@ GST_START_TEST (test_pb_utils_taglist_add_codec_info)
|
|||
ASSERT_CRITICAL (fail_if
|
||||
(gst_pb_utils_add_codec_description_to_tag_list (NULL,
|
||||
GST_TAG_VIDEO_CODEC, caps)));
|
||||
ASSERT_CRITICAL (fail_if
|
||||
(gst_pb_utils_add_codec_description_to_tag_list (list, NULL, caps)));
|
||||
ASSERT_CRITICAL (fail_if
|
||||
(gst_pb_utils_add_codec_description_to_tag_list (list, "asdfa", caps)));
|
||||
ASSERT_CRITICAL (fail_if
|
||||
|
@ -443,10 +442,68 @@ GST_START_TEST (test_pb_utils_taglist_add_codec_info)
|
|||
ASSERT_CRITICAL (fail_if
|
||||
(gst_pb_utils_add_codec_description_to_tag_list (list,
|
||||
GST_TAG_VIDEO_CODEC, NULL)));
|
||||
/* FIXME: do something here */
|
||||
|
||||
/* Try adding bogus caps (should fail) */
|
||||
bogus_caps = gst_caps_new_empty_simple ("bogus/format");
|
||||
fail_if (gst_pb_utils_add_codec_description_to_tag_list (list,
|
||||
GST_TAG_VIDEO_CODEC, bogus_caps));
|
||||
gst_caps_unref (bogus_caps);
|
||||
|
||||
/* Try adding valid caps with known tag */
|
||||
fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list,
|
||||
GST_TAG_VIDEO_CODEC, caps));
|
||||
fail_if (gst_tag_list_is_empty (list));
|
||||
fail_unless (gst_tag_list_get_string (list, GST_TAG_VIDEO_CODEC, &res));
|
||||
g_free (res);
|
||||
gst_tag_list_unref (list);
|
||||
|
||||
/* Try adding valid caps with auto-tag (for video, audio, subtitle, generic) */
|
||||
list = gst_tag_list_new_empty ();
|
||||
fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
|
||||
caps));
|
||||
fail_if (gst_tag_list_is_empty (list));
|
||||
fail_unless (gst_tag_list_get_string (list, GST_TAG_VIDEO_CODEC, &res));
|
||||
g_free (res);
|
||||
gst_tag_list_unref (list);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
list = gst_tag_list_new_empty ();
|
||||
caps = gst_caps_new_empty_simple ("audio/x-vorbis");
|
||||
fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
|
||||
caps));
|
||||
fail_if (gst_tag_list_is_empty (list));
|
||||
fail_unless (gst_tag_list_get_string (list, GST_TAG_AUDIO_CODEC, &res));
|
||||
g_free (res);
|
||||
gst_tag_list_unref (list);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
list = gst_tag_list_new_empty ();
|
||||
caps = gst_caps_new_empty_simple ("subtitle/x-kate");
|
||||
fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
|
||||
caps));
|
||||
fail_if (gst_tag_list_is_empty (list));
|
||||
fail_unless (gst_tag_list_get_string (list, GST_TAG_SUBTITLE_CODEC, &res));
|
||||
g_free (res);
|
||||
gst_tag_list_unref (list);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
list = gst_tag_list_new_empty ();
|
||||
caps = gst_caps_new_empty_simple ("application/ogg");
|
||||
fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
|
||||
caps));
|
||||
fail_if (gst_tag_list_is_empty (list));
|
||||
fail_unless (gst_tag_list_get_string (list, GST_TAG_CONTAINER_FORMAT, &res));
|
||||
g_free (res);
|
||||
gst_tag_list_unref (list);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
list = gst_tag_list_new_empty ();
|
||||
caps = gst_caps_new_empty_simple ("image/bmp");
|
||||
fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, NULL,
|
||||
caps));
|
||||
fail_if (gst_tag_list_is_empty (list));
|
||||
fail_unless (gst_tag_list_get_string (list, GST_TAG_CODEC, &res));
|
||||
g_free (res);
|
||||
gst_tag_list_unref (list);
|
||||
gst_caps_unref (caps);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue