source: roaraudio/libroarpulse/simple.c @ 416:3c1e97685b59

Last change on this file since 416:3c1e97685b59 was 416:3c1e97685b59, checked in by phi, 11 years ago

use roar_simple_new_stream_obj() not roar_simple_*() to create a new stream so we can update meta data

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