blob: a80482b445861996e9513876203f1dd65dc6b8da [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001// Copyright (C) 2001,2002,2004 Federico Montesino Pouzols <fedemp@altern.org>.
Alexandre Lisionddd731e2014-01-31 11:50:08 -05002//
Emeric Vigier2f625822012-08-06 11:09:52 -04003// 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 Lisionddd731e2014-01-31 11:50:08 -05007//
Emeric Vigier2f625822012-08-06 11:09:52 -04008// 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 Lisionddd731e2014-01-31 11:50:08 -050012//
Emeric Vigier2f625822012-08-06 11:09:52 -040013// You should have received a copy of the GNU General Public License
Alexandre Lisionddd731e2014-01-31 11:50:08 -050014// along with this program; if not, write to the Free Software
Emeric Vigier2f625822012-08-06 11:09:52 -040015// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Alexandre Lisionddd731e2014-01-31 11:50:08 -050016//
Emeric Vigier2f625822012-08-06 11:09:52 -040017// 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 Lisionddd731e2014-01-31 11:50:08 -050022// the GNU General Public License. This exception does not however
Emeric Vigier2f625822012-08-06 11:09:52 -040023// invalidate any other reasons why the executable file might be covered by
Alexandre Lisionddd731e2014-01-31 11:50:08 -050024// the GNU General Public License.
Emeric Vigier2f625822012-08-06 11:09:52 -040025//
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 Lisionddd731e2014-01-31 11:50:08 -050038/**
39 * @file queuebase.h
Emeric Vigier2f625822012-08-06 11:09:52 -040040 *
41 * @short Base classes for RTP queues.
42 **/
43
Alexandre Lisionddd731e2014-01-31 11:50:08 -050044#ifndef CCXX_RTP_QUEUEBASE_H_
Emeric Vigier2f625822012-08-06 11:09:52 -040045#define CCXX_RTP_QUEUEBASE_H_
46
Alexandre Lisionddd731e2014-01-31 11:50:08 -050047#include <commoncpp/pointer.h>
Emeric Vigier2f625822012-08-06 11:09:52 -040048#include <ccrtp/rtppkt.h>
49#include <ccrtp/sources.h>
50
Alexandre Lisionddd731e2014-01-31 11:50:08 -050051NAMESPACE_COMMONCPP
Emeric Vigier2f625822012-08-06 11:09:52 -040052
53/**
54 * @defgroup queuebase Base classes for RTP queues.
55 * @{
56 **/
57
Alexandre Lisionddd731e2014-01-31 11:50:08 -050058/**
Emeric Vigier2f625822012-08-06 11:09:52 -040059 * @class AppDataUnit
Alexandre Lisionddd731e2014-01-31 11:50:08 -050060 * @short Interface (envelope) to data received over RTP packets.
Emeric Vigier2f625822012-08-06 11:09:52 -040061 *
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 Lisionddd731e2014-01-31 11:50:08 -050067 * @author Federico Montesino Pouzols <fedemp@altern.org>
Emeric Vigier2f625822012-08-06 11:09:52 -040068 **/
69class __EXPORT AppDataUnit
Alexandre Lisionddd731e2014-01-31 11:50:08 -050070{
Emeric Vigier2f625822012-08-06 11:09:52 -040071public:
Alexandre Lisionddd731e2014-01-31 11:50:08 -050072 AppDataUnit(const IncomingRTPPkt& packet, const SyncSource& src);
Emeric Vigier2f625822012-08-06 11:09:52 -040073
Alexandre Lisionddd731e2014-01-31 11:50:08 -050074 inline ~AppDataUnit()
75 { }
Emeric Vigier2f625822012-08-06 11:09:52 -040076
Alexandre Lisionddd731e2014-01-31 11:50:08 -050077 /**
78 * @param src the AppDataUnit object being copied
79 */
80 AppDataUnit(const AppDataUnit& src);
Emeric Vigier2f625822012-08-06 11:09:52 -040081
Alexandre Lisionddd731e2014-01-31 11:50:08 -050082 /**
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 Vigier2f625822012-08-06 11:09:52 -040090
Alexandre Lisionddd731e2014-01-31 11:50:08 -050091 /**
92 * @return type of this data
93 */
94 inline PayloadType
95 getType() const
96 { return datablock->getPayloadType(); }
Emeric Vigier2f625822012-08-06 11:09:52 -040097
Alexandre Lisionddd731e2014-01-31 11:50:08 -050098 /**
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 Vigier2f625822012-08-06 11:09:52 -0400108
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500109 /**
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 Vigier2f625822012-08-06 11:09:52 -0400154
155private:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500156 Pointer<const IncomingRTPPkt> datablock;
157 const SyncSource* source;
Emeric Vigier2f625822012-08-06 11:09:52 -0400158};
159
160/**
161 * @class RTPQueueBase
162 *
163 * A virtual base class for RTP queue hierarchies.
164 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500165 * @author Federico Montesino Pouzols <fedemp@altern.org>
Emeric Vigier2f625822012-08-06 11:09:52 -0400166 **/
167class __EXPORT RTPQueueBase
168{
169public:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500170 /**
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 Vigier2f625822012-08-06 11:09:52 -0400184
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500185 inline uint32 getLocalSSRC() const
186 { return localSSRC; }
Emeric Vigier2f625822012-08-06 11:09:52 -0400187
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500188 /**
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 Vigier2f625822012-08-06 11:09:52 -0400198
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500199 inline PayloadType getCurrentPayloadType() const
200 { return currentPayloadType; }
Emeric Vigier2f625822012-08-06 11:09:52 -0400201
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500202 inline timeval getInitialTime() const
203 { return initialTime; }
Emeric Vigier2f625822012-08-06 11:09:52 -0400204
205protected:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500206 /**
207 * @param ssrc If not null, the local SSRC identifier for this
208 * session.
209 **/
210 RTPQueueBase(uint32 *ssrc = NULL);
Emeric Vigier2f625822012-08-06 11:09:52 -0400211
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500212 inline void setLocalSSRC(uint32 ssrc)
213 { localSSRC = ssrc; localSSRCNetwork = htonl(ssrc); }
Emeric Vigier2f625822012-08-06 11:09:52 -0400214
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500215 inline uint32 getLocalSSRCNetwork() const
216 { return localSSRCNetwork; }
Emeric Vigier2f625822012-08-06 11:09:52 -0400217
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500218 virtual
219 ~RTPQueueBase()
220 { }
Emeric Vigier2f625822012-08-06 11:09:52 -0400221
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500222 /**
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 Vigier2f625822012-08-06 11:09:52 -0400231
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500232 inline virtual void
233 renewLocalSSRC()
234 { }
Emeric Vigier2f625822012-08-06 11:09:52 -0400235
236private:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500237 // 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 Vigier2f625822012-08-06 11:09:52 -0400248};
249
250/**
251 * @class OutgoingDataQueueBase
252 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500253 * @author Federico Montesino Pouzols <fedemp@altern.org>
Emeric Vigier2f625822012-08-06 11:09:52 -0400254 **/
255class __EXPORT OutgoingDataQueueBase:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500256 public virtual RTPQueueBase
Emeric Vigier2f625822012-08-06 11:09:52 -0400257{
258public:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500259 inline size_t
260 getDefaultMaxSendSegmentSize()
261 { return defaultMaxSendSegmentSize;}
Emeric Vigier2f625822012-08-06 11:09:52 -0400262
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500263 /**
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 Vigier2f625822012-08-06 11:09:52 -0400272
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500273 inline size_t
274 getMaxSendSegmentSize()
275 { return maxSendSegmentSize; }
Emeric Vigier2f625822012-08-06 11:09:52 -0400276
277protected:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500278 OutgoingDataQueueBase();
Emeric Vigier2f625822012-08-06 11:09:52 -0400279
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500280 inline virtual
281 ~OutgoingDataQueueBase()
282 { }
Emeric Vigier2f625822012-08-06 11:09:52 -0400283
284private:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500285 static const size_t defaultMaxSendSegmentSize;
286 // maximum packet size before fragmenting sends.
287 size_t maxSendSegmentSize;
Emeric Vigier2f625822012-08-06 11:09:52 -0400288};
289
290/**
291 * @class IncomingDataQueueBase
292 *
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500293 * @author Federico Montesino Pouzols <fedemp@altern.org>
Emeric Vigier2f625822012-08-06 11:09:52 -0400294 **/
295class __EXPORT IncomingDataQueueBase:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500296 public virtual RTPQueueBase
Emeric Vigier2f625822012-08-06 11:09:52 -0400297{
298public:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500299 inline size_t getDefaultMaxRecvPacketSize() const
300 { return defaultMaxRecvPacketSize; }
Emeric Vigier2f625822012-08-06 11:09:52 -0400301
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500302 inline size_t
303 getMaxRecvPacketSize() const
304 { return maxRecvPacketSize; }
Emeric Vigier2f625822012-08-06 11:09:52 -0400305
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500306 /**
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 Vigier2f625822012-08-06 11:09:52 -0400319
320protected:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500321 IncomingDataQueueBase()
322 { setMaxRecvPacketSize(getDefaultMaxRecvPacketSize()); }
Emeric Vigier2f625822012-08-06 11:09:52 -0400323
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500324 inline virtual
325 ~IncomingDataQueueBase()
326 { }
Emeric Vigier2f625822012-08-06 11:09:52 -0400327
328private:
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500329 static const size_t defaultMaxRecvPacketSize;
330 // filter value for received packets length.
331 size_t maxRecvPacketSize;
Emeric Vigier2f625822012-08-06 11:09:52 -0400332};
333
334/** @}*/ // queuebase
335
Alexandre Lisionddd731e2014-01-31 11:50:08 -0500336END_NAMESPACE
Emeric Vigier2f625822012-08-06 11:09:52 -0400337
338#endif //CCXX_RTP_QUEUEBASE_H_
339
340/** EMACS **
341 * Local variables:
342 * mode: c++
343 * c-basic-offset: 8
344 * End:
345 */