From 4cd7c28bb422531dd0ebbfa01d1fb234d861a573 Mon Sep 17 00:00:00 2001 From: dborth Date: Sat, 13 Jun 2009 08:40:45 +0000 Subject: [PATCH] fix long-standing menu "random" lockup/crashing bug. caused by Hermes' oggplayer threading. oggplayer rewritten. --- source/ngc/audio.cpp | 10 +++++++--- source/ngc/oggplayer.c | 28 ++++++++++++++++------------ source/ngc/snes9xGX.cpp | 3 --- source/ngc/video.cpp | 8 -------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/source/ngc/audio.cpp b/source/ngc/audio.cpp index b99f7c9..3789a98 100644 --- a/source/ngc/audio.cpp +++ b/source/ngc/audio.cpp @@ -91,6 +91,11 @@ GCMixSamples () void InitAudio () { + #ifdef NO_SOUND + AUDIO_Init (NULL); + #else + ASND_Init(); + #endif LWP_CreateThread (&athread, AudioThread, NULL, astack, AUDIOSTACK, 100); } @@ -106,17 +111,16 @@ SwitchAudioMode(int mode) { #ifndef NO_SOUND ASND_Pause(1); - ASND_End(); #endif + AUDIO_StopDMA(); AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ); AUDIO_RegisterDMACallback(GCMixSamples); } else // menu { AUDIO_StopDMA(); - AUDIO_RegisterDMACallback(NULL); #ifndef NO_SOUND - ASND_Init(); + ASND_SetDMACallback(); ASND_Pause(0); #endif } diff --git a/source/ngc/oggplayer.c b/source/ngc/oggplayer.c index 83f2518..a84a17f 100644 --- a/source/ngc/oggplayer.c +++ b/source/ngc/oggplayer.c @@ -2,6 +2,8 @@ Copyright (c) 2008 Francisco Muņoz 'Hermes' All rights reserved. + Threading modifications/corrections by Tantric, 2009 + Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -61,8 +63,8 @@ static private_data_ogg private_ogg; #define STACKSIZE 8192 static u8 oggplayer_stack[STACKSIZE]; -static lwpq_t oggplayer_queue; -static lwp_t h_oggplayer; +static lwpq_t oggplayer_queue = LWP_TQUEUE_NULL; +static lwp_t h_oggplayer = LWP_THREAD_NULL; static int ogg_thread_running = 0; static void ogg_add_callback(int voice) @@ -154,7 +156,6 @@ static void * ogg_player_thread(private_data_ogg * priv) ov_time_seek(&priv[0].vf, 0); // repeat else priv[0].eof = 1; // stops - // } else if (ret < 0) { @@ -205,12 +206,8 @@ static void * ogg_player_thread(private_data_ogg * priv) priv[0].flag = 0; } } - else - { - // if(priv[0].pcm_indx==0) priv[0].flag=0; // all samples sended - } - } + usleep(100); } ov_clear(&priv[0].vf); priv[0].fd = -1; @@ -222,11 +219,19 @@ static void * ogg_player_thread(private_data_ogg * priv) void StopOgg() { ASND_StopVoice(0); - if (ogg_thread_running > 0) + ogg_thread_running = 0; + + if(h_oggplayer != LWP_THREAD_NULL) { - ogg_thread_running = 0; - LWP_ThreadSignal(oggplayer_queue); + if(oggplayer_queue != LWP_TQUEUE_NULL) + LWP_ThreadSignal(oggplayer_queue); LWP_JoinThread(h_oggplayer, NULL); + h_oggplayer = LWP_THREAD_NULL; + } + if(oggplayer_queue != LWP_TQUEUE_NULL) + { + LWP_CloseQueue(oggplayer_queue); + oggplayer_queue = LWP_TQUEUE_NULL; } } @@ -285,7 +290,6 @@ void PauseOgg(int pause) LWP_ThreadSignal(oggplayer_queue); } } - } } diff --git a/source/ngc/snes9xGX.cpp b/source/ngc/snes9xGX.cpp index 9b0f906..b918742 100644 --- a/source/ngc/snes9xGX.cpp +++ b/source/ngc/snes9xGX.cpp @@ -407,9 +407,6 @@ main(int argc, char *argv[]) // Initialize libFAT for SD and USB MountAllFAT(); - // Audio - AUDIO_Init (NULL); - // Set defaults DefaultSettings (); diff --git a/source/ngc/video.cpp b/source/ngc/video.cpp index 10cf57a..19770dd 100644 --- a/source/ngc/video.cpp +++ b/source/ngc/video.cpp @@ -267,7 +267,6 @@ static GXRModeObj *tvmodes[4] = { * VideoThreading ***************************************************************************/ #define TSTACK 16384 -static lwpq_t videoblankqueue; static lwp_t vbthread = LWP_THREAD_NULL; static unsigned char vbstack[TSTACK]; @@ -294,17 +293,10 @@ vbgetback (void *arg) /**************************************************************************** * InitVideoThread - * - * libOGC provides a nice wrapper for LWP access. - * This function sets up a new local queue and attaches the thread to it. ***************************************************************************/ void InitVideoThread () { - /*** Initialise a new queue ***/ - LWP_InitQueue (&videoblankqueue); - - /*** Create the thread on this queue ***/ LWP_CreateThread (&vbthread, vbgetback, NULL, vbstack, TSTACK, 100); }