mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
gst-play: support changing the playback rate in interactive mode
It is fun to have this feature, also it is useful for testing decoders. https://bugzilla.gnome.org/show_bug.cgi?id=745174
This commit is contained in:
parent
621292e754
commit
c243f386c9
1 changed files with 60 additions and 0 deletions
|
@ -625,10 +625,58 @@ seek_failed:
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
change_rate (GstPlay * play, gdouble rate)
|
||||
{
|
||||
GstQuery *query;
|
||||
GstEvent *seek;
|
||||
gboolean seekable = FALSE;
|
||||
gint64 pos = -1;
|
||||
|
||||
g_return_if_fail (rate != 0 && rate >= -10.0 && rate <= 10.0);
|
||||
|
||||
if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos))
|
||||
goto seek_failed;
|
||||
|
||||
query = gst_query_new_seeking (GST_FORMAT_TIME);
|
||||
if (!gst_element_query (play->playbin, query)) {
|
||||
gst_query_unref (query);
|
||||
goto seek_failed;
|
||||
}
|
||||
|
||||
gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL);
|
||||
gst_query_unref (query);
|
||||
|
||||
if (!seekable)
|
||||
goto seek_failed;
|
||||
|
||||
if (rate > 0)
|
||||
seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
|
||||
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_KEY_UNIT,
|
||||
/* start */ GST_SEEK_TYPE_SET, pos,
|
||||
/* stop */ GST_SEEK_TYPE_NONE, 0);
|
||||
else
|
||||
seek = gst_event_new_seek (rate, GST_FORMAT_TIME,
|
||||
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE,
|
||||
/* start */ GST_SEEK_TYPE_SET, 0,
|
||||
/* stop */ GST_SEEK_TYPE_SET, pos);
|
||||
|
||||
if (!gst_element_send_event (play->playbin, seek))
|
||||
goto seek_failed;
|
||||
|
||||
return;
|
||||
|
||||
seek_failed:
|
||||
{
|
||||
g_print ("\nCould not seek.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
keyboard_cb (const gchar * key_input, gpointer user_data)
|
||||
{
|
||||
GstPlay *play = (GstPlay *) user_data;
|
||||
static gdouble rate = 1.0;
|
||||
|
||||
switch (g_ascii_tolower (key_input[0])) {
|
||||
case ' ':
|
||||
|
@ -647,6 +695,18 @@ keyboard_cb (const gchar * key_input, gpointer user_data)
|
|||
case '<':
|
||||
play_prev (play);
|
||||
break;
|
||||
case '+':
|
||||
rate += 0.5;
|
||||
change_rate (play, rate);
|
||||
break;
|
||||
case '-':
|
||||
rate -= 0.5;
|
||||
change_rate (play, rate);
|
||||
break;
|
||||
case 'd':
|
||||
rate *= -1.0;
|
||||
change_rate (play, rate);
|
||||
break;
|
||||
case 27: /* ESC */
|
||||
if (key_input[1] == '\0') {
|
||||
g_main_loop_quit (play->loop);
|
||||
|
|
Loading…
Reference in a new issue