/**
* 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.
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);
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);
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 ();
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
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);
}