[0] | 1 | //simple.c: |
---|
| 2 | |
---|
[690] | 3 | /* |
---|
[6052] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2015 |
---|
[690] | 5 | * |
---|
| 6 | * This file is part of libroar a part of RoarAudio, |
---|
| 7 | * a cross-platform sound system for both, home and professional use. |
---|
| 8 | * See README for details. |
---|
| 9 | * |
---|
| 10 | * This file is free software; you can redistribute it and/or modify |
---|
| 11 | * it under the terms of the GNU General Public License version 3 |
---|
| 12 | * as published by the Free Software Foundation. |
---|
| 13 | * |
---|
| 14 | * libroar is distributed in the hope that it will be useful, |
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 17 | * GNU General Public License for more details. |
---|
| 18 | * |
---|
| 19 | * You should have received a copy of the GNU General Public License |
---|
| 20 | * along with this software; see the file COPYING. If not, write to |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[690] | 23 | * |
---|
| 24 | * NOTE for everyone want's to change something and send patches: |
---|
| 25 | * read README and HACKING! There a addition information on |
---|
| 26 | * the license of this document you need to read before you send |
---|
| 27 | * any patches. |
---|
| 28 | * |
---|
| 29 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
| 30 | * or libpulse*: |
---|
| 31 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
| 32 | * and are therefore GPL. Because of this it may be illigal to use |
---|
| 33 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
| 34 | */ |
---|
| 35 | |
---|
[0] | 36 | #include "libroar.h" |
---|
| 37 | |
---|
[5377] | 38 | static int roar_simple_stream_obj (struct roar_stream * s, uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, const char * server, int dir, const char * name, int mixer); |
---|
[5289] | 39 | |
---|
[5114] | 40 | int roar_simple_connect (struct roar_connection * con, const char * server, const char * name) { |
---|
[4806] | 41 | return roar_simple_connect2(con, server, name, 0, 0); |
---|
| 42 | } |
---|
| 43 | |
---|
[5114] | 44 | int roar_simple_connect2(struct roar_connection * con, const char * server, const char * name, int flags, uint_least32_t timeout) { |
---|
[0] | 45 | |
---|
| 46 | ROAR_DBG("roar_simple_connect(*): trying to connect..."); |
---|
| 47 | |
---|
[5237] | 48 | if ( roar_connect(con, server, flags, timeout) == -1 ) { |
---|
[5845] | 49 | ROAR_DBG("roar_simple_connect(*): roar_connect() faild: %s", roar_errorstring); |
---|
[0] | 50 | return -1; |
---|
| 51 | } |
---|
| 52 | |
---|
| 53 | if ( roar_identify(con, name) == -1 ) { |
---|
[5845] | 54 | ROAR_DBG("roar_simple_connect(*): roar_identify() faild: %s", roar_errorstring); |
---|
[0] | 55 | return -1; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | if ( roar_auth(con) == -1 ) { |
---|
[5845] | 59 | ROAR_DBG("roar_simple_connect(*): roar_auth() faild: %s", roar_errorstring); |
---|
[0] | 60 | return -1; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | return 0; |
---|
| 64 | } |
---|
| 65 | |
---|
[5289] | 66 | static int roar_simple_stream_obj (struct roar_stream * s, uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, const char * server, int dir, const char * name, int mixer) { |
---|
[0] | 67 | struct roar_connection con; |
---|
[1660] | 68 | int ret; |
---|
[5148] | 69 | int safe_error; |
---|
[0] | 70 | |
---|
[2818] | 71 | roar_debug_warn_sysio("roar_simple_stream_obj", NULL, NULL); |
---|
| 72 | |
---|
[0] | 73 | if ( roar_simple_connect(&con, server, name) == -1 ) { |
---|
[5226] | 74 | ROAR_DBG("roar_simple_stream_obj(*): roar_simple_connect() faild!"); |
---|
| 75 | ROAR_ERR("roar_simple_stream_obj(*): Can not connect to server"); |
---|
[0] | 76 | return -1; |
---|
| 77 | } |
---|
| 78 | |
---|
[1158] | 79 | if ( roar_stream_new(s, rate, channels, bits, codec) == -1 ) { |
---|
[5148] | 80 | safe_error = roar_error; |
---|
[0] | 81 | roar_disconnect(&con); |
---|
[5148] | 82 | roar_err_set(safe_error); |
---|
[0] | 83 | return -1; |
---|
| 84 | } |
---|
| 85 | |
---|
[5289] | 86 | if ( roar_stream_connect(&con, s, dir, mixer) == -1 ) { |
---|
[5148] | 87 | safe_error = roar_error; |
---|
[0] | 88 | roar_disconnect(&con); |
---|
[5148] | 89 | roar_err_set(safe_error); |
---|
[0] | 90 | return -1; |
---|
| 91 | } |
---|
| 92 | |
---|
[1158] | 93 | if ( roar_stream_exec(&con, s) == -1 ) { |
---|
[5148] | 94 | safe_error = roar_error; |
---|
[0] | 95 | roar_disconnect(&con); |
---|
[5148] | 96 | roar_err_set(safe_error); |
---|
[0] | 97 | return -1; |
---|
| 98 | } |
---|
| 99 | |
---|
[3857] | 100 | roar_libroar_nowarn(); |
---|
[1660] | 101 | if ( (ret = roar_get_connection_fh(&con)) == -1 ) { |
---|
[5148] | 102 | safe_error = roar_error; |
---|
[3857] | 103 | roar_libroar_warn(); |
---|
[1660] | 104 | roar_disconnect(&con); |
---|
[5148] | 105 | roar_err_set(safe_error); |
---|
[1660] | 106 | return -1; |
---|
[54] | 107 | } |
---|
[3857] | 108 | roar_libroar_warn(); |
---|
[54] | 109 | |
---|
[1660] | 110 | if ( dir == ROAR_DIR_PLAY ) { |
---|
[5017] | 111 | (void)ROAR_SHUTDOWN(ret, SHUT_RD); |
---|
[1660] | 112 | } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) { |
---|
[5017] | 113 | (void)ROAR_SHUTDOWN(ret, SHUT_WR); |
---|
[1660] | 114 | } |
---|
| 115 | |
---|
| 116 | return ret; |
---|
[0] | 117 | } |
---|
| 118 | |
---|
[5289] | 119 | int roar_simple_new_stream_attachexeced_obj (struct roar_connection * con, struct roar_stream * s, uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, int dir, int mixer) { |
---|
[1163] | 120 | int fh; |
---|
| 121 | |
---|
[5296] | 122 | if ( (fh = roar_simple_stream_obj(s, rate, channels, bits, codec, roar_get_connection_server(con), |
---|
[5289] | 123 | dir, "libroar temp stream", mixer)) == -1 ) |
---|
[1163] | 124 | return -1; |
---|
| 125 | |
---|
| 126 | if ( roar_stream_attach_simple(con, s, roar_get_clientid(con)) == -1 ) { |
---|
[1476] | 127 | #ifdef ROAR_HAVE_IO_POSIX |
---|
[1163] | 128 | close(fh); |
---|
[1476] | 129 | #endif /* no else as we return -1 anyway */ |
---|
[1163] | 130 | return -1; |
---|
| 131 | } |
---|
| 132 | |
---|
[1166] | 133 | s->fh = fh; |
---|
| 134 | |
---|
[1163] | 135 | return fh; |
---|
| 136 | } |
---|
| 137 | |
---|
[5225] | 138 | int roar_simple_play_file(const char * file, const char * server, const char * name) { |
---|
[5110] | 139 | roar_vs_t * vss; |
---|
| 140 | int err; |
---|
[235] | 141 | |
---|
[5110] | 142 | vss = roar_vs_new_from_file(server, name, file, &err); |
---|
| 143 | |
---|
| 144 | if ( vss == NULL ) { |
---|
| 145 | roar_err_set(err); |
---|
[235] | 146 | return -1; |
---|
| 147 | } |
---|
| 148 | |
---|
[5110] | 149 | if ( roar_vs_run(vss, &err) == -1 ) { |
---|
[5409] | 150 | roar_vs_close(vss, ROAR_VS_TRUE, NULL); |
---|
[5110] | 151 | roar_err_set(err); |
---|
| 152 | return -1; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | roar_vs_sync(vss, ROAR_VS_WAIT, NULL); |
---|
| 156 | roar_vs_close(vss, ROAR_VS_FALSE, NULL); |
---|
| 157 | |
---|
| 158 | return 0; |
---|
[235] | 159 | } |
---|
| 160 | |
---|
[2697] | 161 | int roar_simple_connect_virtual(struct roar_connection * con, struct roar_stream * s, int parent, int dir) { |
---|
[2656] | 162 | struct roar_stream parent_stream; |
---|
| 163 | |
---|
| 164 | if ( con == NULL || s == NULL || parent < 0 ) |
---|
| 165 | return -1; |
---|
| 166 | |
---|
[2697] | 167 | if ( dir == -1 ) { |
---|
| 168 | if ( roar_get_stream(con, &parent_stream, parent) == -1 ) |
---|
| 169 | return -1; |
---|
[2656] | 170 | |
---|
[2697] | 171 | if ( (dir = roar_stream_get_dir(&parent_stream)) == -1 ) |
---|
| 172 | return -1; |
---|
| 173 | } |
---|
[2656] | 174 | |
---|
| 175 | if ( roar_stream_set_rel_id(s, parent) == -1 ) |
---|
| 176 | return -1; |
---|
| 177 | |
---|
[5238] | 178 | if ( roar_stream_connect(con, s, dir, -1) == -1 ) |
---|
[2656] | 179 | return -1; |
---|
| 180 | |
---|
[5238] | 181 | if ( roar_stream_set_flags(con, s, ROAR_FLAG_VIRTUAL, ROAR_SET_FLAG) == -1 ) { |
---|
[2656] | 182 | roar_kick(con, ROAR_OT_STREAM, roar_stream_get_id(s)); |
---|
| 183 | return -1; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | return 0; |
---|
[2647] | 187 | } |
---|
[0] | 188 | |
---|
| 189 | //ll |
---|