encoding-profile: Add convenience method to find a profile

API: gst_encoding_profile_find
This commit is contained in:
Edward Hervey 2010-12-22 18:18:00 +01:00 committed by Edward Hervey
parent d8f5b6322f
commit deea1eb83f
6 changed files with 204 additions and 15 deletions

View file

@ -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

View file

@ -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)

View file

@ -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)
gst_encoding_profile_class_intern_init (gpointer klass)
{
/* Nothing to initialize */
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;
}

View file

@ -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__ */

View file

@ -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;

View file

@ -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