49 #define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) ) 50 #define ALIGN_UP(a, b) (((a) + (b) - 1) & ~((b) - 1)) 139 int in_sw, in_sh, out_sw, out_sh;
198 int out_width,
int out_height)
228 if (in_width == out_width && in_height == out_height)
257 CUcontext
dummy, cuda_ctx = device_hwctx->cuda_ctx;
262 extern char vf_scale_cuda_ptx[];
264 err = cuCtxPushCurrent(cuda_ctx);
265 if (err != CUDA_SUCCESS) {
271 err = cuModuleLoadData(&s->
cu_module, vf_scale_cuda_ptx);
272 if (err != CUDA_SUCCESS) {
292 cuTexRefSetFlags(s->
cu_tex_uchar, CU_TRSF_READ_AS_INTEGER);
299 cuTexRefSetFilterMode(s->
cu_tex_uchar, CU_TR_FILTER_MODE_LINEAR);
300 cuTexRefSetFilterMode(s->
cu_tex_uchar2, CU_TR_FILTER_MODE_LINEAR);
301 cuTexRefSetFilterMode(s->
cu_tex_uchar4, CU_TR_FILTER_MODE_LINEAR);
302 cuTexRefSetFilterMode(s->
cu_tex_ushort, CU_TR_FILTER_MODE_LINEAR);
303 cuTexRefSetFilterMode(s->
cu_tex_ushort2, CU_TR_FILTER_MODE_LINEAR);
304 cuTexRefSetFilterMode(s->
cu_tex_ushort4, CU_TR_FILTER_MODE_LINEAR);
306 cuCtxPopCurrent(&dummy);
314 if (((int64_t)
h * inlink->
w) > INT_MAX ||
315 ((int64_t)w * inlink->
h) > INT_MAX)
326 inlink->
w, inlink->
h, outlink->
w, outlink->
h);
330 outlink->
w*inlink->
h},
347 CUdeviceptr src_devptr = (CUdeviceptr)src_dptr;
348 CUdeviceptr dst_devptr = (CUdeviceptr)dst_dptr;
349 void *args_uchar[] = { &dst_devptr, &dst_width, &dst_height, &
dst_pitch, &src_width, &src_height };
350 CUDA_ARRAY_DESCRIPTOR
desc;
352 desc.Width = src_width;
353 desc.Height = src_height;
355 if (pixel_size == 1) {
356 desc.Format = CU_AD_FORMAT_UNSIGNED_INT8;
358 desc.Format = CU_AD_FORMAT_UNSIGNED_INT16;
361 cuTexRefSetAddress2D_v3(tex, &desc, src_devptr, src_pitch * pixel_size);
362 cuLaunchKernel(func,
DIV_UP(dst_width,
BLOCKX),
DIV_UP(dst_height,
BLOCKY), 1,
BLOCKX,
BLOCKY, 1, 0, 0, args_uchar,
NULL);
483 err = cuCtxPushCurrent(device_hwctx->cuda_ctx);
484 if (err != CUDA_SUCCESS) {
491 cuCtxPopCurrent(&
dummy);
495 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
508 #define OFFSET(x) offsetof(CUDAScaleContext, x) 509 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM) 542 .
name =
"scale_cuda",
550 .priv_class = &cudascale_class,
552 .
inputs = cudascale_inputs,
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
enum AVPixelFormat format
Output sw format.
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)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data.
BYTE int const BYTE int src_pitch
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define LIBAVUTIL_VERSION_INT
Main libavfilter public API header.
int h
agreed upon image height
const char * av_default_item_name(void *ptr)
Return the context name.
int width
The allocated dimensions of the frames in this pool.
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.
char * w_expr
width expression string
CUfunction cu_func_ushort
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
static int scalecuda_resize(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static enum AVPixelFormat supported_formats[]
static const AVFilterPad cudascale_outputs[]
CUfunction cu_func_ushort4
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
static int cudascale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in)
#define AV_LOG_VERBOSE
Detailed information.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
static av_cold int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
A filter pad used for either input or output.
A link between two filters.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int format_is_supported(enum AVPixelFormat fmt)
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
char * h_expr
height expression string
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
like NV12, with 16bpp per component, little-endian
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
static int cudascale_filter_frame(AVFilterLink *link, AVFrame *in)
int w
agreed upon image width
common internal API header
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames...
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
static const AVClass cudascale_class
FFmpeg internal API for CUDA.
CUfunction cu_func_uchar2
AVFilterContext * src
source filter
like NV12, with 10bpp per component, data in the high bits, zeros in the low bits, little-endian
static const AVFilterPad inputs[]
HW acceleration through CUDA.
static const AVOption options[]
static const AVFilterPad outputs[]
#define FF_ARRAY_ELEMS(a)
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
AVFilter ff_vf_scale_cuda
uint8_t * data
The data buffer.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
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)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static av_cold void cudascale_uninit(AVFilterContext *ctx)
This struct is allocated as AVHWDeviceContext.hwctx.
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
This struct describes a set or pool of "hardware" frames (i.e.
static av_cold int cudascale_config_props(AVFilterLink *outlink)
const char * name
Filter name.
static int call_resize_kernel(CUDAScaleContext *s, CUfunction func, CUtexref tex, int channels, uint8_t *src_dptr, int src_width, int src_height, int src_pitch, uint8_t *dst_dptr, int dst_width, int dst_height, int dst_pitch, int pixel_size)
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
static const AVFilterPad cudascale_inputs[]
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.
CUfunction cu_func_ushort2
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
A reference to a data buffer.
struct CUDAScaleContext::@201 planes_out[3]
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal and external API header
static av_cold int cudascale_init(AVFilterContext *ctx)
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
static int cudascale_query_formats(AVFilterContext *ctx)
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
enum AVPixelFormat in_fmt
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
struct CUDAScaleContext::@201 planes_in[3]
AVFilterContext * dst
dest filter
CUfunction cu_func_uchar4
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
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.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
static av_cold int init_stage(CUDAScaleContext *s, AVBufferRef *device_ctx)
enum AVPixelFormat out_fmt
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.