FFmpeg  2.1.1
vf_tinterlace.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011 Stefano Sabatini
3  * Copyright (c) 2010 Baptiste Coudurier
4  * Copyright (c) 2003 Michael Zucchi <notzed@ximian.com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with FFmpeg if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 /**
24  * @file
25  * temporal field interlace filter, ported from MPlayer/libmpcodecs
26  */
27 
28 #include "libavutil/opt.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/avassert.h"
31 #include "avfilter.h"
32 #include "internal.h"
33 
43 };
44 
45 typedef struct {
46  const AVClass *class;
47  enum TInterlaceMode mode; ///< interlace mode selected
48  int flags; ///< flags affecting interlacing algorithm
49  int frame; ///< number of the output frame
50  int vsub; ///< chroma vertical subsampling
53  uint8_t *black_data[4]; ///< buffer used to fill padded lines
54  int black_linesize[4];
56 
57 #define OFFSET(x) offsetof(TInterlaceContext, x)
58 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
59 #define TINTERLACE_FLAG_VLPF 01
60 
61 static const AVOption tinterlace_options[] = {
62  {"mode", "select interlace mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_MERGE}, 0, MODE_NB-1, FLAGS, "mode"},
63  {"merge", "merge fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_MERGE}, INT_MIN, INT_MAX, FLAGS, "mode"},
64  {"drop_even", "drop even fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_DROP_EVEN}, INT_MIN, INT_MAX, FLAGS, "mode"},
65  {"drop_odd", "drop odd fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_DROP_ODD}, INT_MIN, INT_MAX, FLAGS, "mode"},
66  {"pad", "pad alternate lines with black", 0, AV_OPT_TYPE_CONST, {.i64=MODE_PAD}, INT_MIN, INT_MAX, FLAGS, "mode"},
67  {"interleave_top", "interleave top and bottom fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE_TOP}, INT_MIN, INT_MAX, FLAGS, "mode"},
68  {"interleave_bottom", "interleave bottom and top fields", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLEAVE_BOTTOM}, INT_MIN, INT_MAX, FLAGS, "mode"},
69  {"interlacex2", "interlace fields from two consecutive frames", 0, AV_OPT_TYPE_CONST, {.i64=MODE_INTERLACEX2}, INT_MIN, INT_MAX, FLAGS, "mode"},
70 
71  {"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, INT_MAX, 0, "flags" },
72  {"low_pass_filter", "enable vertical low-pass filter", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, "flags" },
73  {"vlpf", "enable vertical low-pass filter", 0, AV_OPT_TYPE_CONST, {.i64 = TINTERLACE_FLAG_VLPF}, INT_MIN, INT_MAX, FLAGS, "flags" },
74 
75  {NULL}
76 };
77 
78 AVFILTER_DEFINE_CLASS(tinterlace);
79 
80 #define FULL_SCALE_YUVJ_FORMATS \
81  AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P
82 
85 };
86 
88 {
89  static const enum AVPixelFormat pix_fmts[] = {
96  };
97 
99  return 0;
100 }
101 
102 static av_cold void uninit(AVFilterContext *ctx)
103 {
104  TInterlaceContext *tinterlace = ctx->priv;
105 
106  av_frame_free(&tinterlace->cur );
107  av_frame_free(&tinterlace->next);
108  av_freep(&tinterlace->black_data[0]);
109 }
110 
111 static int config_out_props(AVFilterLink *outlink)
112 {
113  AVFilterContext *ctx = outlink->src;
114  AVFilterLink *inlink = outlink->src->inputs[0];
115  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(outlink->format);
116  TInterlaceContext *tinterlace = ctx->priv;
117 
118  tinterlace->vsub = desc->log2_chroma_h;
119  outlink->flags |= FF_LINK_FLAG_REQUEST_LOOP;
120  outlink->w = inlink->w;
121  outlink->h = tinterlace->mode == MODE_MERGE || tinterlace->mode == MODE_PAD ?
122  inlink->h*2 : inlink->h;
123 
124  if (tinterlace->mode == MODE_PAD) {
125  uint8_t black[4] = { 16, 128, 128, 16 };
126  int i, ret;
128  black[0] = black[3] = 0;
129  ret = av_image_alloc(tinterlace->black_data, tinterlace->black_linesize,
130  outlink->w, outlink->h, outlink->format, 1);
131  if (ret < 0)
132  return ret;
133 
134  /* fill black picture with black */
135  for (i = 0; i < 4 && tinterlace->black_data[i]; i++) {
136  int h = i == 1 || i == 2 ? FF_CEIL_RSHIFT(outlink->h, desc->log2_chroma_h) : outlink->h;
137  memset(tinterlace->black_data[i], black[i],
138  tinterlace->black_linesize[i] * h);
139  }
140  }
141  if ((tinterlace->flags & TINTERLACE_FLAG_VLPF)
142  && !(tinterlace->mode == MODE_INTERLEAVE_TOP
143  || tinterlace->mode == MODE_INTERLEAVE_BOTTOM)) {
144  av_log(ctx, AV_LOG_WARNING, "low_pass_filter flag ignored with mode %d\n",
145  tinterlace->mode);
146  tinterlace->flags &= ~TINTERLACE_FLAG_VLPF;
147  }
148  av_log(ctx, AV_LOG_VERBOSE, "mode:%d filter:%s h:%d -> h:%d\n",
149  tinterlace->mode, (tinterlace->flags & TINTERLACE_FLAG_VLPF) ? "on" : "off",
150  inlink->h, outlink->h);
151 
152  return 0;
153 }
154 
155 #define FIELD_UPPER 0
156 #define FIELD_LOWER 1
157 #define FIELD_UPPER_AND_LOWER 2
158 
159 /**
160  * Copy picture field from src to dst.
161  *
162  * @param src_field copy from upper, lower field or both
163  * @param interleave leave a padding line between each copied line
164  * @param dst_field copy to upper or lower field,
165  * only meaningful when interleave is selected
166  * @param flags context flags
167  */
168 static inline
169 void copy_picture_field(uint8_t *dst[4], int dst_linesize[4],
170  const uint8_t *src[4], int src_linesize[4],
171  enum AVPixelFormat format, int w, int src_h,
172  int src_field, int interleave, int dst_field,
173  int flags)
174 {
175  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(format);
176  int plane, vsub = desc->log2_chroma_h;
177  int k = src_field == FIELD_UPPER_AND_LOWER ? 1 : 2;
178  int h, i;
179 
180  for (plane = 0; plane < desc->nb_components; plane++) {
181  int lines = plane == 1 || plane == 2 ? FF_CEIL_RSHIFT(src_h, vsub) : src_h;
182  int linesize = av_image_get_linesize(format, w, plane);
183  uint8_t *dstp = dst[plane];
184  const uint8_t *srcp = src[plane];
185 
186  if (linesize < 0)
187  return;
188 
189  lines = (lines + (src_field == FIELD_UPPER)) / k;
190  if (src_field == FIELD_LOWER)
191  srcp += src_linesize[plane];
192  if (interleave && dst_field == FIELD_LOWER)
193  dstp += dst_linesize[plane];
194  if (flags & TINTERLACE_FLAG_VLPF) {
195  // Low-pass filtering is required when creating an interlaced destination from
196  // a progressive source which contains high-frequency vertical detail.
197  // Filtering will reduce interlace 'twitter' and Moire patterning.
198  int srcp_linesize = src_linesize[plane] * k;
199  int dstp_linesize = dst_linesize[plane] * (interleave ? 2 : 1);
200  for (h = lines; h > 0; h--) {
201  const uint8_t *srcp_above = srcp - src_linesize[plane];
202  const uint8_t *srcp_below = srcp + src_linesize[plane];
203  if (h == lines) srcp_above = srcp; // there is no line above
204  if (h == 1) srcp_below = srcp; // there is no line below
205  for (i = 0; i < linesize; i++) {
206  // this calculation is an integer representation of
207  // '0.5 * current + 0.25 * above + 0.25 * below'
208  // '1 +' is for rounding. */
209  dstp[i] = (1 + srcp[i] + srcp[i] + srcp_above[i] + srcp_below[i]) >> 2;
210  }
211  dstp += dstp_linesize;
212  srcp += srcp_linesize;
213  }
214  } else {
215  av_image_copy_plane(dstp, dst_linesize[plane] * (interleave ? 2 : 1),
216  srcp, src_linesize[plane]*k, linesize, lines);
217  }
218  }
219 }
220 
221 static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
222 {
223  AVFilterContext *ctx = inlink->dst;
224  AVFilterLink *outlink = ctx->outputs[0];
225  TInterlaceContext *tinterlace = ctx->priv;
226  AVFrame *cur, *next, *out;
227  int field, tff, ret;
228 
229  av_frame_free(&tinterlace->cur);
230  tinterlace->cur = tinterlace->next;
231  tinterlace->next = picref;
232 
233  cur = tinterlace->cur;
234  next = tinterlace->next;
235  /* we need at least two frames */
236  if (!tinterlace->cur)
237  return 0;
238 
239  switch (tinterlace->mode) {
240  case MODE_MERGE: /* move the odd frame into the upper field of the new image, even into
241  * the lower field, generating a double-height video at half framerate */
242  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
243  if (!out)
244  return AVERROR(ENOMEM);
245  av_frame_copy_props(out, cur);
246  out->height = outlink->h;
247  out->interlaced_frame = 1;
248  out->top_field_first = 1;
249 
250  /* write odd frame lines into the upper field of the new frame */
251  copy_picture_field(out->data, out->linesize,
252  (const uint8_t **)cur->data, cur->linesize,
253  inlink->format, inlink->w, inlink->h,
254  FIELD_UPPER_AND_LOWER, 1, FIELD_UPPER, tinterlace->flags);
255  /* write even frame lines into the lower field of the new frame */
256  copy_picture_field(out->data, out->linesize,
257  (const uint8_t **)next->data, next->linesize,
258  inlink->format, inlink->w, inlink->h,
259  FIELD_UPPER_AND_LOWER, 1, FIELD_LOWER, tinterlace->flags);
260  av_frame_free(&tinterlace->next);
261  break;
262 
263  case MODE_DROP_ODD: /* only output even frames, odd frames are dropped; height unchanged, half framerate */
264  case MODE_DROP_EVEN: /* only output odd frames, even frames are dropped; height unchanged, half framerate */
265  out = av_frame_clone(tinterlace->mode == MODE_DROP_EVEN ? cur : next);
266  av_frame_free(&tinterlace->next);
267  break;
268 
269  case MODE_PAD: /* expand each frame to double height, but pad alternate
270  * lines with black; framerate unchanged */
271  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
272  if (!out)
273  return AVERROR(ENOMEM);
274  av_frame_copy_props(out, cur);
275  out->height = outlink->h;
276 
277  field = (1 + tinterlace->frame) & 1 ? FIELD_UPPER : FIELD_LOWER;
278  /* copy upper and lower fields */
279  copy_picture_field(out->data, out->linesize,
280  (const uint8_t **)cur->data, cur->linesize,
281  inlink->format, inlink->w, inlink->h,
282  FIELD_UPPER_AND_LOWER, 1, field, tinterlace->flags);
283  /* pad with black the other field */
284  copy_picture_field(out->data, out->linesize,
285  (const uint8_t **)tinterlace->black_data, tinterlace->black_linesize,
286  inlink->format, inlink->w, inlink->h,
287  FIELD_UPPER_AND_LOWER, 1, !field, tinterlace->flags);
288  break;
289 
290  /* interleave upper/lower lines from odd frames with lower/upper lines from even frames,
291  * halving the frame rate and preserving image height */
292  case MODE_INTERLEAVE_TOP: /* top field first */
293  case MODE_INTERLEAVE_BOTTOM: /* bottom field first */
294  tff = tinterlace->mode == MODE_INTERLEAVE_TOP;
295  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
296  if (!out)
297  return AVERROR(ENOMEM);
298  av_frame_copy_props(out, cur);
299  out->interlaced_frame = 1;
300  out->top_field_first = tff;
301 
302  /* copy upper/lower field from cur */
303  copy_picture_field(out->data, out->linesize,
304  (const uint8_t **)cur->data, cur->linesize,
305  inlink->format, inlink->w, inlink->h,
306  tff ? FIELD_UPPER : FIELD_LOWER, 1, tff ? FIELD_UPPER : FIELD_LOWER,
307  tinterlace->flags);
308  /* copy lower/upper field from next */
309  copy_picture_field(out->data, out->linesize,
310  (const uint8_t **)next->data, next->linesize,
311  inlink->format, inlink->w, inlink->h,
312  tff ? FIELD_LOWER : FIELD_UPPER, 1, tff ? FIELD_LOWER : FIELD_UPPER,
313  tinterlace->flags);
314  av_frame_free(&tinterlace->next);
315  break;
316  case MODE_INTERLACEX2: /* re-interlace preserving image height, double frame rate */
317  /* output current frame first */
318  out = av_frame_clone(cur);
319  if (!out)
320  return AVERROR(ENOMEM);
321  out->interlaced_frame = 1;
322 
323  if ((ret = ff_filter_frame(outlink, out)) < 0)
324  return ret;
325 
326  /* output mix of current and next frame */
327  tff = next->top_field_first;
328  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
329  if (!out)
330  return AVERROR(ENOMEM);
331  av_frame_copy_props(out, next);
332  out->interlaced_frame = 1;
333 
334  /* write current frame second field lines into the second field of the new frame */
335  copy_picture_field(out->data, out->linesize,
336  (const uint8_t **)cur->data, cur->linesize,
337  inlink->format, inlink->w, inlink->h,
338  tff ? FIELD_LOWER : FIELD_UPPER, 1, tff ? FIELD_LOWER : FIELD_UPPER,
339  tinterlace->flags);
340  /* write next frame first field lines into the first field of the new frame */
341  copy_picture_field(out->data, out->linesize,
342  (const uint8_t **)next->data, next->linesize,
343  inlink->format, inlink->w, inlink->h,
344  tff ? FIELD_UPPER : FIELD_LOWER, 1, tff ? FIELD_UPPER : FIELD_LOWER,
345  tinterlace->flags);
346  break;
347  default:
348  av_assert0(0);
349  }
350 
351  ret = ff_filter_frame(outlink, out);
352  tinterlace->frame++;
353 
354  return ret;
355 }
356 
357 static const AVFilterPad tinterlace_inputs[] = {
358  {
359  .name = "default",
360  .type = AVMEDIA_TYPE_VIDEO,
361  .filter_frame = filter_frame,
362  },
363  { NULL }
364 };
365 
366 static const AVFilterPad tinterlace_outputs[] = {
367  {
368  .name = "default",
369  .type = AVMEDIA_TYPE_VIDEO,
370  .config_props = config_out_props,
371  },
372  { NULL }
373 };
374 
376  .name = "tinterlace",
377  .description = NULL_IF_CONFIG_SMALL("Perform temporal field interlacing."),
378  .priv_size = sizeof(TInterlaceContext),
379  .uninit = uninit,
381  .inputs = tinterlace_inputs,
382  .outputs = tinterlace_outputs,
383  .priv_class = &tinterlace_class,
384 };
int av_image_get_linesize(enum AVPixelFormat pix_fmt, int width, int plane)
Compute the size of an image line with format pix_fmt and width width for the plane plane...
Definition: imgutils.c:73
static enum AVPixelFormat full_scale_yuvj_pix_fmts[]
Definition: vf_tinterlace.c:83
static int query_formats(AVFilterContext *ctx)
Definition: vf_tinterlace.c:87
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
#define OFFSET(x)
Definition: vf_tinterlace.c:57
AVOption.
Definition: opt.h:253
const char * name
Filter name.
Definition: avfilter.h:468
void * priv
private data for use by the filter
Definition: avfilter.h:648
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: avcodec.h:4153
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
int av_image_alloc(uint8_t *pointers[4], int linesizes[4], int w, int h, enum AVPixelFormat pix_fmt, int align)
Allocate an image with size w and h and pixel format pix_fmt, and fill pointers and linesizes accordi...
Definition: imgutils.c:190
planar YUV 4:2:2, 16bpp, (1 Cr &amp; Cb sample per 2x1 Y samples)
Definition: avcodec.h:4538
#define FIELD_LOWER
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static av_always_inline void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift)
Definition: dirac_dwt.c:51
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
planar YUV 4:4:4 32bpp, (1 Cr &amp; Cb sample per 1x1 Y &amp; A samples)
Definition: avcodec.h:4693
Pixel format.
Definition: avcodec.h:4533
#define av_cold
Definition: avcodec.h:653
Y , 8bpp.
Definition: avcodec.h:4542
int flags
flags affecting interlacing algorithm
Definition: vf_tinterlace.c:48
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:234
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:294
#define FULL_SCALE_YUVJ_FORMATS
Definition: vf_tinterlace.c:80
BYTE int const BYTE * srcp
Definition: avisynth_c.h:713
const char * name
Pad name.
Definition: internal.h:66
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1118
uint8_t
static const AVOption tinterlace_options[]
Definition: vf_tinterlace.c:61
mode
Definition: f_perms.c:27
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only &quot;metadata&quot; fields from src to dst.
Definition: frame.c:446
int frame
number of the output frame
Definition: vf_tinterlace.c:49
#define FF_CEIL_RSHIFT(a, b)
Definition: avcodec.h:916
TInterlaceMode
Definition: vf_tinterlace.c:34
planar YUV 4:2:2 24bpp, (1 Cr &amp; Cb sample per 2x1 Y &amp; A samples)
Definition: avcodec.h:4694
#define AV_LOG_VERBOSE
Detailed information.
Definition: avcodec.h:4163
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:293
planar YUV 4:2:0, 20bpp, (1 Cr &amp; Cb sample per 2x2 Y &amp; A samples)
Definition: avcodec.h:4571
void 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:531
int ff_fmt_is_in(int fmt, const int *fmts)
Tell is a format is contained in the provided list terminated by -1.
Definition: formats.c:254
A filter pad used for either input or output.
Definition: internal.h:60
Frame requests may need to loop in order to be fulfilled.
Definition: internal.h:347
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:77
int vsub
chroma vertical subsampling
Definition: vf_tinterlace.c:50
BYTE * dstp
Definition: avisynth_c.h:713
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
#define FLAGS
Definition: vf_tinterlace.c:58
planar YUV 4:1:1, 12bpp, (1 Cr &amp; Cb sample per 4x1 Y samples)
Definition: avcodec.h:4541
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:59
#define FIELD_UPPER
static av_cold void uninit(AVFilterContext *ctx)
ret
Definition: avfilter.c:961
enum TInterlaceMode mode
interlace mode selected
Definition: vf_tinterlace.c:47
static const AVFilterPad tinterlace_outputs[]
static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
planar YUV 4:2:0, 12bpp, (1 Cr &amp; Cb sample per 2x2 Y samples)
Definition: avcodec.h:4534
planar YUV 4:4:0 (1 Cr &amp; Cb sample per 1x2 Y samples)
Definition: avcodec.h:4569
AVS_Value src
Definition: avisynth_c.h:523
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
uint8_t * black_data[4]
buffer used to fill padded lines
Definition: vf_tinterlace.c:53
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:464
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:635
planar YUV 4:4:4, 24bpp, (1 Cr &amp; Cb sample per 1x1 Y samples)
Definition: avcodec.h:4539
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
static const AVFilterPad tinterlace_inputs[]
static int flags
Definition: cpu.c:45
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:338
static int config_out_props(AVFilterLink *outlink)
static void copy_picture_field(uint8_t *dst[4], int dst_linesize[4], const uint8_t *src[4], int src_linesize[4], enum AVPixelFormat format, int w, int src_h, int src_field, int interleave, int dst_field, int flags)
Copy picture field from src to dst.
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:298
AVFilter avfilter_vf_tinterlace
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){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));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=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);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);ff_audio_convert_init_arm(ac);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_dlog(ac->avr,"%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-> out
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:301
#define AVERROR(e)
An instance of a filter.
Definition: avfilter.h:627
int height
Definition: frame.h:145
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
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:242
internal API functions
#define FIELD_UPPER_AND_LOWER
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
planar YUV 4:1:0, 9bpp, (1 Cr &amp; Cb sample per 4x4 Y samples)
Definition: avcodec.h:4540
#define TINTERLACE_FLAG_VLPF
Definition: vf_tinterlace.c:59