2 * ALSA input and output
3 * Copyright (c) 2007 Luca Abeni ( lucabe72 email it )
4 * Copyright (c) 2007 Benoit Fouet ( benoit fouet free fr )
6 * This file is part of FFmpeg.
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.
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.
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
25 * ALSA input and output: definitions and structures
26 * @author Luca Abeni ( lucabe72 email it )
27 * @author Benoit Fouet ( benoit fouet free fr )
30 #ifndef AVDEVICE_ALSA_AUDIO_H
31 #define AVDEVICE_ALSA_AUDIO_H
33 #include <alsa/asoundlib.h>
35 #include "libavutil/log.h"
36 #include "timefilter.h"
39 /* XXX: we make the assumption that the soundcard accepts this format */
40 /* XXX: find better solution with "preinit" method, needed also in
42 #define DEFAULT_CODEC_ID AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE)
44 typedef void (*ff_reorder_func)(const void *, void *, int);
46 #define ALSA_BUFFER_SIZE_MAX 65536
48 typedef struct AlsaData {
51 int frame_size; ///< bytes per sample * channels
52 int period_size; ///< preferred size for reads and writes, in frames
53 int sample_rate; ///< sample rate set by user
54 int channels; ///< number of channels set by user
56 TimeFilter *timefilter;
57 void (*reorder_func)(const void *, void *, int);
59 int reorder_buf_size; ///< in frames
65 * @param s media file handle
66 * @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
67 * @param sample_rate in: requested sample rate;
68 * out: actually selected sample rate
69 * @param channels number of channels
70 * @param codec_id in: requested AVCodecID or AV_CODEC_ID_NONE;
71 * out: actually selected AVCodecID, changed only if
72 * AV_CODEC_ID_NONE was requested
74 * @return 0 if OK, AVERROR_xxx on error
76 int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
77 unsigned int *sample_rate,
78 int channels, enum AVCodecID *codec_id);
83 * @param s1 media file handle
87 int ff_alsa_close(AVFormatContext *s1);
90 * Try to recover from ALSA buffer underrun.
92 * @param s1 media file handle
93 * @param err error code reported by the previous ALSA call
95 * @return 0 if OK, AVERROR_xxx on error
97 int ff_alsa_xrun_recover(AVFormatContext *s1, int err);
99 int ff_alsa_extend_reorder_buf(AlsaData *s, int size);
101 #endif /* AVDEVICE_ALSA_AUDIO_H */