Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | // Copyright (C) 1999-2003 Open Source Telecom Corporation. |
| 2 | // |
| 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. |
| 7 | // |
| 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. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with this program; if not, write to the Free Software |
| 15 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 16 | // |
| 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 |
| 22 | // the GNU General Public License. This exception does not however |
| 23 | // invalidate any other reasons why the executable file might be covered by |
| 24 | // the GNU General Public License. |
| 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 | |
| 38 | /** |
| 39 | * @file ext.h |
| 40 | * @short ccRTP Stack extensions. |
| 41 | **/ |
| 42 | |
| 43 | #ifndef CCXX_RTP_EXT_H |
| 44 | #define CCXX_RTP_EXT_H |
| 45 | |
| 46 | #ifndef CCXX_SOCKET_H_ |
| 47 | #include <cc++/socket.h> |
| 48 | #endif |
| 49 | |
| 50 | #include <ccrtp/ioqueue.h> |
| 51 | #include <ccrtp/channel.h> |
| 52 | |
| 53 | #ifdef CCXX_NAMESPACES |
| 54 | namespace ost { |
| 55 | #endif |
| 56 | |
| 57 | /** |
| 58 | * @defgroup rtpext ccRTP Extension classes |
| 59 | * @{ |
| 60 | **/ |
| 61 | |
| 62 | /** |
| 63 | * @class RTPDuplex rtp.h cc++/rtp.h |
| 64 | * |
| 65 | * A peer associated RTP socket pair for physically connected peer |
| 66 | * hosts. This has no RTCP and assumes the receiver is connected |
| 67 | * to a known transmitter, hence no "foreign" packets will arrive. |
| 68 | * |
| 69 | * @author David Sugar |
| 70 | * @short RTP peer host over UDP. |
| 71 | */ |
| 72 | class __EXPORT RTPDuplex : public RTPDataQueue, |
| 73 | protected UDPReceive, public UDPTransmit |
| 74 | { |
| 75 | public: |
| 76 | /** |
| 77 | * @param bind network address this socket is to be bound |
| 78 | * @param local transport port this socket is to be bound |
| 79 | * @param remote peer transpor port |
| 80 | */ |
| 81 | RTPDuplex(const InetAddress &bind, tpport_t local, tpport_t remote); |
| 82 | |
| 83 | /** |
| 84 | * |
| 85 | */ |
| 86 | virtual |
| 87 | ~RTPDuplex(); |
| 88 | |
| 89 | /** |
| 90 | * @param host peer address |
| 91 | * @param port peer port. If not specified, the same as the |
| 92 | * local is used |
| 93 | * @return socket status |
| 94 | */ |
| 95 | UDPTransmit::Error |
| 96 | connect(const InetHostAddress &host, tpport_t port = 0); |
| 97 | |
| 98 | protected: |
| 99 | |
| 100 | /** |
| 101 | * @param timeout how much time to wait for new data |
| 102 | * @return if there is some new data |
| 103 | */ |
| 104 | bool |
| 105 | isPendingData(microtimeout_t timeout) |
| 106 | { return isPendingReceive(timeout); } |
| 107 | |
| 108 | /** |
| 109 | * @param buffer pointer to data to be written |
| 110 | * @param len how many octets to write |
| 111 | * @return number of octets written |
| 112 | */ |
| 113 | size_t |
| 114 | sendData(const unsigned char *const buffer, size_t len) |
| 115 | { return UDPTransmit::transmit((const char *)buffer, len); } |
| 116 | |
| 117 | /** |
| 118 | * @param buffer where to store the retrieved data |
| 119 | * @param len how many octets to read |
| 120 | * @param na Source network address. |
| 121 | * @param tp Source transport port. |
| 122 | * @return number of octets read |
| 123 | */ |
| 124 | size_t |
| 125 | recvData(unsigned char *buffer, size_t len, |
| 126 | InetHostAddress& na, tpport_t& tp) |
| 127 | { /* na = UDPReceive::getPeer(&tp); FIX name ambiguity */ |
| 128 | return UDPReceive::receive(buffer, len); } |
| 129 | |
| 130 | /** |
| 131 | * @param - peer host network address. |
| 132 | * @param - peer host RTP data transport port. |
| 133 | **/ |
| 134 | inline void |
| 135 | setDataPeer(const InetAddress&, tpport_t) |
| 136 | { } |
| 137 | |
| 138 | /** |
| 139 | * @param - peer host network address. |
| 140 | * @param - peer host RTCP transport port. |
| 141 | **/ |
| 142 | inline void |
| 143 | setControlPeer(const InetAddress&, tpport_t) |
| 144 | { } |
| 145 | |
| 146 | inline size_t |
| 147 | getNextDataPacketSize() const |
| 148 | { |
| 149 | // the const cast is a trick only needed for cc++2 <= 1.0.10 |
| 150 | size_t len; ccioctl(const_cast<RTPDuplex*>(this)->UDPReceive::getReceiver(),FIONREAD,len); return len; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * @return the associated peer information |
| 155 | */ |
| 156 | SyncSource &getPeer(); |
| 157 | |
| 158 | private: |
| 159 | tpport_t dataBasePort; |
| 160 | }; |
| 161 | |
| 162 | /*@}*/ // rtpext |
| 163 | |
| 164 | #ifdef CCXX_NAMESPACES |
| 165 | } |
| 166 | #endif |
| 167 | |
| 168 | #endif //CCXX_RTP_EXT_H |
| 169 | |
| 170 | /** EMACS ** |
| 171 | * Local variables: |
| 172 | * mode: c++ |
| 173 | * c-basic-offset: 8 |
| 174 | * End: |
| 175 | */ |