mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-16 02:59:49 +01:00
sceVideocodec: let stopping and deleting the decoder take time
Both are ME round-trips that take real time on hardware, and returning from them immediately matters beyond speed. Jak and Daxter deletes its video_sound_thread straight after sceVideocodecDelete without waiting for it to exit. With no time passing in the delete, the game's audio thread never gets to run once more and deliver the wake that lets that thread notice the shutdown and exit, so sceKernelDeleteThread fails with NOT_DORMANT and the thread stays alive. It is then released from the event flag the game has just deleted, resumes on a context that has already been freed - every id and pointer in it zero - and copies from a null pointer. 2ms, chosen to sit above the 1.45ms an audio mix block takes. 100us was measured to be too short, so the fix is the time passing rather than just the reschedule. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
dba91883ec
commit
21928ed43f
1 file changed
+11
-2
@@ -594,12 +594,21 @@ static int sceVideocodecDecode(u32 ctxAddr, int type) {
|
||||
type, auBytes, gotFrame ? "frame" : "no frame yet", width, height);
|
||||
}
|
||||
|
||||
// Stopping or deleting the decoder is an ME round-trip and takes real time on hardware. Returning
|
||||
// immediately matters beyond speed: a game can be relying on a thread of its own getting to run
|
||||
// once more before it tears things down. Jak and Daxter deletes its video_sound_thread straight
|
||||
// after sceVideocodecDelete without waiting for it to exit, and with no time passing here the audio
|
||||
// thread never gets to deliver the wake that would let it exit - so the delete fails with
|
||||
// NOT_DORMANT and the thread lives on, reading a context the game has already freed.
|
||||
// One audio mix block is 64 samples at 44100Hz, about 1.45ms, so stay above that.
|
||||
static const int videocodecTeardownDelayUs = 2000;
|
||||
|
||||
static int sceVideocodecStop(u32 ctxAddr, int type) {
|
||||
auto it = g_videocodecCtxs.find(ctxAddr);
|
||||
if (it != g_videocodecCtxs.end() && it->second.decoder) {
|
||||
it->second.decoder->Flush();
|
||||
}
|
||||
return hleLogInfo(Log::ME, 0);
|
||||
return hleDelayResult(hleLogInfo(Log::ME, 0), "videocodec stop", videocodecTeardownDelayUs);
|
||||
}
|
||||
|
||||
static int sceVideocodecDelete(u32 ctxAddr, int type) {
|
||||
@@ -608,7 +617,7 @@ static int sceVideocodecDelete(u32 ctxAddr, int type) {
|
||||
FreeContext(it->second);
|
||||
g_videocodecCtxs.erase(it);
|
||||
}
|
||||
return hleLogInfo(Log::ME, 0);
|
||||
return hleDelayResult(hleLogInfo(Log::ME, 0), "videocodec delete", videocodecTeardownDelayUs);
|
||||
}
|
||||
|
||||
static int sceVideocodecGetVersion(u32 ctxAddr, int type) {
|
||||
|
||||
Reference in new issue
Block a user