FFmpeg
af_channelmap.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Google, Inc.
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 /**
22  * @file
23  * audio channel mapping filter
24  */
25 
26 #include <ctype.h>
27 
28 #include "libavutil/avstring.h"
30 #include "libavutil/common.h"
31 #include "libavutil/mathematics.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/samplefmt.h"
34 
35 #include "audio.h"
36 #include "avfilter.h"
37 #include "formats.h"
38 #include "internal.h"
39 
40 struct ChannelMap {
41  uint64_t in_channel;
42  uint64_t out_channel;
45 };
46 
55 };
56 
57 #define MAX_CH 64
58 typedef struct ChannelMapContext {
59  const AVClass *class;
60  char *mapping_str;
62  uint64_t output_layout;
64  int nch;
67 
68 #define OFFSET(x) offsetof(ChannelMapContext, x)
69 #define A AV_OPT_FLAG_AUDIO_PARAM
70 #define F AV_OPT_FLAG_FILTERING_PARAM
71 static const AVOption channelmap_options[] = {
72  { "map", "A comma-separated list of input channel numbers in output order.",
73  OFFSET(mapping_str), AV_OPT_TYPE_STRING, .flags = A|F },
74  { "channel_layout", "Output channel layout.",
75  OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, .flags = A|F },
76  { NULL }
77 };
78 
79 AVFILTER_DEFINE_CLASS(channelmap);
80 
81 static char* split(char *message, char delim) {
82  char *next = strchr(message, delim);
83  if (next)
84  *next++ = '\0';
85  return next;
86 }
87 
88 static int get_channel_idx(char **map, int *ch, char delim, int max_ch)
89 {
90  char *next;
91  int len;
92  int n = 0;
93  if (!*map)
94  return AVERROR(EINVAL);
95  next = split(*map, delim);
96  if (!next && delim == '-')
97  return AVERROR(EINVAL);
98  len = strlen(*map);
99  sscanf(*map, "%d%n", ch, &n);
100  if (n != len)
101  return AVERROR(EINVAL);
102  if (*ch < 0 || *ch > max_ch)
103  return AVERROR(EINVAL);
104  *map = next;
105  return 0;
106 }
107 
108 static int get_channel(char **map, uint64_t *ch, char delim)
109 {
110  char *next = split(*map, delim);
111  if (!next && delim == '-')
112  return AVERROR(EINVAL);
115  return AVERROR(EINVAL);
116  *map = next;
117  return 0;
118 }
119 
121 {
122  ChannelMapContext *s = ctx->priv;
123  char *mapping, separator = '|';
124  int map_entries = 0;
125  char buf[256];
126  enum MappingMode mode;
127  uint64_t out_ch_mask = 0;
128  int i;
129 
130  mapping = s->mapping_str;
131 
132  if (!mapping) {
133  mode = MAP_NONE;
134  } else {
135  char *dash = strchr(mapping, '-');
136  if (!dash) { // short mapping
137  if (av_isdigit(*mapping))
138  mode = MAP_ONE_INT;
139  else
140  mode = MAP_ONE_STR;
141  } else if (av_isdigit(*mapping)) {
142  if (av_isdigit(*(dash+1)))
144  else
146  } else {
147  if (av_isdigit(*(dash+1)))
149  else
151  }
152  }
153 
154  if (mode != MAP_NONE) {
155  char *sep = mapping;
156  map_entries = 1;
157  while ((sep = strchr(sep, separator))) {
158  if (*++sep) // Allow trailing comma
159  map_entries++;
160  }
161  }
162 
163  if (map_entries > MAX_CH) {
164  av_log(ctx, AV_LOG_ERROR, "Too many channels mapped: '%d'.\n", map_entries);
165  return AVERROR(EINVAL);
166  }
167 
168  for (i = 0; i < map_entries; i++) {
169  int in_ch_idx = -1, out_ch_idx = -1;
170  uint64_t in_ch = 0, out_ch = 0;
171  static const char err[] = "Failed to parse channel map\n";
172  switch (mode) {
173  case MAP_ONE_INT:
174  if (get_channel_idx(&mapping, &in_ch_idx, separator, MAX_CH) < 0) {
175  av_log(ctx, AV_LOG_ERROR, err);
176  return AVERROR(EINVAL);
177  }
178  s->map[i].in_channel_idx = in_ch_idx;
179  s->map[i].out_channel_idx = i;
180  break;
181  case MAP_ONE_STR:
182  if (get_channel(&mapping, &in_ch, separator) < 0) {
183  av_log(ctx, AV_LOG_ERROR, err);
184  return AVERROR(EINVAL);
185  }
186  s->map[i].in_channel = in_ch;
187  s->map[i].out_channel_idx = i;
188  break;
189  case MAP_PAIR_INT_INT:
190  if (get_channel_idx(&mapping, &in_ch_idx, '-', MAX_CH) < 0 ||
191  get_channel_idx(&mapping, &out_ch_idx, separator, MAX_CH) < 0) {
192  av_log(ctx, AV_LOG_ERROR, err);
193  return AVERROR(EINVAL);
194  }
195  s->map[i].in_channel_idx = in_ch_idx;
196  s->map[i].out_channel_idx = out_ch_idx;
197  break;
198  case MAP_PAIR_INT_STR:
199  if (get_channel_idx(&mapping, &in_ch_idx, '-', MAX_CH) < 0 ||
200  get_channel(&mapping, &out_ch, separator) < 0 ||
201  out_ch & out_ch_mask) {
202  av_log(ctx, AV_LOG_ERROR, err);
203  return AVERROR(EINVAL);
204  }
205  s->map[i].in_channel_idx = in_ch_idx;
206  s->map[i].out_channel = out_ch;
207  out_ch_mask |= out_ch;
208  break;
209  case MAP_PAIR_STR_INT:
210  if (get_channel(&mapping, &in_ch, '-') < 0 ||
211  get_channel_idx(&mapping, &out_ch_idx, separator, MAX_CH) < 0) {
212  av_log(ctx, AV_LOG_ERROR, err);
213  return AVERROR(EINVAL);
214  }
215  s->map[i].in_channel = in_ch;
216  s->map[i].out_channel_idx = out_ch_idx;
217  break;
218  case MAP_PAIR_STR_STR:
219  if (get_channel(&mapping, &in_ch, '-') < 0 ||
220  get_channel(&mapping, &out_ch, separator) < 0 ||
221  out_ch & out_ch_mask) {
222  av_log(ctx, AV_LOG_ERROR, err);
223  return AVERROR(EINVAL);
224  }
225  s->map[i].in_channel = in_ch;
226  s->map[i].out_channel = out_ch;
227  out_ch_mask |= out_ch;
228  break;
229  }
230  }
231  s->mode = mode;
232  s->nch = map_entries;
233  s->output_layout = out_ch_mask ? out_ch_mask :
234  av_get_default_channel_layout(map_entries);
235 
236  if (s->channel_layout_str) {
237  uint64_t fmt;
238  if ((fmt = av_get_channel_layout(s->channel_layout_str)) == 0) {
239  av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n",
240  s->channel_layout_str);
241  return AVERROR(EINVAL);
242  }
243  if (mode == MAP_NONE) {
244  int i;
246  for (i = 0; i < s->nch; i++) {
247  s->map[i].in_channel_idx = i;
248  s->map[i].out_channel_idx = i;
249  }
250  } else if (out_ch_mask && out_ch_mask != fmt) {
251  av_get_channel_layout_string(buf, sizeof(buf), 0, out_ch_mask);
253  "Output channel layout '%s' does not match the list of channel mapped: '%s'.\n",
254  s->channel_layout_str, buf);
255  return AVERROR(EINVAL);
256  } else if (s->nch != av_get_channel_layout_nb_channels(fmt)) {
258  "Output channel layout %s does not match the number of channels mapped %d.\n",
259  s->channel_layout_str, s->nch);
260  return AVERROR(EINVAL);
261  }
262  s->output_layout = fmt;
263  }
264  if (!s->output_layout) {
265  av_log(ctx, AV_LOG_ERROR, "Output channel layout is not set and "
266  "cannot be guessed from the maps.\n");
267  return AVERROR(EINVAL);
268  }
269 
271  for (i = 0; i < s->nch; i++) {
272  s->map[i].out_channel_idx = av_get_channel_layout_channel_index(
273  s->output_layout, s->map[i].out_channel);
274  }
275  }
276 
277  return 0;
278 }
279 
281 {
282  ChannelMapContext *s = ctx->priv;
285  int ret;
286 
288  if (!layouts) {
289  ret = AVERROR(ENOMEM);
290  goto fail;
291  }
292  if ((ret = ff_add_channel_layout (&channel_layouts, s->output_layout )) < 0 ||
295  (ret = ff_channel_layouts_ref (layouts , &ctx->inputs[0]->out_channel_layouts)) < 0 ||
296  (ret = ff_channel_layouts_ref (channel_layouts , &ctx->outputs[0]->in_channel_layouts)) < 0)
297  goto fail;
298 
299  return 0;
300 fail:
301  if (layouts)
302  av_freep(&layouts->channel_layouts);
303  av_freep(&layouts);
304  return ret;
305 }
306 
308 {
309  AVFilterContext *ctx = inlink->dst;
310  AVFilterLink *outlink = ctx->outputs[0];
311  const ChannelMapContext *s = ctx->priv;
312  const int nch_in = inlink->channels;
313  const int nch_out = s->nch;
314  int ch;
315  uint8_t *source_planes[MAX_CH];
316 
317  memcpy(source_planes, buf->extended_data,
318  nch_in * sizeof(source_planes[0]));
319 
320  if (nch_out > nch_in) {
321  if (nch_out > FF_ARRAY_ELEMS(buf->data)) {
322  uint8_t **new_extended_data =
323  av_mallocz_array(nch_out, sizeof(*buf->extended_data));
324  if (!new_extended_data) {
325  av_frame_free(&buf);
326  return AVERROR(ENOMEM);
327  }
328  if (buf->extended_data == buf->data) {
329  buf->extended_data = new_extended_data;
330  } else {
331  av_free(buf->extended_data);
332  buf->extended_data = new_extended_data;
333  }
334  } else if (buf->extended_data != buf->data) {
335  av_free(buf->extended_data);
336  buf->extended_data = buf->data;
337  }
338  }
339 
340  for (ch = 0; ch < nch_out; ch++) {
341  buf->extended_data[s->map[ch].out_channel_idx] =
342  source_planes[s->map[ch].in_channel_idx];
343  }
344 
345  if (buf->data != buf->extended_data)
346  memcpy(buf->data, buf->extended_data,
347  FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));
348 
349  buf->channel_layout = outlink->channel_layout;
350  buf->channels = outlink->channels;
351 
352  return ff_filter_frame(outlink, buf);
353 }
354 
356 {
357  AVFilterContext *ctx = inlink->dst;
358  ChannelMapContext *s = ctx->priv;
359  int nb_channels = inlink->channels;
360  int i, err = 0;
361  const char *channel_name;
362  char layout_name[256];
363 
364  for (i = 0; i < s->nch; i++) {
365  struct ChannelMap *m = &s->map[i];
366 
367  if (s->mode == MAP_PAIR_STR_INT || s->mode == MAP_PAIR_STR_STR) {
369  inlink->channel_layout, m->in_channel);
370  }
371 
372  if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) {
373  av_get_channel_layout_string(layout_name, sizeof(layout_name),
374  nb_channels, inlink->channel_layout);
375  if (m->in_channel) {
378  "input channel '%s' not available from input layout '%s'\n",
379  channel_name, layout_name);
380  } else {
382  "input channel #%d not available from input layout '%s'\n",
383  m->in_channel_idx, layout_name);
384  }
385  err = AVERROR(EINVAL);
386  }
387  }
388 
389  return err;
390 }
391 
393  {
394  .name = "default",
395  .type = AVMEDIA_TYPE_AUDIO,
396  .filter_frame = channelmap_filter_frame,
397  .config_props = channelmap_config_input,
398  .needs_writable = 1,
399  },
400  { NULL }
401 };
402 
404  {
405  .name = "default",
406  .type = AVMEDIA_TYPE_AUDIO
407  },
408  { NULL }
409 };
410 
412  .name = "channelmap",
413  .description = NULL_IF_CONFIG_SMALL("Remap audio channels."),
414  .init = channelmap_init,
415  .query_formats = channelmap_query_formats,
416  .priv_size = sizeof(ChannelMapContext),
417  .priv_class = &channelmap_class,
420 };
ChannelMap::in_channel
uint64_t in_channel
layout describing the input channel
Definition: af_channelmap.c:41
MAX_CH
#define MAX_CH
Definition: af_channelmap.c:57
AVFilterChannelLayouts
A list of supported channel layouts.
Definition: formats.h:85
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
opt.h
MAP_PAIR_STR_STR
@ MAP_PAIR_STR_STR
Definition: af_channelmap.c:54
message
Definition: api-threadmessage-test.c:46
n
int n
Definition: avisynth_c.h:760
ChannelMapContext::mode
enum MappingMode mode
Definition: af_channelmap.c:65
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
ff_channel_layouts_ref
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
Add *ref as a new reference to f.
Definition: formats.c:435
layouts
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
channelmap_filter_frame
static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf)
Definition: af_channelmap.c:307
F
#define F
Definition: af_channelmap.c:70
channelmap_init
static av_cold int channelmap_init(AVFilterContext *ctx)
Definition: af_channelmap.c:120
ch
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_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), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { 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) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;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)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8: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);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=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) { int planes=out->planar ? out->ch_count :1;unsigned m=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){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
ff_all_channel_counts
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition.
Definition: formats.c:410
av_get_channel_layout_string
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
Definition: channel_layout.c:211
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
AVOption
AVOption.
Definition: opt.h:246
avfilter_af_channelmap_outputs
static const AVFilterPad avfilter_af_channelmap_outputs[]
Definition: af_channelmap.c:403
av_mallocz_array
void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.c:191
av_get_channel_layout
uint64_t av_get_channel_layout(const char *name)
Return a channel layout id that matches name, or 0 if no match is found.
Definition: channel_layout.c:139
mathematics.h
channel_name
Definition: channel_layout.c:34
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:148
MAP_NONE
@ MAP_NONE
Definition: af_channelmap.c:48
formats.h
fmt
const char * fmt
Definition: avisynth_c.h:861
fail
#define fail()
Definition: checkasm.h:120
A
#define A
Definition: af_channelmap.c:69
samplefmt.h
ChannelMapContext::channel_layout_str
char * channel_layout_str
Definition: af_channelmap.c:61
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:54
MappingMode
MappingMode
Definition: af_channelmap.c:47
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
av_cold
#define av_cold
Definition: attributes.h:84
ff_set_common_formats
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
ff_af_channelmap
AVFilter ff_af_channelmap
Definition: af_channelmap.c:411
ff_add_channel_layout
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
Definition: formats.c:343
channelmap_options
static const AVOption channelmap_options[]
Definition: af_channelmap.c:71
s
#define s(width, name)
Definition: cbs_vp9.c:257
MAP_PAIR_STR_INT
@ MAP_PAIR_STR_INT
Definition: af_channelmap.c:53
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
ChannelMapContext::nch
int nch
Definition: af_channelmap.c:64
outputs
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
av_get_channel_name
const char * av_get_channel_name(uint64_t channel)
Get the name of a given channel.
Definition: channel_layout.c:243
ctx
AVFormatContext * ctx
Definition: movenc.c:48
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
NULL
#define NULL
Definition: coverity.c:32
ChannelMapContext::output_layout
uint64_t output_layout
Definition: af_channelmap.c:62
inputs
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
Definition: filter_design.txt:243
channelmap_query_formats
static int channelmap_query_formats(AVFilterContext *ctx)
Definition: af_channelmap.c:280
av_get_channel_layout_nb_channels
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
Definition: channel_layout.c:220
MAP_PAIR_INT_INT
@ MAP_PAIR_INT_INT
Definition: af_channelmap.c:51
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
ChannelMap::out_channel
uint64_t out_channel
layout describing the output channel
Definition: af_channelmap.c:42
ChannelMapContext
Definition: af_channelmap.c:58
avfilter_af_channelmap_inputs
static const AVFilterPad avfilter_af_channelmap_inputs[]
Definition: af_channelmap.c:392
MAP_ONE_STR
@ MAP_ONE_STR
Definition: af_channelmap.c:50
MAP_ONE_INT
@ MAP_ONE_INT
Definition: af_channelmap.c:49
MAP_PAIR_INT_STR
@ MAP_PAIR_INT_STR
Definition: af_channelmap.c:52
channelmap_config_input
static int channelmap_config_input(AVFilterLink *inlink)
Definition: af_channelmap.c:355
split
static char * split(char *message, char delim)
Definition: af_channelmap.c:81
av_isdigit
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
Definition: avstring.h:206
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
get_channel_idx
static int get_channel_idx(char **map, int *ch, char delim, int max_ch)
Definition: af_channelmap.c:88
ChannelMap::in_channel_idx
int in_channel_idx
index of in_channel in the input stream data
Definition: af_channelmap.c:43
ChannelMapContext::mapping_str
char * mapping_str
Definition: af_channelmap.c:60
ChannelMapContext::map
struct ChannelMap map[MAX_CH]
Definition: af_channelmap.c:63
internal.h
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
get_channel
static int get_channel(char **map, uint64_t *ch, char delim)
Definition: af_channelmap.c:108
common.h
av_get_channel_layout_channel_index
int av_get_channel_layout_channel_index(uint64_t channel_layout, uint64_t channel)
Get the index of a channel in channel_layout.
Definition: channel_layout.c:233
uint8_t
uint8_t
Definition: audio_convert.c:194
ff_planar_sample_fmts
AVFilterFormats * ff_planar_sample_fmts(void)
Construct a formats list containing all planar sample formats.
Definition: formats.c:382
len
int len
Definition: vorbis_enc_data.h:452
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:60
AVFilter
Filter definition.
Definition: avfilter.h:144
ret
ret
Definition: filter_design.txt:187
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
ff_all_samplerates
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
ChannelMap::out_channel_idx
int out_channel_idx
Definition: af_channelmap.c:44
channel_layout.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(channelmap)
mode
mode
Definition: ebur128.h:83
avfilter.h
ChannelMap
Definition: opus.h:137
AVFilterContext
An instance of a filter.
Definition: avfilter.h:338
OFFSET
#define OFFSET(x)
Definition: af_channelmap.c:68
audio.h
av_get_default_channel_layout
int64_t av_get_default_channel_layout(int nb_channels)
Return default channel layout for a given number of channels.
Definition: channel_layout.c:225
map
const VDPAUPixFmtMap * map
Definition: hwcontext_vdpau.c:85
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:113
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
ff_set_common_samplerates
int ff_set_common_samplerates(AVFilterContext *ctx, AVFilterFormats *samplerates)
Definition: formats.c:556
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:227
nb_channels
int nb_channels
Definition: channel_layout.c:76