playback/player: Make state handling more robust and notify the application about our states

The application now will get one of 4 states via a signal:
STOPPED: After EOS, error and when explicitely stopped
BUFFERING: When moving to the lower states, or we get buffering messages,
           also when seeking.
PAUSED and PLAYING: When having reached that state and it's our target

Also we now always first go to PAUSED state before we seek, and also before we
go to PLAYING. This allows us to deterministically change states and makes
everything a bit more robust.

As a side-effect, get rid of the is-playing property. Applications can now get
this from the corresponding signal if they need to know.

Additionally now notify the application about the buffering percentage.

Also fix a few bugs related to state handling and buffering.
This commit is contained in:
Sebastian Dröge 2015-02-07 11:14:42 +01:00
parent 97c4cfc670
commit ae46c50138

View file

@ -76,7 +76,7 @@ error_cb (GstPlayer * player, GError * err, GstPlay * play)
} }
} }
static gboolean static void
position_updated_cb (GstPlayer * player, GstClockTime pos, GstPlay * play) position_updated_cb (GstPlayer * player, GstClockTime pos, GstPlay * play)
{ {
GstClockTime dur = -1; GstClockTime dur = -1;
@ -84,10 +84,7 @@ position_updated_cb (GstPlayer * player, GstClockTime pos, GstPlay * play)
g_object_get (play->player, "duration", &dur, NULL); g_object_get (play->player, "duration", &dur, NULL);
if (play->desired_state == GST_STATE_PAUSED) memset (status, ' ', sizeof (status) - 1);
g_snprintf (status, sizeof (status), "Paused");
else
memset (status, ' ', sizeof (status) - 1);
if (pos >= 0 && dur > 0) { if (pos >= 0 && dur > 0) {
gchar dstr[32], pstr[32]; gchar dstr[32], pstr[32];
@ -99,8 +96,18 @@ position_updated_cb (GstPlayer * player, GstClockTime pos, GstPlay * play)
dstr[9] = '\0'; dstr[9] = '\0';
g_print ("%s / %s %s\r", pstr, dstr, status); g_print ("%s / %s %s\r", pstr, dstr, status);
} }
}
return TRUE; static void
state_changed_cb (GstPlayer * player, GstPlayerState state, GstPlay * play)
{
g_print ("State changed: %s\n", gst_player_state_get_name (state));
}
static void
buffering_cb (GstPlayer * player, gint percent, GstPlay * play)
{
g_print ("Buffering: %d\n", percent);
} }
static GstPlay * static GstPlay *
@ -119,6 +126,10 @@ play_new (gchar ** uris, gdouble initial_volume)
g_object_set (play->player, "dispatch-to-main-context", TRUE, NULL); g_object_set (play->player, "dispatch-to-main-context", TRUE, NULL);
g_signal_connect (play->player, "position-updated", g_signal_connect (play->player, "position-updated",
G_CALLBACK (position_updated_cb), play); G_CALLBACK (position_updated_cb), play);
g_signal_connect (play->player, "state-changed",
G_CALLBACK (state_changed_cb), play);
g_signal_connect (play->player, "buffering",
G_CALLBACK (buffering_cb), play);
g_signal_connect (play->player, "end-of-stream", g_signal_connect (play->player, "end-of-stream",
G_CALLBACK (end_of_stream_cb), play); G_CALLBACK (end_of_stream_cb), play);
g_signal_connect (play->player, "error", G_CALLBACK (error_cb), play); g_signal_connect (play->player, "error", G_CALLBACK (error_cb), play);