[5115] | 1 | //vio_stream.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011 |
---|
| 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 |
---|
| 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
| 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 | |
---|
| 36 | #include "libroar.h" |
---|
| 37 | |
---|
[5116] | 38 | static ssize_t _vio_stream_read (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 39 | return roar_vio_read(roar_get_connection_vio2(vio->inst), buf, count); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | static ssize_t _vio_stream_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 43 | return roar_vio_write(roar_get_connection_vio2(vio->inst), buf, count); |
---|
| 44 | } |
---|
| 45 | |
---|
[5278] | 46 | static roar_off_t _vio_stream_lseek (struct roar_vio_calls * vio, roar_off_t offset, int whence) { |
---|
[5116] | 47 | return roar_vio_lseek(roar_get_connection_vio2(vio->inst), offset, whence); |
---|
| 48 | } |
---|
| 49 | static int _vio_stream_sync (struct roar_vio_calls * vio) { |
---|
| 50 | return roar_vio_sync(roar_get_connection_vio2(vio->inst)); |
---|
| 51 | } |
---|
[5278] | 52 | static int _vio_stream_ctl (struct roar_vio_calls * vio, roar_vio_ctl_t cmd, void * data) { |
---|
[5116] | 53 | if (vio == NULL) { |
---|
| 54 | roar_err_set(ROAR_ERROR_FAULT); |
---|
| 55 | return -1; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | if (cmd == -1) { |
---|
| 59 | roar_err_set(ROAR_ERROR_INVAL); |
---|
| 60 | return -1; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | switch (cmd) { |
---|
| 64 | case ROAR_VIO_CTL_GET_NAME: |
---|
| 65 | if ( data == NULL ) { |
---|
| 66 | roar_err_set(ROAR_ERROR_FAULT); |
---|
| 67 | return -1; |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | *(char**)data = "stream"; |
---|
| 71 | return 0; |
---|
| 72 | break; |
---|
| 73 | case ROAR_VIO_CTL_GET_NEXT: |
---|
| 74 | *(struct roar_vio_calls **)data = roar_get_connection_vio2(vio->inst); |
---|
| 75 | return 0; |
---|
| 76 | break; |
---|
| 77 | case ROAR_VIO_CTL_SET_NEXT: |
---|
| 78 | roar_err_set(ROAR_ERROR_NOTSUP); |
---|
| 79 | return -1; |
---|
| 80 | break; |
---|
[5276] | 81 | case ROAR_VIO_CTL_NONBLOCK: |
---|
| 82 | return roar_vio_ctl(roar_get_connection_vio2(vio->inst), ROAR_VIO_CTL_NONBLOCK, data); |
---|
| 83 | break; |
---|
[5116] | 84 | } |
---|
| 85 | |
---|
| 86 | return roar_vio_ctl(roar_get_connection_vio2(vio->inst), cmd, data); |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | static int _vio_stream_close (struct roar_vio_calls * vio) { |
---|
| 90 | roar_vio_close(roar_get_connection_vio2(vio->inst)); |
---|
| 91 | roar_mm_free(vio->inst); |
---|
| 92 | |
---|
| 93 | return 0; |
---|
| 94 | } |
---|
[5115] | 95 | |
---|
[5289] | 96 | int roar_vio_simple_stream (struct roar_vio_calls * calls, |
---|
| 97 | uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, |
---|
| 98 | const char * server, int dir, const char * name, int mixer) { |
---|
[5116] | 99 | struct roar_connection * con = NULL; |
---|
| 100 | struct roar_stream stream; |
---|
| 101 | int err; |
---|
[5115] | 102 | |
---|
| 103 | if ( calls == NULL ) { |
---|
| 104 | roar_err_set(ROAR_ERROR_FAULT); |
---|
| 105 | return -1; |
---|
| 106 | } |
---|
| 107 | |
---|
[5116] | 108 | if ( roar_stream_new(&stream, rate, channels, bits, codec) == -1 ) |
---|
| 109 | return -1; |
---|
| 110 | |
---|
| 111 | con = roar_mm_malloc(sizeof(struct roar_connection)); |
---|
| 112 | if ( con == NULL ) |
---|
| 113 | return -1; |
---|
| 114 | |
---|
| 115 | memset(con, 0, sizeof(struct roar_connection)); |
---|
| 116 | |
---|
| 117 | if ( roar_simple_connect(con, server, name) == -1 ) { |
---|
| 118 | err = roar_error; |
---|
| 119 | roar_mm_free(con); |
---|
| 120 | roar_error = err; |
---|
| 121 | return -1; |
---|
| 122 | } |
---|
| 123 | |
---|
[5289] | 124 | if ( roar_stream_connect(con, &stream, dir, mixer) == -1 ) { |
---|
[5116] | 125 | err = roar_error; |
---|
| 126 | roar_disconnect(con); |
---|
| 127 | roar_mm_free(con); |
---|
| 128 | roar_error = err; |
---|
[5115] | 129 | return -1; |
---|
| 130 | } |
---|
[5116] | 131 | |
---|
| 132 | if ( roar_stream_exec(con, &stream) == -1 ) { |
---|
| 133 | err = roar_error; |
---|
| 134 | roar_disconnect(con); |
---|
| 135 | roar_mm_free(con); |
---|
| 136 | roar_error = err; |
---|
| 137 | return -1; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | roar_vio_clear_calls(calls); |
---|
[5115] | 141 | |
---|
[5116] | 142 | calls->inst = con; |
---|
| 143 | calls->read = _vio_stream_read; |
---|
| 144 | calls->write = _vio_stream_write; |
---|
| 145 | calls->lseek = _vio_stream_lseek; |
---|
| 146 | calls->sync = _vio_stream_sync; |
---|
| 147 | calls->ctl = _vio_stream_ctl; |
---|
| 148 | calls->close = _vio_stream_close; |
---|
| 149 | |
---|
| 150 | if ( dir == ROAR_DIR_PLAY ) { |
---|
| 151 | roar_vio_shutdown(calls, SHUT_RD); |
---|
| 152 | } else if ( dir == ROAR_DIR_MONITOR || dir == ROAR_DIR_RECORD ) { |
---|
| 153 | roar_vio_shutdown(calls, SHUT_WR); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | return 0; |
---|
[5115] | 157 | } |
---|
| 158 | |
---|
| 159 | int roar_vio_simple_new_stream_obj (struct roar_vio_calls * calls, |
---|
| 160 | struct roar_connection * con, |
---|
| 161 | struct roar_stream * s, |
---|
[5289] | 162 | uint32_t rate, uint32_t channels, uint32_t bits, uint32_t codec, |
---|
| 163 | int dir, int mixer) { |
---|
[5115] | 164 | struct roar_stream stream; |
---|
| 165 | int fh; |
---|
| 166 | |
---|
| 167 | ROAR_DBG("roar_vio_simple_new_stream_obj(*) = ?"); |
---|
| 168 | |
---|
| 169 | if ( calls == NULL ) { |
---|
| 170 | roar_err_set(ROAR_ERROR_FAULT); |
---|
| 171 | return -1; |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | if ( s == NULL ) |
---|
| 175 | s = &stream; |
---|
| 176 | |
---|
| 177 | roar_libroar_nowarn(); |
---|
[5289] | 178 | if ( (fh = roar_simple_new_stream_obj(con, s, rate, channels, bits, codec, dir, mixer)) == -1 ) { |
---|
[5115] | 179 | roar_libroar_warn(); |
---|
| 180 | ROAR_DBG("roar_vio_simple_new_stream_obj(*) = -1"); |
---|
| 181 | return -1; |
---|
| 182 | } |
---|
| 183 | roar_libroar_warn(); |
---|
| 184 | |
---|
| 185 | ROAR_DBG("roar_vio_simple_new_stream_obj(*): fh=%i", fh); |
---|
| 186 | |
---|
| 187 | return roar_vio_open_fh_socket(calls, fh); |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | //ll |
---|