[398] | 1 | //simple.c: |
---|
| 2 | |
---|
| 3 | #include <libroarpulse/libroarpulse.h> |
---|
| 4 | |
---|
[402] | 5 | /** Create a new connection to the server */ |
---|
| 6 | pa_simple* pa_simple_new( |
---|
| 7 | const char *server, /**< Server name, or NULL for default */ |
---|
| 8 | const char *name, /**< A descriptive name for this client (application name, ...) */ |
---|
| 9 | pa_stream_direction_t dir, /**< Open this stream for recording or playback? */ |
---|
| 10 | const char *dev, /**< Sink (resp. source) name, or NULL for default */ |
---|
| 11 | const char *stream_name, /**< A descriptive name for this client (application name, song title, ...) */ |
---|
| 12 | const pa_sample_spec *ss, /**< The sample type to use */ |
---|
| 13 | const pa_channel_map *map, /**< The channel map to use, or NULL for default */ |
---|
| 14 | const pa_buffer_attr *attr, /**< Buffering attributes, or NULL for default */ |
---|
| 15 | int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */ |
---|
| 16 | ) { |
---|
[406] | 17 | struct roarpulse_simple * s = malloc(sizeof(struct roarpulse_simple)); |
---|
| 18 | int (*roarfunc)(int rate, int channels, int bits, int codec, char * server, char * name) = roar_simple_play; |
---|
| 19 | int codec = -1; |
---|
| 20 | |
---|
| 21 | if ( !s ) |
---|
| 22 | return NULL; |
---|
| 23 | |
---|
| 24 | if ( dir == PA_STREAM_PLAYBACK ) { |
---|
| 25 | roarfunc = roar_simple_play; |
---|
| 26 | } else if ( dir == PA_STREAM_RECORD ) { |
---|
| 27 | roarfunc = roar_simple_record; |
---|
| 28 | } else { |
---|
| 29 | free(s); |
---|
| 30 | return NULL; |
---|
| 31 | } |
---|
| 32 | |
---|
[410] | 33 | codec = roar_codec_pulse2roar(ss->format); |
---|
| 34 | |
---|
[406] | 35 | s->data_fh = roarfunc(ss->rate, ss->channels, 16 /* does PulseAudio support something diffrent? */, |
---|
| 36 | codec, (char*)server, (char*)name); |
---|
| 37 | |
---|
| 38 | return (pa_simple*) s; |
---|
[402] | 39 | } |
---|
| 40 | |
---|
| 41 | /** Close and free the connection to the server. The connection objects becomes invalid when this is called. */ |
---|
| 42 | void pa_simple_free(pa_simple *s) { |
---|
[404] | 43 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
| 44 | if ( !s ) |
---|
| 45 | return; |
---|
| 46 | |
---|
[405] | 47 | close(ss->data_fh); |
---|
| 48 | |
---|
[404] | 49 | free(s); |
---|
[402] | 50 | } |
---|
| 51 | |
---|
| 52 | /** Write some data to the server */ |
---|
| 53 | int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) { |
---|
[404] | 54 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
| 55 | if ( !s ) |
---|
| 56 | return -1; |
---|
| 57 | |
---|
[411] | 58 | return write(ss->data_fh, (char*) data, length); |
---|
[402] | 59 | } |
---|
| 60 | |
---|
| 61 | /** Wait until all data already written is played by the daemon */ |
---|
| 62 | int pa_simple_drain(pa_simple *s, int *error) { |
---|
[405] | 63 | // struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
[404] | 64 | if ( !s ) |
---|
| 65 | return -1; |
---|
| 66 | |
---|
[405] | 67 | pa_simple_flush(s, NULL); |
---|
| 68 | |
---|
[402] | 69 | return -1; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | /** Read some data from the server */ |
---|
| 73 | int pa_simple_read(pa_simple *s, void*data, size_t length, int *error) { |
---|
[404] | 74 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
| 75 | if ( !s ) |
---|
| 76 | return -1; |
---|
| 77 | |
---|
[405] | 78 | return read(ss->data_fh, data, length); |
---|
[402] | 79 | } |
---|
| 80 | |
---|
| 81 | /** Return the playback latency. \since 0.5 */ |
---|
| 82 | pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) { |
---|
[404] | 83 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
| 84 | if ( !s ) |
---|
| 85 | return -1; |
---|
| 86 | |
---|
[402] | 87 | return -1; |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | /** Flush the playback buffer. \since 0.5 */ |
---|
| 91 | int pa_simple_flush(pa_simple *s, int *error) { |
---|
[404] | 92 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
| 93 | if ( !s ) |
---|
| 94 | return -1; |
---|
| 95 | |
---|
| 96 | return fdatasync(ss->data_fh); |
---|
[402] | 97 | } |
---|
| 98 | |
---|
[398] | 99 | //ll |
---|