FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avf_showvolume.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Paul B Mahol
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/avstring.h"
23 #include "libavutil/eval.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/parseutils.h"
28 #include "avfilter.h"
29 #include "formats.h"
30 #include "audio.h"
31 #include "video.h"
32 #include "internal.h"
33 
34 static const char *const var_names[] = { "VOLUME", "CHANNEL", "PEAK", NULL };
36 
37 typedef struct ShowVolumeContext {
38  const AVClass *class;
39  int w, h;
40  int b;
41  double f;
43  char *color;
45  int step;
46 
49  int draw_text;
51  double *values;
52  uint32_t *color_lut;
54 
55 #define OFFSET(x) offsetof(ShowVolumeContext, x)
56 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
57 
58 static const AVOption showvolume_options[] = {
59  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
60  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str="25"}, 0, INT_MAX, FLAGS },
61  { "b", "set border width", OFFSET(b), AV_OPT_TYPE_INT, {.i64=1}, 0, 5, FLAGS },
62  { "w", "set channel width", OFFSET(w), AV_OPT_TYPE_INT, {.i64=400}, 80, 8192, FLAGS },
63  { "h", "set channel height", OFFSET(h), AV_OPT_TYPE_INT, {.i64=20}, 1, 900, FLAGS },
64  { "f", "set fade", OFFSET(f), AV_OPT_TYPE_DOUBLE, {.dbl=0.95}, 0.001, 1, FLAGS },
65  { "c", "set volume color expression", OFFSET(color), AV_OPT_TYPE_STRING, {.str="PEAK*255+floor((1-PEAK)*255)*256+0xff000000"}, 0, 0, FLAGS },
66  { "t", "display channel names", OFFSET(draw_text), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
67  { "v", "display volume value", OFFSET(draw_volume), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, FLAGS },
68  { "o", "set orientation", OFFSET(orientation), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "orientation" },
69  { "h", "horizontal", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "orientation" },
70  { "v", "vertical", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "orientation" },
71  { "s", "set step size", OFFSET(step), AV_OPT_TYPE_INT, {.i64=0}, 0, 5, FLAGS },
72  { NULL }
73 };
74 
75 AVFILTER_DEFINE_CLASS(showvolume);
76 
78 {
79  ShowVolumeContext *s = ctx->priv;
80  int ret;
81 
82  if (s->color) {
83  ret = av_expr_parse(&s->c_expr, s->color, var_names,
84  NULL, NULL, NULL, NULL, 0, ctx);
85  if (ret < 0)
86  return ret;
87  }
88 
89  return 0;
90 }
91 
93 {
96  AVFilterLink *inlink = ctx->inputs[0];
97  AVFilterLink *outlink = ctx->outputs[0];
99  static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
100  int ret;
101 
102  formats = ff_make_format_list(sample_fmts);
103  if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
104  return ret;
105 
106  layouts = ff_all_channel_counts();
107  if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
108  return ret;
109 
110  formats = ff_all_samplerates();
111  if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
112  return ret;
113 
114  formats = ff_make_format_list(pix_fmts);
115  if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
116  return ret;
117 
118  return 0;
119 }
120 
121 static int config_input(AVFilterLink *inlink)
122 {
123  AVFilterContext *ctx = inlink->dst;
124  ShowVolumeContext *s = ctx->priv;
125  int nb_samples;
126 
127  nb_samples = FFMAX(1024, ((double)inlink->sample_rate / av_q2d(s->frame_rate)) + 0.5);
128  inlink->partial_buf_size =
129  inlink->min_samples =
130  inlink->max_samples = nb_samples;
131  s->values = av_calloc(inlink->channels * VAR_VARS_NB, sizeof(double));
132  if (!s->values)
133  return AVERROR(ENOMEM);
134 
135  s->color_lut = av_calloc(s->w, sizeof(*s->color_lut) * inlink->channels);
136  if (!s->color_lut)
137  return AVERROR(ENOMEM);
138 
139  return 0;
140 }
141 
142 static int config_output(AVFilterLink *outlink)
143 {
144  ShowVolumeContext *s = outlink->src->priv;
145  AVFilterLink *inlink = outlink->src->inputs[0];
146  int ch;
147 
148  if (s->orientation) {
149  outlink->h = s->w;
150  outlink->w = s->h * inlink->channels + (inlink->channels - 1) * s->b;
151  } else {
152  outlink->w = s->w;
153  outlink->h = s->h * inlink->channels + (inlink->channels - 1) * s->b;
154  }
155 
156  outlink->sample_aspect_ratio = (AVRational){1,1};
157  outlink->frame_rate = s->frame_rate;
158 
159  for (ch = 0; ch < inlink->channels; ch++) {
160  int i;
161 
162  for (i = 0; i < s->w; i++) {
163  float max = i / (float)(s->w - 1);
164 
165  s->values[ch * VAR_VARS_NB + VAR_PEAK] = max;
166  s->values[ch * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
167  s->values[ch * VAR_VARS_NB + VAR_CHANNEL] = ch;
168  s->color_lut[ch * s->w + i] = av_expr_eval(s->c_expr, &s->values[ch * VAR_VARS_NB], NULL);
169  }
170  }
171 
172  return 0;
173 }
174 
175 static void drawtext(AVFrame *pic, int x, int y, const char *txt, int o)
176 {
177  const uint8_t *font;
178  int font_height;
179  int i;
180 
181  font = avpriv_cga_font, font_height = 8;
182 
183  for (i = 0; txt[i]; i++) {
184  int char_y, mask;
185 
186  if (o) {
187  for (char_y = font_height - 1; char_y >= 0; char_y--) {
188  uint8_t *p = pic->data[0] + (y + i * 10) * pic->linesize[0] + x * 4;
189  for (mask = 0x80; mask; mask >>= 1) {
190  if (font[txt[i] * font_height + font_height - 1 - char_y] & mask)
191  AV_WN32(&p[char_y * 4], ~AV_RN32(&p[char_y * 4]));
192  p += pic->linesize[0];
193  }
194  }
195  } else {
196  uint8_t *p = pic->data[0] + y * pic->linesize[0] + (x + i * 8) * 4;
197  for (char_y = 0; char_y < font_height; char_y++) {
198  for (mask = 0x80; mask; mask >>= 1) {
199  if (font[txt[i] * font_height + char_y] & mask)
200  AV_WN32(p, ~AV_RN32(p));
201  p += 4;
202  }
203  p += pic->linesize[0] - 8 * 4;
204  }
205  }
206  }
207 }
208 
209 static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
210 {
211  AVFilterContext *ctx = inlink->dst;
212  AVFilterLink *outlink = ctx->outputs[0];
213  ShowVolumeContext *s = ctx->priv;
214  const int step = s->step;
215  int c, i, j, k;
216  AVFrame *out;
217 
218  if (!s->out || s->out->width != outlink->w ||
219  s->out->height != outlink->h) {
220  av_frame_free(&s->out);
221  s->out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
222  if (!s->out) {
223  av_frame_free(&insamples);
224  return AVERROR(ENOMEM);
225  }
226 
227  for (i = 0; i < outlink->h; i++)
228  memset(s->out->data[0] + i * s->out->linesize[0], 0, outlink->w * 4);
229  }
230  s->out->pts = insamples->pts;
231 
232  for (j = 0; j < outlink->h; j++) {
233  uint8_t *dst = s->out->data[0] + j * s->out->linesize[0];
234  for (k = 0; k < outlink->w; k++) {
235  dst[k * 4 + 0] = FFMAX(dst[k * 4 + 0] * s->f, 0);
236  dst[k * 4 + 1] = FFMAX(dst[k * 4 + 1] * s->f, 0);
237  dst[k * 4 + 2] = FFMAX(dst[k * 4 + 2] * s->f, 0);
238  dst[k * 4 + 3] = FFMAX(dst[k * 4 + 3] * s->f, 0);
239  }
240  }
241 
242  if (s->orientation) {
243  for (c = 0; c < inlink->channels; c++) {
244  float *src = (float *)insamples->extended_data[c];
245  uint32_t *lut = s->color_lut + s->w * c;
246  float max = 0;
247 
248  for (i = 0; i < insamples->nb_samples; i++)
249  max = FFMAX(max, src[i]);
250 
251  s->values[c * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
252  max = av_clipf(max, 0, 1);
253 
254  for (j = outlink->h - outlink->h * max; j < s->w; j++) {
255  uint8_t *dst = s->out->data[0] + j * s->out->linesize[0] + c * (s->b + s->h) * 4;
256  for (k = 0; k < s->h; k++) {
257  AV_WN32A(&dst[k * 4], lut[s->w - j - 1]);
258  if (j & step)
259  j += step;
260  }
261  }
262 
263  if (s->h >= 8 && s->draw_text) {
265  if (!channel_name)
266  continue;
267  drawtext(s->out, c * (s->h + s->b) + (s->h - 10) / 2, outlink->h - 35, channel_name, 1);
268  }
269  }
270  } else {
271  for (c = 0; c < inlink->channels; c++) {
272  float *src = (float *)insamples->extended_data[c];
273  uint32_t *lut = s->color_lut + s->w * c;
274  float max = 0;
275 
276  for (i = 0; i < insamples->nb_samples; i++)
277  max = FFMAX(max, src[i]);
278 
279  s->values[c * VAR_VARS_NB + VAR_VOLUME] = 20.0 * log10(max);
280  max = av_clipf(max, 0, 1);
281 
282  for (j = 0; j < s->h; j++) {
283  uint8_t *dst = s->out->data[0] + (c * s->h + c * s->b + j) * s->out->linesize[0];
284 
285  for (k = 0; k < s->w * max; k++) {
286  AV_WN32A(dst + k * 4, lut[k]);
287  if (k & step)
288  k += step;
289  }
290  }
291 
292  if (s->h >= 8 && s->draw_text) {
294  if (!channel_name)
295  continue;
296  drawtext(s->out, 2, c * (s->h + s->b) + (s->h - 8) / 2, channel_name, 0);
297  }
298  }
299  }
300 
301  av_frame_free(&insamples);
302  out = av_frame_clone(s->out);
303  if (!out)
304  return AVERROR(ENOMEM);
306 
307  for (c = 0; c < inlink->channels && s->draw_volume; c++) {
308  char buf[16];
309  if (s->orientation) {
310  if (s->h >= 8) {
311  snprintf(buf, sizeof(buf), "%.2f", s->values[c * VAR_VARS_NB + VAR_VOLUME]);
312  drawtext(out, c * (s->h + s->b) + (s->h - 8) / 2, 2, buf, 1);
313  }
314  } else {
315  if (s->h >= 8) {
316  snprintf(buf, sizeof(buf), "%.2f", s->values[c * VAR_VARS_NB + VAR_VOLUME]);
317  drawtext(out, FFMAX(0, s->w - 8 * (int)strlen(buf)), c * (s->h + s->b) + (s->h - 8) / 2, buf, 0);
318  }
319  }
320  }
321 
322  return ff_filter_frame(outlink, out);
323 }
324 
326 {
327  ShowVolumeContext *s = ctx->priv;
328 
329  av_frame_free(&s->out);
330  av_expr_free(s->c_expr);
331  av_freep(&s->values);
332  av_freep(&s->color_lut);
333 }
334 
335 static const AVFilterPad showvolume_inputs[] = {
336  {
337  .name = "default",
338  .type = AVMEDIA_TYPE_AUDIO,
339  .config_props = config_input,
340  .filter_frame = filter_frame,
341  },
342  { NULL }
343 };
344 
345 static const AVFilterPad showvolume_outputs[] = {
346  {
347  .name = "default",
348  .type = AVMEDIA_TYPE_VIDEO,
349  .config_props = config_output,
350  },
351  { NULL }
352 };
353 
355  .name = "showvolume",
356  .description = NULL_IF_CONFIG_SMALL("Convert input audio volume to video output."),
357  .init = init,
358  .uninit = uninit,
359  .query_formats = query_formats,
360  .priv_size = sizeof(ShowVolumeContext),
361  .inputs = showvolume_inputs,
362  .outputs = showvolume_outputs,
363  .priv_class = &showvolume_class,
364 };
float, planar
Definition: samplefmt.h:69
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
AVOption.
Definition: opt.h:246
AVFilter ff_avf_showvolume
uint32_t * color_lut
Main libavfilter public API header.
const char * b
Definition: vf_curves.c:113
int av_expr_parse(AVExpr **expr, const char *s, const char *const *const_names, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), int log_offset, void *log_ctx)
Parse an expression.
Definition: eval.c:672
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:92
static void drawtext(AVFrame *pic, int x, int y, const char *txt, int o)
#define src
Definition: vp8dsp.c:254
#define AV_WN32A(p, v)
Definition: intreadwrite.h:543
static const AVOption showvolume_options[]
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:230
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
const char * name
Pad name.
Definition: internal.h:60
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
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
static const AVFilterPad showvolume_outputs[]
uint8_t
#define av_cold
Definition: attributes.h:82
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
Definition: eval.c:150
#define OFFSET(x)
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
AVRational frame_rate
A filter pad used for either input or output.
Definition: internal.h:54
int width
Definition: frame.h:259
const uint8_t avpriv_cga_font[2048]
Definition: xga_font_data.c:29
static const uint16_t mask[17]
Definition: lzw.c:38
#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
#define FFMAX(a, b)
Definition: common.h:94
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:94
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:379
audio channel layout utility functions
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:440
AVFormatContext * ctx
Definition: movenc.c:48
static int filter_frame(AVFilterLink *inlink, AVFrame *insamples)
static const AVFilterPad showvolume_inputs[]
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:389
static int config_output(AVFilterLink *outlink)
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:492
A list of supported channel layouts.
Definition: formats.h:85
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:379
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
void av_expr_free(AVExpr *e)
Free a parsed expression previously created with av_expr_parse().
Definition: eval.c:327
static int query_formats(AVFilterContext *ctx)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
static void draw_text(FFDrawContext *draw, AVFrame *frame, FFDrawColor *color, int x0, int y0, const uint8_t *text, int vertical)
Definition: vf_datascope.c:79
void * buf
Definition: avisynth_c.h:690
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
Rational number (pair of numerator and denominator).
Definition: rational.h:58
offset must point to AVRational
Definition: opt.h:236
static av_cold int init(AVFilterContext *ctx)
const char * name
Filter name.
Definition: avfilter.h:148
#define snprintf
Definition: snprintf.h:34
#define AV_RN32(p)
Definition: intreadwrite.h:369
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
enum MovChannelLayoutTag * layouts
Definition: mov_chan.c:434
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
AVFilterFormats * ff_all_samplerates(void)
Definition: formats.c:395
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:560
#define FLAGS
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
#define AV_WN32(p, v)
Definition: intreadwrite.h:381
uint64_t av_channel_layout_extract_channel(uint64_t channel_layout, int index)
Get the channel with the given index in channel_layout.
static double c[64]
static int config_input(AVFilterLink *inlink)
static av_cold void uninit(AVFilterContext *ctx)
static const char *const var_names[]
const char * av_get_channel_name(uint64_t channel)
Get the name of a given channel.
double av_expr_eval(AVExpr *e, const double *const_values, void *opaque)
Evaluate a previously parsed expression.
Definition: eval.c:727
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
int height
Definition: frame.h:259
FILE * out
Definition: movenc.c:54
#define av_freep(p)
formats
Definition: signature.h:48
internal API functions
AVFilterChannelLayouts * ff_all_channel_counts(void)
Construct an AVFilterChannelLayouts coding for any channel layout, with known or unknown disposition...
Definition: formats.c:410
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:248
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:267
for(j=16;j >0;--j)
AVFILTER_DEFINE_CLASS(showvolume)
CGA/EGA/VGA ROM font data.
simple arithmetic expression evaluator