49 #ifndef CCXX_RTP_RTP_H_
50 #define CCXX_RTP_RTP_H_
55 #ifdef CCXX_NAMESPACES
101 tpport_t controlPort, uint32 membersSize,
104 { build(ia,dataPort,controlPort); }
122 { build(ia,dataPort,controlPort); }
137 tpport_t controlPort, uint32 membersSize,
140 { build(ia,dataPort,controlPort,iface); }
158 tpport_t controlPort, uint32 membersSize,
161 { build(ia,dataPort,controlPort,iface); }
178 if ( error )
return error;
179 error = dso->setTimeToLive(ttl);
180 if ( error )
return error;
181 error = cso->setMulticast(
true);
182 if ( error )
return error;
183 return cso->setTimeToLive(ttl);
201 {
return dso->isPendingRecv(timeout); }
205 {
return dso->getSender(port); }
209 {
return dso->getNextPacketSize(); }
223 { na = dso->getSender(tp);
return dso->recv(buffer, len); }
227 { dso->setPeer(host,port); }
235 sendData(
const unsigned char*
const buffer,
size_t len)
236 {
return dso->send(buffer, len); }
239 {
return dso->getRecvSocket(); }
247 {
return cso->isPendingRecv(timeout); }
251 {
return cso->getSender(port); }
265 { na = cso->getSender(tp);
return cso->recv(buffer,len); }
269 { cso->setPeer(host,port); }
278 {
return cso->send(buffer,len); }
281 {
return cso->getRecvSocket(); }
293 if ( error )
return error;
294 error = dso->join(ia,iface);
295 if ( error )
return error;
296 error = cso->setMulticast(
true);
301 error = cso->join(ia,iface);
319 if ( error )
return error;
320 error = dso->leaveGroup(ia);
321 if ( error )
return error;
322 error = cso->setMulticast(
false);
323 if ( error )
return error;
324 return cso->leaveGroup(ia);
347 if ( 0 == controlPort ) {
348 dataBasePort = even_port(dataPort);
349 controlBasePort = dataBasePort + 1;
351 dataBasePort = dataPort;
352 controlBasePort = controlPort;
354 dso =
new RTPDataChannel(ia,dataBasePort);
355 cso =
new RTCPChannel(ia,controlBasePort);
362 if ( 0 == controlPort ) {
363 dataBasePort = even_port(dataPort);
364 controlBasePort = dataBasePort + 1;
366 dataBasePort = dataPort;
367 controlBasePort = controlPort;
383 {
return (port & 0x01)? (port) : (port - 1); }
394 {
return (port & 0x01)? (port - 1) : (port); }
431 #
if defined(_MSC_VER) && _MSC_VER >= 1300
437 (ia,dataPort,controlPort,memberssize,app)
448 #
if defined(_MSC_VER) && _MSC_VER >= 1300
454 (ssrc, ia,dataPort,controlPort,memberssize,app)
466 #
if defined(_MSC_VER) && _MSC_VER >= 1300
472 (ia,dataPort,controlPort,memberssize,app,iface)
484 #
if defined(_MSC_VER) && _MSC_VER >= 1300
490 (ssrc,ia,dataPort,controlPort,memberssize,app,iface)
502 #if defined(_MSC_VER) && _MSC_VER >= 1300
503 virtual void startRunning();
536 #if defined(_MSC_VER) && _MSC_VER >= 1300
537 virtual void run(
void);
539 virtual void timerTick(
void);
557 while ( ServiceQueue::isActive() ) {
558 if ( timeout < 1000 ){
559 timeout = getSchedulingTimeout();
561 setCancel(cancelDeferred);
562 controlReceptionService();
563 controlTransmissionService();
564 setCancel(cancelImmediate);
570 timeout = (timeout > maxWait)? maxWait : timeout;
571 if ( timeout < 1000 ) {
572 setCancel(cancelDeferred);
573 dispatchDataPacket();
574 setCancel(cancelImmediate);
577 if ( isPendingData(timeout/1000) ) {
578 setCancel(cancelDeferred);
579 if (ServiceQueue::isActive()) {
582 setCancel(cancelImmediate);
587 dispatchBYE(
"GNU ccRTP stack finishing.");
651 template <
class RTPDataChannel = DualRTPUDPIPv6Channel,
652 class RTCPChannel = DualRTPUDPIPv6Channel,
666 TRTPSessionBaseIPV6(
const IPV6Host& ia,
tpport_t dataPort,
667 tpport_t controlPort, uint32 membersSize,
670 { build(ia,dataPort,controlPort); }
683 TRTPSessionBaseIPV6(uint32 ssrc,
688 { build(ia,dataPort,controlPort); }
702 TRTPSessionBaseIPV6(
const IPV6Multicast& ia,
tpport_t dataPort,
703 tpport_t controlPort, uint32 membersSize,
706 { build(ia,dataPort,controlPort,iface); }
722 TRTPSessionBaseIPV6(uint32 ssrc,
723 const IPV6Multicast& ia,
tpport_t dataPort,
724 tpport_t controlPort, uint32 membersSize,
727 { build(ia,dataPort,controlPort,iface); }
729 virtual size_t dispatchBYE(
const std::string &str)
735 ~TRTPSessionBaseIPV6()
740 inline RTPDataChannel *getDSO(
void)
749 {
return dso->isPendingRecv(timeout); }
752 getDataSender(
tpport_t *port = NULL)
const
753 {
return dso->getSender(port); }
756 getNextDataPacketSize()
const
757 {
return dso->getNextPacketSize(); }
769 recvData(
unsigned char* buffer,
size_t len,
771 { na = dso->getSender(tp);
return dso->recv(buffer, len); }
774 setDataPeerIPV6(
const IPV6Host &host,
tpport_t port)
775 { dso->setPeer(host,port); }
782 sendDataIPV6(
const unsigned char*
const buffer,
size_t len)
783 {
return dso->send(buffer, len); }
785 inline SOCKET getDataRecvSocket()
const
786 {
return dso->getRecvSocket(); }
794 {
return cso->isPendingRecv(timeout); }
797 getControlSender(
tpport_t *port = NULL)
const
798 {
return cso->getSender(port); }
810 recvControl(
unsigned char *buffer,
size_t len,
812 { na = cso->getSender(tp);
return cso->recv(buffer,len); }
815 setControlPeerIPV6(
const IPV6Host &host,
tpport_t port)
816 { cso->setPeer(host,port); }
824 sendControl(
const unsigned char*
const buffer,
size_t len)
825 {
return cso->send(buffer,len); }
827 inline SOCKET getControlRecvSocket()
const
828 {
return cso->getRecvSocket(); }
843 build(
const IPV6Host& ia,
tpport_t dataPort,
846 if ( 0 == controlPort ) {
847 dataBasePort = even_port(dataPort);
848 controlBasePort = dataBasePort + 1;
850 dataBasePort = dataPort;
851 controlBasePort = controlPort;
853 dso =
new RTPDataChannel(ia,dataBasePort);
854 cso =
new RTCPChannel(ia,controlBasePort);
858 build(
const IPV6Multicast& ia,
tpport_t dataPort,
861 if ( 0 == controlPort ) {
862 dataBasePort = even_port(dataPort);
863 controlBasePort = dataBasePort + 1;
865 dataBasePort = dataPort;
866 controlBasePort = controlPort;
868 dso =
new RTPDataChannel(IPV6Host(
"0.0.0.0"),dataBasePort);
869 cso =
new RTCPChannel(IPV6Host(
"0.0.0.0"),controlBasePort);
880 joinGroup(
const IPV6Multicast& ia, uint32 iface)
883 if ( error )
return error;
884 error = dso->join(ia,iface);
885 if ( error )
return error;
886 error = cso->setMulticast(
true);
891 error = cso->join(ia,iface);
906 leaveGroup(
const IPV6Multicast& ia)
909 if ( error )
return error;
910 error = dso->leaveGroup(ia);
911 if ( error )
return error;
912 error = cso->setMulticast(
false);
913 if ( error )
return error;
914 return cso->leaveGroup(ia);
924 setMcastTTL(uint8 ttl)
927 if ( error )
return error;
928 error = dso->setTimeToLive(ttl);
929 if ( error )
return error;
930 error = cso->setMulticast(
true);
931 if ( error )
return error;
932 return cso->setTimeToLive(ttl);
944 {
return (port & 0x01)? (port) : (port - 1); }
955 {
return (port & 0x01)? (port - 1) : (port); }
977 <
class RTPDataChannel = DualRTPUDPIPv6Channel,
978 class RTCPChannel = DualRTPUDPIPv6Channel,
980 class __EXPORT SingleThreadRTPSessionIPV6 :
982 public TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
985 SingleThreadRTPSessionIPV6(
const IPV6Host& ia,
992 #
if defined(_MSC_VER) && _MSC_VER >= 1300
997 TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
998 (ia,dataPort,controlPort,memberssize,app)
1002 SingleThreadRTPSessionIPV6(
const IPV6Multicast& ia,
1006 uint32 memberssize =
1010 #
if defined(_MSC_VER) && _MSC_VER >= 1300
1015 TRTPSessionBaseIPV6<RTPDataChannel,RTCPChannel,ServiceQueue>
1016 (ia,dataPort,controlPort,memberssize,app,iface)
1020 ~SingleThreadRTPSessionIPV6()
1027 #if defined(_MSC_VER) && _MSC_VER >= 1300
1028 virtual void startRunning();
1040 inline void enableStack(
void)
1043 inline void disableStack(
void)
1049 inline void controlReceptionService(
void)
1052 inline void controlTransmissionService(
void)
1055 inline timeval getRTCPCheckInterval(
void)
1058 inline size_t dispatchDataPacket(
void)
1061 #if defined(_MSC_VER) && _MSC_VER >= 1300
1062 virtual void run(
void);
1064 virtual void timerTick(
void);
1069 virtual void timerTick(
void)
1079 virtual void run(
void)
1082 while ( ServiceQueue::isActive() ) {
1083 if ( timeout < 1000 ){
1084 timeout = getSchedulingTimeout();
1086 setCancel(cancelDeferred);
1087 controlReceptionService();
1088 controlTransmissionService();
1089 setCancel(cancelImmediate);
1095 timeout = (timeout > maxWait)? maxWait : timeout;
1096 if ( timeout < 1000 ) {
1097 setCancel(cancelDeferred);
1098 dispatchDataPacket();
1099 setCancel(cancelImmediate);
1102 if ( isPendingData(timeout/1000) ) {
1103 setCancel(cancelDeferred);
1105 setCancel(cancelImmediate);
1110 dispatchBYE(
"GNU ccRTP stack finishing.");
1116 inline size_t takeInDataPacket(
void)
1119 inline size_t dispatchBYE(
const std::string &str)
1131 typedef SingleThreadRTPSessionIPV6<> RTPSessionIPV6;
1138 typedef RTPSessionIPV6 RTPSocketIPV6;
1148 typedef SingleThreadRTPSessionIPV6<SymmetricRTPChannelIPV6,
1149 SymmetricRTPChannelIPV6> SymmetricRTPSessionIPV6;
1156 #ifdef CCXX_NAMESPACES
1160 #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
__EXPORT AppLog & error(AppLog &sl)
Manipulator for error level.
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...
unsigned short tpport_t
Transport Protocol Ports.
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)
int start(Semaphore *start=0)
When a new thread is created, it does not begin immediate execution.
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)
void join(void)
Blocking call which unlocks when thread terminates.
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)
A UDP/IPv4 socket class targetted at RTP stacks.
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...
void exit(void)
Used to properly exit from a Thread derived run() or initial() method.
Every thread of execution in an application is created by instantiating an object of a class derived ...
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...