From 524caec5a07266e66cd40d81d096d6afe95ac586 Mon Sep 17 00:00:00 2001 From: yangsen5 Date: Mon, 2 Sep 2024 21:12:37 +0800 Subject: [PATCH] nxcodec: Modify the logic of judging the correctness of the incoming pixformat Signed-off-by: yangsen5 --- system/nxcodec/nxcodec.c | 14 -------------- system/nxcodec/nxcodec_context.c | 24 +++++++++++++++++++++--- system/nxcodec/nxcodec_context.h | 1 - 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/system/nxcodec/nxcodec.c b/system/nxcodec/nxcodec.c index b808b63cf..b019a4f42 100644 --- a/system/nxcodec/nxcodec.c +++ b/system/nxcodec/nxcodec.c @@ -114,13 +114,6 @@ int nxcodec_init(FAR nxcodec_t *codec) goto err0; } - if (codec->output.fdesc.pixelformat != - codec->output.format.fmt.pix.pixelformat) - { - ret = -EINVAL; - goto err0; - } - codec->output.format.type = codec->output.type; ret = nxcodec_context_set_format(&codec->output); @@ -138,13 +131,6 @@ int nxcodec_init(FAR nxcodec_t *codec) goto err0; } - if (codec->capture.fdesc.pixelformat != - codec->capture.format.fmt.pix.pixelformat) - { - ret = -EINVAL; - goto err1; - } - codec->capture.format.type = codec->capture.type; ret = nxcodec_context_set_format(&codec->capture); diff --git a/system/nxcodec/nxcodec_context.c b/system/nxcodec/nxcodec_context.c index d9c3b793d..510112253 100644 --- a/system/nxcodec/nxcodec_context.c +++ b/system/nxcodec/nxcodec_context.c @@ -265,11 +265,29 @@ int nxcodec_context_dequeue_frame(FAR nxcodec_context_t *ctx) int nxcodec_context_get_format(FAR nxcodec_context_t *ctx) { FAR nxcodec_t *codec = nxcodec_context_to_nxcodec(ctx); + struct v4l2_fmtdesc fdesc; + int ret; - memset(&ctx->fdesc, 0, sizeof(ctx->fdesc)); - ctx->fdesc.type = ctx->type; + fdesc.type = ctx->type; - return ioctl(codec->fd, VIDIOC_ENUM_FMT, &ctx->fdesc) < 0 ? -errno : 0; + while (true) + { + ret = ioctl(codec->fd, VIDIOC_ENUM_FMT, &fdesc); + if (ret < 0) + { + return -errno; + } + + if (fdesc.pixelformat == ctx->format.fmt.pix.pixelformat) + { + break; + } + + fdesc.index++; + } + + ctx->format.type = ctx->type; + return ioctl(codec->fd, VIDIOC_TRY_FMT, &ctx->format) < 0 ? -errno : 0; } int nxcodec_context_set_format(FAR nxcodec_context_t *ctx) diff --git a/system/nxcodec/nxcodec_context.h b/system/nxcodec/nxcodec_context.h index 09319e6ff..854fc67aa 100644 --- a/system/nxcodec/nxcodec_context.h +++ b/system/nxcodec/nxcodec_context.h @@ -45,7 +45,6 @@ typedef struct nxcodec_context_s int fd; enum v4l2_buf_type type; struct v4l2_format format; - struct v4l2_fmtdesc fdesc; FAR nxcodec_context_buf_t *buf; int nbuffers; } nxcodec_context_t;