From: Edward Hervey Date: Wed, 22 Dec 2010 17:18:00 +0000 (+0100) Subject: encoding-profile: Add convenience method to find a profile X-Git-Tag: RELEASE-0.10.32~54 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=deea1eb83f5bd07ff45a44a460dc6af590185fc3;p=platform%2Fupstream%2Fgst-plugins-base.git encoding-profile: Add convenience method to find a profile API: gst_encoding_profile_find --- diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 00e8bd7..e42c956 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -1913,6 +1913,7 @@ gst_codec_utils_mpeg4video_caps_set_level_and_profile GstEncodingProfile gst_encoding_profile_unref gst_encoding_profile_ref +gst_encoding_profile_find gst_encoding_profile_get_name gst_encoding_profile_get_description gst_encoding_profile_get_format diff --git a/gst-libs/gst/pbutils/Makefile.am b/gst-libs/gst/pbutils/Makefile.am index 73251e1..fea84c4 100644 --- a/gst-libs/gst/pbutils/Makefile.am +++ b/gst-libs/gst/pbutils/Makefile.am @@ -90,6 +90,7 @@ GstPbutils-@GST_MAJORMINOR@.gir: $(INTROSPECTION_SCANNER) libgstpbutils-@GST_MAJ --pkg gstreamer-0.10 \ --pkg gstreamer-video-@GST_MAJORMINOR@ \ --pkg-export gstreamer-pbutils-@GST_MAJORMINOR@ \ + --add-init-section="gst_init(NULL,NULL);" \ --output $@ \ $(gir_headers) \ $(gir_sources) diff --git a/gst-libs/gst/pbutils/encoding-profile.c b/gst-libs/gst/pbutils/encoding-profile.c index 174bfe6..5fa3abb 100644 --- a/gst-libs/gst/pbutils/encoding-profile.c +++ b/gst-libs/gst/pbutils/encoding-profile.c @@ -118,6 +118,7 @@ #endif #include "encoding-profile.h" +#include "encoding-target.h" /* GstEncodingProfile API */ @@ -134,12 +135,53 @@ struct _GstEncodingProfile GstCaps *restriction; }; -G_DEFINE_TYPE (GstEncodingProfile, gst_encoding_profile, GST_TYPE_MINI_OBJECT); +static void string_to_profile_transform (const GValue * src_value, + GValue * dest_value); +static gboolean gst_encoding_profile_deserialize_valfunc (GValue * value, + const gchar * s); + +static void gst_encoding_profile_class_init (GstEncodingProfileClass * klass); +static gpointer gst_encoding_profile_parent_class = NULL; static void -gst_encoding_profile_init (GstEncodingProfile * prof) -{ - /* Nothing to initialize */ +gst_encoding_profile_class_intern_init (gpointer klass) +{ + gst_encoding_profile_parent_class = g_type_class_peek_parent (klass); + gst_encoding_profile_class_init ((GstEncodingProfileClass *) klass); +} + +GType +gst_encoding_profile_get_type (void) +{ + static volatile gsize g_define_type_id__volatile = 0; + + if (g_once_init_enter (&g_define_type_id__volatile)) { + GType g_define_type_id = + g_type_register_static_simple (GST_TYPE_MINI_OBJECT, + g_intern_static_string ("GstEncodingProfile"), + sizeof (GstEncodingProfileClass), + (GClassInitFunc) gst_encoding_profile_class_intern_init, + sizeof (GstEncodingProfile), + NULL, + (GTypeFlags) 0); + static GstValueTable gstvtable = { + G_TYPE_NONE, + (GstValueCompareFunc) NULL, + (GstValueSerializeFunc) NULL, + (GstValueDeserializeFunc) gst_encoding_profile_deserialize_valfunc + }; + + gstvtable.type = g_define_type_id; + + /* Register a STRING=>PROFILE GValueTransformFunc */ + g_value_register_transform_func (G_TYPE_STRING, g_define_type_id, + string_to_profile_transform); + /* Register gst-specific GValue functions */ + gst_value_register (&gstvtable); + + g_once_init_leave (&g_define_type_id__volatile, g_define_type_id); + } + return g_define_type_id__volatile; } static void @@ -828,3 +870,82 @@ gst_encoding_profile_get_type_nick (GstEncodingProfile * profile) return "audio"; return NULL; } + +/** + * gst_encoding_profile_find: + * @targetname: (transfer none): The name of the target + * @profilename: (transfer none): The name of the profile + * @category: (transfer none) (allow-none): The target category. Can be %NULL + * + * Find the #GstEncodingProfile with the specified name and category. + * + * Returns: (transfer full): The matching #GstEncodingProfile or %NULL. + */ +GstEncodingProfile * +gst_encoding_profile_find (const gchar * targetname, const gchar * profilename, + const gchar * category) +{ + GstEncodingProfile *res = NULL; + GstEncodingTarget *target; + + g_return_val_if_fail (targetname != NULL, NULL); + g_return_val_if_fail (profilename != NULL, NULL); + + /* FIXME : how do we handle profiles named the same in several + * categories but of which only one has the required profile ? */ + target = gst_encoding_target_load (targetname, category, NULL); + if (target) { + res = gst_encoding_target_get_profile (target, profilename); + gst_encoding_target_unref (target); + } + + return res; +} + +static GstEncodingProfile * +combo_search (const gchar * pname) +{ + GstEncodingProfile *res; + gchar **split; + + /* Splitup */ + split = g_strsplit (pname, "/", 2); + if (g_strv_length (split) != 2) + return NULL; + + res = gst_encoding_profile_find (split[0], split[1], NULL); + + g_strfreev (split); + + return res; +} + +/* GValue transform function */ +static void +string_to_profile_transform (const GValue * src_value, GValue * dest_value) +{ + const gchar *profilename; + GstEncodingProfile *profile; + + profilename = g_value_get_string (src_value); + + profile = combo_search (profilename); + + if (profile) + gst_value_take_mini_object (dest_value, (GstMiniObject *) profile); +} + +static gboolean +gst_encoding_profile_deserialize_valfunc (GValue * value, const gchar * s) +{ + GstEncodingProfile *profile; + + profile = combo_search (s); + + if (profile) { + gst_value_take_mini_object (value, (GstMiniObject *) profile); + return TRUE; + } + + return FALSE; +} diff --git a/gst-libs/gst/pbutils/encoding-profile.h b/gst-libs/gst/pbutils/encoding-profile.h index f455a60..69d3d63 100644 --- a/gst-libs/gst/pbutils/encoding-profile.h +++ b/gst-libs/gst/pbutils/encoding-profile.h @@ -147,6 +147,10 @@ GstCaps * gst_encoding_profile_get_output_caps (GstEncodingProfile *profile); const gchar *gst_encoding_profile_get_type_nick (GstEncodingProfile *profile); +GstEncodingProfile * gst_encoding_profile_find (const gchar *targetname, + const gchar *profilename, + const gchar *category); + /* GstEncodingContainerProfile API */ gboolean gst_encoding_container_profile_add_profile (GstEncodingContainerProfile *container, GstEncodingProfile *profile); @@ -178,7 +182,6 @@ void gst_encoding_video_profile_set_pass (GstEncodingVideoProfi guint pass); void gst_encoding_video_profile_set_variableframerate (GstEncodingVideoProfile *prof, gboolean variableframerate); - G_END_DECLS #endif /* __GST_PROFILE_H__ */ diff --git a/tests/check/libs/profile.c b/tests/check/libs/profile.c index fef3406..adedbba 100644 --- a/tests/check/libs/profile.c +++ b/tests/check/libs/profile.c @@ -325,22 +325,13 @@ GST_START_TEST (test_saving_profile) GST_END_TEST; -GST_START_TEST (test_loading_profile) +static void +test_individual_target (GstEncodingTarget * target) { - GstEncodingTarget *target; - gchar *profile_file_name; GstEncodingProfile *prof; GstCaps *tmpcaps, *tmpcaps2; GstEncodingProfile *sprof1, *sprof2; - profile_file_name = g_build_filename (g_get_home_dir (), ".gstreamer-0.10", - "profile", "TestProfile.profile", NULL); - - GST_DEBUG ("Loading target from '%s'", profile_file_name); - target = gst_encoding_target_load_from (profile_file_name, NULL); - g_free (profile_file_name); - fail_unless (target != NULL); - GST_DEBUG ("Checking the target properties"); /* Check the target */ fail_unless_equals_string (gst_encoding_target_get_name (target), @@ -396,8 +387,79 @@ GST_START_TEST (test_loading_profile) gst_encoding_profile_unref (sprof2); gst_caps_unref (tmpcaps); gst_caps_unref (tmpcaps2); +} + +GST_START_TEST (test_loading_profile) +{ + GstEncodingTarget *target; + gchar *profile_file_name; + GstEncodingProfile *profile; + GstCaps *tmpcaps; + GValue strvalue = { 0, }; + GValue miniobjectvalue = { 0, }; + /* Test loading using short method and all arguments */ + target = gst_encoding_target_load ("myponytarget", "herding", NULL); + fail_unless (target != NULL); + test_individual_target (target); gst_encoding_target_unref (target); + + /* Test loading using short method and no category */ + target = gst_encoding_target_load ("myponytarget", NULL, NULL); + fail_unless (target != NULL); + test_individual_target (target); + gst_encoding_target_unref (target); + + /* Test loading using fully specified path */ + profile_file_name = g_build_filename (g_get_home_dir (), ".gstreamer-0.10", + "encoding-profile", "herding", "myponytarget.gstprofile", NULL); + + GST_DEBUG ("Loading target from '%s'", profile_file_name); + target = gst_encoding_target_load_from (profile_file_name, NULL); + g_free (profile_file_name); + fail_unless (target != NULL); + test_individual_target (target); + gst_encoding_target_unref (target); + + /* Test getting the profiles directly + * First without category */ + profile = gst_encoding_profile_find ("myponytarget", "pony", NULL); + fail_unless (profile != NULL); + tmpcaps = gst_caps_from_string ("animal/x-pony"); + CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL, + 0, 0); + gst_caps_unref (tmpcaps); + gst_encoding_profile_unref (profile); + + /* Then with a specific category */ + profile = gst_encoding_profile_find ("myponytarget", "pony", "herding"); + fail_unless (profile != NULL); + tmpcaps = gst_caps_from_string ("animal/x-pony"); + CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL, + 0, 0); + gst_caps_unref (tmpcaps); + gst_encoding_profile_unref (profile); + + /* For my next trick, I will need the assistance of a GValue */ + g_value_init (&strvalue, G_TYPE_STRING); + g_value_init (&miniobjectvalue, GST_TYPE_ENCODING_PROFILE); + g_value_set_static_string (&strvalue, "myponytarget/pony"); + fail_unless (g_value_transform (&strvalue, &miniobjectvalue)); + profile = (GstEncodingProfile *) gst_value_dup_mini_object (&miniobjectvalue); + fail_if (profile == NULL); + g_value_unset (&strvalue); + g_value_unset (&miniobjectvalue); + tmpcaps = gst_caps_from_string ("animal/x-pony"); + CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL, + 0, 0); + gst_caps_unref (tmpcaps); + gst_encoding_profile_unref (profile); + + /* Let's go crazy for error detection */ + fail_if (gst_encoding_profile_find ("myponytarget", "whales", NULL)); + fail_if (gst_encoding_profile_find ("myponytarget", "whales", "herding")); + fail_if (gst_encoding_profile_find ("myponytarget", "", NULL)); + fail_if (gst_encoding_profile_find ("", "pony", NULL)); } GST_END_TEST; diff --git a/win32/common/libgstpbutils.def b/win32/common/libgstpbutils.def index d92c398..333bc68 100644 --- a/win32/common/libgstpbutils.def +++ b/win32/common/libgstpbutils.def @@ -65,6 +65,7 @@ EXPORTS gst_encoding_container_profile_get_profiles gst_encoding_container_profile_get_type gst_encoding_container_profile_new + gst_encoding_profile_find gst_encoding_profile_get_description gst_encoding_profile_get_format gst_encoding_profile_get_name