[2639] | 1 | //vio_transcode.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009 |
---|
| 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 |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include "libroardsp.h" |
---|
| 26 | |
---|
[2641] | 27 | int roar_vio_open_xcode (struct roar_vio_calls * calls, int encoder, struct roar_audio_info * info, |
---|
| 28 | struct roar_vio_calls * dst) { |
---|
[3063] | 29 | struct roar_xcoder * xcoder = roar_mm_malloc(sizeof(struct roar_xcoder)); |
---|
[2641] | 30 | |
---|
| 31 | if ( xcoder == NULL ) |
---|
| 32 | return -1; |
---|
| 33 | |
---|
| 34 | if ( calls == NULL || info == NULL || dst == NULL ) { |
---|
[3063] | 35 | roar_mm_free(xcoder); |
---|
[2641] | 36 | return -1; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | if ( roar_xcoder_init(xcoder, encoder, info, dst) == -1 ) { |
---|
[3063] | 40 | roar_mm_free(xcoder); |
---|
[2641] | 41 | return -1; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | memset(calls, 0, sizeof(struct roar_vio_calls)); |
---|
| 45 | |
---|
| 46 | calls->inst = (void*)xcoder; |
---|
| 47 | |
---|
| 48 | calls->close = roar_vio_xcode_close; |
---|
| 49 | |
---|
| 50 | if ( encoder ) { |
---|
| 51 | calls->write = roar_vio_xcode_proc; |
---|
| 52 | } else { |
---|
| 53 | calls->read = roar_vio_xcode_proc; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | return 0; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | ssize_t roar_vio_xcode_proc (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
[2642] | 60 | #ifdef DEBUG |
---|
| 61 | int ret; |
---|
| 62 | #endif |
---|
| 63 | |
---|
[2641] | 64 | if ( vio == NULL ) |
---|
| 65 | return -1; |
---|
| 66 | |
---|
| 67 | if ( buf == NULL && count != 0 ) |
---|
| 68 | return -1; |
---|
| 69 | |
---|
[2642] | 70 | #ifdef DEBUG |
---|
| 71 | ret = roar_xcoder_proc(vio->inst, buf, count); |
---|
| 72 | |
---|
| 73 | ROAR_DBG("roar_vio_xcode_proc(vio=%p, buf=%p, count=%lu): ret=%i", vio, buf, (unsigned long) count, ret); |
---|
| 74 | |
---|
| 75 | return !ret ? count : -1; |
---|
| 76 | #else |
---|
| 77 | return !roar_xcoder_proc(vio->inst, buf, count) ? count : -1; |
---|
| 78 | #endif |
---|
[2641] | 79 | } |
---|
| 80 | |
---|
| 81 | off_t roar_vio_xcode_lseek (struct roar_vio_calls * vio, off_t offset, int whence); |
---|
| 82 | int roar_vio_xcode_nonblock(struct roar_vio_calls * vio, int state); |
---|
| 83 | int roar_vio_xcode_sync (struct roar_vio_calls * vio); |
---|
| 84 | int roar_vio_xcode_ctl (struct roar_vio_calls * vio, int cmd, void * data); |
---|
| 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)); |
---|
| 119 | |
---|
| 120 | calls->inst = (void*)bixcoder; |
---|
| 121 | |
---|
| 122 | calls->close = roar_vio_bixcode_close; |
---|
| 123 | |
---|
| 124 | calls->read = roar_vio_bixcode_read; |
---|
| 125 | calls->write = roar_vio_bixcode_write; |
---|
| 126 | |
---|
| 127 | return 0; |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | ssize_t roar_vio_bixcode_read (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 131 | |
---|
| 132 | if ( vio == NULL ) |
---|
| 133 | return -1; |
---|
| 134 | |
---|
| 135 | if ( buf == NULL && count != 0 ) |
---|
| 136 | return -1; |
---|
| 137 | |
---|
| 138 | return !roar_bixcoder_read(vio->inst, buf, count) ? count : -1; |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | ssize_t roar_vio_bixcode_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 142 | |
---|
| 143 | if ( vio == NULL ) |
---|
| 144 | return -1; |
---|
| 145 | |
---|
| 146 | if ( buf == NULL && count != 0 ) |
---|
| 147 | return -1; |
---|
| 148 | |
---|
| 149 | return !roar_bixcoder_write(vio->inst, buf, count) ? count : -1; |
---|
| 150 | } |
---|
| 151 | |
---|
[2641] | 152 | off_t roar_vio_bixcode_lseek (struct roar_vio_calls * vio, off_t offset, int whence); |
---|
| 153 | int roar_vio_bixcode_nonblock(struct roar_vio_calls * vio, int state); |
---|
| 154 | int roar_vio_bixcode_sync (struct roar_vio_calls * vio); |
---|
| 155 | int roar_vio_bixcode_ctl (struct roar_vio_calls * vio, int cmd, void * data); |
---|
[2644] | 156 | |
---|
| 157 | int roar_vio_bixcode_close (struct roar_vio_calls * vio) { |
---|
| 158 | int ret = 0; |
---|
| 159 | |
---|
| 160 | if ( vio == NULL ) |
---|
| 161 | return -1; |
---|
| 162 | |
---|
| 163 | if ( roar_bixcoder_close(vio->inst) == -1 ) |
---|
| 164 | ret = -1; |
---|
| 165 | |
---|
| 166 | if ( vio->inst != NULL ) |
---|
[3063] | 167 | roar_mm_free(vio->inst); |
---|
[2644] | 168 | |
---|
| 169 | return ret; |
---|
| 170 | } |
---|
[2639] | 171 | |
---|
| 172 | //ll |
---|