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.
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
qrtplib::RTCPCompoundPacketBuilder Class Reference

#include <rtcpcompoundpacketbuilder.h>

+ Inheritance diagram for qrtplib::RTCPCompoundPacketBuilder:
+ Collaboration diagram for qrtplib::RTCPCompoundPacketBuilder:

Classes

class  Buffer
 
class  Report
 
class  SDES
 
class  SDESSource
 

Public Member Functions

 RTCPCompoundPacketBuilder ()
 
 ~RTCPCompoundPacketBuilder ()
 
int InitBuild (std::size_t maxpacketsize)
 
int InitBuild (void *externalbuffer, std::size_t buffersize)
 
int StartSenderReport (uint32_t senderssrc, const RTPNTPTime &ntptimestamp, uint32_t rtptimestamp, uint32_t packetcount, uint32_t octetcount)
 
int StartReceiverReport (uint32_t senderssrc)
 
int AddReportBlock (uint32_t ssrc, uint8_t fractionlost, int32_t packetslost, uint32_t exthighestseq, uint32_t jitter, uint32_t lsr, uint32_t dlsr)
 
int AddSDESSource (uint32_t ssrc)
 
int AddSDESNormalItem (RTCPSDESPacket::ItemType t, const void *itemdata, uint8_t itemlength)
 
int AddSDESPrivateItem (const void *prefixdata, uint8_t prefixlength, const void *valuedata, uint8_t valuelength)
 
int AddBYEPacket (uint32_t *ssrcs, uint8_t numssrcs, const void *reasondata, uint8_t reasonlength)
 
int AddAPPPacket (uint8_t subtype, uint32_t ssrc, const uint8_t name[4], const void *appdata, std::size_t appdatalen)
 
int EndBuild ()
 
- Public Member Functions inherited from qrtplib::RTCPCompoundPacket
 RTCPCompoundPacket (RTPRawPacket &rawpack)
 
 RTCPCompoundPacket (uint8_t *packet, std::size_t len)
 
virtual ~RTCPCompoundPacket ()
 
int GetCreationError ()
 
uint8_tGetCompoundPacketData ()
 
std::size_t GetCompoundPacketLength ()
 
void GotoFirstPacket ()
 
RTCPPacketGetNextPacket ()
 

Private Member Functions

void ClearBuildBuffers ()
 

Private Attributes

RTPEndian m_endian
 
std::size_t maximumpacketsize
 
uint8_tbuffer
 
bool external
 
bool arebuilding
 
Report report
 
SDES sdes
 
std::list< Bufferbyepackets
 
std::size_t byesize
 
std::list< Bufferapppackets
 
std::size_t appsize
 

Additional Inherited Members

- Protected Member Functions inherited from qrtplib::RTCPCompoundPacket
 RTCPCompoundPacket ()
 
void ClearPacketList ()
 
int ParseData (uint8_t *packet, std::size_t len)
 
- Protected Attributes inherited from qrtplib::RTCPCompoundPacket
RTPEndian m_endian
 
int error
 
uint8_tcompoundpacket
 
std::size_t compoundpacketlength
 
std::list< RTCPPacket * > rtcppacklist
 
std::list< RTCPPacket * >::const_iterator rtcppackit
 

Detailed Description

This class can be used to construct an RTCP compound packet. The RTCPCompoundPacketBuilder class can be used to construct an RTCP compound packet. It inherits the member functions of RTCPCompoundPacket which can be used to access the information in the compound packet once it has been built successfully. The member functions described below return ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT if the action would cause the maximum allowed size to be exceeded.

Definition at line 62 of file rtcpcompoundpacketbuilder.h.

Constructor & Destructor Documentation

◆ RTCPCompoundPacketBuilder()

qrtplib::RTCPCompoundPacketBuilder::RTCPCompoundPacketBuilder ( )

◆ ~RTCPCompoundPacketBuilder()

qrtplib::RTCPCompoundPacketBuilder::~RTCPCompoundPacketBuilder ( )

Definition at line 54 of file rtcpcompoundpacketbuilder.cpp.

References ClearBuildBuffers(), qrtplib::RTCPCompoundPacket::compoundpacket, and external.

55 {
56  if (external)
57  compoundpacket = 0; // make sure RTCPCompoundPacket doesn't delete the external buffer
59 }
+ Here is the call graph for this function:

Member Function Documentation

◆ AddAPPPacket()

int qrtplib::RTCPCompoundPacketBuilder::AddAPPPacket ( uint8_t  subtype,
uint32_t  ssrc,
const uint8_t  name[4],
const void *  appdata,
std::size_t  appdatalen 
)

Adds the APP packet specified by the arguments to the compound packet. Adds the APP packet specified by the arguments to the compound packet. Note that appdatalen has to be a multiple of four.

Definition at line 397 of file rtcpcompoundpacketbuilder.cpp.

References apppackets, appsize, arebuilding, byesize, qrtplib::RTCPCommonHeader::count, ERR_RTP_RTCPCOMPPACKBUILDER_APPDATALENTOOBIG, ERR_RTP_RTCPCOMPPACKBUILDER_ILLEGALAPPDATALENGTH, ERR_RTP_RTCPCOMPPACKBUILDER_ILLEGALSUBTYPE, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT, qrtplib::RTCPCommonHeader::length, maximumpacketsize, qrtplib::RTCPCompoundPacketBuilder::Report::NeededBytes(), qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytes(), qrtplib::RTCPCommonHeader::packettype, qrtplib::RTCPCommonHeader::padding, report, RTP_RTCPTYPE_APP, sdes, and qrtplib::RTCPCommonHeader::version.

