uvcvideo: Add quirk to force the Oculus DK2 IR tracker to grayscale
Subsystems (2)
PATCH v2 1/1 uvcvideo: Add quirk to force the Oculus DK2 IR tracker to grayscale
This patch adds a quirk to force Y8 pixel format even if the camera reports half-width YUYV.
--- drivers/media/usb/uvc/uvc_driver.c | 29 ++++++++++++++++++++++++++++- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-)
drivers/media/usb/uvc/uvc_driver.c +28 -1
@@ -311,6 +311,7 @@ static int uvc_parse_format(struct uvc_device *dev,struct uvc_format_desc *fmtdesc;struct uvc_frame *frame;const unsigned char *start = buffer; +bool force_yuy2_to_y8 = false;unsigned int interval;unsigned int i, n;__u8 ftype;
@@ -333,6 +334,22 @@ static int uvc_parse_format(struct uvc_device *dev,/* Find the format descriptor from its GUID. */ fmtdesc =uvc_format_by_guid (&buffer[5 ]); + format->bpp = buffer[21 ]; + +if (dev->quirks &UVC_QUIRK_FORCE_Y8 ) { +if (fmtdesc && fmtdesc->fcc ==V4L2_PIX_FMT_YUYV && + format->bpp ==16 ) { + force_yuy2_to_y8 = true; + fmtdesc = &uvc_fmts[9 ]; + format->bpp =8 ; + }else { +uvc_printk (KERN_WARNING , +"Forcing %d-bit %s to %s not supported" , + format->bpp, fmtdesc->name, + uvc_fmts[9 ].name); + } + } +if (fmtdesc !=NULL ) {strlcpy (format->name, fmtdesc->name,sizeof format->name);
@@ -345,7 +362,6 @@ static int uvc_parse_format(struct uvc_device *dev, format->fcc =0 ; } - format->bpp = buffer[21 ];if (buffer[2 ] ==UVC_VS_FORMAT_UNCOMPRESSED ) { ftype =UVC_VS_FRAME_UNCOMPRESSED ; }else {
@@ -455,6 +471,8 @@ static int uvc_parse_format(struct uvc_device *dev, frame->bFrameIndex = buffer[3 ]; frame->bmCapabilities = buffer[4 ]; frame->wWidth =get_unaligned_le16 (&buffer[5 ]); +if (force_yuy2_to_y8) + frame->wWidth *=2 ; frame->wHeight =get_unaligned_le16 (&buffer[7 ]); frame->dwMinBitRate =get_unaligned_le32 (&buffer[9 ]); frame->dwMaxBitRate =get_unaligned_le32 (&buffer[13 ]);
@@ -2467,6 +2485,15 @@ static struct usb_device_id uvc_ids[] = { .bInterfaceProtocol = 0, .driver_info =UVC_QUIRK_PROBE_MINMAX | UVC_QUIRK_IGNORE_SELECTOR_UNIT }, + /* Oculus VR Positional Tracker DK2 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x2833, + .idProduct = 0x0201, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_QUIRK_FORCE_Y8 },/* Generic USB Video Class */ { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) }, {}
drivers/media/usb/uvc/uvcvideo.h +1 -0
@@ -137,6 +137,7 @@#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080#define UVC_QUIRK_PROBE_DEF 0x00000100#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200 +#define UVC_QUIRK_FORCE_Y8 0x00000400/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001
Signature · 1 line
2.0.1
Hi Laurent,
Quoted 4 lines · Philipp Zabel
This patch adds a quirk to force Y8 pixel format even if the camera reports half-width YUYV.
Signed-off-by Philipp Zabel <[email protected]>
do you have any further comments on this patch?
regards
Philipp
Quoted 88 lines
--- drivers/media/usb/uvc/uvc_driver.c | 29 ++++++++++++++++++++++++++++- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-)drivers/media/usb/uvc/uvc_driver.c +28
-1@@ -311,6 +311,7 @@ static int uvc_parse_format(struct uvc_device *dev,struct uvc_format_desc *fmtdesc;struct uvc_frame *frame;const unsigned char *start = buffer; +bool force_yuy2_to_y8 = false;unsigned int interval;unsigned int i, n;__u8 ftype;@@ -333,6 +334,22 @@ static int uvc_parse_format(struct uvc_device *dev,/* Find the format descriptor from its GUID. */ fmtdesc =uvc_format_by_guid (&buffer[5 ]); + format->bpp = buffer[21 ]; + +if (dev->quirks &UVC_QUIRK_FORCE_Y8 ) { +if (fmtdesc && fmtdesc->fcc ==V4L2_PIX_FMT_YUYV && + format->bpp ==16 ) { + force_yuy2_to_y8 = true; + fmtdesc = &uvc_fmts[9 ]; + format->bpp =8 ; + }else { +uvc_printk (KERN_WARNING , +"Forcing %d-bit %s to %s not supported" , + format->bpp, fmtdesc->name, + uvc_fmts[9 ].name); + } + } +if (fmtdesc !=NULL ) {strlcpy (format->name, fmtdesc->name,sizeof format->name);@@ -345,7 +362,6 @@ static int uvc_parse_format(struct uvc_device *dev, format->fcc =0 ; } - format->bpp = buffer[21 ];if (buffer[2 ] ==UVC_VS_FORMAT_UNCOMPRESSED ) { ftype =UVC_VS_FRAME_UNCOMPRESSED ; }else {@@ -455,6 +471,8 @@ static int uvc_parse_format(struct uvc_device *dev, frame->bFrameIndex = buffer[3 ]; frame->bmCapabilities = buffer[4 ]; frame->wWidth =get_unaligned_le16 (&buffer[5 ]); +if (force_yuy2_to_y8) + frame->wWidth *=2 ; frame->wHeight =get_unaligned_le16 (&buffer[7 ]); frame->dwMinBitRate =get_unaligned_le32 (&buffer[9 ]); frame->dwMaxBitRate =get_unaligned_le32 (&buffer[13 ]);@@ -2467,6 +2485,15 @@ static struct usb_device_id uvc_ids[] = { .bInterfaceProtocol = 0, .driver_info =UVC_QUIRK_PROBE_MINMAX | UVC_QUIRK_IGNORE_SELECTOR_UNIT }, + /* Oculus VR Positional Tracker DK2 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x2833, + .idProduct = 0x0201, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_QUIRK_FORCE_Y8 },/* Generic USB Video Class */ { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) }, {}drivers/media/usb/uvc/uvcvideo.h +1
-1@@ -137,6 +137,7 @@#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080#define UVC_QUIRK_PROBE_DEF 0x00000100#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200 +#define UVC_QUIRK_FORCE_Y8 0x00000400/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001 --2.0.1
Laurent Pinchart
maintainerHi Philipp,
Quoted 7 lines · On Monday 29 September 2014 21:38:39 Philipp Zabel wrote:
Quoted 4 lines · Philipp Zabel
This patch adds a quirk to force Y8 pixel format even if the camera reports half-width YUYV.
Signed-off-by Philipp Zabel <[email protected]>do you have any further comments on this patch?
Sorry for the late reply. Please see below for a couple of small comments.
Quoted 6 lines
Quoted 6 lines
---
drivers/media/usb/uvc/uvc_driver.c | 29 ++++++++++++++++++++++++++++- drivers/media/usb/uvc/uvcvideo.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-)
Quoted 9 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 314
Quoted 9 lines
(quoted diff) +0
-0
b/drivers/media/usb/uvc/uvc_driver.cindex c3bb250..90a8f10 100644drivers/media/usb/uvc/uvc_driver.c +1
-0@@ -311,6 +311,7 @@ static int uvc_parse_format(struct uvc_device *dev,struct uvc_format_desc *fmtdesc;struct uvc_frame *frame;const unsigned char *start = buffer; +bool force_yuy2_to_y8 = false;
To keep things a bit more generic, how about an unsigned int width_multiplier initialized to 1 and set to 2 when the quirk applies ?
Quoted 5 lines
Quoted 5 lines
drivers/media/usb/uvc/uvc_driver.c +0
-0unsigned int interval;unsigned int i, n;__u8 ftype;@@ -333,6 +334,22 @@ static int uvc_parse_format(struct uvc_device *dev,
Quoted 8 lines
Quoted 8 lines
drivers/media/usb/uvc/uvc_driver.c +4
-0/* Find the format descriptor from its GUID. */ fmtdesc =uvc_format_by_guid (&buffer[5 ]); + format->bpp = buffer[21 ]; + +if (dev->quirks &UVC_QUIRK_FORCE_Y8 ) { + if (fmtdesc && fmtdesc->fcc == V4L2_PIX_FMT_YUYV&&
+format->bpp== 16) {
I wonder if that check is really needed, all YUYV formats should have 16bpp.
Quoted 2 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 343
Quoted 2 lines
drivers/media/usb/uvc/uvc_driver.c +2
-0+ force_yuy2_to_y8 = true; + fmtdesc = &uvc_fmts[9 ];
The hardcoded index here is hair-raising :-) How about something like the following instead ?
}
format->bpp = buffer[21];
+
+ /* Some devices report a format that doesn't match what they
+ * really send.
+ */
+ if (dev->quirks & UVC_QUIRK_FORCE_Y8) {
+ if (format->fcc == V4L2_PIX_FMT_YUYV) {
+ strlcpy(format->name, "Greyscale 8-bit (Y8 )",
+ sizeof(format->name));
+ format->fcc = V4L2_PIX_FMT_GREY;
+ format->bpp = 8;
+ width_multiplier = 2;
+ }
+ }
+
if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) {
ftype = UVC_VS_FRAME_UNCOMPRESSED;
} else {
I know it duplicates the format string, but as we're trying to move them to the V4L2 core anyway, I don't see that as being a big problem.
Quoted 17 lines
Quoted 17 lines
drivers/media/usb/uvc/uvc_driver.c +4
-0+ format->bpp =8 ; + }else { + uvc_printk(KERN_WARNING, + "Forcing %d-bit %s to %s notsupported",
drivers/media/usb/uvc/uvc_driver.c +5
-0+ format->bpp, fmtdesc->name, + uvc_fmts[9].name); + } + } +if (fmtdesc !=NULL ) {strlcpy (format->name, fmtdesc->name,sizeof format->name);@@ -345,7 +362,6 @@ static int uvc_parse_format(struct uvc_device *dev, format->fcc =0 ; }
Quoted 10 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 475
Quoted 10 lines
drivers/media/usb/uvc/uvc_driver.c +2
-1- format->bpp = buffer[21 ];if (buffer[2 ] ==UVC_VS_FORMAT_UNCOMPRESSED ) { ftype =UVC_VS_FRAME_UNCOMPRESSED ; }else {@@ -455,6 +471,8 @@ static int uvc_parse_format(struct uvc_device *dev, frame->bFrameIndex = buffer[3 ]; frame->bmCapabilities = buffer[4 ]; frame->wWidth =get_unaligned_le16 (&buffer[5 ]); +if (force_yuy2_to_y8) + frame->wWidth *=2 ;
This would become
+ frame->wWidth = get_unaligned_le16(&buffer[5])
+ * width_multiplier;
If you're fine with that there's no need to resubmit, I'll modify the patch when applying it to my tree.
Quoted 31 lines
Quoted 31 lines
drivers/media/usb/uvc/uvc_driver.c +9
-0frame->wHeight =get_unaligned_le16 (&buffer[7 ]); frame->dwMinBitRate =get_unaligned_le32 (&buffer[9 ]); frame->dwMaxBitRate =get_unaligned_le32 (&buffer[13 ]);@@ -2467,6 +2485,15 @@ static struct usb_device_id uvc_ids[] = { .bInterfaceProtocol = 0, .driver_info =UVC_QUIRK_PROBE_MINMAX | UVC_QUIRK_IGNORE_SELECTOR_UNIT }, + /* Oculus VR Positional Tracker DK2 */ + { .match_flags = USB_DEVICE_ID_MATCH_DEVICE + | USB_DEVICE_ID_MATCH_INT_INFO, + .idVendor = 0x2833, + .idProduct = 0x0201, + .bInterfaceClass = USB_CLASS_VIDEO, + .bInterfaceSubClass = 1, + .bInterfaceProtocol = 0, + .driver_info = UVC_QUIRK_FORCE_Y8 },/* Generic USB Video Class */ { USB_INTERFACE_INFO(USB_CLASS_VIDEO, 1, 0) }, {}(quoted diff) +0
-0
b/drivers/media/usb/uvc/uvcvideo.hindex 9e35982..1dd78c0 100644drivers/media/usb/uvc/uvcvideo.h +1
-0@@ -137,6 +137,7 @@#define UVC_QUIRK_FIX_BANDWIDTH 0x00000080#define UVC_QUIRK_PROBE_DEF 0x00000100#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200 +#define UVC_QUIRK_FORCE_Y8 0x00000400/* Format flags */ #define UVC_FMT_FLAG_COMPRESSED 0x00000001
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Quoted 8 lines · Laurent Pinchart
Quoted 5 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 314
Quoted 5 lines
drivers/media/usb/uvc/uvc_driver.c +1
-0@@ -311,6 +311,7 @@ static int uvc_parse_format(struct uvc_device *dev,struct uvc_format_desc *fmtdesc;struct uvc_frame *frame;const unsigned char *start = buffer; +bool force_yuy2_to_y8 = false;To keep things a bit more generic, how about an unsigned int
width_multiplierinitialized to 1 and set to 2 when the quirk applies ?
[...]
Quoted 42 lines
Quoted 10 lines
Quoted 10 lines
drivers/media/usb/uvc/uvc_driver.c +4
-0@@ -333,6 +334,22 @@ static int uvc_parse_format(struct uvc_device *dev,/* Find the format descriptor from its GUID. */ fmtdesc =uvc_format_by_guid (&buffer[5 ]); + format->bpp = buffer[21 ]; + +if (dev->quirks &UVC_QUIRK_FORCE_Y8 ) { + if (fmtdesc && fmtdesc->fcc == V4L2_PIX_FMT_YUYV&&
+format->bpp== 16) {I wonder if that check is really needed, all YUYV formats should have 16bpp.
Quoted 2 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 343
Quoted 2 lines
drivers/media/usb/uvc/uvc_driver.c +2
-0+ force_yuy2_to_y8 = true; + fmtdesc = &uvc_fmts[9 ];The hardcoded index here is hair-raising :-) How about something like the following instead ?
} format->bpp = buffer[21];(quoted diff) +14
-0+ + /* Some devices report a format that doesn't match what they + * really send. + */ + if (dev->quirks & UVC_QUIRK_FORCE_Y8) { + if (format->fcc == V4L2_PIX_FMT_YUYV) { + strlcpy(format->name, "Greyscale 8-bit (Y8 )", + sizeof(format->name)); + format->fcc = V4L2_PIX_FMT_GREY; + format->bpp = 8; + width_multiplier = 2; + } + } + if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) { ftype = UVC_VS_FRAME_UNCOMPRESSED; } else {I know it duplicates the format string, but as we're trying to move them to the V4L2 core anyway, I don't see that as being a big problem.
[...]
Quoted 12 lines
Quoted 6 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 475
Quoted 6 lines
drivers/media/usb/uvc/uvc_driver.c +2
-0@@ -455,6 +471,8 @@ static int uvc_parse_format(struct uvc_device *dev, frame->bFrameIndex = buffer[3 ]; frame->bmCapabilities = buffer[4 ]; frame->wWidth =get_unaligned_le16 (&buffer[5 ]); +if (force_yuy2_to_y8) + frame->wWidth *=2 ;This would become
(quoted diff) +2
-0+ frame->wWidth = get_unaligned_le16(&buffer[5]) + * width_multiplier;
Quoted 2 lines
If you're fine with that there's no need to resubmit, I'll modify the patch when applying it to my tree.
Thank you, I'm fine with your suggested changes. Especially the format setting part looks a lot more civilized now.
regards
Philipp
Laurent Pinchart
maintainerHi Philipp,
Quoted 76 lines · On Monday 06 October 2014 23:45:54 Philipp Zabel wrote:
Quoted 8 lines · Laurent Pinchart
Quoted 5 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 314
Quoted 5 lines
drivers/media/usb/uvc/uvc_driver.c +1
-0@@ -311,6 +311,7 @@ static int uvc_parse_format(struct uvc_device *dev,struct uvc_format_desc *fmtdesc;struct uvc_frame *frame;const unsigned char *start = buffer; +bool force_yuy2_to_y8 = false;To keep things a bit more generic, how about an unsigned int
width_multiplierinitialized to 1 and set to 2 when the quirk applies ?[...]
Quoted 50 lines
Quoted 6 lines
Quoted 6 lines
drivers/media/usb/uvc/uvc_driver.c +0
-0@@ -333,6 +334,22 @@ static int uvc_parse_format(struct uvc_device *dev,/* Find the format descriptor from its GUID. */ fmtdesc =uvc_format_by_guid (&buffer[5 ]);Quoted 7 lines
Quoted 7 lines
drivers/media/usb/uvc/uvc_driver.c +4
-0+ format->bpp = buffer[21 ]; + + if (dev->quirks & UVC_QUIRK_FORCE_Y8) { + if (fmtdesc && fmtdesc->fcc ==
V4L2_PIX_FMT_YUYV
&&
+format->bpp== 16) {I wonder if that check is really needed, all YUYV formats should have 16bpp.
Quoted 2 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 343
Quoted 2 lines
drivers/media/usb/uvc/uvc_driver.c +2
-0+ force_yuy2_to_y8 = true; + fmtdesc = &uvc_fmts[9 ];The hardcoded index here is hair-raising :-) How about something like the following instead ?
} format->bpp = buffer[21];(quoted diff) +2
-0+ + /* Some devices report a format that doesn't match whatthey
(quoted diff) +11
-0+ * really send. + */ + if (dev->quirks & UVC_QUIRK_FORCE_Y8) { + if (format->fcc == V4L2_PIX_FMT_YUYV) { + strlcpy(format->name, "Greyscale 8-bit (Y8 )", + sizeof(format->name)); + format->fcc = V4L2_PIX_FMT_GREY; + format->bpp = 8; + width_multiplier = 2; + } + } + if (buffer[2] == UVC_VS_FORMAT_UNCOMPRESSED) { ftype = UVC_VS_FRAME_UNCOMPRESSED; } else {I know it duplicates the format string, but as we're trying to move them to the V4L2 core anyway, I don't see that as being a big problem.
[...]
Quoted 11 lines
Quoted 8 lines
drivers/media/usb/uvc/uvc_driver.c static int uvc_parse_format(struct uvc_device *dev, · line 477
Quoted 8 lines
drivers/media/usb/uvc/uvc_driver.c +2
-0@@ -455,6 +471,8 @@ static int uvc_parse_format(struct uvc_device *dev, frame->bFrameIndex = buffer[3 ]; frame->bmCapabilities = buffer[4 ]; frame->wWidth =get_unaligned_le16 (&buffer[5 ]); +if (force_yuy2_to_y8) + frame->wWidth *=2 ;This would become
Quoted 8 lines
Quoted 5 lines
(quoted diff) +2
-0+ frame->wWidth = get_unaligned_le16(&buffer[5]) + * width_multiplier;If you're fine with that there's no need to resubmit, I'll modify the patch when applying it to my tree.
Thank you, I'm fine with your suggested changes. Especially the format setting part looks a lot more civilized now.
Great. I'll add the patch to my next pull request. Thank you.
Signature · 3 lines
Regards, Laurent Pinchart