-
Notifications
You must be signed in to change notification settings - Fork 6
/
media-elements.hpp
85 lines (67 loc) · 1.92 KB
/
media-elements.hpp
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
#ifndef MEDIA_ELEMENTS_HPP___
#define MEDIA_ELEMENTS_HPP___
#include <list>
#include <string>
#define STREAMID_MIN 0xE0
#define STREAMID_MAX 0xEF
// Misc
// -----------------------------------------------------------------------------------------
extern std::vector<std::string> gStreamTypeName;
static std::string &GetStreamType(uint8_t st) { return gStreamTypeName[st]; }
enum PESPacketState { OK = 0x00, CONTINUITY_ERROR = 0x01 };
// Media Classes
// -----------------------------------------------------------------------------------------
class PES_Packet {
public:
PES_Packet()
: mData((uint8_t *)0),
mDataPESPayload((uint8_t *)0),
mSize(0),
mContinuityCounter(0),
mState(0),
mStreamId(0),
mPTSDTSIndicator(0),
mPTS(0),
mDTS(0),
mPID(0) {
mData = mWritePointer = new uint8_t[PES_PACKET_MAXSIZE];
}
~PES_Packet() {
if (mData) delete[] mData;
}
bool AsAPTS() { return mPTSDTSIndicator & 0x2; }
bool AsADTS() { return mPTSDTSIndicator & 0x1; }
// Points to the beginning
uint8_t *mData;
// Points to the beginning of the PES packet payload (set after Parse).
uint8_t *mDataPESPayload;
// Points to the end (where to write)
uint8_t *mWritePointer;
// Current size in bytes, result of parsing
uint32_t mSize;
uint8_t mContinuityCounter; // used when parsing PES to keep last CC
uint32_t mState;
// Stream Identifier
uint8_t mStreamId;
// Timestamps
uint8_t mPTSDTSIndicator;
uint64_t mPTS;
uint64_t mDTS;
// Forward protocol layering
uint32_t mPID;
};
class Stream {
public:
Stream(uint32_t type, uint32_t pid) : mType(type), mPID(pid) {}
uint32_t mType;
uint32_t mPID;
std::string &GetStreamTypeName() { return gStreamTypeName[mType]; }
};
class Channel {
public:
Channel() : mPMTPID(0) {}
Channel(uint32_t pmtpid) : mPMTPID(pmtpid) {}
uint32_t mPMTPID;
std::list<Stream> mStreams;
};
#endif