Code Monkey home page Code Monkey logo

uvc-gadget's Introduction

UVC gadget test application Readme

Copyright (C) 2010 Ideas on board SPRL
Copyright (C) 2013 ST Microelectronics Ltd.

Contacts:
Laurent Pinchart <laurent.pinchart@xxxxxxxxxxxxxxxx>
Bhupesh Sharma <bhupesh.sharma@xxxxxx>

Introduction
============

This README file documents the UVC gadget test application available
here git://git.ideasonboard.org/uvc-gadget.git, which can be used to
test the UVC webcam gadget driver located under drivers/usb/gadget
directory.

Possible Use-Case scenarios
===========================

There can be a number of scenarios under which the UVC webcam gadget can
be used and each use-case can vary in the following ways:

- Video streaming endpoint choice:
  --------------------------------

  As per UVC specifications (Revision 1.1), either Bulk or Isochronous
  USB endpoints can be used are for implementing UVC Video streaming
  interface. Both have there unique challenges as:

	Isochronous video streaming interface will have two
	alt-settings:
		- Alt-setting 0 for zero-bandwidth mode, and
		- Alt-setting 1 for full-bandwidth mode.

	This requires us to ACK status stage of SET_ALT(alt-setting =
	1), only when we have video frames available which can be queued
	to UVC domain.

	Bulk video streaming interface, on the other hand will have only
	one alt-setting.

	This requires us to prepare UVC gadget for streaming when we
	receive a a UVC_VS_COMMIT_CONTROL command from USB host and
	actually start streaming as soon as we have video frames
	available which can be queued to UVC domain.

- Availability of a video capture device:
  ---------------------------------------

  To emulate a real UVC webcam gadget (capturing live video from a video
  capture source and sending it over USB bus), it is possible to
  integrate a V4L2 based video-capture device driver with the UVC gadget
  test application acting as an interface between the UVC based
  video-output device and V4L2 based video-capture device.
  
  Accordingly, there can be the following scenarios possible:

	- No video capture device available:

		In this case, there is no video capture device available
		and the UVC webcam gadget is working in an standalone
		environment.

		It is possible in this case to stream a dummy test
		pattern from the UVC webcam gadget and view the same on
		the Linux/Windows USB Host machine using standard video
		capture utilities like CHEESE.

	- VIVI (Virtual Video driver) acting as a video capture source:

		In case we don't have a real video capture hardware
		(e.g. sensor) available, it is still possible to
		exercise the complete path from the V4L2 based
		video-capture domain to UVC based video-output domain,
		using the Virtual Video driver (VIVI) available here:
		drivers/media/platform/vivi.c

		It is possible in this case to stream changing vertical
		color bar pattern pattern from the VIVI capture device
		and send it to UVC webcam gadget, which will eventually
		send these frames over USB bus.

		Similar to the case above, it is possible to view the
		frames on the Linux/Windows USB Host machine using
		standard video capture utilities like CHEESE.

	- Real video capture hardware and corresponding V4L2 driver
	  available:

		In this case, we have a real video capture hardware
		(e.g. CCD / CMOS sensor) available.

		Here, it is possible to exercise the complete path from
		the V4L2 based video-capture driver domain to UVC based
		video-output domain, using the UVC gadget test
		application.

		It is possible in this case to stream real video/still
		images from capture source and send it to UVC webcam
		gadget, which will eventually send these frames over USB
		bus.

