source: roaraudio/libroarpulse/simple.c @ 3386:89f9ef49c056

Last change on this file since 3386:89f9ef49c056 was 3386:89f9ef49c056, checked in by phi, 10 years ago

use RoarAudio's MemMgr?, not system's

File size: 5.2 KB
Line 
1//simple.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010
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, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 *
32 *  NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc
33 *  or libpulse*:
34 *  The libs libroaresd, libroararts and libroarpulse link this libroar
35 *  and are therefore GPL. Because of this it may be illigal to use
36 *  them with any software that uses libesd, libartsc or libpulse*.
37 */
38
39#include <libroarpulse/libroarpulse.h>
40
41/** Create a new connection to the server */
42pa_simple* pa_simple_new(
43    const char *server,                 /**< Server name, or NULL for default */
44    const char *name,                   /**< A descriptive name for this client (application name, ...) */
45    pa_stream_direction_t dir,          /**< Open this stream for recording or playback? */
46    const char *dev,                    /**< Sink (resp. source) name, or NULL for default */
47    const char *stream_name,            /**< A descriptive name for this client (application name, song title, ...) */
48    const pa_sample_spec *ss,           /**< The sample type to use */
49    const pa_channel_map *map,          /**< The channel map to use, or NULL for default */
50    const pa_buffer_attr *attr,         /**< Buffering attributes, or NULL for default */
51    int *error                          /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */
52    ) {
53 struct roarpulse_simple * s = roar_mm_malloc(sizeof(struct roarpulse_simple));
54 struct roar_audio_info info;
55 int roar_dir;
56 struct roar_meta meta;
57
58 if ( !s )
59  return NULL;
60
61 if ( dir == PA_STREAM_PLAYBACK ) {
62  roar_dir = ROAR_DIR_PLAY;
63 } else if ( dir == PA_STREAM_RECORD ) {
64  roar_dir = ROAR_DIR_RECORD;
65 } else {
66  roar_mm_free(s);
67  return NULL;
68 }
69
70 if ( roar_pa_sspec2auinfo(&info, ss) == -1 ) {
71  roar_mm_free(s);
72  return NULL;
73 }
74
75 if ( !server )
76  server = getenv("PULSE_SERVER");
77
78 if ( roar_simple_connect(&(s->con), (char*)server, (char*)name) == -1 ) {
79  roar_mm_free(s);
80  return NULL;
81 }
82
83 if ( roar_vio_simple_new_stream_obj(&(s->vio), &(s->con), &(s->stream),
84                                     info.rate, info.channels,
85                                     info.bits, info.codec, roar_dir) == -1 ) {
86  roar_disconnect(&(s->con));
87  roar_mm_free(s);
88  return NULL;
89 }
90
91 if ( stream_name && stream_name[0] != 0 ) {
92  meta.value  = (char*)stream_name;
93  meta.key[0] = 0;
94  meta.type   = ROAR_META_TYPE_DESCRIPTION;
95
96  roar_stream_meta_set(&(s->con), &(s->stream), ROAR_META_MODE_SET, &meta);
97 }
98
99 return (pa_simple*) s;
100}
101
102/** Close and free the connection to the server. The connection objects becomes invalid when this is called. */
103void pa_simple_free(pa_simple *s) {
104 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
105 if ( !s )
106  return;
107
108 roar_vio_close(&(ss->vio));
109 roar_disconnect(&(ss->con));
110
111 roar_mm_free(s);
112}
113
114/** Write some data to the server */
115int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) {
116 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
117 if ( !s )
118  return -1;
119
120 return roar_vio_write(&(ss->vio), (char*) data, length);
121}
122
123/** Wait until all data already written is played by the daemon */
124int pa_simple_drain(pa_simple *s, int *error) {
125// struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
126 if ( !s )
127  return -1;
128
129 pa_simple_flush(s, NULL);
130
131 return -1;
132}
133
134/** Read some data from the server */
135int pa_simple_read(pa_simple *s, void*data, size_t length, int *error) {
136 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
137 if ( !s )
138  return -1;
139
140 return roar_vio_read(&(ss->vio), data, length);
141}
142
143/** Return the playback latency. \since 0.5 */
144pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) {
145 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
146 if ( !s )
147  return -1;
148
149 return -1;
150}
151
152/** Flush the playback buffer. \since 0.5 */
153int pa_simple_flush(pa_simple *s, int *error) {
154 struct roarpulse_simple * ss = (struct roarpulse_simple*) s;
155 if ( !s )
156  return -1;
157
158#ifdef ROAR_FDATASYNC
159 return roar_vio_sync(&(ss->vio));
160#else
161 return 0;
162#endif
163}
164
165//ll
Note: See TracBrowser for help on using the repository browser.