This repository was archived by the owner on Aug 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMP2TMuxer.h
More file actions
167 lines (126 loc) · 4.2 KB
/
MP2TMuxer.h
File metadata and controls
167 lines (126 loc) · 4.2 KB
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
#pragma once
#include <map>
#include <queue>
#include <vector>
#include <stdint.h>
#include "PAT.h"
#include "PMT.h"
#include "Program.h"
#include "Packet.h"
#include "PES.h"
#include "IDeliverer.h"
#include "MutableHeaderBuffer.h"
#include "Ticker.h"
using namespace com::cloume::common;
namespace com{
namespace cloume{
namespace cap{
namespace streaming{
class MP2TMuxer
{
public:
const static int PATPMT_INTERVAL = 255;
explicit MP2TMuxer(bool mPeriodicSendPSI = false, double fps = 25.);
virtual ~MP2TMuxer(void);
typedef std::pair<unsigned short, unsigned char> ContinuityCounterPair;
typedef std::map<unsigned short, unsigned char> ContinuityCounterMap;
public:
void AddProgram(Program*);
Program *GetProgram(int idx = 0); //现在只支持一个Program
int Mux(Program::Stream *, MutableHeaderBuffer *, unsigned int duration);
//int Mux(Program::Stream *, MutableHeaderBuffer *, double duration);
void SetDeliverer(IDeliverer *);
typedef int(*PacketsDeliverer)(const unsigned char*, const unsigned long, void*);
void SetPacketsDeliverer(PacketsDeliverer deliverer, void* handler) {
mDeliverer = deliverer;
mDeliverHandler = handler;
}
//周期性用该方法发送数据
void Deliver();
//void Reset();
unsigned long &FrameCount(){ return mFrameCount; }
//double FPS(){ return mFPS; }
//double FrameDuration(){ return mFrameDuration; }
void SetTicker(Ticker *);
protected:
double mLastPCR;
///double mCurrentPCR;
void DeliverPATPMT();
void DeliverPCR();
Ticker *GetTicker();
unsigned int getVideoStartTimestamp() {
if (mVideoStartTimestamp == 0) {
mVideoStartTimestamp = GetTicker()->TickCount();
}
return mVideoStartTimestamp;
}
typedef std::vector<PMT*> PMTVector;
typedef std::vector<unsigned short> PCRPIDVector;
private:
class PacketData{
public:
unsigned char *data;
unsigned int ts;
PacketData(unsigned char *indata, unsigned int tsx1000) : ts(tsx1000){
data = new unsigned char[188];
memcpy(data, indata, 188);
}
~PacketData(){
delete[] data;
}
};
//inline int DeliverPacket(const unsigned char* data, unsigned long size = Packet::PACKET_LENGTH);
int DeliverPacket(Packet &packet);
int DeliverPacket2(Packet &packet, std::vector<PacketData> &packs);
//-
// Method: Deliver
// FullName: com::cloume::cap::streaming::MP2TMuxer::Deliver
// Access: private
// Returns: int
// Qualifier:
// Parameter: unsigned short pid 数据所属的PID
// Parameter: unsigned char * data PES帧数据或者PAT/PMT数据
// Parameter: unsigned long size 帧数据字节数
// Description: 分发整帧PES数据,或者PAT/PMT等数据!
//-
int PackAndDeliver(unsigned short pid, unsigned char* data, unsigned long size, unsigned int timestamp, bool pes = true);
IDeliverer *GetDeliverer();
public:
double &FPS(){ return mFPS; }
private:
ProgramVector mPrograms;
PacketsDeliverer mDeliverer;
void* mDeliverHandler;
IDeliverer *mpDeliverer;
ContinuityCounterMap mContinuityCounter;
//send PAT & PMT every N packets
long mPSIPeriod;
bool mPeriodicSendPSI;
PAT mPAT;
PMTVector mPMTs;
PCRPIDVector mPCRPIDs;
double mFPS;
//double mFrameDuration; //ms
unsigned long mFrameCount; //用作Simple PCR
unsigned int mVideoStartTimestamp;
class PESData{
public:
double tsx1000;
double dpp; //duration per packet
unsigned int offset;
PES *pes;
unsigned short pid;
PESData():tsx1000(0), dpp(0), offset(0), pes(NULL), pid(0){};
};
///typedef std::queue<PES *> PESQueue;
typedef std::queue<PESData> PESDataQueue;
PESDataQueue mAudioPESQueue;
PESDataQueue mVideoPESQueue;
///typedef std::map<unsigned short, PESQueue *> PESQueueMap;
///PESQueueMap mPESQueueMap;
Ticker *mpTicker;
};
}
}
}
}