37 #ifndef RTCPCOMPOUNDPACKETBUILDER_H
39 #define RTCPCOMPOUNDPACKETBUILDER_H
41 #include "rtpconfig.h"
73 int InitBuild(
void *externalbuffer,
size_t buffersize);
81 uint32_t packetcount,uint32_t octetcount);
94 int AddReportBlock(uint32_t ssrc,uint8_t fractionlost,int32_t packetslost,uint32_t exthighestseq,
95 uint32_t jitter,uint32_t lsr,uint32_t dlsr);
105 #ifdef RTP_SUPPORT_SDESPRIV
107 int AddSDESPrivateItem(
const void *prefixdata,uint8_t prefixlength,
const void *valuedata,
108 uint8_t valuelength);
109 #endif // RTP_SUPPORT_SDESPRIV
116 int AddBYEPacket(uint32_t *ssrcs,uint8_t numssrcs,
const void *reasondata,uint8_t reasonlength);
122 int AddAPPPacket(uint8_t subtype,uint32_t ssrc,
const uint8_t name[4],
const void *appdata,
size_t appdatalen);
133 Buffer():packetdata(0),packetlength(0) { }
134 Buffer(uint8_t *data,
size_t len):packetdata(data),packetlength(len) { }
140 class Report :
public RTPMemoryObject
145 headerdata = (uint8_t *)headerdata32;
149 ~Report() { Clear(); }
153 std::list<Buffer>::const_iterator it;
154 for (it = reportblocks.begin() ; it != reportblocks.end() ; it++)
156 if ((*it).packetdata)
157 RTPDeleteByteArray((*it).packetdata,GetMemoryManager());
159 reportblocks.clear();
167 n = reportblocks.size();
170 if (headerlength == 0)
172 x =
sizeof(RTCPCommonHeader)+headerlength;
176 x = n*
sizeof(RTCPReceiverReport);
181 x += d*(
sizeof(RTCPCommonHeader)+
sizeof(uint32_t));
183 x +=
sizeof(RTCPSenderReport);
188 size_t NeededBytesWithExtraReportBlock()
191 n = reportblocks.size() + 1;
192 x = n*
sizeof(RTCPReceiverReport);
197 x += d*(
sizeof(RTCPCommonHeader)+
sizeof(uint32_t));
199 x +=
sizeof(RTCPSenderReport);
206 uint32_t headerdata32[(
sizeof(uint32_t)+
sizeof(RTCPSenderReport))/
sizeof(uint32_t)];
208 std::list<Buffer> reportblocks;
211 class SDESSource :
public RTPMemoryObject
214 SDESSource(uint32_t s,
RTPMemoryManager *mgr) : RTPMemoryObject(mgr),ssrc(s),totalitemsize(0) { }
217 std::list<Buffer>::const_iterator it;
218 for (it = items.begin() ; it != items.end() ; it++)
220 if ((*it).packetdata)
221 RTPDeleteByteArray((*it).packetdata,GetMemoryManager());
229 x = totalitemsize + 1;
230 r = x%
sizeof(uint32_t);
232 x += (
sizeof(uint32_t)-r);
233 x +=
sizeof(uint32_t);
237 size_t NeededBytesWithExtraItem(uint8_t itemdatalength)
240 x = totalitemsize +
sizeof(RTCPSDESHeader) + (
size_t)itemdatalength + 1;
241 r = x%
sizeof(uint32_t);
243 x += (
sizeof(uint32_t)-r);
244 x +=
sizeof(uint32_t);
248 void AddItem(uint8_t *buf,
size_t len)
251 totalitemsize += len;
256 std::list<Buffer> items;
258 size_t totalitemsize;
261 class SDES :
public RTPMemoryObject
264 SDES(
RTPMemoryManager *mgr) : RTPMemoryObject(mgr) { sdesit = sdessources.end(); }
269 std::list<SDESSource *>::const_iterator it;
271 for (it = sdessources.begin() ; it != sdessources.end() ; it++)
272 RTPDelete(*it,GetMemoryManager());
276 int AddSSRC(uint32_t ssrc)
280 return ERR_RTP_OUTOFMEM;
281 sdessources.push_back(s);
282 sdesit = sdessources.end();
287 int AddItem(uint8_t *buf,
size_t len)
289 if (sdessources.empty())
290 return ERR_RTP_RTCPCOMPPACKBUILDER_NOCURRENTSOURCE;
291 (*sdesit)->AddItem(buf,len);
297 std::list<SDESSource *>::const_iterator it;
301 if (sdessources.empty())
304 for (it = sdessources.begin() ; it != sdessources.end() ; it++)
305 x += (*it)->NeededBytes();
306 n = sdessources.size();
311 x += d*
sizeof(RTCPCommonHeader);
315 size_t NeededBytesWithExtraItem(uint8_t itemdatalength)
317 std::list<SDESSource *>::const_iterator it;
321 if (sdessources.empty())
324 for (it = sdessources.begin() ; it != sdesit ; it++)
325 x += (*it)->NeededBytes();
326 x += (*sdesit)->NeededBytesWithExtraItem(itemdatalength);
327 n = sdessources.size();
332 x += d*
sizeof(RTCPCommonHeader);
336 size_t NeededBytesWithExtraSource()
338 std::list<SDESSource *>::const_iterator it;
342 if (sdessources.empty())
345 for (it = sdessources.begin() ; it != sdessources.end() ; it++)
346 x += (*it)->NeededBytes();
349 x +=
sizeof(uint32_t)*2;
351 n = sdessources.size() + 1;
356 x += d*
sizeof(RTCPCommonHeader);
360 std::list<SDESSource *> sdessources;
362 std::list<SDESSource *>::const_iterator sdesit;
365 size_t maximumpacketsize;
373 std::list<Buffer> byepackets;
376 std::list<Buffer> apppackets;
379 void ClearBuildBuffers();
382 #endif // RTCPCOMPOUNDPACKETBUILDER_H
int 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.
RTCPCompoundPacketBuilder(RTPMemoryManager *memmgr=0)
Constructs an RTCPCompoundPacketBuilder instance, optionally installing a memory manager.
A memory manager.
Definition: rtpmemorymanager.h:144
int StartReceiverReport(uint32_t senderssrc)
Adds a receiver report to the compound packet.
int AddAPPPacket(uint8_t subtype, uint32_t ssrc, const uint8_t name[4], const void *appdata, size_t appdatalen)
Adds the APP packet specified by the arguments to the compound packet.
Represents an RTCP compound packet.
Definition: rtcpcompoundpacket.h:50
int StartSenderReport(uint32_t senderssrc, const RTPNTPTime &ntptimestamp, uint32_t rtptimestamp, uint32_t packetcount, uint32_t octetcount)
Adds a sender report to the compound packet.
This class can be used to construct an RTCP compound packet.
Definition: rtcpcompoundpacketbuilder.h:56
int 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.
int AddBYEPacket(uint32_t *ssrcs, uint8_t numssrcs, const void *reasondata, uint8_t reasonlength)
Adds a BYE packet to the compound packet.
int AddSDESSource(uint32_t ssrc)
Starts an SDES chunk for participant ssrc.
#define RTPMEM_TYPE_CLASS_SDESSOURCE
Buffer to store an SDESSource instance.
Definition: rtpmemorymanager.h:138
ItemType
Identifies the type of an SDES item.
Definition: rtcpsdespacket.h:56
int InitBuild(size_t maxpacketsize)
Starts building an RTCP compound packet with maximum size maxpacketsize.
int EndBuild()
Finishes building the compound packet.
This is a simple wrapper for the most significant word (MSW) and least significant word (LSW) of an N...
Definition: rtptimeutilities.h:58
int 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.