FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_premultiply.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 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/imgutils.h"
22 #include "libavutil/pixdesc.h"
23 #include "libavutil/opt.h"
24 #include "avfilter.h"
25 #include "formats.h"
26 #include "framesync.h"
27 #include "internal.h"
28 #include "video.h"
29 
30 typedef struct PreMultiplyContext {
31  const AVClass *class;
32  int width[4], height[4];
33  int nb_planes;
34  int planes;
35  int half, depth, offset;
37 
38  void (*premultiply[4])(const uint8_t *msrc, const uint8_t *asrc,
39  uint8_t *dst,
40  ptrdiff_t mlinesize, ptrdiff_t alinesize,
41  ptrdiff_t dlinesize,
42  int w, int h,
43  int half, int shift, int offset);
45 
46 #define OFFSET(x) offsetof(PreMultiplyContext, x)
47 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
48 
49 static const AVOption premultiply_options[] = {
50  { NULL }
51 };
52 
53 AVFILTER_DEFINE_CLASS(premultiply);
54 
56 {
57  static const enum AVPixelFormat pix_fmts[] = {
66  };
67 
68  return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
69 }
70 
71 static void premultiply8(const uint8_t *msrc, const uint8_t *asrc,
72  uint8_t *dst,
73  ptrdiff_t mlinesize, ptrdiff_t alinesize,
74  ptrdiff_t dlinesize,
75  int w, int h,
76  int half, int shift, int offset)
77 {
78  int x, y;
79 
80  for (y = 0; y < h; y++) {
81  for (x = 0; x < w; x++) {
82  dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8;
83  }
84 
85  dst += dlinesize;
86  msrc += mlinesize;
87  asrc += alinesize;
88  }
89 }
90 
91 static void premultiply8yuv(const uint8_t *msrc, const uint8_t *asrc,
92  uint8_t *dst,
93  ptrdiff_t mlinesize, ptrdiff_t alinesize,
94  ptrdiff_t dlinesize,
95  int w, int h,
96  int half, int shift, int offset)
97 {
98  int x, y;
99 
100  for (y = 0; y < h; y++) {
101  for (x = 0; x < w; x++) {
102  dst[x] = ((((msrc[x] - 128) * (((asrc[x] >> 1) & 1) + asrc[x]))) >> 8) + 128;
103  }
104 
105  dst += dlinesize;
106  msrc += mlinesize;
107  asrc += alinesize;
108  }
109 }
110 
111 static void premultiply8offset(const uint8_t *msrc, const uint8_t *asrc,
112  uint8_t *dst,
113  ptrdiff_t mlinesize, ptrdiff_t alinesize,
114  ptrdiff_t dlinesize,
115  int w, int h,
116  int half, int shift, int offset)
117 {
118  int x, y;
119 
120  for (y = 0; y < h; y++) {
121  for (x = 0; x < w; x++) {
122  dst[x] = ((((msrc[x] - offset) * (((asrc[x] >> 1) & 1) + asrc[x])) + 128) >> 8) + offset;
123  }
124 
125  dst += dlinesize;
126  msrc += mlinesize;
127  asrc += alinesize;
128  }
129 }
130 
131 static void premultiply16(const uint8_t *mmsrc, const uint8_t *aasrc,
132  uint8_t *ddst,
133  ptrdiff_t mlinesize, ptrdiff_t alinesize,
134  ptrdiff_t dlinesize,
135  int w, int h,
136  int half, int shift, int offset)
137 {
138  const uint16_t *msrc = (const uint16_t *)mmsrc;
139  const uint16_t *asrc = (const uint16_t *)aasrc;
140  uint16_t *dst = (uint16_t *)ddst;
141  int x, y;
142 
143  for (y = 0; y < h; y++) {
144  for (x = 0; x < w; x++) {
145  dst[x] = ((msrc[x] * (((asrc[x] >> 1) & 1) + asrc[x])) + half) >> shift;
146  }
147 
148  dst += dlinesize / 2;
149  msrc += mlinesize / 2;
150  asrc += alinesize / 2;
151  }
152 }
153 
154 static void premultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc,
155  uint8_t *ddst,
156  ptrdiff_t mlinesize, ptrdiff_t alinesize,
157  ptrdiff_t dlinesize,
158  int w, int h,
159  int half, int shift, int offset)
160 {
161  const uint16_t *msrc = (const uint16_t *)mmsrc;
162  const uint16_t *asrc = (const uint16_t *)aasrc;
163  uint16_t *dst = (uint16_t *)ddst;
164  int x, y;
165 
166  for (y = 0; y < h; y++) {
167  for (x = 0; x < w; x++) {
168  dst[x] = ((((msrc[x] - half) * (((asrc[x] >> 1) & 1) + asrc[x]))) >> shift) + half;
169  }
170 
171  dst += dlinesize / 2;
172  msrc += mlinesize / 2;
173  asrc += alinesize / 2;
174  }
175 }
176 
177 static void premultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc,
178  uint8_t *ddst,
179  ptrdiff_t mlinesize, ptrdiff_t alinesize,
180  ptrdiff_t dlinesize,
181  int w, int h,
182  int half, int shift, int offset)
183 {
184  const uint16_t *msrc = (const uint16_t *)mmsrc;
185  const uint16_t *asrc = (const uint16_t *)aasrc;
186  uint16_t *dst = (uint16_t *)ddst;
187  int x, y;
188 
189  for (y = 0; y < h; y++) {
190  for (x = 0; x < w; x++) {
191  dst[x] = ((((msrc[x] - offset) * (((asrc[x] >> 1) & 1) + asrc[x])) + half) >> shift) + offset;
192  }
193 
194  dst += dlinesize / 2;
195  msrc += mlinesize / 2;
196  asrc += alinesize / 2;
197  }
198 }
199 
200 static int process_frame(FFFrameSync *fs)
201 {
202  AVFilterContext *ctx = fs->parent;
203  PreMultiplyContext *s = fs->opaque;
204  AVFilterLink *outlink = ctx->outputs[0];
205  AVFrame *out, *base, *alpha;
206  int ret;
207 
208  if ((ret = ff_framesync_get_frame(&s->fs, 0, &base, 0)) < 0 ||
209  (ret = ff_framesync_get_frame(&s->fs, 1, &alpha, 0)) < 0)
210  return ret;
211 
212  if (ctx->is_disabled) {
213  out = av_frame_clone(base);
214  if (!out)
215  return AVERROR(ENOMEM);
216  } else {
217  int p, full, limited;
218 
219  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
220  if (!out)
221  return AVERROR(ENOMEM);
222  av_frame_copy_props(out, base);
223 
224  full = base->color_range == AVCOL_RANGE_JPEG;
225  limited = base->color_range == AVCOL_RANGE_MPEG;
226 
227  switch (outlink->format) {
228  case AV_PIX_FMT_YUV444P:
232  break;
233  case AV_PIX_FMT_YUVJ444P:
234  s->premultiply[0] = premultiply8;
237  break;
238  case AV_PIX_FMT_GBRP:
239  s->premultiply[0] = limited ? premultiply8offset : premultiply8;
240  s->premultiply[1] = limited ? premultiply8offset : premultiply8;
241  s->premultiply[2] = limited ? premultiply8offset : premultiply8;
242  break;
243  case AV_PIX_FMT_YUV444P9:
251  break;
252  case AV_PIX_FMT_GBRP9:
253  case AV_PIX_FMT_GBRP10:
254  case AV_PIX_FMT_GBRP12:
255  case AV_PIX_FMT_GBRP14:
256  case AV_PIX_FMT_GBRP16:
257  s->premultiply[0] = limited ? premultiply16offset : premultiply16;
258  s->premultiply[1] = limited ? premultiply16offset : premultiply16;
259  s->premultiply[2] = limited ? premultiply16offset : premultiply16;
260  break;
261  case AV_PIX_FMT_GRAY8:
262  s->premultiply[0] = limited ? premultiply8offset : premultiply8;
263  break;
264  case AV_PIX_FMT_GRAY10:
265  case AV_PIX_FMT_GRAY12:
266  case AV_PIX_FMT_GRAY16:
267  s->premultiply[0] = limited ? premultiply16offset : premultiply16;
268  break;
269  }
270 
271  for (p = 0; p < s->nb_planes; p++) {
272  s->premultiply[p](base->data[p], alpha->data[0],
273  out->data[p],
274  base->linesize[p], alpha->linesize[0],
275  out->linesize[p],
276  s->width[p], s->height[p],
277  s->half, s->depth, s->offset);
278  }
279  }
280  out->pts = av_rescale_q(base->pts, s->fs.time_base, outlink->time_base);
281 
282  return ff_filter_frame(outlink, out);
283 }
284 
285 static int config_input(AVFilterLink *inlink)
286 {
287  AVFilterContext *ctx = inlink->dst;
288  PreMultiplyContext *s = ctx->priv;
290  int vsub, hsub;
291 
293 
294  hsub = desc->log2_chroma_w;
295  vsub = desc->log2_chroma_h;
296  s->height[1] = s->height[2] = AV_CEIL_RSHIFT(inlink->h, vsub);
297  s->height[0] = s->height[3] = inlink->h;
298  s->width[1] = s->width[2] = AV_CEIL_RSHIFT(inlink->w, hsub);
299  s->width[0] = s->width[3] = inlink->w;
300 
301  s->depth = desc->comp[0].depth;
302  s->half = (1 << s->depth) / 2;
303  s->offset = 16 << (s->depth - 8);
304 
305  return 0;
306 }
307 
308 static int config_output(AVFilterLink *outlink)
309 {
310  AVFilterContext *ctx = outlink->src;
311  PreMultiplyContext *s = ctx->priv;
312  AVFilterLink *base = ctx->inputs[0];
313  AVFilterLink *alpha = ctx->inputs[1];
314  FFFrameSyncIn *in;
315  int ret;
316 
317  if (base->format != alpha->format) {
318  av_log(ctx, AV_LOG_ERROR, "inputs must be of same pixel format\n");
319  return AVERROR(EINVAL);
320  }
321  if (base->w != alpha->w ||
322  base->h != alpha->h) {
323  av_log(ctx, AV_LOG_ERROR, "First input link %s parameters "
324  "(size %dx%d) do not match the corresponding "
325  "second input link %s parameters (%dx%d) ",
326  ctx->input_pads[0].name, base->w, base->h,
327  ctx->input_pads[1].name, alpha->w, alpha->h);
328  return AVERROR(EINVAL);
329  }
330 
331  outlink->w = base->w;
332  outlink->h = base->h;
333  outlink->time_base = base->time_base;
334  outlink->sample_aspect_ratio = base->sample_aspect_ratio;
335  outlink->frame_rate = base->frame_rate;
336 
337  if ((ret = ff_framesync_init(&s->fs, ctx, 2)) < 0)
338  return ret;
339 
340  in = s->fs.in;
341  in[0].time_base = base->time_base;
342  in[1].time_base = alpha->time_base;
343  in[0].sync = 1;
344  in[0].before = EXT_STOP;
345  in[0].after = EXT_INFINITY;
346  in[1].sync = 1;
347  in[1].before = EXT_STOP;
348  in[1].after = EXT_INFINITY;
349  s->fs.opaque = s;
351 
352  return ff_framesync_configure(&s->fs);
353 }
354 
355 static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
356 {
357  PreMultiplyContext *s = inlink->dst->priv;
358  return ff_framesync_filter_frame(&s->fs, inlink, buf);
359 }
360 
361 static int request_frame(AVFilterLink *outlink)
362 {
363  PreMultiplyContext *s = outlink->src->priv;
364  return ff_framesync_request_frame(&s->fs, outlink);
365 }
366 
368 {
369  PreMultiplyContext *s = ctx->priv;
370 
371  ff_framesync_uninit(&s->fs);
372 }
373 
374 static const AVFilterPad premultiply_inputs[] = {
375  {
376  .name = "main",
377  .type = AVMEDIA_TYPE_VIDEO,
378  .filter_frame = filter_frame,
379  .config_props = config_input,
380  },
381  {
382  .name = "alpha",
383  .type = AVMEDIA_TYPE_VIDEO,
384  .filter_frame = filter_frame,
385  },
386  { NULL }
387 };
388 
390  {
391  .name = "default",
392  .type = AVMEDIA_TYPE_VIDEO,
393  .config_props = config_output,
394  .request_frame = request_frame,
395  },
396  { NULL }
397 };
398 
400  .name = "premultiply",
401  .description = NULL_IF_CONFIG_SMALL("PreMultiply first stream with first plane of second stream."),
402  .priv_size = sizeof(PreMultiplyContext),
403  .uninit = uninit,
405  .inputs = premultiply_inputs,
406  .outputs = premultiply_outputs,
407  .priv_class = &premultiply_class,
409 };
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:768
static int shift(int a, int b)
Definition: sonic.c:82
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2333
This structure describes decoded (raw) audio or video data.
Definition: frame.h:187
AVOption.
Definition: opt.h:246
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:361
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2373
Main libavfilter public API header.
const char * desc
Definition: nvenc.c:60
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
Definition: framesync.h:175
static const AVOption premultiply_options[]
static int filter_frame(AVFilterLink *inlink, AVFrame *buf)
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:367
static void premultiply16(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
static void premultiply8(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:80
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
int is_disabled
the enabled state from the last expression evaluation
Definition: avfilter.h:370
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
AVFILTER_DEFINE_CLASS(premultiply)
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:93
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:333
const char * name
Pad name.
Definition: internal.h:60
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:334
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:331
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1125
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
AVOptions.
void * parent
Definition: framesync.h:155
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:271
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:206
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:366
static int flags
Definition: log.c:57
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:364
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:98
Input stream structure.
Definition: framesync.h:83
AVFilter ff_vf_premultiply
#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_framesync_filter_frame(FFFrameSync *fs, AVFilterLink *inlink, AVFrame *in)
Accept a frame on a filter input.
Definition: framesync.c:303
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:330
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:99
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:568
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:269
Frame sync structure.
Definition: framesync.h:153
#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
void(* premultiply[4])(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
void * priv
private data for use by the filter
Definition: avfilter.h:338
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:423
static int request_frame(AVFilterLink *outlink)
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:103
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:354
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:370
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:335
int ff_framesync_request_frame(FFFrameSync *fs, AVFilterLink *outlink)
Request a frame on the filter output.
Definition: framesync.c:317
typedef void(APIENTRY *FF_PFNGLACTIVETEXTUREPROC)(GLenum texture)
AVFormatContext * ctx
Definition: movenc.c:48
AVRational time_base
Time base for the output events.
Definition: framesync.h:165
static const AVFilterPad premultiply_outputs[]
static av_cold void uninit(AVFilterContext *ctx)
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:180
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:350
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:369
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:485
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:476
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
Extend the frame to infinity.
Definition: framesync.h:77
static int process_frame(FFFrameSync *fs)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:218
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
static int query_formats(AVFilterContext *ctx)
void * buf
Definition: avisynth_c.h:690
int ff_framesync_init(FFFrameSync *fs, void *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:52
unsigned sync
Synchronization level: frames on input at the highest sync level will generate output frame events...
Definition: framesync.h:146
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
static void premultiply16yuv(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
static int config_output(AVFilterLink *outlink)
const char * name
Filter name.
Definition: avfilter.h:148
#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:335
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
static void premultiply16offset(const uint8_t *mmsrc, const uint8_t *aasrc, uint8_t *ddst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:368
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:358
static int config_input(AVFilterLink *inlink)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:201
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:475
static void premultiply8offset(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
Y , 8bpp.
Definition: pixfmt.h:70
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
Completely stop all streams with this one.
Definition: framesync.h:67
An instance of a filter.
Definition: avfilter.h:323
static void premultiply8yuv(const uint8_t *msrc, const uint8_t *asrc, uint8_t *dst, ptrdiff_t mlinesize, ptrdiff_t alinesize, ptrdiff_t dlinesize, int w, int h, int half, int shift, int offset)
FILE * out
Definition: movenc.c:54
static const AVFilterPad premultiply_inputs[]
internal API functions
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
Definition: framesync.c:232
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:596
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58