【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了transmit_dialog.cpp相关资料,希望对各位网友有所帮助!
/*
* 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. 2001. All Rights Reserved.
*
* Contributor(s):
* Dave Mackie dmackie@cisco.com
* Bill May wmay@cisco.com
*/
#define __STDC_LIMIT_MACROS
#include "mp4live.h"
#include "mp4live_gui.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "rtp_transmitter.h"
static GtkWidget *dialog;
static GtkWidget *unicast_button;
static GtkWidget *mcast_button;
static GtkWidget *address_entry;
static bool address_modified;
static GtkWidget *video_port_entry;
static bool video_port_modified;
static GtkWidget *audio_port_entry;
static bool audio_port_modified;
static GtkWidget *mcast_ttl_menu;
static GtkWidget *sdp_file_entry;
static GtkWidget *address_generate_button;
static GtkWidget *sdp_generate_button;
static u_int8_t ttlValues[] = {
1, 15, 63, 127
};
static char* ttlNames[] = {
"LAN - 1", "Organization - 15", "Regional - 63", "Worldwide - 127"
};
static u_int8_t ttlIndex;
static void on_destroy_dialog (GtkWidget *widget, gpointer *data)
{
gtk_grab_remove(dialog);
gtk_widget_destroy(dialog);
dialog = NULL;
}
static void on_unicast (GtkWidget *widget, gpointer *data)
{
bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
gtk_widget_set_sensitive(GTK_WIDGET(address_generate_button), !enabled);
gtk_widget_set_sensitive(GTK_WIDGET(mcast_ttl_menu), !enabled);
}
static void on_changed (GtkWidget *widget, gpointer *data)
{
if (widget == address_entry) {
address_modified = true;
} else if (widget == video_port_entry) {
video_port_modified = true;
} else if (widget == audio_port_entry) {
audio_port_modified = true;
}
}
bool ValidateAddress(GtkWidget* widget)
{
const char* address = gtk_entry_get_text(GTK_ENTRY(widget));
struct in_addr in;
if (inet_pton(AF_INET, address, &in) > 0) {
return true;
}
struct in6_addr in6;
if (inet_pton(AF_I
NET6, address, &in6) > 0) {
return true;
}
// Might have a DNS address...
if (gethostbyname(address) != NULL) {
return true;
}
ShowMessage("Transmission Address", "Invalid address entered");
return false;
}
static void on_address_leave(GtkWidget *widget, gpointer *data)
{
if (!address_modified) {
return;
}
ValidateAddress(widget);
}
bool ValidatePort(GtkWidget* entry, u_int16_t* port)
{
int value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(entry));
if (value < 1024 || value > 65534 || (value & 1)) {
ShowMessage("Transmission Port Number",
"Please enter an even number between 1024 and 65534");
// TBD gtk_widget_grab_focus(widget);
return false;
}
if (port) {
*port = value;
}
return true;
}
static void on_port_leave(GtkWidget *widget, gpointer *data)
{
if (widget == video_port_entry) {
if (!video_port_modified) {
return;
}
} else { // widget == audio_port_entry
if (!audio_port_modified) {
return;
}
}
ValidatePort(widget, NULL);
}
static void on_ttl_menu_activate (GtkWidget *widget, gpointer data)
{
ttlIndex = (unsigned int)data & 0xFF;
}
static void on_address_generate (GtkWidget *widget, gpointer *data)
{
struct in_addr in;
in.s_addr = CRtpTransmitter::GetRandomMcastAddress();
gtk_entry_set_text(GTK_ENTRY(address_entry), inet_ntoa(in));
u_int16_t portBlock = CRtpTransmitter::GetRandomPortBlock();
gtk_spin_button_set_value(GTK_SPIN_BUTTON(video_port_entry), portBlock);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(audio_port_entry), portBlock + 2);
}
static bool ValidateAndSave(void)
{
if (!ValidateAddress(address_entry)) {
return false;
}
u_int16_t videoPort;
if (!ValidatePort(video_port_entry, &videoPort)) {
return false;
}
u_int16_t audioPort;
if (!ValidatePort(audio_port_entry, &audioPort