static void keyboard_cb (const gchar * key_input, gpointer user_data) { GstPlay *play = (GstPlay *) user_data; switch (g_ascii_tolower (key_input[0])) { case 'i': { GstPlayerMediaInfo *media_info = gst_player_get_media_info (play->player); if (media_info) { print_media_info (media_info); g_object_unref (media_info); print_current_tracks (play); } break; } case ' ': toggle_paused (play); break; case 'q': case 'Q': g_main_loop_quit (play->loop); break; case '>': if (!play_next (play)) { g_print ("\nReached end of play list.\n"); g_main_loop_quit (play->loop); } break; case '<': play_prev (play); break; case 27: /* ESC */ if (key_input[1] == '\0') { g_main_loop_quit (play->loop); break; } /* fall through */ 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; } }
static gboolean play_bus_msg (GstBus * bus, GstMessage * msg, gpointer user_data) { GstPlay *play = user_data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ASYNC_DONE: /* dump graph on preroll */ GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin), GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.async-done"); g_print ("Prerolled.\r"); if (play->missing != NULL && play_install_missing_plugins (play)) { g_print ("New plugins installed, trying again...\n"); --play->cur_idx; play_next (play); } break; case GST_MESSAGE_BUFFERING:{ gint percent; if (!play->buffering) g_print ("\n"); gst_message_parse_buffering (msg, &percent); g_print ("%s %d%% \r", _("Buffering..."), percent); if (percent == 100) { /* a 100% message means buffering is done */ if (play->buffering) { play->buffering = FALSE; /* no state management needed for live pipelines */ if (!play->is_live) gst_element_set_state (play->playbin, play->desired_state); } } else { /* buffering... */ if (!play->buffering) { if (!play->is_live) gst_element_set_state (play->playbin, GST_STATE_PAUSED); play->buffering = TRUE; } } break; } case GST_MESSAGE_CLOCK_LOST:{ g_print (_("Clock lost, selecting a new one\n")); gst_element_set_state (play->playbin, GST_STATE_PAUSED); gst_element_set_state (play->playbin, GST_STATE_PLAYING); break; } case GST_MESSAGE_LATENCY: g_print ("Redistribute latency...\n"); gst_bin_recalculate_latency (GST_BIN (play->playbin)); break; case GST_MESSAGE_REQUEST_STATE:{ GstState state; gchar *name; name = gst_object_get_path_string (GST_MESSAGE_SRC (msg)); gst_message_parse_request_state (msg, &state); g_print ("Setting state to %s as requested by %s...\n", gst_element_state_get_name (state), name); gst_element_set_state (play->playbin, state); g_free (name); break; } case GST_MESSAGE_EOS: /* print final position at end */ play_timeout (play); g_print ("\n"); /* and switch to next item in list */ if (!play_next (play)) { g_print ("%s\n", _("Reached end of play list.")); g_main_loop_quit (play->loop); } break; case GST_MESSAGE_WARNING:{ GError *err; gchar *dbg = NULL; /* dump graph on warning */ GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin), GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.warning"); gst_message_parse_warning (msg, &err, &dbg); g_printerr ("WARNING %s\n", err->message); if (dbg != NULL) g_printerr ("WARNING debug information: %s\n", dbg); g_clear_error (&err); g_free (dbg); break; } case GST_MESSAGE_ERROR:{ GError *err; gchar *dbg; /* dump graph on error */ GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (play->playbin), GST_DEBUG_GRAPH_SHOW_ALL, "gst-play.error"); gst_message_parse_error (msg, &err, &dbg); g_printerr ("ERROR %s for %s\n", err->message, play->uris[play->cur_idx]); if (dbg != NULL) g_printerr ("ERROR debug information: %s\n", dbg); g_clear_error (&err); g_free (dbg); /* flush any other error messages from the bus and clean up */ gst_element_set_state (play->playbin, GST_STATE_NULL); if (play->missing != NULL && play_install_missing_plugins (play)) { g_print ("New plugins installed, trying again...\n"); --play->cur_idx; play_next (play); break; } /* try next item in list then */ if (!play_next (play)) { g_print ("%s\n", _("Reached end of play list.")); g_main_loop_quit (play->loop); } break; } case GST_MESSAGE_ELEMENT: { GstNavigationMessageType mtype = gst_navigation_message_get_type (msg); if (mtype == GST_NAVIGATION_MESSAGE_EVENT) { GstEvent *ev = NULL; if (gst_navigation_message_parse_event (msg, &ev)) { GstNavigationEventType e_type = gst_navigation_event_get_type (ev); switch (e_type) { case GST_NAVIGATION_EVENT_KEY_PRESS: { const gchar *key; if (gst_navigation_event_parse_key_event (ev, &key)) { GST_INFO ("Key press: %s", key); if (strcmp (key, "Left") == 0) key = GST_PLAY_KB_ARROW_LEFT; else if (strcmp (key, "Right") == 0) key = GST_PLAY_KB_ARROW_RIGHT; else if (strcmp (key, "Up") == 0) key = GST_PLAY_KB_ARROW_UP; else if (strcmp (key, "Down") == 0) key = GST_PLAY_KB_ARROW_DOWN; else if (strcmp (key, "space") == 0) key = " "; else if (strlen (key) > 1) break; keyboard_cb (key, user_data); } break; } case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS: { gint button; if (gst_navigation_event_parse_mouse_button_event (ev, &button, NULL, NULL)) { if (button == 4) { /* wheel up */ relative_seek (play, +0.08); } else if (button == 5) { /* wheel down */ relative_seek (play, -0.01); } } break; } default: break; } } if (ev) gst_event_unref (ev); } break; } default: if (gst_is_missing_plugin_message (msg)) { gchar *desc; desc = gst_missing_plugin_message_get_description (msg); g_print ("Missing plugin: %s\n", desc); g_free (desc); play->missing = g_list_append (play->missing, gst_message_ref (msg)); } break; } return TRUE; }
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; } }
static gboolean master_bus_msg (GstBus * bus, GstMessage * msg, gpointer data) { GstPipeline *pipeline = data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_ERROR:{ GError *err; gchar *dbg; gst_message_parse_error (msg, &err, &dbg); g_printerr ("MASTER: ERROR: %s\n", err->message); if (dbg != NULL) g_printerr ("MASTER: ERROR debug information: %s\n", dbg); g_error_free (err); g_free (dbg); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "ipc.master.error"); g_main_loop_quit (loop); break; } case GST_MESSAGE_WARNING:{ GError *err; gchar *dbg; gst_message_parse_warning (msg, &err, &dbg); g_printerr ("MASTER: WARNING: %s\n", err->message); if (dbg != NULL) g_printerr ("MASTER: WARNING debug information: %s\n", dbg); g_error_free (err); g_free (dbg); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "ipc.master.warning"); break; } case GST_MESSAGE_ASYNC_DONE: GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_ALL, "ipc.master.async-done"); break; case GST_MESSAGE_EOS: g_print ("EOS on master\n"); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); g_main_loop_quit (loop); break; case GST_MESSAGE_BUFFERING:{ gint percent; GstBufferingMode bufmode; if (!buffering) g_print ("\n"); gst_message_parse_buffering (msg, &percent); g_print ("%s %d%% \r", "Buffering...", percent); gst_message_parse_buffering_stats (msg, &bufmode, NULL, NULL, NULL); /* no state management needed for live pipelines */ if (bufmode != GST_BUFFERING_LIVE) { if (percent == 100) { /* a 100% message means buffering is done */ if (buffering) { buffering = FALSE; gst_element_set_state (GST_ELEMENT (pipeline), desired_state); g_print ("\n%s\n", gst_element_state_get_name (desired_state)); } } else { /* buffering... */ if (!buffering) { gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED); buffering = TRUE; } } } break; } case GST_MESSAGE_CLOCK_LOST:{ g_print ("Clock lost, selecting a new one\n"); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PAUSED); gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); break; } case GST_MESSAGE_LATENCY: { gst_bin_recalculate_latency (GST_BIN (pipeline)); break; } case GST_MESSAGE_REQUEST_STATE:{ GstState state; gchar *name; name = gst_object_get_path_string (GST_MESSAGE_SRC (msg)); gst_message_parse_request_state (msg, &state); GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), GST_DEBUG_GRAPH_SHOW_VERBOSE, "ipc.slave.reqstate"); g_print ("Setting state to %s as requested by %s...\n", gst_element_state_get_name (state), name); gst_element_set_state (GST_ELEMENT (pipeline), state); g_free (name); break; } case GST_MESSAGE_ELEMENT: { GstNavigationMessageType mtype = gst_navigation_message_get_type (msg); if (mtype == GST_NAVIGATION_MESSAGE_EVENT) { GstEvent *ev = NULL; if (gst_navigation_message_parse_event (msg, &ev)) { GstNavigationEventType e_type = gst_navigation_event_get_type (ev); switch (e_type) { case GST_NAVIGATION_EVENT_KEY_PRESS: { const gchar *key; if (gst_navigation_event_parse_key_event (ev, &key)) { GST_INFO ("Key press: %s", key); if (strcmp (key, "Left") == 0) key = GST_PLAY_KB_ARROW_LEFT; else if (strcmp (key, "Right") == 0) key = GST_PLAY_KB_ARROW_RIGHT; else if (strcmp (key, "Up") == 0) key = GST_PLAY_KB_ARROW_UP; else if (strcmp (key, "Down") == 0) key = GST_PLAY_KB_ARROW_DOWN; else if (strcmp (key, "space") == 0) key = " "; else if (strlen (key) > 1) break; keyboard_cb (key, GST_ELEMENT (pipeline)); } break; } case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS: { gint button; if (gst_navigation_event_parse_mouse_button_event (ev, &button, NULL, NULL)) { if (button == 4) { /* wheel up */ relative_seek (GST_ELEMENT (pipeline), +0.08); } else if (button == 5) { /* wheel down */ relative_seek (GST_ELEMENT (pipeline), -0.01); } } break; } default: break; } } if (ev) gst_event_unref (ev); } break; } default: break; } return TRUE; }
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; } }