49 #ifndef CCXX_RTP_RTP_H_ 50 #define CCXX_RTP_RTP_H_ 99 tpport_t controlPort, uint32 membersSize,
101 ServiceQueue(membersSize,app)
102 { build(ia,dataPort,controlPort); }
116 const InetHostAddress& ia,
117 tpport_t dataPort, tpport_t controlPort,
119 ServiceQueue(ssrc,membersSize,app)
120 { build(ia,dataPort,controlPort); }
135 tpport_t controlPort, uint32 membersSize,
137 ServiceQueue(membersSize,app)
138 { build(ia,dataPort,controlPort,iface); }
155 const InetMcastAddress& ia, tpport_t dataPort,
156 tpport_t controlPort, uint32 membersSize,
158 ServiceQueue(ssrc,membersSize,app)
159 { build(ia,dataPort,controlPort,iface); }
175 Socket::Error error = dso->setMulticast(
true);
176 if ( error )
return error;
177 error = dso->setTimeToLive(ttl);
178 if ( error )
return error;
179 error = cso->setMulticast(
true);
180 if ( error )
return error;
181 return cso->setTimeToLive(ttl);
199 {
return dso->isPendingRecv(timeout); }
203 {
return dso->getSender(port); }
207 {
return dso->getNextPacketSize(); }
220 InetHostAddress& na, tpport_t& tp)
221 { na = dso->getSender(tp);
return dso->recv(buffer, len); }
225 { dso->setPeer(host,port); }
233 sendData(
const unsigned char*
const buffer,
size_t len)
234 {
return dso->send(buffer, len); }
237 {
return dso->getRecvSocket(); }
245 {
return cso->isPendingRecv(timeout); }
249 {
return cso->getSender(port); }
262 InetHostAddress& na, tpport_t& tp)
263 { na = cso->getSender(tp);
return cso->recv(buffer,len); }
267 { cso->setPeer(host,port); }
276 {
return cso->send(buffer,len); }
279 {
return cso->getRecvSocket(); }
290 Socket::Error error = dso->setMulticast(
true);
291 if ( error )
return error;
292 error = dso->join(ia,iface);
293 if ( error )
return error;
294 error = cso->setMulticast(
true);
299 error = cso->join(ia,iface);
304 return Socket::errSuccess;
316 Socket::Error error = dso->setMulticast(
false);
317 if ( error )
return error;
318 error = dso->leaveGroup(ia);
319 if ( error )
return error;
320 error = cso->setMulticast(
false);
321 if ( error )
return error;
322 return cso->leaveGroup(ia);
342 build(
const InetHostAddress& ia, tpport_t dataPort,
343 tpport_t controlPort)
345 if ( 0 == controlPort ) {
346 dataBasePort = even_port(dataPort);
347 controlBasePort = dataBasePort + 1;
349 dataBasePort = dataPort;
350 controlBasePort = controlPort;
352 dso =
new RTPDataChannel(ia,dataBasePort);
353 cso =
new RTCPChannel(ia,controlBasePort);
357 build(
const InetMcastAddress& ia, tpport_t dataPort,
358 tpport_t controlPort, uint32 iface)
360 if ( 0 == controlPort ) {
361 dataBasePort = even_port(dataPort);
362 controlBasePort = dataBasePort + 1;
364 dataBasePort = dataPort;
365 controlBasePort = controlPort;
367 dso =
new RTPDataChannel(InetHostAddress(
"0.0.0.0"),dataBasePort);
368 cso =
new RTCPChannel(InetHostAddress(
"0.0.0.0"),controlBasePort);
380 odd_port(tpport_t port)
381 {
return (port & 0x01)? (port) : (port - 1); }
391 even_port(tpport_t port)
392 {
return (port & 0x01)? (port - 1) : (port); }
394 tpport_t dataBasePort;
395 tpport_t controlBasePort;
424 tpport_t controlPort = 0,
429 #
if defined(_MSC_VER) && _MSC_VER >= 1300
435 (ia,dataPort,controlPort,memberssize,app)
441 tpport_t controlPort = 0,
446 #
if defined(_MSC_VER) && _MSC_VER >= 1300
452 (ssrc, ia,dataPort,controlPort,memberssize,app)
458 tpport_t controlPort = 0,
464 #
if defined(_MSC_VER) && _MSC_VER >= 1300
470 (ia,dataPort,controlPort,memberssize,app,iface)
476 tpport_t controlPort = 0,
482 #
if defined(_MSC_VER) && _MSC_VER >= 1300
488 (ssrc,ia,dataPort,controlPort,memberssize,app,iface)
496 disableStack(); Thread::join();
500 #if defined(_MSC_VER) && _MSC_VER >= 1300 501 virtual void startRunning();
508 { enableStack(); Thread::start(); }
534 #if defined(_MSC_VER) && _MSC_VER >= 1300 535 virtual void run(
void);
537 virtual void timerTick(
void);
555 while ( ServiceQueue::isActive() ) {
556 if ( timeout < 1000 ){
557 timeout = getSchedulingTimeout();
559 controlReceptionService();
560 controlTransmissionService();
566 timeout = (timeout > maxWait)? maxWait : timeout;
567 if ( timeout < 1000 ) {
568 dispatchDataPacket();
572 if (ServiceQueue::isActive()) {
643 template <
class RTPDataChannel = DualRTPUDPIPv6Channel,
644 class RTCPChannel = DualRTPUDPIPv6Channel,
646 class __EXPORT TRTPSessionBaseIPV6 :
public ServiceQueue
658 TRTPSessionBaseIPV6(
const IPV6Host& ia, tpport_t dataPort,
659 tpport_t controlPort, uint32 membersSize,
661 ServiceQueue(membersSize,app)
662 { build(ia,dataPort,controlPort); }
675 TRTPSessionBaseIPV6(uint32 ssrc,
677 tpport_t dataPort, tpport_t controlPort,
679 ServiceQueue(ssrc,membersSize,app)
680 { build(ia,dataPort,controlPort); }
694 TRTPSessionBaseIPV6(
const IPV6Multicast& ia, tpport_t dataPort,
695 tpport_t controlPort, uint32 membersSize,
697 ServiceQueue(membersSize,app)
698 { build(ia,dataPort,controlPort,iface); }
714 TRTPSessionBaseIPV6(uint32 ssrc,
715 const IPV6Multicast& ia, tpport_t dataPort,
716 tpport_t controlPort, uint32 membersSize,
718 ServiceQueue(ssrc,membersSize,app)
719 { build(ia,dataPort,controlPort,iface); }
721 virtual size_t dispatchBYE(
const std::string &str)
727 ~TRTPSessionBaseIPV6()
732 inline RTPDataChannel *getDSO(
void)
741 {
return dso->isPendingRecv(timeout); }
744 getDataSender(tpport_t *port = NULL)
const 745 {
return dso->getSender(port); }
748 getNextDataPacketSize()
const 749 {
return dso->getNextPacketSize(); }
761 recvData(
unsigned char* buffer,
size_t len,
762 IPV6Host& na, tpport_t& tp)
763 { na = dso->getSender(tp);
return dso->recv(buffer, len); }
766 setDataPeerIPV6(
const IPV6Host &host, tpport_t port)
767 { dso->setPeer(host,port); }
774 sendDataIPV6(
const unsigned char*
const buffer,
size_t len)
775 {
return dso->send(buffer, len); }
777 inline SOCKET getDataRecvSocket()
const 778 {
return dso->getRecvSocket(); }
786 {
return cso->isPendingRecv(timeout); }
789 getControlSender(tpport_t *port = NULL)
const 790 {
return cso->getSender(port); }
802 recvControl(
unsigned char *buffer,
size_t len,
803 IPV6Host& na, tpport_t& tp)
804 { na = cso->getSender(tp);
return cso->recv(buffer,len); }
807 setControlPeerIPV6(
const IPV6Host &host, tpport_t port)
808 { cso->setPeer(host,port); }
816 sendControl(
const unsigned char*
const buffer,
size_t len)
817 {
return cso->send(buffer,len); }
819 inline SOCKET getControlRecvSocket()
const 820 {
return cso->getRecvSocket(); }
835 build(
const IPV6Host& ia, tpport_t dataPort,
836 tpport_t controlPort)
838 if ( 0 == controlPort ) {
839 dataBasePort = even_port(dataPort);
840 controlBasePort = dataBasePort + 1;
842 dataBasePort = dataPort;
843 controlBasePort = controlPort;
845 dso =
new RTPDataChannel(ia,dataBasePort);
846 cso =
new RTCPChannel(ia,controlBasePort);
850 build(
const IPV6Multicast& ia, tpport_t dataPort,
851 tpport_t controlPort, uint32 iface)
853 if ( 0 == controlPort ) {
854 dataBasePort = even_port(dataPort);
855 controlBasePort = dataBasePort + 1;
857 dataBasePort = dataPort;
858 controlBasePort = controlPort;
860 dso =
new RTPDataChannel(IPV6Host(
"0.0.0.0"),dataBasePort);
861 cso =
new RTCPChannel(IPV6Host(
"0.0.0.0"),controlBasePort);
872 joinGroup(
const IPV6Multicast& ia, uint32 iface)
874 Socket::Error error = dso->setMulticast(
true);
875 if ( error )
return error;
876 error = dso->join(ia,iface);
877 if ( error )
return error;
878 error = cso->setMulticast(
true);
883 error = cso->join(ia,iface);
888 return Socket::errSuccess;
898 leaveGroup(
const IPV6Multicast& ia)
900 Socket::Error error = dso->setMulticast(
false);
901 if ( error )
return error;
902 error = dso->leaveGroup(ia);
903 if ( error )
return error;
904 error = cso->setMulticast(
false);
905 if ( error )
return error;
906 return cso->leaveGroup(ia);
916 setMcastTTL(uint8 ttl)
918 Socket::Error error = dso->setMulticast(
true);
919 if ( error )
return error;
920 error = dso->setTimeToLive(ttl);
921 if ( error )
return error;
922 error = cso->setMulticast(
true);
923 if ( error )
return error;
924 return cso->setTimeToLive(ttl);
935 odd_port(tpport_t port)
936 {
return (port & 0x01)? (port) : (port - 1); }
946 even_port(tpport_t port)
947 {
return (port & 0x01)? (port - 1) : (port); }
949 tpport_t dataBasePort;
950 tpport_t controlBasePort;
969 <
class RTPDataChannel = DualRTPUDPIPv6Channel,
970 class RTCPChannel = DualRTPUDPIPv6Channel,
972 class __EXPORT SingleThreadRTPSessionIPV6 :
974 public TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
977 SingleThreadRTPSessionIPV6(
const IPV6Host& ia,
979 tpport_t controlPort = 0,
984 #
if defined(_MSC_VER) && _MSC_VER >= 1300
989 TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
990 (ia,dataPort,controlPort,memberssize,app)
994 SingleThreadRTPSessionIPV6(
const IPV6Multicast& ia,
996 tpport_t controlPort = 0,
1002 #
if defined(_MSC_VER) && _MSC_VER >= 1300
1007 TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
1008 (ia,dataPort,controlPort,memberssize,app,iface)
1012 ~SingleThreadRTPSessionIPV6()
1015 disableStack(); Thread::join();
1019 #if defined(_MSC_VER) && _MSC_VER >= 1300 1020 virtual void startRunning();
1027 { enableStack(); Thread::start(); }
1032 inline void enableStack(
void)
1033 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::enableStack();}
1035 inline void disableStack(
void)
1036 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::disableStack();}
1039 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::getSchedulingTimeout();}
1041 inline void controlReceptionService(
void)
1042 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::controlReceptionService();}
1044 inline void controlTransmissionService(
void)
1045 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::controlTransmissionService();}
1047 inline timeval getRTCPCheckInterval(
void)
1048 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::getRTCPCheckInterval();}
1050 inline size_t dispatchDataPacket(
void)
1051 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchDataPacket();}
1053 #if defined(_MSC_VER) && _MSC_VER >= 1300 1054 virtual void run(
void);
1056 virtual void timerTick(
void);
1061 virtual void timerTick(
void)
1065 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::isPendingData(timeout);}
1071 virtual void run(
void)
1074 while ( ServiceQueue::isActive() ) {
1075 if ( timeout < 1000 ){
1076 timeout = getSchedulingTimeout();
1078 controlReceptionService();
1079 controlTransmissionService();
1085 timeout = (timeout > maxWait)? maxWait : timeout;
1086 if ( timeout < 1000 ) {
1087 dispatchDataPacket();
1090 if ( isPendingData(timeout/1000) ) {
1096 dispatchBYE(
"GNU ccRTP stack finishing.");
1102 inline size_t takeInDataPacket(
void)
1103 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::takeInDataPacket();}
1105 inline size_t dispatchBYE(
const std::string &str)
1106 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchBYE(str);}
1117 typedef SingleThreadRTPSessionIPV6<> RTPSessionIPV6;
1124 typedef RTPSessionIPV6 RTPSocketIPV6;
1134 typedef SingleThreadRTPSessionIPV6<SymmetricRTPChannelIPV6,
1135 SymmetricRTPChannelIPV6> SymmetricRTPSessionIPV6;
1144 #endif //CCXX_RTP_RTP_H_ virtual bool isPendingData(microtimeout_t timeout)
Definition: rtp.h:545
SOCKET getControlRecvSocket() const
Definition: rtp.h:278
bool isPendingData(microtimeout_t timeout)
Definition: rtp.h:198
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:456
virtual size_t dispatchBYE(const std::string &str)
Definition: rtp.h:161
RTPSession RTPSocket
Alias for RTPSession.
Definition: rtp.h:607
Socket::Error setMcastTTL(uint8 ttl)
Set the value of the TTL field in the sent packets.
Definition: rtp.h:173
DualRTPChannel< RTPBaseUDPIPv4Socket > DualRTPUDPIPv4Channel
Definition: channel.h:445
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition: base.h:68
size_t dispatchDataPacket(void)
Definition: rtp.h:531
virtual void run(void)
Single runnable method for this RTP stacks, schedules outgoing and incoming RTP data and RTCP packets...
Definition: rtp.h:552
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:134
microtimeout_t timeval2microtimeout(const timeval &t)
Convert a time interval, expressed as a timeval value into a microseconds counter.
Definition: base.h:91
RTCPChannel * cso
Definition: rtp.h:399
void controlReceptionService(void)
Definition: rtp.h:522
size_t takeInDataPacket(void)
Definition: rtp.h:585
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
Definition: rtp.h:417
SOCKET getDataRecvSocket() const
Definition: rtp.h:236
SingleRTPChannel SymmetricRTPChannel
Actually, RTP with a single channel can be called 'Symmetric RTP'.
Definition: channel.h:456
virtual void timerTick(void)
Definition: rtp.h:542
void enableStack(void)
Definition: rtp.h:516
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:98
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...
Definition: cqueue.h:709
void controlTransmissionService(void)
Definition: rtp.h:525
Definition of socket classes for different underlying transport and/or network protocols that can be ...
RTPDataChannel * dso
Definition: rtp.h:398
void setControlPeer(const InetAddress &host, tpport_t port)
Definition: rtp.h:266
timeval getRTCPCheckInterval(void)
Definition: rtp.h:528
SingleThreadRTPSession RTPSession
Uses two pairs of sockets for RTP data and RTCP transmission/reception.
Definition: rtp.h:600
InetHostAddress getControlSender(tpport_t *port=NULL) const
Definition: rtp.h:248
size_t dispatchBYE(const std::string &reason)
This method is used to send an RTCP BYE packet.
void disableStack(void)
Definition: rtp.h:513
size_t sendControl(const unsigned char *const buffer, size_t len)
Definition: rtp.h:275
Generic RTCP control queues.
An RTP application, holding identifying RTCP SDES item values.
Definition: sources.h:366
InetHostAddress getDataSender(tpport_t *port=NULL) const
Definition: rtp.h:202
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
Definition: base.h:110
size_t getNextDataPacketSize() const
Definition: rtp.h:206
static const size_t defaultMembersHashSize
Definition: iqueue.h:855
Socket::Error joinGroup(const InetMcastAddress &ia, uint32 iface)
Join a multicast group.
Definition: rtp.h:288
size_t sendData(const unsigned char *const buffer, size_t len)
Definition: rtp.h:233
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:115
RTPDataChannel * getDSO(void)
Definition: rtp.h:190
Socket::Error leaveGroup(const InetMcastAddress &ia)
Leave a multicast group.
Definition: rtp.h:314
size_t recvData(unsigned char *buffer, size_t len, InetHostAddress &na, tpport_t &tp)
Receive data from the data channel/socket.
Definition: rtp.h:219
size_t dispatchBYE(const std::string &str)
Definition: rtp.h:588
size_t recvControl(unsigned char *buffer, size_t len, InetHostAddress &na, tpport_t &tp)
Receive data from the control channel/socket.
Definition: rtp.h:261
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:474
SingleThreadRTPSession< SymmetricRTPChannel, SymmetricRTPChannel > SymmetricRTPSession
Uses one pair of sockets, (1) for RTP data and (2) for RTCP transmission/reception.
Definition: rtp.h:618
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:439
microtimeout_t getSchedulingTimeout(void)
Definition: rtp.h:519
void endSocket()
Definition: rtp.h:326
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:154
void startRunning()
Activate stack and start service thread.
Definition: rtp.h:507
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
virtual ~TRTPSessionBase()
Definition: rtp.h:185
void setDataPeer(const InetAddress &host, tpport_t port)
Definition: rtp.h:224
~SingleThreadRTPSession()
Definition: rtp.h:493
bool isPendingControl(microtimeout_t timeout)
Definition: rtp.h:244
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:422