- IO methods supported:
  --------------------

  V4L2 framework supports a number of IO methods and to achieve
  zero-memcpy of video frames as they pass from V4L2 video-capture
  domain to UVC video-output domain, it is important to select
  appropriate IO methods for working on videobuffers.

  Accordingly we can have the following scenarios possible:
  
	- UVC webcam standalone, supporting IO_METHOD_MMAP method:

		In this case, there is no video capture device available
		and the UVC webcam gadget is working in an standalone
		environment.

		It is supporting IO_MMAP method, which implies that the
		videobuffers are allocated by the UVC webcam gadget
		itself and they are filled with dummy test pattern by
		UVC gadget test application.

	- UVC webcam standalone, supporting IO_METHOD_USERPTR method:

		In this case, there is no video capture device available
		and the UVC webcam gadget is working in an standalone
		environment.

		It is supporting IO_METHOD_USERPTR method, which implies
		that the videobuffers are allocated and filled with
		dummy test pattern by the UVC gadget test application
		and UVC webcam gadget operates on a USERPTR of these
		videobuffers.

	- UVC webcam integrated with V4L2 video-capture driver, with
	  V4L2 video-capture driver supporting IO_METHOD_MMAP method and
	  UVC webcam supporting IO_METHOD_USERPTR:

		In this case, either VIVI or another V4L2 based driver
		(working on real HW) is available as a video capture
		device and is integrated with the UVC webcam gadget via
		UVC gadget test application, with V4L2 video-capture
		driver supporting IO_METHOD_MMAP method and UVC webcam
		supporting IO_METHOD_USERPTR.

		Here, the videobuffers are allocated in the V4L2
		video-capture domain and UVC gadget test application
		acts as a means to pass a USERPTR of these videobuffers
		to the UVC webcam gadget domain, without requiring any
		memcpy from the CPU.

	- UVC webcam integrated with V4L2 video-capture driver, with
	  V4L2 video-capture driver supporting IO_METHOD_USERPTR method
	  and UVC webcam supporting IO_METHOD_MMAP:

		In this case, either VIVI or another V4L2 based driver
		(working on real HW) is available as a video capture
		device and is integrated with the UVC webcam gadget via
		UVC gadget test application, with V4L2 video-capture
		driver supporting IO_METHOD_USERPTR method and UVC
		webcam supporting IO_METHOD_MMAP.

		Here, the videobuffers are allocated in the UVC webcam
		gadget domain and UVC gadget test application acts as a
		means to pass a USERPTR of these videobuffers to the
		V4L2 video-capture domain, without requiring any memcpy
		from the CPU.

Modifying UVC gadget test application
=====================================

The UVC webcam gadget kernel driver located under drivers/usb/gadget
directory and compilable as g_webcam.ko kernel module, supports 360p and
720p frame resolutions and YUV4:2:2 and MJPEG frame formats by default.

So, the video capture device must be aligned to support similar frame
format and resolutions.

In case the video capture device supports other resolutions and frame
formats, we need to replace the default values used in the UVC gadget
test application with the same and also update the UVC webcam gadget
kernel driver.

Keeping USBCV's UVC test-suite happy
====================================

The UVC webcam gadget kernel driver located under drivers/usb/gadget
directory and compilable as g_webcam.ko kernel module, supports changing
the Brightness attribute of the Processing Unit (PU) by default.

If the underlying video capture device supports changing the Brightness
attribute of the image being acquired (like the Virtual Video, VIVI
driver does), then we should route this UVC request to the respective
video capture device.

Incase, there is no actual video capture device associated with the UVC
gadget and we wish to use this application as the final destination of
the UVC specific requests then we should return pre-cooked (static)
responses to GET_CUR(BRIGHTNESS) and SET_CUR(BRIGHTNESS) commands to
keep command verifier test tools like UVC class specific test suite of
USBCV, happy.

Note that the values used in UVC gadget test application are in sync
with the VIVI driver and must be changed for your specific video capture
device. These values also work well in case there in no actual video
capture device.

uvc-gadget's People

Contributors

jdonald avatar pinchartl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

uvc-gadget's Issues

Raspberry zero wh - kernel module problem

Hello,

thanks for all the patches. I am trying to turn my raspberry pi zeroWH with a pinoir (1.3 or 2.1) or a spycam to a uvc camera .

$ uname -a
Linux raspberrypi 4.9.80+ #1098 Fri Mar 9 18:51:28 GMT 2018 armv6l GNU/Linux

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.3 (stretch)
Release: 9.3
Codename: stretch

raspberry kernel commit :
a2f34d45809d8685bca1e91989e35746499ac400

This is the command line launched most of the time for the tests :
$ ./uvc-gadget -b -s 2 -m 1 -v /dev/video0 -u /dev/video1

There is a problem with drivers/usb/gadget/function/uvc_video.c in function uvc_video_alloc_requests:
video->ep->mult is always equal to 0 and as a result, req_size = 0 which leads to a null pointer in uvc_video_encode_isoc or uvc_video_encode_bulk

