FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_pp7.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2005 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (c) 2014 Arwa Arif <arwaarif1994@gmail.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 /**
23  * @file
24  * Postprocessing filter - 7
25  *
26  * Originally written by Michael Niedermayer for the MPlayer
27  * project, and ported by Arwa Arif for FFmpeg.
28  */
29 
30 #include "libavutil/avassert.h"
31 #include "libavutil/imgutils.h"
32 #include "libavutil/opt.h"
33 #include "libavutil/pixdesc.h"
34 #include "internal.h"
35 #include "vf_pp7.h"
36 
37 enum mode {
41 };
42 
43 #define OFFSET(x) offsetof(PP7Context, x)
44 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
45 static const AVOption pp7_options[] = {
46  { "qp", "force a constant quantizer parameter", OFFSET(qp), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 64, FLAGS },
47  { "mode", "set thresholding mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64 = MODE_MEDIUM}, 0, 2, FLAGS, "mode" },
48  { "hard", "hard thresholding", 0, AV_OPT_TYPE_CONST, {.i64 = MODE_HARD}, INT_MIN, INT_MAX, FLAGS, "mode" },
49  { "soft", "soft thresholding", 0, AV_OPT_TYPE_CONST, {.i64 = MODE_SOFT}, INT_MIN, INT_MAX, FLAGS, "mode" },
50  { "medium", "medium thresholding", 0, AV_OPT_TYPE_CONST, {.i64 = MODE_MEDIUM}, INT_MIN, INT_MAX, FLAGS, "mode" },
51  { NULL }
52 };
53 
55 
56 DECLARE_ALIGNED(8, static const uint8_t, dither)[8][8] = {
57  { 0, 48, 12, 60, 3, 51, 15, 63, },
58  { 32, 16, 44, 28, 35, 19, 47, 31, },
59  { 8, 56, 4, 52, 11, 59, 7, 55, },
60  { 40, 24, 36, 20, 43, 27, 39, 23, },
61  { 2, 50, 14, 62, 1, 49, 13, 61, },
62  { 34, 18, 46, 30, 33, 17, 45, 29, },
63  { 10, 58, 6, 54, 9, 57, 5, 53, },
64  { 42, 26, 38, 22, 41, 25, 37, 21, },
65 };
66 
67 #define N0 4
68 #define N1 5
69 #define N2 10
70 #define SN0 2
71 #define SN1 2.2360679775
72 #define SN2 3.16227766017
73 #define N (1 << 16)
74 
75 static const int factor[16] = {
76  N / (N0 * N0), N / (N0 * N1), N / (N0 * N0), N / (N0 * N2),
77  N / (N1 * N0), N / (N1 * N1), N / (N1 * N0), N / (N1 * N2),
78  N / (N0 * N0), N / (N0 * N1), N / (N0 * N0), N / (N0 * N2),
79  N / (N2 * N0), N / (N2 * N1), N / (N2 * N0), N / (N2 * N2),
80 };
81 
82 static void init_thres2(PP7Context *p)
83 {
84  int qp, i;
85  int bias = 0; //FIXME
86 
87  for (qp = 0; qp < 99; qp++) {
88  for (i = 0; i < 16; i++) {
89  p->thres2[qp][i] = ((i&1) ? SN2 : SN0) * ((i&4) ? SN2 : SN0) * FFMAX(1, qp) * (1<<2) - 1 - bias;
90  }
91  }
92 }
93 
94 static inline void dctA_c(int16_t *dst, uint8_t *src, int stride)
95 {
96  int i;
97 
98  for (i = 0; i < 4; i++) {
99  int s0 = src[0 * stride] + src[6 * stride];
100  int s1 = src[1 * stride] + src[5 * stride];
101  int s2 = src[2 * stride] + src[4 * stride];
102  int s3 = src[3 * stride];
103  int s = s3 + s3;
104  s3 = s - s0;
105  s0 = s + s0;
106  s = s2 + s1;
107  s2 = s2 - s1;
108  dst[0] = s0 + s;
109  dst[2] = s0 - s;
110  dst[1] = 2 * s3 + s2;
111  dst[3] = s3 - 2 * s2;
112  src++;
113  dst += 4;
114  }
115 }
116 
117 static void dctB_c(int16_t *dst, int16_t *src)
118 {
119  int i;
120 
121  for (i = 0; i < 4; i++) {
122  int s0 = src[0 * 4] + src[6 * 4];
123  int s1 = src[1 * 4] + src[5 * 4];
124  int s2 = src[2 * 4] + src[4 * 4];
125  int s3 = src[3 * 4];
126  int s = s3 + s3;
127  s3 = s - s0;
128  s0 = s + s0;
129  s = s2 + s1;
130  s2 = s2 - s1;
131  dst[0 * 4] = s0 + s;
132  dst[2 * 4] = s0 - s;
133  dst[1 * 4] = 2 * s3 + s2;
134  dst[3 * 4] = s3 - 2 * s2;
135  src++;
136  dst++;
137  }
138 }
139 
140 static int hardthresh_c(PP7Context *p, int16_t *src, int qp)
141 {
142  int i;
143  int a;
144 
145  a = src[0] * factor[0];
146  for (i = 1; i < 16; i++) {
147  unsigned int threshold1 = p->thres2[qp][i];
148  unsigned int threshold2 = threshold1 << 1;
149  int level = src[i];
150  if (((unsigned)(level + threshold1)) > threshold2)
151  a += level * factor[i];
152  }
153  return (a + (1 << 11)) >> 12;
154 }
155 
156 static int mediumthresh_c(PP7Context *p, int16_t *src, int qp)
157 {
158  int i;
159  int a;
160 
161  a = src[0] * factor[0];
162  for (i = 1; i < 16; i++) {
163  unsigned int threshold1 = p->thres2[qp][i];
164  unsigned int threshold2 = threshold1 << 1;
165  int level = src[i];
166  if (((unsigned)(level + threshold1)) > threshold2) {
167  if (((unsigned)(level + 2 * threshold1)) > 2 * threshold2)
168  a += level * factor[i];
169  else {
170  if (level > 0)
171  a += 2 * (level - (int)threshold1) * factor[i];
172  else
173  a += 2 * (level + (int)threshold1) * factor[i];
174  }
175  }
176  }
177  return (a + (1 << 11)) >> 12;
178 }
179 
180 static int softthresh_c(PP7Context *p, int16_t *src, int qp)
181 {
182  int i;
183  int a;
184 
185  a = src[0] * factor[0];
186  for (i = 1; i < 16; i++) {
187  unsigned int threshold1 = p->thres2[qp][i];
188  unsigned int threshold2 = threshold1 << 1;
189  int level = src[i];
190  if (((unsigned)(level + threshold1)) > threshold2) {
191  if (level > 0)
192  a += (level - (int)threshold1) * factor[i];
193  else
194  a += (level + (int)threshold1) * factor[i];
195  }
196  }
197  return (a + (1 << 11)) >> 12;
198 }
199 
200 static void filter(PP7Context *p, uint8_t *dst, uint8_t *src,
201  int dst_stride, int src_stride,
202  int width, int height,
203  uint8_t *qp_store, int qp_stride, int is_luma)
204 {
205  int x, y;
206  const int stride = is_luma ? p->temp_stride : ((width + 16 + 15) & (~15));
207  uint8_t *p_src = p->src + 8 * stride;
208  int16_t *block = (int16_t *)p->src;
209  int16_t *temp = (int16_t *)(p->src + 32);
210 
211  if (!src || !dst) return;
212  for (y = 0; y < height; y++) {
213  int index = 8 + 8 * stride + y * stride;
214  memcpy(p_src + index, src + y * src_stride, width);
215  for (x = 0; x < 8; x++) {
216  p_src[index - x - 1]= p_src[index + x ];
217  p_src[index + width + x ]= p_src[index + width - x - 1];
218  }
219  }
220  for (y = 0; y < 8; y++) {
221  memcpy(p_src + ( 7 - y ) * stride, p_src + ( y + 8 ) * stride, stride);
222  memcpy(p_src + (height + 8 + y) * stride, p_src + (height - y + 7) * stride, stride);
223  }
224  //FIXME (try edge emu)
225 
226  for (y = 0; y < height; y++) {
227  for (x = -8; x < 0; x += 4) {
228  const int index = x + y * stride + (8 - 3) * (1 + stride) + 8; //FIXME silly offset
229  uint8_t *src = p_src + index;
230  int16_t *tp = temp + 4 * x;
231 
232  dctA_c(tp + 4 * 8, src, stride);
233  }
234  for (x = 0; x < width; ) {
235  const int qps = 3 + is_luma;
236  int qp;
237  int end = FFMIN(x + 8, width);
238 
239  if (p->qp)
240  qp = p->qp;
241  else {
242  qp = qp_store[ (FFMIN(x, width - 1) >> qps) + (FFMIN(y, height - 1) >> qps) * qp_stride];
243  qp = ff_norm_qscale(qp, p->qscale_type);
244  }
245  for (; x < end; x++) {
246  const int index = x + y * stride + (8 - 3) * (1 + stride) + 8; //FIXME silly offset
247  uint8_t *src = p_src + index;
248  int16_t *tp = temp + 4 * x;
249  int v;
250 
251  if ((x & 3) == 0)
252  dctA_c(tp + 4 * 8, src, stride);
253 
254  p->dctB(block, tp);
255 
256  v = p->requantize(p, block, qp);
257  v = (v + dither[y & 7][x & 7]) >> 6;
258  if ((unsigned)v > 255)
259  v = (-v) >> 31;
260  dst[x + y * dst_stride] = v;
261  }
262  }
263  }
264 }
265 
267 {
268  static const enum AVPixelFormat pix_fmts[] = {
276  };
277 
278  AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
279  if (!fmts_list)
280  return AVERROR(ENOMEM);
281  return ff_set_common_formats(ctx, fmts_list);
282 }
283 
284 static int config_input(AVFilterLink *inlink)
285 {
286  AVFilterContext *ctx = inlink->dst;
287  PP7Context *pp7 = ctx->priv;
288  const int h = FFALIGN(inlink->h + 16, 16);
290 
291  pp7->hsub = desc->log2_chroma_w;
292  pp7->vsub = desc->log2_chroma_h;
293 
294  pp7->temp_stride = FFALIGN(inlink->w + 16, 16);
295  pp7->src = av_malloc_array(pp7->temp_stride, (h + 8) * sizeof(uint8_t));
296 
297  if (!pp7->src)
298  return AVERROR(ENOMEM);
299 
300  init_thres2(pp7);
301 
302  switch (pp7->mode) {
303  case 0: pp7->requantize = hardthresh_c; break;
304  case 1: pp7->requantize = softthresh_c; break;
305  default:
306  case 2: pp7->requantize = mediumthresh_c; break;
307  }
308 
309  pp7->dctB = dctB_c;
310 
311  if (ARCH_X86)
312  ff_pp7_init_x86(pp7);
313 
314  return 0;
315 }
316 
317 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
318 {
319  AVFilterContext *ctx = inlink->dst;
320  PP7Context *pp7 = ctx->priv;
321  AVFilterLink *outlink = ctx->outputs[0];
322  AVFrame *out = in;
323 
324  int qp_stride = 0;
325  uint8_t *qp_table = NULL;
326 
327  if (!pp7->qp)
328  qp_table = av_frame_get_qp_table(in, &qp_stride, &pp7->qscale_type);
329 
330  if (!ctx->is_disabled) {
331  const int cw = AV_CEIL_RSHIFT(inlink->w, pp7->hsub);
332  const int ch = AV_CEIL_RSHIFT(inlink->h, pp7->vsub);
333 
334  /* get a new frame if in-place is not possible or if the dimensions
335  * are not multiple of 8 */
336  if (!av_frame_is_writable(in) || (inlink->w & 7) || (inlink->h & 7)) {
337  const int aligned_w = FFALIGN(inlink->w, 8);
338  const int aligned_h = FFALIGN(inlink->h, 8);
339 
340  out = ff_get_video_buffer(outlink, aligned_w, aligned_h);
341  if (!out) {
342  av_frame_free(&in);
343  return AVERROR(ENOMEM);
344  }
345  av_frame_copy_props(out, in);
346  out->width = in->width;
347  out->height = in->height;
348  }
349 
350  if (qp_table || pp7->qp) {
351 
352  filter(pp7, out->data[0], in->data[0], out->linesize[0], in->linesize[0],
353  inlink->w, inlink->h, qp_table, qp_stride, 1);
354  filter(pp7, out->data[1], in->data[1], out->linesize[1], in->linesize[1],
355  cw, ch, qp_table, qp_stride, 0);
356  filter(pp7, out->data[2], in->data[2], out->linesize[2], in->linesize[2],
357  cw, ch, qp_table, qp_stride, 0);
358  emms_c();
359  }
360  }
361 
362  if (in != out) {
363  if (in->data[3])
364  av_image_copy_plane(out->data[3], out->linesize[3],
365  in ->data[3], in ->linesize[3],
366  inlink->w, inlink->h);
367  av_frame_free(&in);
368  }
369  return ff_filter_frame(outlink, out);
370 }
371 
373 {
374  PP7Context *pp7 = ctx->priv;
375  av_freep(&pp7->src);
376 }
377 
378 static const AVFilterPad pp7_inputs[] = {
379  {
380  .name = "default",
381  .type = AVMEDIA_TYPE_VIDEO,
382  .config_props = config_input,
383  .filter_frame = filter_frame,
384  },
385  { NULL }
386 };
387 
388 static const AVFilterPad pp7_outputs[] = {
389  {
390  .name = "default",
391  .type = AVMEDIA_TYPE_VIDEO,
392  },
393  { NULL }
394 };
395 
397  .name = "pp7",
398  .description = NULL_IF_CONFIG_SMALL("Apply Postprocessing 7 filter."),
399  .priv_size = sizeof(PP7Context),
400  .uninit = uninit,
402  .inputs = pp7_inputs,
403  .outputs = pp7_outputs,
404  .priv_class = &pp7_class,
406 };
#define NULL
Definition: coverity.c:32
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2446
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
AVOption.
Definition: opt.h:246
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
else temp
Definition: vf_mcdeint.c:256
const char * desc
Definition: nvenc.c:65
AVFILTER_DEFINE_CLASS(pp7)
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
#define OFFSET(x)
Definition: vf_pp7.c:43
#define SN0
Definition: vf_pp7.c:70
#define src
Definition: vp8dsp.c:254
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:385
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
static int16_t block[64]
Definition: dct.c:115
const char * name
Pad name.
Definition: internal.h:60
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
uint8_t
#define av_cold
Definition: attributes.h:82
AVOptions.
int thres2[99][16]
Definition: vf_pp7.h:29
int qp
Definition: vf_pp7.h:31
static int query_formats(AVFilterContext *ctx)
Definition: vf_pp7.c:266
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static const AVOption pp7_options[]
Definition: vf_pp7.c:45
static int softthresh_c(PP7Context *p, int16_t *src, int qp)
Definition: vf_pp7.c:180
#define N
Definition: vf_pp7.c:73
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
Definition: mem.h:112
#define height
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
#define N2
Definition: vf_pp7.c:69
#define FFALIGN(x, a)
Definition: macros.h:48
A filter pad used for either input or output.
Definition: internal.h:54
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_pp7.c:372
int qscale_type
Definition: vf_pp7.h:33
int width
Definition: frame.h:284
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
static void init_thres2(PP7Context *p)
Definition: vf_pp7.c:82
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
void(* dctB)(int16_t *dst, int16_t *src)
Definition: vf_pp7.h:40
#define s2
Definition: regdef.h:39
#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:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define s0
Definition: regdef.h:37
static void dctB_c(int16_t *dst, int16_t *src)
Definition: vf_pp7.c:117
simple assert() macros that are a bit more flexible than ISO C assert().
int(* requantize)(struct PP7Context *p, int16_t *src, int qp)
Definition: vf_pp7.h:39
#define FFMAX(a, b)
Definition: common.h:94
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_pp7.c:317
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
#define FLAGS
Definition: vf_pp7.c:44
static int hardthresh_c(PP7Context *p, int16_t *src, int qp)
Definition: vf_pp7.c:140
#define FFMIN(a, b)
Definition: common.h:96
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
#define SN2
Definition: vf_pp7.c:72
#define width
#define N0
Definition: vf_pp7.c:67
int hsub
Definition: vf_pp7.h:34
AVFormatContext * ctx
Definition: movenc.c:48
int vsub
Definition: vf_pp7.h:35
static const AVFilterPad pp7_outputs[]
Definition: vf_pp7.c:388
#define s(width, name)
Definition: cbs_vp9.c:257
static void filter(PP7Context *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma)
Definition: vf_pp7.c:200
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
#define s3
Definition: regdef.h:40
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
uint8_t * src
Definition: vf_pp7.h:37
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:257
static int mediumthresh_c(PP7Context *p, int16_t *src, int qp)
Definition: vf_pp7.c:156
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
Filter definition.
Definition: avfilter.h:144
int index
Definition: gxfenc.c:89
void ff_pp7_init_x86(PP7Context *pp7)
Definition: vf_pp7_init.c:28
static const int factor[16]
Definition: vf_pp7.c:75
const char * name
Filter name.
Definition: avfilter.h:148
#define s1
Definition: regdef.h:38
#define AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
Same as AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, except that the filter will have its filter_frame() c...
Definition: avfilter.h:133
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static int ff_norm_qscale(int qscale, int type)
Normalize the qscale factor FIXME the H264 qscale is a log based scale, mpeg1/2 is not...
Definition: internal.h:397
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
#define flags(name, subs,...)
Definition: cbs_av1.c:596
static const uint8_t dither[8][8]
Definition: vf_pp7.c:56
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
uint8_t level
Definition: svq3.c:207
static void dctA_c(int16_t *dst, uint8_t *src, int stride)
Definition: vf_pp7.c:94
static const AVFilterPad pp7_inputs[]
Definition: vf_pp7.c:378
int
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
int mode
Definition: vf_pp7.h:32
#define N1
Definition: vf_pp7.c:68
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
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
int height
Definition: frame.h:284
FILE * out
Definition: movenc.c:54
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
#define av_malloc_array(a, b)
int temp_stride
Definition: vf_pp7.h:36
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:338
#define stride
internal API functions
int8_t * av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
Definition: frame.c:90
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
AVFilter ff_vf_pp7
Definition: vf_pp7.c:396
mode
Use these values in ebur128_init (or'ed).
Definition: ebur128.h:83
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
static int config_input(AVFilterLink *inlink)
Definition: vf_pp7.c:284
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
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58