From 38bbee084126b15d39c1bce5cb5d45e6efea64fa Mon Sep 17 00:00:00 2001 From: ArenM Date: Fri, 26 May 2023 11:43:22 -0400 Subject: [PATCH] camera_test: add bridge support (MR 31) --- tools/camera_test.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/camera_test.c b/tools/camera_test.c index ae311c3..6b81da6 100644 --- a/tools/camera_test.c +++ b/tools/camera_test.c @@ -44,7 +44,7 @@ main(int argc, char *argv[]) uint32_t video_entity_id; { const struct media_v2_entity *entity = - mp_device_find_entity(device, video_name); + mp_device_find_entity_type(device, MEDIA_ENT_F_IO_V4L); if (!entity) { printf("Unable to find video device interface\n"); return 1; @@ -68,6 +68,28 @@ main(int argc, char *argv[]) } } + int bridge_fd = -1; + const struct media_v2_entity *bridge = + mp_device_find_entity_type(device, MEDIA_ENT_F_VID_IF_BRIDGE); + if (bridge) { + video_entity_id = bridge->id; + + const struct media_v2_interface *iface = + mp_device_find_entity_interface(device, bridge->id); + + char buf[256]; + if (!mp_find_device_path(iface->devnode, buf, 256)) { + printf("Unable to find bridge device path\n"); + return 1; + } + + bridge_fd = open(buf, O_RDWR); + if (bridge_fd == -1) { + printf("Unable to open bridge device\n"); + return 1; + } + } + int subdev_fd = -1; const struct media_v2_entity *entity = mp_device_find_entity(device, subdev_name); @@ -115,7 +137,7 @@ main(int argc, char *argv[]) printf("Opening the device took %fms\n", (open_end - find_end) * 1000); - MPCamera *camera = mp_camera_new(video_fd, subdev_fd, -1); + MPCamera *camera = mp_camera_new(video_fd, subdev_fd, bridge_fd); MPControlList *controls = mp_camera_list_controls(camera); @@ -199,6 +221,8 @@ main(int argc, char *argv[]) close(video_fd); if (subdev_fd != -1) close(subdev_fd); + if (bridge_fd != -1) + close(bridge_fd); mp_device_close(device);