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

Last change on this file since 416:3c1e97685b59 was 416:3c1e97685b59, checked in by phi, 16 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
RevLine 
[398]1//simple.c:
2
3#include <libroarpulse/libroarpulse.h>
4
[402]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    ) {
[406]17 struct roarpulse_simple * s = malloc(sizeof(struct roarpulse_simple));
[416]18 int roar_dir;
[406]19 int codec = -1;
[416]20 struct roar_meta meta;
[406]21
22 if ( !s )
23  return NULL;
24
25 if ( dir == PA_STREAM_PLAYBACK ) {
[416]26  roar_dir = ROAR_DIR_PLAY;
[406]27 } else if ( dir == PA_STREAM_RECORD ) {
[416]28  roar_dir = ROAR_DIR_RECORD;
[406]29 } else {
30  free(s);
31  return NULL;
32 }
33
[410]34 codec = roar_codec_pulse2roar(ss->format);
35
[416]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);
[406]55
56 return (pa_simple*) s;
[402]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) {
[404]61 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
62 if ( !s )
63  return;
64
[405]65 close(ss->data_fh);
[416]66 roar_disconnect(&(ss->con));
[405]67
[404]68 free(s);
[402]69}
70
71/** Write some data to the server */
72int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) {
[404]73 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
74 if ( !s )
75  return -1;
76
[411]77 return write(ss->data_fh, (char*) data, length);
[402]78}
79
80/** Wait until all data already written is played by the daemon */
81int pa_simple_drain(pa_simple *s, int *error) {
[405]82// struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
[404]83 if ( !s )
84  return -1;
85
[405]86 pa_simple_flush(s, NULL);
87
[402]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) {
[404]93 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
94 if ( !s )
95  return -1;
96
[405]97 return read(ss->data_fh, data, length);
[402]98}
99
100/** Return the playback latency. \since 0.5 */
101pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) {
[404]102 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
103 if ( !s )
104  return -1;
105
[402]106 return -1;
107}
108
109/** Flush the playback buffer. \since 0.5 */
110int pa_simple_flush(pa_simple *s, int *error) {
[404]111 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
112 if ( !s )
113  return -1;
114
115 return fdatasync(ss->data_fh);
[402]116}
117
[398]118//ll
Note: See TracBrowser for help on using the repository browser.