1 #ifndef BUF_H 2 #define BUF_H 3 4 #include <pthread.h> 5 #include "fifo_buf.h" 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 typedef void (out_buf_free_callback)(); 12 13 struct out_buf 14 { 15 struct fifo_buf buf; 16 pthread_mutex_t mutex; 17 pthread_t tid; /* Thread id of the reading thread. */ 18 19 /* Signals. */ 20 pthread_cond_t play_cond; /* Something was written to the buffer. */ 21 pthread_cond_t ready_cond; /* There is some space in the buffer. */ 22 23 /* Optional callback called when there is some free space in 24 * the buffer. */ 25 out_buf_free_callback *free_callback; 26 27 /* State flags of the buffer. */ 28 int pause; 29 int exit; /* Exit when the buffer is empty. */ 30 int stop; /* Don't play anything. */ 31 32 int reset_dev; /* Request to the reading thread to reset the audio 33 device. */ 34 35 float time; /* Time of played sound. */ 36 int hardware_buf_fill; /* How the sound card buffer is filled. */ 37 38 int read_thread_waiting; /* Is the read thread waiting for data? */ 39 }; 40 41 void out_buf_init (struct out_buf *buf, int size); 42 void out_buf_destroy (struct out_buf *buf); 43 int out_buf_put (struct out_buf *buf, const char *data, int size); 44 void out_buf_pause (struct out_buf *buf); 45 void out_buf_unpause (struct out_buf *buf); 46 void out_buf_stop (struct out_buf *buf); 47 void out_buf_reset (struct out_buf *buf); 48 void out_buf_time_set (struct out_buf *buf, const float time); 49 int out_buf_time_get (struct out_buf *buf); 50 void out_buf_set_free_callback (struct out_buf *buf, 51 out_buf_free_callback callback); 52 int out_buf_get_free (struct out_buf *buf); 53 int out_buf_get_fill (struct out_buf *buf); 54 void out_buf_wait (struct out_buf *buf); 55 56 #ifdef __cplusplus 57 } 58 #endif 59 60 #endif 61