FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vsrc_mptestsrc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 /**
22  * @file
23  * MP test source, ported from MPlayer libmpcodecs/vf_test.c
24  */
25 
26 #include "libavutil/avstring.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/parseutils.h"
29 #include "libavutil/pixdesc.h"
30 #include "avfilter.h"
31 #include "internal.h"
32 #include "formats.h"
33 #include "video.h"
34 
35 #define WIDTH 512
36 #define HEIGHT 512
37 
38 enum test_type {
51 };
52 
53 typedef struct MPTestContext {
54  const AVClass *class;
56  int64_t pts, max_pts, duration;
57  int hsub, vsub;
58  int test; ///< test_type
60 
61 #define OFFSET(x) offsetof(MPTestContext, x)
62 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
63 static const AVOption mptestsrc_options[]= {
64  { "rate", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
65  { "r", "set video rate", OFFSET(frame_rate), AV_OPT_TYPE_VIDEO_RATE, {.str = "25"}, 0, INT_MAX, FLAGS },
66  { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
67  { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
68 
69  { "test", "set test to perform", OFFSET(test), AV_OPT_TYPE_INT, {.i64=TEST_ALL}, 0, INT_MAX, FLAGS, "test" },
70  { "t", "set test to perform", OFFSET(test), AV_OPT_TYPE_INT, {.i64=TEST_ALL}, 0, INT_MAX, FLAGS, "test" },
71  { "dc_luma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_DC_LUMA}, INT_MIN, INT_MAX, FLAGS, "test" },
72  { "dc_chroma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_DC_CHROMA}, INT_MIN, INT_MAX, FLAGS, "test" },
73  { "freq_luma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_FREQ_LUMA}, INT_MIN, INT_MAX, FLAGS, "test" },
74  { "freq_chroma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_FREQ_CHROMA}, INT_MIN, INT_MAX, FLAGS, "test" },
75  { "amp_luma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_AMP_LUMA}, INT_MIN, INT_MAX, FLAGS, "test" },
76  { "amp_chroma", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_AMP_CHROMA}, INT_MIN, INT_MAX, FLAGS, "test" },
77  { "cbp", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_CBP}, INT_MIN, INT_MAX, FLAGS, "test" },
78  { "mv", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_MV}, INT_MIN, INT_MAX, FLAGS, "test" },
79  { "ring1", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_RING1}, INT_MIN, INT_MAX, FLAGS, "test" },
80  { "ring2", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_RING2}, INT_MIN, INT_MAX, FLAGS, "test" },
81  { "all", "", 0, AV_OPT_TYPE_CONST, {.i64=TEST_ALL}, INT_MIN, INT_MAX, FLAGS, "test" },
82  { NULL }
83 };
84 
85 AVFILTER_DEFINE_CLASS(mptestsrc);
86 
87 static double c[64];
88 
89 static void init_idct(void)
90 {
91  int i, j;
92 
93  for (i = 0; i < 8; i++) {
94  double s = i == 0 ? sqrt(0.125) : 0.5;
95 
96  for (j = 0; j < 8; j++)
97  c[i*8+j] = s*cos((M_PI/8.0)*i*(j+0.5));
98  }
99 }
100 
101 static void idct(uint8_t *dst, int dst_linesize, int src[64])
102 {
103  int i, j, k;
104  double tmp[64];
105 
106  for (i = 0; i < 8; i++) {
107  for (j = 0; j < 8; j++) {
108  double sum = 0.0;
109 
110  for (k = 0; k < 8; k++)
111  sum += c[k*8+j] * src[8*i+k];
112 
113  tmp[8*i+j] = sum;
114  }
115  }
116 
117  for (j = 0; j < 8; j++) {
118  for (i = 0; i < 8; i++) {
119  double sum = 0.0;
120 
121  for (k = 0; k < 8; k++)
122  sum += c[k*8+i]*tmp[8*k+j];
123 
124  dst[dst_linesize*i + j] = av_clip_uint8(lrint(sum));
125  }
126  }
127 }
128 
129 static void draw_dc(uint8_t *dst, int dst_linesize, int color, int w, int h)
130 {
131  int x, y;
132 
133  for (y = 0; y < h; y++)
134  for (x = 0; x < w; x++)
135  dst[x + y*dst_linesize] = color;
136 }
137 
138 static void draw_basis(uint8_t *dst, int dst_linesize, int amp, int freq, int dc)
139 {
140  int src[64];
141 
142  memset(src, 0, 64*sizeof(int));
143  src[0] = dc;
144  if (amp)
145  src[freq] = amp;
146  idct(dst, dst_linesize, src);
147 }
148 
149 static void draw_cbp(uint8_t *dst[3], int dst_linesize[3], int cbp, int amp, int dc)
150 {
151  if (cbp&1) draw_basis(dst[0] , dst_linesize[0], amp, 1, dc);
152  if (cbp&2) draw_basis(dst[0]+8 , dst_linesize[0], amp, 1, dc);
153  if (cbp&4) draw_basis(dst[0]+ 8*dst_linesize[0], dst_linesize[0], amp, 1, dc);
154  if (cbp&8) draw_basis(dst[0]+8+8*dst_linesize[0], dst_linesize[0], amp, 1, dc);
155  if (cbp&16) draw_basis(dst[1] , dst_linesize[1], amp, 1, dc);
156  if (cbp&32) draw_basis(dst[2] , dst_linesize[2], amp, 1, dc);
157 }
158 
159 static void dc_test(uint8_t *dst, int dst_linesize, int w, int h, int off)
160 {
161  const int step = FFMAX(256/(w*h/256), 1);
162  int x, y, color = off;
163 
164  for (y = 0; y < h; y += 16) {
165  for (x = 0; x < w; x += 16) {
166  draw_dc(dst + x + y*dst_linesize, dst_linesize, color, 8, 8);
167  color += step;
168  }
169  }
170 }
171 
172 static void freq_test(uint8_t *dst, int dst_linesize, int off)
173 {
174  int x, y, freq = 0;
175 
176  for (y = 0; y < 8*16; y += 16) {
177  for (x = 0; x < 8*16; x += 16) {
178  draw_basis(dst + x + y*dst_linesize, dst_linesize, 4*(96+off), freq, 128*8);
179  freq++;
180  }
181  }
182 }
183 
184 static void amp_test(uint8_t *dst, int dst_linesize, int off)
185 {
186  int x, y, amp = off;
187 
188  for (y = 0; y < 16*16; y += 16) {
189  for (x = 0; x < 16*16; x += 16) {
190  draw_basis(dst + x + y*dst_linesize, dst_linesize, 4*amp, 1, 128*8);
191  amp++;
192  }
193  }
194 }
195 
196 static void cbp_test(uint8_t *dst[3], int dst_linesize[3], int off)
197 {
198  int x, y, cbp = 0;
199 
200  for (y = 0; y < 16*8; y += 16) {
201  for (x = 0; x < 16*8; x += 16) {
202  uint8_t *dst1[3];
203  dst1[0] = dst[0] + x*2 + y*2*dst_linesize[0];
204  dst1[1] = dst[1] + x + y* dst_linesize[1];
205  dst1[2] = dst[2] + x + y* dst_linesize[2];
206 
207  draw_cbp(dst1, dst_linesize, cbp, (64+off)*4, 128*8);
208  cbp++;
209  }
210  }
211 }
212 
213 static void mv_test(uint8_t *dst, int dst_linesize, int off)
214 {
215  int x, y;
216 
217  for (y = 0; y < 16*16; y++) {
218  if (y&16)
219  continue;
220  for (x = 0; x < 16*16; x++)
221  dst[x + y*dst_linesize] = x + off*8/(y/32+1);
222  }
223 }
224 
225 static void ring1_test(uint8_t *dst, int dst_linesize, int off)
226 {
227  int x, y, color = 0;
228 
229  for (y = off; y < 16*16; y += 16) {
230  for (x = off; x < 16*16; x += 16) {
231  draw_dc(dst + x + y*dst_linesize, dst_linesize, ((x+y)&16) ? color : -color, 16, 16);
232  color++;
233  }
234  }
235 }
236 
237 static void ring2_test(uint8_t *dst, int dst_linesize, int off)
238 {
239  int x, y;
240 
241  for (y = 0; y < 16*16; y++) {
242  for (x = 0; x < 16*16; x++) {
243  double d = hypot(x-8*16, y-8*16);
244  double r = d/20 - (int)(d/20);
245  if (r < off/30.0) {
246  dst[x + y*dst_linesize] = 255;
247  dst[x + y*dst_linesize+256] = 0;
248  } else {
249  dst[x + y*dst_linesize] = x;
250  dst[x + y*dst_linesize+256] = x;
251  }
252  }
253  }
254 }
255 
257 {
258  MPTestContext *test = ctx->priv;
259 
260  test->max_pts = test->duration >= 0 ?
262  test->pts = 0;
263 
264  av_log(ctx, AV_LOG_VERBOSE, "rate:%d/%d duration:%f\n",
265  test->frame_rate.num, test->frame_rate.den,
266  test->duration < 0 ? -1 : test->max_pts * av_q2d(av_inv_q(test->frame_rate)));
267  init_idct();
268 
269  return 0;
270 }
271 
272 static int config_props(AVFilterLink *outlink)
273 {
274  AVFilterContext *ctx = outlink->src;
275  MPTestContext *test = ctx->priv;
276  const AVPixFmtDescriptor *pix_desc = av_pix_fmt_desc_get(outlink->format);
277 
278  test->hsub = pix_desc->log2_chroma_w;
279  test->vsub = pix_desc->log2_chroma_h;
280 
281  outlink->w = WIDTH;
282  outlink->h = HEIGHT;
283  outlink->time_base = av_inv_q(test->frame_rate);
284 
285  return 0;
286 }
287 
289 {
290  static const enum AVPixelFormat pix_fmts[] = {
292  };
293 
294  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
295  if (!fmts_list)
296  return AVERROR(ENOMEM);
297  return ff_set_common_formats(ctx, fmts_list);
298 }
299 
300 static int request_frame(AVFilterLink *outlink)
301 {
302  MPTestContext *test = outlink->src->priv;
303  AVFrame *picref;
304  int w = WIDTH, h = HEIGHT,
305  cw = AV_CEIL_RSHIFT(w, test->hsub), ch = AV_CEIL_RSHIFT(h, test->vsub);
306  unsigned int frame = outlink->frame_count_in;
307  enum test_type tt = test->test;
308  int i;
309 
310  if (test->max_pts >= 0 && test->pts > test->max_pts)
311  return AVERROR_EOF;
312  picref = ff_get_video_buffer(outlink, w, h);
313  if (!picref)
314  return AVERROR(ENOMEM);
315  picref->pts = test->pts++;
316 
317  // clean image
318  for (i = 0; i < h; i++)
319  memset(picref->data[0] + i*picref->linesize[0], 0, w);
320  for (i = 0; i < ch; i++) {
321  memset(picref->data[1] + i*picref->linesize[1], 128, cw);
322  memset(picref->data[2] + i*picref->linesize[2], 128, cw);
323  }
324 
325  if (tt == TEST_ALL && frame%30) /* draw a black frame at the beginning of each test */
326  tt = (frame/30)%(TEST_NB-1);
327 
328  switch (tt) {
329  case TEST_DC_LUMA: dc_test(picref->data[0], picref->linesize[0], 256, 256, frame%30); break;
330  case TEST_DC_CHROMA: dc_test(picref->data[1], picref->linesize[1], 256, 256, frame%30); break;
331  case TEST_FREQ_LUMA: freq_test(picref->data[0], picref->linesize[0], frame%30); break;
332  case TEST_FREQ_CHROMA: freq_test(picref->data[1], picref->linesize[1], frame%30); break;
333  case TEST_AMP_LUMA: amp_test(picref->data[0], picref->linesize[0], frame%30); break;
334  case TEST_AMP_CHROMA: amp_test(picref->data[1], picref->linesize[1], frame%30); break;
335  case TEST_CBP: cbp_test(picref->data , picref->linesize , frame%30); break;
336  case TEST_MV: mv_test(picref->data[0], picref->linesize[0], frame%30); break;
337  case TEST_RING1: ring1_test(picref->data[0], picref->linesize[0], frame%30); break;
338  case TEST_RING2: ring2_test(picref->data[0], picref->linesize[0], frame%30); break;
339  }
340 
341  return ff_filter_frame(outlink, picref);
342 }
343 
344 static const AVFilterPad mptestsrc_outputs[] = {
345  {
346  .name = "default",
347  .type = AVMEDIA_TYPE_VIDEO,
348  .request_frame = request_frame,
349  .config_props = config_props,
350  },
351  { NULL }
352 };
353 
355  .name = "mptestsrc",
356  .description = NULL_IF_CONFIG_SMALL("Generate various test pattern."),
357  .priv_size = sizeof(MPTestContext),
358  .priv_class = &mptestsrc_class,
359  .init = init,
361  .inputs = NULL,
362  .outputs = mptestsrc_outputs,
363 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2419
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
AVOption.
Definition: opt.h:246
#define HEIGHT
static int config_props(AVFilterLink *outlink)
Main libavfilter public API header.
static void init_idct(void)
int num
Numerator.
Definition: rational.h:59
static av_cold int init(AVFilterContext *ctx)
static int request_frame(AVFilterLink *outlink)
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
#define src
Definition: vp8dsp.c:254
static void dc_test(uint8_t *dst, int dst_linesize, int w, int h, int off)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
int test
test_type
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
static void cbp_test(uint8_t *dst[3], int dst_linesize[3], int off)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1151
uint8_t
AVRational frame_rate
#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
int64_t duration
Definition: movenc.c:63
static AVFrame * frame
static double av_q2d(AVRational a)
Convert an AVRational to a double.
Definition: rational.h:104
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define av_log(a,...)
A filter pad used for either input or output.
Definition: internal.h:54
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:142
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
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
const char * r
Definition: vf_curves.c:111
void * priv
private data for use by the filter
Definition: avfilter.h:353
AVFILTER_DEFINE_CLASS(mptestsrc)
#define FFMAX(a, b)
Definition: common.h:94
static av_const double hypot(double x, double y)
Definition: libm.h:366
static void ring2_test(uint8_t *dst, int dst_linesize, int off)
static const AVFilterPad mptestsrc_outputs[]
AVFormatContext * ctx
Definition: movenc.c:48
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:389
static void mv_test(uint8_t *dst, int dst_linesize, int off)
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:379
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:260
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
AVFilter ff_vsrc_mptestsrc
static int query_formats(AVFilterContext *ctx)
#define OFFSET(x)
static void test(const char *pattern, const char *host)
Definition: noproxy.c:23
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
test_type
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
int64_t duration
Rational number (pair of numerator and denominator).
Definition: rational.h:58
offset must point to AVRational
Definition: opt.h:236
const char * name
Filter name.
Definition: avfilter.h:148
static void amp_test(uint8_t *dst, int dst_linesize, int off)
misc parsing utilities
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
static void draw_basis(uint8_t *dst, int dst_linesize, int amp, int freq, int dc)
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
Definition: rational.h:159
#define FLAGS
int
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
static double c[64]
int den
Denominator.
Definition: rational.h:60
static void draw_dc(uint8_t *dst, int dst_linesize, int color, int w, int h)
A list of supported formats for one end of a filter link.
Definition: formats.h:64
#define lrint
Definition: tablegen.h:53
#define WIDTH
An instance of a filter.
Definition: avfilter.h:338
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-> dc
static void ring1_test(uint8_t *dst, int dst_linesize, int off)
static const AVOption mptestsrc_options[]
static void idct(uint8_t *dst, int dst_linesize, int src[64])
#define M_PI
Definition: mathematics.h:52
static void draw_cbp(uint8_t *dst[3], int dst_linesize[3], int cbp, int amp, int dc)
internal API functions
static void freq_test(uint8_t *dst, int dst_linesize, int off)
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
static uint8_t tmp[11]
Definition: aes_ctr.c:26