From 5a262b4bd3b577a775c05bc78db28a796596ec33 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 4 Nov 2022 10:59:13 +0100 Subject: [PATCH] v4l2: return a default format from G_FMT --- pipewire-v4l2/src/pipewire-v4l2.c | 33 +++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/pipewire-v4l2/src/pipewire-v4l2.c b/pipewire-v4l2/src/pipewire-v4l2.c index 2ee2062c5..0db44806d 100644 --- a/pipewire-v4l2/src/pipewire-v4l2.c +++ b/pipewire-v4l2/src/pipewire-v4l2.c @@ -1466,11 +1466,40 @@ static int vidioc_enum_fmt(struct file *file, struct v4l2_fmtdesc *arg) static int vidioc_g_fmt(struct file *file, struct v4l2_format *arg) { + struct param *p; + struct global *g = file->node; + int res; + if (arg->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) return -EINVAL; - *arg = file->v4l2_format; - return 0; + pw_thread_loop_lock(file->loop); + if (file->v4l2_format.fmt.pix.pixelformat != 0) { + *arg = file->v4l2_format; + } else { + struct v4l2_format tmp; + bool found = false; + + spa_list_for_each(p, &g->param_list, link) { + if (p->id != SPA_PARAM_EnumFormat || p->param == NULL) + continue; + + if (param_to_fmt(p->param, &tmp) < 0) + continue; + + found = true; + break; + } + if (!found) { + res = -EINVAL; + goto exit_unlock; + } + *arg = file->v4l2_format = tmp; + } + res = 0; +exit_unlock: + pw_thread_loop_unlock(file->loop); + return res; } static int score_diff(struct v4l2_format *fmt, struct v4l2_format *tmp)