1--- eflite-0.4.1.orig/fs.c
2+++ eflite-0.4.1/fs.c
3@@ -9,7 +9,7 @@
4 * GNU General Public License, as published by the Free Software
5 * Foundation. Please see the file COPYING for details.
6 *
7- * $Id: fs.c,v 1.19 2007/01/18 23:58:42 mgorse Exp $
8+ * $Id: fs.c,v 1.22 2008/03/05 15:21:43 mgorse Exp $
9 *
10 * Notes:
11 *
12@@ -505,19 +505,6 @@
13 }
14 }
15
16-
17-
18-static void play_audio_close(void *cancel)
19-{
20- if (audiodev)
21- {
22- audio_drain(audiodev);
23- close_audiodev();
24- // usleep(5000);
25- }
26-}
27-
28-
29 static inline void determine_playlen(int speed, cst_wave *wptr, int type, int *pl, int *s)
30 {
31 int playlen, skip;
32@@ -573,12 +560,12 @@
33 type = ac[ac_head].type;
34 WAVE_UNLOCK;
35 pthread_testcancel();
36- pthread_cleanup_push(play_audio_close, NULL);
37-
38+
39 es_log(2, "Opening audio device.");
40 /* We abuse the wave mutex here to avoid being canceled
41 * while the audio device is being openned */
42 WAVE_LOCK;
43+ assert(audiodev == NULL);
44 audiodev = audio_open(wptr->sample_rate, wptr->num_channels, CST_AUDIO_LINEAR16);
45 WAVE_UNLOCK;
46 if (audiodev == NULL)
47@@ -606,8 +593,8 @@
48 #ifdef DEBUG
49 start_time = get_ticks_count();
50 #endif
51- pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
52 audio_write(audiodev, wptr->samples + skip, playlen * 2);
53+ pthread_testcancel();
54 es_log(2, "Write took %.2f seconds.", get_ticks_count() - start_time);
55 }
56 es_log(2, "play: syncing.");
57@@ -617,16 +604,16 @@
58 audio_flush(audiodev);
59 pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
60 es_log(2, "Flush took %.2f seconds.", get_ticks_count() - start_time);
61- es_log(2, "play: Closing audio device");
62- close_audiodev();
63- pthread_cleanup_pop(0);
64- pthread_testcancel();
65- TEXT_LOCK;
66+ pthread_testcancel();
67+
68+ TEXT_LOCK;
69 time_left -= ((float)playlen) / wptr->sample_rate;
70 pthread_cond_signal(&text_condition);
71 TEXT_UNLOCK;
72
73 WAVE_LOCK;
74+ es_log(2, "play: Closing audio device");
75+ close_audiodev();
76 ac_destroy(&ac[ac_head]);
77 ac_head++;
78 if (ac_head == ac_tail)
79@@ -894,6 +881,7 @@
80 WAVE_LOCK_NI;
81 pthread_cond_signal(&wave_condition); // necessary because we inhibit cancellation while waiting
82 pthread_cancel(wave_thread);
83+ if (audiodev != NULL) audio_drain(audiodev);
84 WAVE_UNLOCK_NI;
85 }
86
87@@ -917,7 +905,10 @@
88 }
89
90 /* At this point, no thread is running */
91-
92+
93+ // Make sure audio device is closed
94+ close_audiodev();
95+
96 /* Free any wave data */
97 es_log(2, "s_clear: freeing wave data: %d", ac_tail);
98 for (i = 0; i < ac_tail; i++)