Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | // Copyright (C) 1999-2003 Open Source Telecom Corporation. |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 2 | // |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 3 | // This program is free software; you can redistribute it and/or modify |
| 4 | // it under the terms of the GNU General Public License as published by |
| 5 | // the Free Software Foundation; either version 2 of the License, or |
| 6 | // (at your option) any later version. |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 7 | // |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 8 | // This program is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 12 | // |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 13 | // You should have received a copy of the GNU General Public License |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 14 | // along with this program; if not, write to the Free Software |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 15 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 16 | // |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 17 | // As a special exception, you may use this file as part of a free software |
| 18 | // library without restriction. Specifically, if other files instantiate |
| 19 | // templates or use macros or inline functions from this file, or you compile |
| 20 | // this file and link it with other files to produce an executable, this |
| 21 | // file does not by itself cause the resulting executable to be covered by |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 22 | // the GNU General Public License. This exception does not however |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 23 | // invalidate any other reasons why the executable file might be covered by |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 24 | // the GNU General Public License. |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 25 | // |
| 26 | // This exception applies only to the code released under the name GNU |
| 27 | // ccRTP. If you copy code from other releases into a copy of GNU |
| 28 | // ccRTP, as the General Public License permits, the exception does |
| 29 | // not apply to the code that you add in this way. To avoid misleading |
| 30 | // anyone as to the status of such modified files, you must delete |
| 31 | // this exception notice from them. |
| 32 | // |
| 33 | // If you write modifications of your own for GNU ccRTP, it is your choice |
| 34 | // whether to permit this exception to apply to your modifications. |
| 35 | // If you do not wish that, delete this exception notice. |
| 36 | // |
| 37 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 38 | /** |
| 39 | * @file ext.h |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 40 | * @short ccRTP Stack extensions. |
| 41 | **/ |
| 42 | |
| 43 | #ifndef CCXX_RTP_EXT_H |
| 44 | #define CCXX_RTP_EXT_H |
| 45 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 46 | #ifndef COMMONCPP_SOCKET_H_ |
| 47 | #include <commoncpp/socket.h> |
| 48 | #include <commoncpp/udp.h> |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 49 | #endif |
| 50 | |
| 51 | #include <ccrtp/ioqueue.h> |
| 52 | #include <ccrtp/channel.h> |
| 53 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 54 | NAMESPACE_COMMONCPP |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * @defgroup rtpext ccRTP Extension classes |
| 58 | * @{ |
| 59 | **/ |
| 60 | |
| 61 | /** |
| 62 | * @class RTPDuplex rtp.h cc++/rtp.h |
| 63 | * |
| 64 | * A peer associated RTP socket pair for physically connected peer |
| 65 | * hosts. This has no RTCP and assumes the receiver is connected |
| 66 | * to a known transmitter, hence no "foreign" packets will arrive. |
| 67 | * |
| 68 | * @author David Sugar |
| 69 | * @short RTP peer host over UDP. |
| 70 | */ |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 71 | class __EXPORT RTPDuplex : public RTPDataQueue, |
| 72 | protected UDPReceive, public UDPTransmit |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 73 | { |
| 74 | public: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 75 | /** |
| 76 | * @param bind network address this socket is to be bound |
| 77 | * @param local transport port this socket is to be bound |
| 78 | * @param remote peer transpor port |
| 79 | */ |
| 80 | RTPDuplex(const InetAddress &bind, tpport_t local, tpport_t remote); |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 81 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 82 | /** |
| 83 | * |
| 84 | */ |
| 85 | virtual |
| 86 | ~RTPDuplex(); |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 87 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 88 | /** |
| 89 | * @param host peer address |
| 90 | * @param port peer port. If not specified, the same as the |
| 91 | * local is used |
| 92 | * @return socket status |
| 93 | */ |
| 94 | UDPTransmit::Error |
| 95 | connect(const InetHostAddress &host, tpport_t port = 0); |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 96 | |
| 97 | protected: |
| 98 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 99 | /** |
| 100 | * @param timeout how much time to wait for new data |
| 101 | * @return if there is some new data |
| 102 | */ |
| 103 | bool |
| 104 | isPendingData(microtimeout_t timeout) |
| 105 | { return isPendingReceive(timeout); } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 106 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 107 | /** |
| 108 | * @param buffer pointer to data to be written |
| 109 | * @param len how many octets to write |
| 110 | * @return number of octets written |
| 111 | */ |
| 112 | size_t |
| 113 | sendData(const unsigned char *const buffer, size_t len) |
| 114 | { return UDPTransmit::transmit((const char *)buffer, len); } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 115 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 116 | /** |
| 117 | * @param buffer where to store the retrieved data |
| 118 | * @param len how many octets to read |
| 119 | * @param na Source network address. |
| 120 | * @param tp Source transport port. |
| 121 | * @return number of octets read |
| 122 | */ |
| 123 | size_t |
| 124 | recvData(unsigned char *buffer, size_t len, |
| 125 | InetHostAddress& na, tpport_t& tp) |
| 126 | { /* na = UDPReceive::getPeer(&tp); FIX name ambiguity */ |
| 127 | return UDPReceive::receive(buffer, len); } |
| 128 | |
| 129 | /** |
| 130 | * @param - peer host network address. |
| 131 | * @param - peer host RTP data transport port. |
| 132 | **/ |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 133 | inline void |
| 134 | setDataPeer(const InetAddress&, tpport_t) |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 135 | { } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 136 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 137 | /** |
| 138 | * @param - peer host network address. |
| 139 | * @param - peer host RTCP transport port. |
| 140 | **/ |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 141 | inline void |
| 142 | setControlPeer(const InetAddress&, tpport_t) |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 143 | { } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 144 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 145 | inline size_t |
| 146 | getNextDataPacketSize() const |
| 147 | { |
| 148 | // the const cast is a trick only needed for cc++2 <= 1.0.10 |
| 149 | size_t len; ccioctl(const_cast<RTPDuplex*>(this)->UDPReceive::getReceiver(),FIONREAD,len); return len; |
| 150 | } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 151 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 152 | /** |
| 153 | * @return the associated peer information |
| 154 | */ |
| 155 | SyncSource &getPeer(); |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 156 | |
| 157 | private: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 158 | tpport_t dataBasePort; |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | /*@}*/ // rtpext |
| 162 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 163 | END_NAMESPACE |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 164 | |
| 165 | #endif //CCXX_RTP_EXT_H |
| 166 | |
| 167 | /** EMACS ** |
| 168 | * Local variables: |
| 169 | * mode: c++ |
| 170 | * c-basic-offset: 8 |
| 171 | * End: |
| 172 | */ |