📄 gui_main.cpp
字号:
double val; val = max_time; if (time_slider_pressed == 0 && val > 0.0 && psptr->get_session_state() == SESSION_PLAYING) { if (playtime < 0) { val = 0.0; } else if (playtime > val) { val = 100.0; } else { val = (playtime * 100.0) / val; }#ifdef HAVE_GTK_2_0 gtk_range_set_value(GTK_RANGE(time_slider), val);#else GtkAdjustment *adj = gtk_range_get_adjustment(GTK_RANGE(time_slider)); adj->value = val; gtk_range_set_adjustment(GTK_RANGE(time_slider), adj); gtk_range_slider_update(GTK_RANGE(time_slider)); gtk_range_clear_background(GTK_RANGE(time_slider)); gtk_range_draw_background(GTK_RANGE(time_slider)); gtk_widget_show(time_slider);#endif } int hr, min, tot; tot = (int) playtime; hr = tot / 3600; tot %= 3600; min = tot / 60; tot %= 60; playtime -= (double)((hr * 3600) + (min * 60)); if (max_time == 0.0) { gchar buffer[30]; g_snprintf(buffer, 30, "%d:%02d:%04.1f", hr, min, playtime); gtk_label_set_text(GTK_LABEL(time_disp), buffer); } else { int mhr, mmin, msec, mtot; mtot = (int)max_time; mhr = mtot / 3600; mtot %= 3600; mmin = mtot / 60; msec = mtot % 60; gchar buffer[60]; g_snprintf(buffer, 60, "%d:%02d:%04.1f of %d:%02d:%02d", hr, min, playtime, mhr, mmin, msec); gtk_label_set_text(GTK_LABEL(time_disp), buffer); } for (int ix = 0; ix < 4; ix++) { const char *text; text = psptr->get_session_desc(ix); if (text != NULL) { gtk_label_set_text(GTK_LABEL(session_desc[ix]), text); } else { gtk_label_set_text(GTK_LABEL(session_desc[ix]), ""); } } } CMsg *newmsg; while ((newmsg = master_queue.get_message()) != NULL) { switch (newmsg->get_value()) { case MSG_SESSION_STARTED: adjust_gui_for_play(); break; case MSG_SESSION_ERROR: case MSG_SESSION_WARNING: // if (psptr != NULL) { char buffer[1024]; snprintf(buffer, sizeof(buffer), "%s cannot be opened\n%s", psptr->get_session_name(), psptr->get_message()); ShowMessage("Open error", buffer); } if (newmsg->get_value() == MSG_SESSION_WARNING) { adjust_gui_for_play(); break; } // otherwise fall through into quit case MSG_RECEIVED_QUIT: //player_debug_message("received quit"); on_main_menu_close(NULL, 0); break; case MSG_SESSION_FINISHED: player_debug_message("gui received finished message"); if (master_playlist != NULL) { SDL_mutexP(command_mutex); const char *start; do { start = master_playlist->get_next(); if (start == NULL) { if (master_looped) start = master_playlist->get_first(); } if (start != NULL) create_session_from_name(start); else { on_stop_clicked(NULL, NULL); } } while (start != NULL && psptr == NULL); SDL_mutexV(command_mutex); } else if (master_looped) { if (play_state == PLAYING) { if (psptr == NULL) break; SDL_mutexP(command_mutex); psptr->pause_all_media(); if (psptr->play_all_media(TRUE, 0.0) < 0) { snprintf(buffer, sizeof(buffer), "Error re-starting session: %s", psptr->get_message()); close_session(); ShowMessage("Play error", buffer); } else { adjust_gui_for_play(); } SDL_mutexV(command_mutex); } } else if (psptr != NULL) { play_state = STOPPED; toggle_button_adjust(play_button, FALSE); toggle_button_adjust(stop_button, TRUE); psptr->pause_all_media(); master_fullscreen = 0; } break; case MSG_SDL_KEY_EVENT: sdl_event_msg_t *msg; uint32_t len; msg = (sdl_event_msg_t *)newmsg->get_message(len); if (len != sizeof(*msg)) { player_error_message("key event message is wrong size %d %d", len, (int) sizeof(*msg)); break; } switch (msg->sym) { case SDLK_ESCAPE: player_debug_message("Got escape"); master_fullscreen = 0; break; case SDLK_RETURN: if ((msg->mod & (KMOD_ALT | KMOD_META)) != 0) { master_fullscreen = 1; } break; case SDLK_c: if ((msg->mod & (KMOD_LCTRL | KMOD_RCTRL)) != 0) { on_main_menu_close(NULL, 0); } break; case SDLK_n: if ((msg->mod & KMOD_CTRL) != 0) { if (master_playlist != NULL) { master_queue.send_message(MSG_SESSION_FINISHED); } } break; case SDLK_x: if ((msg->mod & KMOD_CTRL) != 0) { delete_event(NULL, 0); } break; case SDLK_s: if ((msg->mod & KMOD_CTRL) != 0) { on_menu_seek(NULL, NULL); } break; case SDLK_UP: master_volume += 10; if (master_volume > 100) master_volume = 100; volume_adjusted(master_volume); break; case SDLK_DOWN: if (master_volume > 10) { master_volume -= 10; } else { master_volume = 0; } volume_adjusted(master_volume); break; case SDLK_SPACE: if (play_state == PLAYING) { do_pause(); } else if (play_state == PAUSED && psptr) { SDL_mutexP(command_mutex); if (psptr->play_all_media(FALSE, 0.0) == 0) { adjust_gui_for_play(); SDL_mutexV(command_mutex); } else { SDL_mutexV(command_mutex); snprintf(buffer, sizeof(buffer), "Error re-starting session: %s", psptr->get_message()); close_session(); ShowMessage("Play error", buffer); } } break; case SDLK_HOME: if (psptr && play_state == PLAYING) { psptr->pause_all_media(); if (psptr->play_all_media(TRUE, 0.0) < 0) { snprintf(buffer, sizeof(buffer), "Error re-starting session: %s", psptr->get_message()); close_session(); ShowMessage("Play error", buffer); } } break; case SDLK_RIGHT: if (psptr && psptr->session_is_seekable() && play_state == PLAYING) { SDL_mutexP(command_mutex); play_time = psptr->get_playing_time(); double ptime, maxtime; play_time += TO_U64(10000); ptime = (double)play_time; ptime /= 1000.0; maxtime = psptr->get_max_time(); if (ptime < maxtime) { psptr->pause_all_media(); if (psptr->play_all_media(FALSE, ptime) == 0) { adjust_gui_for_play(); } else { SDL_mutexV(command_mutex); snprintf(buffer, sizeof(buffer), "Error re-starting session: %s", psptr->get_message()); close_session(); ShowMessage("Play error", buffer); break; } } SDL_mutexV(command_mutex); } break; case SDLK_LEFT: if (psptr && psptr->session_is_seekable() && play_state == PLAYING) { SDL_mutexP(command_mutex); play_time = psptr->get_playing_time(); double ptime; if (play_time >= TO_U64(10000)) { play_time -= TO_U64(10000); ptime = (double)play_time; ptime /= 1000.0; psptr->pause_all_media(); if (psptr->play_all_media(FALSE, ptime) == 0) { adjust_gui_for_play(); } else { SDL_mutexV(command_mutex); snprintf(buffer, sizeof(buffer), "Error starting session: %s", psptr->get_message()); close_session(); ShowMessage("Play error", buffer); break; } } SDL_mutexV(command_mutex); } break; case SDLK_PAGEUP: if (master_screen_size < 200) { change_video_size (master_screen_size * 2); } break; case SDLK_PAGEDOWN: if (master_screen_size > 50) { change_video_size (master_screen_size / 2); } break; case SDLK_0: case SDLK_1: case SDLK_2: case SDLK_3: case SDLK_4: case SDLK_5: if ((msg->mod & KMOD_CTRL) != 0) { set_aspect_ratio(msg->sym - SDLK_0); } break; default: break; } break; } delete newmsg; } return (TRUE); // keep timer going}/* * Main routine - set up window */int main (int argc, char **argv){ static struct option orig_options[] = { { "version", 0, 0, 'v' }, { "help", 0, 0, 'H'}, { "config-vars", 0, 0, 'c'}, { NULL, 0, 0, 0 } }; player_error_message("%s version %s", argv[0], MPEG4IP_VERSION); bool have_unknown_opts = false; char buffer[FILENAME_MAX]; char *home = getenv("HOME"); if (home == NULL) {#ifdef _WIN32 strcpy(buffer, "gmp4player_rc");#else strcpy(buffer, ".gmp4player_rc");#endif } else { strcpy(buffer, home); strcat(buffer, "/.gmp4player_rc"); } initialize_plugins(&config); config.SetFileName(buffer); config.InitializeIndexes(); opterr = 0; while (true) { int c = -1; int option_index = 0; c = getopt_long_only(argc, argv, "af:hsvc", orig_options, &option_index); if (c == -1) break; switch (c) { case 'H': fprintf(stderr, "Usage: %s [--help] [--version] [--<config variable>=<value>] media-to-play\n", argv[0]); fprintf(stderr, "Use [--config-vars] to dump configuration variables\n"); exit(-1); case 'c': config.DisplayHelp(); exit(0); case 'v': fprintf(stderr, "%s version %s\n", argv[0], MPEG4IP_VERSION); exit(0); case '?': default: have_unknown_opts = true; break; } } command_mutex = SDL_CreateMutex(); config.ReadFile(); if (config.get_config_string(CONFIG_LOG_FILE) != NULL) { open_log_file(config.get_config_string(CONFIG_LOG_FILE)); } if (have_unknown_opts) { /* * Create an struct option that allows all the loaded configuration * options */ struct option *long_options; uint32_t origo = sizeof(orig_options) / sizeof(*orig_options); long_options = create_long_opts_from_config(&config, orig_options, origo, 128); if (long_options == NULL) { player_error_message("Couldn't create options"); exit(-1); } optind = 1; // command line parsing while (true) { int c = -1; int option_index = 0; config_index_t ix; c = getopt_long_only(argc, argv, "af:hsv", long_options, &option_index); if (c == -1) break; /* * We set a value of 128 to 128 + number of variables * we added the original options to the block, but don't * process them here. */ if (c >= 128) { // we have an option from the config file ix = c - 128; player_debug_message("setting %s to %s", config.GetNameFromIndex(ix), optarg); if (config.GetTypeFromIndex(ix) == CONFIG_TYPE_BOOL && optarg == NULL) { config.SetBoolValue(ix, true); } else if (optarg == NULL) { player_error_message("Missing argument with variable %s", config.GetNameFromIndex(ix)); } else config.SetVariableFromAscii(ix, optarg); } else if (c == '?') { fprintf(stderr, "Usage: %s [--help] [--version] [--<config variable>=<value>] media-to-play\n", argv[0]); exit(-1); } } free(long_options); } gtk_init(&argc, &argv); const char *read; playlist = g_list_append(playlist, (void *)""); read = config.get_config_string(CONFIG_PREV_FILE_0); if (read != NULL) { gchar *newone = g_strdup(read); playlist = g_list_append(playlist, newone); } read = config.get_config_string(CONFIG_PREV_FILE_1); if (read != NULL) { gchar *newone = g_strdup(read); playlist = g_list_append(playlist, newone); } read = config.get_config_string(CONFIG_PREV_FILE_2); if (read != NULL) { gchar *newone = g_strdup(read); playlist = g_list_append(playlist, newone); } read = config.get_config_string(CONFIG_PREV_FILE_3); if (read != NULL) { gchar *newone = g_strdup(read); playlist = g_list_append(playlist, newone); } last_file = g_strdup(config.get_config_string(CONFIG_PREV_DIRECTORY)); master_looped = config.GetBoolValue(CONFIG_LOOPED); master_muted = config.GetBoolValue(CONFIG_MUTED); master_volume = config.get_config_value(CONFIG_VOLUME); rtsp_set_error_func(library_message); rtsp_set_loglevel(config.get_config_value(CONFIG_RTSP_DEBUG)); rtp_set_error_msg_func(library_message); rtp_set_loglevel(config.get_config_value(CONFIG_RTP_DEBUG)); sdp_set_error_func(library_message); sdp_set_loglevel(config.get_config_value(CONFIG_SDP_DEBUG)); http_set_error_func(library_message); http_set_loglevel(config.get_config_value(CONFIG_HTTP_DEBUG)); mpeg2t_set_error_func(library_message); mpeg2t_set_loglevel(config.get_config_value(CONFIG_MPEG2T_DEBUG)); mpeg2ps_set_error_func(library_message); mpeg2ps_set_loglevel(config.get_config_value(CONFIG_MPEG2PS_DEBUG)); if (config.get_config_value(CONFIG_RX_SOCKET_SIZE) != 0) { rtp_set_receive_buffer_default_size(config.get_config_value(CONFIG_RX_SOCKET_SIZE)); } /* * Set up main window */ main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_policy(GTK_WINDOW(main_window), FALSE, TRUE, FALSE); sprintf(buffer, "Cisco Open Source Streaming Video Player %s", MPEG4IP_VERSION); gtk_window_set_title(GTK_WINDOW(main_window), buffer); gtk_widget_set_uposition(GTK_WIDGET(main_window), 10, 10); gtk_widget_set_usize(main_window, 450, 200); gtk_window_set_default_size(GTK_WINDOW(main_window), 460, 210); gtk_signal_connect(GTK_OBJECT(main_window), "delete_event", GTK_SIGNAL_FUNC(delete_event), NULL); main_vbox = gtk_vbox_new(FALSE, 1); gtk_widget_show(main_vbox); // add stuff accel_group = gtk_accel_group_new();#ifdef HAVE_GTK_2_0 gtk_window_add_accel_group(GTK_WINDOW(main_window), accel_group);#else gtk_accel_group_attach(accel_group, GTK_OBJECT(main_window));#endif tooltips = gtk_tooltips_new(); GtkWidget *menubar, *menu, *menuitem; menubar = gtk_menu_bar_new(); gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, FALSE, 0); gtk_widget_show(menubar); menu = CreateBarSubMenu(menubar, "File"); menuitem = CreateMenuItem(menu, accel_group, tooltips, "Open", "^O", "Open local media file", GTK_SIGNAL_FUNC(on_browse_button_clicked), NULL); close_menuitem = CreateMenuItem(menu, accel_group, tooltips, "Close", "^C", "Close file/stream being viewed", GTK_SIGNAL_FUNC(on_main_menu_close), NULL); // NULL entry is a seperator menuitem = CreateMenuItem(menu, accel_group, tooltips, NULL, NULL, NULL, NULL, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -