| 1 |
#include "allegro5/allegro.h" |
| 2 |
#include "allegro5/allegro_audio.h" |
| 3 |
#include "allegro5/internal/aintern.h" |
| 4 |
#include "allegro5/internal/aintern_audio.h" |
| 5 |
#include "helper.h" |
| 6 |
|
| 7 |
void _al_acodec_start_feed_thread(ALLEGRO_AUDIO_STREAM *stream) |
| 8 |
{ |
| 9 |
stream->feed_thread = al_create_thread(_al_kcm_feed_stream, stream); |
| 10 |
stream->feed_thread_started_cond = al_create_cond(); |
| 11 |
stream->feed_thread_started_mutex = al_create_mutex(); |
| 12 |
al_start_thread(stream->feed_thread); |
| 13 |
|
| 14 |
/* Need to wait for the thread to start, otherwise the quit event may be |
| 15 |
* sent before the event source is registered with the queue. |
| 16 |
* |
| 17 |
* This also makes the pre-fill system thread safe, as it needs to operate |
| 18 |
* before the mutexes are set up. |
| 19 |
*/ |
| 20 |
al_lock_mutex(stream->feed_thread_started_mutex); |
| 21 |
while (!stream->feed_thread_started) { |
| 22 |
al_wait_cond(stream->feed_thread_started_cond, stream->feed_thread_started_mutex); |
| 23 |
} |
| 24 |
al_unlock_mutex(stream->feed_thread_started_mutex); |
| 25 |
} |
| 26 |
|
| 27 |
void _al_acodec_stop_feed_thread(ALLEGRO_AUDIO_STREAM *stream) |
| 28 |
{ |
| 29 |
ALLEGRO_EVENT quit_event; |
| 30 |
|
| 31 |
quit_event.type = _KCM_STREAM_FEEDER_QUIT_EVENT_TYPE; |
| 32 |
al_emit_user_event(al_get_audio_stream_event_source(stream), &quit_event, NULL); |
| 33 |
al_join_thread(stream->feed_thread, NULL); |
| 34 |
al_destroy_thread(stream->feed_thread); |
| 35 |
al_destroy_cond(stream->feed_thread_started_cond); |
| 36 |
al_destroy_mutex(stream->feed_thread_started_mutex); |
| 37 |
|
| 38 |
stream->feed_thread = NULL; |
| 39 |
} |