FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
af_join.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file
21  * Audio join filter
22  *
23  * Join multiple audio inputs as different channels in
24  * a single output
25  */
26 
27 #include "libavutil/avassert.h"
29 #include "libavutil/common.h"
30 #include "libavutil/opt.h"
31 
32 #include "audio.h"
33 #include "avfilter.h"
34 #include "formats.h"
35 #include "internal.h"
36 
37 typedef struct ChannelMap {
38  int input; ///< input stream index
39  int in_channel_idx; ///< index of in_channel in the input stream data
40  uint64_t in_channel; ///< layout describing the input channel
41  uint64_t out_channel; ///< layout describing the output channel
42 } ChannelMap;
43 
44 typedef struct JoinContext {
45  const AVClass *class;
46 
47  int inputs;
48  char *map;
50  uint64_t channel_layout;
51 
54 
55  /**
56  * Temporary storage for input frames, until we get one on each input.
57  */
59 
60  /**
61  * Temporary storage for buffer references, for assembling the output frame.
62  */
64 } JoinContext;
65 
66 #define OFFSET(x) offsetof(JoinContext, x)
67 #define A AV_OPT_FLAG_AUDIO_PARAM
68 #define F AV_OPT_FLAG_FILTERING_PARAM
69 static const AVOption join_options[] = {
70  { "inputs", "Number of input streams.", OFFSET(inputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, A|F },
71  { "channel_layout", "Channel layout of the "
72  "output stream.", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, A|F },
73  { "map", "A comma-separated list of channels maps in the format "
74  "'input_stream.input_channel-output_channel.",
75  OFFSET(map), AV_OPT_TYPE_STRING, .flags = A|F },
76  { NULL }
77 };
78 
80 
82 
84 {
85  AVFilterContext *ctx = link->dst;
86  JoinContext *s = ctx->priv;
87  int i, j;
88 
89  for (i = 0; i < ctx->nb_inputs; i++)
90  if (link == ctx->inputs[i])
91  break;
92  av_assert0(i < ctx->nb_inputs);
93  av_assert0(!s->input_frames[i]);
94  s->input_frames[i] = frame;
95 
96  /* request the same number of samples on all inputs */
97  /* FIXME that means a frame arriving asynchronously on a different input
98  will not have the requested number of samples */
99  if (i == 0) {
100  int nb_samples = s->input_frames[0]->nb_samples;
101 
102  for (j = 1; !i && j < ctx->nb_inputs; j++)
103  ctx->inputs[j]->request_samples = nb_samples;
104  }
105 
106  return try_push_frame(ctx);
107 }
108 
110 {
111  JoinContext *s = ctx->priv;
112  char separator = '|';
113  char *cur = s->map;
114 
115 #if FF_API_OLD_FILTER_OPTS
116  if (cur && strchr(cur, ',')) {
117  av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "
118  "separate the mappings.\n");
119  separator = ',';
120  }
121 #endif
122 
123  while (cur && *cur) {
124  char *sep, *next, *p;
125  uint64_t in_channel = 0, out_channel = 0;
126  int input_idx, out_ch_idx, in_ch_idx;
127 
128  next = strchr(cur, separator);
129  if (next)
130  *next++ = 0;
131 
132  /* split the map into input and output parts */
133  if (!(sep = strchr(cur, '-'))) {
134  av_log(ctx, AV_LOG_ERROR, "Missing separator '-' in channel "
135  "map '%s'\n", cur);
136  return AVERROR(EINVAL);
137  }
138  *sep++ = 0;
139 
140 #define PARSE_CHANNEL(str, var, inout) \
141  if (!(var = av_get_channel_layout(str))) { \
142  av_log(ctx, AV_LOG_ERROR, "Invalid " inout " channel: %s.\n", str);\
143  return AVERROR(EINVAL); \
144  } \
145  if (av_get_channel_layout_nb_channels(var) != 1) { \
146  av_log(ctx, AV_LOG_ERROR, "Channel map describes more than one " \
147  inout " channel.\n"); \
148  return AVERROR(EINVAL); \
149  }
150 
151  /* parse output channel */
152  PARSE_CHANNEL(sep, out_channel, "output");
153  if (!(out_channel & s->channel_layout)) {
154  av_log(ctx, AV_LOG_ERROR, "Output channel '%s' is not present in "
155  "requested channel layout.\n", sep);
156  return AVERROR(EINVAL);
157  }
158 
160  out_channel);
161  if (s->channels[out_ch_idx].input >= 0) {
162  av_log(ctx, AV_LOG_ERROR, "Multiple maps for output channel "
163  "'%s'.\n", sep);
164  return AVERROR(EINVAL);
165  }
166 
167  /* parse input channel */
168  input_idx = strtol(cur, &cur, 0);
169  if (input_idx < 0 || input_idx >= s->inputs) {
170  av_log(ctx, AV_LOG_ERROR, "Invalid input stream index: %d.\n",
171  input_idx);
172  return AVERROR(EINVAL);
173  }
174 
175  if (*cur)
176  cur++;
177 
178  in_ch_idx = strtol(cur, &p, 0);
179  if (p == cur) {
180  /* channel specifier is not a number,
181  * try to parse as channel name */
182  PARSE_CHANNEL(cur, in_channel, "input");
183  }
184 
185  s->channels[out_ch_idx].input = input_idx;
186  if (in_channel)
187  s->channels[out_ch_idx].in_channel = in_channel;
188  else
189  s->channels[out_ch_idx].in_channel_idx = in_ch_idx;
190 
191  cur = next;
192  }
193  return 0;
194 }
195 
197 {
198  JoinContext *s = ctx->priv;
199  int ret, i;
200 
202  av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
203  s->channel_layout_str);
204  return AVERROR(EINVAL);
205  }
206 
208  s->channels = av_mallocz_array(s->nb_channels, sizeof(*s->channels));
209  s->buffers = av_mallocz_array(s->nb_channels, sizeof(*s->buffers));
210  s->input_frames = av_mallocz_array(s->inputs, sizeof(*s->input_frames));
211  if (!s->channels || !s->buffers|| !s->input_frames)
212  return AVERROR(ENOMEM);
213 
214  for (i = 0; i < s->nb_channels; i++) {
216  s->channels[i].input = -1;
217  }
218 
219  if ((ret = parse_maps(ctx)) < 0)
220  return ret;
221 
222  for (i = 0; i < s->inputs; i++) {
223  char name[32];
224  AVFilterPad pad = { 0 };
225 
226  snprintf(name, sizeof(name), "input%d", i);
227  pad.type = AVMEDIA_TYPE_AUDIO;
228  pad.name = av_strdup(name);
229  if (!pad.name)
230  return AVERROR(ENOMEM);
232 
233  pad.needs_fifo = 1;
234 
235  if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0) {
236  av_freep(&pad.name);
237  return ret;
238  }
239  }
240 
241  return 0;
242 }
243 
245 {
246  JoinContext *s = ctx->priv;
247  int i;
248 
249  for (i = 0; i < ctx->nb_inputs; i++) {
250  av_freep(&ctx->input_pads[i].name);
251  av_frame_free(&s->input_frames[i]);
252  }
253 
254  av_freep(&s->channels);
255  av_freep(&s->buffers);
256  av_freep(&s->input_frames);
257 }
258 
260 {
261  JoinContext *s = ctx->priv;
263  int i, ret;
264 
265  if ((ret = ff_add_channel_layout(&layouts, s->channel_layout)) < 0 ||
266  (ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
267  return ret;
268 
269  for (i = 0; i < ctx->nb_inputs; i++) {
270  layouts = ff_all_channel_layouts();
271  if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
272  return ret;
273  }
274 
275  if ((ret = ff_set_common_formats(ctx, ff_planar_sample_fmts())) < 0 ||
276  (ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0)
277  return ret;
278 
279  return 0;
280 }
281 
283  uint64_t *inputs)
284 {
285  int i;
286 
287  for (i = 0; i < ctx->nb_inputs; i++) {
288  AVFilterLink *link = ctx->inputs[i];
289 
290  if (ch->out_channel & link->channel_layout &&
291  !(ch->out_channel & inputs[i])) {
292  ch->input = i;
293  ch->in_channel = ch->out_channel;
294  inputs[i] |= ch->out_channel;
295  return;
296  }
297  }
298 }
299 
301  uint64_t *inputs)
302 {
303  int i;
304 
305  for (i = 0; i < ctx->nb_inputs; i++) {
306  AVFilterLink *link = ctx->inputs[i];
307 
308  if ((inputs[i] & link->channel_layout) != link->channel_layout) {
309  uint64_t unused = link->channel_layout & ~inputs[i];
310 
311  ch->input = i;
313  inputs[i] |= ch->in_channel;
314  return;
315  }
316  }
317 }
318 
319 static int join_config_output(AVFilterLink *outlink)
320 {
321  AVFilterContext *ctx = outlink->src;
322  JoinContext *s = ctx->priv;
323  uint64_t *inputs; // nth element tracks which channels are used from nth input
324  int i, ret = 0;
325 
326  /* initialize inputs to user-specified mappings */
327  if (!(inputs = av_mallocz_array(ctx->nb_inputs, sizeof(*inputs))))
328  return AVERROR(ENOMEM);
329  for (i = 0; i < s->nb_channels; i++) {
330  ChannelMap *ch = &s->channels[i];
331  AVFilterLink *inlink;
332 
333  if (ch->input < 0)
334  continue;
335 
336  inlink = ctx->inputs[ch->input];
337 
338  if (!ch->in_channel)
340  ch->in_channel_idx);
341 
342  if (!(ch->in_channel & inlink->channel_layout)) {
343  av_log(ctx, AV_LOG_ERROR, "Requested channel %s is not present in "
344  "input stream #%d.\n", av_get_channel_name(ch->in_channel),
345  ch->input);
346  ret = AVERROR(EINVAL);
347  goto fail;
348  }
349 
350  inputs[ch->input] |= ch->in_channel;
351  }
352 
353  /* guess channel maps when not explicitly defined */
354  /* first try unused matching channels */
355  for (i = 0; i < s->nb_channels; i++) {
356  ChannelMap *ch = &s->channels[i];
357 
358  if (ch->input < 0)
359  guess_map_matching(ctx, ch, inputs);
360  }
361 
362  /* if the above failed, try to find _any_ unused input channel */
363  for (i = 0; i < s->nb_channels; i++) {
364  ChannelMap *ch = &s->channels[i];
365 
366  if (ch->input < 0)
367  guess_map_any(ctx, ch, inputs);
368 
369  if (ch->input < 0) {
370  av_log(ctx, AV_LOG_ERROR, "Could not find input channel for "
371  "output channel '%s'.\n",
373  goto fail;
374  }
375 
377  ch->in_channel);
378  }
379 
380  /* print mappings */
381  av_log(ctx, AV_LOG_VERBOSE, "mappings: ");
382  for (i = 0; i < s->nb_channels; i++) {
383  ChannelMap *ch = &s->channels[i];
384  av_log(ctx, AV_LOG_VERBOSE, "%d.%s => %s ", ch->input,
387  }
388  av_log(ctx, AV_LOG_VERBOSE, "\n");
389 
390  for (i = 0; i < ctx->nb_inputs; i++) {
391  if (!inputs[i])
392  av_log(ctx, AV_LOG_WARNING, "No channels are used from input "
393  "stream %d.\n", i);
394  }
395 
396 fail:
397  av_freep(&inputs);
398  return ret;
399 }
400 
401 static int join_request_frame(AVFilterLink *outlink)
402 {
403  AVFilterContext *ctx = outlink->src;
404  JoinContext *s = ctx->priv;
405  int i;
406 
407  /* get a frame on each input */
408  for (i = 0; i < ctx->nb_inputs; i++) {
409  AVFilterLink *inlink = ctx->inputs[i];
410  if (!s->input_frames[i])
411  return ff_request_frame(inlink);
412  }
413  return 0;
414 }
415 
417 {
418  AVFilterLink *outlink = ctx->outputs[0];
419  JoinContext *s = ctx->priv;
420  AVFrame *frame;
421  int linesize = INT_MAX;
422  int nb_samples = INT_MAX;
423  int nb_buffers = 0;
424  int i, j, ret;
425 
426  for (i = 0; i < ctx->nb_inputs; i++) {
427  if (!s->input_frames[i])
428  return 0;
429  nb_samples = FFMIN(nb_samples, s->input_frames[i]->nb_samples);
430  }
431 
432  /* setup the output frame */
433  frame = av_frame_alloc();
434  if (!frame)
435  return AVERROR(ENOMEM);
436  if (s->nb_channels > FF_ARRAY_ELEMS(frame->data)) {
438  sizeof(*frame->extended_data));
439  if (!frame->extended_data) {
440  ret = AVERROR(ENOMEM);
441  goto fail;
442  }
443  }
444 
445  /* copy the data pointers */
446  for (i = 0; i < s->nb_channels; i++) {
447  ChannelMap *ch = &s->channels[i];
448  AVFrame *cur = s->input_frames[ch->input];
449  AVBufferRef *buf;
450 
451  frame->extended_data[i] = cur->extended_data[ch->in_channel_idx];
452  linesize = FFMIN(linesize, cur->linesize[0]);
453 
454  /* add the buffer where this plan is stored to the list if it's
455  * not already there */
457  if (!buf) {
458  ret = AVERROR(EINVAL);
459  goto fail;
460  }
461  for (j = 0; j < nb_buffers; j++)
462  if (s->buffers[j]->buffer == buf->buffer)
463  break;
464  if (j == i)
465  s->buffers[nb_buffers++] = buf;
466  }
467 
468  /* create references to the buffers we copied to output */
469  if (nb_buffers > FF_ARRAY_ELEMS(frame->buf)) {
470  frame->nb_extended_buf = nb_buffers - FF_ARRAY_ELEMS(frame->buf);
472  sizeof(*frame->extended_buf));
473  if (!frame->extended_buf) {
474  frame->nb_extended_buf = 0;
475  ret = AVERROR(ENOMEM);
476  goto fail;
477  }
478  }
479  for (i = 0; i < FFMIN(FF_ARRAY_ELEMS(frame->buf), nb_buffers); i++) {
480  frame->buf[i] = av_buffer_ref(s->buffers[i]);
481  if (!frame->buf[i]) {
482  ret = AVERROR(ENOMEM);
483  goto fail;
484  }
485  }
486  for (i = 0; i < frame->nb_extended_buf; i++) {
487  frame->extended_buf[i] = av_buffer_ref(s->buffers[i +
488  FF_ARRAY_ELEMS(frame->buf)]);
489  if (!frame->extended_buf[i]) {
490  ret = AVERROR(ENOMEM);
491  goto fail;
492  }
493  }
494 
495  frame->nb_samples = nb_samples;
496  frame->channel_layout = outlink->channel_layout;
497  frame->channels = outlink->channels;
498  frame->sample_rate = outlink->sample_rate;
499  frame->format = outlink->format;
500  frame->pts = s->input_frames[0]->pts;
501  frame->linesize[0] = linesize;
502  if (frame->data != frame->extended_data) {
503  memcpy(frame->data, frame->extended_data, sizeof(*frame->data) *
504  FFMIN(FF_ARRAY_ELEMS(frame->data), s->nb_channels));
505  }
506 
507  ret = ff_filter_frame(outlink, frame);
508 
509  for (i = 0; i < ctx->nb_inputs; i++)
510  av_frame_free(&s->input_frames[i]);
511 
512  return ret;
513 
514 fail:
515  av_frame_free(&frame);
516  return ret;
517 }
518 
520  {
521  .name = "default",
522  .type = AVMEDIA_TYPE_AUDIO,
523  .config_props = join_config_output,
524  .request_frame = join_request_frame,
525  },
526  { NULL }
527 };
528 
530  .name = "join",
531  .description = NULL_IF_CONFIG_SMALL("Join multiple audio streams into "
532  "multi-channel output."),
533  .priv_size = sizeof(JoinContext),
534  .priv_class = &join_class,
535  .init = join_init,
536  .uninit = join_uninit,
538  .inputs = NULL,
539  .outputs = avfilter_af_join_outputs,
541 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
uint64_t in_channel
layout describing the input channel
Definition: af_channelmap.c:41
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
AVOption.
Definition: opt.h:246
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
Main libavfilter public API header.
#define A
Definition: af_join.c:67
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:393
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:105
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:411
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:65
AVBufferRef ** buffers
Temporary storage for buffer references, for assembling the output frame.
Definition: af_join.c:63
char * map
Definition: af_join.c:48
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
const char * name
Pad name.
Definition: internal.h:60
int nb_channels
Definition: af_join.c:52
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1151
#define av_cold
Definition: attributes.h:82
static av_cold void join_uninit(AVFilterContext *ctx)
Definition: af_join.c:244
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
static av_cold int uninit(AVCodecContext *avctx)
Definition: crystalhd.c:279
AVOptions.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:294
static av_cold int join_init(AVFilterContext *ctx)
Definition: af_join.c:196
static AVFrame * frame
static void guess_map_matching(AVFilterContext *ctx, ChannelMap *ch, uint64_t *inputs)
Definition: af_join.c:282
static int flags
Definition: log.c:57
int input
input stream index
Definition: af_join.c:38
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
static int join_query_formats(AVFilterContext *ctx)
Definition: af_join.c:259
A filter pad used for either input or output.
Definition: internal.h:54
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:345
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:343
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
void * priv
private data for use by the filter
Definition: avfilter.h:353
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
Definition: internal.h:93
simple assert() macros that are a bit more flexible than ISO C assert().
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
#define fail()
Definition: checkasm.h:109
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:379
static const AVOption join_options[]
Definition: af_join.c:69
int channels
number of audio channels, only used for audio.
Definition: frame.h:506
audio channel layout utility functions
unsigned nb_inputs
number of input pads
Definition: avfilter.h:347
#define FFMIN(a, b)
Definition: common.h:96
AVBufferRef ** extended_buf
For planar audio which requires more than AV_NUM_DATA_POINTERS AVBufferRef pointers, this array will hold all the references which cannot fit into AVFrame.buf.
Definition: frame.h:407
AVFormatContext * ctx
Definition: movenc.c:48
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:608
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition: formats.c:382
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:389
AVFilter ff_af_join
Definition: af_join.c:529
AVFilterChannelLayouts * ff_all_channel_layouts(void)
Construct an empty AVFilterChannelLayouts/AVFilterFormats struct – representing any channel layout (w...
Definition: formats.c:401
static const AVFilterPad avfilter_af_join_outputs[]
Definition: af_join.c:519
#define FF_ARRAY_ELEMS(a)
int in_channel_idx
index of in_channel in the input stream data
Definition: af_channelmap.c:43
A list of supported channel layouts.
Definition: formats.h:85
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:274
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:379
AVFILTER_DEFINE_CLASS(join)
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:237
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
int inputs
Definition: af_join.c:47
void * buf
Definition: avisynth_c.h:690
AVBuffer * buffer
Definition: buffer.h:82
Describe the class of an AVClass context structure.
Definition: log.h:67
int sample_rate
Sample rate of the audio data.
Definition: frame.h:374
#define PARSE_CHANNEL(str, var, inout)
Filter definition.
Definition: avfilter.h:144
uint64_t out_channel
layout describing the output channel
Definition: af_channelmap.c:42
const char * name
Filter name.
Definition: avfilter.h:148
const VDPAUPixFmtMap * map
#define snprintf
Definition: snprintf.h:34
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
int av_get_channel_layout_channel_index(uint64_t channel_layout, uint64_t channel)
Get the index of a channel in channel_layout.
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
AVFrame ** input_frames
Temporary storage for input frames, until we get one on each input.
Definition: af_join.c:58
ChannelMap * channels
Definition: af_join.c:53
#define F
Definition: af_join.c:68
A reference to a data buffer.
Definition: buffer.h:81
#define OFFSET(x)
Definition: af_join.c:66
static int query_formats(AVFilterContext *ctx)
Definition: aeval.c:244
static void guess_map_any(AVFilterContext *ctx, ChannelMap *ch, uint64_t *inputs)
Definition: af_join.c:300
common internal and external API header
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
static int parse_maps(AVFilterContext *ctx)
Definition: af_join.c:109
static int join_request_frame(AVFilterLink *outlink)
Definition: af_join.c:401
char * channel_layout_str
Definition: af_join.c:49
const char * av_get_channel_name(uint64_t channel)
Get the name of a given channel.
static int try_push_frame(AVFilterContext *ctx)
Definition: af_join.c:416
An instance of a filter.
Definition: avfilter.h:338
#define av_freep(p)
static int join_config_output(AVFilterLink *outlink)
Definition: af_join.c:319
int needs_fifo
The filter expects a fifo to be inserted on its input link, typically because it has a delay...
Definition: internal.h:137
int ff_request_frame(AVFilterLink *link)
Request an input frame from the filter at the other end of the link.
Definition: avfilter.c:405
static int filter_frame(AVFilterLink *link, AVFrame *frame)
Definition: af_join.c:83
internal API functions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:248
uint64_t channel_layout
Definition: af_join.c:50
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:267
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
const char * name
Definition: opengl_enc.c:103
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:277