81#define DIV_UP(a, b) ( ((a) + (b) - 1) / (b) )
85#define CHECK_CU(x) FF_CUDA_CHECK_DL(ctx, s->hwctx->internal->cuda_dl, x)
149#define CUDA_SCALE_MAX_PASSES 3
244 int in_sub,
int out_sub)
247 (
int64_t)in_size * (1 << out_sub);
251 int in_sub,
int out_sub)
254 (
int64_t)in_size * (1 << out_sub);
259 int in_sub,
int out_sub)
262 (1 << in_sub) / (1 << out_sub);
266 int in_width,
int in_height,
267 int out_width,
int out_height,
268 int in_sub_x,
int in_sub_y,
269 int out_sub_x,
int out_sub_y,
272 unsigned int x_planes = 0;
273 unsigned int y_planes = 0;
286 in_sub_x, out_sub_x))
289 in_sub_y, out_sub_y))
296 if (x_planes && y_planes) {
299 }
else if (x_planes) {
301 }
else if (y_planes) {
324 cu->cuMemFree(
filter->weights);
326 cu->cuMemFree(
filter->offsets);
334 cu->cuTexObjectDestroy(t->
tex[
i]);
336 cu->cuMemFree(t->
data[
i]);
339 memset(t, 0,
sizeof(*t));
350 memset(
set, 0,
sizeof(*
set));
358 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
361 CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
366 CHECK_CU(cu->cuModuleUnload(
s->cu_module));
407 s->frames_ctx = out_ref;
417 int log2_chroma_w,
int log2_chroma_h,
418 int nb_planes,
const int depths[4],
420 int use_float,
unsigned int planes)
423 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
431 .log2_chroma_w = log2_chroma_w,
432 .log2_chroma_h = log2_chroma_h,
435 for (
int i = 0;
i < nb_planes;
i++) {
436 const int is_chroma =
i == 1 ||
i == 2;
443 const int sizeof_pixel = (use_float ?
sizeof(
float) :
451 (
size_t) plane_w * sizeof_pixel,
457 CUDA_TEXTURE_DESC tex_desc = {
459 .filterMode = CU_TR_FILTER_MODE_POINT,
462 CUDA_RESOURCE_DESC res_desc = {
463 .resType = CU_RESOURCE_TYPE_PITCH2D,
464 .res.pitch2D.format = use_float ? CU_AD_FORMAT_FLOAT :
466 CU_AD_FORMAT_UNSIGNED_INT8 :
467 CU_AD_FORMAT_UNSIGNED_INT16,
469 .res.pitch2D.devPtr = tex->
data[
i],
470 .res.pitch2D.pitchInBytes = pitch,
471 .res.pitch2D.width = plane_w,
472 .res.pitch2D.height = plane_h,
517 float y_scale = 1.0f;
518 float uv_scale = 1.0f;
524 "Unsupported colorspace %d for YUV->RGB conversion\n", colorspace);
532 y_scale = 255.0f / (235.0f - 16.0f);
534 : 255.0f / (240.0f - 16.0f);
537 for (
int i = 0;
i < 3;
i++) {
552 float y_scale = 1.0f;
553 float uv_scale = 1.0f;
557 "Unsupported colorspace %d for RGB->YUV conversion\n", colorspace);
564 y_scale = (235.0f - 16.0f) / 255.0f;
566 : (240.0f - 16.0f) / 255.0f;
569 for (
int i = 0;
i < 3;
i++) {
570 float scale = (
i == 0) ? y_scale : uv_scale;
582 return in !=
out && in != unspecified &&
out != unspecified;
590 s->in_fmt = in_format;
591 s->out_fmt = out_format;
602 for (
i = 0;
i <
s->in_desc->nb_components;
i++) {
603 d = (
s->in_desc->comp[
i].depth + 7) / 8;
604 p =
s->in_desc->comp[
i].plane;
605 s->in_plane_channels[p] =
FFMAX(
s->in_plane_channels[p],
s->in_desc->comp[
i].step / d);
607 s->in_plane_depths[p] =
s->in_desc->comp[
i].depth;
612 int out_width,
int out_height)
663 "YUV input is tagged with the RGB colorspace\n");
676 "YUV->RGB conversion enabled (%s, %s range)\n",
678 limited_range ?
"limited" :
"full");
702 "RGB->YUV conversion enabled (%s, %s range)\n",
704 limited_range ?
"limited" :
"full");
713 "out_range and out_color_matrix cannot be used with RGB output\n");
716 }
else if (
s->rgb2yuv) {
717 if ((
s->out_desc->log2_chroma_w ||
s->out_desc->log2_chroma_h) &&
721 "RGB->YUV conversion produces centered chroma, cannot "
722 "output %s chroma location\n",
737 "Cannot convert from %s %s range to %s %s range, scale_cuda "
738 "only changes YCbCr matrix and range when converting from RGB\n",
747 if ((
s->in_desc->log2_chroma_w ||
s->in_desc->log2_chroma_h) &&
748 s->in_desc->log2_chroma_w ==
s->out_desc->log2_chroma_w &&
749 s->in_desc->log2_chroma_h ==
s->out_desc->log2_chroma_h &&
753 "Cannot convert chroma location from %s to %s\n",
760 if (
s->passthrough && in_width == out_width && in_height == out_height && in_format == out_format) {
773 if (in_width == out_width && in_height == out_height &&
775 s->use_filters_opt != 1)
778 if (
s->yuv2rgb ||
s->rgb2yuv) {
781 if (
s->use_filters_opt == 0 &&
782 (in_width != out_width || in_height != out_height))
784 "conversion always uses the generic filters\n");
788 }
else if (
s->use_filters_opt >= 0) {
789 s->use_filters =
s->use_filters_opt;
799 (
s->in_planes > 1 &&
s->out_planes > 1 &&
802 s->in_desc->log2_chroma_w,
803 s->out_desc->log2_chroma_w) ||
805 in_height, out_height,
806 s->in_desc->log2_chroma_h,
807 s->out_desc->log2_chroma_h)));
821 CUcontext
dummy, cuda_ctx =
s->hwctx->cuda_ctx;
822 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
829 const char *fixed_infix;
830 int fixed_use_linear;
831 int fixed_as_integer;
833 extern const unsigned char ff_vf_scale_cuda_ptx_data[];
834 extern const unsigned int ff_vf_scale_cuda_ptx_len;
840 fixed_infix =
"Nearest";
841 fixed_use_linear = 0;
842 fixed_as_integer = 1;
845 fixed_infix =
"Bilinear";
846 fixed_use_linear = 1;
847 fixed_as_integer = 1;
851 fixed_infix =
"Bicubic";
852 fixed_use_linear = 0;
853 fixed_as_integer = 0;
856 fixed_infix =
"Lanczos";
857 fixed_use_linear = 0;
858 fixed_as_integer = 0;
870 ff_vf_scale_cuda_ptx_data, ff_vf_scale_cuda_ptx_len);
874 if (
s->use_filters) {
875 static const char *
const infix[] = {
"Generic_h",
"Generic_v" };
877 "Generic_float_h" :
"Generic_h";
879 s->interp_use_linear = 0;
880 s->interp_as_integer = 0;
883 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s",
884 infix[dir], in_fmt_name, out_fmt_name);
885 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_out[dir],
890 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s_uv",
891 infix[dir], in_fmt_name, out_fmt_name);
892 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_out_uv[dir],
898 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s", tmp_infix,
899 in_fmt_name, in_fmt_name);
905 if (
s->in_planes > 1) {
906 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s_uv", tmp_infix,
907 in_fmt_name, in_fmt_name);
908 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_tmp_uv,
914 s->interp_use_linear = fixed_use_linear;
915 s->interp_as_integer = fixed_as_integer;
917 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s", fixed_infix,
918 in_fmt_name, out_fmt_name);
919 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_fixed,
927 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s_uv", fixed_infix,
928 in_fmt_name, out_fmt_name);
929 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_fixed_uv,
936 if (
s->yuv2rgb ||
s->rgb2yuv) {
937 const char *rgb_name =
s->yuv2rgb ? out_fmt_name : in_fmt_name;
939 snprintf(buf,
sizeof(buf),
"Conv_float_%s_%s", in_fmt_name, out_fmt_name);
940 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_conv,
s->cu_module, buf));
944 snprintf(buf,
sizeof(buf),
"Subsample_Generic_float_h_%s_%s", rgb_name, rgb_name);
945 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_tmp,
s->cu_module, buf));
950 static const char *
const infix[] = {
"Generic_h",
"Generic_v" };
953 snprintf(buf,
sizeof(buf),
"Subsample_%s_%s_%s",
954 infix[dir], rgb_name, rgb_name);
955 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_out[dir],
961 snprintf(buf,
sizeof(buf),
"Conv_float_%s_%s_uv", in_fmt_name, out_fmt_name);
962 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_conv_uv,
s->cu_module, buf));
966 snprintf(buf,
sizeof(buf),
"Subsample_Generic_float_v_%s_%s", rgb_name, rgb_name);
967 ret =
CHECK_CU(cu->cuModuleGetFunction(&
s->cu_func_tmp_v,
s->cu_module, buf));
977 in_fmt_name, out_fmt_name);
988 int src_size,
int dst_size,
989 double virtual_size,
int needs_scale)
992 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
996 .src_size = src_size,
997 .dst_size = dst_size,
998 .virtual_size = virtual_size,
1003 params.virtual_size = 0.0;
1005 switch (
s->interp_algo) {
1011 params.scaler_params[0] =
s->param;
1016 params.scaler_params[0] =
params.scaler_params[1] = 0.0;
1018 params.scaler_params[1] =
s->param;
1028 "currently supported by the CUDA scaler (%d).\n",
1039 for (
size_t i = 0;
i <
weights->num_weights;
i++)
1042 f->filter_size =
weights->filter_size;
1043 f->dst_size = dst_size;
1045 const size_t weights_size =
weights->num_weights *
sizeof(*tmp);
1046 ret =
CHECK_CU(cu->cuMemAlloc(&
f->weights, weights_size));
1053 const size_t offsets_size = dst_size *
sizeof(*
weights->offsets);
1054 ret =
CHECK_CU(cu->cuMemAlloc(&
f->offsets, offsets_size));
1081 int in_width,
int in_height)
1086 static const int rgb_depths[4] = { 8 };
1087 static const int rgb_channels[4] = { 4 };
1088 const int scale_x = in_width != outlink->
w;
1089 const int scale_y = in_height != outlink->
h;
1095 set->in_use_linear = 0;
1096 set->in_as_integer =
s->yuv2rgb;
1100 in_width, in_height, 0, 0, 1,
1101 rgb_depths, rgb_channels, 1,
1107 .func =
s->cu_func_conv,
1111 .src_desc =
s->in_desc,
1112 .dst_desc = rgb_desc,
1119 const int to_out = last &&
s->yuv2rgb;
1128 0, 0, 1, rgb_depths, rgb_channels, 1,
1134 pass = &
set->passes[
set->nb_passes++];
1136 .func = to_out ?
s->cu_func_out[dir] :
1142 .src_desc = rgb_desc,
1143 .dst_desc = rgb_desc,
1156 .func =
s->cu_func_conv,
1157 .func_uv =
s->cu_func_conv_uv,
1161 .src_desc = rgb_desc,
1162 .dst_desc =
s->out_desc,
1171 int in_width,
int in_height,
1180 const int in_sub_x =
s->in_desc->log2_chroma_w;
1181 const int in_sub_y =
s->in_desc->log2_chroma_h;
1182 const int out_sub_x =
s->out_desc->log2_chroma_w;
1183 const int out_sub_y =
s->out_desc->log2_chroma_h;
1185 const int has_chroma =
s->in_planes > 1 &&
s->out_planes > 1;
1191 set->in_width = in_width;
1192 set->in_height = in_height;
1193 set->normalize_crop = normalize_crop;
1194 set->in_use_linear =
s->interp_use_linear;
1195 set->in_as_integer =
s->interp_as_integer;
1197 if ((
s->yuv2rgb ||
s->rgb2yuv) &&
1198 (in_width != outlink->
w || in_height != outlink->
h))
1201 if (!
s->use_filters) {
1205 .func =
s->cu_func_fixed,
1206 .func_uv =
s->cu_func_fixed_uv,
1207 .planes = out_planes,
1210 .src_desc =
s->in_desc,
1211 .dst_desc =
s->out_desc,
1217 in_width, in_height, outlink->
w, outlink->
h,
1218 in_sub_x, in_sub_y, out_sub_x, out_sub_y,
1230 pass_x = &
set->passes[
set->nb_passes++];
1232 .func =
s->cu_func_tmp,
1233 .func_uv =
s->cu_func_tmp_uv,
1234 .planes = normalize_crop ? all_planes : plan.
x_planes,
1237 .src_desc =
s->in_desc,
1238 .dst_desc =
s->in_desc,
1242 pass = &
set->passes[
set->nb_passes++];
1246 .planes = out_planes,
1249 .src_desc =
s->in_desc,
1250 .dst_desc =
s->out_desc,
1259 pass_x->
planes : all_planes;
1263 in_width, outlink->
w, 0.0,
1273 src_size, in_width, outlink->
w, in_sub_x, out_sub_x);
1275 src_size, dst_size, virtual_size,
1285 in_height, outlink->
h, 0.0,
1294 src_size, in_height, outlink->
h, in_sub_y, out_sub_y);
1296 src_size, dst_size, virtual_size,
1306 outlink->
w, in_height,
1307 out_sub_x, in_sub_y,
s->in_planes,
1308 s->in_plane_depths,
s->in_plane_channels,
1319 int in_width,
int in_height,
1323 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
1330 if (
s->filter_set.nb_passes &&
1331 ((!
s->use_filters && !
s->yuv2rgb && !
s->rgb2yuv) ||
1332 (
s->filter_set.in_width == in_width &&
1333 s->filter_set.in_height == in_height &&
1334 s->filter_set.normalize_crop == normalize_crop)))
1342 if (
s->filter_set.nb_passes) {
1349 old =
s->filter_set;
1350 s->filter_set = next;
1351 memset(&next, 0,
sizeof(next));
1355 "Prepared %d pass%s for visible input %dx%d%s\n",
1356 s->filter_set.nb_passes,
s->filter_set.nb_passes > 1 ?
"es" :
"",
1357 in_width, in_height, normalize_crop ?
" (cropped)" :
"");
1366 int in_width,
int in_height)
1369 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
1373 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
1471 &cfg_in[0]->chroma_locations)) < 0)
1494 s->w_expr,
s->h_expr,
1504 s->force_original_aspect_ratio,
1505 s->force_divisible_by, w_adj);
1509 if (((
int64_t)
h * inlink->
w) > INT_MAX ||
1523 s->hwctx = device_hwctx;
1524 s->cu_stream =
s->hwctx->stream;
1530 outlink->
w*inlink->
h},
1539 s->passthrough ?
" (passthrough)" :
"");
1545 if (!
s->passthrough) {
1559 int *normalize_crop)
1562 size_t frame_width, frame_height;
1564 if (
frame->width <= 0 ||
frame->height <= 0) {
1569 frame_width =
frame->width;
1570 frame_height =
frame->height;
1571 if (
frame->crop_left >= frame_width ||
1572 frame->crop_right >= frame_width -
frame->crop_left ||
1573 frame->crop_top >= frame_height ||
1574 frame->crop_bottom >= frame_height -
frame->crop_top) {
1581 *normalize_crop =
frame->crop_left ||
frame->crop_top ||
1589 const int depths[4],
const int channels[4],
1590 CUDATex *tex,
int use_linear,
int as_integer)
1593 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
1600 .width =
frame->width,
1601 .height =
frame->height,
1602 .crop_left =
frame->crop_left,
1603 .crop_top =
frame->crop_top,
1605 .crop_height = (
frame->height -
frame->crop_bottom) -
frame->crop_top,
1606 .color_range =
frame->color_range,
1607 .log2_chroma_w =
desc->log2_chroma_w,
1608 .log2_chroma_h =
desc->log2_chroma_h,
1618 CUDA_TEXTURE_DESC tex_desc = {
1619 .filterMode = use_linear ?
1620 CU_TR_FILTER_MODE_LINEAR :
1621 CU_TR_FILTER_MODE_POINT,
1622 .flags = as_integer ? CU_TRSF_READ_AS_INTEGER : 0,
1625 const int is_chroma =
i == 1 ||
i == 2;
1626 const int sub_x = is_chroma ?
desc->log2_chroma_w : 0;
1627 const int sub_y = is_chroma ?
desc->log2_chroma_h : 0;
1628 CUDA_RESOURCE_DESC res_desc = {
1629 .resType = CU_RESOURCE_TYPE_PITCH2D,
1630 .res.pitch2D.format = depths[
i] <= 8 ?
1631 CU_AD_FORMAT_UNSIGNED_INT8 :
1632 CU_AD_FORMAT_UNSIGNED_INT16,
1634 .res.pitch2D.pitchInBytes = tex->
linesize[
i],
1635 .res.pitch2D.devPtr = tex->
data[
i],
1652 const CUtexObject src_tex[4],
1653 int src_left,
int src_top,
int src_width,
int src_height,
1654 const CUdeviceptr out_data[4],
1655 int dst_width,
int dst_height,
int dst_pitch,
int mpeg_range)
1658 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
1663 .src_tex = {src_tex[0], src_tex[1], src_tex[2], src_tex[3]},
1670 .dst_width = dst_width,
1671 .dst_height = dst_height,
1672 .dst_pitch = dst_pitch,
1673 .src_left = src_left,
1675 .src_width = src_width,
1676 .src_height = src_height,
1678 .mpeg_range = mpeg_range,
1679 .weights =
filter->weights,
1680 .offsets =
filter->offsets,
1681 .filter_size =
filter->filter_size,
1685 .src_storage_max = ((1U << src_desc->
comp[0].
depth) - 1) <<
1687 .color_matrix =
s->color_matrix,
1703 void *args[] = { &
params };
1719 const int mpeg_range = conversion ?
1730 out->linesize[0], mpeg_range);
1748 out->linesize[1], mpeg_range);
1761 const int out_sub =
s->out_desc->log2_chroma_w ||
s->out_desc->log2_chroma_h;
1768 }
else if (
s->rgb2yuv) {
1788 int in_width,
int in_height,
int normalize_crop)
1791 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
1800 CUDATex in_tex = {0}, out_tex = {0};
1802 s->in_plane_channels, &in_tex,
1803 s->filter_set.in_use_linear,
1804 s->filter_set.in_as_integer);
1820 for (
int i = 0;
i <
s->filter_set.nb_passes;
i++) {
1834 dst->tex[j] =
src->tex[j];
1836 dst->color_range =
src->color_range;
1847 s->frame->width = outlink->
w;
1848 s->frame->height = outlink->
h;
1857 out->crop_bottom = 0;
1859 out->crop_right = 0;
1863 out->width != in_width ||
out->height != in_height) {
1879 CudaFunctions *cu =
s->hwctx->internal->cuda_dl;
1883 int in_width, in_height, normalize_crop;
1886 if (
s->passthrough) {
1902 ret =
CHECK_CU(cu->cuCtxPushCurrent(
s->hwctx->cuda_ctx));
1916 av_reduce(&
out->sample_aspect_ratio.num, &
out->sample_aspect_ratio.den,
1934 return s->passthrough ?
1939#define OFFSET(x) offsetof(CUDAScaleContext, x)
1940#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
1950 {
"passthrough",
"Do not process frames at all if parameters match",
OFFSET(passthrough),
AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1,
FLAGS },
1951 {
"use_filters",
"Use generic filters instead of fixed function kernels",
OFFSET(use_filters_opt),
AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1,
FLAGS, .unit =
"use_filters" },
1954 {
"force_original_aspect_ratio",
"decrease or increase w/h if necessary to keep the original AR",
OFFSET(force_original_aspect_ratio),
AV_OPT_TYPE_INT, { .i64 = 0 }, 0,
SCALE_FORCE_OAR_NB-1,
FLAGS, .unit =
"force_oar" },
1958 {
"force_divisible_by",
"enforce that the output resolution is divisible by a defined integer when force_original_aspect_ratio is used",
OFFSET(force_divisible_by),
AV_OPT_TYPE_INT, { .i64 = 1 }, 1, 256,
FLAGS },
1959 {
"reset_sar",
"reset SAR to 1 and scale to square pixels if scaling proportionally",
OFFSET(reset_sar),
AV_OPT_TYPE_BOOL, { .i64 = 0}, 0, 1,
FLAGS },
1984 .class_name =
"cudascale",
2008 .p.name =
"scale_cuda",
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
SwsAArch64OpImplParams params
static const char *const format[]
const FFFilter ff_vf_scale_cuda
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Main libavfilter public API header.
#define i(width, name, range_min, range_max)
static void fn rgb2yuv(uint8_t *_yuv[3], const ptrdiff_t yuv_stride[3], int16_t *rgb[3], ptrdiff_t s, int w, int h, const int16_t rgb2yuv_coeffs[3][3][8], const int16_t yuv_offset[8])
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
Colorspace value utility functions for libavutil.
const char * ff_sws_scaler_name(SwsScaler scaler)
Return the friendly name of a given scaler enum, or NULL if invalid.
int ff_sws_filter_generate(void *log, const SwsFilterParams *params, SwsFilterWeights **out)
Generate a filter kernel for the given parameters.
static void yuv2rgb(uint8_t *out, int ridx, int Y, int U, int V)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_PIXEL_FMT
Underlying C type is enum AVPixelFormat.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
const struct AVLumaCoefficients * av_csp_luma_coeffs_from_avcsp(enum AVColorSpace csp)
Retrieves the Luma coefficients necessary to construct a conversion matrix from an enum constant desc...
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
#define LIBAVUTIL_VERSION_INT
#define SWS_PARAM_DEFAULT
@ SWS_SCALE_POINT
nearest neighbor (point sampling)
@ SWS_SCALE_LANCZOS
3-tap sinc/sinc
@ SWS_SCALE_BILINEAR
bilinear filtering
@ SWS_SCALE_BICUBIC
2-tap cubic BC-spline
static const int weights[]
static av_always_inline void scale(vec_s32 res[4], vec_s16 res_packed[2], const int shift)
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
FFmpeg internal API for CUDA.
static int unsupported(AVCodecContext *avctx)
int(* func)(AVBPrint *dst, const char *in, const char *arg)
void ff_matrix_invert_3x3(const double in[3][3], double out[3][3])
void ff_fill_rgb2yuv_table(const AVLumaCoefficients *coeffs, double rgb2yuv[3][3])
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static FilterLink * ff_filter_link(AVFilterLink *link)
#define FILTER_QUERY_FUNC2(func)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static enum AVPixelFormat pix_fmts[]
@ SWS_FILTER_SCALE
14-bit coefficients are picked to fit comfortably within int16_t for efficient SIMD processing (e....
static const struct @257111027162314367033347246032313251342043035002 planes[]
int ff_cuda_load_module(void *avctx, AVCUDADeviceContext *hwctx, CUmodule *cu_module, const unsigned char *data, const unsigned int length)
Loads a CUDA module and applies any decompression, if necessary.
Memory handling functions.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const char * av_color_space_name(enum AVColorSpace space)
const char * av_color_range_name(enum AVColorRange range)
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.
const char * av_chroma_location_name(enum AVChromaLocation location)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
#define AV_PIX_FMT_0RGB32
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
@ AVCHROMA_LOC_UNSPECIFIED
#define AV_PIX_FMT_YUV420P10
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV444P12MSB
AVPixelFormat
Pixel 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...
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P10MSB
#define AV_PIX_FMT_0BGR32
#define AV_PIX_FMT_YUV444P10
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_YCGCO_RE
YCgCo-R, even addition of bits.
@ AVCOL_SPC_BT709
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / derived in SMPTE RP 177 Annex B
@ AVCOL_SPC_BT470BG
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601
@ AVCOL_SPC_BT2020_CL
ITU-R BT2020 constant luminance system.
@ AVCOL_SPC_NB
Not part of ABI.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
@ AVCOL_SPC_BT2020_NCL
ITU-R BT2020 non-constant luminance system.
@ AVCOL_SPC_SMPTE170M
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above
@ AVCOL_SPC_FCC
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
@ AVCOL_SPC_SMPTE240M
derived from 170M primaries and D65 white point, 170M is derived from BT470 System M's primaries
@ AVCOL_SPC_YCGCO_RO
YCgCo-R, odd addition of bits.
@ AVCOL_SPC_YCGCO
used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16
@ AVCOL_SPC_RESERVED
reserved for future use by ITU-T and ISO/IEC just like 15-255 are
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
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)
Parse and evaluate string expressions for width and height.
@ SCALE_FORCE_OAR_DISABLE
@ SCALE_FORCE_OAR_INCREASE
@ SCALE_FORCE_OAR_DECREASE
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
This struct is allocated as AVHWDeviceContext.hwctx.
Describe the class of an AVClass context structure.
int shift
Number of least significant bits that must be shifted away to get the value.
int depth
Number of bits in the component.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
enum AVChromaLocation chroma_location
Agreed upon chroma sample location, for video with subsampled chroma.
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
enum AVColorSpace colorspace
For non-YUV links, these are respectively set to fallback values (as appropriate for that colorspace)...
AVFilterContext * dst
dest filter
enum AVColorRange color_range
agreed upon YUV color range
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int width
The allocated dimensions of the frames in this pool.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar calculations.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint64_t flags
Combination of AV_PIX_FMT_FLAG_... flags.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Rational number (pair of numerator and denominator).
CUfunction cu_func_conv
conversion with a float RGB side
int out_range
requested output color range (AVColorRange)
enum AVPixelFormat format
Output sw format.
int force_original_aspect_ratio
CUfunction cu_func_tmp_uv
const AVPixFmtDescriptor * in_desc
enum AVPixelFormat in_fmt out_fmt
CUfunction cu_func_tmp_v
vertical float pass before RGB->YUV
int out_color_matrix
requested output YCbCr matrix (AVColorSpace)
AVCUDADeviceContext * hwctx
CUDAScaleFilterSet filter_set
char * w_expr
width expression string
enum AVColorRange color_range
resolved color range for conversion
const AVPixFmtDescriptor * out_desc
CUfunction cu_func_fixed_uv
CUfunction cu_func_conv_uv
char * h_expr
height expression string
CUfunction cu_func_out[2]
CUDAScaleColorMatrix color_matrix
CUfunction cu_func_out_uv[2]
int in_as_integer
integer texture reads of the input
CUDATex tmp[2]
CUDA_SCALE_BUF_TMP, CUDA_SCALE_BUF_TMP2.
int in_use_linear
texture filtering of the input
CUDAScalePass passes[CUDA_SCALE_MAX_PASSES]
CUdeviceptr weights
float[dst_size][filter_size]
CUdeviceptr offsets
int[dst_size]
const AVPixFmtDescriptor * src_desc
sample format read
CUfunction func_uv
kernel for the chroma plane(s)
CUfunction func
kernel for the primary plane(s)
CUDAScaleFilter filter
generic filter weights for func
unsigned int planes
plane groups written, CUDA_SCALE_PLANE_*
CUDAScaleFilter filter_uv
generic filter weights for func_uv
const AVPixFmtDescriptor * dst_desc
sample format written
Link properties exposed to filter code, but not external callers.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
Represents a computed filter kernel.
enum AVPixelFormat format
#define av_malloc_array(a, b)
void(* filter)(uint8_t *src, ptrdiff_t stride, int qscale)
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
static enum AVPixelFormat supported_formats[]
static int cudascale_filter_set_init(AVFilterContext *ctx, CUDAScaleFilterSet *set, int in_width, int in_height, int normalize_crop)
static int inter_buf_init(AVFilterContext *ctx, CUDATex *tex, int width, int height, int log2_chroma_w, int log2_chroma_h, int nb_planes, const int depths[4], const int channels[4], int use_float, unsigned int planes)
static double cudascale_plane_virtual_size(int src_size, int in_size, int out_size, int in_sub, int out_sub)
@ CUDA_SCALE_PLANE_PRIMARY
@ CUDA_SCALE_PLANE_CHROMA
static int call_resize_kernel(AVFilterContext *ctx, const CUDAScalePass *pass, CUfunction func, const CUDAScaleFilter *filter, const CUtexObject src_tex[4], int src_left, int src_top, int src_width, int src_height, const CUdeviceptr out_data[4], int dst_width, int dst_height, int dst_pitch, int mpeg_range)
static int cudascale_plane_needs_scale(int in_size, int out_size, int in_sub, int out_sub)
static av_cold int cudascale_setup_filters(AVFilterContext *ctx, int in_width, int in_height)
static int cudascale_conflicts(int in, int out, int unspecified)
static int cudascale_filter_init(AVFilterContext *ctx, CUDAScaleFilter *f, int src_size, int dst_size, double virtual_size, int needs_scale)
static int cudascale_plane_is_downscaled(int in_size, int out_size, int in_sub, int out_sub)
static av_cold int init_hwframe_ctx(CUDAScaleContext *s, AVBufferRef *device_ctx, int width, int height)
static av_cold void cudascale_uninit(AVFilterContext *ctx)
static int cudascale_frame_geometry(AVFilterContext *ctx, const AVFrame *frame, int *width, int *height, int *normalize_crop)
static int cudascale_scale(AVFilterContext *ctx, AVFrame *out, AVFrame *in, int in_width, int in_height, int normalize_crop)
static av_cold int cudascale_config_props(AVFilterLink *outlink)
static av_cold int init_processing_chain(AVFilterContext *ctx, int in_width, int in_height, int out_width, int out_height)
static int compute_yuv2rgb_matrix(void *log_ctx, CUDAScaleColorMatrix *mat, enum AVColorSpace colorspace, bool limited_range)
static int cudascale_conv_set_init(AVFilterContext *ctx, CUDAScaleFilterSet *set, int in_width, int in_height)
static av_cold int cudascale_init(AVFilterContext *ctx)
static const AVClass cudascale_class
static int compute_rgb2yuv_matrix(void *log_ctx, CUDAScaleColorMatrix *mat, enum AVColorSpace colorspace, bool limited_range)
static av_cold int cudascale_load_functions(AVFilterContext *ctx)
static const char * get_format_name(enum AVPixelFormat fmt)
static int cudascale_run_pass(AVFilterContext *ctx, const CUDAScalePass *pass, const CUDATex *out, const CUDATex *in)
static void filter_set_uninit(CudaFunctions *cu, CUDAScaleFilterSet *set)
static void cuda_tex_uninit(CudaFunctions *cu, CUDATex *t)
static int format_is_supported(enum AVPixelFormat fmt)
static void cudascale_describe_frame(AVFilterContext *ctx, AVFrame *frame)
static int cudascale_query_formats(const AVFilterContext *ctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
static av_cold void set_format_info(AVFilterContext *ctx, enum AVPixelFormat in_format, enum AVPixelFormat out_format)
static AVFrame * cudascale_get_video_buffer(AVFilterLink *inlink, int w, int h)
static int chroma_uses_luma_span(enum AVColorSpace colorspace)
#define CUDA_SCALE_MAX_PASSES
static void cudascale_plan_passes(CUDAScalePassPlan *plan, int in_width, int in_height, int out_width, int out_height, int in_sub_x, int in_sub_y, int out_sub_x, int out_sub_y, int has_chroma)
static int cudascale_prepare_filter_set(AVFilterContext *ctx, int in_width, int in_height, int normalize_crop)
static int cuda_tex_map_frame(AVFilterContext *ctx, const AVFrame *frame, const int depths[4], const int channels[4], CUDATex *tex, int use_linear, int as_integer)
static void filter_uninit(CudaFunctions *cu, CUDAScaleFilter *filter)
static int cudascale_filter_frame(AVFilterLink *link, AVFrame *in)
static const AVFilterPad cudascale_outputs[]
static const AVFilterPad cudascale_inputs[]
static AVFilterFormats * cudascale_yuv_color_spaces(void)
#define SCALE_CUDA_PARAM_DEFAULT
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
AVFrame * ff_default_get_video_buffer(AVFilterLink *link, int w, int h)