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: output
26 * @author Luca Abeni ( lucabe72 email it )
27 * @author Benoit Fouet ( benoit fouet free fr )
28 *
29 * This avdevice encoder can play audio to an ALSA (Advanced Linux
30 * Sound Architecture) device.
31 *
32 * The filename parameter is the name of an ALSA PCM device capable of
33 * capture, for example "default" or "plughw:1"; see the ALSA documentation
34 * for naming conventions. The empty string is equivalent to "default".
35 *
36 * The playback period is set to the lower value available for the device,
37 * which gives a low latency suitable for real-time playback.
38 */
39
40 #include <alsa/asoundlib.h>
41
45
46
51
53 {
56 unsigned int sample_rate;
58 int res;
59
63 }
65
68 res =
ff_alsa_open(s1, SND_PCM_STREAM_PLAYBACK, &sample_rate,
72 "sample rate %d not available, nearest is %d\n",
75 }
77
78 return res;
79
83 }
84
86 {
88 int res;
91
92 size /=
s->frame_size;
96
97 if (
s->reorder_func) {
98 if (
size >
s->reorder_buf_size)
101 s->reorder_func(buf,
s->reorder_buf,
size);
102 buf =
s->reorder_buf;
103 }
104 while ((res = snd_pcm_writei(
s->h, buf,
size)) < 0) {
105 if (res == -EAGAIN) {
106
108 }
109
112 snd_strerror(res));
113
115 }
116 }
117
118 return 0;
119 }
120
123 {
126
127 /* ff_alsa_open() should have accepted only supported formats */
131 /* set only used fields */
133 pkt.
size = (*frame)->nb_samples *
s->frame_size;
134 pkt.
dts = (*frame)->pkt_dts;
137 }
138
139 static void
142 {
144 snd_pcm_sframes_t delay = 0;
146 snd_pcm_delay(
s->h, &delay);
147 *dts =
s->timestamp - delay;
148 }
149
151 {
153 }
154
160 };
161
176 };