Mercurial > hg > xmms-sid
diff src/xmms-sid.c @ 75:653c9b0d1320
SIDPlay2 support "works" now. Borked problems with threads.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 15 Sep 2003 11:10:03 +0000 |
parents | 8cb66a3f75f7 |
children | ab522ab65c85 |
line wrap: on
line diff
--- a/src/xmms-sid.c Sun Sep 14 18:51:05 2003 +0000 +++ b/src/xmms-sid.c Mon Sep 15 11:10:03 2003 +0000 @@ -136,12 +136,10 @@ memset(&xs_cfg, 0, sizeof(xs_cfg)); xs_read_configuration(); - /* Initialize status */ memset(&xs_status, 0, sizeof(xs_status)); xs_status.allowNext = TRUE; - /* Try to initialize emulator engine */ XSDEBUG("initializing emulator engine...\n"); @@ -249,30 +247,17 @@ void *xs_play_loop(void *argPointer) { t_xs_status myStatus; - gboolean audioOpen; + gboolean audioOpen, doPlay; gint audioFreq, audioChannels, songLength, audioFmt; gchar audioBuffer[XS_BUFSIZE]; - + /* Initialize */ pthread_mutex_lock(&xs_mutex); XSDEBUG("entering play thread\n"); - - /* No idea, if this is really required here, but better be - * careful since we're dealing with EVIL threads ... - */ - if (!xs_status.allowNext) - { - pthread_mutex_unlock(&xs_mutex); - pthread_exit(NULL); - } - - /* Don't allow next song to be set yet */ - xs_status.allowNext = FALSE; xs_status.isPlaying = TRUE; memcpy(&myStatus, &xs_status, sizeof(t_xs_status)); pthread_mutex_unlock(&xs_mutex); - /* Copy and check audio options here (they might change in config while running) */ #ifdef HAVE_UNSIGNEDPCM audioFmt = (xs_cfg.fmtBitsPerSample == XS_RES_16BIT) ? FMT_U16_NE : FMT_U8; @@ -286,11 +271,13 @@ /* * Main player loop: while not stopped, loop here - play subtunes */ - while (xs_status.isPlaying) + doPlay = TRUE; + while (xs_status.isPlaying && doPlay) { pthread_mutex_lock(&xs_mutex); myStatus.currSong = xs_status.currSong; myStatus.isPlaying = TRUE; + xs_status.allowNext = TRUE; pthread_mutex_unlock(&xs_mutex); XSDEBUG("subtune #%i selected, initializing...\n", myStatus.currSong); @@ -384,33 +371,32 @@ } /* Now determine if we continue by selecting other subtune or something */ - if (!myStatus.isPlaying) xs_status.isPlaying = FALSE; + if (!myStatus.isPlaying) doPlay = FALSE; } - /* When exiting, delete data */ err_exit: - pthread_mutex_lock(&xs_mutex); - xs_status.isPlaying = FALSE; - pthread_mutex_unlock(&xs_mutex); - + /* Close audio */ if (audioOpen) { XSDEBUG("close audio #2\n"); xs_plugin_ip.output->close_audio(); } - xs_player->plrDeleteSID(&myStatus); - /* Exit the playing thread */ XSDEBUG("exiting thread, bye.\n"); - /* Last thing we do is set allowNext to TRUE to flag - * that we have ended all action in the thread - */ pthread_mutex_lock(&xs_mutex); + xs_player->plrDeleteSID(&myStatus); + + if (xs_status.currFileName) + { + g_free(xs_status.currFileName); + xs_status.currFileName = NULL; + } + + xs_status.isPlaying = FALSE; xs_status.allowNext = TRUE; pthread_mutex_unlock(&xs_mutex); - pthread_exit(NULL); } @@ -420,10 +406,24 @@ */ void xs_play_file(gchar *pcFileName) { + while (!xs_status.allowNext) usleep(5000); + + pthread_mutex_lock(&xs_mutex); + xs_status.allowNext = FALSE; + pthread_mutex_unlock(&xs_mutex); + + fprintf(stderr, "\n\n"); + XSDEBUG("play '%s'\n", pcFileName); + /* Initialize the tune */ if (!xs_player->plrLoadSID(&xs_status, pcFileName)) return; + /* Set general status information */ + xs_status.isPlaying = FALSE; + xs_status.isError = FALSE; + xs_status.currFileName = g_strdup(pcFileName); + /* Start the playing thread! */ if (pthread_create(&xs_decode_thread, NULL, xs_play_loop, NULL) < 0) { @@ -442,6 +442,7 @@ { /* If playing, stop. */ XSDEBUG("STOP_REQ\n"); + if (xs_status.isPlaying) { XSDEBUG("stopping...\n"); @@ -450,6 +451,7 @@ pthread_mutex_unlock(&xs_mutex); pthread_join(xs_decode_thread, NULL); } + } @@ -490,7 +492,7 @@ return -2; /* If tune has ended, return -1 */ - if (xs_status.allowNext && !xs_status.isPlaying) + if (!xs_status.isPlaying) return -1; /* Obsolete? */