From 91a10d7c9e3f3a03872c953f5b497ee96af21f1b Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 18 Jun 2018 11:33:06 +0200 Subject: [PATCH] v4l2: Check device node Check the device node on init. Only remove the source once --- spa/plugins/v4l2/v4l2-source.c | 4 ++++ spa/plugins/v4l2/v4l2-utils.c | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/spa/plugins/v4l2/v4l2-source.c b/spa/plugins/v4l2/v4l2-source.c index 27394f01c..1c4651c0d 100644 --- a/spa/plugins/v4l2/v4l2-source.c +++ b/spa/plugins/v4l2/v4l2-source.c @@ -993,6 +993,7 @@ impl_init(const struct spa_handle_factory *factory, uint32_t i; const char *str; struct port *port; + int res; spa_return_val_if_fail(factory != NULL, -EINVAL); spa_return_val_if_fail(handle != NULL, -EINVAL); @@ -1042,6 +1043,9 @@ impl_init(const struct spa_handle_factory *factory, if (info && (str = spa_dict_lookup(info, "device.path"))) { strncpy(this->props.device, str, 63); + if ((res = spa_v4l2_open(this)) < 0) + return res; + spa_v4l2_close(this); } return 0; diff --git a/spa/plugins/v4l2/v4l2-utils.c b/spa/plugins/v4l2/v4l2-utils.c index b8dcaa644..e3cac0e52 100644 --- a/spa/plugins/v4l2/v4l2-utils.c +++ b/spa/plugins/v4l2/v4l2-utils.c @@ -1194,8 +1194,9 @@ static void v4l2_on_fd_events(struct spa_source *source) if (source->rmask & SPA_IO_ERR) { struct port *port = &this->out_ports[0]; - spa_log_error(this->log, "v4l2 %p: error %d", this, source->rmask); - spa_loop_remove_source(port->data_loop, &port->source); + spa_log_error(this->log, "v4l2 %p: error %08x", this, source->rmask); + if (port->source.loop) + spa_loop_remove_source(port->data_loop, &port->source); return; } @@ -1471,7 +1472,8 @@ static int do_remove_source(struct spa_loop *loop, void *user_data) { struct port *port = user_data; - spa_loop_remove_source(port->data_loop, &port->source); + if (port->source.loop) + spa_loop_remove_source(port->data_loop, &port->source); return 0; }