Skip to content

Commit

Permalink
Fix some warnings-as-errors in GCC 14
Browse files Browse the repository at this point in the history
Signed-off-by: nyanmisaka <[email protected]>
  • Loading branch information
nyanmisaka committed May 22, 2024
1 parent 5234bdc commit 60c9db4
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 92 deletions.
29 changes: 13 additions & 16 deletions debian/patches/0005-add-cuda-tonemap-impl.patch
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Index: jellyfin-ffmpeg/libavfilter/colorspace.c
void ff_matrix_mul_3x3(double dst[3][3],
const double src1[3][3], const double src2[3][3])
{
@@ -191,3 +203,157 @@ void ff_update_hdr_metadata(AVFrame *in,
@@ -191,3 +203,155 @@ void ff_update_hdr_metadata(AVFrame *in,
metadata->max_luminance = av_d2q(peak * REFERENCE_WHITE, 10000);
}
}
Expand Down Expand Up @@ -183,8 +183,7 @@ Index: jellyfin-ffmpeg/libavfilter/colorspace.c
+// linearizer for PQ/ST2084
+float eotf_st2084_common(float x)
+{
+ x = FFMAX(x, 0.0f);
+ float xpow = powf(x, 1.0f / ST2084_M2);
+ float xpow = powf(FFMAX(x, 0.0f), 1.0f / ST2084_M2);
+ float num = FFMAX(xpow - ST2084_C1, 0.0f);
+ float den = FFMAX(ST2084_C2 - ST2084_C3 * xpow, FLOAT_EPS);
+ x = powf(num / den, 1.0f / ST2084_M1);
Expand All @@ -199,8 +198,7 @@ Index: jellyfin-ffmpeg/libavfilter/colorspace.c
+// delinearizer for PQ/ST2084
+float inverse_eotf_st2084_common(float x)
+{
+ x = FFMAX(x, 0.0f);
+ float xpow = powf(x, ST2084_M1);
+ float xpow = powf(FFMAX(x, 0.0f), ST2084_M1);
+#if 0
+ // Original formulation from SMPTE ST 2084:2014 publication.
+ float num = ST2084_C1 + ST2084_C2 * xpow;
Expand Down Expand Up @@ -599,7 +597,7 @@ Index: jellyfin-ffmpeg/libavfilter/cuda/host_util.c
===================================================================
--- /dev/null
+++ jellyfin-ffmpeg/libavfilter/cuda/host_util.c
@@ -0,0 +1,78 @@
@@ -0,0 +1,77 @@
+/*
+ * This file is part of FFmpeg.
+ *
Expand Down Expand Up @@ -637,15 +635,14 @@ Index: jellyfin-ffmpeg/libavfilter/cuda/host_util.c
+ dst->data[i] = src->data[i];
+ dst->linesize[i] = src->linesize[i];
+ dst->tex[i] = 0;
+ }
+
+ if (!make_cuTex)
+ continue;
+
+ for (i = 0; make_cuTex && (i < dst->planes); i++) {
+#ifndef CU_TRSF_NORMALIZED_COORDINATES
+ #define CU_TRSF_NORMALIZED_COORDINATES 2
+#endif
+ CUDA_TEXTURE_DESC tex_desc = {
+ .addressMode = CU_TR_ADDRESS_MODE_CLAMP,
+ .addressMode = { CU_TR_ADDRESS_MODE_CLAMP },
+ .filterMode = i == 0 ? CU_TR_FILTER_MODE_POINT : CU_TR_FILTER_MODE_LINEAR,
+ .flags = i == 0 ? 0 : CU_TRSF_NORMALIZED_COORDINATES,
+ };
Expand Down Expand Up @@ -1688,7 +1685,7 @@ Index: jellyfin-ffmpeg/libavfilter/vf_tonemap_cuda.c
+ return AVERROR(ENOMEM);
+
+ s->dovi = NULL;
+ s->doviBuffer = NULL;
+ s->doviBuffer = 0;
+
+ return 0;
+}
Expand Down Expand Up @@ -1786,7 +1783,7 @@ Index: jellyfin-ffmpeg/libavfilter/vf_tonemap_cuda.c
+ #define CU_TRSF_NORMALIZED_COORDINATES 2
+#endif
+ CUDA_TEXTURE_DESC tex_desc = {
+ .addressMode = CU_TR_ADDRESS_MODE_WRAP,
+ .addressMode = { CU_TR_ADDRESS_MODE_WRAP },
+ .filterMode = CU_TR_FILTER_MODE_POINT,
+ .flags = CU_TRSF_NORMALIZED_COORDINATES,
+ };
Expand Down Expand Up @@ -2270,13 +2267,13 @@ Index: jellyfin-ffmpeg/libavfilter/vf_tonemap_cuda.c
+ if (ret < 0)
+ goto fail;
+
+ ret = CHECK_CU(cu->cuLinkAddData(link_state, CU_JIT_INPUT_PTX, constants.str,
+ constants.len, "constants", 0, NULL, NULL));
+ ret = CHECK_CU(cu->cuLinkAddData(link_state, CU_JIT_INPUT_PTX, (void *)constants.str,
+ (size_t)constants.len, "constants", 0, NULL, NULL));
+ if (ret < 0)
+ goto fail2;
+
+ ret = CHECK_CU(cu->cuLinkAddData(link_state, CU_JIT_INPUT_PTX, ff_tonemap_ptx_data,
+ ff_tonemap_ptx_len, "ff_tonemap_ptx_data", 0, NULL, NULL));
+ ret = CHECK_CU(cu->cuLinkAddData(link_state, CU_JIT_INPUT_PTX, (void *)ff_tonemap_ptx_data,
+ (size_t)ff_tonemap_ptx_len, "ff_tonemap_ptx_data", 0, NULL, NULL));
+ if (ret < 0)
+ goto fail2;
+
Expand Down
37 changes: 17 additions & 20 deletions debian/patches/0006-add-amf-refactor-and-hevc-10-bit-encoding.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1132,23 +1132,20 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c
break;
case AV_CODEC_ID_AV1:
buffer->pVtbl->GetProperty(buffer, AMF_VIDEO_ENCODER_AV1_OUTPUT_FRAME_TYPE, &var);
@@ -476,44 +368,27 @@ static int amf_copy_buffer(AVCodecContex
@@ -476,7 +368,6 @@ static int amf_copy_buffer(AVCodecContex

pkt->pts = var.int64Value; // original pts

-
- AMF_RETURN_IF_FALSE(ctx, av_fifo_read(ctx->timestamp_list, &timestamp, 1) >= 0,
- AVERROR_UNKNOWN, "timestamp_list is empty\n");
+ AMF_RETURN_IF_FALSE(ctx, av_fifo_read(ctx->timestamp_list, &timestamp, 1) >= 0, AVERROR_UNKNOWN, "timestamp_list is empty\n");
AMF_RETURN_IF_FALSE(ctx, av_fifo_read(ctx->timestamp_list, &timestamp, 1) >= 0,
AVERROR_UNKNOWN, "timestamp_list is empty\n");

// calc dts shift if max_b_frames > 0
if (avctx->max_b_frames > 0 && ctx->dts_delay == 0) {
int64_t timestamp_last = AV_NOPTS_VALUE;
@@ -486,34 +377,20 @@ static int amf_copy_buffer(AVCodecContex
size_t can_read = av_fifo_can_read(ctx->timestamp_list);

- AMF_RETURN_IF_FALSE(ctx, can_read > 0, AVERROR_UNKNOWN,
AMF_RETURN_IF_FALSE(ctx, can_read > 0, AVERROR_UNKNOWN,
- "timestamp_list is empty while max_b_frames = %d\n", avctx->max_b_frames);
+ AMF_RETURN_IF_FALSE(ctx, can_read > 0, AVERROR_UNKNOWN, AVERROR_UNKNOWN, "timestamp_list is empty while max_b_frames = %d\n", avctx->max_b_frames);
+ "timestamp_list is empty while max_b_frames = %d\n", avctx->max_b_frames);
+
av_fifo_peek(ctx->timestamp_list, &timestamp_last, 1, can_read - 1);
- if (timestamp < 0 || timestamp_last < AV_NOPTS_VALUE) {
Expand Down Expand Up @@ -1184,7 +1181,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c
{
AMF_RESULT res;
AMFVariantStruct var;
@@ -527,15 +402,16 @@ static AMF_RESULT amf_set_property_buffe
@@ -527,15 +404,16 @@ static AMF_RESULT amf_set_property_buffe
res = AMFVariantAssignInterface(&var, amf_interface);
amf_interface->pVtbl->Release(amf_interface);
}
Expand All @@ -1204,7 +1201,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c
{
AMF_RESULT res;
AMFVariantStruct var;
@@ -583,9 +459,60 @@ static void amf_release_buffer_with_fram
@@ -583,9 +461,60 @@ static void amf_release_buffer_with_fram
frame_ref_storage_buffer->pVtbl->Release(frame_ref_storage_buffer);
}

Expand Down Expand Up @@ -1266,7 +1263,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c
AMFSurface *surface;
AMF_RESULT res;
int ret;
@@ -612,10 +539,9 @@ int ff_amf_receive_packet(AVCodecContext
@@ -612,10 +541,9 @@ int ff_amf_receive_packet(AVCodecContext
if (res == AMF_INPUT_FULL) {
ctx->delayed_drain = 1; // input queue is full: resubmit Drain() in ff_amf_receive_packet
} else {
Expand All @@ -1279,7 +1276,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c
}
}
}
@@ -631,13 +557,10 @@ int ff_amf_receive_packet(AVCodecContext
@@ -631,13 +559,10 @@ int ff_amf_receive_packet(AVCodecContext
ID3D11Texture2D *texture = (ID3D11Texture2D*)frame->data[0]; // actual texture
int index = (intptr_t)frame->data[1]; // index is a slice in texture array is - set to tell AMF which slice to use

Expand All @@ -1295,7 +1292,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c

hw_surface = 1;
}
@@ -648,8 +571,8 @@ int ff_amf_receive_packet(AVCodecContext
@@ -648,8 +573,8 @@ int ff_amf_receive_packet(AVCodecContext
{
IDirect3DSurface9 *texture = (IDirect3DSurface9 *)frame->data[3]; // actual texture

Expand All @@ -1306,7 +1303,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c

hw_surface = 1;
}
@@ -657,8 +580,8 @@ int ff_amf_receive_packet(AVCodecContext
@@ -657,8 +582,8 @@ int ff_amf_receive_packet(AVCodecContext
#endif
default:
{
Expand All @@ -1317,7 +1314,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c
amf_copy_surface(avctx, frame, surface);
}
break;
@@ -670,28 +593,49 @@ int ff_amf_receive_packet(AVCodecContext
@@ -670,28 +595,49 @@ int ff_amf_receive_packet(AVCodecContext
// input HW surfaces can be vertically aligned by 16; tell AMF the real size
surface->pVtbl->SetCrop(surface, 0, 0, frame->width, frame->height);

Expand Down Expand Up @@ -1376,7 +1373,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c
}

// submit surface
@@ -702,7 +646,7 @@ int ff_amf_receive_packet(AVCodecContext
@@ -702,7 +648,7 @@ int ff_amf_receive_packet(AVCodecContext
} else {
int64_t pts = frame->pts;
surface->pVtbl->Release(surface);
Expand All @@ -1385,15 +1382,15 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c

av_frame_unref(frame);
ret = av_fifo_write(ctx->timestamp_list, &pts, 1);
@@ -711,7 +655,6 @@ int ff_amf_receive_packet(AVCodecContext
@@ -711,7 +657,6 @@ int ff_amf_receive_packet(AVCodecContext
}
}

-
do {
block_and_wait = 0;
// poll data
@@ -728,23 +671,37 @@ int ff_amf_receive_packet(AVCodecContext
@@ -728,23 +673,37 @@ int ff_amf_receive_packet(AVCodecContext
if (data->pVtbl->HasProperty(data, L"av_frame_ref")) {
AMFBuffer *frame_ref_storage_buffer;
res = amf_get_property_buffer(data, L"av_frame_ref", &frame_ref_storage_buffer);
Expand Down Expand Up @@ -1434,7 +1431,7 @@ Index: jellyfin-ffmpeg/libavcodec/amfenc.c

ret = av_fifo_write(ctx->timestamp_list, &pts, 1);
if (ret < 0)
@@ -757,24 +714,26 @@ int ff_amf_receive_packet(AVCodecContext
@@ -757,24 +716,26 @@ int ff_amf_receive_packet(AVCodecContext
if (res != AMF_INPUT_FULL) {
ctx->delayed_drain = 0;
ctx->eof = 1; // drain started
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,23 @@ Index: jellyfin-ffmpeg/libavfilter/opencl/scale.cl
+#endif
+}
+#endif
Index: jellyfin-ffmpeg/libavfilter/opencl_source.h
===================================================================
--- jellyfin-ffmpeg.orig/libavfilter/opencl_source.h
+++ jellyfin-ffmpeg/libavfilter/opencl_source.h
@@ -27,6 +27,7 @@ extern const char *ff_opencl_source_desh
extern const char *ff_opencl_source_neighbor;
extern const char *ff_opencl_source_nlmeans;
extern const char *ff_opencl_source_overlay;
+extern const char *ff_opencl_source_scale;
extern const char *ff_opencl_source_pad;
extern const char *ff_opencl_source_remap;
extern const char *ff_opencl_source_tonemap;
Index: jellyfin-ffmpeg/libavfilter/vf_scale_opencl.c
===================================================================
--- /dev/null
+++ jellyfin-ffmpeg/libavfilter/vf_scale_opencl.c
@@ -0,0 +1,770 @@
@@ -0,0 +1,776 @@
+/*
+ * Copyright (c) 2018 Gabriel Machado
+ * Copyright (c) 2021 NyanMisaka
Expand Down Expand Up @@ -664,8 +676,6 @@ Index: jellyfin-ffmpeg/libavfilter/vf_scale_opencl.c
+ }
+
+ if (ctx->in_desc->comp[0].depth > ctx->out_desc->comp[0].depth) {
+ av_assert0(sizeof(ff_fruit_dither_matrix) == sizeof(ff_fruit_dither_matrix[0]) * ff_fruit_dither_size * ff_fruit_dither_size);
+
+ cl_image_format image_format = {
+ .image_channel_data_type = CL_UNORM_INT16,
+ .image_channel_order = CL_R,
Expand All @@ -677,6 +687,8 @@ Index: jellyfin-ffmpeg/libavfilter/vf_scale_opencl.c
+ .image_row_pitch = 0,
+ };
+
+ av_assert0(sizeof(ff_fruit_dither_matrix) == sizeof(ff_fruit_dither_matrix[0]) * ff_fruit_dither_size * ff_fruit_dither_size);
+
+ ctx->dither_image = clCreateImage(ctx->ocf.hwctx->context, CL_MEM_READ_ONLY,
+ &image_format, &image_desc, NULL, &cle);
+ if (!ctx->dither_image) {
Expand Down Expand Up @@ -796,8 +808,8 @@ Index: jellyfin-ffmpeg/libavfilter/vf_scale_opencl.c
+ ff_scale_adjust_dimensions(inlink, &ctx->dst_w, &ctx->dst_h,
+ ctx->force_original_aspect_ratio, ctx->force_divisible_by);
+
+ if (((int64_t)(ctx->dst_h * inlink->w)) > INT_MAX ||
+ ((int64_t)(ctx->dst_w * inlink->h)) > INT_MAX)
+ if (((int64_t)ctx->dst_h * inlink->w) > INT_MAX ||
+ ((int64_t)ctx->dst_w * inlink->h) > INT_MAX)
+ av_log(ctx, AV_LOG_ERROR, "Rescaled value for width or height is too big.\n");
+
+ ctx->src_w = inlink->w;
Expand Down Expand Up @@ -894,12 +906,15 @@ Index: jellyfin-ffmpeg/libavfilter/vf_scale_opencl.c
+ CL_SET_KERNEL_ARG(ctx->kernel, 3, cl_mem, &input->data[1]);
+
+ idx_arg1 = 4;
+ if (ctx->out_planes > 2)
+ if (ctx->out_planes > 2) {
+ CL_SET_KERNEL_ARG(ctx->kernel, idx_arg1++, cl_mem, &output->data[2]);
+ if (ctx->in_planes > 2)
+ }
+ if (ctx->in_planes > 2) {
+ CL_SET_KERNEL_ARG(ctx->kernel, idx_arg1++, cl_mem, &input->data[2]);
+ if (ctx->dither_image)
+ }
+ if (ctx->dither_image) {
+ CL_SET_KERNEL_ARG(ctx->kernel, idx_arg1++, cl_mem, &ctx->dither_image);
+ }
+
+ // conv_yuv
+ global_work[0] = output->width / x_subsample;
Expand All @@ -917,14 +932,17 @@ Index: jellyfin-ffmpeg/libavfilter/vf_scale_opencl.c
+ CL_SET_KERNEL_ARG(ctx->kernel_uv, 1, cl_mem, &input->data[1]);
+
+ idx_arg1 = 2;
+ if (ctx->out_planes > 2)
+ if (ctx->out_planes > 2) {
+ CL_SET_KERNEL_ARG(ctx->kernel_uv, idx_arg1++, cl_mem, &output->data[2]);
+ if (ctx->in_planes > 2)
+ }
+ if (ctx->in_planes > 2) {
+ CL_SET_KERNEL_ARG(ctx->kernel_uv, idx_arg1++, cl_mem, &input->data[2]);
+ }
+
+ idx_arg2 = 2;
+ if (ctx->dither_image)
+ if (ctx->dither_image) {
+ CL_SET_KERNEL_ARG(ctx->kernel, idx_arg2++, cl_mem, &ctx->dither_image);
+ }
+ if (ctx->algorithm != F_NEIGHBOR) {
+ CL_SET_KERNEL_ARG(ctx->kernel, idx_arg2++, cl_mem, &ctx->cx);
+ CL_SET_KERNEL_ARG(ctx->kernel, idx_arg2++, cl_mem, &ctx->cy);
Expand Down Expand Up @@ -1090,15 +1108,3 @@ Index: jellyfin-ffmpeg/libavfilter/vf_scale_opencl.c
+ FILTER_SINGLE_PIXFMT(AV_PIX_FMT_OPENCL),
+ .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
+};
Index: jellyfin-ffmpeg/libavfilter/opencl_source.h
===================================================================
--- jellyfin-ffmpeg.orig/libavfilter/opencl_source.h
+++ jellyfin-ffmpeg/libavfilter/opencl_source.h
@@ -27,6 +27,7 @@ extern const char *ff_opencl_source_desh
extern const char *ff_opencl_source_neighbor;
extern const char *ff_opencl_source_nlmeans;
extern const char *ff_opencl_source_overlay;
+extern const char *ff_opencl_source_scale;
extern const char *ff_opencl_source_pad;
extern const char *ff_opencl_source_remap;
extern const char *ff_opencl_source_tonemap;
Loading

0 comments on commit 60c9db4

Please sign in to comment.