Referenced by qrtplib::RTPSession::SendRTCPAPPPacket().

398 {
399  if (!arebuilding)
401  if (subtype > 31)
403  if ((appdatalen % 4) != 0)
405 
406  std::size_t appdatawords = appdatalen / 4;
407 
408  if ((appdatawords + 2) > 65535)
410 
411  std::size_t packsize = sizeof(RTCPCommonHeader) + sizeof(uint32_t) * 2 + appdatalen;
412  std::size_t totalotherbytes = appsize + byesize + sdes.NeededBytes() + report.NeededBytes();
413 
414  if ((totalotherbytes + packsize) > maximumpacketsize)
416 
417  uint8_t *buf;
418 
419  buf = new uint8_t[packsize];
420 
421  RTCPCommonHeader *hdr = (RTCPCommonHeader *) buf;
422 
423  hdr->version = 2;
424  hdr->padding = 0;
425  hdr->count = subtype;
426 
427  hdr->length = qToBigEndian((uint16_t) (appdatawords + 2));
428  hdr->packettype = RTP_RTCPTYPE_APP;
429 
430  uint32_t *source = (uint32_t *) (buf + sizeof(RTCPCommonHeader));
431  *source = qToBigEndian(ssrc);
432 
433  buf[sizeof(RTCPCommonHeader) + sizeof(uint32_t) + 0] = name[0];
434  buf[sizeof(RTCPCommonHeader) + sizeof(uint32_t) + 1] = name[1];
435  buf[sizeof(RTCPCommonHeader) + sizeof(uint32_t) + 2] = name[2];
436  buf[sizeof(RTCPCommonHeader) + sizeof(uint32_t) + 3] = name[3];
437 
438  if (appdatalen > 0)
439  memcpy((buf + sizeof(RTCPCommonHeader) + sizeof(uint32_t) * 2), appdata, appdatalen);
440 
441  apppackets.push_back(Buffer(buf, packsize));
442  appsize += packsize;
443 
444  return 0;
445 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT
Definition: rtperrors.h:95
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned short uint16_t
Definition: rtptypes_win.h:44
#define ERR_RTP_RTCPCOMPPACKBUILDER_ILLEGALSUBTYPE
Definition: rtperrors.h:89
#define ERR_RTP_RTCPCOMPPACKBUILDER_ILLEGALAPPDATALENGTH
Definition: rtperrors.h:88
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
#define RTP_RTCPTYPE_APP
Definition: rtpdefines.h:54
#define ERR_RTP_RTCPCOMPPACKBUILDER_APPDATALENTOOBIG
Definition: rtperrors.h:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddBYEPacket()

int qrtplib::RTCPCompoundPacketBuilder::AddBYEPacket ( uint32_t ssrcs,
uint8_t  numssrcs,
const void *  reasondata,
uint8_t  reasonlength 
)

Adds a BYE packet to the compound packet. Adds a BYE packet to the compound packet. It will contain numssrcs source identifiers specified in ssrcs and will indicate as reason for leaving the string of length reasonlength containing data reasondata.

Definition at line 331 of file rtcpcompoundpacketbuilder.cpp.

References appsize, arebuilding, byepackets, byesize, qrtplib::RTCPCommonHeader::count, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT, ERR_RTP_RTCPCOMPPACKBUILDER_TOOMANYSSRCS, i, qrtplib::RTCPCommonHeader::length, maximumpacketsize, qrtplib::RTCPCompoundPacketBuilder::Report::NeededBytes(), qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytes(), qrtplib::RTCPCommonHeader::packettype, qrtplib::RTCPCommonHeader::padding, report, RTP_RTCPTYPE_BYE, sdes, and qrtplib::RTCPCommonHeader::version.

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket().

332 {
333  if (!arebuilding)
335 
336  if (numssrcs > 31)
338 
339  std::size_t packsize = sizeof(RTCPCommonHeader) + sizeof(uint32_t) * ((std::size_t) numssrcs);
340  std::size_t zerobytes = 0;
341 
342  if (reasonlength > 0)
343  {
344  packsize += 1; // 1 byte for the length;
345  packsize += (std::size_t) reasonlength;
346 
347  std::size_t r = (packsize & 0x03);
348  if (r != 0)
349  {
350  zerobytes = 4 - r;
351  packsize += zerobytes;
352  }
353  }
354 
355  std::size_t totalotherbytes = appsize + byesize + sdes.NeededBytes() + report.NeededBytes();
356 
357  if ((totalotherbytes + packsize) > maximumpacketsize)
359 
360  uint8_t *buf;
361  std::size_t numwords;
362 
363  buf = new uint8_t[packsize];
364 
365  RTCPCommonHeader *hdr = (RTCPCommonHeader *) buf;
366 
367  hdr->version = 2;
368  hdr->padding = 0;
369  hdr->count = numssrcs;
370 
371  numwords = packsize / sizeof(uint32_t);
372  hdr->length = qToBigEndian((uint16_t) (numwords - 1));
373  hdr->packettype = RTP_RTCPTYPE_BYE;
374 
375  uint32_t *sources = (uint32_t *) (buf + sizeof(RTCPCommonHeader));
376  uint8_t srcindex;
377 
378  for (srcindex = 0; srcindex < numssrcs; srcindex++)
379  sources[srcindex] = qToBigEndian(ssrcs[srcindex]);
380 
381  if (reasonlength != 0)
382  {
383  std::size_t offset = sizeof(RTCPCommonHeader) + ((std::size_t) numssrcs) * sizeof(uint32_t);
384 
385  buf[offset] = reasonlength;
386  memcpy((buf + offset + 1), reasondata, (std::size_t) reasonlength);
387  for (std::size_t i = 0; i < zerobytes; i++)
388  buf[packsize - 1 - i] = 0;
389  }
390 
391  byepackets.push_back(Buffer(buf, packsize));
392  byesize += packsize;
393 
394  return 0;
395 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT
Definition: rtperrors.h:95
#define RTP_RTCPTYPE_BYE
Definition: rtpdefines.h:53
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned short uint16_t
Definition: rtptypes_win.h:44
int32_t i
Definition: decimators.h:244
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
#define ERR_RTP_RTCPCOMPPACKBUILDER_TOOMANYSSRCS
Definition: rtperrors.h:97
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddReportBlock()

int qrtplib::RTCPCompoundPacketBuilder::AddReportBlock ( uint32_t  ssrc,
uint8_t  fractionlost,
int32_t  packetslost,
uint32_t  exthighestseq,
uint32_t  jitter,
uint32_t  lsr,
uint32_t  dlsr 
)

Adds the report block information specified by the function's arguments. Adds the report block information specified by the function's arguments. If more than 31 report blocks are added, the builder will automatically use a new RTCP receiver report packet.

Definition at line 181 of file rtcpcompoundpacketbuilder.cpp.

References appsize, arebuilding, byesize, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT, ERR_RTP_RTCPCOMPPACKBUILDER_REPORTNOTSTARTED, qrtplib::RTCPCompoundPacketBuilder::Report::headerlength, maximumpacketsize, qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytes(), qrtplib::RTCPCompoundPacketBuilder::Report::NeededBytesWithExtraReportBlock(), report, qrtplib::RTCPCompoundPacketBuilder::Report::reportblocks, sdes, and qrtplib::RTCPReceiverReport::ssrc.

Referenced by qrtplib::RTCPPacketBuilder::FillInReportBlocks().

182 {
183  if (!arebuilding)
185  if (report.headerlength == 0)
187 
188  std::size_t totalothersize = byesize + appsize + sdes.NeededBytes();
189  std::size_t reportsizewithextrablock = report.NeededBytesWithExtraReportBlock();
190 
191  if ((totalothersize + reportsizewithextrablock) > maximumpacketsize)
193 
194  uint8_t *buf = new uint8_t[sizeof(RTCPReceiverReport)];
195 
196  RTCPReceiverReport *rr = (RTCPReceiverReport *) buf;
197  uint32_t *packlost = (uint32_t *) &packetslost;
198  uint32_t packlost2 = (*packlost);
199 
200  rr->ssrc = qToBigEndian(ssrc);
201  rr->fractionlost = fractionlost;
202  rr->packetslost[2] = (uint8_t) (packlost2 & 0xFF);
203  rr->packetslost[1] = (uint8_t) ((packlost2 >> 8) & 0xFF);
204  rr->packetslost[0] = (uint8_t) ((packlost2 >> 16) & 0xFF);
205  rr->exthighseqnr = qToBigEndian(exthighestseq);
206  rr->jitter = qToBigEndian(jitter);
207  rr->lsr = qToBigEndian(lsr);
208  rr->dlsr = qToBigEndian(dlsr);
209 
210  report.reportblocks.push_back(Buffer(buf, sizeof(RTCPReceiverReport)));
211  return 0;
212 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT
Definition: rtperrors.h:95
#define ERR_RTP_RTCPCOMPPACKBUILDER_REPORTNOTSTARTED
Definition: rtperrors.h:96
unsigned int uint32_t
Definition: rtptypes_win.h:46
unsigned char uint8_t
Definition: rtptypes_win.h:42
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddSDESNormalItem()

int qrtplib::RTCPCompoundPacketBuilder::AddSDESNormalItem ( RTCPSDESPacket::ItemType  t,
const void *  itemdata,
uint8_t  itemlength 
)

Adds a normal (non-private) SDES item of type t to the current SDES chunk. Adds a normal (non-private) SDES item of type t to the current SDES chunk. The item's value will have length itemlength and will contain the data itemdata.

Definition at line 232 of file rtcpcompoundpacketbuilder.cpp.

References qrtplib::RTCPCompoundPacketBuilder::SDES::AddItem(), appsize, arebuilding, byesize, qrtplib::RTCPSDESPacket::CNAME, qrtplib::RTCPSDESPacket::EMAIL, ERR_RTP_RTCPCOMPPACKBUILDER_INVALIDITEMTYPE, ERR_RTP_RTCPCOMPPACKBUILDER_NOCURRENTSOURCE, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT, qrtplib::RTCPSDESHeader::length, qrtplib::RTCPSDESPacket::LOC, maximumpacketsize, qrtplib::RTCPSDESPacket::NAME, qrtplib::RTCPCompoundPacketBuilder::Report::NeededBytes(), qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytesWithExtraItem(), qrtplib::RTCPSDESPacket::NOTE, qrtplib::RTCPSDESPacket::PHONE, report, RTCP_SDES_ID_CNAME, RTCP_SDES_ID_EMAIL, RTCP_SDES_ID_LOCATION, RTCP_SDES_ID_NAME, RTCP_SDES_ID_NOTE, RTCP_SDES_ID_PHONE, RTCP_SDES_ID_TOOL, sdes, qrtplib::RTCPSDESHeader::sdesid, qrtplib::RTCPCompoundPacketBuilder::SDES::sdessources, and qrtplib::RTCPSDESPacket::TOOL.

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket(), qrtplib::RTCPPacketBuilder::BuildNextPacket(), qrtplib::RTCPPacketBuilder::FillInSDES(), and qrtplib::RTPSession::SendRTCPAPPPacket().

233 {
234  if (!arebuilding)
236  if (sdes.sdessources.empty())
238 
239  uint8_t itemid;
240 
241  switch (t)
242  {
244  itemid = RTCP_SDES_ID_CNAME;
245  break;
247  itemid = RTCP_SDES_ID_NAME;
248  break;
250  itemid = RTCP_SDES_ID_EMAIL;
251  break;
253  itemid = RTCP_SDES_ID_PHONE;
254  break;
255  case RTCPSDESPacket::LOC:
256  itemid = RTCP_SDES_ID_LOCATION;
257  break;
259  itemid = RTCP_SDES_ID_TOOL;
260  break;
262  itemid = RTCP_SDES_ID_NOTE;
263  break;
264  default:
266  }
267 
268  std::size_t totalotherbytes = byesize + appsize + report.NeededBytes();
269  std::size_t sdessizewithextraitem = sdes.NeededBytesWithExtraItem(itemlength);
270 
271  if ((sdessizewithextraitem + totalotherbytes) > maximumpacketsize)
273 
274  uint8_t *buf;
275  std::size_t len;
276 
277  buf = new uint8_t[sizeof(RTCPSDESHeader) + (std::size_t) itemlength];
278  len = sizeof(RTCPSDESHeader) + (std::size_t) itemlength;
279 
280  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (buf);
281 
282  sdeshdr->sdesid = itemid;
283  sdeshdr->length = itemlength;
284  if (itemlength != 0)
285  memcpy((buf + sizeof(RTCPSDESHeader)), itemdata, (std::size_t) itemlength);
286 
287  sdes.AddItem(buf, len);
288  return 0;
289 }
#define RTCP_SDES_ID_EMAIL
Definition: rtpdefines.h:58
#define RTCP_SDES_ID_LOCATION
Definition: rtpdefines.h:60
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT
Definition: rtperrors.h:95
#define RTCP_SDES_ID_NOTE
Definition: rtpdefines.h:62
std::size_t NeededBytesWithExtraItem(uint8_t itemdatalength)
unsigned char uint8_t
Definition: rtptypes_win.h:42
#define ERR_RTP_RTCPCOMPPACKBUILDER_INVALIDITEMTYPE
Definition: rtperrors.h:90
#define RTCP_SDES_ID_TOOL
Definition: rtpdefines.h:61
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
#define RTCP_SDES_ID_CNAME
Definition: rtpdefines.h:56
int AddItem(uint8_t *buf, std::size_t len)
#define RTCP_SDES_ID_NAME
Definition: rtpdefines.h:57
#define RTCP_SDES_ID_PHONE
Definition: rtpdefines.h:59
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOCURRENTSOURCE
Definition: rtperrors.h:92
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ AddSDESPrivateItem()

int qrtplib::RTCPCompoundPacketBuilder::AddSDESPrivateItem ( const void *  prefixdata,
uint8_t  prefixlength,
const void *  valuedata,
uint8_t  valuelength 
)

Adds an SDES PRIV item described by the function's arguments to the current SDES chunk.

Definition at line 292 of file rtcpcompoundpacketbuilder.cpp.

References qrtplib::RTCPCompoundPacketBuilder::SDES::AddItem(), appsize, arebuilding, byesize, ERR_RTP_RTCPCOMPPACKBUILDER_NOCURRENTSOURCE, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT, ERR_RTP_RTCPCOMPPACKBUILDER_TOTALITEMLENGTHTOOBIG, qrtplib::RTCPSDESHeader::length, maximumpacketsize, qrtplib::RTCPCompoundPacketBuilder::Report::NeededBytes(), qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytesWithExtraItem(), report, RTCP_SDES_ID_PRIVATE, sdes, qrtplib::RTCPSDESHeader::sdesid, and qrtplib::RTCPCompoundPacketBuilder::SDES::sdessources.

293 {
294  if (!arebuilding)
296  if (sdes.sdessources.empty())
298 
299  std::size_t itemlength = ((std::size_t) prefixlength) + 1 + ((std::size_t) valuelength);
300  if (itemlength > 255)
302 
303  std::size_t totalotherbytes = byesize + appsize + report.NeededBytes();
304  std::size_t sdessizewithextraitem = sdes.NeededBytesWithExtraItem(itemlength);
305 
306  if ((sdessizewithextraitem + totalotherbytes) > maximumpacketsize)
308 
309  uint8_t *buf;
310  std::size_t len;
311 
312  buf = new uint8_t[sizeof(RTCPSDESHeader) + itemlength];
313  len = sizeof(RTCPSDESHeader) + (std::size_t) itemlength;
314 
315  RTCPSDESHeader *sdeshdr = (RTCPSDESHeader *) (buf);
316 
317  sdeshdr->sdesid = RTCP_SDES_ID_PRIVATE;
318  sdeshdr->length = itemlength;
319 
320  buf[sizeof(RTCPSDESHeader)] = prefixlength;
321  if (prefixlength != 0)
322  memcpy((buf + sizeof(RTCPSDESHeader) + 1), prefixdata, (std::size_t) prefixlength);
323  if (valuelength != 0)
324  memcpy((buf + sizeof(RTCPSDESHeader) + 1 + (std::size_t) prefixlength), valuedata, (std::size_t) valuelength);
325 
326  sdes.AddItem(buf, len);
327  return 0;
328 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT
Definition: rtperrors.h:95
std::size_t NeededBytesWithExtraItem(uint8_t itemdatalength)
unsigned char uint8_t
Definition: rtptypes_win.h:42
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
int AddItem(uint8_t *buf, std::size_t len)
#define ERR_RTP_RTCPCOMPPACKBUILDER_TOTALITEMLENGTHTOOBIG
Definition: rtperrors.h:98
#define RTCP_SDES_ID_PRIVATE
Definition: rtpdefines.h:63
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOCURRENTSOURCE
Definition: rtperrors.h:92
+ Here is the call graph for this function:

◆ AddSDESSource()

int qrtplib::RTCPCompoundPacketBuilder::AddSDESSource ( uint32_t  ssrc)

Starts an SDES chunk for participant ssrc.

Definition at line 214 of file rtcpcompoundpacketbuilder.cpp.

References qrtplib::RTCPCompoundPacketBuilder::SDES::AddSSRC(), appsize, arebuilding, byesize, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT, maximumpacketsize, qrtplib::RTCPCompoundPacketBuilder::Report::NeededBytes(), qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytesWithExtraSource(), report, and sdes.

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket(), qrtplib::RTCPPacketBuilder::BuildNextPacket(), and qrtplib::RTPSession::SendRTCPAPPPacket().

215 {
216  if (!arebuilding)
218 
219  std::size_t totalotherbytes = byesize + appsize + report.NeededBytes();
220  std::size_t sdessizewithextrasource = sdes.NeededBytesWithExtraSource();
221 
222  if ((totalotherbytes + sdessizewithextrasource) > maximumpacketsize)
224 
225  int status;
226 
227  if ((status = sdes.AddSSRC(ssrc)) < 0)
228  return status;
229  return 0;
230 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT
Definition: rtperrors.h:95
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ClearBuildBuffers()

void qrtplib::RTCPCompoundPacketBuilder::ClearBuildBuffers ( )
private

Definition at line 61 of file rtcpcompoundpacketbuilder.cpp.

References apppackets, appsize, byepackets, byesize, qrtplib::RTCPCompoundPacketBuilder::Report::Clear(), qrtplib::RTCPCompoundPacketBuilder::SDES::Clear(), report, and sdes.

Referenced by EndBuild(), and ~RTCPCompoundPacketBuilder().

62 {
63  report.Clear();
64  sdes.Clear();
65 
66  std::list<Buffer>::const_iterator it;
67  for (it = byepackets.begin(); it != byepackets.end(); it++)
68  {
69  if ((*it).packetdata)
70  delete[] (*it).packetdata;
71  }
72  for (it = apppackets.begin(); it != apppackets.end(); it++)
73  {
74  if ((*it).packetdata)
75  delete[] (*it).packetdata;
76  }
77  byepackets.clear();
78  apppackets.clear();
79  byesize = 0;
80  appsize = 0;
81 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ EndBuild()

int qrtplib::RTCPCompoundPacketBuilder::EndBuild ( )

Finishes building the compound packet. Finishes building the compound packet. If successful, the RTCPCompoundPacket member functions can be used to access the RTCP packet data.

Definition at line 447 of file rtcpcompoundpacketbuilder.cpp.

References apppackets, appsize, arebuilding, buffer, byepackets, byesize, ClearBuildBuffers(), qrtplib::RTCPCompoundPacket::compoundpacket, qrtplib::RTCPCompoundPacket::compoundpacketlength, qrtplib::RTCPCommonHeader::count, ERR_RTP_RTCPCOMPPACKBUILDER_NOREPORTPRESENT, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, external, qrtplib::RTCPCompoundPacketBuilder::Report::headerdata, qrtplib::RTCPCompoundPacketBuilder::Report::headerlength, i, qrtplib::RTCPCompoundPacketBuilder::Report::isSR, qrtplib::RTCPCommonHeader::length, qrtplib::RTCPCompoundPacketBuilder::Report::NeededBytes(), qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytes(), qrtplib::RTCPCommonHeader::packettype, qrtplib::RTCPCommonHeader::padding, report, qrtplib::RTCPCompoundPacketBuilder::Report::reportblocks, qrtplib::RTCPCompoundPacket::rtcppacklist, RTP_RTCPTYPE_RR, RTP_RTCPTYPE_SDES, RTP_RTCPTYPE_SR, sdes, qrtplib::RTCPCompoundPacketBuilder::SDES::sdessources, and qrtplib::RTCPCommonHeader::version.

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket(), qrtplib::RTCPPacketBuilder::BuildNextPacket(), and qrtplib::RTPSession::SendRTCPAPPPacket().

448 {
449  if (!arebuilding)
451  if (report.headerlength == 0)
453 
454  uint8_t *buf;
455  std::size_t len;
456 
458 
459  if (!external)
460  {
461  buf = new uint8_t[len];
462  }
463  else
464  buf = buffer;
465 
466  uint8_t *curbuf = buf;
467  RTCPPacket *p;
468 
469  // first, we'll add all report info
470 
471  {
472  bool firstpacket = true;
473  bool done = false;
474  std::list<Buffer>::const_iterator it = report.reportblocks.begin();
475  do
476  {
477  RTCPCommonHeader *hdr = (RTCPCommonHeader *) curbuf;
478  std::size_t offset;
479 
480  hdr->version = 2;
481  hdr->padding = 0;
482 
483  if (firstpacket && report.isSR)
484  {
485  hdr->packettype = RTP_RTCPTYPE_SR;
486  memcpy((curbuf + sizeof(RTCPCommonHeader)), report.headerdata, report.headerlength);
487  offset = sizeof(RTCPCommonHeader) + report.headerlength;
488  }
489  else
490  {
491  hdr->packettype = RTP_RTCPTYPE_RR;
492  memcpy((curbuf + sizeof(RTCPCommonHeader)), report.headerdata, sizeof(uint32_t));
493  offset = sizeof(RTCPCommonHeader) + sizeof(uint32_t);
494  }
495  firstpacket = false;
496 
497  uint8_t count = 0;
498 
499  while (it != report.reportblocks.end() && count < 31)
500  {
501  memcpy(curbuf + offset, (*it).packetdata, (*it).packetlength);
502  offset += (*it).packetlength;
503  count++;
504  it++;
505  }
506 
507  std::size_t numwords = offset / sizeof(uint32_t);
508 
509  hdr->length = qToBigEndian((uint16_t) (numwords - 1));
510  hdr->count = count;
511 
512  // add entry in parent's list
513  if (hdr->packettype == RTP_RTCPTYPE_SR)
514  p = new RTCPSRPacket(curbuf, offset);
515  else
516  p = new RTCPRRPacket(curbuf, offset);
517  rtcppacklist.push_back(p);
518 
519  curbuf += offset;
520  if (it == report.reportblocks.end())
521  done = true;
522  } while (!done);
523  }
524 
525  // then, we'll add the sdes info
526 
527  if (!sdes.sdessources.empty())
528  {
529  bool done = false;
530  std::list<SDESSource *>::const_iterator sourceit = sdes.sdessources.begin();
531 
532  do
533  {
534  RTCPCommonHeader *hdr = (RTCPCommonHeader *) curbuf;
535  std::size_t offset = sizeof(RTCPCommonHeader);
536 
537  hdr->version = 2;
538  hdr->padding = 0;
539  hdr->packettype = RTP_RTCPTYPE_SDES;
540 
541  uint8_t sourcecount = 0;
542 
543  while (sourceit != sdes.sdessources.end() && sourcecount < 31)
544  {
545  uint32_t *ssrc = (uint32_t *) (curbuf + offset);
546  *ssrc = qToBigEndian((*sourceit)->ssrc);
547  offset += sizeof(uint32_t);
548 
549  std::list<Buffer>::const_iterator itemit, itemend;
550 
551  itemit = (*sourceit)->items.begin();
552  itemend = (*sourceit)->items.end();
553  while (itemit != itemend)
554  {
555  memcpy(curbuf + offset, (*itemit).packetdata, (*itemit).packetlength);
556  offset += (*itemit).packetlength;
557  itemit++;
558  }
559 
560  curbuf[offset] = 0; // end of item list;
561  offset++;
562 
563  std::size_t r = offset & 0x03;
564  if (r != 0) // align to 32 bit boundary
565  {
566  std::size_t num = 4 - r;
567  std::size_t i;
568 
569  for (i = 0; i < num; i++)
570  curbuf[offset + i] = 0;
571  offset += num;
572  }
573 
574  sourceit++;
575  sourcecount++;
576  }
577 
578  std::size_t numwords = offset / 4;
579 
580  hdr->count = sourcecount;
581  hdr->length = qToBigEndian((uint16_t) (numwords - 1));
582 
583  p = new RTCPSDESPacket(curbuf, offset);
584  rtcppacklist.push_back(p);
585 
586  curbuf += offset;
587  if (sourceit == sdes.sdessources.end())
588  done = true;
589  } while (!done);
590  }
591 
592  // adding the app data
593 
594  {
595  std::list<Buffer>::const_iterator it;
596 
597  for (it = apppackets.begin(); it != apppackets.end(); it++)
598  {
599  memcpy(curbuf, (*it).packetdata, (*it).packetlength);
600 
601  p = new RTCPAPPPacket(curbuf, (*it).packetlength);
602  rtcppacklist.push_back(p);
603 
604  curbuf += (*it).packetlength;
605  }
606  }
607 
608  // adding bye packets
609 
610  {
611  std::list<Buffer>::const_iterator it;
612 
613  for (it = byepackets.begin(); it != byepackets.end(); it++)
614  {
615  memcpy(curbuf, (*it).packetdata, (*it).packetlength);
616 
617  p = new RTCPBYEPacket(curbuf, (*it).packetlength);
618  rtcppacklist.push_back(p);
619 
620  curbuf += (*it).packetlength;
621  }
622  }
623 
624  compoundpacket = buf;
625  compoundpacketlength = len;
626  arebuilding = false;
628  return 0;
629 }
unsigned int uint32_t
Definition: rtptypes_win.h:46
#define RTP_RTCPTYPE_RR
Definition: rtpdefines.h:51
std::list< RTCPPacket * > rtcppacklist
unsigned char uint8_t
Definition: rtptypes_win.h:42
unsigned short uint16_t
Definition: rtptypes_win.h:44
int32_t i
Definition: decimators.h:244
#define RTP_RTCPTYPE_SR
Definition: rtpdefines.h:50
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOREPORTPRESENT
Definition: rtperrors.h:93
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
#define RTP_RTCPTYPE_SDES
Definition: rtpdefines.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InitBuild() [1/2]

int qrtplib::RTCPCompoundPacketBuilder::InitBuild ( std::size_t  maxpacketsize)

Starts building an RTCP compound packet with maximum size maxpacketsize. Starts building an RTCP compound packet with maximum size maxpacketsize. New memory will be allocated to store the packet.

Definition at line 83 of file rtcpcompoundpacketbuilder.cpp.

References appsize, arebuilding, buffer, byesize, qrtplib::RTCPCompoundPacket::compoundpacket, ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYBUILT, ERR_RTP_RTCPCOMPPACKBUILDER_MAXPACKETSIZETOOSMALL, external, maximumpacketsize, and RTP_MINPACKETSIZE.

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket(), qrtplib::RTCPPacketBuilder::BuildNextPacket(), and qrtplib::RTPSession::SendRTCPAPPPacket().

84 {
85  if (arebuilding)
87  if (compoundpacket)
89 
90  if (maxpacketsize < RTP_MINPACKETSIZE)
92 
93  maximumpacketsize = maxpacketsize;
94  buffer = 0;
95  external = false;
96  byesize = 0;
97  appsize = 0;
98 
99  arebuilding = true;
100  return 0;
101 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYBUILT
Definition: rtperrors.h:84
#define ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYBUILDING
Definition: rtperrors.h:83
#define RTP_MINPACKETSIZE
Definition: rtpdefines.h:39
#define ERR_RTP_RTCPCOMPPACKBUILDER_MAXPACKETSIZETOOSMALL
Definition: rtperrors.h:91
+ Here is the caller graph for this function:

◆ InitBuild() [2/2]

int qrtplib::RTCPCompoundPacketBuilder::InitBuild ( void *  externalbuffer,
std::size_t  buffersize 
)

Starts building a RTCP compound packet. Starts building a RTCP compound packet. Data will be stored in externalbuffer which can contain buffersize bytes.

Definition at line 103 of file rtcpcompoundpacketbuilder.cpp.

References appsize, arebuilding, buffer, byesize, qrtplib::RTCPCompoundPacket::compoundpacket, ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYBUILT, ERR_RTP_RTCPCOMPPACKBUILDER_BUFFERSIZETOOSMALL, external, maximumpacketsize, and RTP_MINPACKETSIZE.

104 {
105  if (arebuilding)
107  if (compoundpacket)
109 
110  if (buffersize < RTP_MINPACKETSIZE)
112 
113  maximumpacketsize = buffersize;
114  buffer = (uint8_t *) externalbuffer;
115  external = true;
116  byesize = 0;
117  appsize = 0;
118 
119  arebuilding = true;
120  return 0;
121 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYBUILT
Definition: rtperrors.h:84
#define ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYBUILDING
Definition: rtperrors.h:83
#define RTP_MINPACKETSIZE
Definition: rtpdefines.h:39
unsigned char uint8_t
Definition: rtptypes_win.h:42
#define ERR_RTP_RTCPCOMPPACKBUILDER_BUFFERSIZETOOSMALL
Definition: rtperrors.h:87

◆ StartReceiverReport()

int qrtplib::RTCPCompoundPacketBuilder::StartReceiverReport ( uint32_t  senderssrc)

Adds a receiver report to the compound packet. Tells the packet builder that the packet should start with a receiver report which will contain he sender SSRC senderssrc. Once the sender report is started, report blocks can be added using the AddReportBlock function.

Definition at line 156 of file rtcpcompoundpacketbuilder.cpp.

References appsize, arebuilding, byesize, ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYGOTREPORT, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT, qrtplib::RTCPCompoundPacketBuilder::Report::headerdata, qrtplib::RTCPCompoundPacketBuilder::Report::headerlength, qrtplib::RTCPCompoundPacketBuilder::Report::isSR, maximumpacketsize, qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytes(), report, and sdes.

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket(), qrtplib::RTCPPacketBuilder::BuildNextPacket(), and qrtplib::RTPSession::SendRTCPAPPPacket().

157 {
158  if (!arebuilding)
160  if (report.headerlength != 0)
162 
163  std::size_t totalsize = byesize + appsize + sdes.NeededBytes();
164  std::size_t sizeleft = maximumpacketsize - totalsize;
165  std::size_t neededsize = sizeof(RTCPCommonHeader) + sizeof(uint32_t);
166 
167  if (neededsize > sizeleft)
169 
170  // fill in some things
171 
172  report.headerlength = sizeof(uint32_t);
173  report.isSR = false;
174 
175  uint32_t *ssrc = (uint32_t *) report.headerdata;
176  *ssrc = qToBigEndian(senderssrc);
177 
178  return 0;
179 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT
Definition: rtperrors.h:95
unsigned int uint32_t
Definition: rtptypes_win.h:46
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
#define ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYGOTREPORT
Definition: rtperrors.h:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ StartSenderReport()

int qrtplib::RTCPCompoundPacketBuilder::StartSenderReport ( uint32_t  senderssrc,
const RTPNTPTime ntptimestamp,
uint32_t  rtptimestamp,
uint32_t  packetcount,
uint32_t  octetcount 
)

Adds a sender report to the compound packet. Tells the packet builder that the packet should start with a sender report which will contain the sender information specified by this function's arguments. Once the sender report is started, report blocks can be added using the AddReportBlock function.

Definition at line 123 of file rtcpcompoundpacketbuilder.cpp.

References appsize, arebuilding, byesize, ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYGOTREPORT, ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING, ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT, qrtplib::RTPNTPTime::GetLSW(), qrtplib::RTPNTPTime::GetMSW(), qrtplib::RTCPCompoundPacketBuilder::Report::headerdata, qrtplib::RTCPCompoundPacketBuilder::Report::headerlength, qrtplib::RTCPCompoundPacketBuilder::Report::isSR, maximumpacketsize, qrtplib::RTCPCompoundPacketBuilder::SDES::NeededBytes(), qrtplib::RTCPSenderReport::ntptime_lsw, qrtplib::RTCPSenderReport::ntptime_msw, qrtplib::RTCPSenderReport::octetcount, qrtplib::RTCPSenderReport::packetcount, report, qrtplib::RTCPSenderReport::rtptimestamp, and sdes.

Referenced by qrtplib::RTCPPacketBuilder::BuildBYEPacket(), and qrtplib::RTCPPacketBuilder::BuildNextPacket().

124 {
125  if (!arebuilding)
127 
128  if (report.headerlength != 0)
130 
131  std::size_t totalsize = byesize + appsize + sdes.NeededBytes();
132  std::size_t sizeleft = maximumpacketsize - totalsize;
133  std::size_t neededsize = sizeof(RTCPCommonHeader) + sizeof(uint32_t) + sizeof(RTCPSenderReport);
134 
135  if (neededsize > sizeleft)
137 
138  // fill in some things
139 
140  report.headerlength = sizeof(uint32_t) + sizeof(RTCPSenderReport);
141  report.isSR = true;
142 
143  uint32_t *ssrc = (uint32_t *) report.headerdata;
144  *ssrc = qToBigEndian(senderssrc);
145 
146  RTCPSenderReport *sr = (RTCPSenderReport *) (report.headerdata + sizeof(uint32_t));
147  sr->ntptime_msw = qToBigEndian(ntptimestamp.GetMSW());
148  sr->ntptime_lsw = qToBigEndian(ntptimestamp.GetLSW());
149  sr->rtptimestamp = qToBigEndian(rtptimestamp);
150  sr->packetcount = qToBigEndian(packetcount);
151  sr->octetcount = qToBigEndian(octetcount);
152 
153  return 0;
154 }
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTENOUGHBYTESLEFT
Definition: rtperrors.h:95
unsigned int uint32_t
Definition: rtptypes_win.h:46
#define ERR_RTP_RTCPCOMPPACKBUILDER_NOTBUILDING
Definition: rtperrors.h:94
#define ERR_RTP_RTCPCOMPPACKBUILDER_ALREADYGOTREPORT
Definition: rtperrors.h:85
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ apppackets

std::list<Buffer> qrtplib::RTCPCompoundPacketBuilder::apppackets
private

Definition at line 398 of file rtcpcompoundpacketbuilder.h.

Referenced by AddAPPPacket(), ClearBuildBuffers(), and EndBuild().

◆ appsize

std::size_t qrtplib::RTCPCompoundPacketBuilder::appsize
private

◆ arebuilding

bool qrtplib::RTCPCompoundPacketBuilder::arebuilding
private

◆ buffer

uint8_t* qrtplib::RTCPCompoundPacketBuilder::buffer
private

Definition at line 388 of file rtcpcompoundpacketbuilder.h.

Referenced by EndBuild(), InitBuild(), and RTCPCompoundPacketBuilder().

◆ byepackets

std::list<Buffer> qrtplib::RTCPCompoundPacketBuilder::byepackets
private

Definition at line 395 of file rtcpcompoundpacketbuilder.h.

Referenced by AddBYEPacket(), ClearBuildBuffers(), and EndBuild().

◆ byesize

std::size_t qrtplib::RTCPCompoundPacketBuilder::byesize
private

◆ external

bool qrtplib::RTCPCompoundPacketBuilder::external
private

◆ m_endian

RTPEndian qrtplib::RTCPCompoundPacketBuilder::m_endian
private

Definition at line 386 of file rtcpcompoundpacketbuilder.h.

◆ maximumpacketsize

std::size_t qrtplib::RTCPCompoundPacketBuilder::maximumpacketsize
private

◆ report

Report qrtplib::RTCPCompoundPacketBuilder::report
private

◆ sdes

SDES qrtplib::RTCPCompoundPacketBuilder::sdes
private

The documentation for this class was generated from the following files: