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