ppsspp/Core/HW/MpegDemux.h

75 lines
1.4 KiB
C
Raw Normal View History

2013-06-01 17:25:53 +00:00
// This is a simple version MpegDemux that can get media's audio stream.
// Thanks to JPCSP project.
#pragma once
#include "Common/CommonTypes.h"
#include "Core/HW/BufferQueue.h"
2013-06-01 17:25:53 +00:00
2014-03-15 18:32:57 +00:00
class PointerWrap;
2013-06-01 17:25:53 +00:00
class MpegDemux
{
public:
MpegDemux(int size, int offset);
2014-03-30 20:06:42 +00:00
~MpegDemux();
2013-06-01 17:25:53 +00:00
bool addStreamData(const u8 *buf, int addSize);
void demux(int audioChannel);
2013-06-01 17:25:53 +00:00
// return its framesize
int getNextAudioFrame(u8 **buf, int *headerCode1, int *headerCode2, s64 *pts = NULL);
bool hasNextAudioFrame(int *gotsizeOut, int *frameSizeOut, int *headerCode1, int *headerCode2);
2014-12-03 20:16:11 +00:00
int getRemainSize() const {
return m_len - m_readSize;
}
void DoState(PointerWrap &p);
2013-06-01 17:25:53 +00:00
private:
struct PesHeader {
s64 pts;
s64 dts;
2013-06-01 17:25:53 +00:00
int channel;
PesHeader(int chan) {
pts = 0;
dts = 0;
channel = chan;
}
};
2013-06-01 17:25:53 +00:00
int read8() {
return m_buf[m_index++];
2013-06-01 17:25:53 +00:00
}
int read16() {
return (read8() << 8) | read8();
}
s64 readPts() {
2013-06-01 17:25:53 +00:00
return readPts(read8());
}
s64 readPts(int c) {
return (((s64) (c & 0x0E)) << 29) | ((read16() >> 1) << 15) | (read16() >> 1);
2013-06-01 17:25:53 +00:00
}
2014-12-03 20:16:11 +00:00
bool isEOF() const {
2013-06-01 17:25:53 +00:00
return m_index >= m_len;
}
void skip(int n) {
if (n > 0) {
m_index += n;
}
}
int readPesHeader(PesHeader &pesHeader, int length, int startCode);
int demuxStream(bool bdemux, int startCode, int channel);
2013-06-01 17:25:53 +00:00
int m_index;
int m_len;
u8* m_buf;
BufferQueue m_audioStream;
u8 m_audioFrame[0x2000];
2013-06-01 17:25:53 +00:00
int m_audioChannel;
int m_readSize;
};