1 /*
2 * ALSA input and output
3 * Copyright (c) 2007 Luca Abeni ( lucabe72 email it )
4 * Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr )
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /**
24 * @file
25 * ALSA input and output: input
26 * @author Luca Abeni ( lucabe72 email it )
27 * @author Benoit Fouet ( benoit fouet free fr )
28 * @author Nicolas George ( nicolas george normalesup org )
29 *
30 * This avdevice decoder can capture audio from an ALSA (Advanced
31 * Linux Sound Architecture) device.
32 *
33 * The filename parameter is the name of an ALSA PCM device capable of
34 * capture, for example "default" or "plughw:1"; see the ALSA documentation
35 * for naming conventions. The empty string is equivalent to "default".
36 *
37 * The capture period is set to the lower value available for the device,
38 * which gives a low latency suitable for real-time capture.
39 *
40 * The PTS are an Unix time in microsecond.
41 *
42 * Due to a bug in the ALSA library
43 * (https://bugtrack.alsa-project.org/alsa-bug/view.php?id=4308), this
44 * decoder does not work with certain ALSA plugins, especially the dsnoop
45 * plugin.
46 */
47
48 #include <alsa/asoundlib.h>
49
54
57
60
62 {
67
69 if (!st) {
71
73 }
75
76 #if FF_API_ALSA_CHANNELS
77 if (
s->channels > 0) {
79 s->ch_layout.nb_channels =
s->channels;
80 }
81 #endif
82
87 }
88
89 /* take real parameters */
98 /* microseconds instead of seconds, MHz instead of Hz */
100 s->period_size, 1.5E-6);
101 if (!
s->timefilter) {
104 }
105
106 return 0;
107
111 }
112
114 {
116 int res;
118 snd_pcm_sframes_t delay = 0;
119
125 }
126
127 do {
128 while ((res = snd_pcm_readi(
s->h,
s->pkt->data +
s->pkt->size,
s->period_size -
s->pkt->size /
s->frame_size)) < 0) {
129 if (res == -EAGAIN) {
131 }
135 snd_strerror(res));
137 }
139 }
140 s->pkt->size += res *
s->frame_size;
141 }
while (
s->pkt->size <
s->period_size *
s->frame_size);
142
145 snd_pcm_delay(
s->h, &delay);
146 dts -=
av_rescale(delay + res, 1000000,
s->sample_rate);
148 s->last_period = res;
149
150 return 0;
151 }
152
154 {
156 }
157
160 #if FF_API_ALSA_CHANNELS
162 #endif
165 };
166
173 };
174
185 };