source: roaraudio/libroarpulse/simple.c @ 418:f60d587b5195

Last change on this file since 418:f60d587b5195 was 418:f60d587b5195, checked in by phi, 16 years ago

update meta data only in case of stream_name set, and accept $PULSE_SERVER

File size: 3.5 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 roar_dir;
19 int codec = -1;
20 struct roar_meta meta;
21
22 if ( !s )
23  return NULL;
24
25 if ( dir == PA_STREAM_PLAYBACK ) {
26  roar_dir = ROAR_DIR_PLAY;
27 } else if ( dir == PA_STREAM_RECORD ) {
28  roar_dir = ROAR_DIR_RECORD;
29 } else {
30  free(s);
31  return NULL;
32 }
33
34 codec = roar_codec_pulse2roar(ss->format);
35
36 if ( !server )
37  server = getenv("PULSE_SERVER");
38
39 if ( roar_simple_connect(&(s->con), (char*)server, (char*)name) == -1 ) {
40  free(s);
41  return NULL;
42 }
43
44 s->data_fh = roar_simple_new_stream_obj(&(s->con), &(s->stream), ss->rate, ss->channels,
45                  16 /* does PulseAudio support something diffrent? */, codec, roar_dir);
46
47 if ( s->data_fh == -1 ) {
48  roar_disconnect(&(s->con));
49  free(s);
50  return NULL;
51 }
52
53 if ( stream_name && stream_name[0] != 0 ) {
54  meta.value  = (char*)stream_name;
55  meta.key[0] = 0;
56  meta.type   = ROAR_META_TYPE_DESCRIPTION;
57
58  roar_stream_meta_set(&(s->con), &(s->stream), ROAR_META_MODE_SET, &meta);
59 }
60
61 return (pa_simple*) s;
62}
63
64/** Close and free the connection to the server. The connection objects becomes invalid when this is called. */
65void pa_simple_free(pa_simple *s) {
66 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
67 if ( !s )
68  return;
69
70 close(ss->data_fh);
71 roar_disconnect(&(ss->con));
72
73 free(s);
74}
75
76/** Write some data to the server */
77int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) {
78 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
79 if ( !s )
80  return -1;
81
82 return write(ss->data_fh, (char*) data, length);
83}
84
85/** Wait until all data already written is played by the daemon */
86int pa_simple_drain(pa_simple *s, int *error) {
87// struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
88 if ( !s )
89  return -1;
90
91 pa_simple_flush(s, NULL);
92
93 return -1;
94}
95
96/** Read some data from the server */
97int pa_simple_read(pa_simple *s, void*data, size_t length, int *error) {
98 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
99 if ( !s )
100  return -1;
101
102 return read(ss->data_fh, data, length);
103}
104
105/** Return the playback latency. \since 0.5 */
106pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) {
107 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
108 if ( !s )
109  return -1;
110
111 return -1;
112}
113
114/** Flush the playback buffer. \since 0.5 */
115int pa_simple_flush(pa_simple *s, int *error) {
116 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
117 if ( !s )
118  return -1;
119
120 return fdatasync(ss->data_fh);
121}
122
123//ll
Note: See TracBrowser for help on using the repository browser.