source: roaraudio/libroarpulse/simple.c @ 406:91700c05712e

Last change on this file since 406:91700c05712e was 406:91700c05712e, checked in by phi, 16 years ago

added basic code of pa_simple_new()

File size: 3.0 KB
Line 
1//simple.c:
2
3#include <libroarpulse/libroarpulse.h>
4
5/** Create a new connection to the server */
6pa_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    ) {
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
33 s->data_fh = roarfunc(ss->rate, ss->channels, 16 /* does PulseAudio support something diffrent? */,
34                       codec, (char*)server, (char*)name);
35
36 return (pa_simple*) s;
37}
38
39/** Close and free the connection to the server. The connection objects becomes invalid when this is called. */
40void pa_simple_free(pa_simple *s) {
41 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
42 if ( !s )
43  return;
44
45 close(ss->data_fh);
46
47 free(s);
48}
49
50/** Write some data to the server */
51int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) {
52 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
53 if ( !s )
54  return -1;
55
56 return read(ss->data_fh, (char*) data, length);
57}
58
59/** Wait until all data already written is played by the daemon */
60int pa_simple_drain(pa_simple *s, int *error) {
61// struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
62 if ( !s )
63  return -1;
64
65 pa_simple_flush(s, NULL);
66
67 return -1;
68}
69
70/** Read some data from the server */
71int pa_simple_read(pa_simple *s, void*data, size_t length, int *error) {
72 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
73 if ( !s )
74  return -1;
75
76 return read(ss->data_fh, data, length);
77}
78
79/** Return the playback latency. \since 0.5 */
80pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) {
81 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
82 if ( !s )
83  return -1;
84
85 return -1;
86}
87
88/** Flush the playback buffer. \since 0.5 */
89int pa_simple_flush(pa_simple *s, int *error) {
90 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
91 if ( !s )
92  return -1;
93
94 return fdatasync(ss->data_fh);
95}
96
97//ll
Note: See TracBrowser for help on using the repository browser.