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

📄 gui_main.cpp

📁 网络MPEG4IP流媒体开发源代码
💻 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, 2001.  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>/* ??? */#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 int master_looped;static int master_volume;static int 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[5];static GtkTargetEntry drop_types[] = {  { "text/plain", 0, 1 }};static void media_list_query (CPlayerSession *psptr,			      int num_video, 			      video_query_t *vq,			      int num_audio,			      audio_query_t *aq){  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;    }   }}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(int 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 > 4 || newaspect < 0) 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;      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;  char errmsg[512];      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) {    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();  }  psptr = new CPlayerSession(&master_queue,			     NULL,			     name);  if (psptr != NULL) {    errmsg[0] = '\0';    // See if we can create media for this session    int ret = parse_name_for_session(psptr, name, errmsg, sizeof(errmsg),				     &cc_vft);    if (ret >= 0) {      // Yup - valid session.  Set volume, set up sync thread, and      // start the session      if (ret > 0) {	ShowMessage("Warning", errmsg);      }      if (master_muted == 0)	psptr->set_audio_volume(master_volume);      else	psptr->set_audio_volume(0);      psptr->set_up_sync_thread();      psptr->set_screen_location(x, y);      master_fullscreen = config.get_config_value(CONFIG_FULL_SCREEN);      set_aspect_ratio(config.get_config_value(CONFIG_ASPECT_RATIO));      if (psptr->play_all_media(TRUE, 0.0, errmsg,sizeof(errmsg)) < 0) {	delete psptr;	psptr = NULL;	display_err = 1;      } else {	adjust_gui_for_play();      }    } else {      display_err = 1;      delete psptr;      psptr = NULL;    }  }  if (display_err != 0) {    // Nope - display a message    char buffer[1024];    snprintf(buffer, sizeof(buffer), "%s cannot be opened\n%s", name,	     errmsg);    ShowMessage("Open error", buffer);  }}/* * 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, strdup(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, ".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.move_config_strings(CONFIG_PREV_FILE_3, CONFIG_PREV_FILE_2);      config.move_config_strings(CONFIG_PREV_FILE_2, CONFIG_PREV_FILE_1);      config.move_config_strings(CONFIG_PREV_FILE_1, CONFIG_PREV_FILE_0);      config.set_config_string(CONFIG_PREV_FILE_0, strdup(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;  }  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, 			      errmsg, 			      sizeof(errmsg));    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;

⌨️ 快捷键说明

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