From 3198acc472931e6f215adc6c669621e1cc91bbf0 Mon Sep 17 00:00:00 2001 From: Alex Bee Date: Mon, 11 Oct 2021 15:28:23 +0200 Subject: [PATCH] Rockchip: ffmpeg: v4l2request: support validating framesizes supported by the driver --- ...equest-validate-supported-framesizes.patch | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 projects/Rockchip/patches/ffmpeg/ffmpeg-0001-v4l2_request-validate-supported-framesizes.patch diff --git a/projects/Rockchip/patches/ffmpeg/ffmpeg-0001-v4l2_request-validate-supported-framesizes.patch b/projects/Rockchip/patches/ffmpeg/ffmpeg-0001-v4l2_request-validate-supported-framesizes.patch new file mode 100644 index 0000000000..cc79cde7f4 --- /dev/null +++ b/projects/Rockchip/patches/ffmpeg/ffmpeg-0001-v4l2_request-validate-supported-framesizes.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Alex Bee +Date: Sun, 19 Sep 2021 13:10:55 +0200 +Subject: [PATCH] v4l2_request: validate supported framesizes + +Signed-off-by: Alex Bee +--- + libavcodec/v4l2_request.c | 38 +++++++++++++++++++++++++++++++++++++- + 1 file changed, 37 insertions(+), 1 deletion(-) + +diff --git a/libavcodec/v4l2_request.c b/libavcodec/v4l2_request.c +index a8f0ee79ee..2fbe166341 100644 +--- a/libavcodec/v4l2_request.c ++++ b/libavcodec/v4l2_request.c +@@ -376,6 +376,42 @@ int ff_v4l2_request_decode_frame(AVCodecContext *avctx, AVFrame *frame, struct v + return v4l2_request_queue_decode(avctx, frame, control, count, 1, 1); + } + ++static int v4l2_request_try_framesize(AVCodecContext *avctx, uint32_t pixelformat) ++{ ++ V4L2RequestContext *ctx = avctx->internal->hwaccel_priv_data; ++ struct v4l2_frmsizeenum frmsize = { ++ .index = 0, ++ .pixel_format = pixelformat, ++ }; ++ ++ if (ioctl(ctx->video_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) < 0) ++ return 0; ++ ++ /* ++ * We only validate min/max framesize for V4L2_FRMSIZE_TYPE_STEPWISE here, since the alignment ++ * which is eventually needed will be done driver-side later in VIDIOC_S_FMT and there is no need ++ * validate step_width/step_height here ++ */ ++ ++ do { ++ ++ if (frmsize.type == V4L2_FRMSIZE_TYPE_DISCRETE && frmsize.discrete.width == avctx->coded_width && ++ frmsize.discrete.height == avctx->coded_height) ++ return 0; ++ else if ((frmsize.type == V4L2_FRMSIZE_TYPE_STEPWISE || frmsize.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) && ++ avctx->coded_width >= frmsize.stepwise.min_width && avctx->coded_height >= frmsize.stepwise.min_height && ++ avctx->coded_width <= frmsize.stepwise.max_width && avctx->coded_height <= frmsize.stepwise.max_height) ++ return 0; ++ ++ frmsize.index++; ++ ++ } while (ioctl(ctx->video_fd, VIDIOC_ENUM_FRAMESIZES, &frmsize) >= 0); ++ ++ av_log(avctx, AV_LOG_INFO, "%s: pixelformat %u not supported for width %u height %u\n", __func__, pixelformat, avctx->coded_width, avctx->coded_height); ++ ++ return -1; ++} ++ + static int v4l2_request_try_format(AVCodecContext *avctx, enum v4l2_buf_type type, uint32_t pixelformat) + { + V4L2RequestContext *ctx = avctx->internal->hwaccel_priv_data; +@@ -404,7 +440,7 @@ static int v4l2_request_try_format(AVCodecContext *avctx, enum v4l2_buf_type typ + + while (ioctl(ctx->video_fd, VIDIOC_ENUM_FMT, &fmtdesc) >= 0) { + if (fmtdesc.pixelformat == pixelformat) +- return 0; ++ return v4l2_request_try_framesize(avctx, pixelformat); + + fmtdesc.index++; + }