From 1d40731e9dd779bd60a1c946e8f7c90c0d34c637 Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Wed, 17 Jul 2013 13:06:05 -0400 Subject: [PATCH] tests: integration: Refactor and make easier to add encoding profiles --- tests/check/ges/integration.c | 256 ++++++++++++++++++---------------- 1 file changed, 135 insertions(+), 121 deletions(-) diff --git a/tests/check/ges/integration.c b/tests/check/ges/integration.c index 29f5d6e934..dae05dc781 100644 --- a/tests/check/ges/integration.c +++ b/tests/check/ges/integration.c @@ -22,17 +22,18 @@ #include /* *INDENT-OFF* */ -static const char * const profile_specs[][3] = { - { "application/ogg", "audio/x-vorbis", "video/x-theora" }, - { "video/webm", "audio/x-vorbis", "video/x-vp8"}, +static const char * const profile_specs[][4] = { + { "application/ogg", "audio/x-vorbis", "video/x-theora", "ogv" }, + { "video/webm", "audio/x-vorbis", "video/x-vp8", "webm"}, }; /* *INDENT-ON* */ typedef enum { + PROFILE_NONE = -1, PROFILE_OGG, - PROFILE_MP4, -} PROFILE_TYPE; + PROFILE_WEBM, +} EncodingProfileName; typedef struct _PresetInfos { @@ -61,6 +62,7 @@ static gboolean got_async_done = FALSE; static const gchar *testfilename1 = NULL; static const gchar *testfilename2 = NULL; static const gchar *test_image_filename = NULL; +static EncodingProfileName current_profile = PROFILE_NONE; #define DEFAULT_PROFILE_TYPE PROFILE_MP4 #define DURATION_TOLERANCE 0.1 * GST_SECOND @@ -135,14 +137,14 @@ beach: } static GstEncodingProfile * -create_audio_video_profile (PROFILE_TYPE type) +create_audio_video_profile (EncodingProfileName type) { return create_profile (profile_specs[type][0], NULL, profile_specs[type][1], NULL, profile_specs[type][2], NULL); } /* This is used to specify a dot dumping after the target element started outputting buffers */ -static gchar *target_element = NULL; +static const gchar *target_element = NULL; static GstPadProbeReturn dump_to_dot (GstPad * pad, GstPadProbeInfo * info) @@ -207,6 +209,7 @@ get_position (void) &position); tmp = seeks; + GST_LOG ("Current position: %" GST_TIME_FORMAT, GST_TIME_ARGS (position)); while (tmp) { SeekInfo *seek = tmp->data; if ((position >= (seek->seeking_position - seek_tol)) @@ -234,57 +237,8 @@ get_position (void) } static gboolean -test_timeline_with_profile (GESTimeline * timeline, - PROFILE_TYPE profile_type, gboolean render) +check_rendered_file_properties (gchar * render_file, GstClockTime duration) { - GstEncodingProfile *profile; - GstBus *bus; - static gboolean ret; - gchar *uri = ges_test_file_name ("rendered.ogv"); - - ret = FALSE; - - ges_timeline_commit (timeline); - - profile = create_audio_video_profile (profile_type); - - pipeline = ges_timeline_pipeline_new (); - - if (render) - ges_timeline_pipeline_set_render_settings (pipeline, uri, profile); - - g_free (uri); - gst_object_unref (profile); - - if (render) - ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_RENDER); - - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_watch (bus, my_bus_callback, &ret); - gst_object_unref (bus); - - ges_timeline_pipeline_add_timeline (pipeline, timeline); - - gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); - gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, -1); - - if (seeks != NULL) - g_timeout_add (50, (GSourceFunc) get_position, NULL); - - g_main_loop_run (loop); - - gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); - gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, -1); - - gst_object_unref (pipeline); - - return ret; -} - -static gboolean -check_rendered_file_properties (GstClockTime duration) -{ - gchar *uri; GESUriClipAsset *asset; GstDiscovererInfo *info; GError *error = NULL; @@ -292,9 +246,8 @@ check_rendered_file_properties (GstClockTime duration) /* TODO: extend these tests */ - uri = ges_test_file_name ("rendered.ogv"); - asset = ges_uri_clip_asset_request_sync (uri, &error); - g_free (uri); + GST_INFO ("Checking rendered file: %s", render_file); + asset = ges_uri_clip_asset_request_sync (render_file, &error); info = ges_uri_clip_asset_get_info (GES_URI_CLIP_ASSET (asset)); gst_object_unref (asset); @@ -315,9 +268,65 @@ check_rendered_file_properties (GstClockTime duration) return TRUE; } +static gboolean +check_timeline (GESTimeline * timeline) +{ + GstBus *bus; + gint64 duration; + static gboolean ret; + GstEncodingProfile *profile; + gchar *render_uri = NULL; + + ret = FALSE; + + ges_timeline_commit (timeline); + pipeline = ges_timeline_pipeline_new (); + if (current_profile != PROFILE_NONE) { + gchar *filename = g_strdup_printf ("render.%s", + profile_specs[current_profile][3]); + + render_uri = ges_test_file_name (filename); + g_free (filename); + + profile = create_audio_video_profile (current_profile); + ges_timeline_pipeline_set_render_settings (pipeline, render_uri, profile); + ges_timeline_pipeline_set_mode (pipeline, TIMELINE_MODE_RENDER); + + gst_object_unref (profile); + } + + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_add_watch (bus, my_bus_callback, &ret); + gst_object_unref (bus); + + ges_timeline_pipeline_add_timeline (pipeline, timeline); + + gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); + gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, -1); + fail_unless (gst_element_query_duration (GST_ELEMENT (pipeline), + GST_FORMAT_TIME, &duration)); + + if (seeks != NULL) + g_timeout_add (50, (GSourceFunc) get_position, NULL); + + g_main_loop_run (loop); + + gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); + gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, -1); + + if (current_profile != PROFILE_NONE) { + fail_unless (check_rendered_file_properties (render_uri, duration)); + g_free (render_uri); + } + + gst_object_unref (pipeline); + + return ret; +} + /* Test seeking in various situations */ static void -run_simple_seeks_test (GESTimeline * timeline, gboolean render) +run_simple_seeks_test (GESTimeline * timeline) { GList *tmp; GESLayer *layer; @@ -354,7 +363,7 @@ run_simple_seeks_test (GESTimeline * timeline, gboolean render) g_list_append (seeks, new_seek_info (1.0 * GST_SECOND, 1.2 * GST_SECOND)); seeks = g_list_append (seeks, new_seek_info (1.5 * GST_SECOND, 1.8 * GST_SECOND)); - fail_unless (test_timeline_with_profile (timeline, PROFILE_OGG, FALSE)); + fail_unless (check_timeline (timeline)); if (seeks != NULL) { /* free failed seeks */ while (seeks) { @@ -373,38 +382,38 @@ run_simple_seeks_test (GESTimeline * timeline, gboolean render) } static void -test_seeking_audio (gboolean render) +test_seeking_audio (void) { GESTimeline *timeline = ges_timeline_new (); fail_unless (ges_timeline_add_track (timeline, GES_TRACK (ges_audio_track_new ()))); - run_simple_seeks_test (timeline, render); + run_simple_seeks_test (timeline); } static void -test_seeking_video (gboolean render) +test_seeking_video (void) { GESTimeline *timeline = ges_timeline_new (); fail_unless (ges_timeline_add_track (timeline, GES_TRACK (ges_video_track_new ()))); - run_simple_seeks_test (timeline, render); + run_simple_seeks_test (timeline); } static void -test_seeking (gboolean render) +test_seeking (void) { GESTimeline *timeline = ges_timeline_new_audio_video (); - run_simple_seeks_test (timeline, render); + run_simple_seeks_test (timeline); } /* Test adding an effect [E] marks the effect */ static void -test_effect (gboolean render) +test_effect (void) { GESTimeline *timeline; GESLayer *layer; @@ -439,13 +448,11 @@ test_effect (gboolean render) * time 0--------1 */ - fail_unless (test_timeline_with_profile (timeline, PROFILE_OGG, render)); - if (render) - fail_unless (check_rendered_file_properties (1 * GST_SECOND)); + fail_unless (check_timeline (timeline)); } static void -test_transition (gboolean render) +test_transition (void) { GESTimeline *timeline; GESLayer *layer; @@ -489,14 +496,11 @@ test_transition (gboolean render) * time 0------- 2 1--------3 */ - fail_unless (test_timeline_with_profile (timeline, PROFILE_OGG, render)); - - if (render) - fail_unless (check_rendered_file_properties (3 * GST_SECOND)); + fail_unless (check_timeline (timeline)); } static void -test_basic (gboolean render) +test_basic (void) { GESTimeline *timeline; GESLayer *layer; @@ -526,14 +530,11 @@ test_basic (gboolean render) * time 0--------1 */ - fail_unless (test_timeline_with_profile (timeline, PROFILE_OGG, render)); - - if (render) - fail_unless (check_rendered_file_properties (1 * GST_SECOND)); + fail_unless (check_timeline (timeline)); } static void -test_image (gboolean render) +test_image (void) { GESTimeline *timeline; GESLayer *layer; @@ -575,58 +576,76 @@ test_image (gboolean render) * time 0--------1 */ - fail_unless (test_timeline_with_profile (timeline, PROFILE_OGG, render)); - - if (render) - fail_unless (check_rendered_file_properties (1 * GST_SECOND)); + fail_unless (check_timeline (timeline)); } -#define CREATE_TEST(name, func, render) \ +#define CREATE_TEST(name, func, profile) \ GST_START_TEST (test_##name##_mov ) \ { \ testfilename1 = "test1.MOV"; \ testfilename2 = "test2.MOV"; \ - func (render); \ + current_profile = profile; \ + func (); \ } \ GST_END_TEST; \ GST_START_TEST (test_##name##_ogv ) \ { \ testfilename1 = "test1.ogv"; \ testfilename2 = "test2.ogv"; \ - func (render); \ + current_profile = profile; \ + func (); \ } \ GST_END_TEST; \ GST_START_TEST (test_##name##_webm ) \ { \ testfilename1 = "test1.webm"; \ testfilename2 = "test2.webm"; \ - func (render); \ + current_profile = profile; \ + func (); \ } \ GST_END_TEST; -#define ADD_TESTS(name) \ - tcase_add_test (tc_chain, test_##name##_webm); \ - tcase_add_test (tc_chain, test_##name##_ogv); \ - tcase_add_test (tc_chain, test_##name##_mov); \ +#define CREATE_TEST_FROM_NAMES(name, to, profile) \ + CREATE_TEST( name##to, test_##name, profile) +#define CREATE_RENDERING_TEST(name, func) \ + CREATE_TEST_FROM_NAMES(name, _render_to_ogg, PROFILE_OGG) \ + CREATE_TEST_FROM_NAMES(name, _render_to_webm, PROFILE_WEBM) + +#define CREATE_PLAYBACK_TEST(name) \ + CREATE_TEST_FROM_NAMES(name, _playback, PROFILE_NONE) + +#define CREATE_TEST_FULL(name) \ + CREATE_PLAYBACK_TEST(name) \ + CREATE_RENDERING_TEST(name, func) + +#define ADD_PLAYBACK_TESTS(name) \ + tcase_add_test (tc_chain, test_##name##_playback_webm); \ + tcase_add_test (tc_chain, test_##name##_playback_ogv); \ + tcase_add_test (tc_chain, test_##name##_playback_mov); \ + +#define ADD_RENDERING_TESTS(name) \ + tcase_add_test (tc_chain, test_##name##_render_to_ogg_mov); \ + tcase_add_test (tc_chain, test_##name##_render_to_ogg_webm); \ + tcase_add_test (tc_chain, test_##name##_render_to_ogg_ogv); \ + tcase_add_test (tc_chain, test_##name##_render_to_webm_webm); \ + tcase_add_test (tc_chain, test_##name##_render_to_webm_mov); \ + tcase_add_test (tc_chain, test_##name##_render_to_webm_ogv); + +#define ADD_TESTS(name) \ + ADD_PLAYBACK_TESTS(name) \ + ADD_RENDERING_TESTS(name) /* *INDENT-OFF* */ -CREATE_TEST(basic_playback, test_basic, FALSE) -CREATE_TEST(basic_render, test_basic, TRUE) +CREATE_TEST_FULL(basic) +CREATE_TEST_FULL(transition) +CREATE_TEST_FULL(effect) -CREATE_TEST(transition_playback, test_transition, FALSE) -CREATE_TEST(transition_render, test_transition, TRUE) - -CREATE_TEST(effect_playback, test_effect, FALSE) -CREATE_TEST(effect_render, test_effect, TRUE) - -CREATE_TEST(seeking_playback, test_seeking, FALSE) - -CREATE_TEST(seeking_playback_audio, test_seeking_audio, FALSE) -CREATE_TEST(seeking_playback_video, test_seeking_video, FALSE) - -CREATE_TEST(image_playback, test_image, FALSE) +CREATE_PLAYBACK_TEST(seeking) +CREATE_PLAYBACK_TEST(seeking_audio) +CREATE_PLAYBACK_TEST(seeking_video) +CREATE_PLAYBACK_TEST(image) /* *INDENT-ON* */ static Suite * @@ -637,20 +656,15 @@ ges_suite (void) suite_add_tcase (s, tc_chain); - ADD_TESTS (basic_playback); - ADD_TESTS (basic_render); + ADD_TESTS (basic); + ADD_TESTS (effect); + ADD_TESTS (transition); - ADD_TESTS (effect_render); - ADD_TESTS (effect_playback); + ADD_PLAYBACK_TESTS (image); - ADD_TESTS (transition_render); - ADD_TESTS (transition_playback); - - ADD_TESTS (image_playback); - - ADD_TESTS (seeking_playback); - ADD_TESTS (seeking_playback_audio); - ADD_TESTS (seeking_playback_video); + ADD_PLAYBACK_TESTS (seeking); + ADD_PLAYBACK_TESTS (seeking_audio); + ADD_PLAYBACK_TESTS (seeking_video); /* TODO : next test case : complex timeline created from project. */ /* TODO : deep checking of rendered clips */