SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
rtppacketbuilder.h
Go to the documentation of this file.
1 /*
2 
3  This file is a part of JRTPLIB
4  Copyright (c) 1999-2017 Jori Liesenborgs
5 
6  Contact: jori.liesenborgs@gmail.com
7 
8  This library was developed at the Expertise Centre for Digital Media
9  (http://www.edm.uhasselt.be), a research center of the Hasselt University
10  (http://www.uhasselt.be). The library is based upon work done for
11  my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
12 
13  Permission is hereby granted, free of charge, to any person obtaining a
14  copy of this software and associated documentation files (the "Software"),
15  to deal in the Software without restriction, including without limitation
16  the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  and/or sell copies of the Software, and to permit persons to whom the
18  Software is furnished to do so, subject to the following conditions:
19 
20  The above copyright notice and this permission notice shall be included
21  in all copies or substantial portions of the Software.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29  IN THE SOFTWARE.
30 
31  */
32 
37 #ifndef RTPPACKETBUILDER_H
38 
39 #define RTPPACKETBUILDER_H
40 
41 #include "rtpconfig.h"
42 #include "rtperrors.h"
43 #include "rtpdefines.h"
44 #include "rtprandom.h"
45 #include "rtptimeutilities.h"
46 #include "rtptypes.h"
47 
48 #include "export.h"
49 
50 namespace qrtplib
51 {
52 
53 class RTPSources;
54 
59 {
60 public:
64  RTPPacketBuilder(RTPRandom &rtprand);
66 
68  int Init(unsigned int maxpacksize);
69 
71  void Destroy();
72 
75  {
76  if (!init)
77  return 0;
78  return numpackets;
79  }
80 
83  {
84  if (!init)
85  return 0;
86  return numpayloadbytes;
87  }
88 
90  int SetMaximumPacketSize(unsigned int maxpacksize);
91 
93  int AddCSRC(uint32_t csrc);
94 
96  int DeleteCSRC(uint32_t csrc);
97 
99  void ClearCSRCList();
100 
106  int BuildPacket(const void *data, unsigned int len);
107 
113  int BuildPacket(const void *data, unsigned int len, uint8_t pt, bool mark, uint32_t timestampinc);
114 
122  int BuildPacketEx(const void *data, unsigned int len, uint16_t hdrextID, const void *hdrextdata, unsigned int numhdrextwords);
123 
131  int BuildPacketEx(const void *data, unsigned int len, uint8_t pt, bool mark, uint32_t timestampinc, uint16_t hdrextID, const void *hdrextdata, unsigned int numhdrextwords);
132 
135  {
136  if (!init)
137  return 0;
138  return buffer;
139  }
140 
142  unsigned int GetPacketLength()
143  {
144  if (!init)
145  return 0;
146  return packetlength;
147  }
148 
150  int SetDefaultPayloadType(uint8_t pt);
151 
153  int SetDefaultMark(bool m);
154 
156  int SetDefaultTimestampIncrement(uint32_t timestampinc);
157 
164  int IncrementTimestamp(uint32_t inc);
165 
173  int IncrementTimestampDefault();
174 
179  uint32_t CreateNewSSRC();
180 
186  uint32_t CreateNewSSRC(RTPSources &sources);
187 
190  {
191  if (!init)
192  return 0;
193  return ssrc;
194  }
195 
198  {
199  if (!init)
200  return 0;
201  return timestamp;
202  }
203 
206  {
207  if (!init)
208  return 0;
209  return seqnr;
210  }
211 
217  {
218  if (!init)
219  return RTPTime(0, 0);
220  return lastwallclocktime;
221  }
222 
225  {
226  if (!init)
227  return 0;
228  return lastrtptimestamp;
229  }
230 
236  {
237  ssrc = s;
238  }
239 private:
240  int PrivateBuildPacket(
241  const void *data,
242  unsigned int len, uint8_t pt,
243  bool mark,
244  uint32_t timestampinc,
245  bool gotextension, uint16_t hdrextID = 0,
246  const void *hdrextdata = 0,
247  unsigned int numhdrextwords = 0);
248 
250  unsigned int maxpacksize;
252  unsigned int packetlength;
253 
256  bool init;
257 
261 
265 
266  bool deftsset, defptset, defmarkset;
267 
269  int numcsrcs;
270 
274 };
275 
277 {
278  if (!init)
280  defptset = true;
281  defaultpayloadtype = pt;
282  return 0;
283 }
284 
286 {
287  if (!init)
289  defmarkset = true;
290  defaultmark = m;
291  return 0;
292 }
293 
295 {
296  if (!init)
298  deftsset = true;
299  defaulttimestampinc = timestampinc;
300  return 0;
301 }
302 
304 {
305  if (!init)
307  timestamp += inc;
308  return 0;
309 }
310 
312 {
313  if (!init)
315  if (!deftsset)
317  timestamp += defaulttimestampinc;
318  return 0;
319 }
320 
321 } // end namespace
322 
323 #endif // RTPPACKETBUILDER_H
324 
uint16_t GetSequenceNumber() const
int IncrementTimestamp(uint32_t inc)
#define ERR_RTP_PACKBUILD_DEFAULTTSINCNOTSET
Definition: rtperrors.h:70
int SetDefaultTimestampIncrement(uint32_t timestampinc)
#define QRTPLIB_API
Definition: export.h:112
#define ERR_RTP_PACKBUILD_NOTINIT
Definition: rtperrors.h:72
unsigned int uint32_t
Definition: rtptypes_win.h:46
uint32_t GetTimestamp() const
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned short uint16_t
Definition: rtptypes_win.h:44
int SetDefaultPayloadType(uint8_t pt)
#define RTP_MAXCSRCS
Definition: rtpdefines.h:38
uint32_t GetPacketTimestamp() const