uvc-gadget.git
7 days agogitignore: replace all entries by build directory master
Paul Elder [Wed, 6 Feb 2019 07:04:49 +0000 (02:04 -0500)]
gitignore: replace all entries by build directory

The official build instructions mandate usage of out-of-tree builds in
the build subdirectory. Replace the list of generated files in
.gitignore with just the build directory.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
[Remove all other .gitignore entries]
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
7 days agocmake: enable C warning flags
Paul Elder [Wed, 6 Feb 2019 07:04:48 +0000 (02:04 -0500)]
cmake: enable C warning flags

The C flags for warning were present but commented out. Uncomment them
to enable them.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
2 weeks agouvc: reply with max frame rate in response to UVC_GET_MAX
Paul Elder [Tue, 28 Aug 2018 06:45:46 +0000 (02:45 -0400)]
uvc: reply with max frame rate in response to UVC_GET_MAX

Previously, the interval rate that would be selected and replied to the
host in response to UVC_GET_MAX, UVC_GET_MIN, and UVC_GET_DEF were all
the same and were the first interval rate. Assuming the interval rates
are sorted in ascending order, this means that UVC_GET_MAX would always
yield the minimum interval rate.

Modify the call to uvc_fill_streaming_control such that UVC_GET_MAX will
yield the maximum interval rate.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2 weeks agostream, uvc: add uvc_stream_set_frame_rate
Paul Elder [Tue, 28 Aug 2018 06:17:15 +0000 (02:17 -0400)]
stream, uvc: add uvc_stream_set_frame_rate

We would like to be able to set the frame rate of the video source of a
stream. This patch adds such a function to set the source's frame rate
from the stream. The frame rate is set right after the format is set.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2 weeks agov4l2-source: implement set_frame_rate op
Paul Elder [Tue, 28 Aug 2018 06:15:22 +0000 (02:15 -0400)]
v4l2-source: implement set_frame_rate op

Implement the video source op set_frame_rate for v4l2-source video
source.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2 weeks agovideo-source: add video_source_set_frame_rate
Paul Elder [Tue, 28 Aug 2018 06:12:49 +0000 (02:12 -0400)]
video-source: add video_source_set_frame_rate

We would like to be able to set the frame rate for video sources. This
patch adds a set_frame_rate op for video sources, along with a wrapper
to call video sources' set_frame_rate functions.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
2 weeks agov4l2: add v4l2_set_frame_rate
Paul Elder [Tue, 28 Aug 2018 06:10:01 +0000 (02:10 -0400)]
v4l2: add v4l2_set_frame_rate

We would like to be able to set the frame rate of video sources. This
patch adds such a function for v4l2-based video sources to use.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
5 months agomain: Initialise stream object to NULL
Kieran Bingham [Tue, 28 Aug 2018 14:30:08 +0000 (15:30 +0100)]
main: Initialise stream object to NULL

If the capture device fails to load the default cleanup path will be
taken.  This error path relies on objects either existing or being set
to NULL.

Ensure that the stream pointer is initialised to prevent segfaults on
the error path.

Fixes: 1b8f9204db68 ("stream: Use abstract video sources")
Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reiewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6 months agolib: configfs: Detect configfs mount point
Kieran Bingham [Tue, 31 Jul 2018 16:10:20 +0000 (17:10 +0100)]
lib: configfs: Detect configfs mount point

Parse /proc/mounts to identify the correct mount location of the
ConfigFS filesystem.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6 months agolib: Compile custom glob() implementation for Android
Paul Elder [Tue, 26 Jun 2018 14:22:25 +0000 (23:22 +0900)]
lib: Compile custom glob() implementation for Android

The Android C library doesn't provide the glob() function which we use
in the configfs code. Add conditional compilation to cmake such that a
local copy of glob is automatically compiled if glob isn't provided.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6 months agolib: glob: Fix compilation on Android
Laurent Pinchart [Tue, 26 Jun 2018 14:39:38 +0000 (17:39 +0300)]
lib: glob: Fix compilation on Android

The glibc glob() implementation doesn't compile on Android due to
missing support for getlogin_r (before Android ABI 28) and to missing
__THROW, __THROWNL and __attribute_noinline__ macros.

getlogin_r is only used to implement support for the '~' path component
which we don't use in the uvc-gadget library, so we can compile it out.
The three macros can safely be defined as no-op.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6 months agolib: glob: Fix compilation
Laurent Pinchart [Tue, 26 Jun 2018 14:39:38 +0000 (17:39 +0300)]
lib: glob: Fix compilation

