183 int in_sw, in_sh, out_sw, out_sh;
256 int out_width,
int out_height)
267 int i, ret, last_stage = -1;
296 if (in_width != out_width || in_height != out_height ||
297 in_deinterleaved_format != out_deinterleaved_format)
304 if (in_format != in_deinterleaved_format)
306 if (out_format != out_deinterleaved_format)
354 double var_values[
VARS_NB], res;
365 var_values[
VAR_A] = (double) inlink->
w / inlink->
h;
391 if (w < -1 || h < -1) {
395 if (w == -1 && h == -1)
407 if (w > INT_MAX || h > INT_MAX ||
408 (h * inlink->
w) > INT_MAX ||
409 (w * inlink->
h) > INT_MAX)
420 inlink->
w, inlink->
h, outlink->
w, outlink->
h);
424 outlink->
w*inlink->
h},
433 "Error when evaluating the expression '%s'\n", expr);
445 err = nppiYCbCr420_8u_P2P3R(in->
data[0], in->
linesize[0],
453 if (err != NPP_SUCCESS) {
474 err = nppiResizeSqrPixel_8u_C1R(in->
data[i], (NppiSize){ iw, ih },
475 in->
linesize[i], (NppiRect){ 0, 0, iw, ih },
477 (NppiRect){ 0, 0, ow, oh },
478 (double)ow / iw, (
double)oh / ih,
480 if (err != NPP_SUCCESS) {
497 err = nppiYCbCr420_8u_P3P2R((
const uint8_t**)in->
data,
506 if (err != NPP_SUCCESS) {
525 int i, ret, last_stage = -1;
577 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
582 err = cuCtxPushCurrent(device_hwctx->cuda_ctx);
590 cuCtxPopCurrent(&
dummy);
602 #define OFFSET(x) offsetof(NPPScaleContext, x)
603 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
609 {
"interp_algo",
"Interpolation algorithm used for resizing",
OFFSET(interp_algo),
AV_OPT_TYPE_INT, { .i64 = NPPI_INTER_CUBIC }, 0, INT_MAX,
FLAGS,
"interp_algo" },
610 {
"nn",
"nearest neighbour", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_NN }, 0, 0,
FLAGS,
"interp_algo" },
613 {
"cubic2p_bspline",
"2-parameter cubic (B=1, C=0)", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_BSPLINE }, 0, 0,
FLAGS,
"interp_algo" },
614 {
"cubic2p_catmullrom",
"2-parameter cubic (B=0, C=1/2)", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_CATMULLROM }, 0, 0,
FLAGS,
"interp_algo" },
615 {
"cubic2p_b05c03",
"2-parameter cubic (B=1/2, C=3/10)", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_B05C03 }, 0, 0,
FLAGS,
"interp_algo" },
616 {
"super",
"supersampling", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_SUPER }, 0, 0,
FLAGS,
"interp_algo" },
617 {
"lanczos",
"Lanczos", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LANCZOS }, 0, 0,
FLAGS,
"interp_algo" },
649 "scaling and format conversion"),
656 .priv_class = &nppscale_class,
658 .
inputs = nppscale_inputs,
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define LIBAVUTIL_VERSION_INT
Main libavfilter public API header.
int h
agreed upon image height
int width
The allocated dimensions of the frames in this pool.
static int nppscale_config_props(AVFilterLink *outlink)
enum AVPixelFormat out_fmt
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
static enum AVPixelFormat get_deinterleaved_format(enum AVPixelFormat fmt)
static int nppscale_resize(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
enum AVPixelFormat format
Output sw format.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFilterLink ** inputs
array of pointers to input links
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
char * w_expr
width expression string
static const AVFilterPad nppscale_inputs[]
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
enum AVPixelFormat in_fmt
static void nppscale_uninit(AVFilterContext *ctx)
struct NPPScaleStageContext::@172 planes_in[3]
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
#define AV_LOG_VERBOSE
Detailed information.
static const AVOption options[]
An API-specific header for AV_HWDEVICE_TYPE_CUDA.
A filter pad used for either input or output.
struct NPPScaleStageContext::@172 planes_out[3]
static int nppscale_init(AVFilterContext *ctx)
A link between two filters.
int av_expr_parse_and_eval(double *d, const char *s, const char *const *const_names, const double *const_values, const char *const *func1_names, double(*const *funcs1)(void *, double), const char *const *func2_names, double(*const *funcs2)(void *, double, double), void *opaque, int log_offset, void *log_ctx)
Parse and evaluate an expression.
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const char *const var_names[]
static int nppscale_deinterleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
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.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
static int nppscale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
static int nppscale_interleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
int w
agreed upon image width
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
common internal API header
uint8_t nb_components
The number of components each pixel has, (1-4)
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames...
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
static const AVClass nppscale_class
static enum AVPixelFormat supported_formats[]
AVFilterContext * src
source filter
static const AVFilterPad outputs[]
static int format_is_supported(enum AVPixelFormat fmt)
HW acceleration through CUDA.
#define FF_ARRAY_ELEMS(a)
static const AVFilterPad inputs[]
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
uint8_t * data
The data buffer.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
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.
This struct is allocated as AVHWDeviceContext.hwctx.
Describe the class of an AVClass context structure.
rational number numerator/denominator
This struct describes a set or pool of "hardware" frames (i.e.
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
const char * name
Filter name.
static int(*const nppscale_process[])(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
static int nppscale_query_formats(AVFilterContext *ctx)
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
static const AVFilterPad nppscale_outputs[]
A reference to a data buffer.
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
NPPScaleStageContext stages[STAGE_NB]
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
AVFilterContext * dst
dest filter
static enum AVPixelFormat deinterleaved_formats[][2]
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
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.
char * h_expr
height expression string
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
simple arithmetic expression evaluator