FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_transpose_npp.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include <nppi.h>
20 #include <stdio.h>
21 #include <string.h>
22 
23 #include "libavutil/common.h"
24 #include "libavutil/hwcontext.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/opt.h"
28 #include "libavutil/pixdesc.h"
29 
30 #include "avfilter.h"
31 #include "formats.h"
32 #include "internal.h"
33 #include "video.h"
34 
35 static const enum AVPixelFormat supported_formats[] = {
38 };
39 
44 };
45 
46 enum Transpose {
51 };
52 
57 };
58 
59 typedef struct NPPTransposeStageContext {
63  struct {
64  int width;
65  int height;
66  } planes_in[3], planes_out[3];
70 
71 typedef struct NPPTransposeContext {
72  const AVClass *class;
75 
76  int passthrough; ///< PassthroughType, landscape passthrough mode enabled
77  int dir; ///< TransposeDir
79 
81 {
82  NPPTransposeContext *s = ctx->priv;
83  int i;
84 
85  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
86  s->stages[i].frame = av_frame_alloc();
87  if (!s->stages[i].frame)
88  return AVERROR(ENOMEM);
89  }
90 
92  if (!s->tmp_frame)
93  return AVERROR(ENOMEM);
94 
95  return 0;
96 }
97 
99 {
100  NPPTransposeContext *s = ctx->priv;
101  int i;
102 
103  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
104  av_frame_free(&s->stages[i].frame);
106  }
107 
109 }
110 
112 {
113  static const enum AVPixelFormat pixel_formats[] = {
115  };
116 
117  AVFilterFormats *pix_fmts = ff_make_format_list(pixel_formats);
118  return ff_set_common_formats(ctx, pix_fmts);
119 }
120 
121 static int init_stage(NPPTransposeStageContext *stage, AVBufferRef *device_ctx)
122 {
123  AVBufferRef *out_ref = NULL;
124  AVHWFramesContext *out_ctx;
125  int in_sw, in_sh, out_sw, out_sh;
126  int ret, i;
127 
128  av_pix_fmt_get_chroma_sub_sample(stage->in_fmt, &in_sw, &in_sh);
129  av_pix_fmt_get_chroma_sub_sample(stage->out_fmt, &out_sw, &out_sh);
130 
131  if (!stage->planes_out[0].width) {
132  stage->planes_out[0].width = stage->planes_in[0].width;
133  stage->planes_out[0].height = stage->planes_in[0].height;
134  }
135 
136  for (i = 1; i < FF_ARRAY_ELEMS(stage->planes_in); i++) {
137  stage->planes_in[i].width = stage->planes_in[0].width >> in_sw;
138  stage->planes_in[i].height = stage->planes_in[0].height >> in_sh;
139  stage->planes_out[i].width = stage->planes_out[0].width >> out_sw;
140  stage->planes_out[i].height = stage->planes_out[0].height >> out_sh;
141  }
142 
143  out_ref = av_hwframe_ctx_alloc(device_ctx);
144  if (!out_ref)
145  return AVERROR(ENOMEM);
146  out_ctx = (AVHWFramesContext*)out_ref->data;
147 
148  out_ctx->format = AV_PIX_FMT_CUDA;
149  out_ctx->sw_format = stage->out_fmt;
150  out_ctx->width = FFALIGN(stage->planes_out[0].width, 32);
151  out_ctx->height = FFALIGN(stage->planes_out[0].height, 32);
152 
153  ret = av_hwframe_ctx_init(out_ref);
154  if (ret < 0)
155  goto fail;
156 
157  av_frame_unref(stage->frame);
158  ret = av_hwframe_get_buffer(out_ref, stage->frame, 0);
159  if (ret < 0)
160  goto fail;
161 
162  stage->frame->width = stage->planes_out[0].width;
163  stage->frame->height = stage->planes_out[0].height;
164  av_buffer_unref(&stage->frames_ctx);
165  stage->frames_ctx = out_ref;
166 
167  return 0;
168 
169 fail:
170  av_buffer_unref(&out_ref);
171  return ret;
172 }
173 
175 {
176  int i;
177 
178  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
179  if (supported_formats[i] == fmt)
180  return 1;
181 
182  return 0;
183 }
184 
185 static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height,
186  int out_width, int out_height)
187 {
188  NPPTransposeContext *s = ctx->priv;
189  AVHWFramesContext *in_frames_ctx;
190  enum AVPixelFormat format;
191  int i, ret, last_stage = -1;
192  int rot_width = out_width, rot_height = out_height;
193 
194  /* check that we have a hw context */
195  if (!ctx->inputs[0]->hw_frames_ctx) {
196  av_log(ctx, AV_LOG_ERROR, "No hw context provided on input\n");
197  return AVERROR(EINVAL);
198  }
199 
200  in_frames_ctx = (AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
201  format = in_frames_ctx->sw_format;
202 
203  if (!format_is_supported(format)) {
204  av_log(ctx, AV_LOG_ERROR, "Unsupported input format: %s\n",
205  av_get_pix_fmt_name(format));
206  return AVERROR(ENOSYS);
207  }
208 
209  if (s->dir != NPP_TRANSPOSE_CCLOCK_FLIP) {
211  }
212 
215 
216  /* Rotating by 180° in case of clock_flip, or not at all for cclock_flip, so width/height unchanged by rotation */
217  rot_width = in_width;
218  rot_height = in_height;
219  }
220 
223  s->stages[STAGE_ROTATE].planes_in[0].width = in_width;
224  s->stages[STAGE_ROTATE].planes_in[0].height = in_height;
225  s->stages[STAGE_ROTATE].planes_out[0].width = rot_width;
226  s->stages[STAGE_ROTATE].planes_out[0].height = rot_height;
229  s->stages[STAGE_TRANSPOSE].planes_in[0].width = rot_width;
230  s->stages[STAGE_TRANSPOSE].planes_in[0].height = rot_height;
231  s->stages[STAGE_TRANSPOSE].planes_out[0].width = out_width;
232  s->stages[STAGE_TRANSPOSE].planes_out[0].height = out_height;
233 
234  /* init the hardware contexts */
235  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
236  if (!s->stages[i].stage_needed)
237  continue;
238  ret = init_stage(&s->stages[i], in_frames_ctx->device_ref);
239  if (ret < 0)
240  return ret;
241  last_stage = i;
242  }
243 
244  if (last_stage >= 0) {
245  ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->stages[last_stage].frames_ctx);
246  } else {
248  s->passthrough = 1;
249  }
250 
251  if (!ctx->outputs[0]->hw_frames_ctx)
252  return AVERROR(ENOMEM);
253 
254  return 0;
255 }
256 
258 {
259  AVFilterContext *ctx = outlink->src;
260  AVFilterLink *inlink = ctx->inputs[0];
261  NPPTransposeContext *s = ctx->priv;
262  int ret;
263 
264  if ((inlink->w >= inlink->h && s->passthrough == NPP_TRANSPOSE_PT_TYPE_LANDSCAPE) ||
265  (inlink->w <= inlink->h && s->passthrough == NPP_TRANSPOSE_PT_TYPE_PORTRAIT))
266  {
267  if (inlink->hw_frames_ctx) {
268  outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_frames_ctx);
269  if (!outlink->hw_frames_ctx)
270  return AVERROR(ENOMEM);
271  }
272 
273  av_log(ctx, AV_LOG_VERBOSE,
274  "w:%d h:%d -> w:%d h:%d (passthrough mode)\n",
275  inlink->w, inlink->h, inlink->w, inlink->h);
276  return 0;
277  } else {
279  }
280 
281  outlink->w = inlink->h;
282  outlink->h = inlink->w;
284 
285  ret = init_processing_chain(ctx, inlink->w, inlink->h, outlink->w, outlink->h);
286  if (ret < 0)
287  return ret;
288 
289  av_log(ctx, AV_LOG_VERBOSE, "w:%d h:%d -transpose-> w:%d h:%d\n",
290  inlink->w, inlink->h, outlink->w, outlink->h);
291 
292  return 0;
293 }
294 
296  AVFrame *out, AVFrame *in)
297 {
298  NPPTransposeContext *s = ctx->priv;
299  NppStatus err;
300  int i;
301 
302  for (i = 0; i < FF_ARRAY_ELEMS(stage->planes_in) && i < FF_ARRAY_ELEMS(in->data) && in->data[i]; i++) {
303  int iw = stage->planes_in[i].width;
304  int ih = stage->planes_in[i].height;
305  int ow = stage->planes_out[i].width;
306  int oh = stage->planes_out[i].height;
307 
308  // nppRotate uses 0,0 as the rotation point
309  // need to shift the image accordingly after rotation
310  // need to substract 1 to get the correct coordinates
311  double angle = s->dir == NPP_TRANSPOSE_CLOCK ? -90.0 : s->dir == NPP_TRANSPOSE_CCLOCK ? 90.0 : 180.0;
312  int shiftw = (s->dir == NPP_TRANSPOSE_CLOCK || s->dir == NPP_TRANSPOSE_CLOCK_FLIP) ? ow - 1 : 0;
313  int shifth = (s->dir == NPP_TRANSPOSE_CCLOCK || s->dir == NPP_TRANSPOSE_CLOCK_FLIP) ? oh - 1 : 0;
314 
315  err = nppiRotate_8u_C1R(in->data[i], (NppiSize){ iw, ih },
316  in->linesize[i], (NppiRect){ 0, 0, iw, ih },
317  out->data[i], out->linesize[i],
318  (NppiRect){ 0, 0, ow, oh },
319  angle, shiftw, shifth, NPPI_INTER_NN);
320  if (err != NPP_SUCCESS) {
321  av_log(ctx, AV_LOG_ERROR, "NPP rotate error: %d\n", err);
322  return AVERROR_UNKNOWN;
323  }
324  }
325 
326  return 0;
327 }
328 
330  AVFrame *out, AVFrame *in)
331 {
332  NppStatus err;
333  int i;
334 
335  for (i = 0; i < FF_ARRAY_ELEMS(stage->planes_in) && i < FF_ARRAY_ELEMS(in->data) && in->data[i]; i++) {
336  int iw = stage->planes_in[i].width;
337  int ih = stage->planes_in[i].height;
338 
339  err = nppiTranspose_8u_C1R(in->data[i], in->linesize[i],
340  out->data[i], out->linesize[i],
341  (NppiSize){ iw, ih });
342  if (err != NPP_SUCCESS) {
343  av_log(ctx, AV_LOG_ERROR, "NPP transpose error: %d\n", err);
344  return AVERROR_UNKNOWN;
345  }
346  }
347 
348  return 0;
349 }
350 
352  AVFrame *out, AVFrame *in) = {
355 };
356 
358 {
359  NPPTransposeContext *s = ctx->priv;
360  AVFrame *src = in;
361  int i, ret, last_stage = -1;
362 
363  for (i = 0; i < FF_ARRAY_ELEMS(s->stages); i++) {
364  if (!s->stages[i].stage_needed)
365  continue;
366 
367  ret = npptranspose_process[i](ctx, &s->stages[i], s->stages[i].frame, src);
368  if (ret < 0)
369  return ret;
370 
371  src = s->stages[i].frame;
372  last_stage = i;
373  }
374 
375  if (last_stage < 0)
376  return AVERROR_BUG;
377 
378  ret = av_hwframe_get_buffer(src->hw_frames_ctx, s->tmp_frame, 0);
379  if (ret < 0)
380  return ret;
381 
382  av_frame_move_ref(out, src);
383  av_frame_move_ref(src, s->tmp_frame);
384 
385  ret = av_frame_copy_props(out, in);
386  if (ret < 0)
387  return ret;
388 
389  return 0;
390 }
391 
393 {
394  AVFilterContext *ctx = link->dst;
395  NPPTransposeContext *s = ctx->priv;
396  AVFilterLink *outlink = ctx->outputs[0];
397  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
398  AVCUDADeviceContext *device_hwctx = frames_ctx->device_ctx->hwctx;
399  AVFrame *out = NULL;
400  CUresult err;
401  CUcontext dummy;
402  int ret = 0;
403 
404  if (s->passthrough)
405  return ff_filter_frame(outlink, in);
406 
407  out = av_frame_alloc();
408  if (!out) {
409  ret = AVERROR(ENOMEM);
410  goto fail;
411  }
412 
413  err = device_hwctx->internal->cuda_dl->cuCtxPushCurrent(device_hwctx->cuda_ctx);
414  if (err != CUDA_SUCCESS) {
415  ret = AVERROR_UNKNOWN;
416  goto fail;
417  }
418 
419  ret = npptranspose_filter(ctx, out, in);
420 
421  device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&dummy);
422  if (ret < 0)
423  goto fail;
424 
425  av_frame_free(&in);
426 
427  return ff_filter_frame(outlink, out);
428 
429 fail:
430  av_frame_free(&in);
431  av_frame_free(&out);
432  return ret;
433 }
434 
435 #define OFFSET(x) offsetof(NPPTransposeContext, x)
436 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
437 
438 static const AVOption options[] = {
439  { "dir", "set transpose direction", OFFSET(dir), AV_OPT_TYPE_INT, { .i64 = NPP_TRANSPOSE_CCLOCK_FLIP }, 0, 3, FLAGS, "dir" },
440  { "cclock_flip", "rotate counter-clockwise with vertical flip", 0, AV_OPT_TYPE_CONST, { .i64 = NPP_TRANSPOSE_CCLOCK_FLIP }, 0, 0, FLAGS, "dir" },
441  { "clock", "rotate clockwise", 0, AV_OPT_TYPE_CONST, { .i64 = NPP_TRANSPOSE_CLOCK }, 0, 0, FLAGS, "dir" },
442  { "cclock", "rotate counter-clockwise", 0, AV_OPT_TYPE_CONST, { .i64 = NPP_TRANSPOSE_CCLOCK }, 0, 0, FLAGS, "dir" },
443  { "clock_flip", "rotate clockwise with vertical flip", 0, AV_OPT_TYPE_CONST, { .i64 = NPP_TRANSPOSE_CLOCK_FLIP }, 0, 0, FLAGS, "dir" },
444  { "passthrough", "do not apply transposition if the input matches the specified geometry", OFFSET(passthrough), AV_OPT_TYPE_INT, { .i64 = NPP_TRANSPOSE_PT_TYPE_NONE }, 0, 2, FLAGS, "passthrough" },
445  { "none", "always apply transposition", 0, AV_OPT_TYPE_CONST, { .i64 = NPP_TRANSPOSE_PT_TYPE_NONE }, 0, 0, FLAGS, "passthrough" },
446  { "landscape", "preserve landscape geometry", 0, AV_OPT_TYPE_CONST, { .i64 = NPP_TRANSPOSE_PT_TYPE_LANDSCAPE }, 0, 0, FLAGS, "passthrough" },
447  { "portrait", "preserve portrait geometry", 0, AV_OPT_TYPE_CONST, { .i64 = NPP_TRANSPOSE_PT_TYPE_PORTRAIT }, 0, 0, FLAGS, "passthrough" },
448  { NULL },
449 };
450 
451 static const AVClass npptranspose_class = {
452  .class_name = "npptranspose",
453  .item_name = av_default_item_name,
454  .option = options,
455  .version = LIBAVUTIL_VERSION_INT,
456 };
457 
459  {
460  .name = "default",
461  .type = AVMEDIA_TYPE_VIDEO,
462  .filter_frame = npptranspose_filter_frame,
463  },
464  { NULL }
465 };
466 
468  {
469  .name = "default",
470  .type = AVMEDIA_TYPE_VIDEO,
471  .config_props = npptranspose_config_props,
472  },
473  { NULL }
474 };
475 
477  .name = "transpose_npp",
478  .description = NULL_IF_CONFIG_SMALL("NVIDIA Performance Primitives video transpose"),
479  .init = npptranspose_init,
480  .uninit = npptranspose_uninit,
481  .query_formats = npptranspose_query_formats,
482  .priv_size = sizeof(NPPTransposeContext),
483  .priv_class = &npptranspose_class,
484  .inputs = npptranspose_inputs,
485  .outputs = npptranspose_outputs,
486  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
487 };
NPPTransposeStageContext stages[STAGE_NB]
#define NULL
Definition: coverity.c:32
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: internal.h:385
static const char * format[]
Definition: af_aiir.c:330
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:125
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
AVOption.
Definition: opt.h:246
enum AVPixelFormat out_fmt
const char * fmt
Definition: avisynth_c.h:769
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
Main libavfilter public API header.
static int npptranspose_filter_frame(AVFilterLink *link, AVFrame *in)
int dir
TransposeDir.
int num
Numerator.
Definition: rational.h:59
static const AVFilterPad npptranspose_inputs[]
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:191
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:228
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:208
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:582
#define src
Definition: vp8dsp.c:254
static int(*const npptranspose_process[])(AVFilterContext *ctx, NPPTransposeStageContext *stage, AVFrame *out, AVFrame *in)
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
Definition: frame.h:564
static int npptranspose_init(AVFilterContext *ctx)
static void npptranspose_uninit(AVFilterContext *ctx)
const char * name
Pad name.
Definition: internal.h:60
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
AVFilterLink ** inputs
array of pointers to input links
Definition: avfilter.h:346
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
static int format_is_supported(enum AVPixelFormat fmt)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:189
AVOptions.
Transpose
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:91
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
static int npptranspose_filter(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
#define FFALIGN(x, a)
Definition: macros.h:48
static enum AVPixelFormat supported_formats[]
#define av_log(a,...)
static const AVClass npptranspose_class
A filter pad used for either input or output.
Definition: internal.h:54
int width
Definition: frame.h:284
#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
#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
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:2474
#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
TransposeStage
struct NPPTransposeStageContext::@235 planes_out[3]
Passthrough
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
Definition: hwcontext.c:329
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:465
#define fail()
Definition: checkasm.h:117
struct NPPTransposeStageContext::@235 planes_in[3]
common internal API header
#define OFFSET(x)
static int npptranspose_query_formats(AVFilterContext *ctx)
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Definition: hwcontext.h:148
AVFormatContext * ctx
Definition: movenc.c:48
#define s(width, name)
Definition: cbs_vp9.c:257
FFmpeg internal API for CUDA.
static const AVFilterPad npptranspose_outputs[]
int dummy
Definition: motion.c:64
static int npptranspose_transpose(AVFilterContext *ctx, NPPTransposeStageContext *stage, AVFrame *out, AVFrame *in)
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
HW acceleration through CUDA.
Definition: pixfmt.h:235
static int npptranspose_config_props(AVFilterLink *outlink)
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define FF_ARRAY_ELEMS(a)
static const AVOption options[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:257
uint8_t * data
The data buffer.
Definition: buffer.h:89
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
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
This struct is allocated as AVHWDeviceContext.hwctx.
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
Rational number (pair of numerator and denominator).
Definition: rational.h:58
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:123
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:553
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:140
A reference to a data buffer.
Definition: buffer.h:81
static int npptranspose_rotate(AVFilterContext *ctx, NPPTransposeStageContext *stage, AVFrame *out, AVFrame *in)
int
enum AVPixelFormat in_fmt
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
AVFilter ff_vf_transpose_npp
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
Definition: hwcontext.c:243
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
int den
Denominator.
Definition: rational.h:60
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
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
static int init_stage(NPPTransposeStageContext *stage, AVBufferRef *device_ctx)
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2362
internal API functions
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:221
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
#define FLAGS
int passthrough
PassthroughType, landscape passthrough mode enabled.