The glibc glob() implementation seems to be meant to be compilable
outside of glibc, but that clearly hasn't been tested for some time. Fix
compilation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6 months agolib: Import glob.c from glibc 2.26
Laurent Pinchart [Tue, 26 Jun 2018 10:02:06 +0000 (13:02 +0300)]
lib: Import glob.c from glibc 2.26

The Android libc implementation (bionic) doesn't provide the glob()
function. To enable compilation of the UVC gadget library for Android,
import the glibc glob() implementation.

The glob.c and glob.h files are imported unmodified to ease copyright
management, even if they don't compile as-is. Compilation will be fixed
separately.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6 months agolib: configfs: Globalize nested configfs callback functions
Paul Elder [Tue, 26 Jun 2018 10:09:34 +0000 (19:09 +0900)]
lib: configfs: Globalize nested configfs callback functions

Android now uses clang as the default C compiler, and gcc support is
deprecated. clang doesn't support nested functions, which were used to
implement callback functions in the ConfigFS code. We thus move the
callbacks to the global scope.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
6 months agolib: configfs: Fix asprintf return value usage
Kieran Bingham [Tue, 26 Jun 2018 23:07:54 +0000 (00:07 +0100)]
lib: configfs: Fix asprintf return value usage

The asprintf function returns -1, and leaves the first parameter
undefined in case of an allocation error. This conflicts with the
code's assumption that the parameter is set NULL on error.

Check all return values of asprintf, and ensure that the string
parameter is not used as a return value on error paths.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc: check ioctl return value for error
Paul Elder [Tue, 12 Jun 2018 05:17:04 +0000 (14:17 +0900)]
uvc: check ioctl return value for error

There is code that is meant to check for the error of an ioctl, but the
return variable that it checks isn't actually assigned from the ioctl.
Assign the return value before checking it.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
[Fixed error message]
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agoAdd README.md file
Laurent Pinchart [Sat, 9 Jun 2018 12:04:23 +0000 (15:04 +0300)]
Add README.md file

Start by adding short build instructions. The documentation should be
expanded later.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agoImport the g_uvc.h header from the kernel sources
Laurent Pinchart [Sat, 9 Jun 2018 11:52:10 +0000 (14:52 +0300)]
Import the g_uvc.h header from the kernel sources

In order to avoid depending on an external kernel source tree recent
enough to provide the g_uvc.h header, import in the the project.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agolib: Relicense code under the LGPL-2.1+
Laurent Pinchart [Sat, 9 Jun 2018 10:16:45 +0000 (13:16 +0300)]
lib: Relicense code under the LGPL-2.1+

To allow usage of the UVC gadget library in closed-source or otherwise
GPL-incompatible applications, relicense the library under the terms of
the LGPL v2.1 or later, as published by the Free Software Foundation.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agoUpdate copyright dates and owner
Laurent Pinchart [Sat, 9 Jun 2018 10:06:18 +0000 (13:06 +0300)]
Update copyright dates and owner

Ideas on Board SPRL, the original copyright owner of the UVC gadget
application code, has been dissolved. All company copyrights have been
transferred to Laurent Pinchart. Update the copyright notices to
accordingly.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agoUse SPDX headers
Laurent Pinchart [Sat, 9 Jun 2018 10:04:46 +0000 (13:04 +0300)]
Use SPDX headers

Replace the boilerplate copyright headers with an SPDX header to ease
license compliance. This doesn't change the license of any of the files.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agoSplit UVC gadget into a library and test application
Laurent Pinchart [Sat, 9 Jun 2018 11:29:41 +0000 (14:29 +0300)]
Split UVC gadget into a library and test application

Split the project into a UVC gadget library and a test application. To
avoid rolling out a custom build system, switch to CMake.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agostream: Fix file description header
Laurent Pinchart [Sat, 9 Jun 2018 10:55:15 +0000 (13:55 +0300)]
stream: Fix file description header

The file description came from a bad copy&paste, fix it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc: Make uvc_device structure opaque
Laurent Pinchart [Sat, 9 Jun 2018 09:52:45 +0000 (12:52 +0300)]
uvc: Make uvc_device structure opaque

The internals of the uvc_device structure should not be accessed outside
of uvc.c. The only existing need to access the structure internals is in
stream.c, where access to the UVC V4L2 device is needed. To avoid that,
create an accessor function uvc_v4l2_device(), and make the structure
private.

