1 /*
2 * Linux audio play and grab interface
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "config.h"
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <stdint.h>
26 #include <string.h>
27 #include <errno.h>
28 #if HAVE_SOUNDCARD_H
29 #include <soundcard.h>
30 #else
31 #include <sys/soundcard.h>
32 #endif
33 #if HAVE_UNISTD_H
34 #include <unistd.h>
35 #endif
36 #include <fcntl.h>
37 #include <sys/ioctl.h>
38
46
47 #define AUDIO_BLOCK_SIZE 4096
48
56 unsigned int flip_left : 1;
60
62 {
64 int audio_fd;
65 int tmp, err;
66 char *
flip = getenv(
"AUDIO_FLIP_LEFT");
67
68 if (is_output)
70 else
72 if (audio_fd < 0) {
75 }
76
77 if (flip && *flip == '1') {
79 }
80
81 /* non blocking mode */
82 if (!is_output) {
83 if (fcntl(audio_fd, F_SETFL, O_NONBLOCK) < 0) {
84 av_log(s1,
AV_LOG_WARNING,
"%s: Could not enable non block mode (%s)\n", audio_device, strerror(errno));
85 }
86 }
87
89
90 /* select format : favour native format */
91 err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp);
92
93 #if HAVE_BIGENDIAN
94 if (tmp & AFMT_S16_BE) {
95 tmp = AFMT_S16_BE;
96 } else if (tmp & AFMT_S16_LE) {
97 tmp = AFMT_S16_LE;
98 } else {
99 tmp = 0;
100 }
101 #else
102 if (tmp & AFMT_S16_LE) {
103 tmp = AFMT_S16_LE;
104 } else if (tmp & AFMT_S16_BE) {
105 tmp = AFMT_S16_BE;
106 } else {
107 tmp = 0;
108 }
109 #endif
110
111 switch(tmp) {
112 case AFMT_S16_LE:
114 break;
115 case AFMT_S16_BE:
117 break;
118 default:
122 }
123 err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp);
124 if (err < 0) {
126 goto fail;
127 }
128
130 err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &tmp);
131 if (err < 0) {
133 goto fail;
134 }
135
137 err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &tmp);
138 if (err < 0) {
140 goto fail;
141 }
144
145 return 0;
146 fail:
149 }
150
152 {
154 return 0;
155 }
156
157 /* sound output support */
159 {
163
168 if (ret < 0) {
170 } else {
171 return 0;
172 }
173 }
174
176 {
181
182 while (size > 0) {
187 for(;;) {
189 if (ret > 0)
190 break;
191 if (ret < 0 && (errno != EAGAIN && errno != EINTR))
193 }
195 }
198 }
199 return 0;
200 }
201
203 {
205
207 return 0;
208 }
209
210 /* grab support */
211
213 {
217
219 if (!st) {
221 }
222
224 if (ret < 0) {
226 }
227
228 /* take real parameters */
233
235 return 0;
236 }
237
239 {
243 struct audio_buf_info abufi;
244
247
249 if (ret <= 0){
252 if (ret<0)
return AVERROR(errno);
254 }
256
257 /* compute pts of the start of the packet */
260 if (ioctl(s->
fd, SNDCTL_DSP_GETISPACE, &abufi) == 0) {
261 bdelay += abufi.bytes;
262 }
263 /* subtract time represented by the number of bytes in the audio fifo */
265
266 /* convert to wanted units */
268
270 int i;
271 short *p = (
short *) pkt->
data;
272
273 for (i = 0; i <
ret; i += 4) {
274 *p = ~*p;
275 p += 2;
276 }
277 }
278 return 0;
279 }
280
282 {
284
286 return 0;
287 }
288
289 #if CONFIG_OSS_INDEV
293 { NULL },
294 };
295
296 static const AVClass oss_demuxer_class = {
302 };
303
312 .priv_class = &oss_demuxer_class,
313 };
314 #endif
315
316 #if CONFIG_OSS_OUTDEV
317 static const AVClass oss_muxer_class = {
322 };
323
328 /* XXX: we make the assumption that the soundcard accepts this format */
329 /* XXX: find better solution with "preinit" method, needed also in
330 other formats */
337 .priv_class = &oss_muxer_class,
338 };
339 #endif