-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathrtphint.h
362 lines (258 loc) · 8.33 KB
/
rtphint.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is MPEG4IP.
*
* The Initial Developer of the Original Code is Cisco Systems Inc.
* Portions created by Cisco Systems Inc. are
* Copyright (C) Cisco Systems Inc. 2001. All Rights Reserved.
*
* Contributor(s):
* Dave Mackie [email protected]
*/
#ifndef MP4V2_IMPL_RTPHINT_H
#define MP4V2_IMPL_RTPHINT_H
namespace mp4v2 {
namespace impl {
///////////////////////////////////////////////////////////////////////////////
// forward declarations
class MP4RtpHintTrack;
class MP4RtpHint;
class MP4RtpPacket;
class MP4RtpData : public MP4Container {
public:
MP4RtpData(MP4RtpPacket& packet);
MP4RtpPacket& GetPacket() {
return m_packet;
}
virtual uint16_t GetDataSize() = 0;
virtual void GetData(uint8_t* pDest) = 0;
MP4Track* FindTrackFromRefIndex(uint8_t refIndex);
virtual void WriteEmbeddedData(MP4File& file, uint64_t startPos) {
// default is no-op
}
protected:
MP4RtpPacket& m_packet;
};
MP4ARRAY_DECL(MP4RtpData, MP4RtpData*)
class MP4RtpNullData : public MP4RtpData {
public:
MP4RtpNullData(MP4RtpPacket& packet);
uint16_t GetDataSize() {
return 0;
}
void GetData(uint8_t* pDest) {
// no-op
}
};
class MP4RtpImmediateData : public MP4RtpData {
public:
MP4RtpImmediateData(MP4RtpPacket& packet);
void Set(const uint8_t* pBytes, uint8_t numBytes);
uint16_t GetDataSize();
void GetData(uint8_t* pDest);
};
class MP4RtpSampleData : public MP4RtpData {
public:
MP4RtpSampleData(MP4RtpPacket& packet);
~MP4RtpSampleData(void) {
CHECK_AND_FREE(m_pRefData);
};
void SetEmbeddedImmediate(
MP4SampleId sampleId,
uint8_t* pData, uint16_t dataLength);
void SetReferenceSample(
MP4SampleId refSampleId, uint32_t refSampleOffset,
uint16_t sampleLength);
void SetEmbeddedSample(
MP4SampleId sampleId, MP4Track* pRefTrack,
MP4SampleId refSampleId, uint32_t refSampleOffset,
uint16_t sampleLength);
uint16_t GetDataSize();
void GetData(uint8_t* pDest);
void WriteEmbeddedData(MP4File& file, uint64_t startPos);
protected:
uint8_t* m_pRefData;
MP4Track* m_pRefTrack;
MP4SampleId m_refSampleId;
uint32_t m_refSampleOffset;
};
class MP4RtpSampleDescriptionData : public MP4RtpData {
public:
MP4RtpSampleDescriptionData(MP4RtpPacket& packet);
void Set(uint32_t sampleDescrIndex,
uint32_t offset, uint16_t length);
uint16_t GetDataSize();
void GetData(uint8_t* pDest);
};
class MP4RtpPacket : public MP4Container {
public:
MP4RtpPacket(MP4RtpHint& hint);
~MP4RtpPacket();
void AddExtraProperties();
MP4RtpHint& GetHint() {
return m_hint;
}
void Set(uint8_t payloadNumber, uint32_t packetId, bool setMbit);
int32_t GetTransmitOffset();
bool GetPBit();
bool GetXBit();
bool GetMBit();
uint8_t GetPayload();
uint16_t GetSequenceNumber();
void SetTransmitOffset(int32_t transmitOffset);
bool IsBFrame();
void SetBFrame(bool isBFrame);
void SetTimestampOffset(uint32_t timestampOffset);
void AddData(MP4RtpData* pData);
uint32_t GetDataSize();
void GetData(uint8_t* pDest);
void Read(MP4File& file);
void ReadExtra(MP4File& file);
void Write(MP4File& file);
void WriteEmbeddedData(MP4File& file, uint64_t startPos);
void Dump(uint8_t indent, bool dumpImplicits);
protected:
MP4RtpHint& m_hint;
MP4RtpDataArray m_rtpData;
};
MP4ARRAY_DECL(MP4RtpPacket, MP4RtpPacket*)
class MP4RtpHint : public MP4Container {
public:
MP4RtpHint(MP4RtpHintTrack& track);
~MP4RtpHint();
MP4RtpHintTrack& GetTrack() {
return m_track;
}
uint16_t GetNumberOfPackets() {
return m_rtpPackets.Size();
}
bool IsBFrame() {
return m_isBFrame;
}
void SetBFrame(bool isBFrame) {
m_isBFrame = isBFrame;
}
uint32_t GetTimestampOffset() {
return m_timestampOffset;
}
void SetTimestampOffset(uint32_t timestampOffset) {
m_timestampOffset = timestampOffset;
}
MP4RtpPacket* AddPacket();
MP4RtpPacket* GetPacket(uint16_t index) {
return m_rtpPackets[index];
}
MP4RtpPacket* GetCurrentPacket() {
if (m_rtpPackets.Size() == 0) {
return NULL;
}
return m_rtpPackets[m_rtpPackets.Size() - 1];
}
void Read(MP4File& file);
void Write(MP4File& file);
void Dump(uint8_t indent, bool dumpImplicits);
protected:
MP4RtpHintTrack& m_track;
MP4RtpPacketArray m_rtpPackets;
// values when adding packets to a hint (write mode)
bool m_isBFrame;
uint32_t m_timestampOffset;
};
class MP4RtpHintTrack : public MP4Track {
public:
MP4RtpHintTrack(MP4File& file, MP4Atom& trakAtom);
~MP4RtpHintTrack();
void InitRefTrack();
void InitPayload();
void InitRtpStart();
void InitStats();
MP4Track* GetRefTrack() {
InitRefTrack();
return m_pRefTrack;
}
void GetPayload(
char** ppPayloadName = NULL,
uint8_t* pPayloadNumber = NULL,
uint16_t* pMaxPayloadSize = NULL,
char **ppEncodingParams = NULL);
void SetPayload(
const char* payloadName,
uint8_t payloadNumber,
uint16_t maxPayloadSize,
const char *encoding_parms,
bool add_rtpmap,
bool add_mpeg4_esid);
void ReadHint(
MP4SampleId hintSampleId,
uint16_t* pNumPackets = NULL);
uint16_t GetHintNumberOfPackets();
bool GetPacketBFrame(uint16_t packetIndex);
uint16_t GetPacketTransmitOffset(uint16_t packetIndex);
void ReadPacket(
uint16_t packetIndex,
uint8_t** ppBytes,
uint32_t* pNumBytes,
uint32_t ssrc,
bool includeHeader = true,
bool includePayload = true);
MP4Timestamp GetRtpTimestampStart();
void SetRtpTimestampStart(MP4Timestamp start);
void AddHint(bool isBFrame, uint32_t timestampOffset);
void AddPacket(bool setMbit, int32_t transmitOffset = 0);
void AddImmediateData(const uint8_t* pBytes, uint32_t numBytes);
void AddSampleData(MP4SampleId sampleId,
uint32_t dataOffset, uint32_t dataLength);
void AddESConfigurationPacket();
void WriteHint(MP4Duration duration, bool isSyncSample);
void FinishWrite(uint32_t options = 0);
protected:
MP4Track* m_pRefTrack;
MP4StringProperty* m_pRtpMapProperty;
MP4Integer32Property* m_pPayloadNumberProperty;
MP4Integer32Property* m_pMaxPacketSizeProperty;
MP4Integer32Property* m_pSnroProperty;
MP4Integer32Property* m_pTsroProperty;
uint32_t m_rtpSequenceStart;
uint32_t m_rtpTimestampStart;
// reading
MP4RtpHint* m_pReadHint;
uint8_t* m_pReadHintSample;
uint32_t m_readHintSampleSize;
MP4Timestamp m_readHintTimestamp;
// writing
MP4RtpHint* m_pWriteHint;
MP4SampleId m_writeHintId;
uint32_t m_writePacketId;
// statistics
// in trak.udta.hinf
MP4Integer64Property* m_pTrpy;
MP4Integer64Property* m_pNump;
MP4Integer64Property* m_pTpyl;
MP4Integer32Property* m_pMaxr;
MP4Integer64Property* m_pDmed;
MP4Integer64Property* m_pDimm;
MP4Integer32Property* m_pPmax;
MP4Integer32Property* m_pDmax;
// in trak.mdia.minf.hmhd
MP4Integer16Property* m_pMaxPdu;
MP4Integer16Property* m_pAvgPdu;
MP4Integer32Property* m_pMaxBitRate;
MP4Integer32Property* m_pAvgBitRate;
MP4Timestamp m_thisSec;
uint32_t m_bytesThisSec;
uint32_t m_bytesThisHint;
uint32_t m_bytesThisPacket;
};
///////////////////////////////////////////////////////////////////////////////
}
} // namespace mp4v2::impl
#endif // MP4V2_IMPL_RTPHINT_H