2010-08-13 15:27:52 +00:00
|
|
|
/* GStreamer unit test for gstprofile
|
|
|
|
*
|
|
|
|
* Copyright (C) <2009> Edward Hervey <edward.hervey@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-08-13 15:27:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* #include <fcntl.h> */
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gstdio.h>
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
#include <gst/pbutils/encoding-profile.h>
|
|
|
|
#include <gst/pbutils/encoding-target.h>
|
|
|
|
|
2012-04-04 17:41:34 +00:00
|
|
|
static inline gboolean
|
|
|
|
gst_caps_is_equal_unref (GstCaps * caps1, GstCaps * caps2)
|
|
|
|
{
|
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
ret = gst_caps_is_equal (caps1, caps2);
|
|
|
|
gst_caps_unref (caps1);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
#define CHECK_PROFILE(profile, name, description, format, preset, presence, restriction) \
|
|
|
|
{ \
|
|
|
|
fail_if(profile == NULL); \
|
|
|
|
fail_unless_equals_string (gst_encoding_profile_get_name (profile), name); \
|
|
|
|
fail_unless_equals_string (gst_encoding_profile_get_description (profile), description); \
|
2012-04-04 17:41:34 +00:00
|
|
|
fail_unless (gst_caps_is_equal_unref (gst_encoding_profile_get_format (profile), format)); \
|
2010-08-13 15:27:52 +00:00
|
|
|
fail_unless_equals_string (gst_encoding_profile_get_preset (profile), preset); \
|
|
|
|
fail_unless_equals_int (gst_encoding_profile_get_presence (profile), presence); \
|
2012-03-12 11:40:09 +00:00
|
|
|
if (restriction) \
|
2012-04-04 17:41:34 +00:00
|
|
|
fail_unless (gst_caps_is_equal_unref (gst_encoding_profile_get_restriction (profile), restriction)); \
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_profile_creation)
|
|
|
|
{
|
|
|
|
GstEncodingProfile *encprof;
|
|
|
|
GstEncodingAudioProfile *audioprof;
|
|
|
|
GstEncodingVideoProfile *videoprof;
|
|
|
|
GstCaps *ogg, *vorbis, *theora;
|
|
|
|
GstCaps *test1, *test2;
|
|
|
|
|
2011-10-27 15:33:06 +00:00
|
|
|
ogg = gst_caps_new_empty_simple ("application/ogg");
|
|
|
|
vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
|
|
|
|
theora = gst_caps_new_empty_simple ("video/x-theora");
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
encprof = (GstEncodingProfile *) gst_encoding_container_profile_new ((gchar *)
|
|
|
|
"ogg-theora-vorbis", "dumb-profile", ogg, (gchar *) "dumb-preset");
|
|
|
|
CHECK_PROFILE (encprof, "ogg-theora-vorbis", "dumb-profile", ogg,
|
|
|
|
"dumb-preset", 0, NULL);
|
|
|
|
|
|
|
|
audioprof = gst_encoding_audio_profile_new (vorbis, (gchar *) "HQ", NULL, 0);
|
|
|
|
CHECK_PROFILE ((GstEncodingProfile *) audioprof, NULL, NULL, vorbis, "HQ", 0,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
videoprof = gst_encoding_video_profile_new (theora, (gchar *) "HQ", NULL, 0);
|
|
|
|
CHECK_PROFILE ((GstEncodingProfile *) videoprof, NULL, NULL, theora, "HQ",
|
|
|
|
0, NULL);
|
|
|
|
|
|
|
|
fail_unless (gst_encoding_container_profile_add_profile (
|
|
|
|
(GstEncodingContainerProfile *) encprof,
|
|
|
|
(GstEncodingProfile *) audioprof));
|
|
|
|
fail_unless (gst_encoding_container_profile_add_profile (
|
|
|
|
(GstEncodingContainerProfile *) encprof,
|
|
|
|
(GstEncodingProfile *) videoprof));
|
|
|
|
|
|
|
|
/* Test caps */
|
|
|
|
test1 = gst_caps_from_string ("video/x-theora; audio/x-vorbis");
|
2011-01-05 21:02:35 +00:00
|
|
|
test2 = gst_encoding_profile_get_input_caps (encprof);
|
2010-08-13 15:27:52 +00:00
|
|
|
fail_unless (gst_caps_is_equal (test1, test2));
|
|
|
|
gst_caps_unref (test1);
|
|
|
|
gst_caps_unref (test2);
|
|
|
|
|
|
|
|
gst_encoding_profile_unref (encprof);
|
|
|
|
gst_caps_unref (ogg);
|
|
|
|
gst_caps_unref (theora);
|
|
|
|
gst_caps_unref (vorbis);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
|
2011-01-05 21:02:35 +00:00
|
|
|
GST_START_TEST (test_profile_input_caps)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
|
|
|
GstEncodingProfile *sprof;
|
|
|
|
GstCaps *vorbis;
|
|
|
|
GstCaps *out, *restriction, *test1;
|
|
|
|
|
2011-10-27 15:33:06 +00:00
|
|
|
vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
/* Simple case, no restriction */
|
|
|
|
sprof = (GstEncodingProfile *)
|
|
|
|
gst_encoding_audio_profile_new (vorbis, NULL, NULL, 0);
|
|
|
|
fail_if (sprof == NULL);
|
|
|
|
|
2011-01-05 21:02:35 +00:00
|
|
|
out = gst_encoding_profile_get_input_caps (sprof);
|
2010-08-13 15:27:52 +00:00
|
|
|
fail_if (out == NULL);
|
|
|
|
fail_unless (gst_caps_is_equal (out, vorbis));
|
|
|
|
gst_caps_unref (out);
|
|
|
|
gst_encoding_profile_unref (sprof);
|
|
|
|
|
|
|
|
/* One simple restriction */
|
2011-09-29 11:46:36 +00:00
|
|
|
restriction = gst_caps_from_string ("audio/x-raw,channels=2,rate=44100");
|
2010-08-13 15:27:52 +00:00
|
|
|
test1 = gst_caps_from_string ("audio/x-vorbis,channels=2,rate=44100");
|
|
|
|
fail_if (restriction == NULL);
|
|
|
|
|
|
|
|
sprof = (GstEncodingProfile *)
|
|
|
|
gst_encoding_audio_profile_new (vorbis, NULL, restriction, 0);
|
|
|
|
fail_if (sprof == NULL);
|
|
|
|
|
2011-01-05 21:02:35 +00:00
|
|
|
out = gst_encoding_profile_get_input_caps (sprof);
|
2010-08-13 15:27:52 +00:00
|
|
|
fail_if (out == NULL);
|
|
|
|
GST_DEBUG ("got caps %" GST_PTR_FORMAT, out);
|
|
|
|
fail_unless (gst_caps_is_equal (out, test1));
|
|
|
|
gst_caps_unref (out);
|
|
|
|
gst_caps_unref (restriction);
|
|
|
|
gst_caps_unref (test1);
|
|
|
|
gst_encoding_profile_unref (sprof);
|
|
|
|
|
|
|
|
gst_caps_unref (vorbis);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2010-12-21 15:33:50 +00:00
|
|
|
|
|
|
|
GST_START_TEST (test_target_naming)
|
|
|
|
{
|
|
|
|
GstEncodingTarget *target;
|
|
|
|
|
2011-09-05 13:51:25 +00:00
|
|
|
gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
|
|
|
|
|
2010-12-21 15:33:50 +00:00
|
|
|
/* NULL values */
|
|
|
|
ASSERT_CRITICAL (target = gst_encoding_target_new (NULL, NULL, NULL, NULL));
|
|
|
|
fail_if (target != NULL);
|
|
|
|
ASSERT_CRITICAL (target =
|
|
|
|
gst_encoding_target_new ("donkey", NULL, NULL, NULL));
|
|
|
|
fail_if (target != NULL);
|
|
|
|
ASSERT_CRITICAL (target =
|
|
|
|
gst_encoding_target_new (NULL, "donkey", NULL, NULL));
|
|
|
|
fail_if (target != NULL);
|
|
|
|
ASSERT_CRITICAL (target =
|
|
|
|
gst_encoding_target_new (NULL, NULL, "donkey", NULL));
|
|
|
|
fail_if (target != NULL);
|
|
|
|
|
|
|
|
/* Name and Category validation */
|
|
|
|
|
|
|
|
/* empty non-NULL strings */
|
|
|
|
fail_if (gst_encoding_target_new ("", "valid", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("valid", "", "description", NULL) != NULL);
|
|
|
|
|
|
|
|
/* don't start with a lower case ASCII character */
|
|
|
|
fail_if (gst_encoding_target_new ("A", "valid", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("3", "valid", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("-", "valid", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("!", "valid", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new (" ", "valid", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("valid", "A", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("valid", "3", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("valid", "-", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("valid", "!", "description", NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("valid", " ", "description", NULL) != NULL);
|
|
|
|
|
|
|
|
/* Starting with anything else is valid */
|
|
|
|
target = gst_encoding_target_new ("a", "valid", "description", NULL);
|
|
|
|
fail_if (target == NULL);
|
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
target = gst_encoding_target_new ("z", "valid", "description", NULL);
|
|
|
|
fail_if (target == NULL);
|
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
target = gst_encoding_target_new ("valid", "a", "description", NULL);
|
|
|
|
fail_if (target == NULL);
|
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
target = gst_encoding_target_new ("valid", "z", "description", NULL);
|
|
|
|
fail_if (target == NULL);
|
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
|
|
|
|
/* only inner valid characters are lower-case ASCII letters *OR* digits *OR* hyphens */
|
|
|
|
fail_if (gst_encoding_target_new ("aA", "valid", "description",
|
|
|
|
NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("a!", "valid", "description",
|
|
|
|
NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("space donkeys", "valid", "description",
|
|
|
|
NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("howaboutùnicode", "valid", "description",
|
|
|
|
NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("valid", "aA", "description",
|
|
|
|
NULL) != NULL);
|
|
|
|
fail_if (gst_encoding_target_new ("valid", "a!", "description",
|
|
|
|
NULL) != NULL);
|
|
|
|
|
|
|
|
target =
|
|
|
|
gst_encoding_target_new ("donkey-4-ever", "valid", "description", NULL);
|
|
|
|
fail_if (target == NULL);
|
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
target =
|
|
|
|
gst_encoding_target_new ("valid", "donkey-4-ever", "description", NULL);
|
|
|
|
fail_if (target == NULL);
|
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
static GstEncodingTarget *
|
2010-12-22 17:16:33 +00:00
|
|
|
create_saveload_target (const gchar * targetname)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
|
|
|
GstEncodingTarget *target;
|
|
|
|
GstEncodingProfile *profile, *sprof;
|
|
|
|
GstCaps *caps, *caps2;
|
|
|
|
|
|
|
|
GST_DEBUG ("Creating target");
|
|
|
|
|
2010-12-22 17:16:33 +00:00
|
|
|
target = gst_encoding_target_new (targetname, "herding",
|
2010-08-13 15:27:52 +00:00
|
|
|
"Plenty of pony glitter profiles", NULL);
|
|
|
|
caps = gst_caps_from_string ("animal/x-pony");
|
|
|
|
profile =
|
|
|
|
(GstEncodingProfile *) gst_encoding_container_profile_new ("pony",
|
|
|
|
"I don't want a description !", caps, NULL);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
gst_encoding_target_add_profile (target, profile);
|
|
|
|
|
|
|
|
caps = gst_caps_from_string ("audio/x-pony-song,pretty=True");
|
2011-09-29 11:46:36 +00:00
|
|
|
caps2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
|
2010-08-13 15:27:52 +00:00
|
|
|
sprof =
|
|
|
|
(GstEncodingProfile *) gst_encoding_audio_profile_new (caps, NULL, caps2,
|
|
|
|
1);
|
|
|
|
gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile *)
|
|
|
|
profile, sprof);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
gst_caps_unref (caps2);
|
|
|
|
|
|
|
|
caps = gst_caps_from_string ("video/x-glitter,sparkling=True");
|
|
|
|
caps2 =
|
2011-06-16 11:41:25 +00:00
|
|
|
gst_caps_from_string ("video/x-raw,width=640,height=480,framerate=15/1");
|
2010-08-13 15:27:52 +00:00
|
|
|
sprof = (GstEncodingProfile *)
|
|
|
|
gst_encoding_video_profile_new (caps, "seriously glittery", caps2, 0);
|
|
|
|
gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *)
|
|
|
|
sprof, TRUE);
|
|
|
|
gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile *)
|
|
|
|
profile, sprof);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
gst_caps_unref (caps2);
|
|
|
|
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2010-12-22 10:41:41 +00:00
|
|
|
GST_START_TEST (test_target_profile)
|
|
|
|
{
|
|
|
|
GstEncodingTarget *target;
|
|
|
|
GstEncodingProfile *prof;
|
|
|
|
|
2010-12-22 17:16:33 +00:00
|
|
|
target = create_saveload_target ("myponytarget");
|
2010-12-22 10:41:41 +00:00
|
|
|
|
|
|
|
/* NULL isn't a valid profile name */
|
|
|
|
ASSERT_CRITICAL (gst_encoding_target_get_profile (target, NULL));
|
|
|
|
|
|
|
|
/* try finding a profile that doesn't exist */
|
|
|
|
fail_if (gst_encoding_target_get_profile (target,
|
|
|
|
"no-really-does-not-exist"));
|
|
|
|
|
|
|
|
/* try finding a profile that exists */
|
|
|
|
prof = gst_encoding_target_get_profile (target, "pony");
|
|
|
|
fail_if (prof == NULL);
|
|
|
|
|
|
|
|
gst_encoding_profile_unref (prof);
|
|
|
|
gst_encoding_target_unref (target);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
GST_START_TEST (test_saving_profile)
|
|
|
|
{
|
|
|
|
GstEncodingTarget *orig, *loaded = NULL;
|
|
|
|
GstEncodingProfile *proforig, *profloaded;
|
|
|
|
gchar *profile_file_name;
|
|
|
|
|
|
|
|
/* Create and store a target */
|
2010-12-22 17:16:33 +00:00
|
|
|
orig = create_saveload_target ("myponytarget2");
|
|
|
|
GST_DEBUG ("Saving target 'myponytarget2'");
|
|
|
|
fail_unless (gst_encoding_target_save (orig, NULL));
|
2010-08-13 15:27:52 +00:00
|
|
|
|
|
|
|
/* Check we can load it */
|
2011-04-29 12:14:53 +00:00
|
|
|
profile_file_name =
|
2012-04-04 12:20:13 +00:00
|
|
|
g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
|
2011-01-03 15:07:49 +00:00
|
|
|
"encoding-profiles", "herding", "myponytarget2.gep", NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
GST_DEBUG ("Loading target from '%s'", profile_file_name);
|
2011-01-03 17:52:00 +00:00
|
|
|
loaded = gst_encoding_target_load_from_file (profile_file_name, NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
fail_unless (loaded != NULL);
|
|
|
|
g_free (profile_file_name);
|
|
|
|
|
|
|
|
GST_DEBUG ("Checking targets are equal");
|
|
|
|
/* Check targets are identical */
|
|
|
|
/* 1. at the target level */
|
|
|
|
fail_unless_equals_string (gst_encoding_target_get_name (orig),
|
|
|
|
gst_encoding_target_get_name (loaded));
|
|
|
|
fail_unless_equals_string (gst_encoding_target_get_category (orig),
|
|
|
|
gst_encoding_target_get_category (loaded));
|
|
|
|
fail_unless_equals_string (gst_encoding_target_get_description (orig),
|
|
|
|
gst_encoding_target_get_description (loaded));
|
|
|
|
fail_unless_equals_int (g_list_length ((GList *)
|
|
|
|
gst_encoding_target_get_profiles (loaded)), 1);
|
|
|
|
|
|
|
|
/* 2. at the profile level */
|
|
|
|
profloaded =
|
|
|
|
(GstEncodingProfile *) gst_encoding_target_get_profiles (loaded)->data;
|
|
|
|
proforig =
|
|
|
|
(GstEncodingProfile *) gst_encoding_target_get_profiles (orig)->data;
|
|
|
|
|
|
|
|
fail_unless_equals_int (G_TYPE_FROM_INSTANCE (profloaded),
|
|
|
|
G_TYPE_FROM_INSTANCE (proforig));
|
|
|
|
GST_DEBUG ("Comparing loaded:%p to original:%p", profloaded, proforig);
|
|
|
|
fail_unless (gst_encoding_profile_is_equal (profloaded, proforig));
|
|
|
|
|
|
|
|
gst_encoding_target_unref (orig);
|
|
|
|
gst_encoding_target_unref (loaded);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2010-12-22 17:18:00 +00:00
|
|
|
static void
|
|
|
|
test_individual_target (GstEncodingTarget * target)
|
2010-08-13 15:27:52 +00:00
|
|
|
{
|
|
|
|
GstEncodingProfile *prof;
|
|
|
|
GstCaps *tmpcaps, *tmpcaps2;
|
|
|
|
GstEncodingProfile *sprof1, *sprof2;
|
|
|
|
|
|
|
|
GST_DEBUG ("Checking the target properties");
|
|
|
|
/* Check the target */
|
|
|
|
fail_unless_equals_string (gst_encoding_target_get_name (target),
|
|
|
|
"myponytarget");
|
|
|
|
fail_unless_equals_string (gst_encoding_target_get_category (target),
|
|
|
|
"herding");
|
|
|
|
fail_unless_equals_string (gst_encoding_target_get_description (target),
|
|
|
|
"Plenty of pony glitter profiles");
|
|
|
|
|
|
|
|
GST_DEBUG ("Checking the number of profiles the target contains");
|
|
|
|
fail_unless_equals_int (g_list_length ((GList *)
|
|
|
|
gst_encoding_target_get_profiles (target)), 1);
|
|
|
|
|
|
|
|
|
|
|
|
GST_DEBUG ("Checking the container profile");
|
|
|
|
/* Check the profile */
|
|
|
|
prof = (GstEncodingProfile *) gst_encoding_target_get_profiles (target)->data;
|
|
|
|
tmpcaps = gst_caps_from_string ("animal/x-pony");
|
|
|
|
CHECK_PROFILE (prof, "pony", "I don't want a description !", tmpcaps, NULL, 0,
|
|
|
|
0);
|
|
|
|
gst_caps_unref (tmpcaps);
|
|
|
|
|
|
|
|
GST_DEBUG ("Checking the container profile has 2 stream profiles");
|
|
|
|
/* Check the stream profiles */
|
|
|
|
fail_unless_equals_int (g_list_length ((GList *)
|
|
|
|
gst_encoding_container_profile_get_profiles (
|
|
|
|
(GstEncodingContainerProfile *) prof)), 2);
|
|
|
|
|
|
|
|
GST_DEBUG ("Checking the container profile has the audio/x-pony-song stream");
|
|
|
|
tmpcaps = gst_caps_from_string ("audio/x-pony-song,pretty=True");
|
2011-09-29 11:46:36 +00:00
|
|
|
tmpcaps2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
|
2010-08-13 15:27:52 +00:00
|
|
|
sprof1 =
|
|
|
|
(GstEncodingProfile *) gst_encoding_audio_profile_new (tmpcaps, NULL,
|
|
|
|
tmpcaps2, 1);
|
|
|
|
fail_unless (gst_encoding_container_profile_contains_profile (
|
|
|
|
(GstEncodingContainerProfile *) prof, sprof1));
|
|
|
|
gst_encoding_profile_unref (sprof1);
|
|
|
|
gst_caps_unref (tmpcaps);
|
|
|
|
gst_caps_unref (tmpcaps2);
|
|
|
|
|
|
|
|
GST_DEBUG ("Checking the container profile has the video//x-glitter stream");
|
|
|
|
tmpcaps = gst_caps_from_string ("video/x-glitter,sparkling=True");
|
|
|
|
tmpcaps2 =
|
2011-06-16 11:41:25 +00:00
|
|
|
gst_caps_from_string ("video/x-raw,width=640,height=480,framerate=15/1");
|
2010-08-13 15:27:52 +00:00
|
|
|
sprof2 = (GstEncodingProfile *)
|
|
|
|
gst_encoding_video_profile_new (tmpcaps, "seriously glittery", tmpcaps2,
|
|
|
|
0);
|
|
|
|
gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *)
|
|
|
|
sprof2, TRUE);
|
|
|
|
fail_unless (gst_encoding_container_profile_contains_profile (
|
|
|
|
(GstEncodingContainerProfile *) prof, sprof2));
|
|
|
|
gst_encoding_profile_unref (sprof2);
|
|
|
|
gst_caps_unref (tmpcaps);
|
|
|
|
gst_caps_unref (tmpcaps2);
|
2010-12-22 17:18:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_loading_profile)
|
|
|
|
{
|
|
|
|
GstEncodingTarget *target;
|
|
|
|
gchar *profile_file_name;
|
|
|
|
GstEncodingProfile *profile;
|
|
|
|
GstCaps *tmpcaps;
|
|
|
|
GValue strvalue = { 0, };
|
2011-03-28 12:12:24 +00:00
|
|
|
GValue objectvalue = { 0, };
|
2010-12-22 17:18:00 +00:00
|
|
|
|
2011-09-05 13:51:25 +00:00
|
|
|
gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
|
|
|
|
|
2010-12-22 17:18:00 +00:00
|
|
|
/* 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 */
|
2011-04-29 12:14:53 +00:00
|
|
|
profile_file_name =
|
2012-04-04 12:20:13 +00:00
|
|
|
g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
|
2011-01-03 15:07:49 +00:00
|
|
|
"encoding-profiles", "herding", "myponytarget.gep", NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
|
2010-12-22 17:18:00 +00:00
|
|
|
GST_DEBUG ("Loading target from '%s'", profile_file_name);
|
2011-01-03 17:52:00 +00:00
|
|
|
target = gst_encoding_target_load_from_file (profile_file_name, NULL);
|
2010-12-22 17:18:00 +00:00
|
|
|
g_free (profile_file_name);
|
|
|
|
fail_unless (target != NULL);
|
|
|
|
test_individual_target (target);
|
2010-08-13 15:27:52 +00:00
|
|
|
gst_encoding_target_unref (target);
|
2010-12-22 17:18:00 +00:00
|
|
|
|
|
|
|
/* 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);
|
2011-03-28 12:12:24 +00:00
|
|
|
g_value_init (&objectvalue, GST_TYPE_ENCODING_PROFILE);
|
2010-12-22 17:18:00 +00:00
|
|
|
g_value_set_static_string (&strvalue, "myponytarget/pony");
|
2011-03-28 12:12:24 +00:00
|
|
|
fail_unless (g_value_transform (&strvalue, &objectvalue));
|
|
|
|
profile = (GstEncodingProfile *) g_value_dup_object (&objectvalue);
|
2010-12-22 17:18:00 +00:00
|
|
|
fail_if (profile == NULL);
|
|
|
|
g_value_unset (&strvalue);
|
2011-03-28 12:12:24 +00:00
|
|
|
g_value_unset (&objectvalue);
|
2010-12-22 17:18:00 +00:00
|
|
|
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));
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2011-01-03 12:20:19 +00:00
|
|
|
GST_START_TEST (test_target_list)
|
|
|
|
{
|
|
|
|
GList *categories;
|
|
|
|
GList *targets;
|
|
|
|
GList *tmp;
|
|
|
|
|
|
|
|
/* Make sure we get our test category in the available categories */
|
|
|
|
categories = gst_encoding_list_available_categories ();
|
|
|
|
fail_if (categories == NULL);
|
|
|
|
fail_if (g_list_find_custom (categories, "herding",
|
|
|
|
(GCompareFunc) g_strcmp0) == NULL);
|
|
|
|
g_list_foreach (categories, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (categories);
|
|
|
|
|
|
|
|
/* Try getting all available targets with a specified category */
|
|
|
|
targets = gst_encoding_list_all_targets ("herding");
|
|
|
|
fail_if (targets == NULL);
|
|
|
|
for (tmp = targets; tmp; tmp = tmp->next) {
|
|
|
|
GstEncodingTarget *target = (GstEncodingTarget *) tmp->data;
|
|
|
|
if (!g_strcmp0 (gst_encoding_target_get_name (target), "myponytarget"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* If tmp is NULL, it means we iterated the whole list without finding
|
|
|
|
* our target */
|
|
|
|
fail_if (tmp == NULL);
|
2011-03-28 16:17:45 +00:00
|
|
|
g_list_foreach (targets, (GFunc) g_object_unref, NULL);
|
2011-01-03 12:20:19 +00:00
|
|
|
g_list_free (targets);
|
|
|
|
|
|
|
|
/* Try getting all available targets without a specified category */
|
|
|
|
targets = gst_encoding_list_all_targets (NULL);
|
|
|
|
fail_if (targets == NULL);
|
|
|
|
for (tmp = targets; tmp; tmp = tmp->next) {
|
|
|
|
GstEncodingTarget *target = (GstEncodingTarget *) tmp->data;
|
|
|
|
if (!g_strcmp0 (gst_encoding_target_get_name (target), "myponytarget"))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* If tmp is NULL, it means we iterated the whole list without finding
|
|
|
|
* our target */
|
|
|
|
fail_if (tmp == NULL);
|
2011-03-28 16:17:45 +00:00
|
|
|
g_list_foreach (targets, (GFunc) g_object_unref, NULL);
|
2011-01-03 12:20:19 +00:00
|
|
|
g_list_free (targets);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
|
2010-08-13 15:27:52 +00:00
|
|
|
static const gchar *profile_string = "\
|
2011-01-18 10:40:29 +00:00
|
|
|
[GStreamer Encoding Target]\n\
|
2010-08-13 15:27:52 +00:00
|
|
|
name=myponytarget\n\
|
|
|
|
category=herding\n\
|
|
|
|
description=Plenty of pony glitter profiles\n\
|
|
|
|
\n\
|
|
|
|
[profile-pony1]\n\
|
|
|
|
name=pony\n\
|
|
|
|
type=container\n\
|
|
|
|
description=I don't want a description !\n\
|
|
|
|
format=animal/x-pony\n\
|
|
|
|
\n\
|
|
|
|
[streamprofile-pony11]\n\
|
|
|
|
parent=pony\n\
|
|
|
|
type=audio\n\
|
|
|
|
format=audio/x-pony-song,pretty=True\n\
|
2011-09-29 11:46:36 +00:00
|
|
|
restriction=audio/x-raw,channels=1,rate=44100\n\
|
2010-08-13 15:27:52 +00:00
|
|
|
presence=1\n\
|
|
|
|
\n\
|
|
|
|
[streamprofile-pony12]\n\
|
|
|
|
parent=pony\n\
|
|
|
|
type=video\n\
|
|
|
|
preset=seriously glittery\n\
|
|
|
|
format=video/x-glitter,sparkling=True\n\
|
2011-06-16 11:41:25 +00:00
|
|
|
restriction=video/x-raw,width=640,height=480,framerate=15/1\n\
|
2010-08-13 15:27:52 +00:00
|
|
|
presence=0\n\
|
|
|
|
variableframerate=true\n\
|
|
|
|
";
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_profile_file (void)
|
|
|
|
{
|
|
|
|
gchar *profile_file_name;
|
|
|
|
|
2011-04-29 12:14:53 +00:00
|
|
|
profile_file_name =
|
2012-04-04 12:20:13 +00:00
|
|
|
g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
|
2011-01-03 15:07:49 +00:00
|
|
|
"encoding-profiles", "herding", "myponytarget.gep", NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
g_unlink (profile_file_name);
|
|
|
|
g_free (profile_file_name);
|
2011-04-29 12:14:53 +00:00
|
|
|
profile_file_name =
|
2012-04-04 12:20:13 +00:00
|
|
|
g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
|
2011-01-03 15:07:49 +00:00
|
|
|
"encoding-profiles", "herding", "myponytarget2.gep", NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
g_unlink (profile_file_name);
|
|
|
|
g_free (profile_file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_profile_file (void)
|
|
|
|
{
|
|
|
|
gchar *profile_file_name;
|
|
|
|
gchar *profile_dir;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
profile_dir =
|
2012-04-04 12:20:13 +00:00
|
|
|
g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
|
2011-01-03 15:07:49 +00:00
|
|
|
"encoding-profiles", "herding", NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
profile_file_name =
|
2012-04-04 12:20:13 +00:00
|
|
|
g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
|
2011-01-03 15:07:49 +00:00
|
|
|
"encoding-profiles", "herding", "myponytarget.gep", NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
g_mkdir_with_parents (profile_dir, S_IRUSR | S_IWUSR | S_IXUSR);
|
|
|
|
if (!g_file_set_contents (profile_file_name, profile_string,
|
|
|
|
strlen (profile_string), &error))
|
|
|
|
GST_WARNING ("Couldn't write contents to file : %s", error->message);
|
|
|
|
g_free (profile_dir);
|
|
|
|
g_free (profile_file_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_setup (void)
|
|
|
|
{
|
|
|
|
create_profile_file ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_teardown (void)
|
|
|
|
{
|
|
|
|
remove_profile_file ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static Suite *
|
|
|
|
profile_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("profile support library");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
gboolean can_write;
|
|
|
|
gchar *gst_dir;
|
|
|
|
|
|
|
|
/* cehck if we can create profiles */
|
2012-04-04 12:20:13 +00:00
|
|
|
gst_dir = g_build_filename (g_get_user_data_dir (), "gstreamer-1.0", NULL);
|
2010-08-13 15:27:52 +00:00
|
|
|
can_write = (g_access (gst_dir, R_OK | W_OK | X_OK) == 0);
|
|
|
|
g_free (gst_dir);
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
|
|
|
|
tcase_add_test (tc_chain, test_profile_creation);
|
2011-01-05 21:02:35 +00:00
|
|
|
tcase_add_test (tc_chain, test_profile_input_caps);
|
2010-12-21 15:33:50 +00:00
|
|
|
tcase_add_test (tc_chain, test_target_naming);
|
2010-12-22 10:41:41 +00:00
|
|
|
tcase_add_test (tc_chain, test_target_profile);
|
2010-08-13 15:27:52 +00:00
|
|
|
if (can_write) {
|
|
|
|
tcase_add_test (tc_chain, test_loading_profile);
|
|
|
|
tcase_add_test (tc_chain, test_saving_profile);
|
2011-01-03 12:20:19 +00:00
|
|
|
tcase_add_test (tc_chain, test_target_list);
|
2010-08-13 15:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tcase_add_unchecked_fixture (tc_chain, test_setup, test_teardown);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_CHECK_MAIN (profile);
|