📄 gui_main.cpp
字号:
uint32_t count, const char *name){ for (uint32_t ix = 0; ix < count; ix++) { if (strcmp(list[ix], name) == 0) { return ix; } } return 0;}static void DisplayAudioProfiles (void){ free_profile_names(audio_profile_names, audio_profile_names_count); DisplayProfiles(lookup_widget(MainWindow, "AudioProfile"), (CConfigList *)AVFlow->m_audio_profile_list, &audio_profile_names, &audio_profile_names_count);}static void DisplayVideoProfiles (void) { free_profile_names(video_profile_names, video_profile_names_count); DisplayProfiles(lookup_widget(MainWindow, "VideoProfile"), (CConfigList *)AVFlow->m_video_profile_list, &video_profile_names, &video_profile_names_count);}#ifdef HAVE_TEXTstatic void DisplayTextProfiles (void){ free_profile_names(text_profile_names, text_profile_names_count); DisplayProfiles(lookup_widget(MainWindow, "TextProfile"), (CConfigList *)AVFlow->m_text_profile_list, &text_profile_names, &text_profile_names_count);}#endif/* * SetStreamTransmit - sets up information about the stream sdp */static void DisplayStreamTransmit (CMediaStream *ms) { GtkWidget *temp; bool is_set; temp = lookup_widget(MainWindow, "StreamTransmit"); is_set = ms->GetBoolValue(STREAM_TRANSMIT); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(temp), is_set); is_set = is_set && !started; gtk_widget_set_sensitive(temp, !started); temp = lookup_widget(MainWindow, "StreamSdpFileEntry"); gtk_entry_set_text(GTK_ENTRY(temp), ms->GetStringValue(STREAM_SDP_FILE_NAME)); gtk_widget_set_sensitive(temp, is_set); temp = lookup_widget(MainWindow, "SDPFileOpenButton"); gtk_widget_set_sensitive(temp, is_set);}/* * SetStreamRecord - set the stream's record settings */static void DisplayStreamRecord (CMediaStream *ms) { GtkWidget *temp; bool is_set; temp = lookup_widget(MainWindow, "StreamRecord"); is_set = ms->GetBoolValue(STREAM_RECORD); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(temp), is_set); is_set = is_set && !started; gtk_widget_set_sensitive(temp, !started); temp = lookup_widget(MainWindow, "StreamRecordFileEntry"); gtk_entry_set_text(GTK_ENTRY(temp), ms->GetStringValue(STREAM_RECORD_MP4_FILE_NAME)); gtk_widget_set_sensitive(temp, is_set); temp = lookup_widget(MainWindow, "RecordFileOpenButton"); gtk_widget_set_sensitive(temp, is_set);}/* * DisplayStreamsInView - load the streams into the stream view box * only occurs at startup, or if a stream is added/deleted */static void DisplayStreamsInView (GtkTreeView *StreamTreeView = NULL, const char *selected_stream = NULL) { if (StreamTreeView == NULL) { StreamTreeView = GTK_TREE_VIEW(lookup_widget(MainWindow, "StreamTreeView")); } GtkTreeSelection *select = gtk_tree_view_get_selection(StreamTreeView); GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING); GtkTreeIter iter; GtkTreeIter selected_iter; bool selected = false; CMediaStream *ms = AVFlow->m_stream_list->GetHead(); while (ms != NULL) { // Add the stream name to the list. gtk_list_store_append(store, &iter); // check if it should be highlighted if (selected_stream == NULL) { if (selected == false) { selected_iter = iter; selected = true; } } else { if (strcmp(selected_stream, ms->GetName()) == 0) { selected_iter = iter; selected = true; } } gtk_list_store_set(store, &iter, 0, ms->GetName(), -1); ms = ms->GetNext(); } gtk_tree_view_set_model(StreamTreeView, GTK_TREE_MODEL(store)); if (selected) gtk_tree_selection_select_iter(select, &selected_iter);}/* * DisplayStreamData - when a stream is selected, we need to change a lot * of things */static void DisplayStreamData (const char *stream){ CMediaStream *ms; ms = AVFlow->m_stream_list->FindStream(stream); if (ms == NULL) { ms = AVFlow->m_stream_list->GetHead(); } CHECK_AND_FREE(SelectedStream); SelectedStream = strdup(ms->GetName()); GtkWidget *temp, *temp2; const char *ptr; char buffer[1024]; // Name, description temp = lookup_widget(MainWindow, "StreamNameLabel"); gtk_label_set_text(GTK_LABEL(temp), SelectedStream); temp = lookup_widget(MainWindow, "StreamCaption"); ptr = ms->GetStringValue(STREAM_CAPTION); gtk_entry_set_text(GTK_ENTRY(temp), ptr == NULL ? "" : ptr); temp = lookup_widget(MainWindow, "StreamDescription"); ptr = ms->GetStringValue(STREAM_DESCRIPTION); gtk_entry_set_text(GTK_ENTRY(temp), ptr == NULL ? "" : ptr); // transmit and mp4 file DisplayStreamTransmit(ms); DisplayStreamRecord(ms); uint32_t index; // Audio information - enabled, profile, change tooltip to reflect settings temp = lookup_widget(MainWindow, "AudioEnabled"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(temp), ms->GetBoolValue(STREAM_AUDIO_ENABLED)); index = get_index_from_profile_list(audio_profile_names, audio_profile_names_count, ms->GetStringValue(STREAM_AUDIO_PROFILE)); temp = lookup_widget(MainWindow, "AudioProfile"); gtk_option_menu_set_history(GTK_OPTION_MENU(temp), index); bool enabled = ms->GetBoolValue(STREAM_AUDIO_ENABLED); temp2 = lookup_widget(MainWindow, "StreamAudioInfo"); if (enabled == false) { gtk_label_set_text(GTK_LABEL(temp2), "audio disabled"); gtk_tooltips_set_tip(tooltips, temp, "Select/Add/Customize Audio Profile", NULL); } else { CAudioProfile *ap = ms->GetAudioProfile(); float srate = ((float)ap->GetIntegerValue(CFG_AUDIO_SAMPLE_RATE)) / 1000.0; float sbit = ((float)ap->GetIntegerValue(CFG_AUDIO_BIT_RATE)) / 1000.0; snprintf(buffer, sizeof(buffer), "%s %gKbps", ap->GetStringValue(CFG_AUDIO_ENCODING), sbit); gtk_label_set_text(GTK_LABEL(temp2), buffer); snprintf(buffer, sizeof(buffer), "Select/Add/Customize Audio Profile\n" "%s(%s), %s, %gKHz %gKbps", ap->GetStringValue(CFG_AUDIO_ENCODING), ap->GetStringValue(CFG_AUDIO_ENCODER), ap->GetIntegerValue(CFG_AUDIO_CHANNELS) == 1 ? "mono" : "stereo", srate, sbit); gtk_tooltips_set_tip(tooltips, temp, buffer, NULL); } temp2 = lookup_widget(MainWindow, "AudioTxAddrLabel"); if (enabled == false || ms->GetBoolValue(STREAM_TRANSMIT) == false) { gtk_label_set_text(GTK_LABEL(temp2), "disabled"); } else { snprintf(buffer, sizeof(buffer), "%s:%u", ms->GetStringValue(STREAM_AUDIO_DEST_ADDR), ms->GetIntegerValue(STREAM_AUDIO_DEST_PORT)); gtk_label_set_text(GTK_LABEL(temp2), buffer); } enabled = enabled && !started; gtk_widget_set_sensitive(temp, enabled); temp = lookup_widget(MainWindow, "AudioTxAddrButton"); gtk_widget_set_sensitive(temp, enabled); // Video Information temp = lookup_widget(MainWindow, "VideoEnabled"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(temp), ms->GetBoolValue(STREAM_VIDEO_ENABLED)); index = get_index_from_profile_list(video_profile_names, video_profile_names_count, ms->GetStringValue(STREAM_VIDEO_PROFILE)); temp = lookup_widget(MainWindow, "VideoProfile"); gtk_option_menu_set_history(GTK_OPTION_MENU(temp), index); enabled = ms->GetBoolValue(STREAM_VIDEO_ENABLED); temp2 = lookup_widget(MainWindow, "StreamVideoInfo"); if (enabled == false) { gtk_label_set_text(GTK_LABEL(temp2), "video disabled"); gtk_tooltips_set_tip(tooltips, temp, "Select/Add/Customize Video Profile", NULL); } else { CVideoProfile *vp = ms->GetVideoProfile(); snprintf(buffer, sizeof(buffer), "%s %ux%u %uKbps", vp->GetStringValue(CFG_VIDEO_ENCODING), vp->m_videoWidth, vp->m_videoHeight, vp->GetIntegerValue(CFG_VIDEO_BIT_RATE)); gtk_label_set_text(GTK_LABEL(temp2), buffer); snprintf(buffer, sizeof(buffer), "Select/Add/Customize Video Profile\n%s(%s) %uX%u %uKbps@%gfps", vp->GetStringValue(CFG_VIDEO_ENCODING), vp->GetStringValue(CFG_VIDEO_ENCODER), vp->m_videoWidth, vp->m_videoHeight, vp->GetIntegerValue(CFG_VIDEO_BIT_RATE), vp->GetFloatValue(CFG_VIDEO_FRAME_RATE)); gtk_tooltips_set_tip(tooltips, temp, buffer, NULL); } temp2 = lookup_widget(MainWindow, "StreamVideoPreview"); gtk_widget_set_sensitive(temp2, enabled); if (MyConfig->GetBoolValue(CONFIG_VIDEO_PREVIEW)) { const char *preview = MyConfig->GetStringValue(CONFIG_VIDEO_PREVIEW_STREAM); if (preview != NULL) { gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(temp2), strcmp(preview, SelectedStream) == 0); } else { temp2 = lookup_widget(MainWindow, "VideoSourcePreview"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(temp2), true); } } gtk_widget_set_sensitive(temp2, enabled); temp2 = lookup_widget(MainWindow, "VideoTxAddrLabel"); if (enabled == false || ms->GetBoolValue(STREAM_TRANSMIT) == false) { gtk_label_set_text(GTK_LABEL(temp2), "disabled"); } else { snprintf(buffer, sizeof(buffer), "%s:%u", ms->GetStringValue(STREAM_VIDEO_DEST_ADDR), ms->GetIntegerValue(STREAM_VIDEO_DEST_PORT)); gtk_label_set_text(GTK_LABEL(temp2), buffer); } enabled = enabled && !started; gtk_widget_set_sensitive(temp, enabled); temp = lookup_widget(MainWindow, "VideoTxAddrButton"); gtk_widget_set_sensitive(temp, enabled);#ifdef HAVE_TEXT // text information temp = lookup_widget(MainWindow, "TextEnabled"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(temp), ms->GetBoolValue(STREAM_TEXT_ENABLED)); index = get_index_from_profile_list(text_profile_names, text_profile_names_count, ms->GetStringValue(STREAM_TEXT_PROFILE)); temp = lookup_widget(MainWindow, "TextProfile"); gtk_option_menu_set_history(GTK_OPTION_MENU(temp), index); enabled = ms->GetBoolValue(STREAM_TEXT_ENABLED); temp2 = lookup_widget(MainWindow, "StreamTextInfo"); if (enabled == false) { gtk_label_set_text(GTK_LABEL(temp2), "text disabled"); gtk_tooltips_set_tip(tooltips, temp, "Select/Add/Customize Audio Profile", NULL); } else { CTextProfile *tp = ms->GetTextProfile(); snprintf(buffer, sizeof(buffer), "%s", tp->GetStringValue(CFG_TEXT_ENCODING)); gtk_label_set_text(GTK_LABEL(temp2), buffer); snprintf(buffer, sizeof(buffer), "Select/Add/Customize Text Profile\n" "%s", tp->GetStringValue(CFG_TEXT_ENCODING)); gtk_tooltips_set_tip(tooltips, temp, buffer, NULL); } temp2 = lookup_widget(MainWindow, "TextTxAddrLabel"); if (enabled == false || ms->GetBoolValue(STREAM_TRANSMIT) == false) { gtk_label_set_text(GTK_LABEL(temp2), "disabled"); } else { snprintf(buffer, sizeof(buffer), "%s:%u", ms->GetStringValue(STREAM_TEXT_DEST_ADDR), ms->GetIntegerValue(STREAM_TEXT_DEST_PORT)); gtk_label_set_text(GTK_LABEL(temp2), buffer); } enabled = enabled && !started; gtk_widget_set_sensitive(temp, enabled); temp = lookup_widget(MainWindow, "TextTxAddrButton"); gtk_widget_set_sensitive(temp, enabled);#endif}/**************************************************************************** * Main window routines called from other dialogs ****************************************************************************//* * OnAudioProfileFinished and OnVideoProfileFinished get called * when an audio or a video profile are updated. This will change * settings, as well as validating the information for the sources */void OnAudioProfileFinished (CAudioProfile *p){ if (p != NULL) { CMediaStream *ms = GetSelectedStream(); ms->SetAudioProfile(p->GetName()); DisplayAudioProfiles(); } AVFlow->ValidateAndUpdateStreams(); MainWindowDisplaySources(); DisplayStreamData(SelectedStream);}void OnVideoProfileFinished (CVideoProfile *p){ if (p != NULL) { // new video profile created - set the stream to it CMediaStream *ms = GetSelectedStream(); ms->SetVideoProfile(p->GetName()); DisplayVideoProfiles(); // have it appear in the list } AVFlow->ValidateAndUpdateStreams(); MainWindowDisplaySources(); DisplayStreamData(SelectedStream); if (MyConfig->GetBoolValue(CONFIG_VIDEO_PREVIEW)) { AVFlow->StartVideoPreview(); }}void OnTextProfileFinished (CTextProfile *p){ if (p != NULL) { CMediaStream *ms = GetSelectedStream(); ms->SetTextProfile(p->GetName()); DisplayTextProfiles(); } AVFlow->ValidateAndUpdateStreams(); MainWindowDisplaySources(); DisplayStreamData(SelectedStream);}void RefreshCurrentStream (void){ DisplayStreamData(SelectedStream);}// Top level menu handlersstatic void onConfigFileOpenResponse (GtkDialog *sel, gint response_id, gpointer user_data){ if (GTK_RESPONSE_OK == response_id) { const char *name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(sel)); struct stat statbuf; if (GPOINTER_TO_INT(user_data) == false) { if (stat(name, &statbuf) != 0 || !S_ISREG(statbuf.st_mode)) { ShowMessage("Open File Error", "File does not exist", MainWindow); return; } } else { if (stat(name, &statbuf) == 0) { ShowMessage("New File Error", "File exists", MainWindow); return; } } MyConfig->SetDebug(true); MyConfig->SetToDefaults(); MyConfig->ReadFile(name); MyConfig->Update(); StartFlowLoadWindow(); } gtk_widget_destroy(GTK_WIDGET(sel));}static void start_config_file_selection (bool new_one){ GtkWidget *fs, *FileOkayButton, *cancel_button1; fs = gtk_file_selection_new(new_one ? "New global configuration file" : "Open global configuration file"); gtk_container_set_border_width(GTK_CONTAINER(fs), 10); gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(fs)); if (new_one == false) { gtk_file_selection_set_filename(GTK_FILE_SELECTION(fs), MyConfig->GetFileName()); } FileOkayButton = GTK_FILE_SELECTION(fs)->ok_button; gtk_widget_show(FileOkayButton); GTK_WIDGET_SET_FLAGS(FileOkayButton, GTK_CAN_DEFAULT); cancel_button1 = GTK_FILE_SELECTION(fs)->cancel_button; gtk_widget_show(cancel_button1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -