summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2016-05-25 15:01:31 +0200
committerSebastian Dröge <sebastian@centricular.com>2016-05-30 12:43:22 +0300
commit0467923415893eb817994d252befac5d8c8d87c1 (patch)
tree081f097596524db8896541dc4c0216e2ba46680f /tests
parentb00f0d0180267fe767edc320d39d2d9c84f619fa (diff)
downloadgstreamer-plugins-bad-0467923415893eb817994d252befac5d8c8d87c1.tar.gz
player: inhibit signals after gst_player_stop() has been called
Also wait for the state change to STOP to have been announced before destroying the player so it won't appear as leaked by leak detector tools. https://bugzilla.gnome.org/show_bug.cgi?id=766607
Diffstat (limited to 'tests')
-rw-r--r--tests/check/libs/player.c139
1 files changed, 139 insertions, 0 deletions
diff --git a/tests/check/libs/player.c b/tests/check/libs/player.c
index a63ed9901..52a7ca04a 100644
--- a/tests/check/libs/player.c
+++ b/tests/check/libs/player.c
@@ -179,6 +179,7 @@ struct _TestPlayerState
gint width, height;
GstPlayerMediaInfo *media_info;
gchar *uri_loaded;
+ gboolean stopping;
void (*test_callback) (GstPlayer * player, TestPlayerStateChange change,
TestPlayerState * old_state, TestPlayerState * new_state);
@@ -226,6 +227,7 @@ test_player_state_reset (TestPlayerState * state)
state->state = GST_PLAYER_STATE_STOPPED;
state->width = state->height = 0;
state->media_info = NULL;
+ state->stopping = FALSE;
g_clear_pointer (&state->uri_loaded, g_free);
}
@@ -234,6 +236,8 @@ buffering_cb (GstPlayer * player, gint percent, TestPlayerState * state)
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->buffering_percent = percent;
test_player_state_change_debug (player, STATE_CHANGE_BUFFERING, &old_state,
state);
@@ -246,6 +250,8 @@ duration_changed_cb (GstPlayer * player, guint64 duration,
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->duration = duration;
test_player_state_change_debug (player, STATE_CHANGE_DURATION_CHANGED,
&old_state, state);
@@ -258,6 +264,8 @@ end_of_stream_cb (GstPlayer * player, TestPlayerState * state)
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->end_of_stream = TRUE;
test_player_state_change_debug (player, STATE_CHANGE_END_OF_STREAM,
&old_state, state);
@@ -269,6 +277,8 @@ error_cb (GstPlayer * player, GError * error, TestPlayerState * state)
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->error = TRUE;
test_player_state_change_debug (player, STATE_CHANGE_ERROR, &old_state,
state);
@@ -280,6 +290,8 @@ warning_cb (GstPlayer * player, GError * error, TestPlayerState * state)
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->warning = TRUE;
test_player_state_change_debug (player, STATE_CHANGE_WARNING, &old_state,
state);
@@ -292,6 +304,8 @@ position_updated_cb (GstPlayer * player, guint64 position,
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->position = position;
test_player_state_change_debug (player, STATE_CHANGE_POSITION_UPDATED,
&old_state, state);
@@ -305,6 +319,8 @@ media_info_updated_cb (GstPlayer * player, GstPlayerMediaInfo * media_info,
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->media_info = media_info;
test_player_state_change_debug (player, STATE_CHANGE_MEDIA_INFO_UPDATED,
@@ -319,6 +335,8 @@ state_changed_cb (GstPlayer * player, GstPlayerState player_state,
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping || player_state == GST_PLAYER_STATE_STOPPED);
+
state->state = player_state;
if (player_state == GST_PLAYER_STATE_STOPPED)
@@ -335,6 +353,8 @@ video_dimensions_changed_cb (GstPlayer * player, gint width, gint height,
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->width = width;
state->height = height;
test_player_state_change_debug (player, STATE_CHANGE_VIDEO_DIMENSIONS_CHANGED,
@@ -348,6 +368,8 @@ seek_done_cb (GstPlayer * player, guint64 position, TestPlayerState * state)
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->seek_done = TRUE;
state->seek_done_position = position;
test_player_state_change_debug (player, STATE_CHANGE_SEEK_DONE,
@@ -408,6 +430,28 @@ test_player_new (TestPlayerState * state)
}
static void
+test_player_stopped_cb (GstPlayer * player, TestPlayerStateChange change,
+ TestPlayerState * old_state, TestPlayerState * new_state)
+{
+ if (new_state->state == GST_PLAYER_STATE_STOPPED) {
+ g_main_loop_quit (new_state->loop);
+ }
+}
+
+static void
+stop_player (GstPlayer * player, TestPlayerState * state)
+{
+ if (state->state != GST_PLAYER_STATE_STOPPED) {
+ /* Make sure all pending operations are finished so the player won't be
+ * appear as 'leaked' to leak detection tools. */
+ state->test_callback = test_player_stopped_cb;
+ gst_player_stop (player);
+ state->stopping = TRUE;
+ g_main_loop_run (state->loop);
+ }
+}
+
+static void
test_play_audio_video_eos_cb (GstPlayer * player, TestPlayerStateChange change,
TestPlayerState * old_state, TestPlayerState * new_state)
{
@@ -522,6 +566,7 @@ START_TEST (test_play_audio_eos)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 9);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -700,6 +745,7 @@ START_TEST (test_play_media_info)
g_main_loop_run (state.loop);
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 1);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -792,6 +838,7 @@ START_TEST (test_play_stream_disable)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 0x33);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -856,6 +903,7 @@ START_TEST (test_play_stream_switch_audio)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -920,6 +968,7 @@ START_TEST (test_play_stream_switch_subtitle)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -951,6 +1000,7 @@ START_TEST (test_play_error_invalid_external_suburi)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1029,6 +1079,7 @@ START_TEST (test_play_external_suburi)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1100,6 +1151,7 @@ START_TEST (test_play_forward_rate)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data) & 0xf, 10);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1131,6 +1183,7 @@ START_TEST (test_play_backward_rate)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data) & 0xf, 10);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1162,6 +1215,7 @@ START_TEST (test_play_audio_video_eos)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data) & (~0x10), 9);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1225,6 +1279,7 @@ START_TEST (test_play_error_invalid_uri)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 4);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1334,6 +1389,7 @@ START_TEST (test_play_error_invalid_uri_and_play)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 11);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1384,6 +1440,7 @@ START_TEST (test_play_audio_video_seek_done)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data) & (~0x10), 2);
+ stop_player (player, &state);
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1468,6 +1525,87 @@ START_TEST (test_play_position_update_interval)
fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 5);
+ stop_player (player, &state);
+ g_object_unref (player);
+ g_main_loop_unref (state.loop);
+}
+
+END_TEST;
+
+static void
+test_restart_cb (GstPlayer * player,
+ TestPlayerStateChange change, TestPlayerState * old_state,
+ TestPlayerState * new_state)
+{
+ gint steps = GPOINTER_TO_INT (new_state->test_data);
+
+ if (!steps && change == STATE_CHANGE_URI_LOADED) {
+ fail_unless (g_str_has_suffix (new_state->uri_loaded, "sintel.mkv"));
+ new_state->test_data = GINT_TO_POINTER (steps + 1);
+ } else if (change == STATE_CHANGE_STATE_CHANGED
+ && new_state->state == GST_PLAYER_STATE_BUFFERING) {
+ new_state->test_data = GINT_TO_POINTER (steps + 1);
+ g_main_loop_quit (new_state->loop);
+ }
+}
+
+static void
+test_restart_cb2 (GstPlayer * player,
+ TestPlayerStateChange change, TestPlayerState * old_state,
+ TestPlayerState * new_state)
+{
+ gint steps = GPOINTER_TO_INT (new_state->test_data);
+
+ if (!steps && change == STATE_CHANGE_URI_LOADED) {
+ fail_unless (g_str_has_suffix (new_state->uri_loaded, "audio-short.ogg"));
+ new_state->test_data = GINT_TO_POINTER (steps + 1);
+ } else if (change == STATE_CHANGE_STATE_CHANGED
+ && new_state->state == GST_PLAYER_STATE_BUFFERING) {
+ new_state->test_data = GINT_TO_POINTER (steps + 1);
+ g_main_loop_quit (new_state->loop);
+ }
+}
+
+
+START_TEST (test_restart)
+{
+ GstPlayer *player;
+ TestPlayerState state;
+ gchar *uri;
+
+ memset (&state, 0, sizeof (state));
+ state.loop = g_main_loop_new (NULL, FALSE);
+ state.test_callback = test_restart_cb;
+ state.test_data = GINT_TO_POINTER (0);
+
+ player = test_player_new (&state);
+
+ fail_unless (player != NULL);
+
+ uri = gst_filename_to_uri (TEST_PATH "/sintel.mkv", NULL);
+ fail_unless (uri != NULL);
+ gst_player_set_uri (player, uri);
+ g_free (uri);
+
+ gst_player_play (player);
+ g_main_loop_run (state.loop);
+ fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
+ stop_player (player, &state);
+
+ /* Try again with another URI */
+ state.test_data = GINT_TO_POINTER (0);
+ state.test_callback = test_restart_cb2;
+
+ uri = gst_filename_to_uri (TEST_PATH "/audio-short.ogg", NULL);
+ fail_unless (uri != NULL);
+ gst_player_set_uri (player, uri);
+ g_free (uri);
+
+ gst_player_play (player);
+ g_main_loop_run (state.loop);
+ fail_unless_equals_int (GPOINTER_TO_INT (state.test_data), 2);
+ stop_player (player, &state);
+
g_object_unref (player);
g_main_loop_unref (state.loop);
}
@@ -1515,6 +1653,7 @@ player_suite (void)
tcase_add_test (tc_general, test_play_forward_rate);
tcase_add_test (tc_general, test_play_backward_rate);
tcase_add_test (tc_general, test_play_audio_video_seek_done);
+ tcase_add_test (tc_general, test_restart);
suite_add_tcase (s, tc_general);