Ideally the UVC V4L2 device should not be exposed. This can be achieved
by creating an abstract video sink class to handle the UVC video sink.
This is however out of scope for now.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agostream: Use abstract video sources
Laurent Pinchart [Sat, 9 Jun 2018 09:13:38 +0000 (12:13 +0300)]
stream: Use abstract video sources

Replace the manual V4L2 capture implementation by an abstract
video_source, provided by the user of the UVC stream. Removes any
knowledge of the video source internals from the uvc_stream class,
allowing usage of different source types.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agoMakefile: Suppress unused parameter warnings
Laurent Pinchart [Sat, 9 Jun 2018 09:47:43 +0000 (12:47 +0300)]
Makefile: Suppress unused parameter warnings

When implementing callback APIs, it is common to not use some of the
parameters to the callback functions. Instead of requiring the user of
the callback to annotate unused parameters manually, suppress the
warning.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agov4l2-source: Add V4L2 source class
Laurent Pinchart [Sat, 9 Jun 2018 09:44:49 +0000 (12:44 +0300)]
v4l2-source: Add V4L2 source class

The v4l2_source class is an implementation of the video_source class
that uses a V4L2 capture device to provide video.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agovideo-source: Add abstract video source class
Laurent Pinchart [Sat, 9 Jun 2018 09:43:16 +0000 (12:43 +0300)]
video-source: Add abstract video source class

The video_source is an abstract class representing a source of video
buffers. It can be subclassed by implementing the video_source_ops
operations to support different types of video sources.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agov4l2: Extract video buffer structure to separate file
Laurent Pinchart [Sat, 9 Jun 2018 09:11:25 +0000 (12:11 +0300)]
v4l2: Extract video buffer structure to separate file

The v4l2_video_buffer structure describes a video buffer. It is used by
the v4l2_device class only, but isn't otherwise tied to V4L2. To prepare
for non-V4L2 video sources, extract it to a separate file and rename it
to video_buffer.

At the same time, add a new video_buffer_set structure to represent as
set of video buffers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc: Initialize the maxsize field internally
Laurent Pinchart [Fri, 8 Jun 2018 23:57:26 +0000 (02:57 +0300)]
uvc: Initialize the maxsize field internally

The uvc_device maxsize field is initialized in stream.c, requiring
access to the uvc_device internals. Move its initialization to uvc.c.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc: Add API to set video format
Laurent Pinchart [Fri, 8 Jun 2018 23:45:00 +0000 (02:45 +0300)]
uvc: Add API to set video format

Add a uvc_setformat() function to set the format for the UVC video
stream instead of accessing the internals of the uvc_device in
stream.c.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc: Add API to set function configuration
Laurent Pinchart [Fri, 8 Jun 2018 23:45:00 +0000 (02:45 +0300)]
uvc: Add API to set function configuration

Add a uvc_set_config() function to set the UVC function configuration
instead of accessing the internals of the uvc_device in stream.c.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agostream: Make the uvc_stream structure opaque
Laurent Pinchart [Fri, 8 Jun 2018 23:32:03 +0000 (02:32 +0300)]
stream: Make the uvc_stream structure opaque

The internals of the uvc_stream structure don't need to be accessed
outside stream.c. Move the structure definition from stream.h to
stream.c to make it opaque.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc: Handle UVC events internally in uvc.c
Laurent Pinchart [Fri, 8 Jun 2018 23:22:54 +0000 (02:22 +0300)]
uvc: Handle UVC events internally in uvc.c

The event notifier for the UVC device is registered in
uvc_stream_set_event_handler(), which requires exposing the
uvc_events_process() event handler to the uvc_stream class.

Make the event handler internal by registering it in uvc_events_init().
This requires passing the uvc_stream pointer to the uvc_open() function
and storing it internally in the uvc_device object.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agostream: add documentation
Paul Elder [Thu, 7 Jun 2018 11:01:24 +0000 (20:01 +0900)]
stream: add documentation

Add documentation to functions in stream.h header file.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc-gadget: factor out uvc protocol and stream handling code
Paul Elder [Thu, 7 Jun 2018 11:01:23 +0000 (20:01 +0900)]
uvc-gadget: factor out uvc protocol and stream handling code

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>
8 months agouvc-gadget.sh: add new default frame sizes
Paul Elder [Tue, 5 Jun 2018 13:47:07 +0000 (22:47 +0900)]
uvc-gadget.sh: add new default frame sizes

