comparison src/alsa-ng/alsa-core.c @ 3172:1b2350bdeaef

alsa-ng: Be less stupid if things don't open.
author William Pitcock <nenolod@atheme.org>
date Fri, 15 May 2009 16:06:55 -0500
parents 7e58928783b3
children 3fd0d762371c
comparison
equal deleted inserted replaced
3171:cb93b500a364 3172:1b2350bdeaef
181 181
182 static void 182 static void
183 alsaplug_close_audio(void) 183 alsaplug_close_audio(void)
184 { 184 {
185 g_mutex_lock(pcm_state_mutex); 185 g_mutex_lock(pcm_state_mutex);
186
186 pcm_going = FALSE; 187 pcm_going = FALSE;
187 g_mutex_unlock(pcm_state_mutex);
188 g_cond_broadcast(pcm_state_cond);
189
190 if (audio_thread != NULL)
191 g_thread_join(audio_thread);
192
193 audio_thread = NULL;
194 wr_total = 0; 188 wr_total = 0;
195 wr_hwframes = 0; 189 wr_hwframes = 0;
196 bps = 0; 190 bps = 0;
191
192 g_mutex_unlock(pcm_state_mutex);
193 g_cond_broadcast(pcm_state_cond);
194
195 if (audio_thread != NULL)
196 g_thread_join(audio_thread);
197
198 audio_thread = NULL;
197 } 199 }
198 200
199 static void 201 static void
200 alsaplug_write_audio(gpointer data, gint length) 202 alsaplug_write_audio(gpointer data, gint length)
201 { 203 {
204 g_mutex_lock(pcm_pause_mutex); 206 g_mutex_lock(pcm_pause_mutex);
205 g_cond_wait(pcm_pause_cond, pcm_pause_mutex); 207 g_cond_wait(pcm_pause_cond, pcm_pause_mutex);
206 g_mutex_unlock(pcm_pause_mutex); 208 g_mutex_unlock(pcm_pause_mutex);
207 } 209 }
208 210
211 g_mutex_lock(pcm_state_mutex);
209 wr_total += length; 212 wr_total += length;
210 alsaplug_ringbuffer_write(&pcm_ringbuf, data, length); 213 alsaplug_ringbuffer_write(&pcm_ringbuf, data, length);
214 g_mutex_unlock(pcm_state_mutex);
211 g_cond_broadcast(pcm_state_cond); 215 g_cond_broadcast(pcm_state_cond);
212 } 216 }
213 217
214 static gint 218 static gint
215 alsaplug_output_time(void) 219 alsaplug_output_time(void)
265 } 269 }
266 270
267 static gint 271 static gint
268 alsaplug_buffer_playing(void) 272 alsaplug_buffer_playing(void)
269 { 273 {
270 return alsaplug_ringbuffer_used(&pcm_ringbuf) != 0; 274 gint ret;
275
276 g_mutex_lock(pcm_state_mutex);
277
278 if (pcm_going == FALSE)
279 ret = 0;
280 else
281 ret = alsaplug_ringbuffer_used(&pcm_ringbuf) != 0;
282
283 g_mutex_unlock(pcm_state_mutex);
284
285 return ret;
271 } 286 }
272 287
273 static void 288 static void
274 alsaplug_pause(short p) 289 alsaplug_pause(short p)
275 { 290 {