mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-12-14 00:49:49 +00:00
Merge pull request #5002 from unknownbrackets/mpeg-minor
Prevent psmfplayer from loading too many mpeg frames at once
This commit is contained in:
commit
f630d8f1d3
@ -861,16 +861,22 @@ int _PsmfPlayerFillRingbuffer(PsmfPlayer *psmfplayer) {
|
||||
if (!psmfplayer->filehandle || !psmfplayer->tempbuf)
|
||||
return -1;
|
||||
u8* buf = psmfplayer->tempbuf;
|
||||
u32 tempbufSize = sizeof(psmfplayer->tempbuf);
|
||||
int tempbufSize = (int)sizeof(psmfplayer->tempbuf);
|
||||
int size;
|
||||
// Let's not burn a bunch of time adding data all at once.
|
||||
int addMax = std::max(2048 * 100, tempbufSize);
|
||||
do {
|
||||
size = std::min(psmfplayer->mediaengine->getRemainSize(), (int)tempbufSize);
|
||||
size = std::min(psmfplayer->mediaengine->getRemainSize(), tempbufSize);
|
||||
size = std::min(psmfplayer->mediaengine->getAudioRemainSize(), size);
|
||||
size = std::min(psmfplayer->streamSize - psmfplayer->readSize, size);
|
||||
if (size <= 0)
|
||||
break;
|
||||
size = (int)pspFileSystem.ReadFile(psmfplayer->filehandle, buf, size);
|
||||
psmfplayer->readSize += size;
|
||||
psmfplayer->mediaengine->addStreamData(buf, size);
|
||||
addMax -= size;
|
||||
if (addMax <= 0)
|
||||
break;
|
||||
} while (size > 0);
|
||||
if (psmfplayer->readSize >= psmfplayer->streamSize && videoLoopStatus == PSMF_PLAYER_CONFIG_LOOP) {
|
||||
// start looping
|
||||
@ -886,13 +892,13 @@ int _PsmfPlayerSetPsmfOffset(PsmfPlayer *psmfplayer, const char * filename, int
|
||||
if (offset > 0)
|
||||
pspFileSystem.SeekFile(psmfplayer->filehandle, offset, FILEMOVE_BEGIN);
|
||||
u8* buf = psmfplayer->tempbuf;
|
||||
u32 tempbufSize = sizeof(psmfplayer->tempbuf);
|
||||
int tempbufSize = (int)sizeof(psmfplayer->tempbuf);
|
||||
int size = (int)pspFileSystem.ReadFile(psmfplayer->filehandle, buf, 2048);
|
||||
int mpegoffset = bswap32(*(u32*)(buf + PSMF_STREAM_OFFSET_OFFSET));
|
||||
psmfplayer->readSize = size - mpegoffset;
|
||||
psmfplayer->streamSize = bswap32(*(u32*)(buf + PSMF_STREAM_SIZE_OFFSET));
|
||||
psmfplayer->fileoffset = offset + mpegoffset;
|
||||
psmfplayer->mediaengine->loadStream(buf, 2048, std::max(2048 * 500, (int)tempbufSize));
|
||||
psmfplayer->mediaengine->loadStream(buf, 2048, std::max(2048 * 500, tempbufSize));
|
||||
_PsmfPlayerFillRingbuffer(psmfplayer);
|
||||
psmfplayer->psmfPlayerLastTimestamp = psmfplayer->mediaengine->getLastTimeStamp();
|
||||
}
|
||||
|
@ -683,6 +683,15 @@ int MediaEngine::getRemainSize() {
|
||||
return std::max(m_pdata->getRemainSize() - m_decodingsize - 2048, 0);
|
||||
}
|
||||
|
||||
int MediaEngine::getAudioRemainSize() {
|
||||
if (!m_demux) {
|
||||
// No audio, so it can't be full, return video instead.
|
||||
return getRemainSize();
|
||||
}
|
||||
|
||||
return m_demux->getRemainSize();
|
||||
}
|
||||
|
||||
int MediaEngine::getAudioSamples(u32 bufferPtr) {
|
||||
if (!Memory::IsValidAddress(bufferPtr)) {
|
||||
ERROR_LOG_REPORT(ME, "Ignoring bad audio decode address %08x during video playback", bufferPtr);
|
||||
|
@ -70,6 +70,7 @@ public:
|
||||
|
||||
u8 *getFrameImage();
|
||||
int getRemainSize();
|
||||
int getAudioRemainSize();
|
||||
|
||||
bool stepVideo(int videoPixelMode);
|
||||
int writeVideoImage(u32 bufferPtr, int frameWidth = 512, int videoPixelMode = 3);
|
||||
|
@ -61,7 +61,7 @@ int MpegDemux::readPesHeader(PesHeader &pesHeader, int length, int startCode) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((c & 0xC0) == 0x40) {
|
||||
if ((c & 0xC0) == 0x40) {
|
||||
read8();
|
||||
c = read8();
|
||||
length -= 2;
|
||||
|
@ -19,6 +19,10 @@ public:
|
||||
// return its framesize
|
||||
int getNextaudioFrame(u8** buf, int *headerCode1, int *headerCode2);
|
||||
|
||||
inline int getRemainSize() {
|
||||
return m_len - m_readSize;
|
||||
}
|
||||
|
||||
void DoState(PointerWrap &p);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user