AVFrame: add side data.
[FFMpeg-mirror/mplayer-patches.git] / libavdevice / alsa-audio.h
blob26eaee6acf6e938c1ce91934f67bc34675ce77c1
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 )
6 * This file is part of Libav.
8 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 /**
24 * @file
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>
34 #include "config.h"
35 #include "libavformat/avformat.h"
36 #include "libavutil/log.h"
38 /* XXX: we make the assumption that the soundcard accepts this format */
39 /* XXX: find better solution with "preinit" method, needed also in
40 other formats */
41 #define DEFAULT_CODEC_ID AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE)
43 #define ALSA_BUFFER_SIZE_MAX 32768
45 typedef struct AlsaData {
46 AVClass *class;
47 snd_pcm_t *h;
48 int frame_size; ///< preferred size for reads and writes
49 int period_size; ///< bytes per sample * channels
50 int sample_rate; ///< sample rate set by user
51 int channels; ///< number of channels set by user
52 void (*reorder_func)(const void *, void *, int);
53 void *reorder_buf;
54 int reorder_buf_size; ///< in frames
55 } AlsaData;
57 /**
58 * Open an ALSA PCM.
60 * @param s media file handle
61 * @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
62 * @param sample_rate in: requested sample rate;
63 * out: actually selected sample rate
64 * @param channels number of channels
65 * @param codec_id in: requested AVCodecID or AV_CODEC_ID_NONE;
66 * out: actually selected AVCodecID, changed only if
67 * AV_CODEC_ID_NONE was requested
69 * @return 0 if OK, AVERROR_xxx on error
71 int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
72 unsigned int *sample_rate,
73 int channels, enum AVCodecID *codec_id);
75 /**
76 * Close the ALSA PCM.
78 * @param s1 media file handle
80 * @return 0
82 int ff_alsa_close(AVFormatContext *s1);
84 /**
85 * Try to recover from ALSA buffer underrun.
87 * @param s1 media file handle
88 * @param err error code reported by the previous ALSA call
90 * @return 0 if OK, AVERROR_xxx on error
92 int ff_alsa_xrun_recover(AVFormatContext *s1, int err);
94 int ff_alsa_extend_reorder_buf(AlsaData *s, int size);
96 #endif /* AVDEVICE_ALSA_AUDIO_H */