summaryrefslogtreecommitdiff
path: root/uvc-gadget.c
AgeCommit message (Collapse)Author
2018-06-09uvc-gadget: factor out uvc protocol and stream handling codePaul Elder
uvc-gadget.c has been getting cluttered with functions related to UVC protocol handling and stream handling. Additionally, it is forseen that we might want stream handling to be modular for different system models. Factor out code related to UVC protocol handling to uvc.c (and uvc.h) and code related to stream handling to stream.c (and stream.h), and update the Makefile accordingly. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-06-01uvc-gadget: Don't hardcode the maximum payload transfer sizeLaurent Pinchart
Use the streaming endpoint maximum packet size parsed from ConfigFS instead of hardcoding an arbitrary value. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-06-01uvc-gadget: Don't hardcode formats and frame sizesLaurent Pinchart
Replace the hardcode formats and frame sizes with the configuration read from ConfigFS. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-06-01configfs: Refactor ConfigFS parsing codeLaurent Pinchart
Move all attribute parsing to a top-level configfs_parse_uvc() function, and split control and streaming interface attributes to two separate helper functions. In addition to making the code more structured, it will also allow supporting multiple streaming interfaces in a single UVC function in the future. The uvc_function_config structure is similarly reorganized in a hierarchical representation of the configuration. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-05-26configfs: Handle interface numbersKieran Bingham
Store the function configuration pointer in the uvc_device, and use it to identify and store the interface numbers from configfs. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-26configfs: Provide configfs supportKieran Bingham
Parse a configuration name from the commandline, and utilise it to identify the configfs configuration path. Only the short-name (i.e. "uvc.1") is necessary to provide if there is no ambiguity regarding the gadget, otherwise the gadget path should be included ("g1/functions/uvc.1"). If the parameter is not provided then the first function is utilised. Legacy g_webcam is still supported, and the parameter will define the UDC to match against if provided. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-24uvc-gadget: Implement streaming from a capture devicePaul Elder
Capture frames from v4l2 capture device and send frames to uvc gadget output device. This is done by passing buffers between these two devices; the buffers are shared through V4L2_MEMORY_DMABUF. Empty buffers dequeued from the uvc device are enqueued into the v4l2 capture device, from which full buffers are dequeued and enqueued back into the uvc device. Implement and use functions to ease manipulation of the capture device, and remove uvc_fill_buffer, as it is no longer needed to fill frames from a non-v4l2 capture source. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-24uvc-gadget: Add struct uvc_streamPaul Elder
Since we are preparing to stream frames from a capture v4l2 device to uvc-gadget, add a struct to represent this "frame-forwarding" stream, such that it contains a representation of the uvc gadget device (struct uvc_device) and other data relative to the stream, such as a pointer to the events handler and test pattern generation data. A capture v4l2 device object will be added in a subsequent modification. The stream is allocated dynamically, and the event handler is created separately from the stream. This will allow replacing the event handling mechanism with a different implementation without impacting the stream implementation. Change the argument to functions that need to be able to access stream data from uvc_device to uvc_stream. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-24uvc-gadget: Remove bulk supportLaurent Pinchart
Bulk mode is only partially implemented, and it hinders development of the application. Remove it for now, it will be added back properly in the future. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-24uvc-gadget: Constify request data pointersLaurent Pinchart
The request data passed from the UVC event handler to processing functions should never be modified. Make it const through the code. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-24uvc-gadget: Use uvc_fill_streaming_control in uvc_events_process_dataLaurent Pinchart
The uvc_events_process_data() function looks up format and frame descriptors to fill the streaming control structure. This duplicates code from the uvc_fill_streaming_control() function. Refactor the function to make it usable in uvc_events_process_data() and remove the duplicated code. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-22uvc-gadget: Correct spelling of necessaryKieran Bingham
Trivial spelling fix. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2018-05-22uvc-gadget: Sort include headersKieran Bingham
Fix the sort order of the header include sections. Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-22v4l2: Split buffer allocation and mappingLaurent Pinchart
Not all use cases of V4L2_MEMORY_MMAP require mapping buffers to userspace. Separate the allocation and mapping to allow usage of unmapped buffers. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-22uvc-gadget: Use V4L2 helper functionsLaurent Pinchart
Replace the manual implementation of the V4L2 ioctls with the V4L2 helper functions from v4l2.c. This cleans up the code and simplifies handling of the V4L2 API. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-21uvc-gadget: Use macros from tools.hLaurent Pinchart
The tools.h header defines clamp and ARRAY_SIZE macros. Use the header to replace the private implementation. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-21uvc-gadget: Dynamically watch/unwatch uvc device fdPaul Elder
When the uvc device fd is put on the watch list statically, then there are many "Unable to dequeue buffer: Invalid argument (22)." because the V4L2 API returns write events immediately when the stream is off. To fix this, add the fd to the watch list on streamon, and remove it on streamoff. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-21uvc-gadget: Use events libraryPaul Elder
Replace the manual implementation of the select-based event loop with the events library. This cleans up the code and simplifies event handling. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2018-05-20uvc-gadget: Use new kernel API headerLaurent Pinchart
The UVC gadget driver now defines its API in the linux/usb/g_uvc.h public header, use it instead of including an internal kernel header through a relative path. The public API doesn't define the UVC_INTF_CONTROL and UVC_INTF_STREAMING macros, define them locally until we can get rid of them. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2017-03-06uvc-gadget: Do not send Set Interface (alternate setting) response twiceRoger Quadros
On alternate setting change, the webcam gadget sends us a UVC_EVENT_STREAMON or UVC_EVENT_STREAMOFF event. In the first case, the driver will issue a delayed status response automatically when we call the VIDIOC_STREAMON ioctl. In the second case, the driver sends the status response immediately. We must thus not send the status response manually with UVCIOC_SEND_RESPONSE in any of those cases. Without this, the ISO streaming doesn't work if host application (e.g. luvcview) is closed and restarted. On dwc3 gadget controller it was resulting in Buffer Expiry error on the ISO endpoint. Signed-off-by: Roger Quadros <rogerq@ti.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2010-06-07Initial importLaurent Pinchart
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>