37 #ifndef CCRTP_CHANNEL_H_
38 #define CCRTP_CHANNEL_H_
41 #include <commoncpp/socket.h>
44 #include <sys/ioctl.h>
45 inline size_t ccioctl(
int so,
int request,
size_t& len)
46 {
return ioctl(so,request,&len); }
48 inline size_t ccioctl(SOCKET so,
int request,
size_t& len )
52 ::ioctlsocket(so,request,&l);
109 {
return UDPSocket::isPending(UDPSocket::pendingInput, timeout); }
111 inline InetHostAddress
113 {
return UDPSocket::getSender(&port); }
116 recv(
unsigned char* buffer,
size_t len)
117 {
return UDPSocket::receive(buffer, len); }
124 {
size_t len;
ccioctl(UDPSocket::so,FIONREAD,len);
return len; }
128 {
return UDPSocket::setMulticast(enable); }
131 join(
const InetMcastAddress& ia, uint32 iface)
132 {
return UDPSocket::join(ia,iface); }
135 drop(
const InetMcastAddress& ia)
140 {
return UDPSocket::setTimeToLive(ttl); }
151 {UDPSocket::setPeer((InetHostAddress&)ia, port);}
154 send(
const unsigned char*
const buffer,
size_t len)
155 {
return UDPSocket::send(buffer, len); }
158 {
return UDPSocket::so; }
163 { UDPSocket::endSocket(); }
186 template<
class BaseSocket>
201 {
return recvSocket->isPendingRecv(timeout); }
203 inline InetHostAddress
208 recv(
unsigned char* buffer,
size_t len)
217 { Socket::Error error =
recvSocket->setMulticast(enable);
218 if (error)
return error;
222 join(
const InetMcastAddress& ia, uint32 iface)
226 drop(
const InetMcastAddress& ia)
234 setPeer(
const InetAddress& host, tpport_t port)
238 send(
const unsigned char*
const buffer,
size_t len)
277 class RTPBaseUDPIPv6Socket :
private UDPSocket
283 RTPBaseUDPIPv6Socket(
const IPV6Address& ia, tpport_t port) :
287 inline ~RTPBaseUDPIPv6Socket()
292 {
return UDPSocket::isPending(UDPSocket::pendingInput, timeout); }
295 getSender(tpport_t& port)
const
296 {
return UDPSocket::getIPV6Sender(&port); }
299 recv(
unsigned char* buffer,
size_t len)
300 {
return UDPSocket::receive(buffer, len); }
306 getNextPacketSize()
const
307 {
size_t len;
ccioctl(UDPSocket::so,FIONREAD,len);
return len; }
310 setMulticast(
bool enable)
311 {
return UDPSocket::setMulticast(enable); }
314 join(
const IPV6Multicast& ia, uint32 iface)
315 {
return Socket::join(ia); }
318 drop(
const IPV6Multicast& ia)
322 setTimeToLive(
unsigned char ttl)
323 {
return UDPSocket::setTimeToLive(ttl); }
328 RTPBaseUDPIPv6Socket() :
333 setPeer(
const IPV6Host &ia, tpport_t port)
334 {UDPSocket::setPeer(ia, port);}
337 send(
const unsigned char*
const buffer,
size_t len)
338 {
return UDPSocket::send(buffer, len); }
340 inline SOCKET getRecvSocket()
const
341 {
return UDPSocket::so; }
346 { UDPSocket::endSocket(); }
369 template<
class BaseSocket>
370 class DualRTPChannelIPV6
373 DualRTPChannelIPV6(
const IPV6Host& ia, tpport_t port)
375 recvSocket =
new BaseSocket(ia,port);
376 sendSocket =
new BaseSocket;
379 inline ~DualRTPChannelIPV6()
380 {
delete sendSocket;
delete recvSocket; }
384 {
return recvSocket->isPendingRecv(timeout); }
387 getSender(tpport_t& port)
const
388 {
return recvSocket->getIPV6Sender(port); }
391 recv(
unsigned char* buffer,
size_t len)
392 {
return recvSocket->recv(buffer, len); }
395 getNextPacketSize()
const
396 {
return recvSocket->getNextPacketSize(); }
399 setMulticast(
bool enable)
400 { Socket::Error error = recvSocket->setMulticast(enable);
401 if (error)
return error;
402 return sendSocket->setMulticast(enable); }
405 join(
const IPV6Multicast& ia, uint32 iface)
406 {
return recvSocket->join(ia,iface); }
409 drop(
const IPV6Multicast& ia)
410 {
return recvSocket->drop(ia); }
413 setTimeToLive(
unsigned char ttl)
414 {
return sendSocket->setTimeToLive(ttl); }
417 setPeer(
const IPV6Host& host, tpport_t port)
418 { sendSocket->setPeer(host,port); }
421 send(
const unsigned char*
const buffer,
size_t len)
422 {
return sendSocket->send(buffer, len); }
424 inline SOCKET getRecvSocket()
const
425 {
return recvSocket->getRecvSocket(); }
430 { sendSocket->endSocket(); recvSocket->endSocket(); }
433 BaseSocket* sendSocket;
434 BaseSocket* recvSocket;
438 typedef DualRTPChannelIPV6<RTPBaseUDPIPv6Socket> DualRTPUDPIPv6Channel;
439 typedef RTPBaseUDPIPv6Socket SingleRTPChannelIPV6;
440 typedef SingleRTPChannelIPV6 SymmetricRTPChannelIPV6;
461 #endif //CCRTP_CHANNEL_H_
Socket::Error setTimeToLive(unsigned char ttl)
RTPBaseUDPIPv4Socket()
Constructor for transmitter.
Socket::Error drop(const InetMcastAddress &ia)
DualRTPChannel< RTPBaseUDPIPv4Socket > DualRTPUDPIPv4Channel
uint32 microtimeout_t
Time interval expressed in microseconds.
Socket::Error drop(const InetMcastAddress &ia)
SOCKET getRecvSocket() const
RTPBaseUDPIPv4Socket(const InetAddress &ia, tpport_t port)
Constructor for receiver.
SingleRTPChannel SymmetricRTPChannel
Actually, RTP with a single channel can be called 'Symmetric RTP'.
bool isPendingRecv(microtimeout_t timeout) const
SOCKET getRecvSocket() const
Socket::Error join(const InetMcastAddress &ia, uint32 iface)
Socket::Error setTimeToLive(unsigned char ttl)
Socket::Error setMulticast(bool enable)
A UDP/IPv4 socket class targetted at RTP stacks.
size_t getNextPacketSize() const
bool isPendingRecv(microtimeout_t timeout)
size_t getNextPacketSize() const
Get size of next datagram waiting to be read.
InetHostAddress getSender(tpport_t &port) const
RTPBaseUDPIPv4Socket SingleRTPChannel
May be used in applications where using the same socket for both sending and receiving is not a limit...
Socket::Error setMulticast(bool enable)
Socket::Error join(const InetMcastAddress &ia, uint32 iface)
size_t recv(unsigned char *buffer, size_t len)
DualRTPChannel(const InetAddress &ia, tpport_t port)
Base elements for RTP stacks: constants, types and global functions.
size_t send(const unsigned char *const buffer, size_t len)
void setPeer(const InetAddress &ia, tpport_t port)
size_t ccioctl(int so, int request, size_t &len)
void setPeer(const InetAddress &host, tpport_t port)
size_t recv(unsigned char *buffer, size_t len)
InetHostAddress getSender(tpport_t &port) const
size_t send(const unsigned char *const buffer, size_t len)