(#side note: video->max_payload_size is always 0, therefore, even with uvc-gadget -b, uvc_video_encode_bulk is never called)

After modifying drivers/usb/gadget/function/uvc_video.c to force video->ep->mult to be equal to 1 before the call to uvc_video_encode_isoc, the module gets to the point of calling usb_ep_queue but the data is never queued and there is the following warning :

Apr 10 09:32:09 raspberrypi kernel: [ 485.605711] ------------[ cut here ]------------
Apr 10 09:32:09 raspberrypi kernel: [ 485.605854] WARNING: CPU: 0 PID: 899 at drivers/usb/gadget/udc/core.c:262 usb_ep_queue+0xc0/0xd4 [udc_core]
Apr 10 09:32:09 raspberrypi kernel: [ 485.605861] Modules linked in: g_webcam usb_f_uvc libcomposite fuse rfcomm cmac bnep hci_uart btbcm bluetooth brcmfmac brcmutil snd_bcm2835 snd_pcm cfg80211 snd_timer snd rfkill bcm2835_gpiomem uio_pdrv_genirq uio fixed bcm2835_v4l2 v4l2_common videobuf2_vmalloc videobuf2_memops videobuf2_v4l2 videobuf2_core videodev media i2c_dev dwc2 udc_core ip_tables x_tables ipv6 [last unloaded: usb_f_uvc]
Apr 10 09:32:09 raspberrypi kernel: [ 485.605970] CPU: 0 PID: 899 Comm: uvc-gadget Not tainted 4.9.80+ #1098
Apr 10 09:32:09 raspberrypi kernel: [ 485.605975] Hardware name: BCM2835
Apr 10 09:32:09 raspberrypi kernel: [ 485.606030] [] (unwind_backtrace) from [] (show_stack+0x20/0x24)
Apr 10 09:32:09 raspberrypi kernel: [ 485.606056] [] (show_stack) from [] (dump_stack+0x20/0x28)
Apr 10 09:32:09 raspberrypi kernel: [ 485.606082] [] (dump_stack) from [] (__warn+0xe4/0x10c)
Apr 10 09:32:09 raspberrypi kernel: [ 485.606101] [] (__warn) from [] (warn_slowpath_null+0x30/0x38)
Apr 10 09:32:09 raspberrypi kernel: [ 485.606179] [] (warn_slowpath_null) from [] (usb_ep_queue+0xc0/0xd4 [udc_core])
Apr 10 09:32:09 raspberrypi kernel: [ 485.606363] [] (usb_ep_queue [udc_core]) from [] (uvcg_video_pump+0xb8/0x250 [usb_f_uvc])
Apr 10 09:32:09 raspberrypi kernel: [ 485.606494] [] (uvcg_video_pump [usb_f_uvc]) from [] (uvcg_video_enable+0x208/0x26c [usb_f_uvc])
Apr 10 09:32:09 raspberrypi kernel: [ 485.606595] [] (uvcg_video_enable [usb_f_uvc]) from [] (uvc_v4l2_streamon+0x40/0x6c [usb_f_uvc])
Apr 10 09:32:09 raspberrypi kernel: [ 485.606974] [] (uvc_v4l2_streamon [usb_f_uvc]) from [] (v4l_streamon+0x28/0x2c [videodev])
Apr 10 09:32:09 raspberrypi kernel: [ 485.607347] [] (v4l_streamon [videodev]) from [] (__video_do_ioctl+0x2a0/0x320 [videodev])
Apr 10 09:32:09 raspberrypi kernel: [ 485.607716] [] (__video_do_ioctl [videodev]) from [] (video_usercopy+0x234/0x540 [videodev])
Apr 10 09:32:09 raspberrypi kernel: [ 485.608085] [] (video_usercopy [videodev]) from [] (video_ioctl2+0x1c/0x24 [videodev])
Apr 10 09:32:09 raspberrypi kernel: [ 485.608450] [] (video_ioctl2 [videodev]) from [] (v4l2_ioctl+0xd4/0xec [videodev])
Apr 10 09:32:09 raspberrypi kernel: [ 485.608656] [] (v4l2_ioctl [videodev]) from [] (do_vfs_ioctl+0x9c/0x7d4)
Apr 10 09:32:09 raspberrypi kernel: [ 485.608677] [] (do_vfs_ioctl) from [] (SyS_ioctl+0x44/0x6c)
Apr 10 09:32:09 raspberrypi kernel: [ 485.608700] [] (SyS_ioctl) from [] (ret_fast_syscall+0x0/0x1c)
Apr 10 09:32:09 raspberrypi kernel: [ 485.608709] ---[ end trace 12f94de20755f8c5 ]---
Apr 10 09:32:09 raspberrypi kernel: [ 485.608718] Failed to queue request (-108)
Apr 10 09:32:09 raspberrypi kernel: [ 485.608743] dwc2 20980000.usb: dwc2_hsotg_ep_sethalt(ep ce979c90 ep2in, 1)
Apr 10 09:32:09 raspberrypi kernel: [ 485.608931] ------------[ cut here ]------------

I have no idea if the origin of the problem comes from g_webcam, usb_f_uvc or uvc-gadget.
I would be more than happy to dig further but I lack some knowledge. Any hint would be appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.