FFmpeg
alsa.h
Go to the documentation of this file.
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: definitions and structures
26  * @author Luca Abeni ( lucabe72 email it )
27  * @author Benoit Fouet ( benoit fouet free fr )
28  */
29 
30 #ifndef AVDEVICE_ALSA_H
31 #define AVDEVICE_ALSA_H
32 
33 #include <alsa/asoundlib.h>
34 #include "config.h"
35 #include "libavutil/log.h"
36 #include "timefilter.h"
37 #include "avdevice.h"
38 #include "version.h"
39 
40 /* XXX: we make the assumption that the soundcard accepts this format */
41 /* XXX: find better solution with "preinit" method, needed also in
42  other formats */
43 #define DEFAULT_CODEC_ID AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE)
44 
45 typedef void (*ff_reorder_func)(const void *, void *, int);
46 
47 #define ALSA_BUFFER_SIZE_MAX 131072
48 
49 typedef struct AlsaData {
50  AVClass *class;
51  snd_pcm_t *h;
52  int frame_size; ///< bytes per sample * channels
53  int period_size; ///< preferred size for reads and writes, in frames
54  int sample_rate; ///< sample rate set by user
55 #if FF_API_ALSA_CHANNELS
56  int channels; ///< number of channels set by user
57 #endif
58  AVChannelLayout ch_layout; ///< Channel layout set by user
61  void (*reorder_func)(const void *, void *, int);
62  void *reorder_buf;
63  int reorder_buf_size; ///< in frames
64  int64_t timestamp; ///< current timestamp, without latency applied.
66 } AlsaData;
67 
68 /**
69  * Open an ALSA PCM.
70  *
71  * @param s media file handle
72  * @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
73  * @param sample_rate in: requested sample rate;
74  * out: actually selected sample rate
75  * @param channels number of channels
76  * @param codec_id in: requested AVCodecID or AV_CODEC_ID_NONE;
77  * out: actually selected AVCodecID, changed only if
78  * AV_CODEC_ID_NONE was requested
79  *
80  * @return 0 if OK, AVERROR_xxx on error
81  */
83 int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
84  unsigned int *sample_rate,
85  int channels, enum AVCodecID *codec_id);
86 
87 /**
88  * Close the ALSA PCM.
89  *
90  * @param s1 media file handle
91  *
92  * @return 0
93  */
95 
96 /**
97  * Try to recover from ALSA buffer underrun.
98  *
99  * @param s1 media file handle
100  * @param err error code reported by the previous ALSA call
101  *
102  * @return 0 if OK, AVERROR_xxx on error
103  */
105 int ff_alsa_xrun_recover(AVFormatContext *s1, int err);
106 
109 
111 int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type);
112 
113 #endif /* AVDEVICE_ALSA_H */
TimeFilter
Opaque type representing a time filter state.
Definition: timefilter.c:34
ff_alsa_xrun_recover
av_warn_unused_result int ff_alsa_xrun_recover(AVFormatContext *s1, int err)
Try to recover from ALSA buffer underrun.
Definition: alsa.c:325
version.h
int64_t
long long int64_t
Definition: coverity.c:34
AlsaData::timestamp
int64_t timestamp
current timestamp, without latency applied.
Definition: alsa.h:64
mode
Definition: swscale.c:52
AlsaData::sample_rate
int sample_rate
sample rate set by user
Definition: alsa.h:54
AlsaData::frame_size
int frame_size
bytes per sample * channels
Definition: alsa.h:52
AlsaData::last_period
int last_period
Definition: alsa.h:59
AlsaData::h
snd_pcm_t * h
Definition: alsa.h:51
AlsaData::ch_layout
AVChannelLayout ch_layout
Channel layout set by user.
Definition: alsa.h:58
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_alsa_extend_reorder_buf
av_warn_unused_result int ff_alsa_extend_reorder_buf(AlsaData *s, int size)
Definition: alsa.c:346
AlsaData::pkt
AVPacket * pkt
Definition: alsa.h:65
ff_alsa_close
int ff_alsa_close(AVFormatContext *s1)
Close the ALSA PCM.
Definition: alsa.c:309
channels
channels
Definition: aptx.h:31
AlsaData::reorder_buf
void * reorder_buf
Definition: alsa.h:62
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
AVFormatContext
Format I/O context.
Definition: avformat.h:1300
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
AlsaData::timefilter
TimeFilter * timefilter
Definition: alsa.h:60
timefilter.h
AlsaData
Definition: alsa.h:49
ff_alsa_open
av_warn_unused_result int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode, unsigned int *sample_rate, int channels, enum AVCodecID *codec_id)
Open an ALSA PCM.
Definition: alsa.c:173
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
size
int size
Definition: twinvq_data.h:10344
avdevice.h
AlsaData::reorder_func
void(* reorder_func)(const void *, void *, int)
Definition: alsa.h:61
av_warn_unused_result
#define av_warn_unused_result
Definition: attributes.h:64
log.h
AlsaData::reorder_buf_size
int reorder_buf_size
in frames
Definition: alsa.h:63
AVDeviceInfoList
List of devices.
Definition: avdevice.h:343
ff_alsa_get_device_list
av_warn_unused_result int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type)
Definition: alsa.c:363
AlsaData::channels
int channels
number of channels set by user
Definition: alsa.h:56
AVPacket
This structure stores compressed data.
Definition: packet.h:516
ff_reorder_func
void(* ff_reorder_func)(const void *, void *, int)
Definition: alsa.h:45
AlsaData::period_size
int period_size
preferred size for reads and writes, in frames
Definition: alsa.h:53