[398] | 1 | //simple.c: |
---|
| 2 | |
---|
[706] | 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011 |
---|
[706] | 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 |
---|
[3517] | 25 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 26 | * Boston, MA 02110-1301, USA. |
---|
[706] | 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 | |
---|
[398] | 40 | #include <libroarpulse/libroarpulse.h> |
---|
| 41 | |
---|
[402] | 42 | /** Create a new connection to the server */ |
---|
| 43 | pa_simple* pa_simple_new( |
---|
| 44 | const char *server, /**< Server name, or NULL for default */ |
---|
| 45 | const char *name, /**< A descriptive name for this client (application name, ...) */ |
---|
| 46 | pa_stream_direction_t dir, /**< Open this stream for recording or playback? */ |
---|
| 47 | const char *dev, /**< Sink (resp. source) name, or NULL for default */ |
---|
| 48 | const char *stream_name, /**< A descriptive name for this client (application name, song title, ...) */ |
---|
| 49 | const pa_sample_spec *ss, /**< The sample type to use */ |
---|
| 50 | const pa_channel_map *map, /**< The channel map to use, or NULL for default */ |
---|
| 51 | const pa_buffer_attr *attr, /**< Buffering attributes, or NULL for default */ |
---|
| 52 | int *error /**< A pointer where the error code is stored when the routine returns NULL. It is OK to pass NULL here. */ |
---|
| 53 | ) { |
---|
[3848] | 54 | struct roarpulse_simple * s; |
---|
[3384] | 55 | struct roar_audio_info info; |
---|
[416] | 56 | int roar_dir; |
---|
| 57 | struct roar_meta meta; |
---|
[406] | 58 | |
---|
| 59 | if ( dir == PA_STREAM_PLAYBACK ) { |
---|
[416] | 60 | roar_dir = ROAR_DIR_PLAY; |
---|
[406] | 61 | } else if ( dir == PA_STREAM_RECORD ) { |
---|
[416] | 62 | roar_dir = ROAR_DIR_RECORD; |
---|
[406] | 63 | } else { |
---|
| 64 | return NULL; |
---|
| 65 | } |
---|
| 66 | |
---|
[3384] | 67 | if ( roar_pa_sspec2auinfo(&info, ss) == -1 ) { |
---|
| 68 | return NULL; |
---|
| 69 | } |
---|
[410] | 70 | |
---|
[3848] | 71 | if ( (s = roar_mm_malloc(sizeof(struct roarpulse_simple))) == NULL ) |
---|
| 72 | return NULL; |
---|
| 73 | |
---|
[3389] | 74 | server = roar_pa_find_server((char*)server); |
---|
[418] | 75 | |
---|
[416] | 76 | if ( roar_simple_connect(&(s->con), (char*)server, (char*)name) == -1 ) { |
---|
[3386] | 77 | roar_mm_free(s); |
---|
[416] | 78 | return NULL; |
---|
| 79 | } |
---|
| 80 | |
---|
[3385] | 81 | if ( roar_vio_simple_new_stream_obj(&(s->vio), &(s->con), &(s->stream), |
---|
| 82 | info.rate, info.channels, |
---|
| 83 | info.bits, info.codec, roar_dir) == -1 ) { |
---|
[416] | 84 | roar_disconnect(&(s->con)); |
---|
[3386] | 85 | roar_mm_free(s); |
---|
[416] | 86 | return NULL; |
---|
| 87 | } |
---|
| 88 | |
---|
[3848] | 89 | if ( stream_name != NULL && stream_name[0] != 0 ) { |
---|
[418] | 90 | meta.value = (char*)stream_name; |
---|
| 91 | meta.key[0] = 0; |
---|
| 92 | meta.type = ROAR_META_TYPE_DESCRIPTION; |
---|
[416] | 93 | |
---|
[418] | 94 | roar_stream_meta_set(&(s->con), &(s->stream), ROAR_META_MODE_SET, &meta); |
---|
| 95 | } |
---|
[406] | 96 | |
---|
| 97 | return (pa_simple*) s; |
---|
[402] | 98 | } |
---|
| 99 | |
---|
| 100 | /** Close and free the connection to the server. The connection objects becomes invalid when this is called. */ |
---|
| 101 | void pa_simple_free(pa_simple *s) { |
---|
[404] | 102 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
[3848] | 103 | |
---|
| 104 | if ( s == NULL ) |
---|
[404] | 105 | return; |
---|
| 106 | |
---|
[3385] | 107 | roar_vio_close(&(ss->vio)); |
---|
[416] | 108 | roar_disconnect(&(ss->con)); |
---|
[405] | 109 | |
---|
[3386] | 110 | roar_mm_free(s); |
---|
[402] | 111 | } |
---|
| 112 | |
---|
| 113 | /** Write some data to the server */ |
---|
| 114 | int pa_simple_write(pa_simple *s, const void*data, size_t length, int *error) { |
---|
[404] | 115 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
[3848] | 116 | |
---|
| 117 | if ( s == NULL ) |
---|
[404] | 118 | return -1; |
---|
| 119 | |
---|
[3385] | 120 | return roar_vio_write(&(ss->vio), (char*) data, length); |
---|
[402] | 121 | } |
---|
| 122 | |
---|
| 123 | /** Wait until all data already written is played by the daemon */ |
---|
| 124 | int pa_simple_drain(pa_simple *s, int *error) { |
---|
[405] | 125 | // struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
[3848] | 126 | |
---|
| 127 | if ( s == NULL ) |
---|
[404] | 128 | return -1; |
---|
| 129 | |
---|
[3848] | 130 | pa_simple_flush(s, error); |
---|
[405] | 131 | |
---|
[402] | 132 | return -1; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | /** Read some data from the server */ |
---|
| 136 | int pa_simple_read(pa_simple *s, void*data, size_t length, int *error) { |
---|
[404] | 137 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
[3848] | 138 | |
---|
| 139 | if ( s == NULL ) |
---|
[404] | 140 | return -1; |
---|
| 141 | |
---|
[3385] | 142 | return roar_vio_read(&(ss->vio), data, length); |
---|
[402] | 143 | } |
---|
| 144 | |
---|
| 145 | /** Return the playback latency. \since 0.5 */ |
---|
| 146 | pa_usec_t pa_simple_get_latency(pa_simple *s, int *error) { |
---|
[404] | 147 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
[3848] | 148 | |
---|
| 149 | if ( s == NULL ) |
---|
[404] | 150 | return -1; |
---|
| 151 | |
---|
[402] | 152 | return -1; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | /** Flush the playback buffer. \since 0.5 */ |
---|
| 156 | int pa_simple_flush(pa_simple *s, int *error) { |
---|
[404] | 157 | struct roarpulse_simple * ss = (struct roarpulse_simple*) s; |
---|
[3848] | 158 | |
---|
| 159 | if ( s == NULL ) |
---|
[404] | 160 | return -1; |
---|
| 161 | |
---|
[3385] | 162 | return roar_vio_sync(&(ss->vio)); |
---|
[402] | 163 | } |
---|
| 164 | |
---|
[398] | 165 | //ll |
---|