GstClockTime last_seek_time; /* Only set from main context */
GSource *seek_source;
GstClockTime seek_position;
+ /* If TRUE, all signals are inhibited except the
+ * state-changed:GST_PLAYER_STATE_STOPPED/PAUSED. This ensures that no signal
+ * is emitted after gst_player_stop/pause() has been called by the user. */
+ gboolean inhibit_sigs;
};
struct _GstPlayerClass
self->seek_pending = FALSE;
self->seek_position = GST_CLOCK_TIME_NONE;
self->last_seek_time = GST_CLOCK_TIME_NONE;
+ self->inhibit_sigs = FALSE;
GST_TRACE_OBJECT (self, "Initialized");
}
{
StateChangedSignalData *data = user_data;
+ if (data->player->inhibit_sigs && data->state != GST_PLAYER_STATE_STOPPED
+ && data->state != GST_PLAYER_STATE_PAUSED)
+ return;
+
g_signal_emit (data->player, signals[SIGNAL_STATE_CHANGED], 0, data->state);
}
{
PositionUpdatedSignalData *data = user_data;
+ if (data->player->inhibit_sigs)
+ return;
+
if (data->player->target_state >= GST_STATE_PAUSED) {
g_signal_emit (data->player, signals[SIGNAL_POSITION_UPDATED], 0,
data->position);
{
ErrorSignalData *data = user_data;
+ if (data->player->inhibit_sigs)
+ return;
+
g_signal_emit (data->player, signals[SIGNAL_ERROR], 0, data->err);
}
{
WarningSignalData *data = user_data;
+ if (data->player->inhibit_sigs)
+ return;
+
g_signal_emit (data->player, signals[SIGNAL_WARNING], 0, data->err);
}
static void
eos_dispatch (gpointer user_data)
{
- g_signal_emit (user_data, signals[SIGNAL_END_OF_STREAM], 0);
+ GstPlayer *player = user_data;
+
+ if (player->inhibit_sigs)
+ return;
+
+ g_signal_emit (player, signals[SIGNAL_END_OF_STREAM], 0);
}
static void
{
BufferingSignalData *data = user_data;
+ if (data->player->inhibit_sigs)
+ return;
+
if (data->player->target_state >= GST_STATE_PAUSED) {
g_signal_emit (data->player, signals[SIGNAL_BUFFERING], 0, data->percent);
}
{
VideoDimensionsChangedSignalData *data = user_data;
+ if (data->player->inhibit_sigs)
+ return;
+
if (data->player->target_state >= GST_STATE_PAUSED) {
g_signal_emit (data->player, signals[SIGNAL_VIDEO_DIMENSIONS_CHANGED], 0,
data->width, data->height);
{
DurationChangedSignalData *data = user_data;
+ if (data->player->inhibit_sigs)
+ return;
+
if (data->player->target_state >= GST_STATE_PAUSED) {
g_signal_emit (data->player, signals[SIGNAL_DURATION_CHANGED], 0,
data->duration);
{
SeekDoneSignalData *data = user_data;
+ if (data->player->inhibit_sigs)
+ return;
+
g_signal_emit (data->player, signals[SIGNAL_SEEK_DONE], 0, data->position);
}
{
MediaInfoUpdatedSignalData *data = user_data;
+ if (data->player->inhibit_sigs)
+ return;
+
if (data->player->target_state >= GST_STATE_PAUSED) {
g_signal_emit (data->player, signals[SIGNAL_MEDIA_INFO_UPDATED], 0,
data->info);
static void
volume_changed_dispatch (gpointer user_data)
{
- g_signal_emit (user_data, signals[SIGNAL_VOLUME_CHANGED], 0);
- g_object_notify_by_pspec (G_OBJECT (user_data), param_specs[PROP_VOLUME]);
+ GstPlayer *player = user_data;
+
+ if (player->inhibit_sigs)
+ return;
+
+ g_signal_emit (player, signals[SIGNAL_VOLUME_CHANGED], 0);
+ g_object_notify_by_pspec (G_OBJECT (player), param_specs[PROP_VOLUME]);
}
static void
static void
mute_changed_dispatch (gpointer user_data)
{
- g_signal_emit (user_data, signals[SIGNAL_MUTE_CHANGED], 0);
- g_object_notify_by_pspec (G_OBJECT (user_data), param_specs[PROP_MUTE]);
+ GstPlayer *player = user_data;
+
+ if (player->inhibit_sigs)
+ return;
+
+ g_signal_emit (player, signals[SIGNAL_MUTE_CHANGED], 0);
+ g_object_notify_by_pspec (G_OBJECT (player), param_specs[PROP_MUTE]);
}
static void
{
g_return_if_fail (GST_IS_PLAYER (self));
+ g_mutex_lock (&self->lock);
+ self->inhibit_sigs = FALSE;
+ g_mutex_unlock (&self->lock);
+
g_main_context_invoke_full (self->context, G_PRIORITY_DEFAULT,
gst_player_play_internal, self, NULL);
}
{
g_return_if_fail (GST_IS_PLAYER (self));
+ g_mutex_lock (&self->lock);
+ self->inhibit_sigs = TRUE;
+ g_mutex_unlock (&self->lock);
+
g_main_context_invoke_full (self->context, G_PRIORITY_DEFAULT,
gst_player_pause_internal, self, NULL);
}
{
g_return_if_fail (GST_IS_PLAYER (self));
+ g_mutex_lock (&self->lock);
+ self->inhibit_sigs = TRUE;
+ g_mutex_unlock (&self->lock);
+
g_main_context_invoke_full (self->context, G_PRIORITY_DEFAULT,
gst_player_stop_internal, self, NULL);
}
gint width, height;
GstPlayerMediaInfo *media_info;
gchar *uri_loaded;
+ gboolean stopping;
void (*test_callback) (GstPlayer * player, TestPlayerStateChange change,
TestPlayerState * old_state, TestPlayerState * new_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);
}
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->buffering_percent = percent;
test_player_state_change_debug (player, STATE_CHANGE_BUFFERING, &old_state,
state);
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->duration = duration;
test_player_state_change_debug (player, STATE_CHANGE_DURATION_CHANGED,
&old_state, 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);
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->error = TRUE;
test_player_state_change_debug (player, STATE_CHANGE_ERROR, &old_state,
state);
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->warning = TRUE;
test_player_state_change_debug (player, STATE_CHANGE_WARNING, &old_state,
state);
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->position = position;
test_player_state_change_debug (player, STATE_CHANGE_POSITION_UPDATED,
&old_state, state);
{
TestPlayerState old_state = *state;
+ g_assert (!state->stopping);
+
state->media_info = media_info;
test_player_state_change_debug (player, STATE_CHANGE_MEDIA_INFO_UPDATED,
{
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)
{
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,
{
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,
}
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)
{
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);
}
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);