[2639] | 1 | //vio_transcode.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011 |
---|
[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)); |
---|
| 46 | |
---|
| 47 | calls->inst = (void*)xcoder; |
---|
| 48 | |
---|
| 49 | calls->close = roar_vio_xcode_close; |
---|
| 50 | |
---|
| 51 | if ( encoder ) { |
---|
| 52 | calls->write = roar_vio_xcode_proc; |
---|
| 53 | } else { |
---|
| 54 | calls->read = roar_vio_xcode_proc; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | return 0; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | ssize_t roar_vio_xcode_proc (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
[2642] | 61 | #ifdef DEBUG |
---|
| 62 | int ret; |
---|
| 63 | #endif |
---|
| 64 | |
---|
[2641] | 65 | if ( vio == NULL ) |
---|
| 66 | return -1; |
---|
| 67 | |
---|
| 68 | if ( buf == NULL && count != 0 ) |
---|
| 69 | return -1; |
---|
| 70 | |
---|
[2642] | 71 | #ifdef DEBUG |
---|
| 72 | ret = roar_xcoder_proc(vio->inst, buf, count); |
---|
| 73 | |
---|
| 74 | ROAR_DBG("roar_vio_xcode_proc(vio=%p, buf=%p, count=%lu): ret=%i", vio, buf, (unsigned long) count, ret); |
---|
| 75 | |
---|
| 76 | return !ret ? count : -1; |
---|
| 77 | #else |
---|
| 78 | return !roar_xcoder_proc(vio->inst, buf, count) ? count : -1; |
---|
| 79 | #endif |
---|
[2641] | 80 | } |
---|
| 81 | |
---|
| 82 | off_t roar_vio_xcode_lseek (struct roar_vio_calls * vio, off_t offset, int whence); |
---|
| 83 | int roar_vio_xcode_nonblock(struct roar_vio_calls * vio, int state); |
---|
| 84 | int roar_vio_xcode_sync (struct roar_vio_calls * vio); |
---|
| 85 | int roar_vio_xcode_ctl (struct roar_vio_calls * vio, int cmd, void * data); |
---|
| 86 | |
---|
| 87 | int roar_vio_xcode_close (struct roar_vio_calls * vio) { |
---|
| 88 | int ret = 0; |
---|
| 89 | |
---|
| 90 | if ( vio == NULL ) |
---|
| 91 | return -1; |
---|
| 92 | |
---|
| 93 | if ( roar_xcoder_close(vio->inst) == -1 ) |
---|
| 94 | ret = -1; |
---|
| 95 | |
---|
| 96 | if ( vio->inst != NULL ) |
---|
[3063] | 97 | roar_mm_free(vio->inst); |
---|
[2641] | 98 | |
---|
| 99 | return ret; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | int roar_vio_open_bixcode (struct roar_vio_calls * calls, struct roar_audio_info * info, |
---|
[2644] | 103 | struct roar_vio_calls * dst) { |
---|
[3063] | 104 | struct roar_bixcoder * bixcoder = roar_mm_malloc(sizeof(struct roar_bixcoder)); |
---|
[2644] | 105 | |
---|
| 106 | if ( bixcoder == NULL ) |
---|
| 107 | return -1; |
---|
| 108 | |
---|
| 109 | if ( calls == NULL || info == NULL || dst == NULL ) { |
---|
[3063] | 110 | roar_mm_free(bixcoder); |
---|
[2644] | 111 | return -1; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | if ( roar_bixcoder_init(bixcoder, info, dst) == -1 ) { |
---|
[3063] | 115 | roar_mm_free(bixcoder); |
---|
[2644] | 116 | return -1; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
| 120 | |
---|
| 121 | calls->inst = (void*)bixcoder; |
---|
| 122 | |
---|
| 123 | calls->close = roar_vio_bixcode_close; |
---|
| 124 | |
---|
| 125 | calls->read = roar_vio_bixcode_read; |
---|
| 126 | calls->write = roar_vio_bixcode_write; |
---|
| 127 | |
---|
| 128 | return 0; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | ssize_t roar_vio_bixcode_read (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 132 | |
---|
| 133 | if ( vio == NULL ) |
---|
| 134 | return -1; |
---|
| 135 | |
---|
| 136 | if ( buf == NULL && count != 0 ) |
---|
| 137 | return -1; |
---|
| 138 | |
---|
| 139 | return !roar_bixcoder_read(vio->inst, buf, count) ? count : -1; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | ssize_t roar_vio_bixcode_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 143 | |
---|
| 144 | if ( vio == NULL ) |
---|
| 145 | return -1; |
---|
| 146 | |
---|
| 147 | if ( buf == NULL && count != 0 ) |
---|
| 148 | return -1; |
---|
| 149 | |
---|
| 150 | return !roar_bixcoder_write(vio->inst, buf, count) ? count : -1; |
---|
| 151 | } |
---|
| 152 | |
---|
[2641] | 153 | off_t roar_vio_bixcode_lseek (struct roar_vio_calls * vio, off_t offset, int whence); |
---|
| 154 | int roar_vio_bixcode_nonblock(struct roar_vio_calls * vio, int state); |
---|
| 155 | int roar_vio_bixcode_sync (struct roar_vio_calls * vio); |
---|
| 156 | int roar_vio_bixcode_ctl (struct roar_vio_calls * vio, int cmd, void * data); |
---|
[2644] | 157 | |
---|
| 158 | int roar_vio_bixcode_close (struct roar_vio_calls * vio) { |
---|
| 159 | int ret = 0; |
---|
| 160 | |
---|
| 161 | if ( vio == NULL ) |
---|
| 162 | return -1; |
---|
| 163 | |
---|
| 164 | if ( roar_bixcoder_close(vio->inst) == -1 ) |
---|
| 165 | ret = -1; |
---|
| 166 | |
---|
| 167 | if ( vio->inst != NULL ) |
---|
[3063] | 168 | roar_mm_free(vio->inst); |
---|
[2644] | 169 | |
---|
| 170 | return ret; |
---|
| 171 | } |
---|
[2639] | 172 | |
---|
| 173 | //ll |
---|