Create a couple more frame sizes through configfs. This is so that we
can test by default with multiple frame sizes. The frame sizes are
instantiated in a non-sorted order purposefully to test and make sure
that bFrameIndex parsing is done properly by all involved components.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc-gadget.sh: add function to create frame size
Paul Elder [Tue, 5 Jun 2018 13:47:06 +0000 (22:47 +0900)]
uvc-gadget.sh: add function to create frame size

Currently there are a set of files that need to be written to in
configfs to instantiate a single frame size of a UVC function. Add a
function create_frame() to do this in one call.

There is no delete_frame() since delete_uvc() will delete the frame
settings. Previously delete_uvc() only deleted the single frame size, so
this has been changed to a wildcard to catch all frame sizes.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agoconfigfs: add support for bFrameIndex
Paul Elder [Mon, 4 Jun 2018 14:55:14 +0000 (23:55 +0900)]
configfs: add support for bFrameIndex

Driver now supports bFrameIndex through configfs; enable reading this
attribute from configfs. This is necessary to associate the correct
bFrameIndexes with the UVC frame descriptors.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc-gadget: Don't hardcode the maximum payload transfer size
Laurent Pinchart [Fri, 25 May 2018 21:33:23 +0000 (00:33 +0300)]
uvc-gadget: Don't hardcode the maximum payload transfer size

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>
8 months agouvc-gadget: Don't hardcode formats and frame sizes
Laurent Pinchart [Sat, 26 May 2018 21:05:26 +0000 (00:05 +0300)]
uvc-gadget: Don't hardcode formats and frame sizes

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>
8 months agoconfigfs: Parse UVC formats, frames and intervals
Laurent Pinchart [Sat, 26 May 2018 21:04:05 +0000 (00:04 +0300)]
configfs: Parse UVC formats, frames and intervals

Extend the ConfigFS parser to parse UVC formats and intervals.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
8 months agoconfigfs: Restructure attribute read to support binary attributes
Laurent Pinchart [Sat, 26 May 2018 21:01:08 +0000 (00:01 +0300)]
configfs: Restructure attribute read to support binary attributes

Modify the attribute_read() function to not add a terminating 0 to the
buffer, and to return the number of bytes read, in order to support
binary attributes. The attribute_read_uint() and attribute_read_str()
functions are modified accordingly to use the new attribute_read()
semantics.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
8 months agoconfigfs: Refactor ConfigFS parsing code
Laurent Pinchart [Sat, 26 May 2018 17:58:19 +0000 (20:58 +0300)]
configfs: Refactor ConfigFS parsing code

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>
8 months agoconfigfs: Document the uvc_function_config structure
Laurent Pinchart [Sat, 26 May 2018 18:04:04 +0000 (21:04 +0300)]
configfs: Document the uvc_function_config structure

The structure is part of the API towards the UVC gadget application,
document it.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
8 months agoconfigfs: Don't guess interface numbers if they can't be parsed
Laurent Pinchart [Sat, 26 May 2018 17:50:50 +0000 (20:50 +0300)]
configfs: Don't guess interface numbers if they can't be parsed

Interface numbers are crucial parameters required for proper UVC gadget
operation. If we can't parse them from ConfigFS there's little point in
falling back to defaults that have a high chance being wrong. Treating
that case as a fatal error is better to get the root cause fixed.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
8 months agoconfigfs: Handle interface numbers
Kieran Bingham [Fri, 25 May 2018 15:31:33 +0000 (16:31 +0100)]
configfs: Handle interface numbers

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>
8 months agoconfigfs: Provide configfs support
Kieran Bingham [Fri, 25 May 2018 15:31:32 +0000 (16:31 +0100)]
configfs: Provide configfs support

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>
8 months agoscripts: Provide a multi-function config script
Kieran Bingham [Thu, 24 May 2018 17:01:48 +0000 (18:01 +0100)]
scripts: Provide a multi-function config script

