00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00037 #ifndef RTPPACKETBUILDER_H
00038
00039 #define RTPPACKETBUILDER_H
00040
00041 #include "rtpconfig.h"
00042 #include "rtperrors.h"
00043 #include "rtpdefines.h"
00044 #include "rtprandom.h"
00045 #include "rtptimeutilities.h"
00046 #include "rtptypes.h"
00047 #include "rtpmemoryobject.h"
00048
00049 class RTPSources;
00050
00054 class RTPPacketBuilder : public RTPMemoryObject
00055 {
00056 public:
00058 RTPPacketBuilder(RTPMemoryManager *mgr = 0);
00059 ~RTPPacketBuilder();
00060
00062 int Init(size_t maxpacksize);
00063
00065 void Destroy();
00066
00068 uint32_t GetPacketCount() { if (!init) return 0; return numpackets; }
00069
00071 uint32_t GetPayloadOctetCount() { if (!init) return 0; return numpayloadbytes; }
00072
00074 int SetMaximumPacketSize(size_t maxpacksize);
00075
00077 int AddCSRC(uint32_t csrc);
00078
00080 int DeleteCSRC(uint32_t csrc);
00081
00083 void ClearCSRCList();
00084
00090 int BuildPacket(const void *data,size_t len);
00091
00097 int BuildPacket(const void *data,size_t len,
00098 uint8_t pt,bool mark,uint32_t timestampinc);
00099
00107 int BuildPacketEx(const void *data,size_t len,
00108 uint16_t hdrextID,const void *hdrextdata,size_t numhdrextwords);
00109
00117 int BuildPacketEx(const void *data,size_t len,
00118 uint8_t pt,bool mark,uint32_t timestampinc,
00119 uint16_t hdrextID,const void *hdrextdata,size_t numhdrextwords);
00120
00122 uint8_t *GetPacket() { if (!init) return 0; return buffer; }
00123
00125 size_t GetPacketLength() { if (!init) return 0; return packetlength; }
00126
00128 int SetDefaultPayloadType(uint8_t pt);
00129
00131 int SetDefaultMark(bool m);
00132
00134 int SetDefaultTimestampIncrement(uint32_t timestampinc);
00135
00142 int IncrementTimestamp(uint32_t inc);
00143
00151 int IncrementTimestampDefault();
00152
00157 uint32_t CreateNewSSRC();
00158
00164 uint32_t CreateNewSSRC(RTPSources &sources);
00165
00167 uint32_t GetSSRC() const { if (!init) return 0; return ssrc; }
00168
00170 uint32_t GetTimestamp() const { if (!init) return 0; return timestamp; }
00171
00173 uint16_t GetSequenceNumber() const { if (!init) return 0; return seqnr; }
00174
00179 RTPTime GetPacketTime() const { if (!init) return RTPTime(0,0); return lastwallclocktime; }
00180
00182 uint32_t GetPacketTimestamp() const { if (!init) return 0; return lastrtptimestamp; }
00183 private:
00184 int PrivateBuildPacket(const void *data,size_t len,
00185 uint8_t pt,bool mark,uint32_t timestampinc,bool gotextension,
00186 uint16_t hdrextID = 0,const void *hdrextdata = 0,size_t numhdrextwords = 0);
00187
00188 RTPRandom rtprnd;
00189 size_t maxpacksize;
00190 uint8_t *buffer;
00191 size_t packetlength;
00192
00193 uint32_t numpayloadbytes;
00194 uint32_t numpackets;
00195 bool init;
00196
00197 uint32_t ssrc;
00198 uint32_t timestamp;
00199 uint16_t seqnr;
00200
00201 uint32_t defaulttimestampinc;
00202 uint8_t defaultpayloadtype;
00203 bool defaultmark;
00204
00205 bool deftsset,defptset,defmarkset;
00206
00207 uint32_t csrcs[RTP_MAXCSRCS];
00208 int numcsrcs;
00209
00210 RTPTime lastwallclocktime;
00211 uint32_t lastrtptimestamp;
00212 uint32_t prevrtptimestamp;
00213 };
00214
00215 inline int RTPPacketBuilder::SetDefaultPayloadType(uint8_t pt)
00216 {
00217 if (!init)
00218 return ERR_RTP_PACKBUILD_NOTINIT;
00219 defptset = true;
00220 defaultpayloadtype = pt;
00221 return 0;
00222 }
00223
00224 inline int RTPPacketBuilder::SetDefaultMark(bool m)
00225 {
00226 if (!init)
00227 return ERR_RTP_PACKBUILD_NOTINIT;
00228 defmarkset = true;
00229 defaultmark = m;
00230 return 0;
00231 }
00232
00233 inline int RTPPacketBuilder::SetDefaultTimestampIncrement(uint32_t timestampinc)
00234 {
00235 if (!init)
00236 return ERR_RTP_PACKBUILD_NOTINIT;
00237 deftsset = true;
00238 defaulttimestampinc = timestampinc;
00239 return 0;
00240 }
00241
00242 inline int RTPPacketBuilder::IncrementTimestamp(uint32_t inc)
00243 {
00244 if (!init)
00245 return ERR_RTP_PACKBUILD_NOTINIT;
00246 timestamp += inc;
00247 return 0;
00248 }
00249
00250 inline int RTPPacketBuilder::IncrementTimestampDefault()
00251 {
00252 if (!init)
00253 return ERR_RTP_PACKBUILD_NOTINIT;
00254 if (!deftsset)
00255 return ERR_RTP_PACKBUILD_DEFAULTTSINCNOTSET;
00256 timestamp += defaulttimestampinc;
00257 return 0;
00258 }
00259
00260 #endif // RTPPACKETBUILDER_H
00261