From cf335a5dc4bf13bad4d739c2b558ee3d33d7749a Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 7 Mar 2015 20:39:25 +0300 Subject: [PATCH] Video freezing fixed --- rpcs3/Emu/SysCalls/Modules/cellDmux.cpp | 41 ++++++++++++++++++------- rpcs3/Emu/SysCalls/Modules/cellDmux.h | 2 ++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp index e9a9b7c72c..f5fc056ef9 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.cpp @@ -347,12 +347,18 @@ u32 dmuxOpen(Demuxer* dmux_ptr) if (!stream.peek(code)) { // demuxing finished + dmux.is_running = false; + + // callback auto dmuxMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE; dmuxMsg->supplementalInfo = stream.userdata; dmux.cbFunc(*dmux.dmuxCb, dmux.id, dmuxMsg, dmux.cbArg); - dmux.is_running = false; + dmux.is_working = false; + + stream = {}; + continue; } @@ -634,16 +640,20 @@ u32 dmuxOpen(Demuxer* dmux_ptr) case dmuxResetStream: case dmuxResetStreamAndWaitDone: { - auto dmuxMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); - dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE; - dmuxMsg->supplementalInfo = stream.userdata; - dmux.cbFunc(*dmux.dmuxCb, dmux.id, dmuxMsg, dmux.cbArg); + // demuxing stopped + if (dmux.is_running.exchange(false)) + { + // callback + auto dmuxMsg = vm::ptr::make(dmux.memAddr + (cb_add ^= 16)); + dmuxMsg->msgType = CELL_DMUX_MSG_TYPE_DEMUX_DONE; + dmuxMsg->supplementalInfo = stream.userdata; + dmux.cbFunc(*dmux.dmuxCb, dmux.id, dmuxMsg, dmux.cbArg); + + stream = {}; + + dmux.is_working = false; + } - stream = {}; - dmux.is_running = false; - //if (task.type == dmuxResetStreamAndWaitDone) - //{ - //} break; } @@ -926,8 +936,16 @@ int cellDmuxResetStreamAndWaitDone(u32 demuxerHandle) return CELL_DMUX_ERROR_ARG; } + if (!dmux->is_running) + { + return CELL_OK; + } + + dmux->is_working = true; + dmux->job.push(DemuxerTask(dmuxResetStreamAndWaitDone), &dmux->is_closed); - while (dmux->is_running && !dmux->is_closed) // TODO: ensure that it is safe + + while (dmux->is_running && dmux->is_working && !dmux->is_closed) // TODO: ensure that it is safe { if (Emu.IsStopped()) { @@ -936,6 +954,7 @@ int cellDmuxResetStreamAndWaitDone(u32 demuxerHandle) } std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack } + return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/Modules/cellDmux.h b/rpcs3/Emu/SysCalls/Modules/cellDmux.h index edca677727..5456db607f 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellDmux.h +++ b/rpcs3/Emu/SysCalls/Modules/cellDmux.h @@ -404,6 +404,7 @@ public: volatile bool is_finished; volatile bool is_closed; std::atomic is_running; + std::atomic is_working; PPUThread* dmuxCb; @@ -411,6 +412,7 @@ public: : is_finished(false) , is_closed(false) , is_running(false) + , is_working(false) , memAddr(addr) , memSize(size) , cbFunc(func)