⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gui_main.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ *  * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. *  * The Original Code is MPEG4IP. *  * The Initial Developer of the Original Code is Cisco Systems Inc. * Portions created by Cisco Systems Inc. are * Copyright (C) Cisco Systems Inc. 2000-2005.  All Rights Reserved. *  * Contributor(s):  *              Bill May        wmay@cisco.com *            Peter Maersk-Moller     peter@maersk-moller.net *//* * gui_main.cpp - Contains the gtk based gui for this player. */#include <stdlib.h>#include <stdio.h>#include "player_session.h"#include "player_media.h"#include <glib.h>#include <gtk/gtk.h>#include "gui_utils.h"#include "media_utils.h"#include "player_util.h"#include "gui_xpm.h"#include <syslog.h>#include <rtsp/rtsp_client.h>#include "our_config_file.h"#include "playlist.h"#include <libhttp/http.h>#include <rtp/debug.h>#include "codec_plugin_private.h"#include <mpeg2t/mpeg2_transport.h>#include "mpeg4ip_getopt.h"#include "mpeg2_ps.h"/* ??? */#ifndef LOG_PRI#define LOG_PRI(p) ((p) & LOG_PRIMASK)#endif/* Local variables */static GtkWidget *main_window;static GtkWidget *main_vbox;static GtkWidget *close_menuitem, *seek_menuitem;static GtkAccelGroup *accel_group = NULL;static GtkTooltips         *tooltips = NULL;static GList *playlist = NULL;static GtkWidget *combo;static volatile enum {  PLAYING_NONE,  PLAYING,  STOPPED,  PAUSED,} play_state = PLAYING_NONE;static CPlaylist *master_playlist;static CPlayerSession *psptr = NULL;static CMsgQueue master_queue;static GtkWidget *play_button;static GtkWidget *pause_button;static GtkWidget *stop_button;//static GtkWidget *rewind_button;//static GtkWidget *ff_button;static GtkWidget *speaker_button;static GtkWidget *volume_slider;static GtkWidget *time_slider;static GtkWidget *time_disp;static GtkWidget *session_desc[5];static SDL_mutex *command_mutex;static bool master_looped;static int master_volume;static bool master_muted;static int master_fullscreen = 0;static uint64_t master_time;static int time_slider_pressed = 0;static int master_screen_size = 100;static const char *last_entry = NULL;static const gchar *last_file = NULL;static int doing_seek = 0;static GtkWidget *videoradio[3];static GtkWidget *aspectratio[6];static GtkTargetEntry drop_types[] = {  { "text/plain", 0, 1 },};static void media_list_query (CPlayerSession *psptr,			      uint num_video, 			      video_query_t *vq,			      uint num_audio,			      audio_query_t *aq,			      uint num_text,			      text_query_t *tq){  if (num_video > 0) {    if (config.get_config_value(CONFIG_PLAY_VIDEO) != 0) {      vq[0].enabled = 1;    }   }  if (num_audio > 0) {    if (config.get_config_value(CONFIG_PLAY_AUDIO) != 0) {      aq[0].enabled = 1;    }   }  if (num_text > 0) {    if (config.get_config_value(CONFIG_PLAY_TEXT) != 0) {      tq[0].enabled = 1;    }   }}static control_callback_vft_t cc_vft = {  media_list_query,};/* * toggle_button_adjust - make sure a toggle button reflects the correct * state */static void toggle_button_adjust (GtkWidget *button, int state){  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)) == state)    return;  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), state);}/* * close_session - delete the session, and set the various gui pieces */static void close_session (void){  if (psptr != NULL) {    delete psptr;    psptr = NULL;    play_state = PLAYING_NONE;    gtk_widget_set_sensitive(close_menuitem, 0);    gtk_widget_set_sensitive(seek_menuitem, 0);    toggle_button_adjust(play_button, FALSE);    toggle_button_adjust(pause_button, FALSE);    toggle_button_adjust(stop_button, FALSE);    gtk_widget_set_sensitive(stop_button, 0);    gtk_widget_set_sensitive(play_button, 0);    gtk_widget_set_sensitive(pause_button, 0);    gtk_widget_set_sensitive(time_slider, 0);  }}/* * When we hit play, adjust the gui */static void adjust_gui_for_play (void){  gtk_widget_set_sensitive(close_menuitem, 1);  gtk_widget_set_sensitive(play_button, 1);  gtk_widget_set_sensitive(pause_button, 1);  gtk_widget_set_sensitive(stop_button, 1);#ifdef HAVE_GTK_2_0  gtk_range_set_value(GTK_RANGE(time_slider), 0.0);#endif  if (psptr->session_is_seekable()) {    gtk_widget_set_sensitive(time_slider, 1);    gtk_widget_set_sensitive(seek_menuitem, 1);  }  play_state = PLAYING;  toggle_button_adjust(play_button, TRUE);  toggle_button_adjust(stop_button, FALSE);  toggle_button_adjust(pause_button, FALSE);  gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(combo)->entry), last_entry);  gtk_editable_select_region(GTK_EDITABLE(GTK_COMBO(combo)->entry), 0, -1);  gtk_editable_set_position(GTK_EDITABLE(GTK_COMBO(combo)->entry), -1);  gtk_widget_grab_focus(combo);}static void set_aspect_ratio(uint32_t newaspect){  // Unfortunately psptr is NULL upon startup so we won't set aspect ratio  // correct  if (config.get_config_value(CONFIG_ASPECT_RATIO) == newaspect) {    return;  }  if (newaspect > 5) newaspect = 0;  config.set_config_value(CONFIG_ASPECT_RATIO, newaspect);  if (psptr != NULL) {    switch (newaspect) {    case 1 :       psptr->set_screen_size(master_screen_size/50,master_fullscreen,4,3);      break;    case 2 :       psptr->set_screen_size(master_screen_size/50,master_fullscreen,16,9);      break;    case 3 :       psptr->set_screen_size(master_screen_size/50,master_fullscreen,185,100);      break;    case 4 :       psptr->set_screen_size(master_screen_size/50,master_fullscreen,235,100);      break;    case 5:      psptr->set_screen_size(master_screen_size/50,master_fullscreen, 1, 1);      break;    default:       psptr->set_screen_size(master_screen_size/50,master_fullscreen,0,0);      newaspect = 0;      break;    }  }   gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(aspectratio[newaspect]), TRUE);  }static void create_session_from_name (const char *name){  gint x, y, w, h;  GdkWindow *window;  //  int display_err = 0;      window = GTK_WIDGET(main_window)->window;  gdk_window_get_position(window, &x, &y);  gdk_window_get_size(window, &w, &h);  y += h + 40;  if (config.get_config_value(CONFIG_PLAY_AUDIO) == 0 &&      config.get_config_value(CONFIG_PLAY_VIDEO) == 0 &&      config.get_config_value(CONFIG_PLAY_TEXT) == 0) {    ShowMessage("Hey Dummy", "You have both audio and video disabled");    return;  }  // If we're already running a session, close it.  if (psptr != NULL) {    close_session();  }  //  bool do_delete = false;  psptr = start_session(&master_queue, 			NULL,			NULL,			name, 			&cc_vft,			master_muted ? 0 : master_volume,			x, 			y, 			master_screen_size / 50);  if (psptr != NULL) {    adjust_gui_for_play();  }}/* * start a session */static void start_session_from_name (const char *name){  GList *p;  int in_list = 0;  // Save the last file, so we can use it next time we do a file open  if (last_entry != NULL) {    free((void *)last_entry);  }  last_entry = strdup(name);  if (strstr(name, "://") == NULL) {    if (last_file != NULL) {      free((void *)last_file);      last_file = NULL;    }    last_file = g_strdup(name);    config.set_config_string(CONFIG_PREV_DIRECTORY, last_file);  }  // See if entry is already in the list.  p = g_list_first(playlist);  while (p != NULL && in_list == 0) {    if (g_strcasecmp(name, (const gchar *)p->data) == 0) {      in_list = 1;    }    p = g_list_next(p);  }    SDL_mutexP(command_mutex);    // If we're running a playlist, close it now.  if (master_playlist != NULL) {    delete master_playlist;    master_playlist = NULL;  }  // Create a new player session  const char *suffix = strrchr(name, '.');  if ((suffix != NULL) &&       ((strcasecmp(suffix, ".mp4plist") == 0) ||       (strcasecmp(suffix, ".mxu") == 0) ||       (strcasecmp(suffix, ".m4u") == 0) ||       (strcasecmp(suffix, ".gmp4_playlist") == 0))) {    const char *errmsg = NULL;    master_playlist = new CPlaylist(name, &errmsg);    if (errmsg != NULL) {      ShowMessage("Playlist error", errmsg);    } else {      create_session_from_name(master_playlist->get_first());    }  } else {    create_session_from_name(name);  }  // Add this file to the drop down list  // If we're playing, adjust the gui  if (psptr != NULL) {    if (in_list == 0) {      config.set_config_string(CONFIG_PREV_FILE_3, 				config.get_config_string(CONFIG_PREV_FILE_2));      config.set_config_string(CONFIG_PREV_FILE_2, 				config.get_config_string(CONFIG_PREV_FILE_1));      config.set_config_string(CONFIG_PREV_FILE_1, 				config.get_config_string(CONFIG_PREV_FILE_0));      config.set_config_string(CONFIG_PREV_FILE_0, name);    }  }  if (in_list == 0) {    gchar *newone = g_strdup(name);    playlist = g_list_append(playlist, newone);    gtk_combo_set_popdown_strings (GTK_COMBO(combo), playlist);    gtk_widget_show(combo);  }  SDL_mutexV(command_mutex);}/* * delete_event - called when window closed */void delete_event (GtkWidget *widget, gpointer *data){  if (psptr != NULL) {    delete psptr;  }  if (master_playlist != NULL) {    delete master_playlist;  }  if (config.get_config_string(CONFIG_LOG_FILE) != NULL) {    close_log_file();  }  config.WriteToFile();  close_plugins();  gtk_main_quit();}static void on_main_menu_close (GtkWidget *window, gpointer data){  SDL_mutexP(command_mutex);  close_session();  master_fullscreen = 0;  SDL_mutexV(command_mutex);}static GtkWidget *seek_dialog;static void on_seek_destroy (GtkWidget *window, gpointer data){  gtk_widget_destroy(window);  doing_seek = 0;}static void on_seek_activate (GtkWidget *window, gpointer data){  const gchar *entry =     gtk_entry_get_text(GTK_ENTRY(data));  double time;  bool good = true;  if (strchr(entry, ':') == NULL) {    if (sscanf(entry, "%lf", &time) != 1) {      good = false;    }  } else {    int hr, min;    hr = 0;     min = 0;    if (sscanf(entry, "%u", &hr) == 1) {      entry = strchr(entry, ':') + 1;      if (strchr(entry, ':') == NULL) {	min = hr;	hr = 0;      } else {	if (sscanf(entry, "%u", &min) != 1) {	  good = false;	} else 	  entry = strchr(entry, ':') + 1;      }      if (good) {	if (sscanf(entry, "%lf", &time) == 1) {	  time += ((hr * 60) + min) * 60;	} else good = false;      }    } else good = false;  }	  if (good && psptr && time < psptr->get_max_time()) {    if (play_state == PLAYING) {      psptr->pause_all_media();    }    char errmsg[512];    int ret = 	psptr->play_all_media(time == 0.0 ? TRUE : FALSE, 			      time);    if (ret == 0) {      adjust_gui_for_play();    }    if (ret != 0) {      char buffer[1024];      close_session();      snprintf(buffer, sizeof(buffer), "Error seeking session: %s", 	       errmsg);      ShowMessage("Play error", buffer);    }   }  on_seek_destroy(seek_dialog, data);}static void on_seek_cancel (GtkWidget *window, gpointer data){  on_seek_destroy(seek_dialog, data);}static void on_menu_seek (GtkWidget *window, gpointer data){  if (master_fullscreen || doing_seek != 0) return;  seek_dialog = gtk_dialog_new();  gtk_signal_connect(GTK_OBJECT(seek_dialog),		     "destroy",		     GTK_SIGNAL_FUNC(on_seek_destroy),		     seek_dialog);  gtk_window_set_title(GTK_WINDOW(seek_dialog), "Seek to");  gtk_container_border_width(GTK_CONTAINER(seek_dialog), 5);  GtkWidget *vbox;  vbox = gtk_vbox_new(FALSE, 1);  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(seek_dialog)->action_area),		     vbox, 		     TRUE, 		     TRUE,		     0);  gtk_widget_show(vbox);  GtkWidget *hbox;  hbox = gtk_hbox_new(FALSE, 1);  gtk_widget_show(hbox);  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);  GtkWidget *seek_entry;  seek_entry = gtk_entry_new();  gtk_signal_connect(GTK_OBJECT(seek_entry),		     "activate",		     GTK_SIGNAL_FUNC(on_seek_activate),		     seek_entry);  gtk_box_pack_start(GTK_BOX(hbox), seek_entry, TRUE, TRUE, 0);  gtk_widget_show(seek_entry);  hbox = gtk_hbox_new(FALSE, 1);  gtk_widget_show(hbox);  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);  GtkWidget *button;  button = gtk_button_new_with_label("Ok");  gtk_signal_connect(GTK_OBJECT(button), "clicked",		     GTK_SIGNAL_FUNC(on_seek_activate),		     seek_entry);  gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);  gtk_widget_show(button);  button = gtk_button_new_with_label("Cancel");  gtk_signal_connect(GTK_OBJECT(button), "clicked",		     GTK_SIGNAL_FUNC(on_seek_cancel),		     NULL);  gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);  gtk_widget_show(button);   gtk_widget_show(seek_dialog);  doing_seek = 1;}static void on_main_menu_help (GtkWidget *window, gpointer data){}static void on_main_menu_about (GtkWidget *window, gpointer data){  char buffer[1024];  sprintf(buffer,	  "gmp4player Version %s.\n"	  "An open source file/streaming MPEG4 player\n"	  "Developed by Cisco Systems using the\n"	  "following open source packages:\n"	  "\n"	  "SDL, SMPEG audio (MP3) from lokigames\n"	  "RTP from UCL\n"	  "ISO reference decoder for MPEG4\n"	  "FAAC decoder\n"	  "Developed by Bill May, 10/00 to present", MPEG4IP_VERSION	  );  ShowMessage("About gmp4player",buffer);}/* * on_drag_data_received - copied from gtv, who copied from someone else */static void on_drag_data_received (GtkWidget *widget,				   GdkDragContext *context,				   gint x,				   gint y,				   GtkSelectionData *selection_data,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -