[2639] | 1 | //vio_transcode.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5823] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2013 |
---|
[2639] | 5 | * |
---|
| 6 | * This file is part of libroardsp 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 | * libroardsp 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. |
---|
[2639] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "libroardsp.h" |
---|
| 27 | |
---|
[2641] | 28 | int roar_vio_open_xcode (struct roar_vio_calls * calls, int encoder, struct roar_audio_info * info, |
---|
| 29 | struct roar_vio_calls * dst) { |
---|
[3063] | 30 | struct roar_xcoder * xcoder = roar_mm_malloc(sizeof(struct roar_xcoder)); |
---|
[2641] | 31 | |
---|
| 32 | if ( xcoder == NULL ) |
---|
| 33 | return -1; |
---|
| 34 | |
---|
| 35 | if ( calls == NULL || info == NULL || dst == NULL ) { |
---|
[3063] | 36 | roar_mm_free(xcoder); |
---|
[2641] | 37 | return -1; |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | if ( roar_xcoder_init(xcoder, encoder, info, dst) == -1 ) { |
---|
[3063] | 41 | roar_mm_free(xcoder); |
---|
[2641] | 42 | return -1; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
[5388] | 46 | calls->flags = ROAR_VIO_FLAGS_NONE; |
---|
| 47 | calls->refc = 1; |
---|
[2641] | 48 | |
---|
| 49 | calls->inst = (void*)xcoder; |
---|
| 50 | |
---|
| 51 | calls->close = roar_vio_xcode_close; |
---|
| 52 | |
---|
| 53 | if ( encoder ) { |
---|
| 54 | calls->write = roar_vio_xcode_proc; |
---|
| 55 | } else { |
---|
| 56 | calls->read = roar_vio_xcode_proc; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | return 0; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | ssize_t roar_vio_xcode_proc (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
[2642] | 63 | #ifdef DEBUG |
---|
| 64 | int ret; |
---|
| 65 | #endif |
---|
| 66 | |
---|
[2641] | 67 | if ( vio == NULL ) |
---|
| 68 | return -1; |
---|
| 69 | |
---|
| 70 | if ( buf == NULL && count != 0 ) |
---|
| 71 | return -1; |
---|
| 72 | |
---|
[2642] | 73 | #ifdef DEBUG |
---|
| 74 | ret = roar_xcoder_proc(vio->inst, buf, count); |
---|
| 75 | |
---|
| 76 | ROAR_DBG("roar_vio_xcode_proc(vio=%p, buf=%p, count=%lu): ret=%i", vio, buf, (unsigned long) count, ret); |
---|
| 77 | |
---|
| 78 | return !ret ? count : -1; |
---|
| 79 | #else |
---|
[5270] | 80 | return !roar_xcoder_proc(vio->inst, buf, count) ? (ssize_t)count : -1; |
---|
[2642] | 81 | #endif |
---|
[2641] | 82 | } |
---|
| 83 | |
---|
| 84 | int roar_vio_xcode_sync (struct roar_vio_calls * vio); |
---|
| 85 | |
---|
| 86 | int roar_vio_xcode_close (struct roar_vio_calls * vio) { |
---|
| 87 | int ret = 0; |
---|
| 88 | |
---|
| 89 | if ( vio == NULL ) |
---|
| 90 | return -1; |
---|
| 91 | |
---|
| 92 | if ( roar_xcoder_close(vio->inst) == -1 ) |
---|
| 93 | ret = -1; |
---|
| 94 | |
---|
| 95 | if ( vio->inst != NULL ) |
---|
[3063] | 96 | roar_mm_free(vio->inst); |
---|
[2641] | 97 | |
---|
| 98 | return ret; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | int roar_vio_open_bixcode (struct roar_vio_calls * calls, struct roar_audio_info * info, |
---|
[2644] | 102 | struct roar_vio_calls * dst) { |
---|
[3063] | 103 | struct roar_bixcoder * bixcoder = roar_mm_malloc(sizeof(struct roar_bixcoder)); |
---|
[2644] | 104 | |
---|
| 105 | if ( bixcoder == NULL ) |
---|
| 106 | return -1; |
---|
| 107 | |
---|
| 108 | if ( calls == NULL || info == NULL || dst == NULL ) { |
---|
[3063] | 109 | roar_mm_free(bixcoder); |
---|
[2644] | 110 | return -1; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | if ( roar_bixcoder_init(bixcoder, info, dst) == -1 ) { |
---|
[3063] | 114 | roar_mm_free(bixcoder); |
---|
[2644] | 115 | return -1; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
[5388] | 119 | calls->flags = ROAR_VIO_FLAGS_NONE; |
---|
| 120 | calls->refc = 1; |
---|
[2644] | 121 | |
---|
[5388] | 122 | calls->inst = (void*)bixcoder; |
---|
[2644] | 123 | |
---|
[5388] | 124 | calls->close = roar_vio_bixcode_close; |
---|
[2644] | 125 | |
---|
| 126 | calls->read = roar_vio_bixcode_read; |
---|
| 127 | calls->write = roar_vio_bixcode_write; |
---|
| 128 | |
---|
| 129 | return 0; |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | ssize_t roar_vio_bixcode_read (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 133 | |
---|
| 134 | if ( vio == NULL ) |
---|
| 135 | return -1; |
---|
| 136 | |
---|
| 137 | if ( buf == NULL && count != 0 ) |
---|
| 138 | return -1; |
---|
| 139 | |
---|
[5270] | 140 | return !roar_bixcoder_read(vio->inst, buf, count) ? (ssize_t)count : -1; |
---|
[2644] | 141 | } |
---|
| 142 | |
---|
| 143 | ssize_t roar_vio_bixcode_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 144 | |
---|
| 145 | if ( vio == NULL ) |
---|
| 146 | return -1; |
---|
| 147 | |
---|
| 148 | if ( buf == NULL && count != 0 ) |
---|
| 149 | return -1; |
---|
| 150 | |
---|
[5270] | 151 | return !roar_bixcoder_write(vio->inst, buf, count) ? (ssize_t)count : -1; |
---|
[2644] | 152 | } |
---|
| 153 | |
---|
[2641] | 154 | int roar_vio_bixcode_sync (struct roar_vio_calls * vio); |
---|
[2644] | 155 | |
---|
| 156 | int roar_vio_bixcode_close (struct roar_vio_calls * vio) { |
---|
| 157 | int ret = 0; |
---|
| 158 | |
---|
| 159 | if ( vio == NULL ) |
---|
| 160 | return -1; |
---|
| 161 | |
---|
| 162 | if ( roar_bixcoder_close(vio->inst) == -1 ) |
---|
| 163 | ret = -1; |
---|
| 164 | |
---|
| 165 | if ( vio->inst != NULL ) |
---|
[3063] | 166 | roar_mm_free(vio->inst); |
---|
[2644] | 167 | |
---|
| 168 | return ret; |
---|
| 169 | } |
---|
[2639] | 170 | |
---|
| 171 | //ll |
---|