From 3d1e426e4a38570822cb58ddf09d96d114803d0d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 1 Jun 2013 14:53:07 -0700 Subject: [PATCH] Send games a free packet count that makes sense. --- Core/HLE/sceMpeg.cpp | 19 +++++++++++-------- Core/HW/MediaEngine.cpp | 5 +++-- Core/HW/MediaEngine.h | 4 +++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Core/HLE/sceMpeg.cpp b/Core/HLE/sceMpeg.cpp index 69d923948..d1c23cf2d 100644 --- a/Core/HLE/sceMpeg.cpp +++ b/Core/HLE/sceMpeg.cpp @@ -23,7 +23,8 @@ #include "sceKernelThread.h" #include "HLE.h" #include "../HW/MediaEngine.h" -#include "../../Core/Config.h" +#include "Core/Config.h" +#include "Core/Reporting.h" static bool useMediaEngine; @@ -193,7 +194,7 @@ MpegContext *getMpegCtx(u32 mpegAddr) { // TODO: Remove. if (mpegMap.find(mpeg) == mpegMap.end()) { - ERROR_LOG(HLE, "Bad mpeg handle %08x - using last one (%08x) instead", mpeg, lastMpegHandle); + ERROR_LOG_REPORT(HLE, "Bad mpeg handle %08x - using last one (%08x) instead", mpeg, lastMpegHandle); mpeg = lastMpegHandle; } @@ -633,7 +634,7 @@ u32 sceMpegAvcDecode(u32 mpeg, u32 auAddr, u32 frameWidth, u32 bufferAddr, u32 i if (ctx->mediaengine->stepVideo()) { ctx->mediaengine->writeVideoImage(Memory::GetPointer(buffer), frameWidth, ctx->videoPixelMode); } - ringbuffer.packetsFree = std::min(16, ctx->mediaengine->getRemainSize() / 2048); + ringbuffer.packetsFree = std::max(0, ringbuffer.packets - ctx->mediaengine->getBufferedSize() / 2048); avcAu.pts = ctx->mediaengine->getVideoTimeStamp(); @@ -779,7 +780,7 @@ int sceMpegAvcDecodeYCbCr(u32 mpeg, u32 auAddr, u32 bufferAddr, u32 initAddr) ; } - ringbuffer.packetsFree = std::min(16, ctx->mediaengine->getRemainSize() / 2048); + ringbuffer.packetsFree = std::max(0, ringbuffer.packets - ctx->mediaengine->getBufferedSize() / 2048); avcAu.pts = ctx->mediaengine->getVideoTimeStamp(); ctx->avc.avcFrameStatus = 1; @@ -886,13 +887,15 @@ void PostPutAction::run(MipsCall &call) { WARN_LOG(HLE, "sceMpegRingbufferPut clamping packetsAdded old=%i new=%i", packetsAdded, ringbuffer.packetsFree); packetsAdded = ringbuffer.packetsFree; } - ctx->mediaengine->addStreamData(Memory::GetPointer(ringbuffer.data), packetsAdded * 2048); + int actuallyAdded = ctx->mediaengine->addStreamData(Memory::GetPointer(ringbuffer.data), packetsAdded * 2048) / 2048; + if (actuallyAdded != packetsAdded) { + WARN_LOG_REPORT(HLE, "sceMpegRingbufferPut(): unable to enqueue all added packets, going to overwrite some frames."); + } ringbuffer.packetsRead += packetsAdded; ringbuffer.packetsWritten += packetsAdded; - //ringbuffer.packetsFree = std::min(16, ctx->mediaengine->getRemainSize() / 2048); - ringbuffer.packetsFree = 0; + ringbuffer.packetsFree -= packetsAdded; } - DEBUG_LOG(HLE, "packetAdded: %i packetsRead: %i packetsTotol: %i", packetsAdded, ringbuffer.packetsRead, ringbuffer.packets); + DEBUG_LOG(HLE, "packetAdded: %i packetsRead: %i packetsTotal: %i", packetsAdded, ringbuffer.packetsRead, ringbuffer.packets); Memory::WriteStruct(ringAddr_, &ringbuffer); call.setReturnValue(packetsAdded); diff --git a/Core/HW/MediaEngine.cpp b/Core/HW/MediaEngine.cpp index ca18719b8..45bb7e66f 100644 --- a/Core/HW/MediaEngine.cpp +++ b/Core/HW/MediaEngine.cpp @@ -178,7 +178,7 @@ bool MediaEngine::openContext() { av_dump_format(pFormatCtx, 0, NULL, 0); // Find the first video stream - for(int i = 0; i < pFormatCtx->nb_streams; i++) { + for(int i = 0; i < (int)pFormatCtx->nb_streams; i++) { if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) { m_videoStream = i; break; @@ -259,7 +259,7 @@ bool MediaEngine::loadFile(const char* filename) return true; } -void MediaEngine::addStreamData(u8* buffer, int addSize) { +int MediaEngine::addStreamData(u8* buffer, int addSize) { int size = std::min(addSize, m_streamSize - m_readSize); if (size > 0) { memcpy(m_pdata + m_readSize, buffer, size); @@ -271,6 +271,7 @@ void MediaEngine::addStreamData(u8* buffer, int addSize) { m_demux->demux(); } } + return size; } bool MediaEngine::setVideoDim(int width, int height) diff --git a/Core/HW/MediaEngine.h b/Core/HW/MediaEngine.h index e10147748..27f42d626 100644 --- a/Core/HW/MediaEngine.h +++ b/Core/HW/MediaEngine.h @@ -39,8 +39,10 @@ public: void closeMedia(); bool loadStream(u8* buffer, int readSize, int StreamSize); bool loadFile(const char* filename); - void addStreamData(u8* buffer, int addSize); + // Returns number of packets actually added. + int addStreamData(u8* buffer, int addSize); int getRemainSize() { return m_streamSize - m_readSize;} + int getBufferedSize() { return m_readSize - m_decodePos; } bool stepVideo(); bool writeVideoImage(u8* buffer, int frameWidth = 512, int videoPixelMode = 3);