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
80 }
81
82 /* take real parameters */
89 /* microseconds instead of seconds, MHz instead of Hz */
91 s->period_size, 1.5E-6);
94
95 return 0;
96
100 }
101
103 {
105 int res;
107 snd_pcm_sframes_t delay = 0;
108
114 }
115
116 do {
117 while ((res = snd_pcm_readi(
s->h,
s->pkt->data +
s->pkt->size,
s->period_size -
s->pkt->size /
s->frame_size)) < 0) {
118 if (res == -EAGAIN) {
120 }
124 snd_strerror(res));
126 }
128 }
129 s->pkt->size += res *
s->frame_size;
130 }
while (
s->pkt->size <
s->period_size *
s->frame_size);
131
134 snd_pcm_delay(
s->h, &delay);
135 dts -=
av_rescale(delay + res, 1000000,
s->sample_rate);
137 s->last_period = res;
138
139 return 0;
140 }
141
143 {
145 }
146
151 };
152
159 };
160
171 };