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 <commoncpp/pointer.h>
48 #include <ccrtp/rtppkt.h>
49 #include <ccrtp/sources.h>
50 
51 NAMESPACE_COMMONCPP
52 
69 class __EXPORT AppDataUnit
70 {
71 public:
72  AppDataUnit(const IncomingRTPPkt& packet, const SyncSource& src);
73 
74  inline ~AppDataUnit()
75  { }
76 
80  AppDataUnit(const AppDataUnit& src);
81 
89  operator=(const AppDataUnit& source);
90 
94  inline PayloadType
95  getType() const
96  { return datablock->getPayloadType(); }
97 
105  inline const uint8* const
106  getData() const
107  { return datablock->getPayload(); }
108 
112  size_t
113  getSize() const
114  { return datablock->getPayloadSize(); }
115 
119  inline const SyncSource&
120  getSource() const
121  { return *source; }
122 
128  inline bool
129  isMarked() const
130  { return datablock->isMarked(); }
131 
135  inline uint16
136  getSeqNum() const
137  { return datablock->getSeqNum(); }
138 
142  inline uint8
143  getContributorsCount() const
144  { return (uint8)datablock->getCSRCsCount(); }
145 
151  inline const uint32*
152  getContributorsID() const
153  { return datablock->getCSRCs(); }
154 
155 private:
156  Pointer<const IncomingRTPPkt> datablock;
157  const SyncSource* source;
158 };
159 
167 class __EXPORT RTPQueueBase
168 {
169 public:
177  inline bool
178  setPayloadFormat(const PayloadFormat& pf)
179  {
180  currentPayloadType = pf.getPayloadType();
181  currentRTPClockRate = pf.getRTPClockRate();
182  return true;
183  }
184 
185  inline uint32 getLocalSSRC() const
186  { return localSSRC; }
187 
196  inline uint32 getCurrentRTPClockRate() const
197  { return currentRTPClockRate; }
198 
199  inline PayloadType getCurrentPayloadType() const
200  { return currentPayloadType; }
201 
202  inline timeval getInitialTime() const
203  { return initialTime; }
204 
205 protected:
210  RTPQueueBase(uint32 *ssrc = NULL);
211 
212  inline void setLocalSSRC(uint32 ssrc)
213  { localSSRC = ssrc; localSSRCNetwork = htonl(ssrc); }
214 
215  inline uint32 getLocalSSRCNetwork() const
216  { return localSSRCNetwork; }
217 
218  virtual
220  { }
221 
228  inline virtual size_t
229  dispatchBYE(const std::string&)
230  { return 0; }
231 
232  inline virtual void
233  renewLocalSSRC()
234  { }
235 
236 private:
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;
248 };
249 
255 class __EXPORT OutgoingDataQueueBase:
256  public virtual RTPQueueBase
257 {
258 public:
259  inline size_t
260  getDefaultMaxSendSegmentSize()
261  { return defaultMaxSendSegmentSize;}
262 
269  inline void
270  setMaxSendSegmentSize(size_t size)
271  { maxSendSegmentSize = size; }
272 
273  inline size_t
274  getMaxSendSegmentSize()
275  { return maxSendSegmentSize; }
276 
277 protected:
279 
280  inline virtual
282  { }
283 
284 private:
285  static const size_t defaultMaxSendSegmentSize;
286  // maximum packet size before fragmenting sends.
287  size_t maxSendSegmentSize;
288 };
289 
295 class __EXPORT IncomingDataQueueBase:
296  public virtual RTPQueueBase
297 {
298 public:
299  inline size_t getDefaultMaxRecvPacketSize() const
300  { return defaultMaxRecvPacketSize; }
301 
302  inline size_t
303  getMaxRecvPacketSize() const
304  { return maxRecvPacketSize; }
305 
316  inline void
317  setMaxRecvPacketSize(size_t maxsize)
318  { maxRecvPacketSize = maxsize; }
319 
320 protected:
322  { setMaxRecvPacketSize(getDefaultMaxRecvPacketSize()); }
323 
324  inline virtual
326  { }
327 
328 private:
329  static const size_t defaultMaxRecvPacketSize;
330  // filter value for received packets length.
331  size_t maxRecvPacketSize;
332 };
333  // queuebase
335 
336 END_NAMESPACE
337 
338 #endif //CCXX_RTP_QUEUEBASE_H_
339