source: roaraudio/libroardsp/vio_transcode.c @ 3329:d939b3aedbc5

Last change on this file since 3329:d939b3aedbc5 was 3063:955233719a84, checked in by phi, 14 years ago

use memory functions from libroar, not libc, fixed a small memory leak

File size: 4.3 KB
Line 
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
27int     roar_vio_open_xcode    (struct roar_vio_calls * calls, int encoder, struct roar_audio_info * info,
28                                struct roar_vio_calls * dst) {
29 struct roar_xcoder * xcoder = roar_mm_malloc(sizeof(struct roar_xcoder));
30
31 if ( xcoder == NULL )
32  return -1;
33
34 if ( calls == NULL || info == NULL || dst == NULL ) {
35  roar_mm_free(xcoder);
36  return -1;
37 }
38
39 if ( roar_xcoder_init(xcoder, encoder, info, dst) == -1 ) {
40  roar_mm_free(xcoder);
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
59ssize_t roar_vio_xcode_proc    (struct roar_vio_calls * vio, void *buf, size_t count) {
60#ifdef DEBUG
61 int ret;
62#endif
63
64 if ( vio == NULL )
65  return -1;
66
67 if ( buf == NULL && count != 0 )
68  return -1;
69
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
79}
80
81off_t   roar_vio_xcode_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
82int     roar_vio_xcode_nonblock(struct roar_vio_calls * vio, int state);
83int     roar_vio_xcode_sync    (struct roar_vio_calls * vio);
84int     roar_vio_xcode_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
85
86int     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 )
96  roar_mm_free(vio->inst);
97
98 return ret;
99}
100
101int     roar_vio_open_bixcode    (struct roar_vio_calls * calls, struct roar_audio_info * info,
102                                  struct roar_vio_calls * dst) {
103 struct roar_bixcoder * bixcoder = roar_mm_malloc(sizeof(struct roar_bixcoder));
104
105 if ( bixcoder == NULL )
106  return -1;
107
108 if ( calls == NULL || info == NULL || dst == NULL ) {
109  roar_mm_free(bixcoder);
110  return -1;
111 }
112
113 if ( roar_bixcoder_init(bixcoder, info, dst) == -1 ) {
114  roar_mm_free(bixcoder);
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
130ssize_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
141ssize_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
152off_t   roar_vio_bixcode_lseek   (struct roar_vio_calls * vio, off_t offset, int whence);
153int     roar_vio_bixcode_nonblock(struct roar_vio_calls * vio, int state);
154int     roar_vio_bixcode_sync    (struct roar_vio_calls * vio);
155int     roar_vio_bixcode_ctl     (struct roar_vio_calls * vio, int cmd, void * data);
156
157int     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 )
167  roar_mm_free(vio->inst);
168
169 return ret;
170}
171
172//ll
Note: See TracBrowser for help on using the repository browser.