ccRTP
queuebase.h
Go to the documentation of this file.
1 // Copyright (C) 2001-2015 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 Lesser General Public License
14 // along with GNU ccRTP. If not, see <http://www.gnu.org/licenses/>.
15 //
16 // As a special exception, you may use this file as part of a free software
17 // library without restriction. Specifically, if other files instantiate
18 // templates or use macros or inline functions from this file, or you compile
19 // this file and link it with other files to produce an executable, this
20 // file does not by itself cause the resulting executable to be covered by
21 // the GNU General Public License. This exception does not however
22 // invalidate any other reasons why the executable file might be covered by
23 // the GNU General Public License.
24 //
25 // This exception applies only to the code released under the name GNU
26 // ccRTP. If you copy code from other releases into a copy of GNU
27 // ccRTP, as the General Public License permits, the exception does
28 // not apply to the code that you add in this way. To avoid misleading
29 // anyone as to the status of such modified files, you must delete
30 // this exception notice from them.
31 //
32 // If you write modifications of your own for GNU ccRTP, it is your choice
33 // whether to permit this exception to apply to your modifications.
34 // If you do not wish that, delete this exception notice.
35 //
36 
43 #ifndef CCXX_RTP_QUEUEBASE_H_
44 #define CCXX_RTP_QUEUEBASE_H_
45 
46 #include <commoncpp/pointer.h>
47 #include <ccrtp/rtppkt.h>
48 #include <ccrtp/sources.h>
49 
50 NAMESPACE_COMMONCPP
51 
68 class __EXPORT AppDataUnit
69 {
70 public:
71  AppDataUnit(const IncomingRTPPkt& packet, const SyncSource& src);
72 
73  inline ~AppDataUnit()
74  { }
75 
79  AppDataUnit(const AppDataUnit& src);
80 
88  operator=(const AppDataUnit& source);
89 
93  inline PayloadType
94  getType() const
95  { return datablock->getPayloadType(); }
96 
104  inline const uint8* const
105  getData() const
106  { return datablock->getPayload(); }
107 
111  size_t
112  getSize() const
113  { return datablock->getPayloadSize(); }
114 
118  inline const SyncSource&
119  getSource() const
120  { return *source; }
121 
127  inline bool
128  isMarked() const
129  { return datablock->isMarked(); }
130 
134  inline uint16
135  getSeqNum() const
136  { return datablock->getSeqNum(); }
137 
141  inline uint8
142  getContributorsCount() const
143  { return (uint8)datablock->getCSRCsCount(); }
144 
150  inline const uint32*
151  getContributorsID() const
152  { return datablock->getCSRCs(); }
153 
154 private:
155  Pointer<const IncomingRTPPkt> datablock;
156  const SyncSource* source;
157 };
158 
166 class __EXPORT RTPQueueBase
167 {
168 public:
176  inline bool
177  setPayloadFormat(const PayloadFormat& pf)
178  {
179  currentPayloadType = pf.getPayloadType();
180  currentRTPClockRate = pf.getRTPClockRate();
181  return true;
182  }
183 
184  inline uint32 getLocalSSRC() const
185  { return localSSRC; }
186 
195  inline uint32 getCurrentRTPClockRate() const
196  { return currentRTPClockRate; }
197 
198  inline PayloadType getCurrentPayloadType() const
199  { return currentPayloadType; }
200 
201  inline timeval getInitialTime() const
202  { return initialTime; }
203 
204 protected:
209  RTPQueueBase(uint32 *ssrc = NULL);
210 
211  inline void setLocalSSRC(uint32 ssrc)
212  { localSSRC = ssrc; localSSRCNetwork = htonl(ssrc); }
213 
214  inline uint32 getLocalSSRCNetwork() const
215  { return localSSRCNetwork; }
216 
217  virtual
219  { }
220 
227  inline virtual size_t
228  dispatchBYE(const std::string&)
229  { return 0; }
230 
231  inline virtual void
232  renewLocalSSRC()
233  { }
234 
235 private:
236  // local SSRC 32-bit identifier
237  uint32 localSSRC;
238  // SSRC in network byte order
239  uint32 localSSRCNetwork;
240  // RTP clock rate for the current payload type.
241  uint32 currentRTPClockRate;
242  // Current payload type set for outgoing packets and expected
243  // from incoming packets.
244  PayloadType currentPayloadType;
245  // when the queue is created
246  timeval initialTime;
247 };
248 
254 class __EXPORT OutgoingDataQueueBase:
255  public virtual RTPQueueBase
256 {
257 public:
258  inline size_t
259  getDefaultMaxSendSegmentSize()
260  { return defaultMaxSendSegmentSize;}
261 
268  inline void
269  setMaxSendSegmentSize(size_t size)
270  { maxSendSegmentSize = size; }
271 
272  inline size_t
273  getMaxSendSegmentSize()
274  { return maxSendSegmentSize; }
275 
276 protected:
278 
279  inline virtual
281  { }
282 
283 private:
284  static const size_t defaultMaxSendSegmentSize;
285  // maximum packet size before fragmenting sends.
286  size_t maxSendSegmentSize;
287 };
288 
294 class __EXPORT IncomingDataQueueBase:
295  public virtual RTPQueueBase
296 {
297 public:
298  inline size_t getDefaultMaxRecvPacketSize() const
299  { return defaultMaxRecvPacketSize; }
300 
301  inline size_t
302  getMaxRecvPacketSize() const
303  { return maxRecvPacketSize; }
304 
315  inline void
316  setMaxRecvPacketSize(size_t maxsize)
317  { maxRecvPacketSize = maxsize; }
318 
319 protected:
321  { setMaxRecvPacketSize(getDefaultMaxRecvPacketSize()); }
322 
323  inline virtual
325  { }
326 
327 private:
328  static const size_t defaultMaxRecvPacketSize;
329  // filter value for received packets length.
330  size_t maxRecvPacketSize;
331 };
332  // queuebase
334 
335 END_NAMESPACE
336 
337 #endif //CCXX_RTP_QUEUEBASE_H_
338