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
24 #include <string.h>
25
26 #if HAVE_UNISTD_H
27 #include <unistd.h>
28 #endif
29 #include <fcntl.h>
30 #include <sys/ioctl.h>
31 #include <sys/soundcard.h>
32
35
37
39
41 const char *audio_device)
42 {
44 int audio_fd;
46 char *
flip = getenv(
"AUDIO_FLIP_LEFT");
47
48 if (is_output)
50 else
52 if (audio_fd < 0) {
55 }
56
59 }
60
61 /* non blocking mode */
62 if (!is_output) {
63 if (fcntl(audio_fd, F_SETFL, O_NONBLOCK) < 0) {
65 }
66 }
67
69
70 #define CHECK_IOCTL_ERROR(event) \
71 if (err < 0) { \
72 av_log(s1, AV_LOG_ERROR, #event ": %s\n", av_err2str(AVERROR(errno)));\
73 goto fail; \
74 }
75
76 /* select format : favour native format
77 * We don't CHECK_IOCTL_ERROR here because even if failed OSS still may be
78 * usable. If OSS is not usable the SNDCTL_DSP_SETFMTS later is going to
79 * fail anyway. */
80 err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &
tmp);
81 if (err < 0) {
83 }
84
85 #if HAVE_BIGENDIAN
86 if (
tmp & AFMT_S16_BE) {
88 }
else if (
tmp & AFMT_S16_LE) {
90 } else {
92 }
93 #else
94 if (
tmp & AFMT_S16_LE) {
96 }
else if (
tmp & AFMT_S16_BE) {
98 } else {
100 }
101 #endif
102
104 case AFMT_S16_LE:
107 break;
108 case AFMT_S16_BE:
111 break;
112 default:
116 }
117 err=ioctl(audio_fd, SNDCTL_DSP_SETFMT, &
tmp);
119
120 tmp = (
s->channels == 2);
121 err = ioctl(audio_fd, SNDCTL_DSP_STEREO, &
tmp);
123
124 tmp =
s->sample_rate;
125 err = ioctl(audio_fd, SNDCTL_DSP_SPEED, &
tmp);
127 s->sample_rate =
tmp;
/* store real sample rate */
129
130 return 0;
134 #undef CHECK_IOCTL_ERROR
135 }
136
138 {
140 return 0;
141 }