source: roaraudio/libroardsp/vio_transcode.c @ 5278:b3e0dd3f3141

Last change on this file since 5278:b3e0dd3f3141 was 5278:b3e0dd3f3141, checked in by phi, 12 years ago

last parts of merging _nonblock into _ctl and fixed sizeof(cmd) of _ctls

File size: 3.9 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) ? (ssize_t)count : -1;
79#endif
80}
81
82int     roar_vio_xcode_sync    (struct roar_vio_calls * vio);
83
84int     roar_vio_xcode_close   (struct roar_vio_calls * vio) {
85 int ret = 0;
86
87 if ( vio == NULL )
88  return -1;
89
90 if ( roar_xcoder_close(vio->inst) == -1 )
91  ret = -1;
92
93 if ( vio->inst != NULL )
94  roar_mm_free(vio->inst);
95
96 return ret;
97}
98
99int     roar_vio_open_bixcode    (struct roar_vio_calls * calls, struct roar_audio_info * info,
100                                  struct roar_vio_calls * dst) {
101 struct roar_bixcoder * bixcoder = roar_mm_malloc(sizeof(struct roar_bixcoder));
102
103 if ( bixcoder == NULL )
104  return -1;
105
106 if ( calls == NULL || info == NULL || dst == NULL ) {
107  roar_mm_free(bixcoder);
108  return -1;
109 }
110
111 if ( roar_bixcoder_init(bixcoder, info, dst) == -1 ) {
112  roar_mm_free(bixcoder);
113  return -1;
114 }
115
116 memset(calls, 0, sizeof(struct roar_vio_calls));
117
118 calls->inst   = (void*)bixcoder;
119
120 calls->close  = roar_vio_bixcode_close;
121
122 calls->read  = roar_vio_bixcode_read;
123 calls->write = roar_vio_bixcode_write;
124
125 return 0;
126}
127
128ssize_t roar_vio_bixcode_read    (struct roar_vio_calls * vio, void *buf, size_t count) {
129
130 if ( vio == NULL )
131  return -1;
132
133 if ( buf == NULL && count != 0 )
134  return -1;
135
136 return !roar_bixcoder_read(vio->inst, buf, count) ? (ssize_t)count : -1;
137}
138
139ssize_t roar_vio_bixcode_write   (struct roar_vio_calls * vio, void *buf, size_t count) {
140
141 if ( vio == NULL )
142  return -1;
143
144 if ( buf == NULL && count != 0 )
145  return -1;
146
147 return !roar_bixcoder_write(vio->inst, buf, count) ? (ssize_t)count : -1;
148}
149
150int     roar_vio_bixcode_sync    (struct roar_vio_calls * vio);
151
152int     roar_vio_bixcode_close   (struct roar_vio_calls * vio) {
153 int ret = 0;
154
155 if ( vio == NULL )
156  return -1;
157
158 if ( roar_bixcoder_close(vio->inst) == -1 )
159  ret = -1;
160
161 if ( vio->inst != NULL )
162  roar_mm_free(vio->inst);
163
164 return ret;
165}
166
167//ll
Note: See TracBrowser for help on using the repository browser.