3 * Copyright (C) 2014-2015 Sebastian Dröge <sebastian@centricular.com>
4 * Copyright (C) 2015 Brijesh Singh <brijesh.ksingh@gmail.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 * - start with pause, go to playing
25 * - set uri in play/pause
26 * - play/pause after eos
27 * - seek in play/pause/stopped, after eos, back to 0, after duration
36 # include <valgrind/valgrind.h>
39 #include <gst/check/gstcheck.h>
41 #define fail_unless_equals_int(a, b) \
45 fail_unless(first == second, \
46 "'" #a "' (%d) is not equal to '" #b"' (%d)", first, second); \
49 #define fail_unless_equals_uint64(a, b) \
53 fail_unless(first == second, \
54 "'" #a "' (%" G_GUINT64_FORMAT ") is not equal to '" #b"' (%" \
55 G_GUINT64_FORMAT ")", first, second); \
58 #define fail_unless_equals_double(a, b) \
62 fail_unless(first == second, \
63 "'" #a "' (%lf) is not equal to '" #b"' (%lf)", first, second); \
66 #include <gst/player/player.h>
68 START_TEST (test_create_and_free)
72 player = gst_player_new (NULL, NULL);
73 fail_unless (player != NULL);
74 g_object_unref (player);
79 START_TEST (test_set_and_get_uri)
84 player = gst_player_new (NULL, NULL);
86 fail_unless (player != NULL);
88 gst_player_set_uri (player, "file:///path/to/a/file");
89 uri = gst_player_get_uri (player);
91 fail_unless (g_strcmp0 (uri, "file:///path/to/a/file") == 0);
94 g_object_unref (player);
99 START_TEST (test_set_and_get_position_update_interval)
103 GstStructure *config;
105 player = gst_player_new (NULL, NULL);
107 fail_unless (player != NULL);
109 config = gst_player_get_config (player);
110 gst_player_config_set_position_update_interval (config, 500);
111 interval = gst_player_config_get_position_update_interval (config);
112 fail_unless (interval == 500);
113 gst_player_set_config (player, config);
115 g_object_unref (player);
122 STATE_CHANGE_BUFFERING,
123 STATE_CHANGE_DURATION_CHANGED,
124 STATE_CHANGE_END_OF_STREAM,
126 STATE_CHANGE_WARNING,
127 STATE_CHANGE_POSITION_UPDATED,
128 STATE_CHANGE_STATE_CHANGED,
129 STATE_CHANGE_VIDEO_DIMENSIONS_CHANGED,
130 STATE_CHANGE_MEDIA_INFO_UPDATED,
131 STATE_CHANGE_SEEK_DONE,
132 STATE_CHANGE_URI_LOADED,
133 } TestPlayerStateChange;
136 test_player_state_change_get_name (TestPlayerStateChange change)
139 case STATE_CHANGE_BUFFERING:
141 case STATE_CHANGE_DURATION_CHANGED:
142 return "duration-changed";
143 case STATE_CHANGE_END_OF_STREAM:
144 return "end-of-stream";
145 case STATE_CHANGE_WARNING:
147 case STATE_CHANGE_ERROR:
149 case STATE_CHANGE_POSITION_UPDATED:
150 return "position-updated";
151 case STATE_CHANGE_STATE_CHANGED:
152 return "state-changed";
153 case STATE_CHANGE_VIDEO_DIMENSIONS_CHANGED:
154 return "video-dimensions-changed";
155 case STATE_CHANGE_MEDIA_INFO_UPDATED:
156 return "media-info-updated";
157 case STATE_CHANGE_SEEK_DONE:
159 case STATE_CHANGE_URI_LOADED:
162 g_assert_not_reached ();
167 typedef struct _TestPlayerState TestPlayerState;
168 struct _TestPlayerState
172 gint buffering_percent;
173 guint64 position, duration, seek_done_position;
174 gboolean end_of_stream, error, warning, seek_done;
175 GstPlayerState state;
177 GstPlayerMediaInfo *media_info;
181 void (*test_callback) (GstPlayer * player, TestPlayerStateChange change,
182 TestPlayerState * old_state, TestPlayerState * new_state);
187 test_player_state_change_debug (GstPlayer * player,
188 TestPlayerStateChange change, TestPlayerState * old_state,
189 TestPlayerState * new_state)
191 GST_DEBUG_OBJECT (player, "Changed %s:\n"
192 "\tbuffering %d%% -> %d%%\n"
193 "\tposition %" GST_TIME_FORMAT " -> %" GST_TIME_FORMAT "\n"
194 "\tduration %" GST_TIME_FORMAT " -> %" GST_TIME_FORMAT "\n"
195 "\tseek position %" GST_TIME_FORMAT " -> %" GST_TIME_FORMAT "\n"
196 "\tend-of-stream %d -> %d\n"
198 "\tseek_done %d -> %d\n"
200 "\twidth/height %d/%d -> %d/%d\n"
201 "\tmedia_info %p -> %p\n"
202 "\turi_loaded %s -> %s",
203 test_player_state_change_get_name (change),
204 old_state->buffering_percent, new_state->buffering_percent,
205 GST_TIME_ARGS (old_state->position), GST_TIME_ARGS (new_state->position),
206 GST_TIME_ARGS (old_state->duration), GST_TIME_ARGS (new_state->duration),
207 GST_TIME_ARGS (old_state->seek_done_position),
208 GST_TIME_ARGS (new_state->seek_done_position), old_state->end_of_stream,
209 new_state->end_of_stream, old_state->error, new_state->error,
210 old_state->seek_done, new_state->seek_done,
211 gst_player_state_get_name (old_state->state),
212 gst_player_state_get_name (new_state->state), old_state->width,
213 old_state->height, new_state->width, new_state->height,
214 old_state->media_info, new_state->media_info,
215 old_state->uri_loaded, new_state->uri_loaded);
219 test_player_state_reset (TestPlayerState * state)
221 state->buffering_percent = 100;
222 state->position = state->duration = state->seek_done_position = -1;
223 state->end_of_stream = state->error = state->seek_done = FALSE;
224 state->state = GST_PLAYER_STATE_STOPPED;
225 state->width = state->height = 0;
226 state->media_info = NULL;
227 state->stopping = FALSE;
228 g_clear_pointer (&state->uri_loaded, g_free);
232 buffering_cb (GstPlayer * player, gint percent, TestPlayerState * state)
234 TestPlayerState old_state = *state;
236 g_assert (!state->stopping);
238 state->buffering_percent = percent;
239 test_player_state_change_debug (player, STATE_CHANGE_BUFFERING, &old_state,
241 state->test_callback (player, STATE_CHANGE_BUFFERING, &old_state, state);
245 duration_changed_cb (GstPlayer * player, guint64 duration,
246 TestPlayerState * state)
248 TestPlayerState old_state = *state;
250 g_assert (!state->stopping);
252 state->duration = duration;
253 test_player_state_change_debug (player, STATE_CHANGE_DURATION_CHANGED,
255 state->test_callback (player, STATE_CHANGE_DURATION_CHANGED, &old_state,
260 end_of_stream_cb (GstPlayer * player, TestPlayerState * state)
262 TestPlayerState old_state = *state;
264 g_assert (!state->stopping);
266 state->end_of_stream = TRUE;
267 test_player_state_change_debug (player, STATE_CHANGE_END_OF_STREAM,
269 state->test_callback (player, STATE_CHANGE_END_OF_STREAM, &old_state, state);
273 error_cb (GstPlayer * player, GError * error, TestPlayerState * state)
275 TestPlayerState old_state = *state;
277 g_assert (!state->stopping);
280 test_player_state_change_debug (player, STATE_CHANGE_ERROR, &old_state,
282 state->test_callback (player, STATE_CHANGE_ERROR, &old_state, state);
286 warning_cb (GstPlayer * player, GError * error, TestPlayerState * state)
288 TestPlayerState old_state = *state;
290 g_assert (!state->stopping);
292 state->warning = TRUE;
293 test_player_state_change_debug (player, STATE_CHANGE_WARNING, &old_state,
295 state->test_callback (player, STATE_CHANGE_WARNING, &old_state, state);
299 position_updated_cb (GstPlayer * player, guint64 position,
300 TestPlayerState * state)
302 TestPlayerState old_state = *state;
304 g_assert (!state->stopping);
306 state->position = position;
307 test_player_state_change_debug (player, STATE_CHANGE_POSITION_UPDATED,
309 state->test_callback (player, STATE_CHANGE_POSITION_UPDATED, &old_state,
314 media_info_updated_cb (GstPlayer * player, GstPlayerMediaInfo * media_info,
315 TestPlayerState * state)
317 TestPlayerState old_state = *state;
319 g_assert (!state->stopping);
321 state->media_info = media_info;
323 test_player_state_change_debug (player, STATE_CHANGE_MEDIA_INFO_UPDATED,
325 state->test_callback (player, STATE_CHANGE_MEDIA_INFO_UPDATED, &old_state,
330 state_changed_cb (GstPlayer * player, GstPlayerState player_state,
331 TestPlayerState * state)
333 TestPlayerState old_state = *state;
335 g_assert (!state->stopping || player_state == GST_PLAYER_STATE_STOPPED);
337 state->state = player_state;
339 if (player_state == GST_PLAYER_STATE_STOPPED)
340 test_player_state_reset (state);
342 test_player_state_change_debug (player, STATE_CHANGE_STATE_CHANGED,
344 state->test_callback (player, STATE_CHANGE_STATE_CHANGED, &old_state, state);
348 video_dimensions_changed_cb (GstPlayer * player, gint width, gint height,
349 TestPlayerState * state)
351 TestPlayerState old_state = *state;
353 g_assert (!state->stopping);
355 state->width = width;
356 state->height = height;
357 test_player_state_change_debug (player, STATE_CHANGE_VIDEO_DIMENSIONS_CHANGED,
359 state->test_callback (player, STATE_CHANGE_VIDEO_DIMENSIONS_CHANGED,
364 seek_done_cb (GstPlayer * player, guint64 position, TestPlayerState * state)
366 TestPlayerState old_state = *state;
368 g_assert (!state->stopping);
370 state->seek_done = TRUE;
371 state->seek_done_position = position;
372 test_player_state_change_debug (player, STATE_CHANGE_SEEK_DONE,
374 state->test_callback (player, STATE_CHANGE_SEEK_DONE, &old_state, state);
378 uri_loaded_cb (GstPlayer * player, const gchar * uri, TestPlayerState * state)
380 TestPlayerState old_state = *state;
382 state->uri_loaded = g_strdup (uri);
383 state->test_callback (player, STATE_CHANGE_URI_LOADED, &old_state, state);
387 test_player_new (TestPlayerState * state)
390 GstElement *playbin, *fakesink;
393 gst_player_new (NULL,
394 gst_player_g_main_context_signal_dispatcher_new (NULL));
395 fail_unless (player != NULL);
397 test_player_state_reset (state);
399 playbin = gst_player_get_pipeline (player);
400 fakesink = gst_element_factory_make ("fakesink", "audio-sink");
401 g_object_set (fakesink, "sync", TRUE, NULL);
402 g_object_set (playbin, "audio-sink", fakesink, NULL);
403 fakesink = gst_element_factory_make ("fakesink", "video-sink");
404 g_object_set (fakesink, "sync", TRUE, NULL);
405 g_object_set (playbin, "video-sink", fakesink, NULL);
406 gst_object_unref (playbin);
408 g_signal_connect (player, "buffering", G_CALLBACK (buffering_cb), state);
409 g_signal_connect (player, "duration-changed",
410 G_CALLBACK (duration_changed_cb), state);
411 g_signal_connect (player, "end-of-stream", G_CALLBACK (end_of_stream_cb),
413 g_signal_connect (player, "error", G_CALLBACK (error_cb), state);
414 g_signal_connect (player, "warning", G_CALLBACK (warning_cb), state);
415 g_signal_connect (player, "position-updated",
416 G_CALLBACK (position_updated_cb), state);
417 g_signal_connect (player, "state-changed", G_CALLBACK (state_changed_cb),
419 g_signal_connect (player, "media-info-updated",
420 G_CALLBACK (media_info_updated_cb), state);
421 g_signal_connect (player, "video-dimensions-changed",
422 G_CALLBACK (video_dimensions_changed_cb), state);
423 g_signal_connect (player, "seek-done", G_CALLBACK (seek_done_cb), state);
424 g_signal_connect (player, "uri-loaded", G_CALLBACK (uri_loaded_cb), state);
430 test_player_stopped_cb (GstPlayer * player, TestPlayerStateChange change,
431 TestPlayerState * old_state, TestPlayerState * new_state)
433 if (new_state->state == GST_PLAYER_STATE_STOPPED) {
434 g_main_loop_quit (new_state->loop);
439 stop_player (GstPlayer * player, TestPlayerState * state)
441 if (state->state != GST_PLAYER_STATE_STOPPED) {
442 /* Make sure all pending operations are finished so the player won't be
443 * appear as 'leaked' to leak detection tools. */
444 state->test_callback = test_player_stopped_cb;
445 gst_player_stop (player);
446 state->stopping = TRUE;
447 g_main_loop_run (state->loop);
452 test_play_audio_video_eos_cb (GstPlayer * player, TestPlayerStateChange change,
453 TestPlayerState * old_state, TestPlayerState * new_state)
455 gint step = GPOINTER_TO_INT (new_state->test_data);
458 video = ! !(step & 0x10);
459 step = (step & (~0x10));
463 fail_unless_equals_int (change, STATE_CHANGE_URI_LOADED);
465 fail_unless (g_str_has_suffix (new_state->uri_loaded,
466 "audio-video-short.ogg"));
468 fail_unless (g_str_has_suffix (new_state->uri_loaded,
470 new_state->test_data =
471 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
474 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
475 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_STOPPED);
476 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_BUFFERING);
477 new_state->test_data =
478 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
481 fail_unless_equals_int (change, STATE_CHANGE_MEDIA_INFO_UPDATED);
482 new_state->test_data =
483 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
486 fail_unless_equals_int (change, STATE_CHANGE_VIDEO_DIMENSIONS_CHANGED);
488 fail_unless_equals_int (new_state->width, 320);
489 fail_unless_equals_int (new_state->height, 240);
491 fail_unless_equals_int (new_state->width, 0);
492 fail_unless_equals_int (new_state->height, 0);
494 new_state->test_data =
495 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
498 fail_unless_equals_int (change, STATE_CHANGE_MEDIA_INFO_UPDATED);
499 new_state->test_data =
500 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
503 fail_unless_equals_int (change, STATE_CHANGE_DURATION_CHANGED);
504 fail_unless_equals_uint64 (new_state->duration,
505 G_GUINT64_CONSTANT (464399092));
506 new_state->test_data =
507 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
510 fail_unless_equals_int (change, STATE_CHANGE_POSITION_UPDATED);
511 fail_unless_equals_uint64 (new_state->position, G_GUINT64_CONSTANT (0));
512 new_state->test_data =
513 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
516 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
517 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_BUFFERING);
518 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_PLAYING);
519 new_state->test_data =
520 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
523 if (change == STATE_CHANGE_POSITION_UPDATED) {
524 fail_unless (old_state->position <= new_state->position);
526 fail_unless_equals_uint64 (old_state->position, old_state->duration);
527 fail_unless_equals_int (change, STATE_CHANGE_END_OF_STREAM);
528 new_state->test_data =
529 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
533 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
534 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_PLAYING);
535 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_STOPPED);
536 new_state->test_data =
537 GINT_TO_POINTER ((video ? 0x10 : 0x00) | (step + 1));
538 g_main_loop_quit (new_state->loop);
546 START_TEST (test_play_audio_eos)
549 TestPlayerState state;
552 memset (&state, 0, sizeof (state));
553 state.loop = g_main_loop_new (NULL, FALSE);
554 state.test_callback = test_play_audio_video_eos_cb;
555 state.test_data = GINT_TO_POINTER (0);
557 player = test_player_new (&state);
559 fail_unless (player != NULL);
561 uri = gst_filename_to_uri (TEST_PATH "/audio-short.ogg", NULL);
562 fail_unless (uri != NULL);
563 gst_player_set_uri (player, uri);
566 gst_player_play (player);
567 g_main_loop_run (state.loop);
569 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 10);
571 stop_player (player, &state);
572 g_object_unref (player);
573 g_main_loop_unref (state.loop);
579 test_audio_info (GstPlayerMediaInfo * media_info)
584 for (list = gst_player_media_info_get_audio_streams (media_info);
585 list != NULL; list = list->next) {
586 GstPlayerStreamInfo *stream = (GstPlayerStreamInfo *) list->data;
587 GstPlayerAudioInfo *audio_info = (GstPlayerAudioInfo *) stream;
589 fail_unless (gst_player_stream_info_get_tags (stream) != NULL);
590 fail_unless (gst_player_stream_info_get_caps (stream) != NULL);
591 fail_unless_equals_string (gst_player_stream_info_get_stream_type (stream),
595 fail_unless_equals_string (gst_player_stream_info_get_codec (stream),
596 "MPEG-1 Layer 3 (MP3)");
597 fail_unless_equals_int (gst_player_audio_info_get_sample_rate
598 (audio_info), 48000);
599 fail_unless_equals_int (gst_player_audio_info_get_channels (audio_info),
601 fail_unless_equals_int (gst_player_audio_info_get_max_bitrate
602 (audio_info), 192000);
603 fail_unless (gst_player_audio_info_get_language (audio_info) != NULL);
605 fail_unless_equals_string (gst_player_stream_info_get_codec (stream),
607 fail_unless_equals_int (gst_player_audio_info_get_sample_rate
608 (audio_info), 48000);
609 fail_unless_equals_int (gst_player_audio_info_get_channels (audio_info),
611 fail_unless (gst_player_audio_info_get_language (audio_info) != NULL);
619 test_video_info (GstPlayerMediaInfo * media_info)
623 for (list = gst_player_media_info_get_video_streams (media_info);
624 list != NULL; list = list->next) {
627 GstPlayerStreamInfo *stream = (GstPlayerStreamInfo *) list->data;
628 GstPlayerVideoInfo *video_info = (GstPlayerVideoInfo *) stream;
630 fail_unless (gst_player_stream_info_get_tags (stream) != NULL);
631 fail_unless (gst_player_stream_info_get_caps (stream) != NULL);
632 fail_unless_equals_int (gst_player_stream_info_get_index (stream), 0);
633 fail_unless (strstr (gst_player_stream_info_get_codec (stream),
635 || strstr (gst_player_stream_info_get_codec (stream), "H264") != NULL);
636 fail_unless_equals_int (gst_player_video_info_get_width (video_info), 320);
637 fail_unless_equals_int (gst_player_video_info_get_height (video_info), 240);
638 gst_player_video_info_get_framerate (video_info, &fps_n, &fps_d);
639 fail_unless_equals_int (fps_n, 24);
640 fail_unless_equals_int (fps_d, 1);
641 gst_player_video_info_get_pixel_aspect_ratio (video_info, &par_n, &par_d);
642 fail_unless_equals_int (par_n, 33);
643 fail_unless_equals_int (par_d, 20);
648 test_subtitle_info (GstPlayerMediaInfo * media_info)
652 for (list = gst_player_media_info_get_subtitle_streams (media_info);
653 list != NULL; list = list->next) {
654 GstPlayerStreamInfo *stream = (GstPlayerStreamInfo *) list->data;
655 GstPlayerSubtitleInfo *sub = (GstPlayerSubtitleInfo *) stream;
657 fail_unless_equals_string (gst_player_stream_info_get_stream_type (stream),
659 fail_unless (gst_player_stream_info_get_tags (stream) != NULL);
660 fail_unless (gst_player_stream_info_get_caps (stream) != NULL);
661 fail_unless_equals_string (gst_player_stream_info_get_codec (stream),
663 fail_unless (gst_player_subtitle_info_get_language (sub) != NULL);
668 test_media_info_object (GstPlayer * player, GstPlayerMediaInfo * media_info)
673 fail_unless (gst_player_media_info_is_seekable (media_info) == TRUE);
674 fail_unless (gst_player_media_info_get_tags (media_info) != NULL);
675 fail_unless_equals_string (gst_player_media_info_get_title (media_info),
677 fail_unless_equals_string (gst_player_media_info_get_container_format
678 (media_info), "Matroska");
679 fail_unless (gst_player_media_info_get_image_sample (media_info) == NULL);
680 fail_unless (strstr (gst_player_media_info_get_uri (media_info),
681 "sintel.mkv") != NULL);
683 /* number of streams */
684 list = gst_player_media_info_get_stream_list (media_info);
685 fail_unless (list != NULL);
686 fail_unless_equals_int (g_list_length (list), 10);
688 list = gst_player_media_info_get_video_streams (media_info);
689 fail_unless (list != NULL);
690 fail_unless_equals_int (g_list_length (list), 1);
692 list = gst_player_media_info_get_audio_streams (media_info);
693 fail_unless (list != NULL);
694 fail_unless_equals_int (g_list_length (list), 2);
696 list = gst_player_media_info_get_subtitle_streams (media_info);
697 fail_unless (list != NULL);
698 fail_unless_equals_int (g_list_length (list), 7);
701 test_subtitle_info (media_info);
704 test_audio_info (media_info);
707 test_video_info (media_info);
711 test_play_media_info_cb (GstPlayer * player, TestPlayerStateChange change,
712 TestPlayerState * old_state, TestPlayerState * new_state)
714 gint completed = GPOINTER_TO_INT (new_state->test_data);
716 if (change == STATE_CHANGE_MEDIA_INFO_UPDATED) {
717 test_media_info_object (player, new_state->media_info);
718 new_state->test_data = GINT_TO_POINTER (completed + 1);
719 g_main_loop_quit (new_state->loop);
720 } else if (change == STATE_CHANGE_END_OF_STREAM ||
721 change == STATE_CHANGE_ERROR) {
722 g_main_loop_quit (new_state->loop);
726 START_TEST (test_play_media_info)
729 TestPlayerState state;
732 memset (&state, 0, sizeof (state));
733 state.loop = g_main_loop_new (NULL, FALSE);
734 state.test_callback = test_play_media_info_cb;
735 state.test_data = GINT_TO_POINTER (0);
737 player = test_player_new (&state);
739 fail_unless (player != NULL);
741 uri = gst_filename_to_uri (TEST_PATH "/sintel.mkv", NULL);
742 fail_unless (uri != NULL);
743 gst_player_set_uri (player, uri);
746 gst_player_play (player);
747 g_main_loop_run (state.loop);
749 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 1);
750 stop_player (player, &state);
751 g_object_unref (player);
752 g_main_loop_unref (state.loop);
758 test_play_error_invalid_external_suburi_cb (GstPlayer * player,
759 TestPlayerStateChange change, TestPlayerState * old_state,
760 TestPlayerState * new_state)
762 gint steps = GPOINTER_TO_INT (new_state->test_data);
764 if (new_state->state == GST_PLAYER_STATE_PLAYING && !steps) {
767 suburi = gst_filename_to_uri (TEST_PATH "/foo.srt", NULL);
768 fail_unless (suburi != NULL);
770 new_state->test_data = GINT_TO_POINTER (steps + 1);
771 /* load invalid suburi */
772 gst_player_set_subtitle_uri (player, suburi);
775 } else if (steps && change == STATE_CHANGE_WARNING) {
776 new_state->test_data = GINT_TO_POINTER (steps + 1);
777 g_main_loop_quit (new_state->loop);
779 } else if (change == STATE_CHANGE_END_OF_STREAM ||
780 change == STATE_CHANGE_ERROR)
781 g_main_loop_quit (new_state->loop);
785 test_play_stream_disable_cb (GstPlayer * player,
786 TestPlayerStateChange change, TestPlayerState * old_state,
787 TestPlayerState * new_state)
789 gint steps = GPOINTER_TO_INT (new_state->test_data) & 0xf;
790 gint mask = GPOINTER_TO_INT (new_state->test_data) & 0xf0;
792 if (new_state->state == GST_PLAYER_STATE_PLAYING && !steps) {
793 new_state->test_data = GINT_TO_POINTER (0x10 + steps + 1);
794 gst_player_set_audio_track_enabled (player, FALSE);
796 } else if (mask == 0x10 && change == STATE_CHANGE_POSITION_UPDATED) {
797 GstPlayerAudioInfo *audio;
799 audio = gst_player_get_current_audio_track (player);
800 fail_unless (audio == NULL);
801 new_state->test_data = GINT_TO_POINTER (0x20 + steps + 1);
802 gst_player_set_subtitle_track_enabled (player, FALSE);
804 } else if (mask == 0x20 && change == STATE_CHANGE_POSITION_UPDATED) {
805 GstPlayerSubtitleInfo *sub;
807 sub = gst_player_get_current_subtitle_track (player);
808 fail_unless (sub == NULL);
809 new_state->test_data = GINT_TO_POINTER (0x30 + steps + 1);
810 g_main_loop_quit (new_state->loop);
812 } else if (change == STATE_CHANGE_END_OF_STREAM ||
813 change == STATE_CHANGE_ERROR) {
814 g_main_loop_quit (new_state->loop);
818 START_TEST (test_play_stream_disable)
821 TestPlayerState state;
824 memset (&state, 0, sizeof (state));
825 state.loop = g_main_loop_new (NULL, FALSE);
826 state.test_callback = test_play_stream_disable_cb;
827 state.test_data = GINT_TO_POINTER (0);
829 player = test_player_new (&state);
831 fail_unless (player != NULL);
833 uri = gst_filename_to_uri (TEST_PATH "/sintel.mkv", NULL);
834 fail_unless (uri != NULL);
835 gst_player_set_uri (player, uri);
838 gst_player_play (player);
839 g_main_loop_run (state.loop);
841 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 0x33);
843 stop_player (player, &state);
844 g_object_unref (player);
845 g_main_loop_unref (state.loop);
851 test_play_stream_switch_audio_cb (GstPlayer * player,
852 TestPlayerStateChange change, TestPlayerState * old_state,
853 TestPlayerState * new_state)
855 gint steps = GPOINTER_TO_INT (new_state->test_data);
857 if (new_state->state == GST_PLAYER_STATE_PLAYING && !steps) {
860 new_state->test_data = GINT_TO_POINTER (steps + 1);
861 ret = gst_player_set_audio_track (player, 1);
862 fail_unless_equals_int (ret, 1);
864 } else if (steps && change == STATE_CHANGE_POSITION_UPDATED) {
866 GstPlayerAudioInfo *audio;
868 audio = gst_player_get_current_audio_track (player);
869 fail_unless (audio != NULL);
870 index = gst_player_stream_info_get_index ((GstPlayerStreamInfo *) audio);
871 fail_unless_equals_int (index, 1);
872 g_object_unref (audio);
874 new_state->test_data = GINT_TO_POINTER (steps + 1);
875 g_main_loop_quit (new_state->loop);
877 } else if (change == STATE_CHANGE_END_OF_STREAM ||
878 change == STATE_CHANGE_ERROR) {
879 g_main_loop_quit (new_state->loop);
883 START_TEST (test_play_stream_switch_audio)
886 TestPlayerState state;
889 memset (&state, 0, sizeof (state));
890 state.loop = g_main_loop_new (NULL, FALSE);
891 state.test_callback = test_play_stream_switch_audio_cb;
892 state.test_data = GINT_TO_POINTER (0);
894 player = test_player_new (&state);
896 fail_unless (player != NULL);
898 uri = gst_filename_to_uri (TEST_PATH "/sintel.mkv", NULL);
899 fail_unless (uri != NULL);
900 gst_player_set_uri (player, uri);
903 gst_player_play (player);
904 g_main_loop_run (state.loop);
906 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
908 stop_player (player, &state);
909 g_object_unref (player);
910 g_main_loop_unref (state.loop);
916 test_play_stream_switch_subtitle_cb (GstPlayer * player,
917 TestPlayerStateChange change, TestPlayerState * old_state,
918 TestPlayerState * new_state)
920 gint steps = GPOINTER_TO_INT (new_state->test_data);
922 if (new_state->state == GST_PLAYER_STATE_PLAYING && !steps) {
925 new_state->test_data = GINT_TO_POINTER (steps + 1);
926 ret = gst_player_set_subtitle_track (player, 5);
927 fail_unless_equals_int (ret, 1);
929 } else if (steps && change == STATE_CHANGE_POSITION_UPDATED) {
931 GstPlayerSubtitleInfo *sub;
933 sub = gst_player_get_current_subtitle_track (player);
934 fail_unless (sub != NULL);
935 index = gst_player_stream_info_get_index ((GstPlayerStreamInfo *) sub);
936 fail_unless_equals_int (index, 5);
937 g_object_unref (sub);
939 new_state->test_data = GINT_TO_POINTER (steps + 1);
940 g_main_loop_quit (new_state->loop);
942 } else if (change == STATE_CHANGE_END_OF_STREAM ||
943 change == STATE_CHANGE_ERROR) {
944 g_main_loop_quit (new_state->loop);
948 START_TEST (test_play_stream_switch_subtitle)
951 TestPlayerState state;
954 memset (&state, 0, sizeof (state));
955 state.loop = g_main_loop_new (NULL, FALSE);
956 state.test_callback = test_play_stream_switch_subtitle_cb;
957 state.test_data = GINT_TO_POINTER (0);
959 player = test_player_new (&state);
961 fail_unless (player != NULL);
963 uri = gst_filename_to_uri (TEST_PATH "/sintel.mkv", NULL);
964 fail_unless (uri != NULL);
965 gst_player_set_uri (player, uri);
968 gst_player_play (player);
969 g_main_loop_run (state.loop);
971 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
973 stop_player (player, &state);
974 g_object_unref (player);
975 g_main_loop_unref (state.loop);
980 START_TEST (test_play_error_invalid_external_suburi)
983 TestPlayerState state;
986 memset (&state, 0, sizeof (state));
987 state.loop = g_main_loop_new (NULL, FALSE);
988 state.test_callback = test_play_error_invalid_external_suburi_cb;
989 state.test_data = GINT_TO_POINTER (0);
991 player = test_player_new (&state);
993 fail_unless (player != NULL);
995 uri = gst_filename_to_uri (TEST_PATH "/audio-video.ogg", NULL);
996 fail_unless (uri != NULL);
997 gst_player_set_uri (player, uri);
1000 gst_player_play (player);
1001 g_main_loop_run (state.loop);
1003 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
1005 stop_player (player, &state);
1006 g_object_unref (player);
1007 g_main_loop_unref (state.loop);
1013 has_subtitle_stream (TestPlayerState * new_state)
1015 if (gst_player_media_info_get_subtitle_streams (new_state->media_info))
1022 test_play_external_suburi_cb (GstPlayer * player,
1023 TestPlayerStateChange change, TestPlayerState * old_state,
1024 TestPlayerState * new_state)
1026 gint steps = GPOINTER_TO_INT (new_state->test_data);
1028 if (new_state->state == GST_PLAYER_STATE_PLAYING && !steps) {
1031 suburi = gst_filename_to_uri (TEST_PATH "/test_sub.srt", NULL);
1032 fail_unless (suburi != NULL);
1034 gst_player_set_subtitle_uri (player, suburi);
1036 new_state->test_data = GINT_TO_POINTER (steps + 1);
1038 } else if (change == STATE_CHANGE_MEDIA_INFO_UPDATED &&
1039 has_subtitle_stream (new_state)) {
1040 gchar *current_suburi, *suburi;
1042 current_suburi = gst_player_get_subtitle_uri (player);
1043 fail_unless (current_suburi != NULL);
1044 suburi = gst_filename_to_uri (TEST_PATH "/test_sub.srt", NULL);
1045 fail_unless (suburi != NULL);
1047 fail_unless_equals_int (g_strcmp0 (current_suburi, suburi), 0);
1049 g_free (current_suburi);
1051 new_state->test_data = GINT_TO_POINTER (steps + 1);
1052 g_main_loop_quit (new_state->loop);
1054 } else if (change == STATE_CHANGE_END_OF_STREAM ||
1055 change == STATE_CHANGE_ERROR)
1056 g_main_loop_quit (new_state->loop);
1059 START_TEST (test_play_external_suburi)
1062 TestPlayerState state;
1065 memset (&state, 0, sizeof (state));
1066 state.loop = g_main_loop_new (NULL, FALSE);
1067 state.test_callback = test_play_external_suburi_cb;
1068 state.test_data = GINT_TO_POINTER (0);
1070 player = test_player_new (&state);
1072 fail_unless (player != NULL);
1074 uri = gst_filename_to_uri (TEST_PATH "/audio-video.ogg", NULL);
1075 fail_unless (uri != NULL);
1076 gst_player_set_uri (player, uri);
1079 gst_player_play (player);
1080 g_main_loop_run (state.loop);
1082 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
1084 stop_player (player, &state);
1085 g_object_unref (player);
1086 g_main_loop_unref (state.loop);
1092 test_play_rate_cb (GstPlayer * player,
1093 TestPlayerStateChange change, TestPlayerState * old_state,
1094 TestPlayerState * new_state)
1096 gint steps = GPOINTER_TO_INT (new_state->test_data) & 0xf;
1097 gint mask = GPOINTER_TO_INT (new_state->test_data) & 0xf0;
1099 if (new_state->state == GST_PLAYER_STATE_PLAYING && !steps) {
1100 guint64 dur = -1, pos = -1;
1102 g_object_get (player, "position", &pos, "duration", &dur, NULL);
1103 pos = pos + dur * 0.2; /* seek 20% */
1104 gst_player_seek (player, pos);
1106 /* default rate should be 1.0 */
1107 fail_unless_equals_double (gst_player_get_rate (player), 1.0);
1108 new_state->test_data = GINT_TO_POINTER (mask + steps + 1);
1109 } else if (change == STATE_CHANGE_END_OF_STREAM ||
1110 change == STATE_CHANGE_ERROR) {
1111 g_main_loop_quit (new_state->loop);
1112 } else if (steps == 1 && change == STATE_CHANGE_SEEK_DONE) {
1114 gst_player_set_rate (player, 1.5);
1115 else if (mask == 0x20)
1116 gst_player_set_rate (player, -1.0);
1118 new_state->test_data = GINT_TO_POINTER (mask + steps + 1);
1119 } else if (steps && (change == STATE_CHANGE_POSITION_UPDATED)) {
1121 g_main_loop_quit (new_state->loop);
1123 if (mask == 0x10 && (new_state->position > old_state->position))
1124 new_state->test_data = GINT_TO_POINTER (mask + steps + 1);
1125 else if (mask == 0x20 && (new_state->position < old_state->position))
1126 new_state->test_data = GINT_TO_POINTER (mask + steps + 1);
1131 START_TEST (test_play_forward_rate)
1134 TestPlayerState state;
1137 memset (&state, 0, sizeof (state));
1138 state.loop = g_main_loop_new (NULL, FALSE);
1139 state.test_callback = test_play_rate_cb;
1140 state.test_data = GINT_TO_POINTER (0x10);
1142 player = test_player_new (&state);
1144 fail_unless (player != NULL);
1146 uri = gst_filename_to_uri (TEST_PATH "/audio.ogg", NULL);
1147 fail_unless (uri != NULL);
1148 gst_player_set_uri (player, uri);
1151 gst_player_play (player);
1152 g_main_loop_run (state.loop);
1154 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data) & 0xf, 10);
1156 stop_player (player, &state);
1157 g_object_unref (player);
1158 g_main_loop_unref (state.loop);
1163 START_TEST (test_play_backward_rate)
1166 TestPlayerState state;
1169 memset (&state, 0, sizeof (state));
1170 state.loop = g_main_loop_new (NULL, FALSE);
1171 state.test_callback = test_play_rate_cb;
1172 state.test_data = GINT_TO_POINTER (0x20);
1174 player = test_player_new (&state);
1176 fail_unless (player != NULL);
1178 uri = gst_filename_to_uri (TEST_PATH "/audio.ogg", NULL);
1179 fail_unless (uri != NULL);
1180 gst_player_set_uri (player, uri);
1183 gst_player_play (player);
1184 g_main_loop_run (state.loop);
1186 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data) & 0xf, 10);
1188 stop_player (player, &state);
1189 g_object_unref (player);
1190 g_main_loop_unref (state.loop);
1195 START_TEST (test_play_audio_video_eos)
1198 TestPlayerState state;
1201 memset (&state, 0, sizeof (state));
1202 state.loop = g_main_loop_new (NULL, FALSE);
1203 state.test_callback = test_play_audio_video_eos_cb;
1204 state.test_data = GINT_TO_POINTER (0x10);
1206 player = test_player_new (&state);
1208 fail_unless (player != NULL);
1210 uri = gst_filename_to_uri (TEST_PATH "/audio-video-short.ogg", NULL);
1211 fail_unless (uri != NULL);
1212 gst_player_set_uri (player, uri);
1215 gst_player_play (player);
1216 g_main_loop_run (state.loop);
1218 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data) & (~0x10), 10);
1220 stop_player (player, &state);
1221 g_object_unref (player);
1222 g_main_loop_unref (state.loop);
1228 test_play_error_invalid_uri_cb (GstPlayer * player,
1229 TestPlayerStateChange change, TestPlayerState * old_state,
1230 TestPlayerState * new_state)
1232 gint step = GPOINTER_TO_INT (new_state->test_data);
1236 fail_unless_equals_int (change, STATE_CHANGE_URI_LOADED);
1237 fail_unless_equals_string (new_state->uri_loaded, "foo://bar");
1238 new_state->test_data = GINT_TO_POINTER (step + 1);
1241 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
1242 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_STOPPED);
1243 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_BUFFERING);
1244 new_state->test_data = GINT_TO_POINTER (step + 1);
1247 fail_unless_equals_int (change, STATE_CHANGE_ERROR);
1248 new_state->test_data = GINT_TO_POINTER (step + 1);
1251 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
1252 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_BUFFERING);
1253 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_STOPPED);
1254 new_state->test_data = GINT_TO_POINTER (step + 1);
1255 g_main_loop_quit (new_state->loop);
1263 START_TEST (test_play_error_invalid_uri)
1266 TestPlayerState state;
1268 memset (&state, 0, sizeof (state));
1269 state.loop = g_main_loop_new (NULL, FALSE);
1270 state.test_callback = test_play_error_invalid_uri_cb;
1271 state.test_data = GINT_TO_POINTER (0);
1273 player = test_player_new (&state);
1275 fail_unless (player != NULL);
1277 gst_player_set_uri (player, "foo://bar");
1279 gst_player_play (player);
1280 g_main_loop_run (state.loop);
1282 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 4);
1284 stop_player (player, &state);
1285 g_object_unref (player);
1286 g_main_loop_unref (state.loop);
1292 test_play_error_invalid_uri_and_play_cb (GstPlayer * player,
1293 TestPlayerStateChange change, TestPlayerState * old_state,
1294 TestPlayerState * new_state)
1296 gint step = GPOINTER_TO_INT (new_state->test_data);
1301 fail_unless_equals_int (change, STATE_CHANGE_URI_LOADED);
1302 fail_unless_equals_string (new_state->uri_loaded, "foo://bar");
1303 new_state->test_data = GINT_TO_POINTER (step + 1);
1306 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
1307 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_STOPPED);
1308 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_BUFFERING);
1309 new_state->test_data = GINT_TO_POINTER (step + 1);
1312 fail_unless_equals_int (change, STATE_CHANGE_ERROR);
1313 new_state->test_data = GINT_TO_POINTER (step + 1);
1316 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
1317 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_BUFFERING);
1318 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_STOPPED);
1319 new_state->test_data = GINT_TO_POINTER (step + 1);
1321 uri = gst_filename_to_uri (TEST_PATH "/audio-short.ogg", NULL);
1322 fail_unless (uri != NULL);
1323 gst_player_set_uri (player, uri);
1326 gst_player_play (player);
1329 fail_unless_equals_int (change, STATE_CHANGE_URI_LOADED);
1330 fail_unless (g_str_has_suffix (new_state->uri_loaded, "audio-short.ogg"));
1331 new_state->test_data = GINT_TO_POINTER (step + 1);
1334 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
1335 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_STOPPED);
1336 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_BUFFERING);
1337 new_state->test_data = GINT_TO_POINTER (step + 1);
1340 fail_unless_equals_int (change, STATE_CHANGE_MEDIA_INFO_UPDATED);
1341 new_state->test_data = GINT_TO_POINTER (step + 1);
1344 fail_unless_equals_int (change, STATE_CHANGE_VIDEO_DIMENSIONS_CHANGED);
1345 fail_unless_equals_int (new_state->width, 0);
1346 fail_unless_equals_int (new_state->height, 0);
1347 new_state->test_data = GINT_TO_POINTER (step + 1);
1350 fail_unless_equals_int (change, STATE_CHANGE_MEDIA_INFO_UPDATED);
1351 new_state->test_data = GINT_TO_POINTER (step + 1);
1354 fail_unless_equals_int (change, STATE_CHANGE_DURATION_CHANGED);
1355 fail_unless_equals_uint64 (new_state->duration,
1356 G_GUINT64_CONSTANT (464399092));
1357 new_state->test_data = GINT_TO_POINTER (step + 1);
1360 fail_unless_equals_int (change, STATE_CHANGE_POSITION_UPDATED);
1361 fail_unless_equals_uint64 (new_state->position, G_GUINT64_CONSTANT (0));
1362 new_state->test_data = GINT_TO_POINTER (step + 1);
1365 fail_unless_equals_int (change, STATE_CHANGE_STATE_CHANGED);
1366 fail_unless_equals_int (old_state->state, GST_PLAYER_STATE_BUFFERING);
1367 fail_unless_equals_int (new_state->state, GST_PLAYER_STATE_PLAYING);
1368 new_state->test_data = GINT_TO_POINTER (step + 1);
1369 g_main_loop_quit (new_state->loop);
1377 START_TEST (test_play_error_invalid_uri_and_play)
1380 TestPlayerState state;
1382 memset (&state, 0, sizeof (state));
1383 state.loop = g_main_loop_new (NULL, FALSE);
1384 state.test_callback = test_play_error_invalid_uri_and_play_cb;
1385 state.test_data = GINT_TO_POINTER (0);
1387 player = test_player_new (&state);
1389 fail_unless (player != NULL);
1391 gst_player_set_uri (player, "foo://bar");
1393 gst_player_play (player);
1394 g_main_loop_run (state.loop);
1396 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 12);
1398 stop_player (player, &state);
1399 g_object_unref (player);
1400 g_main_loop_unref (state.loop);
1406 test_play_seek_done_cb (GstPlayer * player,
1407 TestPlayerStateChange change, TestPlayerState * old_state,
1408 TestPlayerState * new_state)
1410 gint step = GPOINTER_TO_INT (new_state->test_data) & (~0x10);
1412 if (new_state->state == GST_PLAYER_STATE_PLAYING && !step) {
1413 gst_player_seek (player, 0);
1414 new_state->test_data = GINT_TO_POINTER (step + 1);
1415 } else if (change == STATE_CHANGE_SEEK_DONE || change == STATE_CHANGE_ERROR) {
1416 fail_unless_equals_int (change, STATE_CHANGE_SEEK_DONE);
1417 fail_unless_equals_uint64 (new_state->seek_done_position,
1418 G_GUINT64_CONSTANT (0));
1419 new_state->test_data = GINT_TO_POINTER (step + 1);
1420 g_main_loop_quit (new_state->loop);
1424 START_TEST (test_play_audio_video_seek_done)
1427 TestPlayerState state;
1430 memset (&state, 0, sizeof (state));
1431 state.loop = g_main_loop_new (NULL, FALSE);
1432 state.test_callback = test_play_seek_done_cb;
1433 state.test_data = GINT_TO_POINTER (0);
1435 player = test_player_new (&state);
1437 fail_unless (player != NULL);
1439 uri = gst_filename_to_uri (TEST_PATH "/audio-video.ogg", NULL);
1440 fail_unless (uri != NULL);
1441 gst_player_set_uri (player, uri);
1444 gst_player_play (player);
1445 g_main_loop_run (state.loop);
1447 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data) & (~0x10), 2);
1449 stop_player (player, &state);
1450 g_object_unref (player);
1451 g_main_loop_unref (state.loop);
1457 test_play_position_update_interval_cb (GstPlayer * player,
1458 TestPlayerStateChange change, TestPlayerState * old_state,
1459 TestPlayerState * new_state)
1461 static gboolean do_quit = TRUE;
1462 static GstClockTime last_position = GST_CLOCK_TIME_NONE;
1464 gint steps = GPOINTER_TO_INT (new_state->test_data);
1466 if (new_state->state == GST_PLAYER_STATE_PLAYING && !steps) {
1467 new_state->test_data = GINT_TO_POINTER (steps + 1);
1468 } else if (steps && change == STATE_CHANGE_POSITION_UPDATED) {
1469 GstClockTime position = gst_player_get_position (player);
1470 new_state->test_data = GINT_TO_POINTER (steps + 1);
1472 if (GST_CLOCK_TIME_IS_VALID (last_position)) {
1473 GstClockTime interval = GST_CLOCK_DIFF (last_position, position);
1474 GST_DEBUG_OBJECT (player,
1475 "position update interval: %" GST_TIME_FORMAT "\n",
1476 GST_TIME_ARGS (interval));
1477 fail_unless (interval > (590 * GST_MSECOND)
1478 && interval < (610 * GST_MSECOND));
1481 last_position = position;
1483 if (do_quit && position >= 2000 * GST_MSECOND) {
1485 g_main_loop_quit (new_state->loop);
1487 } else if (change == STATE_CHANGE_END_OF_STREAM ||
1488 change == STATE_CHANGE_ERROR) {
1489 g_main_loop_quit (new_state->loop);
1494 quit_loop_cb (gpointer user_data)
1496 GMainLoop *loop = user_data;
1497 g_main_loop_quit (loop);
1499 return G_SOURCE_REMOVE;
1502 START_TEST (test_play_position_update_interval)
1505 TestPlayerState state;
1507 GstStructure *config;
1509 memset (&state, 0, sizeof (state));
1510 state.loop = g_main_loop_new (NULL, FALSE);
1511 state.test_callback = test_play_position_update_interval_cb;
1512 state.test_data = GINT_TO_POINTER (0);
1514 player = test_player_new (&state);
1516 config = gst_player_get_config (player);
1517 gst_player_config_set_position_update_interval (config, 600);
1518 gst_player_set_config (player, config);
1520 fail_unless (player != NULL);
1522 uri = gst_filename_to_uri (TEST_PATH "/sintel.mkv", NULL);
1523 fail_unless (uri != NULL);
1524 gst_player_set_uri (player, uri);
1527 gst_player_play (player);
1528 g_main_loop_run (state.loop);
1530 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 5);
1532 /* Disable position updates */
1533 gst_player_stop (player);
1535 config = gst_player_get_config (player);
1536 gst_player_config_set_position_update_interval (config, 0);
1537 gst_player_set_config (player, config);
1539 g_timeout_add (2000, quit_loop_cb, state.loop);
1540 g_main_loop_run (state.loop);
1542 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 5);
1544 stop_player (player, &state);
1545 g_object_unref (player);
1546 g_main_loop_unref (state.loop);
1552 test_restart_cb (GstPlayer * player,
1553 TestPlayerStateChange change, TestPlayerState * old_state,
1554 TestPlayerState * new_state)
1556 gint steps = GPOINTER_TO_INT (new_state->test_data);
1558 if (!steps && change == STATE_CHANGE_URI_LOADED) {
1559 fail_unless (g_str_has_suffix (new_state->uri_loaded, "sintel.mkv"));
1560 new_state->test_data = GINT_TO_POINTER (steps + 1);
1561 } else if (change == STATE_CHANGE_STATE_CHANGED
1562 && new_state->state == GST_PLAYER_STATE_BUFFERING) {
1563 new_state->test_data = GINT_TO_POINTER (steps + 1);
1564 g_main_loop_quit (new_state->loop);
1569 test_restart_cb2 (GstPlayer * player,
1570 TestPlayerStateChange change, TestPlayerState * old_state,
1571 TestPlayerState * new_state)
1573 gint steps = GPOINTER_TO_INT (new_state->test_data);
1575 if (!steps && change == STATE_CHANGE_URI_LOADED) {
1576 fail_unless (g_str_has_suffix (new_state->uri_loaded, "audio-short.ogg"));
1577 new_state->test_data = GINT_TO_POINTER (steps + 1);
1578 } else if (change == STATE_CHANGE_STATE_CHANGED
1579 && new_state->state == GST_PLAYER_STATE_BUFFERING) {
1580 new_state->test_data = GINT_TO_POINTER (steps + 1);
1581 g_main_loop_quit (new_state->loop);
1586 START_TEST (test_restart)
1589 TestPlayerState state;
1592 memset (&state, 0, sizeof (state));
1593 state.loop = g_main_loop_new (NULL, FALSE);
1594 state.test_callback = test_restart_cb;
1595 state.test_data = GINT_TO_POINTER (0);
1597 player = test_player_new (&state);
1599 fail_unless (player != NULL);
1601 uri = gst_filename_to_uri (TEST_PATH "/sintel.mkv", NULL);
1602 fail_unless (uri != NULL);
1603 gst_player_set_uri (player, uri);
1606 gst_player_play (player);
1607 g_main_loop_run (state.loop);
1608 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
1609 stop_player (player, &state);
1611 /* Try again with another URI */
1612 state.test_data = GINT_TO_POINTER (0);
1613 state.test_callback = test_restart_cb2;
1615 uri = gst_filename_to_uri (TEST_PATH "/audio-short.ogg", NULL);
1616 fail_unless (uri != NULL);
1617 gst_player_set_uri (player, uri);
1620 gst_player_play (player);
1621 g_main_loop_run (state.loop);
1622 fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
1623 stop_player (player, &state);
1625 g_object_unref (player);
1626 g_main_loop_unref (state.loop);
1631 #define TEST_USER_AGENT "test user agent"
1634 source_setup_cb (GstElement * playbin, GstElement * source, GMainLoop * loop)
1638 g_object_get (source, "user-agent", &user_agent, NULL);
1639 fail_unless_equals_string (user_agent, TEST_USER_AGENT);
1640 g_free (user_agent);
1642 g_main_loop_quit (loop);
1645 START_TEST (test_user_agent)
1649 GstElement *pipeline;
1650 GstStructure *config;
1653 loop = g_main_loop_new (NULL, FALSE);
1654 player = gst_player_new (NULL, NULL);
1655 fail_unless (player != NULL);
1657 gst_player_set_uri (player, "http://badger.com/test.mkv");
1659 config = gst_player_get_config (player);
1660 gst_player_config_set_user_agent (config, TEST_USER_AGENT);
1662 user_agent = gst_player_config_get_user_agent (config);
1663 fail_unless_equals_string (user_agent, TEST_USER_AGENT);
1664 g_free (user_agent);
1666 gst_player_set_config (player, config);
1668 pipeline = gst_player_get_pipeline (player);
1669 g_signal_connect (pipeline, "source-setup", G_CALLBACK (source_setup_cb),
1672 gst_player_pause (player);
1673 g_main_loop_run (loop);
1675 gst_object_unref (pipeline);
1677 g_object_unref (player);
1678 g_main_loop_unref (loop);
1686 Suite *s = suite_create ("GstPlayer");
1688 TCase *tc_general = tcase_create ("general");
1690 /* Use a longer timeout */
1691 #ifdef HAVE_VALGRIND
1692 if (RUNNING_ON_VALGRIND) {
1693 tcase_set_timeout (tc_general, 5 * 60);
1697 tcase_set_timeout (tc_general, 2 * 60);
1700 tcase_add_test (tc_general, test_create_and_free);
1701 tcase_add_test (tc_general, test_set_and_get_uri);
1702 tcase_add_test (tc_general, test_set_and_get_position_update_interval);
1704 /* Skip playback tests for now.
1705 * See https://bugzilla.gnome.org/show_bug.cgi?id=787374 */
1707 #ifdef HAVE_VALGRIND
1708 if (RUNNING_ON_VALGRIND) {
1712 tcase_skip_broken_test (tc_general, test_play_position_update_interval);
1714 tcase_skip_broken_test (tc_general, test_play_audio_eos);
1715 tcase_skip_broken_test (tc_general, test_play_audio_video_eos);
1716 tcase_skip_broken_test (tc_general, test_play_error_invalid_uri);
1717 tcase_skip_broken_test (tc_general, test_play_error_invalid_uri_and_play);
1718 tcase_skip_broken_test (tc_general, test_play_media_info);
1719 tcase_skip_broken_test (tc_general, test_play_stream_disable);
1720 tcase_skip_broken_test (tc_general, test_play_stream_switch_audio);
1721 tcase_skip_broken_test (tc_general, test_play_stream_switch_subtitle);
1722 tcase_skip_broken_test (tc_general, test_play_error_invalid_external_suburi);
1723 tcase_skip_broken_test (tc_general, test_play_external_suburi);
1724 tcase_skip_broken_test (tc_general, test_play_forward_rate);
1725 tcase_skip_broken_test (tc_general, test_play_backward_rate);
1726 tcase_skip_broken_test (tc_general, test_play_audio_video_seek_done);
1727 tcase_skip_broken_test (tc_general, test_restart);
1728 tcase_skip_broken_test (tc_general, test_user_agent);
1730 suite_add_tcase (s, tc_general);
1735 GST_CHECK_MAIN (player)