Just a development starter for now.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agouvc-gadget: Implement streaming from a capture device
Paul Elder [Wed, 23 May 2018 20:07:33 +0000 (23:07 +0300)]
uvc-gadget: Implement streaming from a capture device

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>
8 months agouvc-gadget: Add struct uvc_stream
Paul Elder [Wed, 23 May 2018 18:12:38 +0000 (02:12 +0800)]
uvc-gadget: Add struct uvc_stream

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>
8 months agouvc-gadget: Remove bulk support
Laurent Pinchart [Wed, 23 May 2018 21:02:33 +0000 (00:02 +0300)]
uvc-gadget: Remove bulk support

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>
8 months agouvc-gadget: Constify request data pointers
Laurent Pinchart [Wed, 23 May 2018 20:41:30 +0000 (23:41 +0300)]
uvc-gadget: Constify request data pointers

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>
8 months agouvc-gadget: Use uvc_fill_streaming_control in uvc_events_process_data
Laurent Pinchart [Wed, 23 May 2018 20:38:08 +0000 (23:38 +0300)]
uvc-gadget: Use uvc_fill_streaming_control in uvc_events_process_data

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>
8 months agov4l2: Query buffer sizes when exporting buffers
Laurent Pinchart [Wed, 23 May 2018 22:24:39 +0000 (01:24 +0300)]
v4l2: Query buffer sizes when exporting buffers

In order to properly import buffers, the size of each buffer to be
imported must be known. The size is queried when the buffers are
mmap()ed, but mapping them isn't mandatory. Query the size when
exporting buffers to ensure that we always have a valid size for import.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 months agov4l2: Fix typo in error message
Laurent Pinchart [Wed, 23 May 2018 22:26:06 +0000 (01:26 +0300)]
v4l2: Fix typo in error message

Add the missing closing parenthesis.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agov4l2: Document expected fallthrough
Kieran Bingham [Wed, 23 May 2018 09:43:28 +0000 (10:43 +0100)]
v4l2: Document expected fallthrough

Compilers may now enable warnings for implicit fallthrough of switch
case statements, to help catch errors. One such case is highlighted in
our v4l2 module:

v4l2.c: In function ‘v4l2_enum_frame_sizes’:
v4l2.c:179:23: warning: this statement may fall through [-Wimplicit-fallthrough=]
    frame->step_height = frmenum.stepwise.step_height;
    ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
v4l2.c:180:3: note: here
   case V4L2_FRMSIZE_TYPE_CONTINUOUS:
   ^~~~

This fall through is expected, and the warning can be removed simply by
adding a comment to confirm that.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agouvc-gadget: Correct spelling of necessary
Kieran Bingham [Tue, 22 May 2018 13:10:55 +0000 (14:10 +0100)]
uvc-gadget: Correct spelling of necessary

Trivial spelling fix.

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
9 months agouvc-gadget: Sort include headers
Kieran Bingham [Tue, 22 May 2018 09:44:39 +0000 (10:44 +0100)]
uvc-gadget: Sort include headers

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>
9 months agov4l2: Replace USERPTR support with DMABUF support
Laurent Pinchart [Tue, 22 May 2018 08:43:37 +0000 (11:43 +0300)]
v4l2: Replace USERPTR support with DMABUF support

V4L2_MEMORY_USERPTR is deprecated, replace it with V4L2_MEMORY_DMABUF
support for buffer sharing. Two new functions are added,
v4l2_export_buffers() to export previously allocated buffers as dmabuf
objects, and v4l2_import_buffers() to import dmabuf objects as backing
store for V4L2 buffers.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agov4l2: Split buffer allocation and mapping
Laurent Pinchart [Tue, 22 May 2018 08:42:47 +0000 (11:42 +0300)]
v4l2: Split buffer allocation and mapping

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>
9 months agouvc-gadget: Use V4L2 helper functions
Laurent Pinchart [Tue, 22 May 2018 07:23:16 +0000 (10:23 +0300)]
uvc-gadget: Use V4L2 helper functions

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>
9 months agov4l2: Fail v4l2_alloc_buffers() when buffers are already allocated
Laurent Pinchart [Tue, 22 May 2018 07:20:35 +0000 (10:20 +0300)]
v4l2: Fail v4l2_alloc_buffers() when buffers are already allocated

Allocating buffers allocates resources that must be explicitly freed.
Calling v4l2_alloc_buffers() a second time without freeing the buffers
in between causes memory leaks and must not be allowed.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agov4l2: Free v4l2_device object when closing it
Laurent Pinchart [Tue, 22 May 2018 07:19:15 +0000 (10:19 +0300)]
v4l2: Free v4l2_device object when closing it

The v4l2_device object is allocated dynamically by v4l2_open(), free it
in v4l2_close() to make the API symmetrical.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agov4l2: Import V4L2 support code from omap3-isp-live
Laurent Pinchart [Mon, 21 May 2018 11:39:40 +0000 (14:39 +0300)]
v4l2: Import V4L2 support code from omap3-isp-live

