fix long-standing menu "random" lockup/crashing bug. caused by Hermes' oggplayer threading. oggplayer rewritten.

This commit is contained in:
dborth 2009-06-13 08:40:45 +00:00
parent 96e0fda747
commit 4cd7c28bb4
4 changed files with 23 additions and 26 deletions

View File

@ -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
}

View File

@ -2,6 +2,8 @@
Copyright (c) 2008 Francisco Muñoz 'Hermes' <www.elotrolado.net>
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)
{
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);
}
}
}
}

View File

@ -407,9 +407,6 @@ main(int argc, char *argv[])
// Initialize libFAT for SD and USB
MountAllFAT();
// Audio
AUDIO_Init (NULL);
// Set defaults
DefaultSettings ();

View File

@ -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);
}