Go to the documentation of this file.
31 #include "config_components.h"
33 #include <alsa/asoundlib.h>
64 default:
return SND_PCM_FORMAT_UNKNOWN;
68 #define MAKE_REORDER_FUNC(NAME, TYPE, CHANNELS, LAYOUT, MAP) \
69 static void alsa_reorder_ ## NAME ## _ ## LAYOUT(const void *in_v, \
73 const TYPE *in = in_v; \
83 #define MAKE_REORDER_FUNCS(CHANNELS, LAYOUT, MAP) \
84 MAKE_REORDER_FUNC(int8, int8_t, CHANNELS, LAYOUT, MAP) \
85 MAKE_REORDER_FUNC(int16, int16_t, CHANNELS, LAYOUT, MAP) \
86 MAKE_REORDER_FUNC(int32, int32_t, CHANNELS, LAYOUT, MAP) \
87 MAKE_REORDER_FUNC(f32, float, CHANNELS, LAYOUT, MAP)
130 static const struct {
176 snd_pcm_chmap_t *chmap = snd_pcm_get_chmap(
h);
182 if (
layout->nb_channels != chmap->channels) {
193 for (
unsigned i = 0;
i < chmap->channels;
i++) {
195 SND_CHMAP_POSITION_MASK);
198 "unknown ALSA channel position %u.\n",
199 chmap->pos[
i] & SND_CHMAP_POSITION_MASK);
241 default:
return AVERROR(ENOSYS);
253 return s->reorder_func ? 0 :
AVERROR(ENOSYS);
257 unsigned int *sample_rate,
261 const char *audio_device;
265 snd_pcm_hw_params_t *hw_params;
266 snd_pcm_uframes_t buffer_size, period_size;
268 if (
ctx->
url[0] == 0) audio_device =
"default";
269 else audio_device =
ctx->
url;
274 if (
format == SND_PCM_FORMAT_UNKNOWN) {
279 flags = SND_PCM_NONBLOCK;
281 res = snd_pcm_open(&
h, audio_device,
mode,
flags);
284 audio_device, snd_strerror(res));
288 res = snd_pcm_hw_params_malloc(&hw_params);
295 res = snd_pcm_hw_params_any(
h, hw_params);
302 res = snd_pcm_hw_params_set_access(
h, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
309 res = snd_pcm_hw_params_set_format(
h, hw_params,
format);
316 res = snd_pcm_hw_params_set_rate_near(
h, hw_params, sample_rate, 0);
325 if (
mode == SND_PCM_STREAM_CAPTURE &&
layout->nb_channels == 0) {
327 if (snd_pcm_hw_params_test_channels(
h, hw_params,
channels) < 0) {
328 res = snd_pcm_hw_params_get_channels_min(hw_params, &
channels);
335 "stereo not supported, falling back to %u channel(s)\n",
channels);
341 res = snd_pcm_hw_params_set_channels(
h, hw_params,
layout->nb_channels);
344 layout->nb_channels, snd_strerror(res));
350 snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size);
353 res = snd_pcm_hw_params_set_buffer_size_near(
h, hw_params, &buffer_size);
360 snd_pcm_hw_params_get_period_size_min(hw_params, &period_size,
NULL);
362 period_size = buffer_size / 4;
363 res = snd_pcm_hw_params_set_period_size_near(
h, hw_params, &period_size,
NULL);
369 s->period_size = period_size;
371 res = snd_pcm_hw_params(
h, hw_params);
378 snd_pcm_hw_params_free(hw_params);
383 if (
mode == SND_PCM_STREAM_CAPTURE &&
397 name,
mode == SND_PCM_STREAM_PLAYBACK ?
"playback" :
"capture");
399 if (
s->reorder_func) {
400 s->reorder_buf_size = buffer_size;
415 snd_pcm_hw_params_free(hw_params);
425 if (snd_pcm_stream(
s->h) == SND_PCM_STREAM_PLAYBACK) {
426 snd_pcm_nonblock(
s->h, 0);
430 if (CONFIG_ALSA_INDEV)
440 snd_pcm_t *handle =
s->h;
444 err = snd_pcm_prepare(handle);
446 av_log(s1,
AV_LOG_ERROR,
"cannot recover from underrun (snd_pcm_prepare failed: %s)\n", snd_strerror(err));
451 }
else if (err == -ESTRPIPE) {
462 int size =
s->reorder_buf_size;
466 while (
size < min_size)
472 s->reorder_buf_size =
size;
483 const char *
filter = stream_type == SND_PCM_STREAM_PLAYBACK ?
"Output" :
"Input";
485 if (snd_device_name_hint(-1,
"pcm", &hints) < 0)
489 name = snd_device_name_get_hint(*n,
"NAME");
490 descr = snd_device_name_get_hint(*n,
"DESC");
491 io = snd_device_name_get_hint(*n,
"IOID");
492 if (!io || !strcmp(io,
filter)) {
501 else if ((
tmp = strrchr(descr,
'\n')) &&
tmp[1])
528 snd_device_name_free_hint(hints);
#define PICK_REORDER(layout)
#define AV_LOG_WARNING
Something somehow does not look correct.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
char * device_name
device name, format depends on device
#define ALSA_BUFFER_SIZE_MAX
#define AV_CHANNEL_LAYOUT_2_2
int nb_devices
number of autodetected devices
#define AV_LOG_VERBOSE
Detailed information.
void(* filter)(uint8_t *src, int stride, int qscale)
static av_cold int find_reorder_func(AlsaData *s, int codec_id, const AVChannelLayout *layout, int out)
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
AVDeviceInfo ** devices
list of autodetected devices
@ AV_CHAN_BOTTOM_FRONT_LEFT
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
#define flags(name, subs,...)
#define AV_CHANNEL_LAYOUT_7POINT1
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
int flags
Flags modifying the (de)muxer behaviour.
@ AV_CHAN_UNKNOWN
Channel contains data, but its position is unknown.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, unsigned int *sample_rate, AVChannelLayout *layout, enum AVCodecID *codec_id)
Open an ALSA PCM.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static AVFormatContext * ctx
#define MAKE_REORDER_FUNCS(CHANNELS, LAYOUT, MAP)
int ff_alsa_extend_reorder_buf(AlsaData *s, int min_size)
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL
The specified retype target order is ignored and the simplest possible (canonical) order is used for ...
@ AV_CHAN_TOP_BACK_CENTER
@ AV_CHAN_BOTTOM_FRONT_RIGHT
av_cold int ff_alsa_close(AVFormatContext *s1)
Close the ALSA PCM.
@ AV_CHAN_FRONT_RIGHT_OF_CENTER
AVCodecID
Identify the syntax and semantics of the bitstream.
static int alsa_get_chmap(AVFormatContext *ctx, snd_pcm_t *h, AVChannelLayout *layout)
An AVChannelLayout holds information about the channel layout of audio data.
#define i(width, name, range_min, range_max)
static enum AVChannel alsa_chmap_pos_to_av_chan(unsigned int pos)
char * url
input or output URL.
Structure describes basic parameters of the device.
int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags)
Change the AVChannelOrder of a channel layout.
#define AVERROR_EXTERNAL
Generic error in an external library.
@ AV_CHAN_TOP_FRONT_RIGHT
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
@ AV_CHAN_FRONT_LEFT_OF_CENTER
char * device_description
human friendly name
@ AV_CHAN_UNUSED
Channel is empty can be safely skipped.
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels)
Initialize a custom channel layout with the specified number of channels.
static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
void ff_timefilter_destroy(TimeFilter *self)
Free all resources associated with the filter.
#define AV_CHANNEL_LAYOUT_QUAD
#define av_malloc_array(a, b)
@ AV_CHAN_NONE
Invalid channel index.
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
int default_device
index of default device or -1 if no default
@ AV_CHAN_LOW_FREQUENCY_2
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int ff_alsa_xrun_recover(AVFormatContext *s1, int err)
Try to recover from ALSA buffer underrun.
@ AV_CHAN_BOTTOM_FRONT_CENTER
@ AV_CHAN_TOP_FRONT_CENTER
int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type)
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_5POINT0
#define AV_CHANNEL_LAYOUT_5POINT1
void * priv_data
Format private data.