FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
utils.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Justin Ruggles <justin.ruggles@gmail.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/common.h"
22 #include "libavutil/dict.h"
23 // #include "libavutil/error.h"
24 #include "libavutil/frame.h"
25 #include "libavutil/log.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/opt.h"
28 
29 #include "avresample.h"
30 #include "internal.h"
31 #include "audio_data.h"
32 #include "audio_convert.h"
33 #include "audio_mix.h"
34 #include "resample.h"
35 
37 {
38  int ret;
39 
40  if (avresample_is_open(avr)) {
41  av_log(avr, AV_LOG_ERROR, "The resampling context is already open.\n");
42  return AVERROR(EINVAL);
43  }
44 
45  /* set channel mixing parameters */
47  if (avr->in_channels <= 0 || avr->in_channels > AVRESAMPLE_MAX_CHANNELS) {
48  av_log(avr, AV_LOG_ERROR, "Invalid input channel layout: %"PRIu64"\n",
49  avr->in_channel_layout);
50  return AVERROR(EINVAL);
51  }
53  if (avr->out_channels <= 0 || avr->out_channels > AVRESAMPLE_MAX_CHANNELS) {
54  av_log(avr, AV_LOG_ERROR, "Invalid output channel layout: %"PRIu64"\n",
55  avr->out_channel_layout);
56  return AVERROR(EINVAL);
57  }
59  avr->downmix_needed = avr->in_channels > avr->out_channels;
60  avr->upmix_needed = avr->out_channels > avr->in_channels ||
61  (!avr->downmix_needed && (avr->mix_matrix ||
63  avr->mixing_needed = avr->downmix_needed || avr->upmix_needed;
64 
65  /* set resampling parameters */
66  avr->resample_needed = avr->in_sample_rate != avr->out_sample_rate ||
67  avr->force_resampling;
68 
69  /* select internal sample format if not specified by the user */
71  (avr->mixing_needed || avr->resample_needed)) {
74  int max_bps = FFMAX(av_get_bytes_per_sample(in_fmt),
75  av_get_bytes_per_sample(out_fmt));
76  if (max_bps <= 2) {
78  } else if (avr->mixing_needed) {
80  } else {
81  if (max_bps <= 4) {
82  if (in_fmt == AV_SAMPLE_FMT_S32P ||
83  out_fmt == AV_SAMPLE_FMT_S32P) {
84  if (in_fmt == AV_SAMPLE_FMT_FLTP ||
85  out_fmt == AV_SAMPLE_FMT_FLTP) {
86  /* if one is s32 and the other is flt, use dbl */
88  } else {
89  /* if one is s32 and the other is s32, s16, or u8, use s32 */
91  }
92  } else {
93  /* if one is flt and the other is flt, s16 or u8, use flt */
95  }
96  } else {
97  /* if either is dbl, use dbl */
99  }
100  }
101  av_log(avr, AV_LOG_DEBUG, "Using %s as internal sample format\n",
103  }
104 
105  /* we may need to add an extra conversion in order to remap channels if
106  the output format is not planar */
107  if (avr->use_channel_map && !avr->mixing_needed && !avr->resample_needed &&
110  }
111 
112  /* set sample format conversion parameters */
113  if (avr->resample_needed || avr->mixing_needed)
115  else
116  avr->in_convert_needed = avr->use_channel_map &&
118 
119  if (avr->resample_needed || avr->mixing_needed || avr->in_convert_needed)
121  else
122  avr->out_convert_needed = avr->in_sample_fmt != avr->out_sample_fmt;
123 
124  avr->in_copy_needed = !avr->in_convert_needed && (avr->mixing_needed ||
125  (avr->use_channel_map && avr->resample_needed));
126 
127  if (avr->use_channel_map) {
128  if (avr->in_copy_needed) {
129  avr->remap_point = REMAP_IN_COPY;
130  av_log(avr, AV_LOG_TRACE, "remap channels during in_copy\n");
131  } else if (avr->in_convert_needed) {
133  av_log(avr, AV_LOG_TRACE, "remap channels during in_convert\n");
134  } else if (avr->out_convert_needed) {
136  av_log(avr, AV_LOG_TRACE, "remap channels during out_convert\n");
137  } else {
139  av_log(avr, AV_LOG_TRACE, "remap channels during out_copy\n");
140  }
141 
142 #ifdef DEBUG
143  {
144  int ch;
145  av_log(avr, AV_LOG_TRACE, "output map: ");
146  if (avr->ch_map_info.do_remap)
147  for (ch = 0; ch < avr->in_channels; ch++)
148  av_log(avr, AV_LOG_TRACE, " % 2d", avr->ch_map_info.channel_map[ch]);
149  else
150  av_log(avr, AV_LOG_TRACE, "n/a");
151  av_log(avr, AV_LOG_TRACE, "\n");
152  av_log(avr, AV_LOG_TRACE, "copy map: ");
153  if (avr->ch_map_info.do_copy)
154  for (ch = 0; ch < avr->in_channels; ch++)
155  av_log(avr, AV_LOG_TRACE, " % 2d", avr->ch_map_info.channel_copy[ch]);
156  else
157  av_log(avr, AV_LOG_TRACE, "n/a");
158  av_log(avr, AV_LOG_TRACE, "\n");
159  av_log(avr, AV_LOG_TRACE, "zero map: ");
160  if (avr->ch_map_info.do_zero)
161  for (ch = 0; ch < avr->in_channels; ch++)
162  av_log(avr, AV_LOG_TRACE, " % 2d", avr->ch_map_info.channel_zero[ch]);
163  else
164  av_log(avr, AV_LOG_TRACE, "n/a");
165  av_log(avr, AV_LOG_TRACE, "\n");
166  av_log(avr, AV_LOG_TRACE, "input map: ");
167  for (ch = 0; ch < avr->in_channels; ch++)
168  av_log(avr, AV_LOG_TRACE, " % 2d", avr->ch_map_info.input_map[ch]);
169  av_log(avr, AV_LOG_TRACE, "\n");
170  }
171 #endif
172  } else
173  avr->remap_point = REMAP_NONE;
174 
175  /* allocate buffers */
176  if (avr->in_copy_needed || avr->in_convert_needed) {
178  0, avr->internal_sample_fmt,
179  "in_buffer");
180  if (!avr->in_buffer) {
181  ret = AVERROR(EINVAL);
182  goto error;
183  }
184  }
185  if (avr->resample_needed) {
187  1024, avr->internal_sample_fmt,
188  "resample_out_buffer");
189  if (!avr->resample_out_buffer) {
190  ret = AVERROR(EINVAL);
191  goto error;
192  }
193  }
194  if (avr->out_convert_needed) {
196  avr->out_sample_fmt, "out_buffer");
197  if (!avr->out_buffer) {
198  ret = AVERROR(EINVAL);
199  goto error;
200  }
201  }
203  1024);
204  if (!avr->out_fifo) {
205  ret = AVERROR(ENOMEM);
206  goto error;
207  }
208 
209  /* setup contexts */
210  if (avr->in_convert_needed) {
212  avr->in_sample_fmt, avr->in_channels,
213  avr->in_sample_rate,
214  avr->remap_point == REMAP_IN_CONVERT);
215  if (!avr->ac_in) {
216  ret = AVERROR(ENOMEM);
217  goto error;
218  }
219  }
220  if (avr->out_convert_needed) {
221  enum AVSampleFormat src_fmt;
222  if (avr->in_convert_needed)
223  src_fmt = avr->internal_sample_fmt;
224  else
225  src_fmt = avr->in_sample_fmt;
226  avr->ac_out = ff_audio_convert_alloc(avr, avr->out_sample_fmt, src_fmt,
227  avr->out_channels,
228  avr->out_sample_rate,
230  if (!avr->ac_out) {
231  ret = AVERROR(ENOMEM);
232  goto error;
233  }
234  }
235  if (avr->resample_needed) {
236  avr->resample = ff_audio_resample_init(avr);
237  if (!avr->resample) {
238  ret = AVERROR(ENOMEM);
239  goto error;
240  }
241  }
242  if (avr->mixing_needed) {
243  avr->am = ff_audio_mix_alloc(avr);
244  if (!avr->am) {
245  ret = AVERROR(ENOMEM);
246  goto error;
247  }
248  }
249 
250  return 0;
251 
252 error:
253  avresample_close(avr);
254  return ret;
255 }
256 
258 {
259  return !!avr->out_fifo;
260 }
261 
263 {
268  avr->out_fifo = NULL;
272  ff_audio_mix_free(&avr->am);
273  av_freep(&avr->mix_matrix);
274 
275  avr->use_channel_map = 0;
276 }
277 
279 {
280  if (!*avr)
281  return;
282  avresample_close(*avr);
283  av_opt_free(*avr);
284  av_freep(avr);
285 }
286 
288  AudioData *output, AudioData *converted)
289 {
290  int ret;
291 
292  if (!output || av_audio_fifo_size(avr->out_fifo) > 0 ||
293  (converted && output->allocated_samples < converted->nb_samples)) {
294  if (converted) {
295  /* if there are any samples in the output FIFO or if the
296  user-supplied output buffer is not large enough for all samples,
297  we add to the output FIFO */
298  av_log(avr, AV_LOG_TRACE, "[FIFO] add %s to out_fifo\n", converted->name);
299  ret = ff_audio_data_add_to_fifo(avr->out_fifo, converted, 0,
300  converted->nb_samples);
301  if (ret < 0)
302  return ret;
303  }
304 
305  /* if the user specified an output buffer, read samples from the output
306  FIFO to the user output */
307  if (output && output->allocated_samples > 0) {
308  av_log(avr, AV_LOG_TRACE, "[FIFO] read from out_fifo to output\n");
309  av_log(avr, AV_LOG_TRACE, "[end conversion]\n");
310  return ff_audio_data_read_from_fifo(avr->out_fifo, output,
311  output->allocated_samples);
312  }
313  } else if (converted) {
314  /* copy directly to output if it is large enough or there is not any
315  data in the output FIFO */
316  av_log(avr, AV_LOG_TRACE, "[copy] %s to output\n", converted->name);
317  output->nb_samples = 0;
318  ret = ff_audio_data_copy(output, converted,
319  avr->remap_point == REMAP_OUT_COPY ?
320  &avr->ch_map_info : NULL);
321  if (ret < 0)
322  return ret;
323  av_log(avr, AV_LOG_TRACE, "[end conversion]\n");
324  return output->nb_samples;
325  }
326  av_log(avr, AV_LOG_TRACE, "[end conversion]\n");
327  return 0;
328 }
329 
330 int attribute_align_arg avresample_convert(AVAudioResampleContext *avr,
331  uint8_t **output, int out_plane_size,
332  int out_samples, uint8_t **input,
333  int in_plane_size, int in_samples)
334 {
335  AudioData input_buffer;
336  AudioData output_buffer;
337  AudioData *current_buffer;
338  int ret, direct_output;
339 
340  /* reset internal buffers */
341  if (avr->in_buffer) {
342  avr->in_buffer->nb_samples = 0;
345  }
346  if (avr->resample_out_buffer) {
350  }
351  if (avr->out_buffer) {
352  avr->out_buffer->nb_samples = 0;
355  }
356 
357  av_log(avr, AV_LOG_TRACE, "[start conversion]\n");
358 
359  /* initialize output_buffer with output data */
360  direct_output = output && av_audio_fifo_size(avr->out_fifo) == 0;
361  if (output) {
362  ret = ff_audio_data_init(&output_buffer, output, out_plane_size,
363  avr->out_channels, out_samples,
364  avr->out_sample_fmt, 0, "output");
365  if (ret < 0)
366  return ret;
367  output_buffer.nb_samples = 0;
368  }
369 
370  if (input) {
371  /* initialize input_buffer with input data */
372  ret = ff_audio_data_init(&input_buffer, input, in_plane_size,
373  avr->in_channels, in_samples,
374  avr->in_sample_fmt, 1, "input");
375  if (ret < 0)
376  return ret;
377  current_buffer = &input_buffer;
378 
379  if (avr->upmix_needed && !avr->in_convert_needed && !avr->resample_needed &&
380  !avr->out_convert_needed && direct_output && out_samples >= in_samples) {
381  /* in some rare cases we can copy input to output and upmix
382  directly in the output buffer */
383  av_log(avr, AV_LOG_TRACE, "[copy] %s to output\n", current_buffer->name);
384  ret = ff_audio_data_copy(&output_buffer, current_buffer,
385  avr->remap_point == REMAP_OUT_COPY ?
386  &avr->ch_map_info : NULL);
387  if (ret < 0)
388  return ret;
389  current_buffer = &output_buffer;
390  } else if (avr->remap_point == REMAP_OUT_COPY &&
391  (!direct_output || out_samples < in_samples)) {
392  /* if remapping channels during output copy, we may need to
393  * use an intermediate buffer in order to remap before adding
394  * samples to the output fifo */
395  av_log(avr, AV_LOG_TRACE, "[copy] %s to out_buffer\n", current_buffer->name);
396  ret = ff_audio_data_copy(avr->out_buffer, current_buffer,
397  &avr->ch_map_info);
398  if (ret < 0)
399  return ret;
400  current_buffer = avr->out_buffer;
401  } else if (avr->in_copy_needed || avr->in_convert_needed) {
402  /* if needed, copy or convert input to in_buffer, and downmix if
403  applicable */
404  if (avr->in_convert_needed) {
405  ret = ff_audio_data_realloc(avr->in_buffer,
406  current_buffer->nb_samples);
407  if (ret < 0)
408  return ret;
409  av_log(avr, AV_LOG_TRACE, "[convert] %s to in_buffer\n", current_buffer->name);
410  ret = ff_audio_convert(avr->ac_in, avr->in_buffer,
411  current_buffer);
412  if (ret < 0)
413  return ret;
414  } else {
415  av_log(avr, AV_LOG_TRACE, "[copy] %s to in_buffer\n", current_buffer->name);
416  ret = ff_audio_data_copy(avr->in_buffer, current_buffer,
417  avr->remap_point == REMAP_IN_COPY ?
418  &avr->ch_map_info : NULL);
419  if (ret < 0)
420  return ret;
421  }
423  if (avr->downmix_needed) {
424  av_log(avr, AV_LOG_TRACE, "[downmix] in_buffer\n");
425  ret = ff_audio_mix(avr->am, avr->in_buffer);
426  if (ret < 0)
427  return ret;
428  }
429  current_buffer = avr->in_buffer;
430  }
431  } else {
432  /* flush resampling buffer and/or output FIFO if input is NULL */
433  if (!avr->resample_needed)
434  return handle_buffered_output(avr, output ? &output_buffer : NULL,
435  NULL);
436  current_buffer = NULL;
437  }
438 
439  if (avr->resample_needed) {
440  AudioData *resample_out;
441 
442  if (!avr->out_convert_needed && direct_output && out_samples > 0)
443  resample_out = &output_buffer;
444  else
445  resample_out = avr->resample_out_buffer;
446  av_log(avr, AV_LOG_TRACE, "[resample] %s to %s\n",
447  current_buffer ? current_buffer->name : "null",
448  resample_out->name);
449  ret = ff_audio_resample(avr->resample, resample_out,
450  current_buffer);
451  if (ret < 0)
452  return ret;
453 
454  /* if resampling did not produce any samples, just return 0 */
455  if (resample_out->nb_samples == 0) {
456  av_log(avr, AV_LOG_TRACE, "[end conversion]\n");
457  return 0;
458  }
459 
460  current_buffer = resample_out;
461  }
462 
463  if (avr->upmix_needed) {
464  av_log(avr, AV_LOG_TRACE, "[upmix] %s\n", current_buffer->name);
465  ret = ff_audio_mix(avr->am, current_buffer);
466  if (ret < 0)
467  return ret;
468  }
469 
470  /* if we resampled or upmixed directly to output, return here */
471  if (current_buffer == &output_buffer) {
472  av_log(avr, AV_LOG_TRACE, "[end conversion]\n");
473  return current_buffer->nb_samples;
474  }
475 
476  if (avr->out_convert_needed) {
477  if (direct_output && out_samples >= current_buffer->nb_samples) {
478  /* convert directly to output */
479  av_log(avr, AV_LOG_TRACE, "[convert] %s to output\n", current_buffer->name);
480  ret = ff_audio_convert(avr->ac_out, &output_buffer, current_buffer);
481  if (ret < 0)
482  return ret;
483 
484  av_log(avr, AV_LOG_TRACE, "[end conversion]\n");
485  return output_buffer.nb_samples;
486  } else {
488  current_buffer->nb_samples);
489  if (ret < 0)
490  return ret;
491  av_log(avr, AV_LOG_TRACE, "[convert] %s to out_buffer\n", current_buffer->name);
492  ret = ff_audio_convert(avr->ac_out, avr->out_buffer,
493  current_buffer);
494  if (ret < 0)
495  return ret;
496  current_buffer = avr->out_buffer;
497  }
498  }
499 
500  return handle_buffered_output(avr, output ? &output_buffer : NULL,
501  current_buffer);
502 }
503 
505 {
506  if (avresample_is_open(avr)) {
507  avresample_close(avr);
508  }
509 
510  if (in) {
512  avr->in_sample_rate = in->sample_rate;
513  avr->in_sample_fmt = in->format;
514  }
515 
516  if (out) {
518  avr->out_sample_rate = out->sample_rate;
519  avr->out_sample_fmt = out->format;
520  }
521 
522  return 0;
523 }
524 
526  AVFrame *out, AVFrame *in)
527 {
528  int ret = 0;
529 
530  if (in) {
531  if (avr->in_channel_layout != in->channel_layout ||
532  avr->in_sample_rate != in->sample_rate ||
533  avr->in_sample_fmt != in->format) {
534  ret |= AVERROR_INPUT_CHANGED;
535  }
536  }
537 
538  if (out) {
539  if (avr->out_channel_layout != out->channel_layout ||
540  avr->out_sample_rate != out->sample_rate ||
541  avr->out_sample_fmt != out->format) {
542  ret |= AVERROR_OUTPUT_CHANGED;
543  }
544  }
545 
546  return ret;
547 }
548 
549 static inline int convert_frame(AVAudioResampleContext *avr,
550  AVFrame *out, AVFrame *in)
551 {
552  int ret;
553  uint8_t **out_data = NULL, **in_data = NULL;
554  int out_linesize = 0, in_linesize = 0;
555  int out_nb_samples = 0, in_nb_samples = 0;
556 
557  if (out) {
558  out_data = out->extended_data;
559  out_linesize = out->linesize[0];
560  out_nb_samples = out->nb_samples;
561  }
562 
563  if (in) {
564  in_data = in->extended_data;
565  in_linesize = in->linesize[0];
566  in_nb_samples = in->nb_samples;
567  }
568 
569  ret = avresample_convert(avr, out_data, out_linesize,
570  out_nb_samples,
571  in_data, in_linesize,
572  in_nb_samples);
573 
574  if (ret < 0) {
575  if (out)
576  out->nb_samples = 0;
577  return ret;
578  }
579 
580  if (out)
581  out->nb_samples = ret;
582 
583  return 0;
584 }
585 
586 static inline int available_samples(AVFrame *out)
587 {
588  int samples;
589  int bytes_per_sample = av_get_bytes_per_sample(out->format);
590  if (!bytes_per_sample)
591  return AVERROR(EINVAL);
592 
593  samples = out->linesize[0] / bytes_per_sample;
594  if (av_sample_fmt_is_planar(out->format)) {
595  return samples;
596  } else {
598  return samples / channels;
599  }
600 }
601 
603  AVFrame *out, AVFrame *in)
604 {
605  int ret, setup = 0;
606 
607  if (!avresample_is_open(avr)) {
608  if ((ret = avresample_config(avr, out, in)) < 0)
609  return ret;
610  if ((ret = avresample_open(avr)) < 0)
611  return ret;
612  setup = 1;
613  } else {
614  // return as is or reconfigure for input changes?
615  if ((ret = config_changed(avr, out, in)))
616  return ret;
617  }
618 
619  if (out) {
620  if (!out->linesize[0]) {
622  if ((ret = av_frame_get_buffer(out, 0)) < 0) {
623  if (setup)
624  avresample_close(avr);
625  return ret;
626  }
627  } else {
628  if (!out->nb_samples)
629  out->nb_samples = available_samples(out);
630  }
631  }
632 
633  return convert_frame(avr, out, in);
634 }
635 
637  int stride)
638 {
639  int in_channels, out_channels, i, o;
640 
641  if (avr->am)
642  return ff_audio_mix_get_matrix(avr->am, matrix, stride);
643 
646 
647  if ( in_channels <= 0 || in_channels > AVRESAMPLE_MAX_CHANNELS ||
648  out_channels <= 0 || out_channels > AVRESAMPLE_MAX_CHANNELS) {
649  av_log(avr, AV_LOG_ERROR, "Invalid channel layouts\n");
650  return AVERROR(EINVAL);
651  }
652 
653  if (!avr->mix_matrix) {
654  av_log(avr, AV_LOG_ERROR, "matrix is not set\n");
655  return AVERROR(EINVAL);
656  }
657 
658  for (o = 0; o < out_channels; o++)
659  for (i = 0; i < in_channels; i++)
660  matrix[o * stride + i] = avr->mix_matrix[o * in_channels + i];
661 
662  return 0;
663 }
664 
665 int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix,
666  int stride)
667 {
668  int in_channels, out_channels, i, o;
669 
670  if (avr->am)
671  return ff_audio_mix_set_matrix(avr->am, matrix, stride);
672 
675 
676  if ( in_channels <= 0 || in_channels > AVRESAMPLE_MAX_CHANNELS ||
677  out_channels <= 0 || out_channels > AVRESAMPLE_MAX_CHANNELS) {
678  av_log(avr, AV_LOG_ERROR, "Invalid channel layouts\n");
679  return AVERROR(EINVAL);
680  }
681 
682  if (avr->mix_matrix)
683  av_freep(&avr->mix_matrix);
684  avr->mix_matrix = av_malloc(in_channels * out_channels *
685  sizeof(*avr->mix_matrix));
686  if (!avr->mix_matrix)
687  return AVERROR(ENOMEM);
688 
689  for (o = 0; o < out_channels; o++)
690  for (i = 0; i < in_channels; i++)
691  avr->mix_matrix[o * in_channels + i] = matrix[o * stride + i];
692 
693  return 0;
694 }
695 
697  const int *channel_map)
698 {
699  ChannelMapInfo *info = &avr->ch_map_info;
700  int in_channels, ch, i;
701 
703  if (in_channels <= 0 || in_channels > AVRESAMPLE_MAX_CHANNELS) {
704  av_log(avr, AV_LOG_ERROR, "Invalid input channel layout\n");
705  return AVERROR(EINVAL);
706  }
707 
708  memset(info, 0, sizeof(*info));
709  memset(info->input_map, -1, sizeof(info->input_map));
710 
711  for (ch = 0; ch < in_channels; ch++) {
712  if (channel_map[ch] >= in_channels) {
713  av_log(avr, AV_LOG_ERROR, "Invalid channel map\n");
714  return AVERROR(EINVAL);
715  }
716  if (channel_map[ch] < 0) {
717  info->channel_zero[ch] = 1;
718  info->channel_map[ch] = -1;
719  info->do_zero = 1;
720  } else if (info->input_map[channel_map[ch]] >= 0) {
721  info->channel_copy[ch] = info->input_map[channel_map[ch]];
722  info->channel_map[ch] = -1;
723  info->do_copy = 1;
724  } else {
725  info->channel_map[ch] = channel_map[ch];
726  info->input_map[channel_map[ch]] = ch;
727  info->do_remap = 1;
728  }
729  }
730  /* Fill-in unmapped input channels with unmapped output channels.
731  This is used when remapping during conversion from interleaved to
732  planar format. */
733  for (ch = 0, i = 0; ch < in_channels && i < in_channels; ch++, i++) {
734  while (ch < in_channels && info->input_map[ch] >= 0)
735  ch++;
736  while (i < in_channels && info->channel_map[i] >= 0)
737  i++;
738  if (ch >= in_channels || i >= in_channels)
739  break;
740  info->input_map[ch] = i;
741  }
742 
743  avr->use_channel_map = 1;
744  return 0;
745 }
746 
748 {
749  return av_audio_fifo_size(avr->out_fifo);
750 }
751 
753 {
754  int64_t samples = avresample_get_delay(avr) + (int64_t)in_nb_samples;
755 
756  if (avr->resample_needed) {
757  samples = av_rescale_rnd(samples,
758  avr->out_sample_rate,
759  avr->in_sample_rate,
760  AV_ROUND_UP);
761  }
762 
763  samples += avresample_available(avr);
764 
765  if (samples > INT_MAX)
766  return AVERROR(EINVAL);
767 
768  return samples;
769 }
770 
771 int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
772 {
773  if (!output)
774  return av_audio_fifo_drain(avr->out_fifo, nb_samples);
775  return av_audio_fifo_read(avr->out_fifo, (void**)output, nb_samples);
776 }
777 
778 unsigned avresample_version(void)
779 {
781 }
782 
783 const char *avresample_license(void)
784 {
785 #define LICENSE_PREFIX "libavresample license: "
786  return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
787 }
788 
789 const char *avresample_configuration(void)
790 {
791  return FFMPEG_CONFIGURATION;
792 }
float, planar
Definition: samplefmt.h:70
int in_channels
number of input channels
Definition: internal.h:77
#define NULL
Definition: coverity.c:32
AudioConvert * ac_in
input sample format conversion context
Definition: internal.h:93
const char * name
name for debug logging
Definition: audio_data.h:55
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
Definition: audio_fifo.c:60
int av_audio_fifo_read(AVAudioFifo *af, void **data, int nb_samples)
Read data from an AVAudioFifo.
Definition: audio_fifo.c:139
int ff_audio_data_realloc(AudioData *a, int nb_samples)
Reallocate AudioData.
Definition: audio_data.c:161
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
#define LIBAVRESAMPLE_VERSION_INT
Definition: version.h:34
int input_map[AVRESAMPLE_MAX_CHANNELS]
dest index of each input channel
Definition: internal.h:50
AudioData * out_buffer
buffer for converted output
Definition: internal.h:90
Audio buffer used for intermediate storage between conversion phases.
Definition: audio_data.h:37
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
Definition: mathematics.c:63
static int config_changed(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
Definition: utils.c:525
int avresample_convert_frame(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
Convert the samples in the input AVFrame and write them to the output AVFrame.
Definition: utils.c:602
memory handling functions
int ff_audio_data_add_to_fifo(AVAudioFifo *af, AudioData *a, int offset, int nb_samples)
Add samples in AudioData to an AVAudioFifo.
Definition: audio_data.c:350
int do_zero
zeroing needed
Definition: internal.h:49
AudioData * ff_audio_data_alloc(int channels, int nb_samples, enum AVSampleFormat sample_fmt, const char *name)
Allocate AudioData.
Definition: audio_data.c:118
static int convert_frame(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
Definition: utils.c:549
int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
Read samples from the output FIFO.
Definition: utils.c:771
double * mix_matrix
mix matrix only used if avresample_set_matrix() is called before avresample_open() ...
Definition: internal.h:103
uint64_t out_channel_layout
output channel layout
Definition: internal.h:59
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
Definition: audio_fifo.c:45
int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in)
Convert audio data from one sample format to another.
double, planar
Definition: samplefmt.h:71
int avresample_set_channel_mapping(AVAudioResampleContext *avr, const int *channel_map)
Set a customized input channel mapping.
Definition: utils.c:696
int ff_audio_mix(AudioMix *am, AudioData *src)
Apply channel mixing to audio data using the current mixing matrix.
Definition: audio_mix.c:428
int channel_zero[AVRESAMPLE_MAX_CHANNELS]
dest index to zero
Definition: internal.h:48
void avresample_free(AVAudioResampleContext **avr)
Free AVAudioResampleContext and associated AVOption values.
Definition: utils.c:278
int nb_samples
current number of samples
Definition: audio_data.h:43
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AudioData * in_buffer
buffer for converted input
Definition: internal.h:88
Public dictionary API.
int allocated_channels
allocated channel count
Definition: audio_data.h:46
uint8_t
Round toward +infinity.
Definition: mathematics.h:74
#define av_malloc(s)
AVOptions.
int out_channels
number of output channels
Definition: internal.h:78
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:204
static int handle_buffered_output(AVAudioResampleContext *avr, AudioData *output, AudioData *converted)
Definition: utils.c:287
#define LICENSE_PREFIX
int ff_audio_mix_set_matrix(AudioMix *am, const double *matrix, int stride)
Set the current mixing matrix.
Definition: audio_mix.c:653
int ff_sample_fmt_is_planar(enum AVSampleFormat sample_fmt, int channels)
Definition: audio_data.c:51
const char * avresample_license(void)
Return the libavresample license.
Definition: utils.c:783
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:82
AudioConvert * ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map)
Allocate and initialize AudioConvert context for sample format conversion.
#define av_log(a,...)
void avresample_close(AVAudioResampleContext *avr)
Close AVAudioResampleContext.
Definition: utils.c:262
AudioMix * am
channel mixing context
Definition: internal.h:96
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:110
int ff_audio_data_set_channels(AudioData *a, int channels)
Definition: audio_data.c:59
int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src)
Resample audio data.
Definition: resample.c:393
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int out_convert_needed
output sample format conversion is needed
Definition: internal.h:85
#define AVERROR(e)
Definition: error.h:43
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
void ff_audio_convert_free(AudioConvert **ac)
Free AudioConvert.
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:47
AudioConvert * ac_out
output sample format conversion context
Definition: internal.h:94
#define FFMAX(a, b)
Definition: common.h:64
int ff_audio_data_read_from_fifo(AVAudioFifo *af, AudioData *a, int nb_samples)
Read samples from an AVAudioFifo to AudioData.
Definition: audio_data.c:365
reference-counted frame API
int channel_copy[AVRESAMPLE_MAX_CHANNELS]
dest index to copy from
Definition: internal.h:46
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:427
int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in)
Configure or reconfigure the AVAudioResampleContext using the information provided by the AVFrames...
Definition: utils.c:504
int upmix_needed
upmixing is needed
Definition: internal.h:81
ResampleContext * resample
resampling context
Definition: internal.h:95
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
Definition: audio_fifo.c:186
enum RemapPoint remap_point
Definition: internal.h:106
external API header
#define FFMIN(a, b)
Definition: common.h:66
int do_remap
remap needed
Definition: internal.h:45
signed 32 bits, planar
Definition: samplefmt.h:69
ret
Definition: avfilter.c:974
#define AVERROR_INPUT_CHANGED
Input changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_OUTPUT_CHANGED) ...
Definition: error.h:73
int ff_audio_data_init(AudioData *a, uint8_t **src, int plane_size, int channels, int nb_samples, enum AVSampleFormat sample_fmt, int read_only, const char *name)
Initialize AudioData using a given source.
Definition: audio_data.c:73
ChannelMapInfo ch_map_info
Definition: internal.h:107
uint64_t in_channel_layout
input channel layout
Definition: internal.h:56
int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix, int stride)
Set channel mixing matrix.
Definition: utils.c:665
int in_sample_rate
input sample rate
Definition: internal.h:58
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:232
int avresample_get_delay(AVAudioResampleContext *avr)
Return the number of samples currently in the resampling delay buffer.
Definition: resample.c:497
int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix, int stride)
Get the current channel mixing matrix.
Definition: utils.c:636
int avresample_available(AVAudioResampleContext *avr)
Return the number of available samples in the output FIFO.
Definition: utils.c:747
void ff_audio_resample_free(ResampleContext **c)
Free a ResampleContext.
Definition: resample.c:224
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
AVAudioFifo * out_fifo
FIFO for output samples.
Definition: internal.h:91
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
#define AVRESAMPLE_MAX_CHANNELS
Definition: avresample.h:104
int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
Provide the upper bound on the number of samples the configured conversion would output.
Definition: utils.c:752
enum AVSampleFormat internal_sample_fmt
internal sample format
Definition: internal.h:62
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
int force_resampling
force resampling
Definition: internal.h:68
void ff_audio_mix_free(AudioMix **am_p)
Free an AudioMix context.
Definition: audio_mix.c:409
int in_copy_needed
input data copy is needed
Definition: internal.h:86
const char * avresample_configuration(void)
Return the libavresample build-time configuration.
Definition: utils.c:789
int sample_rate
Sample rate of the audio data.
Definition: frame.h:422
ResampleContext * ff_audio_resample_init(AVAudioResampleContext *avr)
Allocate and initialize a ResampleContext.
Definition: resample.c:120
enum AVSampleFormat in_sample_fmt
input sample format
Definition: internal.h:57
int attribute_align_arg avresample_convert(AVAudioResampleContext *avr, uint8_t **output, int out_plane_size, int out_samples, uint8_t **input, int in_plane_size, int in_samples)
Convert input samples and write them to the output FIFO.
Definition: utils.c:330
int in_convert_needed
input sample format conversion is needed
Definition: internal.h:84
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:265
int channel_map[AVRESAMPLE_MAX_CHANNELS]
source index of each output channel, -1 if not remapped
Definition: internal.h:44
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:104
#define AVERROR_OUTPUT_CHANGED
Output changed between calls. Reconfiguration is required. (can be OR-ed with AVERROR_INPUT_CHANGED) ...
Definition: error.h:74
enum AVSampleFormat out_sample_fmt
output sample format
Definition: internal.h:60
int av_audio_fifo_drain(AVAudioFifo *af, int nb_samples)
Drain data from an AVAudioFifo.
Definition: audio_fifo.c:159
int ff_audio_data_copy(AudioData *dst, AudioData *src, ChannelMapInfo *map)
Copy data from one AudioData to another.
Definition: audio_data.c:224
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
void av_opt_free(void *obj)
Free all allocated objects in obj.
Definition: opt.c:1435
common internal and external API header
int resample_channels
number of channels used for resampling
Definition: internal.h:79
AudioData * resample_out_buffer
buffer for output from resampler
Definition: internal.h:89
int resample_needed
resampling is needed
Definition: internal.h:83
int do_copy
copy needed
Definition: internal.h:47
AudioMix * ff_audio_mix_alloc(AVAudioResampleContext *avr)
Allocate and initialize an AudioMix context.
Definition: audio_mix.c:341
int avresample_is_open(AVAudioResampleContext *avr)
Check whether an AVAudioResampleContext is open or closed.
Definition: utils.c:257
unsigned avresample_version(void)
Return the LIBAVRESAMPLE_VERSION_INT constant.
Definition: utils.c:778
int allocated_samples
number of samples the buffer can hold
Definition: audio_data.h:42
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define av_freep(p)
int out_sample_rate
output sample rate
Definition: internal.h:61
void ff_audio_data_free(AudioData **a)
Free AudioData.
Definition: audio_data.c:216
signed 16 bits, planar
Definition: samplefmt.h:68
int downmix_needed
downmixing is needed
Definition: internal.h:80
static int available_samples(AVFrame *out)
Definition: utils.c:586
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:215
int avresample_open(AVAudioResampleContext *avr)
Initialize AVAudioResampleContext.
Definition: utils.c:36
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
int mixing_needed
either upmixing or downmixing is needed
Definition: internal.h:82
int ff_audio_mix_get_matrix(AudioMix *am, double *matrix, int stride)
Get the current mixing matrix.
Definition: audio_mix.c:483