📄 rtp.h
字号:
*/ inline tpport_t even_port(tpport_t port) { return (port & 0x01)? (port - 1) : (port); } tpport_t dataBasePort; tpport_t controlBasePort; protected: RTPDataChannel* dso; RTCPChannel* cso; friend class RTPSessionBaseHandler; };/** * @class SingleThreadRTPSession * * This template class adds the threading aspect to the RTPSessionBase * template in one of the many possible ways. It inherits from a * single execution thread that schedules sending of outgoing packets * and receipt of incoming packets. * * @author Federico Montesino Pouzols <fedemp@altern.org> **/ template <class RTPDataChannel = DualRTPUDPIPv4Channel, class RTCPChannel = DualRTPUDPIPv4Channel, class ServiceQueue = AVPQueue> class __EXPORT SingleThreadRTPSession : protected Thread, public TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue> { public: SingleThreadRTPSession(const InetHostAddress& ia, tpport_t dataPort = DefaultRTPDataPort, tpport_t controlPort = 0, int pri = 0, uint32 memberssize = MembershipBookkeeping::defaultMembersHashSize, RTPApplication& app = defaultApplication()#if defined(_MSC_VER) && _MSC_VER >= 1300 );#else ): Thread(pri), TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue> (ia,dataPort,controlPort,memberssize,app) { }#endif SingleThreadRTPSession(uint32 ssrc, const InetHostAddress& ia, tpport_t dataPort = DefaultRTPDataPort, tpport_t controlPort = 0, int pri = 0, uint32 memberssize = MembershipBookkeeping::defaultMembersHashSize, RTPApplication& app = defaultApplication()#if defined(_MSC_VER) && _MSC_VER >= 1300 );#else ): Thread(pri), TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue> (ssrc, ia,dataPort,controlPort,memberssize,app){ }#endifSingleThreadRTPSession(const InetMcastAddress& ia, tpport_t dataPort = DefaultRTPDataPort, tpport_t controlPort = 0, int pri = 0, uint32 memberssize = MembershipBookkeeping::defaultMembersHashSize, RTPApplication& app = defaultApplication(), uint32 iface = 0#if defined(_MSC_VER) && _MSC_VER >= 1300 );#else ): Thread(pri), TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue> (ia,dataPort,controlPort,memberssize,app,iface) { }#endifSingleThreadRTPSession(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#if defined(_MSC_VER) && _MSC_VER >= 1300 );#else ): Thread(pri), TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue> (ssrc,ia,dataPort,controlPort,memberssize,app,iface){ }#endif~SingleThreadRTPSession(){ if (isRunning()) { disableStack(); Thread::join(); }}#if defined(_MSC_VER) && _MSC_VER >= 1300virtual void startRunning();#else/** * Activate stack and start service thread. **/voidstartRunning(){ enableStack(); Thread::start(); }#endifprotected:inline void disableStack(void){TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::disableStack();}inline void enableStack(void){TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::enableStack();}inline microtimeout_t getSchedulingTimeout(void){return TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::getSchedulingTimeout();}inline void controlReceptionService(void){TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::controlReceptionService();}inline void controlTransmissionService(void){TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::controlTransmissionService();}inline timeval getRTCPCheckInterval(void){return TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::getRTCPCheckInterval();};inline size_t dispatchDataPacket(void){return TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchDataPacket();};#if defined(_MSC_VER) && _MSC_VER >= 1300virtual void run(void);virtual void timerTick(void);virtual bool isPendingData(microtimeout_t timeout);#elsevirtual void timerTick(void){return;}virtual bool isPendingData(microtimeout_t timeout){return TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::isPendingData(timeout);}/** * Single runnable method for this RTP stacks, schedules * outgoing and incoming RTP data and RTCP packets. **/virtual void run(void){ microtimeout_t timeout = 0; while ( ServiceQueue::isActive() ) { if ( timeout < 1000 ){ // !(timeout/1000) timeout = getSchedulingTimeout(); } setCancel(cancelDeferred); controlReceptionService(); controlTransmissionService(); setCancel(cancelImmediate); microtimeout_t maxWait = timeval2microtimeout(getRTCPCheckInterval()); // make sure the scheduling timeout is // <= the check interval for RTCP // packets timeout = (timeout > maxWait)? maxWait : timeout; if ( timeout < 1000 ) { // !(timeout/1000) setCancel(cancelDeferred); dispatchDataPacket(); setCancel(cancelImmediate); timerTick(); } else { if ( isPendingData(timeout/1000) ) { setCancel(cancelDeferred); if (ServiceQueue::isActive()) { // take in only if active takeInDataPacket(); } setCancel(cancelImmediate); } timeout = 0; } } dispatchBYE("GNU ccRTP stack finishing."); Thread::exit();}#endifinline size_t takeInDataPacket(void){return TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::takeInDataPacket();}inline size_t dispatchBYE(const std::string &str){return TRTPSessionBase<RTPDataChannel,RTCPChannel,ServiceQueue>::dispatchBYE(str);}};/** * @typedef RTPSession * * Uses two pairs of sockets for RTP data and RTCP * transmission/reception. * * @short UDP/IPv4 RTP Session scheduled by one thread of execution. **/typedef SingleThreadRTPSession<> RTPSession;/** * @typedef RTPSocket * * Alias for RTPSession. **/typedef RTPSession RTPSocket;/** * @typedef SymmetricRTPSession * * Uses one pair of sockets, (1) for RTP data and (2) for RTCP * transmission/reception. * * @short Symmetric UDP/IPv4 RTP session scheduled by one thread of execution. **/typedef SingleThreadRTPSession<SymmetricRTPChannel, SymmetricRTPChannel> SymmetricRTPSession;#ifdef CCXX_IPV6/** * @class RTPSessionBaseIPV6 * * Generic RTP protocol stack for exchange of realtime data. This * stack uses the concept of packet send and receive queues to schedule * and buffer outgoing packets and to arrange or reorder incoming packets * as they arrive. * * This is a template class that allows customization of two aspects: * the underlying network and the control protocol. The RTPDataChannel * and RTCPChannel template parameters specify the socket types to * use. The ServiceQueue template parameter specify which packet queue * is used. * * RTPSessionBase objects do not have any threading policy, thus * allowing to customize this aspect in derived classes (see * SingleThreadRTPSession or RTPSessionPoolBase). * * @author David Sugar <dyfet@ostel.com> * @short RTP protocol stack based on Common C++. **/template <class RTPDataChannel = DualRTPUDPIPv6Channel, class RTCPChannel = DualRTPUDPIPv6Channel, class ServiceQueue = AVPQueue>class __EXPORT TRTPSessionBaseIPV6 : public ServiceQueue{public:/** * Builds a session waiting for packets in a host address. * * @param ia Network address this socket is to be bound. * @param dataPort Transport port the data socket is to be bound. * @param controlPort Transport port the control socket is to be bound. * @param membersSize Initial size of the membership table. * @param app Application this session is associated to. * */TRTPSessionBaseIPV6(const IPV6Host& ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication& app) : ServiceQueue(membersSize,app){ build(ia,dataPort,controlPort); } /** * Builds a session with the specified ssrc identifier for the * local source. * * @param ssrc SSRC identifier for the local source. * @param ia Network address this socket is to be bound. * @param dataPort Transport port the data socket is to be bound. * @param controlPort Transport port the control socket is to be bound. * @param membersSize Initial size of the membership table. * @param app Application this session is associated to. **/ TRTPSessionBaseIPV6(uint32 ssrc, const IPV6Host& ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication& app): ServiceQueue(ssrc,membersSize,app) { build(ia,dataPort,controlPort); } /** * Builds a session waiting for packets in a multicast address. * TODO: ssrc constructor for multicast! * * @param ia Multicast address this socket is to be bound. * @param dataPort Transport port the data socket is to be bound. * @param controlPort Transport port the control socket is to be bound. * @param membersSize Initial size of the membership table. * @param app Application this session is associated to. * @param iface Index (from 0 to n) of network interface to join to * multicast group. **/ TRTPSessionBaseIPV6(const IPV6Multicast& ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication& app, uint32 iface) : ServiceQueue(membersSize,app) { build(ia,dataPort,controlPort,iface); } /** * Builds a session waiting for packets in a multicast * address, with the specified ssrc identifier for the local * source. * * @param ssrc SSRC identifier for the local source. * @param ia Multicast address this socket is to be bound. * @param dataPort Transport port the data socket is to be bound. * @param controlPort Transport port the control socket is to be bound. * @param membersSize Initial size of the membership table. * @param app Application this session is associated to. * @param iface Index (from 0 to n) of network interface to join to * multicast group. **/ TRTPSessionBaseIPV6(uint32 ssrc, const IPV6Multicast& ia, tpport_t dataPort, tpport_t controlPort, uint32 membersSize, RTPApplication& app, uint32 iface) : ServiceQueue(ssrc,membersSize,app) { build(ia,dataPort,controlPort,iface); } virtual size_t dispatchBYE(const std::string &str) { return QueueRTCPManager::dispatchBYE(str); } inline virtual ~TRTPSessionBaseIPV6() { endSocket(); } inline RTPDataChannel *getDSO(void) {return dso;};protected: /** * @param timeout maximum timeout to wait, in microseconds */ inline bool isPendingData(microtimeout_t timeout) { return dso->isPendingRecv(timeout); } inline IPV6Host getDataSender(tpport_t *port = NULL) const { return dso->getSender(port); } inline size_t getNextDataPacketSize() const { return dso->getNextPacketSize(); } /** * Receive data from the data channel/socket. * * @param buffer Memory region to read to. * @param len Maximum number of octets to get. * @param na Source network address. * @param tp Source transport port. * @return Number of octets actually read. */ inline size_t recvData(unsigned char* buffer, size_t len, IPV6Host& na, tpport_t& tp) { na = dso->getSender(tp); return dso->recv(buffer, len); } inline void setDataPeer(const IPV6Host &host, tpport_t port) { dso->setPeer(host,port); } /** * @param buffer memory region to write from * @param len number of octets to write
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -