static gboolean
play_set_rate_and_trick_mode (GstPlay * play, gdouble rate,
    GstPlayTrickMode mode)
{
  gint64 pos = -1;

  g_return_val_if_fail (rate != 0, FALSE);

  if (!gst_element_query_position (play->playbin, GST_FORMAT_TIME, &pos))
    return FALSE;

  return play_do_seek (play, pos, rate, mode);
}
static void
relative_seek (GstPlay * play, gdouble percent)
{
  GstQuery *query;
  gboolean seekable = FALSE;
  gint64 dur = -1, pos = -1, step;

  g_return_if_fail (percent >= -1.0 && percent <= 1.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, &dur);
  gst_query_unref (query);

  if (!seekable || dur <= 0)
    goto seek_failed;

  step = dur * percent;
  if (ABS (step) < GST_SECOND)
    step = (percent < 0) ? -GST_SECOND : GST_SECOND;

  pos = pos + step;
  if (pos > dur) {
    if (!play_next (play)) {
      g_print ("\n%s\n", _("Reached end of play list."));
      g_main_loop_quit (play->loop);
    }
  } else {
    if (pos < 0)
      pos = 0;

    play_do_seek (play, pos, play->rate, play->trick_mode);
  }

  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;
  gchar key = '\0';

  /* only want to switch/case on single char, not first char of string */
  if (key_input[0] != '\0' && key_input[1] == '\0')
    key = g_ascii_tolower (key_input[0]);

  switch (key) {
    case 'k':
      print_keyboard_help ();
      break;
    case ' ':
      toggle_paused (play);
      break;
    case 'q':
    case 'Q':
      g_main_loop_quit (play->loop);
      break;
    case 'n':
    case '>':
      if (!play_next (play)) {
        g_print ("\n%s\n", _("Reached end of play list."));
        g_main_loop_quit (play->loop);
      }
      break;
    case 'b':
    case '<':
      play_prev (play);
      break;
    case '+':
      if (play->rate > -0.2 && play->rate < 0.0)
        play_set_relative_playback_rate (play, 0.0, TRUE);
      else if (ABS (play->rate) < 2.0)
        play_set_relative_playback_rate (play, 0.1, FALSE);
      else if (ABS (play->rate) < 4.0)
        play_set_relative_playback_rate (play, 0.5, FALSE);
      else
        play_set_relative_playback_rate (play, 1.0, FALSE);
      break;
    case '-':
      if (play->rate > 0.0 && play->rate < 0.20)
        play_set_relative_playback_rate (play, 0.0, TRUE);
      else if (ABS (play->rate) <= 2.0)
        play_set_relative_playback_rate (play, -0.1, FALSE);
      else if (ABS (play->rate) <= 4.0)
        play_set_relative_playback_rate (play, -0.5, FALSE);
      else
        play_set_relative_playback_rate (play, -1.0, FALSE);
      break;
    case 'd':
      play_set_relative_playback_rate (play, 0.0, TRUE);
      break;
    case 't':
      play_switch_trick_mode (play);
      break;
    case 27:                   /* ESC */
      if (key_input[1] == '\0') {
        g_main_loop_quit (play->loop);
        break;
      }
    case 'a':
      play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_AUDIO);
      break;
    case 'v':
      play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_VIDEO);
      break;
    case 's':
      play_cycle_track_selection (play, GST_PLAY_TRACK_TYPE_SUBTITLE);
      break;
    case '0':
      play_do_seek (play, 0, play->rate, play->trick_mode);
      break;
    default:
      if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) {
        relative_seek (play, +0.08);
      } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) {
        relative_seek (play, -0.01);
      } else if (strcmp (key_input, GST_PLAY_KB_ARROW_UP) == 0) {
        play_set_relative_volume (play, +1.0 / VOLUME_STEPS);
      } else if (strcmp (key_input, GST_PLAY_KB_ARROW_DOWN) == 0) {
        play_set_relative_volume (play, -1.0 / VOLUME_STEPS);
      } else {
        GST_INFO ("keyboard input:");
        for (; *key_input != '\0'; ++key_input)
          GST_INFO ("  code %3d", *key_input);
      }
      break;
  }
}
示例#4
0
static void
keyboard_cb (const gchar * key_input, GstElement * pipeline)
{
  gchar key = '\0';

  /* only want to switch/case on single char, not first char of string */
  if (key_input[0] != '\0' && key_input[1] == '\0')
    key = g_ascii_tolower (key_input[0]);

  switch (key) {
    case ' ':
      toggle_paused (pipeline);
      break;
    case 'q':
    case 'Q':
      g_main_loop_quit (loop);
      break;
    case 'p':
      if (cur_rate > -0.2 && cur_rate < 0.0)
        play_set_relative_playback_rate (pipeline, 0.0, TRUE);
      else if (ABS (cur_rate) < 2.0)
        play_set_relative_playback_rate (pipeline, 0.1, FALSE);
      else if (ABS (cur_rate) < 4.0)
        play_set_relative_playback_rate (pipeline, 0.5, FALSE);
      else
        play_set_relative_playback_rate (pipeline, 1.0, FALSE);
      break;
    case 'o':
      if (cur_rate > 0.0 && cur_rate < 0.20)
        play_set_relative_playback_rate (pipeline, 0.0, TRUE);
      else if (ABS (cur_rate) <= 2.0)
        play_set_relative_playback_rate (pipeline, -0.1, FALSE);
      else if (ABS (cur_rate) <= 4.0)
        play_set_relative_playback_rate (pipeline, -0.5, FALSE);
      else
        play_set_relative_playback_rate (pipeline, -1.0, FALSE);
      break;
    case 'd':
      play_set_relative_playback_rate (pipeline, 0.0, TRUE);
      break;
    case 't':
      play_switch_trick_mode (pipeline);
      break;
    case 27:                   /* ESC */
      if (key_input[1] == '\0') {
        g_main_loop_quit (loop);
        break;
      }
    case '0':
      play_do_seek (pipeline, 0, cur_rate, trick_mode);
      break;
    case 'r':
      GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline),
          GST_DEBUG_GRAPH_SHOW_ALL, "ipc.master.requested");
      break;
    default:
      if (strcmp (key_input, GST_PLAY_KB_ARROW_RIGHT) == 0) {
        relative_seek (pipeline, +0.08);
      } else if (strcmp (key_input, GST_PLAY_KB_ARROW_LEFT) == 0) {
        relative_seek (pipeline, -0.01);
      } else {
        GST_INFO ("keyboard input:");
        for (; *key_input != '\0'; ++key_input)
          GST_INFO ("  code %3d", *key_input);
      }
      break;
  }
}