Go to the documentation of this file.
43 #define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, device_hwctx->internal->cuda_dl, x)
109 if (!strcmp(
s->format_str,
"same")) {
121 if (!
s->stages[
i].frame)
157 int in_sw, in_sh, out_sw, out_sh;
230 int out_width,
int out_height)
241 int i,
ret, last_stage = -1;
244 if (!
ctx->inputs[0]->hw_frames_ctx) {
270 if (in_width != out_width || in_height != out_height ||
271 in_deinterleaved_format != out_deinterleaved_format) {
274 if (
s->interp_algo == NPPI_INTER_SUPER &&
275 (out_width > in_width && out_height > in_height)) {
276 s->interp_algo = NPPI_INTER_LANCZOS;
279 if (
s->interp_algo == NPPI_INTER_SUPER &&
280 !(out_width < in_width && out_height < in_height)) {
281 s->interp_algo = NPPI_INTER_CUBIC;
286 if (!
s->stages[
STAGE_RESIZE].stage_needed && in_format == out_format)
289 if (!
s->passthrough) {
290 if (in_format != in_deinterleaved_format)
292 if (out_format != out_deinterleaved_format)
315 if (!
s->stages[
i].stage_needed)
326 ctx->outputs[0]->hw_frames_ctx =
av_buffer_ref(
s->stages[last_stage].frames_ctx);
330 if (!
ctx->outputs[0]->hw_frames_ctx)
345 s->w_expr,
s->h_expr,
350 if (((int64_t)
h *
inlink->w) > INT_MAX ||
351 ((int64_t)
w *
inlink->h) > INT_MAX)
364 if (
inlink->sample_aspect_ratio.num)
367 inlink->sample_aspect_ratio);
385 err = nppiYCbCr420_8u_P2P3R(
in->data[0],
in->linesize[0],
386 in->data[1],
in->linesize[1],
388 (NppiSize){ in->width, in->height });
393 if (err != NPP_SUCCESS) {
414 err = nppiResizeSqrPixel_8u_C1R(
in->data[
i], (NppiSize){ iw, ih },
415 in->linesize[
i], (NppiRect){ 0, 0, iw, ih },
417 (NppiRect){ 0, 0, ow, oh },
418 (
double)ow / iw, (
double)oh / ih,
419 0.0, 0.0,
s->interp_algo);
420 if (err != NPP_SUCCESS) {
437 err = nppiYCbCr420_8u_P3P2R((
const uint8_t**)
in->data,
439 out->data[0],
out->linesize[0],
440 out->data[1],
out->linesize[1],
441 (NppiSize){ in->width, in->height });
446 if (err != NPP_SUCCESS) {
465 int i,
ret, last_stage = -1;
468 if (!
s->stages[
i].stage_needed)
475 src =
s->stages[
i].frame;
485 s->tmp_frame->width =
src->width;
486 s->tmp_frame->height =
src->height;
519 ret =
CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPushCurrent(device_hwctx->cuda_ctx));
525 CHECK_CU(device_hwctx->internal->cuda_dl->cuCtxPopCurrent(&
dummy));
529 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
530 (int64_t)
in->sample_aspect_ratio.num * outlink->
h *
link->w,
531 (int64_t)
in->sample_aspect_ratio.den * outlink->
w *
link->h,
542 #define OFFSET(x) offsetof(NPPScaleContext, x)
543 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
549 {
"interp_algo",
"Interpolation algorithm used for resizing",
OFFSET(interp_algo),
AV_OPT_TYPE_INT, { .i64 = NPPI_INTER_CUBIC }, 0, INT_MAX,
FLAGS,
"interp_algo" },
550 {
"nn",
"nearest neighbour", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_NN }, 0, 0,
FLAGS,
"interp_algo" },
553 {
"cubic2p_bspline",
"2-parameter cubic (B=1, C=0)", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_CUBIC2P_BSPLINE }, 0, 0,
FLAGS,
"interp_algo" },
554 {
"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" },
555 {
"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" },
556 {
"super",
"supersampling", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_SUPER }, 0, 0,
FLAGS,
"interp_algo" },
557 {
"lanczos",
"Lanczos", 0,
AV_OPT_TYPE_CONST, { .i64 = NPPI_INTER_LANCZOS }, 0, 0,
FLAGS,
"interp_algo" },
589 "scaling and format conversion"),
static int format_is_supported(enum AVPixelFormat fmt)
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
#define AV_LOG_WARNING
Something somehow does not look correct.
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
AVPixelFormat
Pixel format.
static const AVFilterPad nppscale_inputs[]
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
uint8_t * data
The data buffer.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
static const AVClass nppscale_class
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
This structure describes decoded (raw) audio or video data.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static enum AVPixelFormat supported_formats[]
#define AV_LOG_VERBOSE
Detailed information.
const char * name
Filter name.
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
int width
The allocated dimensions of the frames in this pool.
A link between two filters.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static enum AVPixelFormat get_deinterleaved_format(enum AVPixelFormat fmt)
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.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
A filter pad used for either input or output.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void nppscale_uninit(AVFilterContext *ctx)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
NPPScaleStageContext stages[STAGE_NB]
static int nppscale_query_formats(AVFilterContext *ctx)
static const AVFilterPad outputs[]
static enum AVPixelFormat pix_fmts[]
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
static int init_stage(NPPScaleStageContext *stage, AVBufferRef *device_ctx)
#define LIBAVUTIL_VERSION_INT
Describe the class of an AVClass context structure.
static int nppscale_interleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Rational number (pair of numerator and denominator).
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
AVFilterLink ** inputs
array of pointers to input links
const char * av_default_item_name(void *ptr)
Return the context name.
char * h_expr
height expression string
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
static int nppscale_init(AVFilterContext *ctx)
static const struct @314 planes[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum AVPixelFormat out_fmt
static int nppscale_filter_frame(AVFilterLink *link, AVFrame *in)
AVFilterContext * src
source filter
static int nppscale_config_props(AVFilterLink *outlink)
static int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
static int nppscale_resize(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;} return ac;} 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;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->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);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
#define i(width, name, range_min, range_max)
int w
agreed upon image width
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
const char * name
Pad name.
This struct describes a set or pool of "hardware" frames (i.e.
This struct is allocated as AVHWDeviceContext.hwctx.
enum AVPixelFormat format
Output sw format.
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
char * w_expr
width expression string
#define FF_ARRAY_ELEMS(a)
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
enum AVPixelFormat in_fmt
struct NPPScaleStageContext::@241 planes_in[3]
int h
agreed upon image height
static int(*const nppscale_process[])(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
static const AVFilterPad nppscale_outputs[]
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
A reference to a data buffer.
static const AVOption options[]
static int nppscale_deinterleave(AVFilterContext *ctx, NPPScaleStageContext *stage, AVFrame *out, AVFrame *in)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
static enum AVPixelFormat deinterleaved_formats[][2]
struct NPPScaleStageContext::@241 planes_out[3]
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
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.
static int nppscale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)