mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	spa: v4l2: get the device number of the v4l2 device
This value can be used in filtering the camera devices in consultation with libcamera
This commit is contained in:
		
							parent
							
								
									79518d13ae
								
							
						
					
					
						commit
						6cd29aed05
					
				
					 2 changed files with 10 additions and 3 deletions
				
			
		| 
						 | 
					@ -29,6 +29,7 @@ static const char default_device[] = "/dev/video0";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct props {
 | 
					struct props {
 | 
				
			||||||
	char device[64];
 | 
						char device[64];
 | 
				
			||||||
 | 
						char devnum[32];
 | 
				
			||||||
	char product_id[6];
 | 
						char product_id[6];
 | 
				
			||||||
	char vendor_id[6];
 | 
						char vendor_id[6];
 | 
				
			||||||
	int device_fd;
 | 
						int device_fd;
 | 
				
			||||||
| 
						 | 
					@ -55,7 +56,7 @@ struct impl {
 | 
				
			||||||
static int emit_info(struct impl *this, bool full)
 | 
					static int emit_info(struct impl *this, bool full)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int res;
 | 
						int res;
 | 
				
			||||||
	struct spa_dict_item items[12];
 | 
						struct spa_dict_item items[13];
 | 
				
			||||||
	uint32_t n_items = 0;
 | 
						uint32_t n_items = 0;
 | 
				
			||||||
	struct spa_device_info info;
 | 
						struct spa_device_info info;
 | 
				
			||||||
	struct spa_param_info params[2];
 | 
						struct spa_param_info params[2];
 | 
				
			||||||
| 
						 | 
					@ -78,6 +79,7 @@ static int emit_info(struct impl *this, bool full)
 | 
				
			||||||
	if (this->props.vendor_id[0])
 | 
						if (this->props.vendor_id[0])
 | 
				
			||||||
		ADD_ITEM(SPA_KEY_DEVICE_VENDOR_ID, this->props.vendor_id);
 | 
							ADD_ITEM(SPA_KEY_DEVICE_VENDOR_ID, this->props.vendor_id);
 | 
				
			||||||
	ADD_ITEM(SPA_KEY_API_V4L2_PATH, (char *)this->props.device);
 | 
						ADD_ITEM(SPA_KEY_API_V4L2_PATH, (char *)this->props.device);
 | 
				
			||||||
 | 
						ADD_ITEM(SPA_KEY_DEVICE_DEVIDS, (char *)this->props.devnum);
 | 
				
			||||||
	ADD_ITEM(SPA_KEY_API_V4L2_CAP_DRIVER, (char *)this->dev.cap.driver);
 | 
						ADD_ITEM(SPA_KEY_API_V4L2_CAP_DRIVER, (char *)this->dev.cap.driver);
 | 
				
			||||||
	ADD_ITEM(SPA_KEY_API_V4L2_CAP_CARD, (char *)this->dev.cap.card);
 | 
						ADD_ITEM(SPA_KEY_API_V4L2_CAP_CARD, (char *)this->dev.cap.card);
 | 
				
			||||||
	ADD_ITEM(SPA_KEY_API_V4L2_CAP_BUS_INFO, (char *)this->dev.cap.bus_info);
 | 
						ADD_ITEM(SPA_KEY_API_V4L2_CAP_BUS_INFO, (char *)this->dev.cap.bus_info);
 | 
				
			||||||
| 
						 | 
					@ -233,6 +235,8 @@ impl_init(const struct spa_handle_factory *factory,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (info && (str = spa_dict_lookup(info, SPA_KEY_API_V4L2_PATH)))
 | 
						if (info && (str = spa_dict_lookup(info, SPA_KEY_API_V4L2_PATH)))
 | 
				
			||||||
		strncpy(this->props.device, str, 63);
 | 
							strncpy(this->props.device, str, 63);
 | 
				
			||||||
 | 
						if (info && (str = spa_dict_lookup(info, SPA_KEY_DEVICE_DEVIDS)))
 | 
				
			||||||
 | 
							strncpy(this->props.devnum, str, 31);
 | 
				
			||||||
	if (info && (str = spa_dict_lookup(info, SPA_KEY_DEVICE_PRODUCT_ID)))
 | 
						if (info && (str = spa_dict_lookup(info, SPA_KEY_DEVICE_PRODUCT_ID)))
 | 
				
			||||||
		strncpy(this->props.product_id, str, 5);
 | 
							strncpy(this->props.product_id, str, 5);
 | 
				
			||||||
	if (info && (str = spa_dict_lookup(info, SPA_KEY_DEVICE_VENDOR_ID)))
 | 
						if (info && (str = spa_dict_lookup(info, SPA_KEY_DEVICE_VENDOR_ID)))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -220,8 +220,9 @@ static int emit_object_info(struct impl *this, struct device *device)
 | 
				
			||||||
	uint32_t id = device->id;
 | 
						uint32_t id = device->id;
 | 
				
			||||||
	struct udev_device *dev = device->dev;
 | 
						struct udev_device *dev = device->dev;
 | 
				
			||||||
	const char *str;
 | 
						const char *str;
 | 
				
			||||||
	struct spa_dict_item items[20];
 | 
						struct spa_dict_item items[21];
 | 
				
			||||||
	uint32_t n_items = 0;
 | 
						uint32_t n_items = 0;
 | 
				
			||||||
 | 
						char devnum[32];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	info = SPA_DEVICE_OBJECT_INFO_INIT();
 | 
						info = SPA_DEVICE_OBJECT_INFO_INIT();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -236,6 +237,8 @@ static int emit_object_info(struct impl *this, struct device *device)
 | 
				
			||||||
	items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_MEDIA_CLASS, "Video/Device");
 | 
						items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_MEDIA_CLASS, "Video/Device");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_PATH, udev_device_get_devnode(dev));
 | 
						items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_API_V4L2_PATH, udev_device_get_devnode(dev));
 | 
				
			||||||
 | 
						snprintf(devnum, sizeof(devnum), "%" PRId64, (int64_t)udev_device_get_devnum(dev));
 | 
				
			||||||
 | 
						items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_DEVIDS, devnum);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if ((str = udev_device_get_property_value(dev, "USEC_INITIALIZED")) && *str)
 | 
						if ((str = udev_device_get_property_value(dev, "USEC_INITIALIZED")) && *str)
 | 
				
			||||||
		items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_PLUGGED_USEC, str);
 | 
							items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_DEVICE_PLUGGED_USEC, str);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue