Merge pull request #5002 from unknownbrackets/mpeg-minor

Prevent psmfplayer from loading too many mpeg frames at once
This commit is contained in:
Henrik Rydgård 2014-01-04 01:51:28 -08:00
commit f630d8f1d3
5 changed files with 25 additions and 5 deletions

View File

@ -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();
}

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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: