ccRTP
queuebase.h
Go to the documentation of this file.
1 // 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 
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
52 namespace ost {
53 #endif
54 
71 class __EXPORT AppDataUnit
72 {
73 public:
74  AppDataUnit(const IncomingRTPPkt& packet, const SyncSource& src);
75 
76  inline ~AppDataUnit()
77  { }
78 
82  AppDataUnit(const AppDataUnit& src);
83 
91  operator=(const AppDataUnit& source);
92 
96  inline PayloadType
97  getType() const
98  { return datablock->getPayloadType(); }
99 
107  inline const uint8* const
108  getData() const
109  { return datablock->getPayload(); }
110 
114  size_t
115  getSize() const
116  { return datablock->getPayloadSize(); }
117 
121  inline const SyncSource&
122  getSource() const
123  { return *source; }
124 
130  inline bool
131  isMarked() const
132  { return datablock->isMarked(); }
133 
137  inline uint16
138  getSeqNum() const
139  { return datablock->getSeqNum(); }
140 
144  inline uint8
145  getContributorsCount() const
146  { return (uint8)datablock->getCSRCsCount(); }
147 
153  inline const uint32*
154  getContributorsID() const
155  { return datablock->getCSRCs(); }
156 
157 private:
158  Pointer<const IncomingRTPPkt> datablock;
159  const SyncSource* source;
160 };
161 
169 class __EXPORT RTPQueueBase
170 {
171 public:
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 
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 
207 protected:
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
222  { }
223 
230  inline virtual size_t
231  dispatchBYE(const std::string&)
232  { return 0; }
233 
234  inline virtual void
235  renewLocalSSRC()
236  { }
237 
238 private:
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 
257 class __EXPORT OutgoingDataQueueBase:
258  public virtual RTPQueueBase
259 {
260 public:
261  inline size_t
262  getDefaultMaxSendSegmentSize()
263  { return defaultMaxSendSegmentSize;}
264 
271  inline void
272  setMaxSendSegmentSize(size_t size)
273  { maxSendSegmentSize = size; }
274 
275  inline size_t
276  getMaxSendSegmentSize()
277  { return maxSendSegmentSize; }
278 
279 protected:
281 
282  inline virtual
284  { }
285 
286 private:
287  static const size_t defaultMaxSendSegmentSize;
288  // maximum packet size before fragmenting sends.
289  size_t maxSendSegmentSize;
290 };
291 
297 class __EXPORT IncomingDataQueueBase:
298  public virtual RTPQueueBase
299 {
300 public:
301  inline size_t getDefaultMaxRecvPacketSize() const
302  { return defaultMaxRecvPacketSize; }
303 
304  inline size_t
305  getMaxRecvPacketSize() const
306  { return maxRecvPacketSize; }
307 
318  inline void
319  setMaxRecvPacketSize(size_t maxsize)
320  { maxRecvPacketSize = maxsize; }
321 
322 protected:
324  { setMaxRecvPacketSize(getDefaultMaxRecvPacketSize()); }
325 
326  inline virtual
328  { }
329 
330 private:
331  static const size_t defaultMaxRecvPacketSize;
332  // filter value for received packets length.
333  size_t maxRecvPacketSize;
334 };
335  // queuebase
337 
338 #ifdef CCXX_NAMESPACES
339 }
340 #endif
341 
342 #endif //CCXX_RTP_QUEUEBASE_H_
343