Skip to content

Commit 524caec

Browse files
yangsen5xiaoxiang781216
authored andcommitted
nxcodec: Modify the logic of judging the correctness of the incoming pixformat
Signed-off-by: yangsen5 <[email protected]>
1 parent dad9b5a commit 524caec

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

system/nxcodec/nxcodec.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,6 @@ int nxcodec_init(FAR nxcodec_t *codec)
114114
goto err0;
115115
}
116116

117-
if (codec->output.fdesc.pixelformat !=
118-
codec->output.format.fmt.pix.pixelformat)
119-
{
120-
ret = -EINVAL;
121-
goto err0;
122-
}
123-
124117
codec->output.format.type = codec->output.type;
125118

126119
ret = nxcodec_context_set_format(&codec->output);
@@ -138,13 +131,6 @@ int nxcodec_init(FAR nxcodec_t *codec)
138131
goto err0;
139132
}
140133

141-
if (codec->capture.fdesc.pixelformat !=
142-
codec->capture.format.fmt.pix.pixelformat)
143-
{
144-
ret = -EINVAL;
145-
goto err1;
146-
}
147-
148134
codec->capture.format.type = codec->capture.type;
149135

150136
ret = nxcodec_context_set_format(&codec->capture);

system/nxcodec/nxcodec_context.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,29 @@ int nxcodec_context_dequeue_frame(FAR nxcodec_context_t *ctx)
265265
int nxcodec_context_get_format(FAR nxcodec_context_t *ctx)
266266
{
267267
FAR nxcodec_t *codec = nxcodec_context_to_nxcodec(ctx);
268+
struct v4l2_fmtdesc fdesc;
269+
int ret;
270+
271+
fdesc.type = ctx->type;
268272

269-
memset(&ctx->fdesc, 0, sizeof(ctx->fdesc));
270-
ctx->fdesc.type = ctx->type;
273+
while (true)
274+
{
275+
ret = ioctl(codec->fd, VIDIOC_ENUM_FMT, &fdesc);
276+
if (ret < 0)
277+
{
278+
return -errno;
279+
}
280+
281+
if (fdesc.pixelformat == ctx->format.fmt.pix.pixelformat)
282+
{
283+
break;
284+
}
285+
286+
fdesc.index++;
287+
}
271288

272-
return ioctl(codec->fd, VIDIOC_ENUM_FMT, &ctx->fdesc) < 0 ? -errno : 0;
289+
ctx->format.type = ctx->type;
290+
return ioctl(codec->fd, VIDIOC_TRY_FMT, &ctx->format) < 0 ? -errno : 0;
273291
}
274292

275293
int nxcodec_context_set_format(FAR nxcodec_context_t *ctx)

system/nxcodec/nxcodec_context.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ typedef struct nxcodec_context_s
4545
int fd;
4646
enum v4l2_buf_type type;
4747
struct v4l2_format format;
48-
struct v4l2_fmtdesc fdesc;
4948
FAR nxcodec_context_buf_t *buf;
5049
int nbuffers;
5150
} nxcodec_context_t;

0 commit comments

Comments
 (0)