Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | // Copyright (C) 2001,2002,2004 Federico Montesino Pouzols <fedemp@altern.org>. |
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 queuebase.h |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 40 | * |
| 41 | * @short Base classes for RTP queues. |
| 42 | **/ |
| 43 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 44 | #ifndef CCXX_RTP_QUEUEBASE_H_ |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 45 | #define CCXX_RTP_QUEUEBASE_H_ |
| 46 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 47 | #include <commoncpp/pointer.h> |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 48 | #include <ccrtp/rtppkt.h> |
| 49 | #include <ccrtp/sources.h> |
| 50 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 51 | NAMESPACE_COMMONCPP |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 52 | |
| 53 | /** |
| 54 | * @defgroup queuebase Base classes for RTP queues. |
| 55 | * @{ |
| 56 | **/ |
| 57 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 58 | /** |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 59 | * @class AppDataUnit |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 60 | * @short Interface (envelope) to data received over RTP packets. |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 61 | * |
| 62 | * A class of objects representing data transmitted over RTP packets. |
| 63 | * Tipically, this object will apply to received data. Data blocks |
| 64 | * received via RTP connections as well as its related objects |
| 65 | * (source, etc), are accessed through the methods of this class. |
| 66 | * |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 67 | * @author Federico Montesino Pouzols <fedemp@altern.org> |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 68 | **/ |
| 69 | class __EXPORT AppDataUnit |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 70 | { |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 71 | public: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 72 | AppDataUnit(const IncomingRTPPkt& packet, const SyncSource& src); |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 73 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 74 | inline ~AppDataUnit() |
| 75 | { } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 76 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 77 | /** |
| 78 | * @param src the AppDataUnit object being copied |
| 79 | */ |
| 80 | AppDataUnit(const AppDataUnit& src); |
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 | * Assignment operator |
| 84 | * |
| 85 | * @param source the AppDataUnit object being assigned @return |
| 86 | * the result of the assignment |
| 87 | */ |
| 88 | AppDataUnit& |
| 89 | operator=(const AppDataUnit& source); |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 90 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 91 | /** |
| 92 | * @return type of this data |
| 93 | */ |
| 94 | inline PayloadType |
| 95 | getType() const |
| 96 | { return datablock->getPayloadType(); } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 97 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 98 | /** |
| 99 | * Get data as it is received in RTP packets (i.e. for |
| 100 | * multi-octet encodings, octets are in network |
| 101 | * order. |
| 102 | * |
| 103 | * @return Raw pointer to data block. |
| 104 | **/ |
| 105 | inline const uint8* const |
| 106 | getData() const |
| 107 | { return datablock->getPayload(); } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 108 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 109 | /** |
| 110 | * @return length of data in octets |
| 111 | **/ |
| 112 | size_t |
| 113 | getSize() const |
| 114 | { return datablock->getPayloadSize(); } |
| 115 | |
| 116 | /** |
| 117 | * @return Source that sent this data |
| 118 | */ |
| 119 | inline const SyncSource& |
| 120 | getSource() const |
| 121 | { return *source; } |
| 122 | |
| 123 | /** |
| 124 | * Is this data unit marked?. |
| 125 | * |
| 126 | * @return true if marked. |
| 127 | **/ |
| 128 | inline bool |
| 129 | isMarked() const |
| 130 | { return datablock->isMarked(); } |
| 131 | |
| 132 | /** |
| 133 | * Get data unit sequence number. |
| 134 | **/ |
| 135 | inline uint16 |
| 136 | getSeqNum() const |
| 137 | { return datablock->getSeqNum(); } |
| 138 | |
| 139 | /** |
| 140 | * Get the number of contributing sources in the CSRC list. |
| 141 | **/ |
| 142 | inline uint8 |
| 143 | getContributorsCount() const |
| 144 | { return (uint8)datablock->getCSRCsCount(); } |
| 145 | |
| 146 | /** |
| 147 | * Get the array of 32-bit CSRC identifiers. |
| 148 | * |
| 149 | * @return NULL if (getContributorsCount() == 0) |
| 150 | **/ |
| 151 | inline const uint32* |
| 152 | getContributorsID() const |
| 153 | { return datablock->getCSRCs(); } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 154 | |
| 155 | private: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 156 | Pointer<const IncomingRTPPkt> datablock; |
| 157 | const SyncSource* source; |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | /** |
| 161 | * @class RTPQueueBase |
| 162 | * |
| 163 | * A virtual base class for RTP queue hierarchies. |
| 164 | * |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 165 | * @author Federico Montesino Pouzols <fedemp@altern.org> |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 166 | **/ |
| 167 | class __EXPORT RTPQueueBase |
| 168 | { |
| 169 | public: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 170 | /** |
| 171 | * Set the payload format in use, for timing and payload type |
| 172 | * identification purposes. |
| 173 | * |
| 174 | * @param pf payload format to use from now on. |
| 175 | * @return whether the payload format has been successfully set. |
| 176 | **/ |
| 177 | inline bool |
| 178 | setPayloadFormat(const PayloadFormat& pf) |
| 179 | { |
| 180 | currentPayloadType = pf.getPayloadType(); |
| 181 | currentRTPClockRate = pf.getRTPClockRate(); |
| 182 | return true; |
| 183 | } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 184 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 185 | inline uint32 getLocalSSRC() const |
| 186 | { return localSSRC; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 187 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 188 | /** |
| 189 | * Get the clock rate in RTP clock units (for instance, 8000 |
| 190 | * units per second for PCMU, or 90000 units per second for |
| 191 | * MP2T). This value depends on what payload format has been |
| 192 | * selected using setPayloadFormat(). |
| 193 | * |
| 194 | * @return clock rate in RTP clock units. |
| 195 | **/ |
| 196 | inline uint32 getCurrentRTPClockRate() const |
| 197 | { return currentRTPClockRate; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 198 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 199 | inline PayloadType getCurrentPayloadType() const |
| 200 | { return currentPayloadType; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 201 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 202 | inline timeval getInitialTime() const |
| 203 | { return initialTime; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 204 | |
| 205 | protected: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 206 | /** |
| 207 | * @param ssrc If not null, the local SSRC identifier for this |
| 208 | * session. |
| 209 | **/ |
| 210 | RTPQueueBase(uint32 *ssrc = NULL); |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 211 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 212 | inline void setLocalSSRC(uint32 ssrc) |
| 213 | { localSSRC = ssrc; localSSRCNetwork = htonl(ssrc); } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 214 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 215 | inline uint32 getLocalSSRCNetwork() const |
| 216 | { return localSSRCNetwork; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 217 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 218 | virtual |
| 219 | ~RTPQueueBase() |
| 220 | { } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 221 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 222 | /** |
| 223 | * A plugin point for posting of BYE messages. |
| 224 | * |
| 225 | * @param - reason to leave the RTP session. |
| 226 | * @return number of octets sent. |
| 227 | **/ |
| 228 | inline virtual size_t |
| 229 | dispatchBYE(const std::string&) |
| 230 | { return 0; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 231 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 232 | inline virtual void |
| 233 | renewLocalSSRC() |
| 234 | { } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 235 | |
| 236 | private: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 237 | // local SSRC 32-bit identifier |
| 238 | uint32 localSSRC; |
| 239 | // SSRC in network byte order |
| 240 | uint32 localSSRCNetwork; |
| 241 | // RTP clock rate for the current payload type. |
| 242 | uint32 currentRTPClockRate; |
| 243 | // Current payload type set for outgoing packets and expected |
| 244 | // from incoming packets. |
| 245 | PayloadType currentPayloadType; |
| 246 | // when the queue is created |
| 247 | timeval initialTime; |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | /** |
| 251 | * @class OutgoingDataQueueBase |
| 252 | * |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 253 | * @author Federico Montesino Pouzols <fedemp@altern.org> |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 254 | **/ |
| 255 | class __EXPORT OutgoingDataQueueBase: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 256 | public virtual RTPQueueBase |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 257 | { |
| 258 | public: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 259 | inline size_t |
| 260 | getDefaultMaxSendSegmentSize() |
| 261 | { return defaultMaxSendSegmentSize;} |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 262 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 263 | /** |
| 264 | * Set maximum payload segment size before fragmenting sends. |
| 265 | * |
| 266 | * @param size Maximum payload size. |
| 267 | * @return Whether segment size was successfully set. |
| 268 | **/ |
| 269 | inline void |
| 270 | setMaxSendSegmentSize(size_t size) |
| 271 | { maxSendSegmentSize = size; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 272 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 273 | inline size_t |
| 274 | getMaxSendSegmentSize() |
| 275 | { return maxSendSegmentSize; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 276 | |
| 277 | protected: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 278 | OutgoingDataQueueBase(); |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 279 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 280 | inline virtual |
| 281 | ~OutgoingDataQueueBase() |
| 282 | { } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 283 | |
| 284 | private: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 285 | static const size_t defaultMaxSendSegmentSize; |
| 286 | // maximum packet size before fragmenting sends. |
| 287 | size_t maxSendSegmentSize; |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 288 | }; |
| 289 | |
| 290 | /** |
| 291 | * @class IncomingDataQueueBase |
| 292 | * |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 293 | * @author Federico Montesino Pouzols <fedemp@altern.org> |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 294 | **/ |
| 295 | class __EXPORT IncomingDataQueueBase: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 296 | public virtual RTPQueueBase |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 297 | { |
| 298 | public: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 299 | inline size_t getDefaultMaxRecvPacketSize() const |
| 300 | { return defaultMaxRecvPacketSize; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 301 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 302 | inline size_t |
| 303 | getMaxRecvPacketSize() const |
| 304 | { return maxRecvPacketSize; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 305 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 306 | /** |
| 307 | * @param maxsize maximum length of received RTP data packets, |
| 308 | * in octets. Defaults to the value returned by |
| 309 | * getDefaultMaxRecvPacketSize(). |
| 310 | * |
| 311 | * @note This method sets a filter for incoming |
| 312 | * packets. Setting higher values does not necessarily imply |
| 313 | * higher memory usage (this method does not set any buffer |
| 314 | * size). |
| 315 | **/ |
| 316 | inline void |
| 317 | setMaxRecvPacketSize(size_t maxsize) |
| 318 | { maxRecvPacketSize = maxsize; } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 319 | |
| 320 | protected: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 321 | IncomingDataQueueBase() |
| 322 | { setMaxRecvPacketSize(getDefaultMaxRecvPacketSize()); } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 323 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 324 | inline virtual |
| 325 | ~IncomingDataQueueBase() |
| 326 | { } |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 327 | |
| 328 | private: |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 329 | static const size_t defaultMaxRecvPacketSize; |
| 330 | // filter value for received packets length. |
| 331 | size_t maxRecvPacketSize; |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 332 | }; |
| 333 | |
| 334 | /** @}*/ // queuebase |
| 335 | |
Alexandre Lision | ddd731e | 2014-01-31 11:50:08 -0500 | [diff] [blame] | 336 | END_NAMESPACE |
Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 337 | |
| 338 | #endif //CCXX_RTP_QUEUEBASE_H_ |
| 339 | |
| 340 | /** EMACS ** |
| 341 | * Local variables: |
| 342 | * mode: c++ |
| 343 | * c-basic-offset: 8 |
| 344 | * End: |
| 345 | */ |