OSDN Git Service

cmdutils: add support for caller-provided option context.
[coroid/libav_saccubus.git] / libavdevice / alsa-audio.h
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 Libav.
7  *
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.
12  *
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.
17  *
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
21  */
22
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 )
28  */
29
30 #ifndef AVDEVICE_ALSA_AUDIO_H
31 #define AVDEVICE_ALSA_AUDIO_H
32
33 #include <alsa/asoundlib.h>
34 #include "config.h"
35 #include "libavformat/avformat.h"
36 #include "libavutil/log.h"
37
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(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE)
42
43 #define ALSA_BUFFER_SIZE_MAX 32768
44
45 typedef struct {
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;
56
57 /**
58  * Open an ALSA PCM.
59  *
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 CodecID or CODEC_ID_NONE;
66  *                 out: actually selected CodecID, changed only if
67  *                 CODEC_ID_NONE was requested
68  *
69  * @return 0 if OK, AVERROR_xxx on error
70  */
71 int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
72                  unsigned int *sample_rate,
73                  int channels, enum CodecID *codec_id);
74
75 /**
76  * Close the ALSA PCM.
77  *
78  * @param s1 media file handle
79  *
80  * @return 0
81  */
82 int ff_alsa_close(AVFormatContext *s1);
83
84 /**
85  * Try to recover from ALSA buffer underrun.
86  *
87  * @param s1 media file handle
88  * @param err error code reported by the previous ALSA call
89  *
90  * @return 0 if OK, AVERROR_xxx on error
91  */
92 int ff_alsa_xrun_recover(AVFormatContext *s1, int err);
93
94 int ff_alsa_extend_reorder_buf(AlsaData *s, int size);
95
96 #endif /* AVDEVICE_ALSA_AUDIO_H */