FFmpeg
alsa.c
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: common code
26  * @author Luca Abeni ( lucabe72 email it )
27  * @author Benoit Fouet ( benoit fouet free fr )
28  * @author Nicolas George ( nicolas george normalesup org )
29  */
30 
31 #include "config_components.h"
32 
33 #include <alsa/asoundlib.h>
34 #include "avdevice.h"
35 #include "libavutil/avassert.h"
37 #include "libavutil/mem.h"
38 
39 #include "alsa.h"
40 
41 static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id)
42 {
43  switch(codec_id) {
44  case AV_CODEC_ID_PCM_F64LE: return SND_PCM_FORMAT_FLOAT64_LE;
45  case AV_CODEC_ID_PCM_F64BE: return SND_PCM_FORMAT_FLOAT64_BE;
46  case AV_CODEC_ID_PCM_F32LE: return SND_PCM_FORMAT_FLOAT_LE;
47  case AV_CODEC_ID_PCM_F32BE: return SND_PCM_FORMAT_FLOAT_BE;
48  case AV_CODEC_ID_PCM_S32LE: return SND_PCM_FORMAT_S32_LE;
49  case AV_CODEC_ID_PCM_S32BE: return SND_PCM_FORMAT_S32_BE;
50  case AV_CODEC_ID_PCM_U32LE: return SND_PCM_FORMAT_U32_LE;
51  case AV_CODEC_ID_PCM_U32BE: return SND_PCM_FORMAT_U32_BE;
52  case AV_CODEC_ID_PCM_S24LE: return SND_PCM_FORMAT_S24_3LE;
53  case AV_CODEC_ID_PCM_S24BE: return SND_PCM_FORMAT_S24_3BE;
54  case AV_CODEC_ID_PCM_U24LE: return SND_PCM_FORMAT_U24_3LE;
55  case AV_CODEC_ID_PCM_U24BE: return SND_PCM_FORMAT_U24_3BE;
56  case AV_CODEC_ID_PCM_S16LE: return SND_PCM_FORMAT_S16_LE;
57  case AV_CODEC_ID_PCM_S16BE: return SND_PCM_FORMAT_S16_BE;
58  case AV_CODEC_ID_PCM_U16LE: return SND_PCM_FORMAT_U16_LE;
59  case AV_CODEC_ID_PCM_U16BE: return SND_PCM_FORMAT_U16_BE;
60  case AV_CODEC_ID_PCM_S8: return SND_PCM_FORMAT_S8;
61  case AV_CODEC_ID_PCM_U8: return SND_PCM_FORMAT_U8;
62  case AV_CODEC_ID_PCM_MULAW: return SND_PCM_FORMAT_MU_LAW;
63  case AV_CODEC_ID_PCM_ALAW: return SND_PCM_FORMAT_A_LAW;
64  default: return SND_PCM_FORMAT_UNKNOWN;
65  }
66 }
67 
68 #define MAKE_REORDER_FUNC(NAME, TYPE, CHANNELS, LAYOUT, MAP) \
69 static void alsa_reorder_ ## NAME ## _ ## LAYOUT(const void *in_v, \
70  void *out_v, \
71  int n) \
72 { \
73  const TYPE *in = in_v; \
74  TYPE *out = out_v; \
75  \
76  while (n-- > 0) { \
77  MAP \
78  in += CHANNELS; \
79  out += CHANNELS; \
80  } \
81 }
82 
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)
88 
89 MAKE_REORDER_FUNCS(5, out_50, \
90  out[0] = in[0]; \
91  out[1] = in[1]; \
92  out[2] = in[3]; \
93  out[3] = in[4]; \
94  out[4] = in[2]; \
95  )
96 
97 MAKE_REORDER_FUNCS(6, out_51, \
98  out[0] = in[0]; \
99  out[1] = in[1]; \
100  out[2] = in[4]; \
101  out[3] = in[5]; \
102  out[4] = in[2]; \
103  out[5] = in[3]; \
104  )
105 
106 MAKE_REORDER_FUNCS(8, out_71, \
107  out[0] = in[0]; \
108  out[1] = in[1]; \
109  out[2] = in[4]; \
110  out[3] = in[5]; \
111  out[4] = in[2]; \
112  out[5] = in[3]; \
113  out[6] = in[6]; \
114  out[7] = in[7]; \
115  )
116 
117 #define FORMAT_I8 0
118 #define FORMAT_I16 1
119 #define FORMAT_I32 2
120 #define FORMAT_F32 3
121 
122 #define PICK_REORDER(layout)\
123 switch(format) {\
124  case FORMAT_I8: s->reorder_func = alsa_reorder_int8_out_ ##layout; break;\
125  case FORMAT_I16: s->reorder_func = alsa_reorder_int16_out_ ##layout; break;\
126  case FORMAT_I32: s->reorder_func = alsa_reorder_int32_out_ ##layout; break;\
127  case FORMAT_F32: s->reorder_func = alsa_reorder_f32_out_ ##layout; break;\
128 }
129 
130 static const struct {
131  unsigned int pos;
132  enum AVChannel ch;
134  { SND_CHMAP_MONO, AV_CHAN_FRONT_CENTER },
135  { SND_CHMAP_FL, AV_CHAN_FRONT_LEFT },
136  { SND_CHMAP_FR, AV_CHAN_FRONT_RIGHT },
137  { SND_CHMAP_RL, AV_CHAN_BACK_LEFT },
138  { SND_CHMAP_RR, AV_CHAN_BACK_RIGHT },
139  { SND_CHMAP_FC, AV_CHAN_FRONT_CENTER },
140  { SND_CHMAP_LFE, AV_CHAN_LOW_FREQUENCY },
141  { SND_CHMAP_SL, AV_CHAN_SIDE_LEFT },
142  { SND_CHMAP_SR, AV_CHAN_SIDE_RIGHT },
143  { SND_CHMAP_RC, AV_CHAN_BACK_CENTER },
144  { SND_CHMAP_FLC, AV_CHAN_FRONT_LEFT_OF_CENTER },
145  { SND_CHMAP_FRC, AV_CHAN_FRONT_RIGHT_OF_CENTER},
146  { SND_CHMAP_FLW, AV_CHAN_WIDE_LEFT },
147  { SND_CHMAP_FRW, AV_CHAN_WIDE_RIGHT },
148  { SND_CHMAP_TC, AV_CHAN_TOP_CENTER },
149  { SND_CHMAP_TFL, AV_CHAN_TOP_FRONT_LEFT },
150  { SND_CHMAP_TFR, AV_CHAN_TOP_FRONT_RIGHT },
151  { SND_CHMAP_TFC, AV_CHAN_TOP_FRONT_CENTER },
152  { SND_CHMAP_TRL, AV_CHAN_TOP_BACK_LEFT },
153  { SND_CHMAP_TRR, AV_CHAN_TOP_BACK_RIGHT },
154  { SND_CHMAP_TRC, AV_CHAN_TOP_BACK_CENTER },
155  { SND_CHMAP_TSL, AV_CHAN_TOP_SIDE_LEFT },
156  { SND_CHMAP_TSR, AV_CHAN_TOP_SIDE_RIGHT },
157  { SND_CHMAP_LLFE, AV_CHAN_LOW_FREQUENCY },
158  { SND_CHMAP_RLFE, AV_CHAN_LOW_FREQUENCY_2 },
159  { SND_CHMAP_BC, AV_CHAN_BOTTOM_FRONT_CENTER },
160  { SND_CHMAP_BLC, AV_CHAN_BOTTOM_FRONT_LEFT },
161  { SND_CHMAP_BRC, AV_CHAN_BOTTOM_FRONT_RIGHT },
162  { SND_CHMAP_UNKNOWN, AV_CHAN_UNKNOWN },
163  { SND_CHMAP_NA, AV_CHAN_UNUSED },
164 };
165 
166 static enum AVChannel alsa_chmap_pos_to_av_chan(unsigned int pos)
167 {
168  for (unsigned i = 0; i < FF_ARRAY_ELEMS(alsa_chmap_table); i++)
169  if (alsa_chmap_table[i].pos == pos)
170  return alsa_chmap_table[i].ch;
171  return AV_CHAN_NONE;
172 }
173 
175 {
176  snd_pcm_chmap_t *chmap = snd_pcm_get_chmap(h);
177  int ret = 0;
178 
179  if (!chmap)
180  return 0;
181 
182  if (layout->nb_channels != chmap->channels) {
183  av_log(ctx, AV_LOG_ERROR, "Inconsistent channel layout requested!\n");
184  ret = AVERROR(EINVAL);
185  goto out;
186  }
187 
189  ret = av_channel_layout_custom_init(layout, chmap->channels);
190  if (ret < 0)
191  goto out;
192 
193  for (unsigned i = 0; i < chmap->channels; i++) {
194  enum AVChannel ch = alsa_chmap_pos_to_av_chan(chmap->pos[i] &
195  SND_CHMAP_POSITION_MASK);
196  if (ch == AV_CHAN_NONE) {
198  "unknown ALSA channel position %u.\n",
199  chmap->pos[i] & SND_CHMAP_POSITION_MASK);
200  continue;
201  }
202  layout->u.map[i].id = ch;
203  }
206 
207 out:
208  free(chmap);
209  return ret;
210 }
211 
213  const AVChannelLayout *layout, int out)
214 {
215  int format;
216 
217  /* reordering input is not currently supported */
218  if (!out)
219  return AVERROR(ENOSYS);
220 
221  /* reordering is not needed for QUAD or 2_2 layout */
224  return 0;
225 
226  switch (codec_id) {
227  case AV_CODEC_ID_PCM_S8:
228  case AV_CODEC_ID_PCM_U8:
230  case AV_CODEC_ID_PCM_MULAW: format = FORMAT_I8; break;
234  case AV_CODEC_ID_PCM_U16BE: format = FORMAT_I16; break;
238  case AV_CODEC_ID_PCM_U32BE: format = FORMAT_I32; break;
240  case AV_CODEC_ID_PCM_F32BE: format = FORMAT_F32; break;
241  default: return AVERROR(ENOSYS);
242  }
243 
246  PICK_REORDER(50)
249  PICK_REORDER(51)
251  PICK_REORDER(71)
252 
253  return s->reorder_func ? 0 : AVERROR(ENOSYS);
254 }
255 
256 av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode,
257  unsigned int *sample_rate,
259 {
260  AlsaData *s = ctx->priv_data;
261  const char *audio_device;
262  int res, flags = 0;
263  snd_pcm_format_t format;
264  snd_pcm_t *h;
265  snd_pcm_hw_params_t *hw_params;
266  snd_pcm_uframes_t buffer_size, period_size;
267 
268  if (ctx->url[0] == 0) audio_device = "default";
269  else audio_device = ctx->url;
270 
271  if (*codec_id == AV_CODEC_ID_NONE)
274  if (format == SND_PCM_FORMAT_UNKNOWN) {
275  av_log(ctx, AV_LOG_ERROR, "sample format 0x%04x is not supported\n", *codec_id);
276  return AVERROR(ENOSYS);
277  }
278  if (ctx->flags & AVFMT_FLAG_NONBLOCK) {
279  flags = SND_PCM_NONBLOCK;
280  }
281  res = snd_pcm_open(&h, audio_device, mode, flags);
282  if (res < 0) {
283  av_log(ctx, AV_LOG_ERROR, "cannot open audio device %s (%s)\n",
284  audio_device, snd_strerror(res));
285  return AVERROR(EIO);
286  }
287 
288  res = snd_pcm_hw_params_malloc(&hw_params);
289  if (res < 0) {
290  av_log(ctx, AV_LOG_ERROR, "cannot allocate hardware parameter structure (%s)\n",
291  snd_strerror(res));
292  goto fail1;
293  }
294 
295  res = snd_pcm_hw_params_any(h, hw_params);
296  if (res < 0) {
297  av_log(ctx, AV_LOG_ERROR, "cannot initialize hardware parameter structure (%s)\n",
298  snd_strerror(res));
299  goto fail;
300  }
301 
302  res = snd_pcm_hw_params_set_access(h, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
303  if (res < 0) {
304  av_log(ctx, AV_LOG_ERROR, "cannot set access type (%s)\n",
305  snd_strerror(res));
306  goto fail;
307  }
308 
309  res = snd_pcm_hw_params_set_format(h, hw_params, format);
310  if (res < 0) {
311  av_log(ctx, AV_LOG_ERROR, "cannot set sample format 0x%04x %d (%s)\n",
312  *codec_id, format, snd_strerror(res));
313  goto fail;
314  }
315 
316  res = snd_pcm_hw_params_set_rate_near(h, hw_params, sample_rate, 0);
317  if (res < 0) {
318  av_log(ctx, AV_LOG_ERROR, "cannot set sample rate (%s)\n",
319  snd_strerror(res));
320  goto fail;
321  }
322 
323  // For output streams, the stream should already have a layout.
324  // Adding this check for clarity.
325  if (mode == SND_PCM_STREAM_CAPTURE && layout->nb_channels == 0) {
326  unsigned int channels = 2;
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);
329  if (res < 0) {
330  av_log(ctx, AV_LOG_ERROR, "cannot get minimum channel count (%s)\n",
331  snd_strerror(res));
332  goto fail;
333  }
335  "stereo not supported, falling back to %u channel(s)\n", channels);
336  }
338  layout->nb_channels = channels;
339  }
340 
341  res = snd_pcm_hw_params_set_channels(h, hw_params, layout->nb_channels);
342  if (res < 0) {
343  av_log(ctx, AV_LOG_ERROR, "cannot set channel count to %d (%s)\n",
344  layout->nb_channels, snd_strerror(res));
345  goto fail;
346  }
347 
348  s->frame_size = av_get_bits_per_sample(*codec_id) / 8 * layout->nb_channels;
349 
350  snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size);
351  buffer_size = FFMIN(buffer_size, ALSA_BUFFER_SIZE_MAX);
352  /* TODO: maybe use ctx->max_picture_buffer somehow */
353  res = snd_pcm_hw_params_set_buffer_size_near(h, hw_params, &buffer_size);
354  if (res < 0) {
355  av_log(ctx, AV_LOG_ERROR, "cannot set ALSA buffer size (%s)\n",
356  snd_strerror(res));
357  goto fail;
358  }
359 
360  snd_pcm_hw_params_get_period_size_min(hw_params, &period_size, NULL);
361  if (!period_size)
362  period_size = buffer_size / 4;
363  res = snd_pcm_hw_params_set_period_size_near(h, hw_params, &period_size, NULL);
364  if (res < 0) {
365  av_log(ctx, AV_LOG_ERROR, "cannot set ALSA period size (%s)\n",
366  snd_strerror(res));
367  goto fail;
368  }
369  s->period_size = period_size;
370 
371  res = snd_pcm_hw_params(h, hw_params);
372  if (res < 0) {
373  av_log(ctx, AV_LOG_ERROR, "cannot set parameters (%s)\n",
374  snd_strerror(res));
375  goto fail;
376  }
377 
378  snd_pcm_hw_params_free(hw_params);
379 
380  // TODO: when support for channel layout gets more widespread in alsa
381  // drivers, this might be used to supersede the re-ordering function
382  // below.
383  if (mode == SND_PCM_STREAM_CAPTURE &&
384  layout->order == AV_CHANNEL_ORDER_UNSPEC) {
385  res = alsa_get_chmap(ctx, h, layout);
386  if (res < 0)
387  goto fail1;
388  }
389 
390  if (layout->nb_channels > 2 && layout->order != AV_CHANNEL_ORDER_UNSPEC) {
391  // See comment above. find_reorder_func is currently only implemented in
392  // playback mode.
393  if (find_reorder_func(s, *codec_id, layout, mode == SND_PCM_STREAM_PLAYBACK) < 0) {
394  char name[128];
396  av_log(ctx, AV_LOG_WARNING, "ALSA channel layout unknown or unimplemented for %s %s.\n",
397  name, mode == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture");
398  }
399  if (s->reorder_func) {
400  s->reorder_buf_size = buffer_size;
401  s->reorder_buf = av_malloc_array(s->reorder_buf_size, s->frame_size);
402  if (!s->reorder_buf)
403  goto fail1;
404  }
405  }
406 
407  s->pkt = av_packet_alloc();
408  if (!s->pkt)
409  goto fail1;
410 
411  s->h = h;
412  return 0;
413 
414 fail:
415  snd_pcm_hw_params_free(hw_params);
416 fail1:
417  snd_pcm_close(h);
418  return AVERROR(EIO);
419 }
420 
422 {
423  AlsaData *s = s1->priv_data;
424 
425  if (snd_pcm_stream(s->h) == SND_PCM_STREAM_PLAYBACK) {
426  snd_pcm_nonblock(s->h, 0);
427  snd_pcm_drain(s->h);
428  }
429  av_freep(&s->reorder_buf);
430  if (CONFIG_ALSA_INDEV)
431  ff_timefilter_destroy(s->timefilter);
432  snd_pcm_close(s->h);
433  av_packet_free(&s->pkt);
434  return 0;
435 }
436 
438 {
439  AlsaData *s = s1->priv_data;
440  snd_pcm_t *handle = s->h;
441 
442  av_log(s1, AV_LOG_WARNING, "ALSA buffer xrun.\n");
443  if (err == -EPIPE) {
444  err = snd_pcm_prepare(handle);
445  if (err < 0) {
446  av_log(s1, AV_LOG_ERROR, "cannot recover from underrun (snd_pcm_prepare failed: %s)\n", snd_strerror(err));
447 
448  return AVERROR(EIO);
449  }
450 #ifdef ESTRPIPE
451  } else if (err == -ESTRPIPE) {
452  av_log(s1, AV_LOG_ERROR, "-ESTRPIPE... Unsupported!\n");
453 
454  return -1;
455 #endif
456  }
457  return err;
458 }
459 
461 {
462  int size = s->reorder_buf_size;
463  void *r;
464 
465  av_assert0(size != 0);
466  while (size < min_size)
467  size *= 2;
468  r = av_realloc_array(s->reorder_buf, size, s->frame_size);
469  if (!r)
470  return AVERROR(ENOMEM);
471  s->reorder_buf = r;
472  s->reorder_buf_size = size;
473  return 0;
474 }
475 
476 /* ported from alsa-utils/aplay.c */
477 int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type)
478 {
479  int ret = 0;
480  void **hints, **n;
481  char *name = NULL, *descr = NULL, *io = NULL, *tmp;
482  AVDeviceInfo *new_device = NULL;
483  const char *filter = stream_type == SND_PCM_STREAM_PLAYBACK ? "Output" : "Input";
484 
485  if (snd_device_name_hint(-1, "pcm", &hints) < 0)
486  return AVERROR_EXTERNAL;
487  n = hints;
488  while (*n && !ret) {
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)) {
493  new_device = av_mallocz(sizeof(AVDeviceInfo));
494  if (!new_device) {
495  ret = AVERROR(ENOMEM);
496  goto fail;
497  }
498  new_device->device_name = av_strdup(name ? name : "");
499  if (!descr)
500  new_device->device_description = av_strdup("");
501  else if ((tmp = strrchr(descr, '\n')) && tmp[1])
502  new_device->device_description = av_strdup(&tmp[1]);
503  else
504  new_device->device_description = av_strdup(descr);
505  if (!new_device->device_description || !new_device->device_name) {
506  ret = AVERROR(ENOMEM);
507  goto fail;
508  }
509  if ((ret = av_dynarray_add_nofree(&device_list->devices,
510  &device_list->nb_devices, new_device)) < 0) {
511  goto fail;
512  }
513  if (!strcmp(new_device->device_name, "default"))
514  device_list->default_device = device_list->nb_devices - 1;
515  new_device = NULL;
516  }
517  fail:
518  free(io);
519  free(name);
520  free(descr);
521  n++;
522  }
523  if (new_device) {
524  av_free(new_device->device_description);
525  av_free(new_device->device_name);
526  av_free(new_device);
527  }
528  snd_device_name_free_hint(hints);
529  return ret;
530 }
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: codec_id.h:330
PICK_REORDER
#define PICK_REORDER(layout)
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AV_CODEC_ID_PCM_F32BE
@ AV_CODEC_ID_PCM_F32BE
Definition: codec_id.h:350
name
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
Definition: writing_filters.txt:88
r
const char * r
Definition: vf_curves.c:127
AVERROR
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
FORMAT_I32
#define FORMAT_I32
out
static FILE * out
Definition: movenc.c:55
AVDeviceInfo::device_name
char * device_name
device name, format depends on device
Definition: avdevice.h:334
AV_CHAN_WIDE_LEFT
@ AV_CHAN_WIDE_LEFT
Definition: channel_layout.h:72
av_cold
#define av_cold
Definition: attributes.h:119
ALSA_BUFFER_SIZE_MAX
#define ALSA_BUFFER_SIZE_MAX
Definition: alsa.h:47
AV_CHANNEL_LAYOUT_2_2
#define AV_CHANNEL_LAYOUT_2_2
Definition: channel_layout.h:402
AVDeviceInfoList::nb_devices
int nb_devices
number of autodetected devices
Definition: avdevice.h:345
mode
Definition: swscale.c:71
FORMAT_I8
#define FORMAT_I8
AV_CODEC_ID_PCM_U24LE
@ AV_CODEC_ID_PCM_U24LE
Definition: codec_id.h:344
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
filter
void(* filter)(uint8_t *src, int stride, int qscale)
Definition: h263dsp.c:29
find_reorder_func
static av_cold int find_reorder_func(AlsaData *s, int codec_id, const AVChannelLayout *layout, int out)
Definition: alsa.c:212
av_packet_free
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
Definition: packet.c:74
DEFAULT_CODEC_ID
#define DEFAULT_CODEC_ID
Definition: alsa.h:43
AV_CODEC_ID_PCM_S16BE
@ AV_CODEC_ID_PCM_S16BE
Definition: codec_id.h:331
AV_CHAN_TOP_BACK_RIGHT
@ AV_CHAN_TOP_BACK_RIGHT
Definition: channel_layout.h:67
av_get_bits_per_sample
int av_get_bits_per_sample(enum AVCodecID codec_id)
Return codec bits per sample.
Definition: utils.c:556
AVDeviceInfoList::devices
AVDeviceInfo ** devices
list of autodetected devices
Definition: avdevice.h:344
AV_CODEC_ID_PCM_S8
@ AV_CODEC_ID_PCM_S8
Definition: codec_id.h:334
avassert.h
AV_CHAN_BOTTOM_FRONT_LEFT
@ AV_CHAN_BOTTOM_FRONT_LEFT
Definition: channel_layout.h:80
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_channel_layout_describe
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.
Definition: channel_layout.c:654
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:504
AV_CHANNEL_LAYOUT_7POINT1
#define AV_CHANNEL_LAYOUT_7POINT1
Definition: channel_layout.h:417
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
AVFormatContext::flags
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1484
AV_CHAN_UNKNOWN
@ AV_CHAN_UNKNOWN
Channel contains data, but its position is unknown.
Definition: channel_layout.h:94
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:119
AV_CHANNEL_LAYOUT_5POINT0_BACK
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
Definition: channel_layout.h:406
ff_alsa_open
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.
Definition: alsa.c:256
AV_CHAN_SIDE_RIGHT
@ AV_CHAN_SIDE_RIGHT
Definition: channel_layout.h:60
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
MAKE_REORDER_FUNCS
#define MAKE_REORDER_FUNCS(CHANNELS, LAYOUT, MAP)
Definition: alsa.c:83
channels
channels
Definition: aptx.h:31
ff_alsa_extend_reorder_buf
int ff_alsa_extend_reorder_buf(AlsaData *s, int min_size)
Definition: alsa.c:460
AV_CODEC_ID_PCM_MULAW
@ AV_CODEC_ID_PCM_MULAW
Definition: codec_id.h:336
AV_CODEC_ID_PCM_U16BE
@ AV_CODEC_ID_PCM_U16BE
Definition: codec_id.h:333
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:410
av_mallocz
#define av_mallocz(s)
Definition: tableprint_vlc.h:31
tmp
static uint8_t tmp[40]
Definition: aes_ctr.c:52
AV_CHAN_TOP_SIDE_LEFT
@ AV_CHAN_TOP_SIDE_LEFT
Definition: channel_layout.h:77
AV_CHAN_TOP_SIDE_RIGHT
@ AV_CHAN_TOP_SIDE_RIGHT
Definition: channel_layout.h:78
AVFormatContext
Format I/O context.
Definition: avformat.h:1333
AV_CODEC_ID_PCM_ALAW
@ AV_CODEC_ID_PCM_ALAW
Definition: codec_id.h:337
fail
#define fail
Definition: test.h:478
NULL
#define NULL
Definition: coverity.c:32
format
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
Definition: swscale-v2.txt:14
AV_CODEC_ID_PCM_U24BE
@ AV_CODEC_ID_PCM_U24BE
Definition: codec_id.h:345
AlsaData
Definition: alsa.h:49
AV_CODEC_ID_PCM_U32BE
@ AV_CODEC_ID_PCM_U32BE
Definition: codec_id.h:341
AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL
#define AV_CHANNEL_LAYOUT_RETYPE_FLAG_CANONICAL
The specified retype target order is ignored and the simplest possible (canonical) order is used for ...
Definition: channel_layout.h:721
AV_CHAN_TOP_BACK_CENTER
@ AV_CHAN_TOP_BACK_CENTER
Definition: channel_layout.h:66
AV_CHAN_BOTTOM_FRONT_RIGHT
@ AV_CHAN_BOTTOM_FRONT_RIGHT
Definition: channel_layout.h:81
AV_CHAN_TOP_CENTER
@ AV_CHAN_TOP_CENTER
Definition: channel_layout.h:61
ff_alsa_close
av_cold int ff_alsa_close(AVFormatContext *s1)
Close the ALSA PCM.
Definition: alsa.c:421
AV_CHAN_FRONT_RIGHT_OF_CENTER
@ AV_CHAN_FRONT_RIGHT_OF_CENTER
Definition: channel_layout.h:57
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
AV_CHAN_FRONT_RIGHT
@ AV_CHAN_FRONT_RIGHT
Definition: channel_layout.h:51
AV_CHAN_FRONT_CENTER
@ AV_CHAN_FRONT_CENTER
Definition: channel_layout.h:52
alsa_get_chmap
static int alsa_get_chmap(AVFormatContext *ctx, snd_pcm_t *h, AVChannelLayout *layout)
Definition: alsa.c:174
AV_CODEC_ID_PCM_S24LE
@ AV_CODEC_ID_PCM_S24LE
Definition: codec_id.h:342
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:319
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
alsa_chmap_pos_to_av_chan
static enum AVChannel alsa_chmap_pos_to_av_chan(unsigned int pos)
Definition: alsa.c:166
AVFormatContext::url
char * url
input or output URL.
Definition: avformat.h:1449
AV_CHAN_LOW_FREQUENCY
@ AV_CHAN_LOW_FREQUENCY
Definition: channel_layout.h:53
size
int size
Definition: twinvq_data.h:10344
AV_CHAN_BACK_RIGHT
@ AV_CHAN_BACK_RIGHT
Definition: channel_layout.h:55
AV_CHAN_SIDE_LEFT
@ AV_CHAN_SIDE_LEFT
Definition: channel_layout.h:59
AVDeviceInfo
Structure describes basic parameters of the device.
Definition: avdevice.h:333
avdevice.h
av_channel_layout_retype
int av_channel_layout_retype(AVChannelLayout *channel_layout, enum AVChannelOrder order, int flags)
Change the AVChannelOrder of a channel layout.
Definition: channel_layout.c:887
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
AV_CHAN_TOP_FRONT_RIGHT
@ AV_CHAN_TOP_FRONT_RIGHT
Definition: channel_layout.h:64
av_packet_alloc
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
Definition: packet.c:63
AV_CHAN_FRONT_LEFT_OF_CENTER
@ AV_CHAN_FRONT_LEFT_OF_CENTER
Definition: channel_layout.h:56
AVDeviceInfo::device_description
char * device_description
human friendly name
Definition: avdevice.h:335
AV_CHAN_UNUSED
@ AV_CHAN_UNUSED
Channel is empty can be safely skipped.
Definition: channel_layout.h:91
alsa_chmap_table
alsa_chmap_table[]
Definition: alsa.c:133
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:811
FORMAT_F32
#define FORMAT_F32
av_channel_layout_custom_init
int av_channel_layout_custom_init(AVChannelLayout *channel_layout, int nb_channels)
Initialize a custom channel layout with the specified number of channels.
Definition: channel_layout.c:233
codec_id_to_pcm_format
static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id)
Definition: alsa.c:41
layout
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
Definition: filter_design.txt:18
AVChannel
AVChannel
Definition: channel_layout.h:47
ff_timefilter_destroy
void ff_timefilter_destroy(TimeFilter *self)
Free all resources associated with the filter.
Definition: timefilter.c:66
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
AV_CHANNEL_LAYOUT_QUAD
#define AV_CHANNEL_LAYOUT_QUAD
Definition: channel_layout.h:403
FORMAT_I16
#define FORMAT_I16
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
s
uint8_t s
Definition: llvidencdsp.c:39
AV_CODEC_ID_PCM_F64BE
@ AV_CODEC_ID_PCM_F64BE
Definition: codec_id.h:352
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_CODEC_ID_PCM_S32BE
@ AV_CODEC_ID_PCM_S32BE
Definition: codec_id.h:339
AVFMT_FLAG_NONBLOCK
#define AVFMT_FLAG_NONBLOCK
Do not block when reading packets from input.
Definition: avformat.h:1487
alsa.h
ret
ret
Definition: filter_design.txt:187
AVDeviceInfoList
List of devices.
Definition: avdevice.h:343
pos
unsigned int pos
Definition: spdifenc.c:414
AV_CHAN_BACK_CENTER
@ AV_CHAN_BACK_CENTER
Definition: channel_layout.h:58
AV_CHAN_NONE
@ AV_CHAN_NONE
Invalid channel index.
Definition: channel_layout.h:49
av_dynarray_add_nofree
int av_dynarray_add_nofree(void *tab_ptr, int *nb_ptr, void *elem)
Add an element to a dynamic array.
Definition: mem.c:313
AVDeviceInfoList::default_device
int default_device
index of default device or -1 if no default
Definition: avdevice.h:346
channel_layout.h
AV_CHAN_LOW_FREQUENCY_2
@ AV_CHAN_LOW_FREQUENCY_2
Definition: channel_layout.h:76
AV_CHAN_TOP_BACK_LEFT
@ AV_CHAN_TOP_BACK_LEFT
Definition: channel_layout.h:65
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:443
AV_CODEC_ID_PCM_U32LE
@ AV_CODEC_ID_PCM_U32LE
Definition: codec_id.h:340
AV_CHAN_BACK_LEFT
@ AV_CHAN_BACK_LEFT
Definition: channel_layout.h:54
ff_alsa_xrun_recover
int ff_alsa_xrun_recover(AVFormatContext *s1, int err)
Try to recover from ALSA buffer underrun.
Definition: alsa.c:437
AV_CHAN_BOTTOM_FRONT_CENTER
@ AV_CHAN_BOTTOM_FRONT_CENTER
Definition: channel_layout.h:79
AV_CHAN_TOP_FRONT_CENTER
@ AV_CHAN_TOP_FRONT_CENTER
Definition: channel_layout.h:63
AV_CODEC_ID_PCM_S32LE
@ AV_CODEC_ID_PCM_S32LE
Definition: codec_id.h:338
mem.h
AV_CHAN_WIDE_RIGHT
@ AV_CHAN_WIDE_RIGHT
Definition: channel_layout.h:73
AV_CODEC_ID_PCM_U8
@ AV_CODEC_ID_PCM_U8
Definition: codec_id.h:335
av_strdup
#define av_strdup(s)
Definition: ops_asmgen.c:47
AV_CODEC_ID_PCM_F64LE
@ AV_CODEC_ID_PCM_F64LE
Definition: codec_id.h:353
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
ff_alsa_get_device_list
int ff_alsa_get_device_list(AVDeviceInfoList *device_list, snd_pcm_stream_t stream_type)
Definition: alsa.c:477
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AV_CHAN_TOP_FRONT_LEFT
@ AV_CHAN_TOP_FRONT_LEFT
Definition: channel_layout.h:62
AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:407
AV_CODEC_ID_PCM_U16LE
@ AV_CODEC_ID_PCM_U16LE
Definition: codec_id.h:332
AV_CODEC_ID_PCM_F32LE
@ AV_CODEC_ID_PCM_F32LE
Definition: codec_id.h:351
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
h
h
Definition: vp9dsp_template.c:2070
AV_CHANNEL_LAYOUT_5POINT0
#define AV_CHANNEL_LAYOUT_5POINT0
Definition: channel_layout.h:404
AV_CHAN_FRONT_LEFT
@ AV_CHAN_FRONT_LEFT
Definition: channel_layout.h:50
AV_CHANNEL_LAYOUT_5POINT1
#define AV_CHANNEL_LAYOUT_5POINT1
Definition: channel_layout.h:405
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1361
AV_CODEC_ID_PCM_S24BE
@ AV_CODEC_ID_PCM_S24BE
Definition: codec_id.h:343