Mpeg:Checks autual available space before putting data.

This commit is contained in:
shenweip 2020-11-23 15:24:03 +08:00
parent ded92e51dd
commit 3380d31974

View File

@ -1507,15 +1507,6 @@ void PostPutAction::run(MipsCall &call) {
// Program signals that it has written data to the ringbuffer and gets a callback ?
static u32 sceMpegRingbufferPut(u32 ringbufferAddr, int numPackets, int available)
{
// Generally, program will call sceMpegRingbufferAvailableSize() before this func.
// Still need to check available?
numPackets = std::min(numPackets, available);
if (numPackets <= 0) {
DEBUG_LOG(ME, "sceMpegRingbufferPut(%08x, %i, %i): no packets to enqueue", ringbufferAddr, numPackets, available);
return 0;
}
auto ringbuffer = PSPPointer<SceMpegRingBuffer>::Create(ringbufferAddr);
if (!ringbuffer.IsValid()) {
// Would have crashed before, TODO test behavior.
@ -1523,6 +1514,15 @@ static u32 sceMpegRingbufferPut(u32 ringbufferAddr, int numPackets, int availabl
return -1;
}
numPackets = std::min(numPackets, available);
// Generally, program will call sceMpegRingbufferAvailableSize() before this func.
// Seems still need to check actual available, Patapon 3 for example.
numPackets = std::min(numPackets, ringbuffer->packets - ringbuffer->packetsAvail);
if (numPackets <= 0) {
DEBUG_LOG(ME, "sceMpegRingbufferPut(%08x, %i, %i): no packets to enqueue", ringbufferAddr, numPackets, available);
return 0;
}
MpegContext *ctx = getMpegCtx(ringbuffer->mpeg);
if (!ctx) {
WARN_LOG(ME, "sceMpegRingbufferPut(%08x, %i, %i): bad mpeg handle %08x", ringbufferAddr, numPackets, available, ringbuffer->mpeg);