48 #ifndef CCXX_RTP_RTP_H_ 49 #define CCXX_RTP_RTP_H_ 98 tpport_t controlPort, uint32 membersSize,
100 ServiceQueue(membersSize,app)
101 { build(ia,dataPort,controlPort); }
115 const InetHostAddress& ia,
116 tpport_t dataPort, tpport_t controlPort,
118 ServiceQueue(ssrc,membersSize,app)
119 { build(ia,dataPort,controlPort); }
134 tpport_t controlPort, uint32 membersSize,
136 ServiceQueue(membersSize,app)
137 { build(ia,dataPort,controlPort,iface); }
154 const InetMcastAddress& ia, tpport_t dataPort,
155 tpport_t controlPort, uint32 membersSize,
157 ServiceQueue(ssrc,membersSize,app)
158 { build(ia,dataPort,controlPort,iface); }
174 Socket::Error error = dso->setMulticast(
true);
175 if ( error )
return error;
176 error = dso->setTimeToLive(ttl);
177 if ( error )
return error;
178 error = cso->setMulticast(
true);
179 if ( error )
return error;
180 return cso->setTimeToLive(ttl);
198 {
return dso->isPendingRecv(timeout); }
202 {
return dso->getSender(port); }
206 {
return dso->getNextPacketSize(); }
219 InetHostAddress& na, tpport_t& tp)
220 { na = dso->getSender(tp);
return dso->recv(buffer, len); }
224 { dso->setPeer(host,port); }
232 sendData(
const unsigned char*
const buffer,
size_t len)
233 {
return dso->send(buffer, len); }
236 {
return dso->getRecvSocket(); }
244 {
return cso->isPendingRecv(timeout); }
248 {
return cso->getSender(port); }
261 InetHostAddress& na, tpport_t& tp)
262 { na = cso->getSender(tp);
return cso->recv(buffer,len); }
266 { cso->setPeer(host,port); }
275 {
return cso->send(buffer,len); }
278 {
return cso->getRecvSocket(); }
289 Socket::Error error = dso->setMulticast(
true);
290 if ( error )
return error;
291 error = dso->join(ia,iface);
292 if ( error )
return error;
293 error = cso->setMulticast(
true);
298 error = cso->join(ia,iface);
303 return Socket::errSuccess;
315 Socket::Error error = dso->setMulticast(
false);
316 if ( error )
return error;
317 error = dso->leaveGroup(ia);
318 if ( error )
return error;
319 error = cso->setMulticast(
false);
320 if ( error )
return error;
321 return cso->leaveGroup(ia);
341 build(
const InetHostAddress& ia, tpport_t dataPort,
342 tpport_t controlPort)
344 if ( 0 == controlPort ) {
345 dataBasePort = even_port(dataPort);
346 controlBasePort = dataBasePort + 1;
348 dataBasePort = dataPort;
349 controlBasePort = controlPort;
351 dso =
new RTPDataChannel(ia,dataBasePort);
352 cso =
new RTCPChannel(ia,controlBasePort);
356 build(
const InetMcastAddress& ia, tpport_t dataPort,
357 tpport_t controlPort, uint32 iface)
359 if ( 0 == controlPort ) {
360 dataBasePort = even_port(dataPort);
361 controlBasePort = dataBasePort + 1;
363 dataBasePort = dataPort;
364 controlBasePort = controlPort;
366 dso =
new RTPDataChannel(InetHostAddress(
"0.0.0.0"),dataBasePort);
367 cso =
new RTCPChannel(InetHostAddress(
"0.0.0.0"),controlBasePort);
379 odd_port(tpport_t port)
380 {
return (port & 0x01)? (port) : (port - 1); }
390 even_port(tpport_t port)
391 {
return (port & 0x01)? (port - 1) : (port); }
393 tpport_t dataBasePort;
394 tpport_t controlBasePort;
423 tpport_t controlPort = 0,
428 #
if defined(_MSC_VER) && _MSC_VER >= 1300
434 (ia,dataPort,controlPort,memberssize,app)
440 tpport_t controlPort = 0,
445 #
if defined(_MSC_VER) && _MSC_VER >= 1300
451 (ssrc, ia,dataPort,controlPort,memberssize,app)
457 tpport_t controlPort = 0,
463 #
if defined(_MSC_VER) && _MSC_VER >= 1300
469 (ia,dataPort,controlPort,memberssize,app,iface)
475 tpport_t controlPort = 0,
481 #
if defined(_MSC_VER) && _MSC_VER >= 1300
487 (ssrc,ia,dataPort,controlPort,memberssize,app,iface)
495 disableStack(); Thread::join();
499 #if defined(_MSC_VER) && _MSC_VER >= 1300 500 virtual void startRunning();
507 { enableStack(); Thread::start(); }
533 #if defined(_MSC_VER) && _MSC_VER >= 1300 534 virtual void run(
void);
536 virtual void timerTick(
void);
554 while ( ServiceQueue::isActive() ) {
555 if ( timeout < 1000 ){
556 timeout = getSchedulingTimeout();
558 controlReceptionService();
559 controlTransmissionService();
565 timeout = (timeout > maxWait)? maxWait : timeout;
566 if ( timeout < 1000 ) {
567 dispatchDataPacket();
571 if (ServiceQueue::isActive()) {
642 template <
class RTPDataChannel = DualRTPUDPIPv6Channel,
643 class RTCPChannel = DualRTPUDPIPv6Channel,
645 class __EXPORT TRTPSessionBaseIPV6 :
public ServiceQueue
657 TRTPSessionBaseIPV6(
const IPV6Host& ia, tpport_t dataPort,
658 tpport_t controlPort, uint32 membersSize,
660 ServiceQueue(membersSize,app)
661 { build(ia,dataPort,controlPort); }
674 TRTPSessionBaseIPV6(uint32 ssrc,
676 tpport_t dataPort, tpport_t controlPort,
678 ServiceQueue(ssrc,membersSize,app)
679 { build(ia,dataPort,controlPort); }
693 TRTPSessionBaseIPV6(
const IPV6Multicast& ia, tpport_t dataPort,
694 tpport_t controlPort, uint32 membersSize,
696 ServiceQueue(membersSize,app)
697 { build(ia,dataPort,controlPort,iface); }
713 TRTPSessionBaseIPV6(uint32 ssrc,
714 const IPV6Multicast& ia, tpport_t dataPort,
715 tpport_t controlPort, uint32 membersSize,
717 ServiceQueue(ssrc,membersSize,app)
718 { build(ia,dataPort,controlPort,iface); }
720 virtual size_t dispatchBYE(
const std::string &str)
726 ~TRTPSessionBaseIPV6()
731 inline RTPDataChannel *getDSO(
void)
740 {
return dso->isPendingRecv(timeout); }
743 getDataSender(tpport_t *port = NULL)
const 744 {
return dso->getSender(port); }
747 getNextDataPacketSize()
const 748 {
return dso->getNextPacketSize(); }
760 recvData(
unsigned char* buffer,
size_t len,
761 IPV6Host& na, tpport_t& tp)
762 { na = dso->getSender(tp);
return dso->recv(buffer, len); }
765 setDataPeerIPV6(
const IPV6Host &host, tpport_t port)
766 { dso->setPeer(host,port); }
773 sendDataIPV6(
const unsigned char*
const buffer,
size_t len)
774 {
return dso->send(buffer, len); }
776 inline SOCKET getDataRecvSocket()
const 777 {
return dso->getRecvSocket(); }
785 {
return cso->isPendingRecv(timeout); }
788 getControlSender(tpport_t *port = NULL)
const 789 {
return cso->getSender(port); }
801 recvControl(
unsigned char *buffer,
size_t len,
802 IPV6Host& na, tpport_t& tp)
803 { na = cso->getSender(tp);
return cso->recv(buffer,len); }
806 setControlPeerIPV6(
const IPV6Host &host, tpport_t port)
807 { cso->setPeer(host,port); }
815 sendControl(
const unsigned char*
const buffer,
size_t len)
816 {
return cso->send(buffer,len); }
818 inline SOCKET getControlRecvSocket()
const 819 {
return cso->getRecvSocket(); }
834 build(
const IPV6Host& ia, tpport_t dataPort,
835 tpport_t controlPort)
837 if ( 0 == controlPort ) {
838 dataBasePort = even_port(dataPort);
839 controlBasePort = dataBasePort + 1;
841 dataBasePort = dataPort;
842 controlBasePort = controlPort;
844 dso =
new RTPDataChannel(ia,dataBasePort);
845 cso =
new RTCPChannel(ia,controlBasePort);
849 build(
const IPV6Multicast& ia, tpport_t dataPort,
850 tpport_t controlPort, uint32 iface)
852 if ( 0 == controlPort ) {
853 dataBasePort = even_port(dataPort);
854 controlBasePort = dataBasePort + 1;
856 dataBasePort = dataPort;
857 controlBasePort = controlPort;
859 dso =
new RTPDataChannel(IPV6Host(
"0.0.0.0"),dataBasePort);
860 cso =
new RTCPChannel(IPV6Host(
"0.0.0.0"),controlBasePort);
871 joinGroup(
const IPV6Multicast& ia, uint32 iface)
873 Socket::Error error = dso->setMulticast(
true);
874 if ( error )
return error;
875 error = dso->join(ia,iface);
876 if ( error )
return error;
877 error = cso->setMulticast(
true);
882 error = cso->join(ia,iface);
887 return Socket::errSuccess;
897 leaveGroup(
const IPV6Multicast& ia)
899 Socket::Error error = dso->setMulticast(
false);
900 if ( error )
return error;
901 error = dso->leaveGroup(ia);
902 if ( error )
return error;
903 error = cso->setMulticast(
false);
904 if ( error )
return error;
905 return cso->leaveGroup(ia);
915 setMcastTTL(uint8 ttl)
917 Socket::Error error = dso->setMulticast(
true);
918 if ( error )
return error;
919 error = dso->setTimeToLive(ttl);
920 if ( error )
return error;
921 error = cso->setMulticast(
true);
922 if ( error )
return error;
923 return cso->setTimeToLive(ttl);
934 odd_port(tpport_t port)
935 {
return (port & 0x01)? (port) : (port - 1); }
945 even_port(tpport_t port)
946 {
return (port & 0x01)? (port - 1) : (port); }
948 tpport_t dataBasePort;
949 tpport_t controlBasePort;
968 <
class RTPDataChannel = DualRTPUDPIPv6Channel,
969 class RTCPChannel = DualRTPUDPIPv6Channel,
971 class __EXPORT SingleThreadRTPSessionIPV6 :
973 public TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
976 SingleThreadRTPSessionIPV6(
const IPV6Host& ia,
978 tpport_t controlPort = 0,
983 #
if defined(_MSC_VER) && _MSC_VER >= 1300
988 TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
989 (ia,dataPort,controlPort,memberssize,app)
993 SingleThreadRTPSessionIPV6(
const IPV6Multicast& ia,
995 tpport_t controlPort = 0,
1001 #
if defined(_MSC_VER) && _MSC_VER >= 1300
1006 TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
1007 (ia,dataPort,controlPort,memberssize,app,iface)
1011 ~SingleThreadRTPSessionIPV6()
1014 disableStack(); Thread::join();
1018 #if defined(_MSC_VER) && _MSC_VER >= 1300 1019 virtual void startRunning();
1026 { enableStack(); Thread::start(); }
1031 inline void enableStack(
void)
1032 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::enableStack();}
1034 inline void disableStack(
void)
1035 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::disableStack();}
1038 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::getSchedulingTimeout();}
1040 inline void controlReceptionService(
void)
1041 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::controlReceptionService();}
1043 inline void controlTransmissionService(
void)
1044 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::controlTransmissionService();}
1046 inline timeval getRTCPCheckInterval(
void)
1047 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::getRTCPCheckInterval();}
1049 inline size_t dispatchDataPacket(
void)
1050 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchDataPacket();}
1052 #if defined(_MSC_VER) && _MSC_VER >= 1300 1053 virtual void run(
void);
1055 virtual void timerTick(
void);
1060 virtual void timerTick(
void)
1064 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::isPendingData(timeout);}
1070 virtual void run(
void)
1073 while ( ServiceQueue::isActive() ) {
1074 if ( timeout < 1000 ){
1075 timeout = getSchedulingTimeout();
1077 controlReceptionService();
1078 controlTransmissionService();
1084 timeout = (timeout > maxWait)? maxWait : timeout;
1085 if ( timeout < 1000 ) {
1086 dispatchDataPacket();
1089 if ( isPendingData(timeout/1000) ) {
1095 dispatchBYE(
"GNU ccRTP stack finishing.");
1101 inline size_t takeInDataPacket(
void)
1102 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::takeInDataPacket();}
1104 inline size_t dispatchBYE(
const std::string &str)
1105 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchBYE(str);}
1116 typedef SingleThreadRTPSessionIPV6<> RTPSessionIPV6;
1123 typedef RTPSessionIPV6 RTPSocketIPV6;
1133 typedef SingleThreadRTPSessionIPV6<SymmetricRTPChannelIPV6,
1134 SymmetricRTPChannelIPV6> SymmetricRTPSessionIPV6;
1143 #endif //CCXX_RTP_RTP_H_ virtual bool isPendingData(microtimeout_t timeout)
Definition: rtp.h:544
SOCKET getControlRecvSocket() const
Definition: rtp.h:277
bool isPendingData(microtimeout_t timeout)
Definition: rtp.h:197
SingleThreadRTPSession(const InetMcastAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0, int pri=0, uint32 memberssize=MembershipBookkeeping::defaultMembersHashSize, RTPApplication &app=defaultApplication(), uint32 iface=0)
Definition: rtp.h:455
virtual size_t dispatchBYE(const std::string &str)
Definition: rtp.h:160
RTPSession RTPSocket
Alias for RTPSession.
Definition: rtp.h:606
Socket::Error setMcastTTL(uint8 ttl)
Set the value of the TTL field in the sent packets.
Definition: rtp.h:172
DualRTPChannel< RTPBaseUDPIPv4Socket > DualRTPUDPIPv4Channel
Definition: channel.h:444
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:67
size_t dispatchDataPacket(void)
Definition: rtp.h:530
virtual void run(void)
Single runnable method for this RTP stacks, schedules outgoing and incoming RTP data and RTCP packets...
Definition: rtp.h:551
TRTPSessionBase(const InetMcastAddress &ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication &app, uint32 iface)
Builds a session waiting for packets in a multicast address.
Definition: rtp.h:133
microtimeout_t timeval2microtimeout(const timeval &t)
Convert a time interval, expressed as a timeval value into a microseconds counter.
Definition: base.h:90
RTCPChannel * cso
Definition: rtp.h:398
void controlReceptionService(void)
Definition: rtp.h:521
size_t takeInDataPacket(void)
Definition: rtp.h:584
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
Definition: rtp.h:416
SOCKET getDataRecvSocket() const
Definition: rtp.h:235
SingleRTPChannel SymmetricRTPChannel
Actually, RTP with a single channel can be called 'Symmetric RTP'.
Definition: channel.h:455
virtual void timerTick(void)
Definition: rtp.h:541
void enableStack(void)
Definition: rtp.h:515
TRTPSessionBase(const InetHostAddress &ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication &app)
Builds a session waiting for packets in a host address.
Definition: rtp.h:97
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...
Definition: cqueue.h:708
void controlTransmissionService(void)
Definition: rtp.h:524
Definition of socket classes for different underlying transport and/or network protocols that can be ...
RTPDataChannel * dso
Definition: rtp.h:397
void setControlPeer(const InetAddress &host, tpport_t port)
Definition: rtp.h:265
timeval getRTCPCheckInterval(void)
Definition: rtp.h:527
SingleThreadRTPSession RTPSession
Uses two pairs of sockets for RTP data and RTCP transmission/reception.
Definition: rtp.h:599
InetHostAddress getControlSender(tpport_t *port=NULL) const
Definition: rtp.h:247
size_t dispatchBYE(const std::string &reason)
This method is used to send an RTCP BYE packet.
void disableStack(void)
Definition: rtp.h:512
size_t sendControl(const unsigned char *const buffer, size_t len)
Definition: rtp.h:274
Generic RTCP control queues.
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:364
InetHostAddress getDataSender(tpport_t *port=NULL) const
Definition: rtp.h:201
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
Definition: base.h:109
size_t getNextDataPacketSize() const
Definition: rtp.h:205
static const size_t defaultMembersHashSize
Definition: iqueue.h:854
Socket::Error joinGroup(const InetMcastAddress &ia, uint32 iface)
Join a multicast group.
Definition: rtp.h:287
size_t sendData(const unsigned char *const buffer, size_t len)
Definition: rtp.h:232
TRTPSessionBase(uint32 ssrc, const InetHostAddress &ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication &app)
Builds a session with the specified ssrc identifier for the local source.
Definition: rtp.h:114
RTPDataChannel * getDSO(void)
Definition: rtp.h:189
Socket::Error leaveGroup(const InetMcastAddress &ia)
Leave a multicast group.
Definition: rtp.h:313
size_t recvData(unsigned char *buffer, size_t len, InetHostAddress &na, tpport_t &tp)
Receive data from the data channel/socket.
Definition: rtp.h:218
size_t dispatchBYE(const std::string &str)
Definition: rtp.h:587
size_t recvControl(unsigned char *buffer, size_t len, InetHostAddress &na, tpport_t &tp)
Receive data from the control channel/socket.
Definition: rtp.h:260
SingleThreadRTPSession(uint32 ssrc, const InetMcastAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0, int pri=0, uint32 memberssize=MembershipBookkeeping::defaultMembersHashSize, RTPApplication &app=defaultApplication(), uint32 iface=0)
Definition: rtp.h:473
SingleThreadRTPSession< SymmetricRTPChannel, SymmetricRTPChannel > SymmetricRTPSession
Uses one pair of sockets, (1) for RTP data and (2) for RTCP transmission/reception.
Definition: rtp.h:617
SingleThreadRTPSession(uint32 ssrc, const InetHostAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0, int pri=0, uint32 memberssize=MembershipBookkeeping::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Definition: rtp.h:438
microtimeout_t getSchedulingTimeout(void)
Definition: rtp.h:518
void endSocket()
Definition: rtp.h:325
TRTPSessionBase(uint32 ssrc, const InetMcastAddress &ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication &app, uint32 iface)
Builds a session waiting for packets in a multicast address, with the specified ssrc identifier for t...
Definition: rtp.h:153
void startRunning()
Activate stack and start service thread.
Definition: rtp.h:506
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
virtual ~TRTPSessionBase()
Definition: rtp.h:184
void setDataPeer(const InetAddress &host, tpport_t port)
Definition: rtp.h:223
~SingleThreadRTPSession()
Definition: rtp.h:492
bool isPendingControl(microtimeout_t timeout)
Definition: rtp.h:243
SingleThreadRTPSession(const InetHostAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0, int pri=0, uint32 memberssize=MembershipBookkeeping::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Definition: rtp.h:421