• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer unit test for gstprofile
2  *
3  * Copyright (C) <2009> Edward Hervey <edward.hervey@collabora.co.uk>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24 
25 #include <glib.h>
26 #include <glib/gstdio.h>
27 #include <gst/check/gstcheck.h>
28 
29 #include <gst/pbutils/encoding-profile.h>
30 #include <gst/pbutils/encoding-target.h>
31 #include <gst/pbutils/pbutils.h>
32 
33 #ifdef G_OS_UNIX
34 #include <unistd.h>             /* For R_OK etc. */
35 #endif
36 
37 static inline gboolean
gst_caps_is_equal_unref(GstCaps * caps1,GstCaps * caps2)38 gst_caps_is_equal_unref (GstCaps * caps1, GstCaps * caps2)
39 {
40   gboolean ret;
41 
42   ret = gst_caps_is_equal (caps1, caps2);
43   gst_caps_unref (caps1);
44 
45   return ret;
46 }
47 
48 #define CHECK_PROFILE(profile, name, description, format, preset, presence, restriction) \
49   {									\
50   fail_if(profile == NULL);						\
51   fail_unless_equals_string (gst_encoding_profile_get_name (profile), name); \
52   fail_unless_equals_string (gst_encoding_profile_get_description (profile), description); \
53   fail_unless (gst_caps_is_equal_unref (gst_encoding_profile_get_format (profile), format)); \
54   fail_unless_equals_string (gst_encoding_profile_get_preset (profile), preset); \
55   fail_unless_equals_int (gst_encoding_profile_get_presence (profile), presence); \
56   if (restriction) \
57     fail_unless (gst_caps_is_equal_unref (gst_encoding_profile_get_restriction (profile), restriction)); \
58   }
59 
GST_START_TEST(test_profile_creation)60 GST_START_TEST (test_profile_creation)
61 {
62   GstEncodingProfile *encprof;
63   GstEncodingAudioProfile *audioprof;
64   GstEncodingVideoProfile *videoprof;
65   GstCaps *ogg, *vorbis, *theora;
66   GstCaps *test1, *test2;
67 
68   ogg = gst_caps_new_empty_simple ("application/ogg");
69   vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
70   theora = gst_caps_new_empty_simple ("video/x-theora");
71 
72   encprof = (GstEncodingProfile *) gst_encoding_container_profile_new ((gchar *)
73       "ogg-theora-vorbis", "dumb-profile", ogg, (gchar *) "dumb-preset");
74   CHECK_PROFILE (encprof, "ogg-theora-vorbis", "dumb-profile", ogg,
75       "dumb-preset", 0, NULL);
76 
77   audioprof = gst_encoding_audio_profile_new (vorbis, (gchar *) "HQ", NULL, 0);
78   CHECK_PROFILE ((GstEncodingProfile *) audioprof, NULL, NULL, vorbis, "HQ", 0,
79       NULL);
80 
81   videoprof = gst_encoding_video_profile_new (theora, (gchar *) "HQ", NULL, 0);
82   CHECK_PROFILE ((GstEncodingProfile *) videoprof, NULL, NULL, theora, "HQ",
83       0, NULL);
84 
85   fail_unless (gst_encoding_container_profile_add_profile (
86           (GstEncodingContainerProfile *) encprof,
87           (GstEncodingProfile *) audioprof));
88   fail_unless (gst_encoding_container_profile_add_profile (
89           (GstEncodingContainerProfile *) encprof,
90           (GstEncodingProfile *) videoprof));
91 
92   /* Test caps */
93   test1 = gst_caps_from_string ("video/x-theora; audio/x-vorbis");
94   test2 = gst_encoding_profile_get_input_caps (encprof);
95   fail_unless (gst_caps_is_equal (test1, test2));
96   gst_caps_unref (test1);
97   gst_caps_unref (test2);
98 
99   gst_encoding_profile_unref (encprof);
100   gst_caps_unref (ogg);
101   gst_caps_unref (theora);
102   gst_caps_unref (vorbis);
103 }
104 
105 GST_END_TEST;
106 
107 
GST_START_TEST(test_profile_input_caps)108 GST_START_TEST (test_profile_input_caps)
109 {
110   GstEncodingProfile *sprof;
111   GstCaps *vorbis;
112   GstCaps *out, *restriction, *test1;
113 
114   vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
115 
116   /* Simple case, no restriction */
117   sprof = (GstEncodingProfile *)
118       gst_encoding_audio_profile_new (vorbis, NULL, NULL, 0);
119   fail_if (sprof == NULL);
120 
121   out = gst_encoding_profile_get_input_caps (sprof);
122   fail_if (out == NULL);
123   fail_unless (gst_caps_is_equal (out, vorbis));
124   gst_caps_unref (out);
125   gst_encoding_profile_unref (sprof);
126 
127   /* One simple restriction */
128   restriction = gst_caps_from_string ("audio/x-raw,channels=2,rate=44100");
129   test1 = gst_caps_from_string ("audio/x-vorbis,channels=2,rate=44100");
130   fail_if (restriction == NULL);
131 
132   sprof = (GstEncodingProfile *)
133       gst_encoding_audio_profile_new (vorbis, NULL, restriction, 0);
134   fail_if (sprof == NULL);
135 
136   out = gst_encoding_profile_get_input_caps (sprof);
137   fail_if (out == NULL);
138   GST_DEBUG ("got caps %" GST_PTR_FORMAT, out);
139   fail_unless (gst_caps_is_equal (out, test1));
140   gst_caps_unref (out);
141   gst_caps_unref (restriction);
142   gst_caps_unref (test1);
143   gst_encoding_profile_unref (sprof);
144 
145   gst_caps_unref (vorbis);
146 }
147 
148 GST_END_TEST;
149 
150 
GST_START_TEST(test_target_naming)151 GST_START_TEST (test_target_naming)
152 {
153   GstEncodingTarget *target;
154 
155   gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
156 
157   /* NULL values */
158   ASSERT_CRITICAL (target = gst_encoding_target_new (NULL, NULL, NULL, NULL));
159   fail_if (target != NULL);
160   ASSERT_CRITICAL (target =
161       gst_encoding_target_new ("donkey", NULL, NULL, NULL));
162   fail_if (target != NULL);
163   ASSERT_CRITICAL (target =
164       gst_encoding_target_new (NULL, "donkey", NULL, NULL));
165   fail_if (target != NULL);
166   ASSERT_CRITICAL (target =
167       gst_encoding_target_new (NULL, NULL, "donkey", NULL));
168   fail_if (target != NULL);
169 
170   /* Name and Category validation */
171 
172   /* empty non-NULL strings */
173   fail_if (gst_encoding_target_new ("", "valid", "description", NULL) != NULL);
174   fail_if (gst_encoding_target_new ("valid", "", "description", NULL) != NULL);
175 
176   /* don't start with a lower case ASCII character */
177   fail_if (gst_encoding_target_new ("A", "valid", "description", NULL) != NULL);
178   fail_if (gst_encoding_target_new ("3", "valid", "description", NULL) != NULL);
179   fail_if (gst_encoding_target_new ("-", "valid", "description", NULL) != NULL);
180   fail_if (gst_encoding_target_new ("!", "valid", "description", NULL) != NULL);
181   fail_if (gst_encoding_target_new (" ", "valid", "description", NULL) != NULL);
182   fail_if (gst_encoding_target_new ("valid", "A", "description", NULL) != NULL);
183   fail_if (gst_encoding_target_new ("valid", "3", "description", NULL) != NULL);
184   fail_if (gst_encoding_target_new ("valid", "-", "description", NULL) != NULL);
185   fail_if (gst_encoding_target_new ("valid", "!", "description", NULL) != NULL);
186   fail_if (gst_encoding_target_new ("valid", " ", "description", NULL) != NULL);
187 
188   /* Starting with anything else is valid */
189   target = gst_encoding_target_new ("a", "valid", "description", NULL);
190   fail_if (target == NULL);
191   gst_encoding_target_unref (target);
192   target = gst_encoding_target_new ("z", "valid", "description", NULL);
193   fail_if (target == NULL);
194   gst_encoding_target_unref (target);
195   target = gst_encoding_target_new ("valid", "a", "description", NULL);
196   fail_if (target == NULL);
197   gst_encoding_target_unref (target);
198   target = gst_encoding_target_new ("valid", "z", "description", NULL);
199   fail_if (target == NULL);
200   gst_encoding_target_unref (target);
201 
202   /* only inner valid characters are lower-case ASCII letters *OR* digits *OR* hyphens */
203   fail_if (gst_encoding_target_new ("aA", "valid", "description",
204           NULL) != NULL);
205   fail_if (gst_encoding_target_new ("a!", "valid", "description",
206           NULL) != NULL);
207   fail_if (gst_encoding_target_new ("space donkeys", "valid", "description",
208           NULL) != NULL);
209   fail_if (gst_encoding_target_new ("howaboutùnicode", "valid", "description",
210           NULL) != NULL);
211   fail_if (gst_encoding_target_new ("valid", "aA", "description",
212           NULL) != NULL);
213   fail_if (gst_encoding_target_new ("valid", "a!", "description",
214           NULL) != NULL);
215 
216   target =
217       gst_encoding_target_new ("donkey-4-ever", "valid", "description", NULL);
218   fail_if (target == NULL);
219   gst_encoding_target_unref (target);
220   target =
221       gst_encoding_target_new ("valid", "donkey-4-ever", "description", NULL);
222   fail_if (target == NULL);
223   gst_encoding_target_unref (target);
224 
225 }
226 
227 GST_END_TEST;
228 
229 static GstEncodingTarget *
create_saveload_target(const gchar * targetname)230 create_saveload_target (const gchar * targetname)
231 {
232   GstEncodingTarget *target;
233   GstEncodingProfile *profile, *sprof;
234   GstCaps *caps, *caps2;
235 
236   GST_DEBUG ("Creating target");
237 
238   target = gst_encoding_target_new (targetname, "herding",
239       "Plenty of pony glitter profiles", NULL);
240   caps = gst_caps_from_string ("animal/x-pony");
241   profile =
242       (GstEncodingProfile *) gst_encoding_container_profile_new ("pony",
243       "I don't want a description !", caps, NULL);
244   gst_caps_unref (caps);
245   gst_encoding_target_add_profile (target, profile);
246 
247   caps = gst_caps_from_string ("audio/x-pony-song,pretty=True");
248   caps2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
249   sprof =
250       (GstEncodingProfile *) gst_encoding_audio_profile_new (caps, NULL, caps2,
251       1);
252   gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile *)
253       profile, sprof);
254   gst_caps_unref (caps);
255   gst_caps_unref (caps2);
256 
257   caps = gst_caps_from_string ("video/x-glitter,sparkling=True");
258   caps2 =
259       gst_caps_from_string ("video/x-raw,width=640,height=480,framerate=15/1");
260   sprof = (GstEncodingProfile *)
261       gst_encoding_video_profile_new (caps, "seriously glittery", caps2, 0);
262   gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *)
263       sprof, TRUE);
264   gst_encoding_container_profile_add_profile ((GstEncodingContainerProfile *)
265       profile, sprof);
266   gst_caps_unref (caps);
267   gst_caps_unref (caps2);
268 
269   return target;
270 }
271 
GST_START_TEST(test_target_profile)272 GST_START_TEST (test_target_profile)
273 {
274   GstEncodingTarget *target;
275   GstEncodingProfile *prof;
276 
277   target = create_saveload_target ("myponytarget");
278 
279   /* NULL isn't a valid profile name */
280   ASSERT_CRITICAL (gst_encoding_target_get_profile (target, NULL));
281 
282   /* try finding a profile that doesn't exist */
283   fail_if (gst_encoding_target_get_profile (target,
284           "no-really-does-not-exist"));
285 
286   /* try finding a profile that exists */
287   prof = gst_encoding_target_get_profile (target, "pony");
288   fail_if (prof == NULL);
289 
290   gst_encoding_profile_unref (prof);
291   gst_encoding_target_unref (target);
292 }
293 
294 GST_END_TEST;
295 
GST_START_TEST(test_saving_profile)296 GST_START_TEST (test_saving_profile)
297 {
298   GstEncodingTarget *orig, *loaded = NULL;
299   GstEncodingProfile *proforig, *profloaded;
300   gchar *profile_file_name;
301 
302   /* Create and store a target */
303   orig = create_saveload_target ("myponytarget2");
304   GST_DEBUG ("Saving target 'myponytarget2'");
305   fail_unless (gst_encoding_target_save (orig, NULL));
306 
307   /* Check we can load it */
308   profile_file_name =
309       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
310       "encoding-profiles", "herding", "myponytarget2.gep", NULL);
311   GST_DEBUG ("Loading target from '%s'", profile_file_name);
312   loaded = gst_encoding_target_load_from_file (profile_file_name, NULL);
313   fail_unless (loaded != NULL);
314   g_free (profile_file_name);
315 
316   GST_DEBUG ("Checking targets are equal");
317   /* Check targets are identical */
318   /* 1. at the target level */
319   fail_unless_equals_string (gst_encoding_target_get_name (orig),
320       gst_encoding_target_get_name (loaded));
321   fail_unless_equals_string (gst_encoding_target_get_category (orig),
322       gst_encoding_target_get_category (loaded));
323   fail_unless_equals_string (gst_encoding_target_get_description (orig),
324       gst_encoding_target_get_description (loaded));
325   fail_unless_equals_int (g_list_length ((GList *)
326           gst_encoding_target_get_profiles (loaded)), 1);
327 
328   /* 2. at the profile level */
329   profloaded =
330       (GstEncodingProfile *) gst_encoding_target_get_profiles (loaded)->data;
331   proforig =
332       (GstEncodingProfile *) gst_encoding_target_get_profiles (orig)->data;
333 
334   fail_unless_equals_int (G_TYPE_FROM_INSTANCE (profloaded),
335       G_TYPE_FROM_INSTANCE (proforig));
336   GST_DEBUG ("Comparing loaded:%p to original:%p", profloaded, proforig);
337   fail_unless (gst_encoding_profile_is_equal (profloaded, proforig));
338 
339   gst_encoding_target_unref (orig);
340   gst_encoding_target_unref (loaded);
341 }
342 
343 GST_END_TEST;
344 
345 static void
test_individual_target(GstEncodingTarget * target)346 test_individual_target (GstEncodingTarget * target)
347 {
348   GstEncodingProfile *prof;
349   GstCaps *tmpcaps, *tmpcaps2;
350   GstEncodingProfile *sprof1, *sprof2;
351 
352   GST_DEBUG ("Checking the target properties");
353   /* Check the target  */
354   fail_unless_equals_string (gst_encoding_target_get_name (target),
355       "myponytarget");
356   fail_unless_equals_string (gst_encoding_target_get_category (target),
357       "herding");
358   fail_unless_equals_string (gst_encoding_target_get_description (target),
359       "Plenty of pony glitter profiles");
360 
361   GST_DEBUG ("Checking the number of profiles the target contains");
362   fail_unless_equals_int (g_list_length ((GList *)
363           gst_encoding_target_get_profiles (target)), 1);
364 
365 
366   GST_DEBUG ("Checking the container profile");
367   /* Check the profile */
368   prof = (GstEncodingProfile *) gst_encoding_target_get_profiles (target)->data;
369   tmpcaps = gst_caps_from_string ("animal/x-pony");
370   CHECK_PROFILE (prof, "pony", "I don't want a description !", tmpcaps, NULL, 0,
371       0);
372   gst_caps_unref (tmpcaps);
373 
374   GST_DEBUG ("Checking the container profile has 2 stream profiles");
375   /* Check the stream profiles */
376   fail_unless_equals_int (g_list_length ((GList *)
377           gst_encoding_container_profile_get_profiles (
378               (GstEncodingContainerProfile *) prof)), 2);
379 
380   GST_DEBUG ("Checking the container profile has the audio/x-pony-song stream");
381   tmpcaps = gst_caps_from_string ("audio/x-pony-song,pretty=True");
382   tmpcaps2 = gst_caps_from_string ("audio/x-raw,channels=1,rate=44100");
383   sprof1 =
384       (GstEncodingProfile *) gst_encoding_audio_profile_new (tmpcaps, NULL,
385       tmpcaps2, 1);
386   fail_unless (gst_encoding_container_profile_contains_profile (
387           (GstEncodingContainerProfile *) prof, sprof1));
388   gst_encoding_profile_unref (sprof1);
389   gst_caps_unref (tmpcaps);
390   gst_caps_unref (tmpcaps2);
391 
392   GST_DEBUG ("Checking the container profile has the video//x-glitter stream");
393   tmpcaps = gst_caps_from_string ("video/x-glitter,sparkling=True");
394   tmpcaps2 =
395       gst_caps_from_string ("video/x-raw,width=640,height=480,framerate=15/1");
396   sprof2 = (GstEncodingProfile *)
397       gst_encoding_video_profile_new (tmpcaps, "seriously glittery", tmpcaps2,
398       0);
399   gst_encoding_video_profile_set_variableframerate ((GstEncodingVideoProfile *)
400       sprof2, TRUE);
401   fail_unless (gst_encoding_container_profile_contains_profile (
402           (GstEncodingContainerProfile *) prof, sprof2));
403   gst_encoding_profile_unref (sprof2);
404   gst_caps_unref (tmpcaps);
405   gst_caps_unref (tmpcaps2);
406 }
407 
GST_START_TEST(test_loading_profile)408 GST_START_TEST (test_loading_profile)
409 {
410   GstEncodingTarget *target;
411   gchar *profile_file_name;
412   GstEncodingProfile *profile;
413   GstCaps *tmpcaps;
414   GValue strvalue = { 0, };
415   GValue objectvalue = { 0, };
416 
417   gst_debug_set_threshold_for_name ("default", GST_LEVEL_NONE);
418 
419   /* Test loading using short method and all arguments */
420   target = gst_encoding_target_load ("myponytarget", "herding", NULL);
421   fail_unless (target != NULL);
422   test_individual_target (target);
423   gst_encoding_target_unref (target);
424 
425   /* Test loading using short method and no category */
426   target = gst_encoding_target_load ("myponytarget", NULL, NULL);
427   fail_unless (target != NULL);
428   test_individual_target (target);
429   gst_encoding_target_unref (target);
430 
431   /* Test loading using fully specified path */
432   profile_file_name =
433       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
434       "encoding-profiles", "herding", "myponytarget.gep", NULL);
435 
436   GST_DEBUG ("Loading target from '%s'", profile_file_name);
437   target = gst_encoding_target_load_from_file (profile_file_name, NULL);
438   g_free (profile_file_name);
439   fail_unless (target != NULL);
440   test_individual_target (target);
441   gst_encoding_target_unref (target);
442 
443   /* Test getting the profiles directly
444    * First without category */
445   profile = gst_encoding_profile_find ("myponytarget", "pony", NULL);
446   fail_unless (profile != NULL);
447   tmpcaps = gst_caps_from_string ("animal/x-pony");
448   CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
449       0, 0);
450   gst_caps_unref (tmpcaps);
451   gst_encoding_profile_unref (profile);
452 
453   /* Then with a specific category */
454   profile = gst_encoding_profile_find ("myponytarget", "pony", "herding");
455   fail_unless (profile != NULL);
456   tmpcaps = gst_caps_from_string ("animal/x-pony");
457   CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
458       0, 0);
459   gst_caps_unref (tmpcaps);
460   gst_encoding_profile_unref (profile);
461 
462   /* For my next trick, I will need the assistance of a GValue */
463   g_value_init (&strvalue, G_TYPE_STRING);
464   g_value_init (&objectvalue, GST_TYPE_ENCODING_PROFILE);
465   g_value_set_static_string (&strvalue, "myponytarget/pony");
466   fail_unless (g_value_transform (&strvalue, &objectvalue));
467   profile = (GstEncodingProfile *) g_value_dup_object (&objectvalue);
468   fail_if (profile == NULL);
469   g_value_unset (&strvalue);
470   g_value_unset (&objectvalue);
471   tmpcaps = gst_caps_from_string ("animal/x-pony");
472   CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
473       0, 0);
474   gst_caps_unref (tmpcaps);
475   gst_encoding_profile_unref (profile);
476 
477   /* Let's go crazy for error detection */
478   fail_if (gst_encoding_profile_find ("myponytarget", "whales", NULL));
479   fail_if (gst_encoding_profile_find ("myponytarget", "whales", "herding"));
480   fail_if (gst_encoding_profile_find ("myponytarget", "", NULL));
481   fail_if (gst_encoding_profile_find ("", "pony", NULL));
482 }
483 
484 GST_END_TEST;
485 
GST_START_TEST(test_target_list)486 GST_START_TEST (test_target_list)
487 {
488   GList *categories;
489   GList *targets;
490   GList *tmp;
491 
492   /* Make sure we get our test category in the available categories */
493   categories = gst_encoding_list_available_categories ();
494   fail_if (categories == NULL);
495   fail_if (g_list_find_custom (categories, "herding",
496           (GCompareFunc) g_strcmp0) == NULL);
497   g_list_foreach (categories, (GFunc) g_free, NULL);
498   g_list_free (categories);
499 
500   /* Try getting all available targets with a specified category */
501   targets = gst_encoding_list_all_targets ("herding");
502   fail_if (targets == NULL);
503   for (tmp = targets; tmp; tmp = tmp->next) {
504     GstEncodingTarget *target = (GstEncodingTarget *) tmp->data;
505     if (!g_strcmp0 (gst_encoding_target_get_name (target), "myponytarget"))
506       break;
507   }
508   /* If tmp is NULL, it means we iterated the whole list without finding
509    * our target */
510   fail_if (tmp == NULL);
511   g_list_foreach (targets, (GFunc) g_object_unref, NULL);
512   g_list_free (targets);
513 
514   /* Try getting all available targets without a specified category */
515   targets = gst_encoding_list_all_targets (NULL);
516   fail_if (targets == NULL);
517   for (tmp = targets; tmp; tmp = tmp->next) {
518     GstEncodingTarget *target = (GstEncodingTarget *) tmp->data;
519     if (!g_strcmp0 (gst_encoding_target_get_name (target), "myponytarget"))
520       break;
521   }
522   /* If tmp is NULL, it means we iterated the whole list without finding
523    * our target */
524   fail_if (tmp == NULL);
525   g_list_foreach (targets, (GFunc) g_object_unref, NULL);
526   g_list_free (targets);
527 }
528 
529 GST_END_TEST;
530 
531 
532 static const gchar *profile_string = "\
533 [GStreamer Encoding Target]\n\
534 name=myponytarget\n\
535 category=herding\n\
536 description=Plenty of pony glitter profiles\n\
537 \n\
538 [profile-pony1]\n\
539 name=pony\n\
540 type=container\n\
541 description=I don't want a description !\n\
542 format=animal/x-pony\n\
543 \n\
544 [streamprofile-pony11]\n\
545 parent=pony\n\
546 type=audio\n\
547 format=audio/x-pony-song,pretty=True\n\
548 restriction=audio/x-raw,channels=1,rate=44100\n\
549 presence=1\n\
550 \n\
551 [streamprofile-pony12]\n\
552 parent=pony\n\
553 type=video\n\
554 preset=seriously glittery\n\
555 format=video/x-glitter,sparkling=True\n\
556 restriction=video/x-raw,width=640,height=480,framerate=15/1\n\
557 presence=0\n\
558 variableframerate=true\n\
559 ";
560 
561 static void
remove_profile_file(void)562 remove_profile_file (void)
563 {
564   gchar *profile_file_name;
565 
566   profile_file_name =
567       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
568       "encoding-profiles", "herding", "myponytarget.gep", NULL);
569   g_unlink (profile_file_name);
570   g_free (profile_file_name);
571   profile_file_name =
572       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
573       "encoding-profiles", "herding", "myponytarget2.gep", NULL);
574   g_unlink (profile_file_name);
575   g_free (profile_file_name);
576 }
577 
578 static void
create_profile_file(void)579 create_profile_file (void)
580 {
581   gchar *profile_file_name;
582   gchar *profile_dir;
583   GError *error = NULL;
584 
585   profile_dir =
586       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
587       "encoding-profiles", "herding", NULL);
588   profile_file_name =
589       g_build_filename (g_get_user_data_dir (), "gstreamer-1.0",
590       "encoding-profiles", "herding", "myponytarget.gep", NULL);
591 
592   /* on Windows it will ignore the mode anyway */
593 #ifdef G_OS_WIN32
594   g_mkdir_with_parents (profile_dir, 0700);
595 #else
596   g_mkdir_with_parents (profile_dir, S_IRUSR | S_IWUSR | S_IXUSR);
597 #endif
598 
599   if (!g_file_set_contents (profile_file_name, profile_string,
600           strlen (profile_string), &error))
601     GST_WARNING ("Couldn't write contents to file : %s", error->message);
602   g_free (profile_dir);
603   g_free (profile_file_name);
604 }
605 
606 static void
test_setup(void)607 test_setup (void)
608 {
609   create_profile_file ();
610 }
611 
612 static void
test_teardown(void)613 test_teardown (void)
614 {
615   remove_profile_file ();
616 }
617 
GST_START_TEST(test_file_extension)618 GST_START_TEST (test_file_extension)
619 {
620   GstEncodingContainerProfile *cprof;
621   GstCaps *ogg, *speex, *vorbis, *theora, *id3, *mp3;
622 
623   /* 1 - ogg variants */
624   ogg = gst_caps_new_empty_simple ("application/ogg");
625   cprof = gst_encoding_container_profile_new ("myprofile", NULL, ogg, NULL);
626   gst_caps_unref (ogg);
627 
628   fail_unless_equals_string (gst_encoding_profile_get_file_extension
629       (GST_ENCODING_PROFILE (cprof)), "ogg");
630 
631   speex = gst_caps_new_empty_simple ("audio/x-speex");
632   gst_encoding_container_profile_add_profile (cprof,
633       (GstEncodingProfile *) gst_encoding_audio_profile_new (speex, NULL,
634           NULL, 1));
635   gst_caps_unref (speex);
636 
637   fail_unless_equals_string (gst_encoding_profile_get_file_extension
638       (GST_ENCODING_PROFILE (cprof)), "spx");
639 
640   vorbis = gst_caps_new_empty_simple ("audio/x-vorbis");
641   gst_encoding_container_profile_add_profile (cprof,
642       (GstEncodingProfile *) gst_encoding_audio_profile_new (vorbis, NULL,
643           NULL, 1));
644   gst_caps_unref (vorbis);
645 
646   fail_unless_equals_string (gst_encoding_profile_get_file_extension
647       (GST_ENCODING_PROFILE (cprof)), "ogg");
648 
649   theora = gst_caps_new_empty_simple ("video/x-theora");
650   gst_encoding_container_profile_add_profile (cprof,
651       (GstEncodingProfile *) gst_encoding_video_profile_new (theora, NULL,
652           NULL, 1));
653   gst_caps_unref (theora);
654 
655   fail_unless_equals_string (gst_encoding_profile_get_file_extension
656       (GST_ENCODING_PROFILE (cprof)), "ogv");
657 
658   gst_encoding_profile_unref (cprof);
659 
660   /* 2 - tag container */
661   id3 = gst_caps_new_empty_simple ("application/x-id3");
662   cprof = gst_encoding_container_profile_new ("myprofile", NULL, id3, NULL);
663   gst_caps_unref (id3);
664 
665   fail_unless (gst_encoding_profile_get_file_extension (GST_ENCODING_PROFILE
666           (cprof)) == NULL);
667 
668   mp3 = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1,
669       "layer", G_TYPE_INT, 3, NULL);
670   gst_encoding_container_profile_add_profile (cprof,
671       (GstEncodingProfile *) gst_encoding_audio_profile_new (mp3, NULL,
672           NULL, 1));
673   gst_caps_unref (mp3);
674 
675   fail_unless_equals_string (gst_encoding_profile_get_file_extension
676       (GST_ENCODING_PROFILE (cprof)), "mp3");
677 
678   gst_encoding_profile_unref (cprof);
679 }
680 
681 GST_END_TEST;
682 
683 static Suite *
profile_suite(void)684 profile_suite (void)
685 {
686   Suite *s = suite_create ("profile support library");
687   TCase *tc_chain = tcase_create ("general");
688   gboolean can_write;
689 
690   /* check if we can create profiles */
691 #ifdef G_OS_UNIX
692   {
693     gchar *gst_dir =
694         g_build_filename (g_get_user_data_dir (), "gstreamer-1.0", NULL);
695     can_write = (g_access (gst_dir, R_OK | W_OK | X_OK) == 0);
696     g_free (gst_dir);
697   }
698 #else
699   can_write = FALSE;            /* FIXME: fix can_write test on Windows */
700 #endif
701 
702   gst_pb_utils_init ();
703 
704   suite_add_tcase (s, tc_chain);
705 
706   tcase_add_test (tc_chain, test_profile_creation);
707   tcase_add_test (tc_chain, test_profile_input_caps);
708   tcase_add_test (tc_chain, test_target_naming);
709   tcase_add_test (tc_chain, test_target_profile);
710   tcase_add_test (tc_chain, test_file_extension);
711   if (can_write) {
712     tcase_add_test (tc_chain, test_loading_profile);
713     tcase_add_test (tc_chain, test_saving_profile);
714     tcase_add_test (tc_chain, test_target_list);
715   }
716 
717   tcase_add_unchecked_fixture (tc_chain, test_setup, test_teardown);
718 
719   return s;
720 }
721 
722 GST_CHECK_MAIN (profile);
723