The omap3-isp-live project [1] includes generic V4L2 support code that
implements the V4L2 API. Instead of reinventing the wheel, import the
code and use it.

The code has been modified to merge the V4L2 buffers pool implementation
in the V4L2 support code as the abstraction wasn't right for the
uvc-gadget project. Further refactoring will be performed separately.

The original license hasn't been modified from the original LGPL-2.1+.
The sole copyright owner is Laurent Pinchart.

[1] git://git.ideasonboard.org/omap3-isp-live.git

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agouvc-gadget: Use macros from tools.h
Laurent Pinchart [Mon, 21 May 2018 18:43:21 +0000 (21:43 +0300)]
uvc-gadget: Use macros from tools.h

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>
9 months agouvc-gadget: Dynamically watch/unwatch uvc device fd
Paul Elder [Mon, 21 May 2018 15:45:17 +0000 (23:45 +0800)]
uvc-gadget: Dynamically watch/unwatch uvc device fd

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>
9 months agouvc-gadget: Use events library
Paul Elder [Mon, 21 May 2018 15:45:16 +0000 (23:45 +0800)]
uvc-gadget: Use events library

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>
9 months agoevents: Remove select timeout
Paul Elder [Mon, 21 May 2018 15:45:15 +0000 (23:45 +0800)]
events: Remove select timeout

The reason why no timeout is needed is twofold:

When the stream is off extensive periods of time can pass without an
event occurring if the host doesn't send any UVC request. As that period
of time is unbound, we can't set any meaningful timeout.

When the stream is on buffers are supposed to flow constantly. If
buffers stop flowing that would indicate a bug somewhere in the stack,
which could be caught by a timeout, but that we wouldn't be able to
recover from anyway.

The timeout is thus not needed and harmful when the stream is off.
Remove it.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agoevents: Switch to _DEFAULT_SOURCE
Paul Elder [Mon, 21 May 2018 15:45:14 +0000 (23:45 +0800)]
events: Switch to _DEFAULT_SOURCE

glibc version 2.27 warns that _BSD_SOURCE is deprecated in favour of _DEFAULT
_SOURCE:

 # warning "_BSD_SOURCE and _SVID_SOURCE are deprecated, use
_DEFAULT_SOURCE"

Fix the source code accordingly.

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agoevents: Add a cleanup function
Laurent Pinchart [Mon, 21 May 2018 13:31:32 +0000 (16:31 +0300)]
events: Add a cleanup function

Add events to the watch list allocates memory. Add a cleanup function to
free all memory at cleanup time without having to remove all events
explicitly one by one.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agoevents: Extend the events_unwatch_fd() API with an event type
Laurent Pinchart [Mon, 21 May 2018 13:29:33 +0000 (16:29 +0300)]
events: Extend the events_unwatch_fd() API with an event type

If a single file descriptor is being watch for multiple event types, it
will be present in multiple entries in the watch list. The
events_unwatch_fd() function will remove the first entry regardless of
its type, not allowing removal of a particular event type.

Fix this by extending the events_unwatch_fd() API to take an event type,
and remove the corresponding entry.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agoevents: Import event handling library from omap3-isp-live
Laurent Pinchart [Mon, 21 May 2018 11:39:40 +0000 (14:39 +0300)]
events: Import event handling library from omap3-isp-live

The omap3-isp-live project [1] includes a generic event handling library
that implements a select-based loop. Instead of reinventing the wheel,
import the library and use it.

The original license hasn't been modified, and includes both GPL-2.0+
and LGPL-2.1+ code. The sole copyright owner is Laurent Pinchart.

[1] git://git.ideasonboard.org/omap3-isp-live.git

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agouvc-gadget: Add .gitignore file
Paul Elder [Mon, 12 Mar 2018 08:56:41 +0000 (04:56 -0400)]
uvc-gadget: Add .gitignore file

Signed-off-by: Paul Elder <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
9 months agouvc-gadget: Use new kernel API header
Laurent Pinchart [Sun, 20 May 2018 18:59:10 +0000 (21:59 +0300)]
uvc-gadget: Use new kernel API header

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>
23 months agouvc-gadget: Do not send Set Interface (alternate setting) response twice
Roger Quadros [Fri, 3 Mar 2017 11:17:15 +0000 (13:17 +0200)]
uvc-gadget: Do not send Set Interface (alternate setting) response twice

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>
8 years agoInitial import
Laurent Pinchart [Mon, 7 Jun 2010 09:30:53 +0000 (11:30 +0200)]
Initial import

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>