source: roaraudio/libroardsp/vio_transcode.c @ 5961:06e7fd9e4c25

Last change on this file since 5961:06e7fd9e4c25 was 5961:06e7fd9e4c25, checked in by phi, 10 years ago

Updates of copyright and license headers

File size: 4.0 KB
Line 
1//vio_transcode.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2014
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 calls->flags  = ROAR_VIO_FLAGS_NONE;
47 calls->refc   = 1;
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
62ssize_t roar_vio_xcode_proc    (struct roar_vio_calls * vio, void *buf, size_t count) {
63#ifdef DEBUG
64 int ret;
65#endif
66
67 if ( vio == NULL )
68  return -1;
69
70 if ( buf == NULL && count != 0 )
71  return -1;
72
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
80 return !roar_xcoder_proc(vio->inst, buf, count) ? (ssize_t)count : -1;
81#endif
82}
83
84int     roar_vio_xcode_sync    (struct roar_vio_calls * vio);
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 calls->flags = ROAR_VIO_FLAGS_NONE;
120 calls->refc  = 1;
121
122 calls->inst  = (void*)bixcoder;
123
124 calls->close = roar_vio_bixcode_close;
125
126 calls->read  = roar_vio_bixcode_read;
127 calls->write = roar_vio_bixcode_write;
128
129 return 0;
130}
131
132ssize_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
140 return !roar_bixcoder_read(vio->inst, buf, count) ? (ssize_t)count : -1;
141}
142
143ssize_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
151 return !roar_bixcoder_write(vio->inst, buf, count) ? (ssize_t)count : -1;
152}
153
154int     roar_vio_bixcode_sync    (struct roar_vio_calls * vio);
155
156int     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 )
166  roar_mm_free(vio->inst);
167
168 return ret;
169}
170
171//ll
Note: See TracBrowser for help on using the repository browser.