📄 udp.cpp
字号:
this->flow_protocol_factory_ = factory;
ACE_INET_Addr *inet_addr;
if (flow_comp == TAO_AV_Core::TAO_AV_CONTROL)
{
this->flowname_ = TAO_AV_Core::get_control_flowname (entry->flowname ());
inet_addr = (ACE_INET_Addr *) entry->control_address ();
}
else
{
this->flowname_ = entry->flowname ();
inet_addr = (ACE_INET_Addr *) entry->address ();
}
if (inet_addr != 0)
{
char buf[BUFSIZ];
inet_addr->addr_to_string (buf,
BUFSIZ);
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG,
"TAO_AV_UDP_Acceptor::open: %s\n",
buf));
}
int result = this->open_i (inet_addr, 0);
if (result < 0)
return result;
return 0;
}
int
TAO_AV_UDP_Acceptor::open_default (TAO_Base_StreamEndPoint *endpoint,
TAO_AV_Core *av_core,
TAO_FlowSpec_Entry *entry,
TAO_AV_Flow_Protocol_Factory *factory,
TAO_AV_Core::Flow_Component flow_comp)
{
this->av_core_ = av_core;
this->endpoint_ = endpoint;
this->entry_ = entry;
this->flow_component_ = flow_comp;
this->flow_protocol_factory_ = factory;
if (flow_comp == TAO_AV_Core::TAO_AV_CONTROL)
{
this->flowname_ = TAO_AV_Core::get_control_flowname (entry->flowname ());
}
else
{
this->flowname_ = entry->flowname ();
ACE_NEW_RETURN (this->address_,
ACE_INET_Addr ("0"),
-1);
}
int result = this->open_i (this->address_, 1);
if (result < 0)
return result;
return 0;
}
int
TAO_AV_UDP_Acceptor::open_i (ACE_INET_Addr *inet_addr,
int is_default_addr)
{
int result = -1;
ACE_INET_Addr *local_addr = 0;
TAO_AV_Flow_Handler *flow_handler = 0;
// if using a default address and this is the control flow component, the
// handler and local address are already set in the flow spec entry
if (is_default_addr &&
(this->flow_component_ == TAO_AV_Core::TAO_AV_CONTROL) &&
(ACE_OS::strcasecmp(this->entry_->flow_protocol_str (), "RTP") == 0))
{
flow_handler = this->entry_->control_handler ();
local_addr = ACE_dynamic_cast (ACE_INET_Addr*,
this->entry_->get_local_control_addr ());
}
else
{
// this variable is only used for RTP/UDP; RFC 1889 requires an even/odd
// consecutive port pair
int get_new_port = 1;
while (get_new_port)
{
// assume the ports will be OK
get_new_port = 0;
result = TAO_AV_UDP_Connection_Setup::setup (flow_handler,
inet_addr,
local_addr,
this->entry_->is_multicast (),
TAO_AV_UDP_Connection_Setup::ACCEPTOR);
if (result < 0)
{
ACE_DEBUG((LM_DEBUG,"(%N,%l) Error during connection setup: %d\n", result));
}
local_addr->set (local_addr->get_port_number (),
local_addr->get_host_name ());
if (is_default_addr)
{
if ((ACE_OS::strcasecmp(this->entry_->flow_protocol_str (), "RTP") == 0) &&
(this->flow_component_ == TAO_AV_Core::TAO_AV_DATA))
{
if (is_default_addr && local_addr->get_port_number ()%2 != 0)
{
// RTP port should be even
delete local_addr;
delete flow_handler;
get_new_port = 1;
}
else
{
ACE_INET_Addr *local_control_addr;
TAO_AV_Flow_Handler *control_flow_handler = 0;
ACE_NEW_RETURN (this->control_inet_address_,
ACE_INET_Addr ("0"),
-1);
TAO_AV_UDP_Connection_Setup::setup(control_flow_handler,
this->control_inet_address_,
local_control_addr,
this->entry_->is_multicast (),
TAO_AV_UDP_Connection_Setup::ACCEPTOR);
if (local_control_addr->get_port_number () !=
local_addr->get_port_number () +1)
{
delete this->control_inet_address_;
delete local_addr;
delete flow_handler;
delete local_control_addr;
delete control_flow_handler;
get_new_port = 1;
}
else
{
this->entry_->control_address (this->control_inet_address_);
this->entry_->set_local_control_addr (local_control_addr);
this->entry_->control_handler (control_flow_handler);
}
}
}
}
}
}
TAO_AV_Protocol_Object *object =
this->flow_protocol_factory_->make_protocol_object (this->entry_,
this->endpoint_,
flow_handler,
flow_handler->transport ());
flow_handler->protocol_object (object);
if (this->flow_component_ == TAO_AV_Core::TAO_AV_DATA)
{
this->endpoint_->set_flow_handler (this->flowname_.c_str (),flow_handler);
this->entry_->protocol_object (object);
this->entry_->set_local_addr (local_addr);
this->entry_->handler (flow_handler);
//this->entry_->address (inet_addr);
this->entry_->address (local_addr);
}
else
{
this->endpoint_->set_control_flow_handler (this->flowname_.c_str (),flow_handler);
this->entry_->control_protocol_object (object);
this->entry_->set_local_control_addr (local_addr);
this->entry_->control_handler (flow_handler);
}
char buf[BUFSIZ];
local_addr->addr_to_string (buf,BUFSIZ);
if (TAO_debug_level > 0)
ACE_DEBUG ((LM_DEBUG,
"TAO_AV_UDP_ACCEPTOR::open:%s \n",
buf));
// call activate svc handler.
return this->activate_svc_handler (flow_handler);
}
int
TAO_AV_UDP_Acceptor::close (void)
{
return 0;
}
//------------------------------------------------------------
// TAO_AV_UDP_Connector
//------------------------------------------------------------
TAO_AV_UDP_Connector::TAO_AV_UDP_Connector (void)
: control_inet_address_ (0)
{
}
TAO_AV_UDP_Connector::~TAO_AV_UDP_Connector (void)
{
if (this->flow_component_ == TAO_AV_Core::TAO_AV_CONTROL)
{
delete this->entry_->control_handler ();
}
delete this->control_inet_address_;
}
int
TAO_AV_UDP_Connector::open (TAO_Base_StreamEndPoint *endpoint,
TAO_AV_Core *av_core,
TAO_AV_Flow_Protocol_Factory *factory)
{
if (TAO_debug_level > 0) ACE_DEBUG ((LM_DEBUG,"TAO_AV_UDP_Connector::open "));
this->endpoint_ = endpoint;
this->av_core_ = av_core;
this->flow_protocol_factory_ = factory;
return 0;
}
int
TAO_AV_UDP_Connector::connect (TAO_FlowSpec_Entry *entry,
TAO_AV_Transport *&transport,
TAO_AV_Core::Flow_Component flow_component)
{
ACE_INET_Addr *local_addr = 0;
ACE_INET_Addr *control_inet_addr = 0;
this->entry_ = entry;
this->flow_component_ = flow_component;
ACE_INET_Addr *inet_addr;
if (flow_component == TAO_AV_Core::TAO_AV_CONTROL)
{
this->flowname_ = TAO_AV_Core::get_control_flowname (entry->flowname());
inet_addr = ACE_dynamic_cast (ACE_INET_Addr*, entry->control_address ());
}
else
{
this->flowname_ = entry->flowname ();
inet_addr = ACE_dynamic_cast (ACE_INET_Addr*, entry->address ());
control_inet_addr = ACE_dynamic_cast (ACE_INET_Addr*, entry->control_address ());
}
TAO_AV_Flow_Handler *flow_handler = 0;
// if this is the control flow component, the
// handler and local address are already set in the flow spec entry
if ((flow_component == TAO_AV_Core::TAO_AV_CONTROL) &&
(ACE_OS::strcasecmp(this->entry_->flow_protocol_str (), "RTP") == 0) &&
!entry->is_multicast ())
{
flow_handler = this->entry_->control_handler ();
flow_handler->set_remote_address (inet_addr);
local_addr = ACE_dynamic_cast (ACE_INET_Addr*,
this->entry_->get_local_control_addr ());
}
else
{
// this variable is only used for RTP/UDP; RFC 1889 requires an even/odd
// consecutive port pair
int get_new_port = 1;
while (get_new_port)
{
// assume the ports will be OK
get_new_port = 0;
ACE_Addr *addr;
if ((addr = entry->get_peer_addr ()) != 0)
{
local_addr = ACE_dynamic_cast (ACE_INET_Addr*,addr);
char buf [BUFSIZ];
local_addr->addr_to_string (buf, BUFSIZ);
}
TAO_AV_UDP_Connection_Setup::setup (flow_handler,
inet_addr,
local_addr,
entry->is_multicast (),
TAO_AV_UDP_Connection_Setup::CONNECTOR);
if ((ACE_OS::strcasecmp(this->entry_->flow_protocol_str (), "RTP") == 0) &&
(flow_component == TAO_AV_Core::TAO_AV_DATA) &&
!entry->is_multicast ())
{
if (local_addr->get_port_number ()%2 != 0)
{
// RTP port should be even
delete local_addr;
delete flow_handler;
get_new_port = 1;
}
else
{
ACE_INET_Addr *local_control_addr;
TAO_AV_Flow_Handler *control_flow_handler = 0;
if (entry->is_multicast ())
control_inet_addr = ACE_dynamic_cast (ACE_INET_Addr*,
entry->control_address ()) ;
else
{
if (local_addr != 0)
{
char buf [BUFSIZ];
ACE_CString addr_str (local_addr->get_host_name ());
addr_str += ":";
addr_str += ACE_OS::itoa (local_addr->get_port_number () + 1, buf, 10);
ACE_NEW_RETURN (local_control_addr,
ACE_INET_Addr (addr_str.c_str ()),
-1);
local_control_addr->addr_to_string (buf, BUFSIZ);
}
if (entry->control_address () == 0)
ACE_NEW_RETURN (this->control_inet_address_,
ACE_INET_Addr ("0"),
-1);
else
control_inet_address_ = ACE_dynamic_cast (ACE_INET_Addr*,entry->control_address ());
}
TAO_AV_UDP_Connection_Setup::setup (control_flow_handler,
control_inet_addr,
local_control_addr,
entry->is_multicast (),
TAO_AV_UDP_Connection_Setup::CONNECTOR);
if (local_control_addr->get_port_number () !=
local_addr->get_port_number () +1)
{
delete local_addr;
delete flow_handler;
delete local_control_addr;
delete control_flow_handler;
get_new_port = 1;
}
else
{
this->entry_->set_local_control_addr (local_control_addr);
this->entry_->control_handler (control_flow_handler);
}
}
}
}
}
TAO_AV_Protocol_Object *object =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -