FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_mergeplanes.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 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/avassert.h"
22 #include "libavutil/avstring.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/pixdesc.h"
26 #include "avfilter.h"
27 #include "internal.h"
28 #include "framesync.h"
29 
30 typedef struct InputParam {
31  int depth[4];
32  int nb_planes;
33  int planewidth[4];
34  int planeheight[4];
35 } InputParam;
36 
37 typedef struct MergePlanesContext {
38  const AVClass *class;
39  int64_t mapping;
40  const enum AVPixelFormat out_fmt;
41  int nb_inputs;
42  int nb_planes;
43  int planewidth[4];
44  int planeheight[4];
45  int map[4][2];
47 
50 
51 #define OFFSET(x) offsetof(MergePlanesContext, x)
52 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
53 static const AVOption mergeplanes_options[] = {
54  { "mapping", "set input to output plane mapping", OFFSET(mapping), AV_OPT_TYPE_INT, {.i64=0}, 0, 0x33333333, FLAGS },
55  { "format", "set output pixel format", OFFSET(out_fmt), AV_OPT_TYPE_PIXEL_FMT, {.i64=AV_PIX_FMT_YUVA444P}, 0, INT_MAX, .flags=FLAGS },
56  { NULL }
57 };
58 
59 AVFILTER_DEFINE_CLASS(mergeplanes);
60 
61 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
62 {
63  MergePlanesContext *s = inlink->dst->priv;
64  return ff_framesync_filter_frame(&s->fs, inlink, in);
65 }
66 
67 static av_cold int init(AVFilterContext *ctx)
68 {
69  MergePlanesContext *s = ctx->priv;
70  int64_t m = s->mapping;
71  int i, ret;
72 
74  if (!(s->outdesc->flags & AV_PIX_FMT_FLAG_PLANAR) ||
75  s->outdesc->nb_components < 2) {
76  av_log(ctx, AV_LOG_ERROR, "Only planar formats with more than one component are supported.\n");
77  return AVERROR(EINVAL);
78  }
80 
81  for (i = s->nb_planes - 1; i >= 0; i--) {
82  s->map[i][0] = m & 0xf;
83  m >>= 4;
84  s->map[i][1] = m & 0xf;
85  m >>= 4;
86 
87  if (s->map[i][0] > 3 || s->map[i][1] > 3) {
88  av_log(ctx, AV_LOG_ERROR, "Mapping with out of range input and/or plane number.\n");
89  return AVERROR(EINVAL);
90  }
91 
92  s->nb_inputs = FFMAX(s->nb_inputs, s->map[i][1] + 1);
93  }
94 
95  av_assert0(s->nb_inputs && s->nb_inputs <= 4);
96 
97  for (i = 0; i < s->nb_inputs; i++) {
98  AVFilterPad pad = { 0 };
99 
100  pad.type = AVMEDIA_TYPE_VIDEO;
101  pad.name = av_asprintf("in%d", i);
102  if (!pad.name)
103  return AVERROR(ENOMEM);
105 
106  if ((ret = ff_insert_inpad(ctx, i, &pad)) < 0){
107  av_freep(&pad.name);
108  return ret;
109  }
110  }
111 
112  return 0;
113 }
114 
116 {
117  MergePlanesContext *s = ctx->priv;
119  int i;
120 
122  for (i = 0; av_pix_fmt_desc_get(i); i++) {
123  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
124  if (desc->comp[0].depth_minus1 == s->outdesc->comp[0].depth_minus1 &&
126  ff_add_format(&formats, i);
127  }
128 
129  for (i = 0; i < s->nb_inputs; i++)
130  ff_formats_ref(formats, &ctx->inputs[i]->out_formats);
131 
132  formats = NULL;
133  ff_add_format(&formats, s->out_fmt);
134  ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
135 
136  return 0;
137 }
138 
139 static int process_frame(FFFrameSync *fs)
140 {
141  AVFilterContext *ctx = fs->parent;
142  AVFilterLink *outlink = ctx->outputs[0];
143  MergePlanesContext *s = fs->opaque;
144  AVFrame *in[4] = { NULL };
145  AVFrame *out;
146  int i, ret;
147 
148  for (i = 0; i < s->nb_inputs; i++) {
149  if ((ret = ff_framesync_get_frame(&s->fs, i, &in[i], 0)) < 0)
150  return ret;
151  }
152 
153  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
154  if (!out)
155  return AVERROR(ENOMEM);
156  out->pts = av_rescale_q(s->fs.pts, s->fs.time_base, outlink->time_base);
157 
158  for (i = 0; i < s->nb_planes; i++) {
159  const int input = s->map[i][1];
160  const int plane = s->map[i][0];
161 
162  av_image_copy_plane(out->data[i], out->linesize[i],
163  in[input]->data[plane], in[input]->linesize[plane],
164  s->planewidth[i], s->planeheight[i]);
165  }
166 
167  return ff_filter_frame(outlink, out);
168 }
169 
170 static int config_output(AVFilterLink *outlink)
171 {
172  AVFilterContext *ctx = outlink->src;
173  MergePlanesContext *s = ctx->priv;
174  InputParam inputsp[4];
175  FFFrameSyncIn *in;
176  int i, ret;
177 
178  if ((ret = ff_framesync_init(&s->fs, ctx, s->nb_inputs)) < 0)
179  return ret;
180 
181  in = s->fs.in;
182  s->fs.opaque = s;
184 
185  outlink->w = ctx->inputs[0]->w;
186  outlink->h = ctx->inputs[0]->h;
187  outlink->time_base = ctx->inputs[0]->time_base;
188  outlink->frame_rate = ctx->inputs[0]->frame_rate;
189  outlink->sample_aspect_ratio = ctx->inputs[0]->sample_aspect_ratio;
190 
191  s->planewidth[1] =
192  s->planewidth[2] = FF_CEIL_RSHIFT(outlink->w, s->outdesc->log2_chroma_w);
193  s->planewidth[0] =
194  s->planewidth[3] = outlink->w;
195  s->planeheight[1] =
196  s->planeheight[2] = FF_CEIL_RSHIFT(outlink->h, s->outdesc->log2_chroma_h);
197  s->planeheight[0] =
198  s->planeheight[3] = outlink->h;
199 
200  for (i = 0; i < s->nb_inputs; i++) {
201  InputParam *inputp = &inputsp[i];
202  AVFilterLink *inlink = ctx->inputs[i];
203  const AVPixFmtDescriptor *indesc = av_pix_fmt_desc_get(inlink->format);
204  int j;
205 
206  if (outlink->sample_aspect_ratio.num != inlink->sample_aspect_ratio.num ||
207  outlink->sample_aspect_ratio.den != inlink->sample_aspect_ratio.den) {
208  av_log(ctx, AV_LOG_ERROR, "input #%d link %s SAR %d:%d "
209  "does not match output link %s SAR %d:%d\n",
210  i, ctx->input_pads[i].name,
211  inlink->sample_aspect_ratio.num,
212  inlink->sample_aspect_ratio.den,
213  ctx->output_pads[0].name,
214  outlink->sample_aspect_ratio.num,
215  outlink->sample_aspect_ratio.den);
216  return AVERROR(EINVAL);
217  }
218 
219  inputp->planewidth[1] =
220  inputp->planewidth[2] = FF_CEIL_RSHIFT(inlink->w, indesc->log2_chroma_w);
221  inputp->planewidth[0] =
222  inputp->planewidth[3] = inlink->w;
223  inputp->planeheight[1] =
224  inputp->planeheight[2] = FF_CEIL_RSHIFT(inlink->h, indesc->log2_chroma_h);
225  inputp->planeheight[0] =
226  inputp->planeheight[3] = inlink->h;
227  inputp->nb_planes = av_pix_fmt_count_planes(inlink->format);
228 
229  for (j = 0; j < inputp->nb_planes; j++)
230  inputp->depth[j] = indesc->comp[j].depth_minus1 + 1;
231 
232  in[i].time_base = inlink->time_base;
233  in[i].sync = 1;
234  in[i].before = EXT_STOP;
235  in[i].after = EXT_STOP;
236  }
237 
238  for (i = 0; i < s->nb_planes; i++) {
239  const int input = s->map[i][1];
240  const int plane = s->map[i][0];
241  InputParam *inputp = &inputsp[input];
242 
243  if (plane + 1 > inputp->nb_planes) {
244  av_log(ctx, AV_LOG_ERROR, "input %d does not have %d plane\n",
245  input, plane);
246  goto fail;
247  }
248  if (s->outdesc->comp[i].depth_minus1 + 1 != inputp->depth[plane]) {
249  av_log(ctx, AV_LOG_ERROR, "output plane %d depth %d does not "
250  "match input %d plane %d depth %d\n",
251  i, s->outdesc->comp[i].depth_minus1 + 1,
252  input, plane, inputp->depth[plane]);
253  goto fail;
254  }
255  if (s->planewidth[i] != inputp->planewidth[plane]) {
256  av_log(ctx, AV_LOG_ERROR, "output plane %d width %d does not "
257  "match input %d plane %d width %d\n",
258  i, s->planewidth[i],
259  input, plane, inputp->planewidth[plane]);
260  goto fail;
261  }
262  if (s->planeheight[i] != inputp->planeheight[plane]) {
263  av_log(ctx, AV_LOG_ERROR, "output plane %d height %d does not "
264  "match input %d plane %d height %d\n",
265  i, s->planeheight[i],
266  input, plane, inputp->planeheight[plane]);
267  goto fail;
268  }
269  }
270 
271  return ff_framesync_configure(&s->fs);
272 fail:
273  return AVERROR(EINVAL);
274 }
275 
276 static int request_frame(AVFilterLink *outlink)
277 {
278  MergePlanesContext *s = outlink->src->priv;
279  return ff_framesync_request_frame(&s->fs, outlink);
280 }
281 
282 static av_cold void uninit(AVFilterContext *ctx)
283 {
284  MergePlanesContext *s = ctx->priv;
285  int i;
286 
287  ff_framesync_uninit(&s->fs);
288 
289  for (i = 0; i < ctx->nb_inputs; i++)
290  av_freep(&ctx->input_pads[i].name);
291 }
292 
294  {
295  .name = "default",
296  .type = AVMEDIA_TYPE_VIDEO,
297  .config_props = config_output,
298  .request_frame = request_frame,
299  },
300  { NULL }
301 };
302 
304  .name = "mergeplanes",
305  .description = NULL_IF_CONFIG_SMALL("Merge planes."),
306  .priv_size = sizeof(MergePlanesContext),
307  .priv_class = &mergeplanes_class,
308  .init = init,
309  .uninit = uninit,
311  .inputs = NULL,
312  .outputs = mergeplanes_outputs,
314 };
static int config_output(AVFilterLink *outlink)
int plane
Definition: avisynth_c.h:291
static int request_frame(AVFilterLink *outlink)
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2129
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
static const AVOption mergeplanes_options[]
AVOption.
Definition: opt.h:255
static av_cold int init(AVFilterContext *ctx)
static int query_formats(AVFilterContext *ctx)
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2169
Main libavfilter public API header.
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
Definition: framesync.h:175
#define AVFILTER_FLAG_DYNAMIC_INPUTS
The number of the filter inputs is not determined just by AVFilter.inputs.
Definition: avfilter.h:431
int planeheight[4]
int num
numerator
Definition: rational.h:44
AVFilter ff_vf_mergeplanes
enum AVMediaType type
AVFilterPad type.
Definition: internal.h:74
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
Definition: framesync.c:77
static enum AVSampleFormat formats[]
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
int64_t pts
Timestamp of the current event.
Definition: framesync.h:170
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
enum FFFrameSyncExtMode before
Extrapolation mode for timestamps before the first frame.
Definition: framesync.h:93
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
const char * name
Pad name.
Definition: internal.h:69
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:641
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
AVFilterPad * output_pads
array of output pads
Definition: avfilter.h:647
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:100
#define av_cold
Definition: attributes.h:74
enum AVPixelFormat out_fmt
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:257
int planewidth[4]
FFFrameSyncIn * in
Pointer to array of inputs.
Definition: framesync.h:206
enum FFFrameSyncExtMode after
Extrapolation mode for timestamps after the last frame.
Definition: framesync.h:98
Input stream structure.
Definition: framesync.h:83
#define av_log(a,...)
unsigned m
Definition: audioconvert.c:187
#define OFFSET(x)
A filter pad used for either input or output.
Definition: internal.h:63
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
int ff_framesync_filter_frame(FFFrameSync *fs, AVFilterLink *inlink, AVFrame *in)
Accept a frame on a filter input.
Definition: framesync.c:300
AVFilterPad * input_pads
array of input pads
Definition: avfilter.h:640
uint16_t depth_minus1
Number of bits in the component minus 1.
Definition: pixdesc.h:57
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
Definition: framesync.c:266
static av_cold void uninit(AVFilterContext *ctx)
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:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
int(* filter_frame)(AVFilterLink *link, AVFrame *frame)
Filtering callback.
Definition: internal.h:102
simple assert() macros that are a bit more flexible than ISO C assert().
AVRational time_base
Time base for the incoming frames.
Definition: framesync.h:103
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:323
#define FFMAX(a, b)
Definition: common.h:79
#define fail()
Definition: checkasm.h:57
char * av_asprintf(const char *fmt,...)
Definition: avstring.c:113
const AVPixFmtDescriptor * outdesc
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
unsigned nb_inputs
number of input pads
Definition: avfilter.h:645
int ff_framesync_request_frame(FFFrameSync *fs, AVFilterLink *outlink)
Request a frame on the filter output.
Definition: framesync.c:314
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
Add *ref as a new reference to formats.
Definition: formats.c:422
#define FLAGS
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
AVRational time_base
Time base for the output events.
Definition: framesync.h:165
void * opaque
Opaque pointer, not used by the API.
Definition: framesync.h:180
int depth[4]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
static int process_frame(FFFrameSync *fs)
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:280
uint8_t flags
Definition: pixdesc.h:90
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
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
int ff_framesync_init(FFFrameSync *fs, void *parent, unsigned nb_in)
Initialize a frame sync structure.
Definition: framesync.c:49
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:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
const char * name
Filter name.
Definition: avfilter.h:474
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static int flags
Definition: cpu.c:47
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
static const AVFilterPad mergeplanes_outputs[]
AVFILTER_DEFINE_CLASS(mergeplanes)
int den
denominator
Definition: rational.h:45
Completely stop all streams with this one.
Definition: framesync.h:67
A list of supported formats for one end of a filter link.
Definition: formats.h:64
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-> out
An instance of a filter.
Definition: avfilter.h:633
#define av_freep(p)
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:273
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:229
AVPixelFormat
Pixel format.
Definition: pixfmt.h:61
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:127
static int ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p)
Insert a new input pad for the filter.
Definition: internal.h:271