FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 
39 /* XXX: we make the assumption that the soundcard accepts this format */
40 /* XXX: find better solution with "preinit" method, needed also in
41  other formats */
42 #define DEFAULT_CODEC_ID AV_NE(AV_CODEC_ID_PCM_S16BE, AV_CODEC_ID_PCM_S16LE)
43 
44 typedef void (*ff_reorder_func)(const void *, void *, int);
45 
46 #define ALSA_BUFFER_SIZE_MAX 131072
47 
48 typedef struct AlsaData {
49  AVClass *class;
50  snd_pcm_t *h;
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
57  void (*reorder_func)(const void *, void *, int);
58  void *reorder_buf;
59  int reorder_buf_size; ///< in frames
60  int64_t timestamp; ///< current timestamp, without latency applied.
61 } AlsaData;
62 
63 /**
64  * Open an ALSA PCM.
65  *
66  * @param s media file handle
67  * @param mode either SND_PCM_STREAM_CAPTURE or SND_PCM_STREAM_PLAYBACK
68  * @param sample_rate in: requested sample rate;
69  * out: actually selected sample rate
70  * @param channels number of channels
71  * @param codec_id in: requested AVCodecID or AV_CODEC_ID_NONE;
72  * out: actually selected AVCodecID, changed only if
73  * AV_CODEC_ID_NONE was requested
74  *
75  * @return 0 if OK, AVERROR_xxx on error
76  */
78 int ff_alsa_open(AVFormatContext *s, snd_pcm_stream_t mode,
79  unsigned int *sample_rate,
80  int channels, enum AVCodecID *codec_id);
81 
82 /**
83  * Close the ALSA PCM.
84  *
85  * @param s1 media file handle
86  *
87  * @return 0
88  */
90 
91 /**
92  * Try to recover from ALSA buffer underrun.
93  *
94  * @param s1 media file handle
95  * @param err error code reported by the previous ALSA call
96  *
97  * @return 0 if OK, AVERROR_xxx on error
98  */
101 
104 
106 int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type);
107 
108 #endif /* AVDEVICE_ALSA_H */
const char * s
Definition: avisynth_c.h:768
channels
Definition: aptx.c:30
int64_t timestamp
current timestamp, without latency applied.
Definition: alsa.h:60
Format I/O context.
Definition: avformat.h:1342
Opaque type representing a time filter state.
Definition: timefilter.c:30
void(* reorder_func)(const void *, void *, int)
Definition: alsa.h:57
ptrdiff_t size
Definition: opengl_enc.c:101
Main libavdevice API header.
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:167
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
Definition: alsa.h:48
av_warn_unused_result int ff_alsa_extend_reorder_buf(AlsaData *s, int size)
Definition: alsa.c:333
av_warn_unused_result int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type)
Definition: alsa.c:350
av_warn_unused_result int ff_alsa_xrun_recover(AVFormatContext *s1, int err)
Try to recover from ALSA buffer underrun.
Definition: alsa.c:312
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
void(* ff_reorder_func)(const void *, void *, int)
Definition: alsa.h:44
int channels
number of channels set by user
Definition: alsa.h:54
enum AVCodecID codec_id
Definition: vaapi_decode.c:362
sample_rate
void * reorder_buf
Definition: alsa.h:58
int ff_alsa_close(AVFormatContext *s1)
Close the ALSA PCM.
Definition: alsa.c:299
TimeFilter * timefilter
Definition: alsa.h:56
Describe the class of an AVClass context structure.
Definition: log.h:67
#define s1
Definition: regdef.h:38
List of devices.
Definition: avdevice.h:460
int period_size
preferred size for reads and writes, in frames
Definition: alsa.h:52
#define av_warn_unused_result
Definition: attributes.h:56
int
int last_period
Definition: alsa.h:55
snd_pcm_t * h
Definition: alsa.h:50
int frame_size
bytes per sample * channels
Definition: alsa.h:51
int sample_rate
sample rate set by user
Definition: alsa.h:53
int reorder_buf_size
in frames
Definition: alsa.h:59
mode
Use these values in ebur128_init (or'ed).
Definition: ebur128.h:83