Mercurial > audlegacy
comparison Plugins/Input/wav/wav-sndfile.c @ 264:852a1455dfb7 trunk
[svn] Use a mutex, lower timeouts. Do not spin waiting for playback to start.
author | chainsaw |
---|---|
date | Wed, 07 Dec 2005 16:54:27 -0800 |
parents | 256b3acc87d4 |
children | d55ffce8b1ba |
comparison
equal
deleted
inserted
replaced
263:ddb59458d7a9 | 264:852a1455dfb7 |
---|---|
39 static int bit_rate = 0; | 39 static int bit_rate = 0; |
40 static int decoding; | 40 static int decoding; |
41 static int seek_time = -1; | 41 static int seek_time = -1; |
42 | 42 |
43 static GThread *decode_thread; | 43 static GThread *decode_thread; |
44 | 44 GStaticMutex decode_mutex = G_STATIC_MUTEX_INIT; |
45 | 45 |
46 InputPlugin wav_ip = { | 46 InputPlugin wav_ip = { |
47 NULL, | 47 NULL, |
48 NULL, | 48 NULL, |
49 NULL, | 49 NULL, |
119 | 119 |
120 static void* | 120 static void* |
121 play_loop (void *arg) | 121 play_loop (void *arg) |
122 { static short buffer [BUFFER_SIZE]; | 122 { static short buffer [BUFFER_SIZE]; |
123 int samples; | 123 int samples; |
124 | |
125 g_static_mutex_lock(&decode_mutex); | |
124 | 126 |
125 decoding = TRUE; | 127 decoding = TRUE; |
126 while (decoding) | 128 while (decoding) |
127 { | 129 { |
128 /* sf_read_short will return 0 for all reads at EOF. */ | 130 /* sf_read_short will return 0 for all reads at EOF. */ |
130 | 132 |
131 if (samples > 0 && decoding) | 133 if (samples > 0 && decoding) |
132 { wav_ip.add_vis_pcm (wav_ip.output->written_time (), HOST_SIGNED_SHORT, sfinfo.channels, samples * sizeof (short), buffer); | 134 { wav_ip.add_vis_pcm (wav_ip.output->written_time (), HOST_SIGNED_SHORT, sfinfo.channels, samples * sizeof (short), buffer); |
133 | 135 |
134 while ((wav_ip.output->buffer_free () < (samples * sizeof (short))) && decoding) | 136 while ((wav_ip.output->buffer_free () < (samples * sizeof (short))) && decoding) |
135 xmms_usleep (80000); | 137 xmms_usleep (10000); |
136 | 138 |
137 wav_ip.output->write_audio (buffer, samples * sizeof (short)); | 139 wav_ip.output->write_audio (buffer, samples * sizeof (short)); |
138 } | 140 } |
139 else | 141 else |
140 xmms_usleep (80000); | 142 xmms_usleep (80000); |
146 seek_time = -1; | 148 seek_time = -1; |
147 }; | 149 }; |
148 | 150 |
149 }; /* while (decoding) */ | 151 }; /* while (decoding) */ |
150 | 152 |
153 g_static_mutex_unlock(&decode_mutex); | |
151 g_thread_exit (NULL); | 154 g_thread_exit (NULL); |
152 return NULL; | 155 return NULL; |
153 } /* play_loop */ | 156 } /* play_loop */ |
154 | 157 |
155 static void | 158 static void |
184 wav_ip.set_info (song_title, song_length, bit_rate, sfinfo.samplerate, sfinfo.channels); | 187 wav_ip.set_info (song_title, song_length, bit_rate, sfinfo.samplerate, sfinfo.channels); |
185 g_free (song_title); | 188 g_free (song_title); |
186 | 189 |
187 decode_thread = g_thread_create ((GThreadFunc)play_loop, NULL, TRUE, NULL); | 190 decode_thread = g_thread_create ((GThreadFunc)play_loop, NULL, TRUE, NULL); |
188 | 191 |
189 while (decoding == FALSE) | 192 xmms_usleep (40000); |
190 xmms_usleep (80000); | |
191 } /* play_start */ | 193 } /* play_start */ |
192 | 194 |
193 static void | 195 static void |
194 play_stop (void) | 196 play_stop (void) |
195 { | 197 { |