source: roaraudio/libroardsp/vio_transcode.c @ 4708:c9d40761088a

Last change on this file since 4708:c9d40761088a was 4708:c9d40761088a, checked in by phi, 13 years ago

updated copyright statements

File size: 4.4 KB
Line 
1//vio_transcode.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "libroardsp.h"
27
28int     roar_vio_open_xcode    (struct roar_vio_calls * calls, int encoder, struct roar_audio_info * info,
29                                struct roar_vio_calls * dst) {
30 struct roar_xcoder * xcoder = roar_mm_malloc(sizeof(struct roar_xcoder));
31
32 if ( xcoder == NULL )
33  return -1;
34
35 if ( calls == NULL || info == NULL || dst == NULL ) {
36  roar_mm_free(xcoder);
37  return -1;
38 }
39
40 if ( roar_xcoder_init(xcoder, encoder, info, dst) == -1 ) {
41  roar_mm_free(xcoder);
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
60ssize_t roar_vio_xcode_proc    (struct roar_vio_calls * vio, void *buf, size_t count) {
61#ifdef DEBUG
62 int ret;
63#endif
64
65 if ( vio == NULL )
66  return -1;
67
68 if ( buf == NULL && count != 0 )
69  return -1;
70
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
80}
81
82off_t   roar_vio_xcode_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
83int     roar_vio_xcode_nonblock(struct roar_vio_calls * vio, int state);
84int     roar_vio_xcode_sync    (struct roar_vio_calls * vio);
85int     roar_vio_xcode_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
86
87int     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 )
97  roar_mm_free(vio->inst);
98
99 return ret;
100}
101
102int     roar_vio_open_bixcode    (struct roar_vio_calls * calls, struct roar_audio_info * info,
103                                  struct roar_vio_calls * dst) {
104 struct roar_bixcoder * bixcoder = roar_mm_malloc(sizeof(struct roar_bixcoder));
105
106 if ( bixcoder == NULL )
107  return -1;
108
109 if ( calls == NULL || info == NULL || dst == NULL ) {
110  roar_mm_free(bixcoder);
111  return -1;
112 }
113
114 if ( roar_bixcoder_init(bixcoder, info, dst) == -1 ) {
115  roar_mm_free(bixcoder);
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
131ssize_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
142ssize_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
153off_t   roar_vio_bixcode_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
154int     roar_vio_bixcode_nonblock(struct roar_vio_calls * vio, int state);
155int     roar_vio_bixcode_sync    (struct roar_vio_calls * vio);
156int     roar_vio_bixcode_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
157
158int     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 )
168  roar_mm_free(vio->inst);
169
170 return ret;
171}
172
173//ll
Note: See TracBrowser for help on using the repository browser.