Skip to content

Commit

Permalink
Revert "Mpeg: Write into the ringbuffer using actual ring."
Browse files Browse the repository at this point in the history
This revert
hrydgard@41f2999
  • Loading branch information
sum2012 committed Jun 10, 2018
1 parent 6c494c3 commit b7c2ef5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions Core/HLE/sceMpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static MpegContext *getMpegCtx(u32 mpegAddr) {
static void InitRingbuffer(SceMpegRingBuffer *buf, int packets, int data, int size, int callback_addr, int callback_args) {
buf->packets = packets;
buf->packetsRead = 0;
buf->packetsWritePos = 0;
buf->packetsWritten = 0;
buf->packetsAvail = 0;
buf->packetSize = 2048;
buf->data = data;
Expand Down Expand Up @@ -1429,9 +1429,6 @@ void PostPutAction::run(MipsCall &call) {
auto ringbuffer = PSPPointer<SceMpegRingBuffer>::Create(ringAddr_);

MpegContext *ctx = getMpegCtx(ringbuffer->mpeg);
int writeOffset = ringbuffer->packetsWritePos % (s32)ringbuffer->packets;
const u8 *data = Memory::GetPointer(ringbuffer->data + writeOffset * 2048);

int packetsAdded = currentMIPS->r[MIPS_REG_V0];

// It seems validation is done only by older mpeg libs.
Expand All @@ -1456,7 +1453,7 @@ void PostPutAction::run(MipsCall &call) {

if (mpegLibVersion <= 0x0103) {
// Act like they were actually added, but don't increment read pos.
ringbuffer->packetsWritePos += packetsAdded;
ringbuffer->packetsWritten += packetsAdded;
ringbuffer->packetsAvail += packetsAdded;
}
return;
Expand All @@ -1472,13 +1469,13 @@ void PostPutAction::run(MipsCall &call) {
if (packetsAdded > ringbuffer->packets - ringbuffer->packetsAvail) {
WARN_LOG(ME, "sceMpegRingbufferPut clamping packetsAdded old=%i new=%i", packetsAdded, ringbuffer->packets - ringbuffer->packetsAvail);
packetsAdded = ringbuffer->packets - ringbuffer->packetsAvail;
}
int actuallyAdded = ctx->mediaengine == NULL ? 8 : ctx->mediaengine->addStreamData(data, packetsAdded * 2048) / 2048;
}
int actuallyAdded = ctx->mediaengine == NULL ? 8 : ctx->mediaengine->addStreamData(Memory::GetPointer(ringbuffer->data), packetsAdded * 2048) / 2048;
if (actuallyAdded != packetsAdded) {
WARN_LOG_REPORT(ME, "sceMpegRingbufferPut(): unable to enqueue all added packets, going to overwrite some frames.");
}
ringbuffer->packetsRead += packetsAdded;
ringbuffer->packetsWritePos += packetsAdded;
ringbuffer->packetsWritten += packetsAdded;
ringbuffer->packetsAvail += packetsAdded;
}
DEBUG_LOG(ME, "packetAdded: %i packetsRead: %i packetsTotal: %i", packetsAdded, ringbuffer->packetsRead, ringbuffer->packets);
Expand Down Expand Up @@ -1518,9 +1515,8 @@ static u32 sceMpegRingbufferPut(u32 ringbufferAddr, int numPackets, int availabl
// TODO: Should call this multiple times until we get numPackets.
// Normally this would be if it did not read enough, but also if available > packets.
// Should ultimately return the TOTAL number of returned packets.
int writeOffset = ringbuffer->packetsWritePos % (s32)ringbuffer->packets;
u32 packetsThisRound = std::min(numPackets, (s32)ringbuffer->packets - writeOffset);
u32 args[3] = {(u32)ringbuffer->data + (u32)writeOffset * 2048, packetsThisRound, (u32)ringbuffer->callback_args};
u32 packetsThisRound = std::min(numPackets, (s32)ringbuffer->packets);
u32 args[3] = { (u32)ringbuffer->data, packetsThisRound, (u32)ringbuffer->callback_args};
__KernelDirectMipsCall(ringbuffer->callback_addr, action, args, 3, false);
} else {
ERROR_LOG_REPORT(ME, "sceMpegRingbufferPut: callback_addr zero");
Expand Down Expand Up @@ -1846,7 +1842,7 @@ static u32 sceMpegFlushAllStream(u32 mpeg)
if (ringbuffer.IsValid()) {
ringbuffer->packetsAvail = 0;
ringbuffer->packetsRead = 0;
ringbuffer->packetsWritePos = 0;
ringbuffer->packetsWritten = 0;
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceMpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct SceMpegRingBuffer {
s32_le packets;
// Misused: this is used as total read, but should be read offset (within ring.)
s32_le packetsRead;
s32_le packetsWritePos;
s32_le packetsWritten;
s32_le packetsAvail; // pspsdk: unk2, noxa: iUnk0
s32_le packetSize; // 2048
u32_le data; // address, ring buffer
Expand Down

0 comments on commit b7c2ef5

Please sign in to comment.