source: roaraudio/libroarpulse/simple.c @ 5243:f286a604a4cf

Last change on this file since 5243:f286a604a4cf was 5239:eb474b0b1805, checked in by phi, 12 years ago

Removed roar_vs_latency().

File size: 5.2 KB
Line 
1//simple.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from libpulse*. They are mostly copyrighted by:
7 *  Lennart Poettering <poettering@users.sourceforge.net> and
8 *  Pierre Ossman <drzeus@drzeus.cx>
9 *
10 *  This file is part of libroarpulse a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 51 Franklin Street, Fifth Floor,
26 *  Boston, MA 02110-1301, USA.
27 *
28 *  NOTE for everyone want's to change something and send patches:
29 *  read README and HACKING! There a addition information on
30 *  the license of this document you need to read before you send
31 *  any patches.
32 *
33 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
34 *  or libpulse*:
35 *  The libs libroaresd, libroararts and libroarpulse link this libroar
36 *  and are therefore GPL. Because of this it may be illigal to use
37 *  them with any software that uses libesd, libartsc or libpulse*.
38 */
39
40#include <libroarpulse/libroarpulse.h>
41
42#define _seterr() if ( error != NULL ) { *error = roar_pa_raerror2paerror(err); }
43
44/** Create a new connection to the server */
45pa_simple* pa_simple_new(
46    const char *server,                 /**< Server name, or NULL for default */
47    const char *name,                   /**< A descriptive name for this client (application name, ...) */
48    pa_stream_direction_t dir,          /**< Open this stream for recording or playback? */
49    const char *dev,                    /**< Sink (resp. source) name, or NULL for default */
50    const char *stream_name,            /**< A descriptive name for this client (application name, song title, ...) */
51    const pa_sample_spec *ss,           /**< The sample type to use */
52    const pa_channel_map *map,          /**< The channel map to use, or NULL for default */
53    const pa_buffer_attr *attr,         /**< Buffering attributes, or NULL for default */
54    int *error                          /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */
55    ) {
56 struct roar_keyval kv[1];
57 roar_vs_t * vss = NULL;
58 struct roar_audio_info info;
59 int roar_dir;
60 int err = ROAR_ERROR_NONE;
61
62 if ( dir == PA_STREAM_PLAYBACK ) {
63  roar_dir = ROAR_DIR_PLAY;
64 } else if ( dir == PA_STREAM_RECORD ) {
65  roar_dir = ROAR_DIR_RECORD;
66 } else {
67  return NULL;
68 }
69
70 if ( roar_pa_sspec2auinfo(&info, ss) == -1 ) {
71  return NULL;
72 }
73
74 server = roar_pa_find_server((char*)server);
75
76 vss = roar_vs_new(server, name, &err);
77 if ( vss == NULL ) {
78  _seterr();
79  return NULL;
80 }
81
82 if ( roar_vs_stream(vss, &info, roar_dir, &err) == -1 ) {
83  roar_vs_close(vss, ROAR_VS_TRUE, NULL);
84  _seterr();
85  return NULL;
86 }
87
88 if ( stream_name != NULL && stream_name[0] != 0 ) {
89  kv[0].key   = "DESCRIPTION";
90  kv[0].value = (char*)stream_name;
91
92  roar_vs_meta(vss, kv, 1, NULL);
93 }
94
95 return (pa_simple*) vss;
96}
97
98/** Close and free the connection to the server. The connection objects becomes invalid when this is called. */
99void pa_simple_free(pa_simple *s) {
100 if ( s == NULL )
101  return;
102
103 roar_vs_close((roar_vs_t*)s, ROAR_VS_FALSE, NULL);
104}
105
106/** Write some data to the server */
107int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) {
108 int ret;
109 int err = ROAR_ERROR_NONE;
110
111 if ( s == NULL )
112  return -1;
113
114 ret = roar_vs_write((roar_vs_t*)s, data, length, &err);
115
116 _seterr();
117
118 return ret;
119}
120
121/** Wait until all data already written is played by the daemon */
122int pa_simple_drain(pa_simple *s, int *error) {
123 int ret;
124 int err = ROAR_ERROR_NONE;
125
126 if ( s == NULL )
127  return -1;
128
129 ret = roar_vs_sync((roar_vs_t*)s, ROAR_VS_WAIT, &err);
130
131 _seterr();
132
133 return ret;
134}
135
136/** Read some data from the server */
137int pa_simple_read(pa_simple *s, void*data, size_t length, int *error) {
138 int ret;
139 int err = ROAR_ERROR_NONE;
140
141 if ( s == NULL )
142  return -1;
143
144 ret = roar_vs_read((roar_vs_t*)s, data, length, &err);
145
146 _seterr();
147
148 return ret;
149}
150
151/** Return the playback latency. \since 0.5 */
152pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) {
153 roar_mus_t ret;
154 int err = ROAR_ERROR_NONE;
155
156 if ( s == NULL )
157  return -1;
158
159 ret = roar_vs_latency((roar_vs_t*)s, ROAR_VS_BACKEND_DEFAULT, ROAR_VS_WAIT, &err);
160
161 if ( ret < 0 )
162  ret *= -1;
163
164 if ( ret == 0 && err != ROAR_ERROR_NONE ) {
165  _seterr();
166  return -1;
167 }
168
169 return ret;
170}
171
172/** Flush the playback buffer. \since 0.5 */
173int pa_simple_flush(pa_simple *s, int *error) {
174 int ret;
175 int err = ROAR_ERROR_NONE;
176
177 if ( s == NULL )
178  return -1;
179
180 ret = roar_vs_sync((roar_vs_t*)s, ROAR_VS_NOWAIT, &err);
181
182 _seterr();
183
184 return ret;
185}
186
187//ll
Note: See TracBrowser for help on using the repository browser.