CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/HW/MpegDemux.h
Views: 1401
1
// This is a simple version MpegDemux that can get media's audio stream.
2
// Thanks to JPCSP project.
3
4
#pragma once
5
6
#include "Common/CommonTypes.h"
7
#include "Core/HW/BufferQueue.h"
8
9
class PointerWrap;
10
11
class MpegDemux
12
{
13
public:
14
MpegDemux(int size, int offset);
15
~MpegDemux();
16
17
bool addStreamData(const u8 *buf, int addSize);
18
bool demux(int audioChannel);
19
20
// return its framesize
21
int getNextAudioFrame(u8 **buf, int *headerCode1, int *headerCode2, s64 *pts = NULL);
22
bool hasNextAudioFrame(int *gotsizeOut, int *frameSizeOut, int *headerCode1, int *headerCode2);
23
24
int getRemainSize() const {
25
return m_len - m_readSize;
26
}
27
28
void DoState(PointerWrap &p);
29
30
private:
31
struct PesHeader {
32
s64 pts;
33
s64 dts;
34
int channel;
35
36
PesHeader(int chan) {
37
pts = 0;
38
dts = 0;
39
channel = chan;
40
}
41
};
42
43
int read8() {
44
return m_buf[m_index++];
45
}
46
int read16() {
47
return (read8() << 8) | read8();
48
}
49
int read24() {
50
return (read8() << 16) | (read8() << 8) | read8();
51
}
52
s64 readPts() {
53
return readPts(read8());
54
}
55
s64 readPts(int c) {
56
return (((s64) (c & 0x0E)) << 29) | ((read16() >> 1) << 15) | (read16() >> 1);
57
}
58
bool isEOF() const {
59
return m_index >= m_readSize;
60
}
61
void skip(int n) {
62
if (n > 0) {
63
m_index += n;
64
}
65
}
66
int readPesHeader(PesHeader &pesHeader, int length, int startCode);
67
int demuxStream(bool bdemux, int startCode, int length, int channel);
68
bool skipPackHeader();
69
70
int m_index;
71
int m_len;
72
u8 *m_buf;
73
BufferQueue m_audioStream;
74
u8 m_audioFrame[0x2000];
75
int m_audioChannel;
76
int m_readSize;
77
};
78
79
80