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);
130 #ifdef RTP_SUPPORT_RTCPUNKNOWN
134 int AddUnknownPacket(uint8_t payload_type, uint8_t subtype, uint32_t ssrc,
const void *data,
size_t len);
135 #endif // RTP_SUPPORT_RTCPUNKNOWN
140 Buffer():packetdata(0),packetlength(0) { }
141 Buffer(uint8_t *data,
size_t len):packetdata(data),packetlength(len) { }
147 class Report :
public RTPMemoryObject
152 headerdata = (uint8_t *)headerdata32;
156 ~Report() { Clear(); }
160 std::list<Buffer>::const_iterator it;
161 for (it = reportblocks.begin() ; it != reportblocks.end() ; it++)
163 if ((*it).packetdata)
164 RTPDeleteByteArray((*it).packetdata,GetMemoryManager());
166 reportblocks.clear();
174 n = reportblocks.size();
177 if (headerlength == 0)
179 x =
sizeof(RTCPCommonHeader)+headerlength;
183 x = n*
sizeof(RTCPReceiverReport);
188 x += d*(
sizeof(RTCPCommonHeader)+
sizeof(uint32_t));
190 x +=
sizeof(RTCPSenderReport);
195 size_t NeededBytesWithExtraReportBlock()
198 n = reportblocks.size() + 1;
199 x = n*
sizeof(RTCPReceiverReport);
204 x += d*(
sizeof(RTCPCommonHeader)+
sizeof(uint32_t));
206 x +=
sizeof(RTCPSenderReport);
213 uint32_t headerdata32[(
sizeof(uint32_t)+
sizeof(RTCPSenderReport))/
sizeof(uint32_t)];
215 std::list<Buffer> reportblocks;
218 class SDESSource :
public RTPMemoryObject
221 SDESSource(uint32_t s,
RTPMemoryManager *mgr) : RTPMemoryObject(mgr),ssrc(s),totalitemsize(0) { }
224 std::list<Buffer>::const_iterator it;
225 for (it = items.begin() ; it != items.end() ; it++)
227 if ((*it).packetdata)
228 RTPDeleteByteArray((*it).packetdata,GetMemoryManager());
236 x = totalitemsize + 1;
237 r = x%
sizeof(uint32_t);
239 x += (
sizeof(uint32_t)-r);
240 x +=
sizeof(uint32_t);
244 size_t NeededBytesWithExtraItem(uint8_t itemdatalength)
247 x = totalitemsize +
sizeof(RTCPSDESHeader) + (
size_t)itemdatalength + 1;
248 r = x%
sizeof(uint32_t);
250 x += (
sizeof(uint32_t)-r);
251 x +=
sizeof(uint32_t);
255 void AddItem(uint8_t *buf,
size_t len)
258 totalitemsize += len;
263 std::list<Buffer> items;
265 size_t totalitemsize;
268 class SDES :
public RTPMemoryObject
271 SDES(
RTPMemoryManager *mgr) : RTPMemoryObject(mgr) { sdesit = sdessources.end(); }
276 std::list<SDESSource *>::const_iterator it;
278 for (it = sdessources.begin() ; it != sdessources.end() ; it++)
279 RTPDelete(*it,GetMemoryManager());
283 int AddSSRC(uint32_t ssrc)
287 return ERR_RTP_OUTOFMEM;
288 sdessources.push_back(s);
289 sdesit = sdessources.end();
294 int AddItem(uint8_t *buf,
size_t len)
296 if (sdessources.empty())
297 return ERR_RTP_RTCPCOMPPACKBUILDER_NOCURRENTSOURCE;
298 (*sdesit)->AddItem(buf,len);
304 std::list<SDESSource *>::const_iterator it;
308 if (sdessources.empty())
311 for (it = sdessources.begin() ; it != sdessources.end() ; it++)
312 x += (*it)->NeededBytes();
313 n = sdessources.size();
318 x += d*
sizeof(RTCPCommonHeader);
322 size_t NeededBytesWithExtraItem(uint8_t itemdatalength)
324 std::list<SDESSource *>::const_iterator it;
328 if (sdessources.empty())
331 for (it = sdessources.begin() ; it != sdesit ; it++)
332 x += (*it)->NeededBytes();
333 x += (*sdesit)->NeededBytesWithExtraItem(itemdatalength);
334 n = sdessources.size();
339 x += d*
sizeof(RTCPCommonHeader);
343 size_t NeededBytesWithExtraSource()
345 std::list<SDESSource *>::const_iterator it;
349 if (sdessources.empty())
352 for (it = sdessources.begin() ; it != sdessources.end() ; it++)
353 x += (*it)->NeededBytes();
356 x +=
sizeof(uint32_t)*2;
358 n = sdessources.size() + 1;
363 x += d*
sizeof(RTCPCommonHeader);
367 std::list<SDESSource *> sdessources;
369 std::list<SDESSource *>::const_iterator sdesit;
372 size_t maximumpacketsize;
380 std::list<Buffer> byepackets;
383 std::list<Buffer> apppackets;
386 #ifdef RTP_SUPPORT_RTCPUNKNOWN
387 std::list<Buffer> unknownpackets;
389 #endif // RTP_SUPPORT_RTCPUNKNOWN
391 void ClearBuildBuffers();
394 #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 AddUnknownPacket(uint8_t payload_type, uint8_t subtype, uint32_t ssrc, const void *data, size_t len)
Adds the RTCP packet specified by the arguments to the compound packet.
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.