diff --git a/src/arvv4l2device.c b/src/arvv4l2device.c index 9555c6e48..8598ae157 100644 --- a/src/arvv4l2device.c +++ b/src/arvv4l2device.c @@ -99,6 +99,19 @@ G_DEFINE_TYPE_WITH_CODE (ArvV4l2Device, arv_v4l2_device, ARV_TYPE_DEVICE, G_ADD_ /* ArvV4l2Device implemenation */ +ArvPixelFormat +arv_pixel_format_from_v4l2 (guint32 v4l2_pixel_format) +{ + unsigned int i; + + for (i = 0; i < G_N_ELEMENTS(pixel_format_map); i++) { + if (v4l2_pixel_format == pixel_format_map[i].v4l2) + return pixel_format_map[i].genicam; + } + + return 0; +} + /* ArvDevice implemenation */ static ArvStream * @@ -547,7 +560,7 @@ arv_v4l2_device_constructed (GObject *self) " Pixel format\n"); for (i = 0; TRUE; i++) { - int j, k; + int j; struct v4l2_fmtdesc format = {0}; guint32 genicam_pixel_format = 0; @@ -558,10 +571,7 @@ arv_v4l2_device_constructed (GObject *self) arv_info_device ("Found format %s", format.description); - for (k = 0; k < G_N_ELEMENTS(pixel_format_map); k++) { - if (format.pixelformat == pixel_format_map[k].v4l2) - genicam_pixel_format = pixel_format_map[k].genicam; - } + genicam_pixel_format = arv_pixel_format_from_v4l2(format.pixelformat); g_array_insert_val (priv->pixel_formats, i, genicam_pixel_format); diff --git a/src/arvv4l2deviceprivate.h b/src/arvv4l2deviceprivate.h index e68c42288..00b30cf79 100644 --- a/src/arvv4l2deviceprivate.h +++ b/src/arvv4l2deviceprivate.h @@ -31,9 +31,11 @@ G_BEGIN_DECLS +ArvPixelFormat arv_pixel_format_from_v4l2 (guint32 v4l2_pixel_format); + gboolean arv_v4l2_device_set_image_format (ArvV4l2Device *device); gboolean arv_v4l2_device_get_image_format (ArvV4l2Device *device, - guint32 *payload_size, guint32 *pixel_format, + guint32 *payload_size, ArvPixelFormat *pixel_format, guint32 *width, guint32 *height, guint32 *bytes_per_line); int arv_v4l2_device_get_fd (ArvV4l2Device *v4l2_device); diff --git a/src/arvv4l2interface.c b/src/arvv4l2interface.c index 74728b159..d03bfc05c 100644 --- a/src/arvv4l2interface.c +++ b/src/arvv4l2interface.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include #include @@ -75,22 +75,46 @@ arv_v4l2_interface_device_infos_new (const char *device_file, const char *name) if (v4l2_ioctl (fd, VIDIOC_QUERYCAP, &cap) != -1 && ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) != 0) && ((cap.capabilities & V4L2_CAP_STREAMING) != 0)) { - infos = g_new0 (ArvV4l2InterfaceDeviceInfos, 1); - - infos->ref_count = 1; - infos->id = g_strdup_printf ("%s-%s", (char *) cap.card, name); - infos->bus = g_strdup ((char *) cap.bus_info); - infos->device_file = g_strdup (device_file); - infos->version = g_strdup_printf ("%d.%d.%d", - (cap.version >> 16) & 0xff, - (cap.version >> 8) & 0xff, - (cap.version >> 0) & 0xff); - - return infos; - } - v4l2_close (fd); - } - } + unsigned int i; + gboolean found = FALSE; + + for (i = 0; TRUE; i++) { + struct v4l2_fmtdesc format = {0}; + + format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + format.index = i; + if (v4l2_ioctl(fd, VIDIOC_ENUM_FMT, &format) == -1) + break; + + if (arv_pixel_format_from_v4l2(format.pixelformat) != 0) { + found = TRUE; + break; + } + } + + if (found) { + infos = g_new0 (ArvV4l2InterfaceDeviceInfos, 1); + + infos->ref_count = 1; + infos->id = g_strdup_printf ("%s-%s", (char *) cap.card, name); + infos->bus = g_strdup ((char *) cap.bus_info); + infos->device_file = g_strdup (device_file); + infos->version = g_strdup_printf ("%d.%d.%d", + (cap.version >> 16) & 0xff, + (cap.version >> 8) & 0xff, + (cap.version >> 0) & 0xff); + + v4l2_close (fd); + + return infos; + } + + arv_warning_interface ("No suitable pixel format found for v4l2 device '%s'", + device_file); + } + v4l2_close (fd); + } + } return NULL; }