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);
382 {
return (port & 0x01)? (port) : (port - 1); }
393 {
return (port & 0x01)? (port - 1) : (port); }
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
502 virtual void startRunning();
509 { enableStack(); Thread::start(); }
535 #if defined(_MSC_VER) && _MSC_VER >= 1300
536 virtual void run(
void);
538 virtual 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();
573 if (ServiceQueue::isActive()) {
644 template <
class RTPDataChannel = DualRTPUDPIPv6Channel,
645 class RTCPChannel = DualRTPUDPIPv6Channel,
647 class __EXPORT TRTPSessionBaseIPV6 :
public ServiceQueue
659 TRTPSessionBaseIPV6(
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,
973 class __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)
995 SingleThreadRTPSessionIPV6(
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
1021 virtual void startRunning();
1028 { enableStack(); Thread::start(); }
1033 inline void enableStack(
void)
1034 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::enableStack();}
1036 inline void disableStack(
void)
1037 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::disableStack();}
1040 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::getSchedulingTimeout();}
1042 inline void controlReceptionService(
void)
1043 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::controlReceptionService();}
1045 inline void controlTransmissionService(
void)
1046 {TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::controlTransmissionService();}
1048 inline timeval getRTCPCheckInterval(
void)
1049 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::getRTCPCheckInterval();}
1051 inline size_t dispatchDataPacket(
void)
1052 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchDataPacket();}
1054 #if defined(_MSC_VER) && _MSC_VER >= 1300
1055 virtual void run(
void);
1057 virtual void timerTick(
void);
1062 virtual void timerTick(
void)
1066 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::isPendingData(timeout);}
1072 virtual 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.");
1103 inline size_t takeInDataPacket(
void)
1104 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::takeInDataPacket();}
1106 inline size_t dispatchBYE(
const std::string &str)
1107 {
return TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchBYE(str);}
1118 typedef SingleThreadRTPSessionIPV6<> RTPSessionIPV6;
1125 typedef RTPSessionIPV6 RTPSocketIPV6;
1135 typedef SingleThreadRTPSessionIPV6<SymmetricRTPChannelIPV6,
1136 SymmetricRTPChannelIPV6> SymmetricRTPSessionIPV6;
1145 #endif //CCXX_RTP_RTP_H_
void setControlPeer(const InetAddress &host, tpport_t port)
An RTP application, holding identifying RTCP SDES item values.
void build(const InetHostAddress &ia, tpport_t dataPort, tpport_t controlPort)
~SingleThreadRTPSession()
RTPSession RTPSocket
Alias for RTPSession.
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)
InetHostAddress getControlSender(tpport_t *port=NULL) const
DualRTPChannel< RTPBaseUDPIPv4Socket > DualRTPUDPIPv4Channel
virtual void timerTick(void)
uint32 microtimeout_t
Time interval expressed in microseconds.
void controlReceptionService(void)
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...
Socket::Error setMcastTTL(uint8 ttl)
Set the value of the TTL field in the sent packets.
microtimeout_t timeval2microtimeout(const timeval &t)
Convert a time interval, expressed as a timeval value into a microseconds counter.
size_t dispatchBYE(const std::string &str)
size_t sendData(const unsigned char *const buffer, size_t len)
void setDataPeer(const InetAddress &host, tpport_t port)
tpport_t even_port(tpport_t port)
Ensure a port number is even.
SingleRTPChannel SymmetricRTPChannel
Actually, RTP with a single channel can be called 'Symmetric RTP'.
void build(const InetMcastAddress &ia, tpport_t dataPort, tpport_t controlPort, uint32 iface)
SOCKET getDataRecvSocket() const
size_t dispatchDataPacket(void)
InetHostAddress getDataSender(tpport_t *port=NULL) const
virtual bool isPendingData(microtimeout_t timeout)
bool isPendingControl(microtimeout_t timeout)
Socket::Error joinGroup(const InetMcastAddress &ia, uint32 iface)
Join a multicast group.
Definition of socket classes for different underlying transport and/or network protocols that can be ...
SOCKET getControlRecvSocket() const
tpport_t odd_port(tpport_t port)
Ensure a port number is odd.
size_t takeInDataPacket(void)
SingleThreadRTPSession(const InetHostAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0, int pri=0, uint32 memberssize=MembershipBookkeeping::defaultMembersHashSize, RTPApplication &app=defaultApplication())
virtual size_t dispatchBYE(const std::string &str)
size_t recvControl(unsigned char *buffer, size_t len, InetHostAddress &na, tpport_t &tp)
Receive data from the control channel/socket.
void startRunning()
Activate stack and start service thread.
SingleThreadRTPSession RTPSession
Uses two pairs of sockets for RTP data and RTCP transmission/reception.
bool isPendingData(microtimeout_t timeout)
static const size_t defaultMembersHashSize
virtual void run(void)
Single runnable method for this RTP stacks, schedules outgoing and incoming RTP data and RTCP packets...
size_t recvData(unsigned char *buffer, size_t len, InetHostAddress &na, tpport_t &tp)
Receive data from the data channel/socket.
Generic RTCP control queues.
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.
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.
const tpport_t DefaultRTPDataPort
registered default RTP data transport port
SingleThreadRTPSession(uint32 ssrc, const InetHostAddress &ia, tpport_t dataPort=DefaultRTPDataPort, tpport_t controlPort=0, int pri=0, uint32 memberssize=MembershipBookkeeping::defaultMembersHashSize, RTPApplication &app=defaultApplication())
Socket::Error leaveGroup(const InetMcastAddress &ia)
Leave a multicast group.
size_t sendControl(const unsigned char *const buffer, size_t len)
This template class adds the threading aspect to the RTPSessionBase template in one of the many possi...
timeval getRTCPCheckInterval(void)
size_t getNextDataPacketSize() const
SingleThreadRTPSession< SymmetricRTPChannel, SymmetricRTPChannel > SymmetricRTPSession
Uses one pair of sockets, (1) for RTP data and (2) for RTCP transmission/reception.
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)
virtual ~TRTPSessionBase()
TRTPSessionBase(const InetHostAddress &ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication &app)
Builds a session waiting for packets in a host address.
__EXPORT RTPApplication & defaultApplication()
Get the RTPApplication object for the "default" application (the only one used by common applications...
microtimeout_t getSchedulingTimeout(void)
RTPDataChannel * getDSO(void)
size_t dispatchBYE(const std::string &reason)
This method is used to send an RTCP BYE packet.
void controlTransmissionService(void)
This class, an RTP/RTCP queue, adds audio/video profile (AVP) specific methods to the generic RTCP se...