50#ifndef CCXX_RTP_RTP_H_
51#define CCXX_RTP_RTP_H_
100 tpport_t controlPort, uint32 membersSize,
102 ServiceQueue(membersSize,app)
103 { build(ia,dataPort,controlPort); }
117 const InetHostAddress& ia,
118 tpport_t dataPort, tpport_t controlPort,
120 ServiceQueue(ssrc,membersSize,app)
121 { build(ia,dataPort,controlPort); }
136 tpport_t controlPort, uint32 membersSize,
138 ServiceQueue(membersSize,app)
139 { build(ia,dataPort,controlPort,iface); }
156 const InetMcastAddress& ia, tpport_t dataPort,
157 tpport_t controlPort, uint32 membersSize,
159 ServiceQueue(ssrc,membersSize,app)
160 { build(ia,dataPort,controlPort,iface); }
176 Socket::Error error = dso->setMulticast(
true);
177 if ( error )
return error;
178 error = dso->setTimeToLive(ttl);
179 if ( error )
return error;
180 error = cso->setMulticast(
true);
181 if ( error )
return error;
182 return cso->setTimeToLive(ttl);
200 {
return dso->isPendingRecv(timeout); }
204 {
return dso->getSender(port); }
208 {
return dso->getNextPacketSize(); }
221 InetHostAddress& na, tpport_t& tp)
222 { na = dso->getSender(tp);
return dso->recv(buffer, len); }
226 { dso->setPeer(host,port); }
234 sendData(
const unsigned char*
const buffer,
size_t len)
235 {
return dso->send(buffer, len); }
238 {
return dso->getRecvSocket(); }
246 {
return cso->isPendingRecv(timeout); }
250 {
return cso->getSender(port); }
263 InetHostAddress& na, tpport_t& tp)
264 { na = cso->getSender(tp);
return cso->recv(buffer,len); }
268 { cso->setPeer(host,port); }
277 {
return cso->send(buffer,len); }
280 {
return cso->getRecvSocket(); }
291 Socket::Error error = dso->setMulticast(
true);
292 if ( error )
return error;
293 error = dso->join(ia,iface);
294 if ( error )
return error;
295 error = cso->setMulticast(
true);
300 error = cso->join(ia,iface);
305 return Socket::errSuccess;
317 Socket::Error error = dso->setMulticast(
false);
318 if ( error )
return error;
319 error = dso->leaveGroup(ia);
320 if ( error )
return error;
321 error = cso->setMulticast(
false);
322 if ( error )
return error;
323 return cso->leaveGroup(ia);
343 build(
const InetHostAddress& ia, tpport_t dataPort,
344 tpport_t controlPort)
346 if ( 0 == controlPort ) {
347 dataBasePort = even_port(dataPort);
348 controlBasePort = dataBasePort + 1;
350 dataBasePort = dataPort;
351 controlBasePort = controlPort;
353 dso =
new RTPDataChannel(ia,dataBasePort);
354 cso =
new RTCPChannel(ia,controlBasePort);
358 build(
const InetMcastAddress& ia, tpport_t dataPort,
359 tpport_t controlPort, uint32 iface)
361 if ( 0 == controlPort ) {
362 dataBasePort = even_port(dataPort);
363 controlBasePort = dataBasePort + 1;
365 dataBasePort = dataPort;
366 controlBasePort = controlPort;
368 dso =
new RTPDataChannel(InetHostAddress(
"0.0.0.0"),dataBasePort);
369 cso =
new RTCPChannel(InetHostAddress(
"0.0.0.0"),controlBasePort);
381 odd_port(tpport_t port)
382 {
return (port & 0x01)? (port) : (port - 1); }
392 even_port(tpport_t port)
393 {
return (port & 0x01)? (port - 1) : (port); }
395 tpport_t dataBasePort;
396 tpport_t controlBasePort;
425 tpport_t controlPort = 0,
430#
if defined(_MSC_VER) && _MSC_VER >= 1300
436 (ia,dataPort,controlPort,memberssize,app)
442 tpport_t controlPort = 0,
447#
if defined(_MSC_VER) && _MSC_VER >= 1300
453 (ssrc, ia,dataPort,controlPort,memberssize,app)
459 tpport_t controlPort = 0,
465#
if defined(_MSC_VER) && _MSC_VER >= 1300
471 (ia,dataPort,controlPort,memberssize,app,iface)
477 tpport_t controlPort = 0,
483#
if defined(_MSC_VER) && _MSC_VER >= 1300
489 (ssrc,ia,dataPort,controlPort,memberssize,app,iface)
497 disableStack(); Thread::join();
501#if defined(_MSC_VER) && _MSC_VER >= 1300
502virtual void startRunning();
509{ enableStack(); Thread::start(); }
535#if defined(_MSC_VER) && _MSC_VER >= 1300
536virtual void run(
void);
538virtual void timerTick(
void);
556 while ( ServiceQueue::isActive() ) {
557 if ( timeout < 1000 ){
558 timeout = getSchedulingTimeout();
560 controlReceptionService();
561 controlTransmissionService();
567 timeout = (timeout > maxWait)? maxWait : timeout;
568 if ( timeout < 1000 ) {
569 dispatchDataPacket();
572 if ( isPendingData(timeout/1000) ) {
573 if (ServiceQueue::isActive()) {
580 dispatchBYE(
"GNU ccRTP stack finishing.");
644template <
class RTPDataChannel = DualRTPUDPIPv6Channel,
645 class RTCPChannel = DualRTPUDPIPv6Channel,
647class __EXPORT TRTPSessionBaseIPV6 :
public ServiceQueue
659TRTPSessionBaseIPV6(
const IPV6Host& ia, tpport_t dataPort,
660 tpport_t controlPort, uint32 membersSize,
662 ServiceQueue(membersSize,app)
663{ build(ia,dataPort,controlPort); }
676 TRTPSessionBaseIPV6(uint32 ssrc,
678 tpport_t dataPort, tpport_t controlPort,
680 ServiceQueue(ssrc,membersSize,app)
681 { build(ia,dataPort,controlPort); }
695 TRTPSessionBaseIPV6(
const IPV6Multicast& ia, tpport_t dataPort,
696 tpport_t controlPort, uint32 membersSize,
698 ServiceQueue(membersSize,app)
699 { build(ia,dataPort,controlPort,iface); }
715 TRTPSessionBaseIPV6(uint32 ssrc,
716 const IPV6Multicast& ia, tpport_t dataPort,
717 tpport_t controlPort, uint32 membersSize,
719 ServiceQueue(ssrc,membersSize,app)
720 { build(ia,dataPort,controlPort,iface); }
722 virtual size_t dispatchBYE(
const std::string &str)
728 ~TRTPSessionBaseIPV6()
733 inline RTPDataChannel *getDSO(
void)
742 {
return dso->isPendingRecv(timeout); }
745 getDataSender(tpport_t *port = NULL)
const
746 {
return dso->getSender(port); }
749 getNextDataPacketSize()
const
750 {
return dso->getNextPacketSize(); }
762 recvData(
unsigned char* buffer,
size_t len,
763 IPV6Host& na, tpport_t& tp)
764 { na = dso->getSender(tp);
return dso->recv(buffer, len); }
767 setDataPeerIPV6(
const IPV6Host &host, tpport_t port)
768 { dso->setPeer(host,port); }
775 sendDataIPV6(
const unsigned char*
const buffer,
size_t len)
776 {
return dso->send(buffer, len); }
778 inline SOCKET getDataRecvSocket()
const
779 {
return dso->getRecvSocket(); }
787 {
return cso->isPendingRecv(timeout); }
790 getControlSender(tpport_t *port = NULL)
const
791 {
return cso->getSender(port); }
803 recvControl(
unsigned char *buffer,
size_t len,
804 IPV6Host& na, tpport_t& tp)
805 { na = cso->getSender(tp);
return cso->recv(buffer,len); }
808 setControlPeerIPV6(
const IPV6Host &host, tpport_t port)
809 { cso->setPeer(host,port); }
817 sendControl(
const unsigned char*
const buffer,
size_t len)
818 {
return cso->send(buffer,len); }
820 inline SOCKET getControlRecvSocket()
const
821 {
return cso->getRecvSocket(); }
836 build(
const IPV6Host& ia, tpport_t dataPort,
837 tpport_t controlPort)
839 if ( 0 == controlPort ) {
840 dataBasePort = even_port(dataPort);
841 controlBasePort = dataBasePort + 1;
843 dataBasePort = dataPort;
844 controlBasePort = controlPort;
846 dso =
new RTPDataChannel(ia,dataBasePort);
847 cso =
new RTCPChannel(ia,controlBasePort);
851 build(
const IPV6Multicast& ia, tpport_t dataPort,
852 tpport_t controlPort, uint32 iface)
854 if ( 0 == controlPort ) {
855 dataBasePort = even_port(dataPort);
856 controlBasePort = dataBasePort + 1;
858 dataBasePort = dataPort;
859 controlBasePort = controlPort;
861 dso =
new RTPDataChannel(IPV6Host(
"0.0.0.0"),dataBasePort);
862 cso =
new RTCPChannel(IPV6Host(
"0.0.0.0"),controlBasePort);
873 joinGroup(
const IPV6Multicast& ia, uint32 iface)
875 Socket::Error error = dso->setMulticast(
true);
876 if ( error )
return error;
877 error = dso->join(ia,iface);
878 if ( error )
return error;
879 error = cso->setMulticast(
true);
884 error = cso->join(ia,iface);
889 return Socket::errSuccess;
899 leaveGroup(
const IPV6Multicast& ia)
901 Socket::Error error = dso->setMulticast(
false);
902 if ( error )
return error;
903 error = dso->leaveGroup(ia);
904 if ( error )
return error;
905 error = cso->setMulticast(
false);
906 if ( error )
return error;
907 return cso->leaveGroup(ia);
917 setMcastTTL(uint8 ttl)
919 Socket::Error error = dso->setMulticast(
true);
920 if ( error )
return error;
921 error = dso->setTimeToLive(ttl);
922 if ( error )
return error;
923 error = cso->setMulticast(
true);
924 if ( error )
return error;
925 return cso->setTimeToLive(ttl);
936 odd_port(tpport_t port)
937 {
return (port & 0x01)? (port) : (port - 1); }
947 even_port(tpport_t port)
948 {
return (port & 0x01)? (port - 1) : (port); }
950 tpport_t dataBasePort;
951 tpport_t controlBasePort;
970<
class RTPDataChannel = DualRTPUDPIPv6Channel,
971 class RTCPChannel = DualRTPUDPIPv6Channel,
973class __EXPORT SingleThreadRTPSessionIPV6 :
975 public TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
978 SingleThreadRTPSessionIPV6(
const IPV6Host& ia,
980 tpport_t controlPort = 0,
985#
if defined(_MSC_VER) && _MSC_VER >= 1300
990 TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
991 (ia,dataPort,controlPort,memberssize,app)
995SingleThreadRTPSessionIPV6(
const IPV6Multicast& ia,
997 tpport_t controlPort = 0,
1003#
if defined(_MSC_VER) && _MSC_VER >= 1300
1008 TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
1009 (ia,dataPort,controlPort,memberssize,app,iface)
1013~SingleThreadRTPSessionIPV6()
1016 disableStack(); Thread::join();
1020#if defined(_MSC_VER) && _MSC_VER >= 1300
1021virtual void startRunning();
1028{ enableStack(); Thread::start(); }
1033inline void enableStack(
void)
1034{TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::enableStack();}
1036inline void disableStack(
void)
1037{TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::disableStack();}
1040{
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::getSchedulingTimeout();}
1042inline void controlReceptionService(
void)
1043{TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::controlReceptionService();}
1045inline void controlTransmissionService(
void)
1046{TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::controlTransmissionService();}
1048inline timeval getRTCPCheckInterval(
void)
1049{
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::getRTCPCheckInterval();}
1051inline size_t dispatchDataPacket(
void)
1052{
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchDataPacket();}
1054#if defined(_MSC_VER) && _MSC_VER >= 1300
1055virtual void run(
void);
1057virtual void timerTick(
void);
1062virtual void timerTick(
void)
1066{
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::isPendingData(timeout);}
1072virtual void run(
void)
1075 while ( ServiceQueue::isActive() ) {
1076 if ( timeout < 1000 ){
1077 timeout = getSchedulingTimeout();
1079 controlReceptionService();
1080 controlTransmissionService();
1086 timeout = (timeout > maxWait)? maxWait : timeout;
1087 if ( timeout < 1000 ) {
1088 dispatchDataPacket();
1091 if ( isPendingData(timeout/1000) ) {
1097 dispatchBYE(
"GNU ccRTP stack finishing.");
1103inline size_t takeInDataPacket(
void)
1104{
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::takeInDataPacket();}
1106inline size_t dispatchBYE(
const std::string &str)
1107{
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchBYE(str);}
1118typedef SingleThreadRTPSessionIPV6<> RTPSessionIPV6;
1125typedef RTPSessionIPV6 RTPSocketIPV6;
1135 typedef SingleThreadRTPSessionIPV6<SymmetricRTPChannelIPV6,
1136 SymmetricRTPChannelIPV6> SymmetricRTPSessionIPV6;
microtimeout_t timeval2microtimeout(const timeval &t)
Convert a time interval, expressed as a timeval value into a microseconds counter.
Definition base.h:90
uint32 microtimeout_t
Time interval expressed in microseconds.
Definition base.h:67
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
Definition base.h:109
Definition of socket classes for different underlying transport and/or network protocols that can be ...
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...
Definition cqueue.h:709
virtual size_t takeInDataPacket()
This function is used by the service thread to process the next incoming packet and place it in the r...
static const size_t defaultMembersHashSize
Definition iqueue.h:854
microtimeout_t getSchedulingTimeout()
This computes the timeout period for scheduling transmission of the next packet at the "head" of the ...
size_t dispatchDataPacket()
This function is used by the service thread to process the next outgoing packet pending in the sendin...
void controlReceptionService()
Process incoming RTCP packets pending in the control reception socket.
void controlTransmissionService()
Build and send RTCP packets following timing rules (including the "timer reconsideration" algorithm).
timeval getRTCPCheckInterval()
Definition cqueue.h:362
size_t dispatchBYE(const std::string &reason)
This method is used to send an RTCP BYE packet.
An RTP application, holding identifying RTCP SDES item values.
Definition sources.h:365
A UDP/IPv4 socket class targetted at RTP stacks.
Definition channel.h:95
void disableStack()
Disable packet queue processing in the stack.
Definition ioqueue.h:129
void enableStack()
Enable packet queue processing in the stack.
Definition ioqueue.h:123
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
Definition rtp.h:421
void controlTransmissionService(void)
Definition rtp.h:526
size_t dispatchDataPacket(void)
Definition rtp.h:532
virtual void timerTick(void)
Definition rtp.h:543
microtimeout_t getSchedulingTimeout(void)
Definition rtp.h:520
void enableStack(void)
Definition rtp.h:517
virtual bool isPendingData(microtimeout_t timeout)
Definition rtp.h:546
virtual void run(void)
Single runnable method for this RTP stacks, schedules outgoing and incoming RTP data and RTCP packets...
Definition rtp.h:553
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:475
size_t takeInDataPacket(void)
Definition rtp.h:586
void controlReceptionService(void)
Definition rtp.h:523
timeval getRTCPCheckInterval(void)
Definition rtp.h:529
~SingleThreadRTPSession()
Definition rtp.h:494
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:440
void disableStack(void)
Definition rtp.h:514
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:423
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:457
size_t dispatchBYE(const std::string &str)
Definition rtp.h:589
void startRunning()
Activate stack and start service thread.
Definition rtp.h:508
void setControlPeer(const InetAddress &host, tpport_t port)
Definition rtp.h:267
virtual size_t dispatchBYE(const std::string &str)
Definition rtp.h:162
Socket::Error setMcastTTL(uint8 ttl)
Set the value of the TTL field in the sent packets.
Definition rtp.h:174
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:155
InetHostAddress getDataSender(tpport_t *port=NULL) const
Definition rtp.h:203
void endSocket()
Definition rtp.h:327
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:135
RTPDataChannel * dso
Definition rtp.h:399
size_t sendControl(const unsigned char *const buffer, size_t len)
Definition rtp.h:276
bool isPendingData(microtimeout_t timeout)
Definition rtp.h:199
bool isPendingControl(microtimeout_t timeout)
Definition rtp.h:245
Socket::Error joinGroup(const InetMcastAddress &ia, uint32 iface)
Join a multicast group.
Definition rtp.h:289
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:116
size_t recvData(unsigned char *buffer, size_t len, InetHostAddress &na, tpport_t &tp)
Receive data from the data channel/socket.
Definition rtp.h:220
size_t sendData(const unsigned char *const buffer, size_t len)
Definition rtp.h:234
SOCKET getDataRecvSocket() const
Definition rtp.h:237
RTPDataChannel * getDSO(void)
Definition rtp.h:191
virtual ~TRTPSessionBase()
Definition rtp.h:186
size_t getNextDataPacketSize() const
Definition rtp.h:207
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:99
Socket::Error leaveGroup(const InetMcastAddress &ia)
Leave a multicast group.
Definition rtp.h:315
size_t recvControl(unsigned char *buffer, size_t len, InetHostAddress &na, tpport_t &tp)
Receive data from the control channel/socket.
Definition rtp.h:262
SOCKET getControlRecvSocket() const
Definition rtp.h:279
void setDataPeer(const InetAddress &host, tpport_t port)
Definition rtp.h:225
RTCPChannel * cso
Definition rtp.h:400
InetHostAddress getControlSender(tpport_t *port=NULL) const
Definition rtp.h:249
Generic RTCP control queues.
SingleThreadRTPSession RTPSession
Uses two pairs of sockets for RTP data and RTCP transmission/reception.
Definition rtp.h:601
SingleThreadRTPSession< SymmetricRTPChannel, SymmetricRTPChannel > SymmetricRTPSession
Uses one pair of sockets, (1) for RTP data and (2) for RTCP transmission/reception.
Definition rtp.h:619
RTPSession RTPSocket
Alias for RTPSession.
Definition rtp.h:608
SingleRTPChannel SymmetricRTPChannel
Actually, RTP with a single channel can be called 'Symmetric RTP'.
Definition channel.h:455
DualRTPChannel< RTPBaseUDPIPv4Socket > DualRTPUDPIPv4Channel
Definition channel.h:444
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...