Skip to content

Commit

Permalink
uvc: add import/export support
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Grzeschik <[email protected]>
  • Loading branch information
mgrzeschik committed Oct 20, 2021
1 parent 2c2e08b commit bfc19b5
Show file tree
Hide file tree
Showing 3 changed files with 786 additions and 58 deletions.
66 changes: 46 additions & 20 deletions examples/gadget-uvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,61 @@ int main(void)
.configuration = "UVC"
};

struct usbg_f_uvc_format_attrs uvc_format_attrs_array[] = {
struct usbg_f_uvc_frame_attrs uvc_frame_attrs_array[] = {
{
.format = UVC_FORMAT_MJPEG,
.dwFrameInterval = "333333",
.height = 1080,
.width = 1920,
.bFrameIndex = 1,
.dwFrameInterval = 2000000,
.wHeight = 480,
.wWidth = 640,
}, {
.format = UVC_FORMAT_MJPEG,
.dwFrameInterval = "333333",
.height = 2160,
.width = 3840,
.bFrameIndex = 2,
.dwFrameInterval = 2000000,
.wHeight = 1080,
.wWidth = 1920,
}, {
.format = UVC_FORMAT_UNCOMPRESSED,
.dwFrameInterval = "333333",
.height = 1080,
.width = 1920,
.bFrameIndex = 3,
.dwFrameInterval = 333333,
.wHeight = 1080,
.wWidth = 1920,
}, {
.format = UVC_FORMAT_UNCOMPRESSED,
.dwFrameInterval = "333333",
.height = 2160,
.width = 3840,
.bFrameIndex = 4,
.dwFrameInterval = 333333,
.wHeight = 2160,
.wWidth = 3840,
}
};

struct usbg_f_uvc_frame_attrs *uvc_frame_mjpeg_attrs[] = {
&uvc_frame_attrs_array[0],
&uvc_frame_attrs_array[1],
&uvc_frame_attrs_array[2],
&uvc_frame_attrs_array[3],
NULL,
};

struct usbg_f_uvc_frame_attrs *uvc_frame_uncompressed_attrs[] = {
&uvc_frame_attrs_array[0],
&uvc_frame_attrs_array[1],
&uvc_frame_attrs_array[2],
&uvc_frame_attrs_array[3],
NULL,
};

struct usbg_f_uvc_format_attrs uvc_format_attrs_array[] = {
{
.frames = uvc_frame_mjpeg_attrs,
.format = "mjpeg/m",
.bDefaultFrameIndex = 3,
}, {
.frames = uvc_frame_uncompressed_attrs,
.format = "uncompressed/u",
.bDefaultFrameIndex = 2,
}
};

struct usbg_f_uvc_format_attrs *uvc_format_attrs[] = {
&uvc_format_attrs_array[3],
&uvc_format_attrs_array[2],
&uvc_format_attrs_array[1],
&uvc_format_attrs_array[0],
&uvc_format_attrs_array[1],
NULL,
};

Expand Down
82 changes: 64 additions & 18 deletions include/usbg/function/uvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,82 @@ extern "C" {
struct usbg_f_uvc;
typedef struct usbg_f_uvc usbg_f_uvc;

enum uvc_format
struct usbg_f_uvc_frame_attrs
{
UVC_FORMAT_MJPEG,
UVC_FORMAT_UNCOMPRESSED
int bFrameIndex;
int bmCapabilities;
int dwMinBitRate;
int dwMaxBitRate;
int dwMaxVideoFrameBufferSize;
int dwDefaultFrameInterval;
int dwFrameInterval;
int wWidth;
int wHeight;
};

struct usbg_f_uvc_format_attrs
{
enum uvc_format format;
const char *dwFrameInterval;
int height;
int width;
int bmaControls;
int bFormatIndex;
int bDefaultFrameIndex;
int bAspectRatioX;
int bAspectRatioY;
int bmInterfaceFlags;
const char *format;
struct usbg_f_uvc_frame_attrs **frames;
};

struct usbg_f_uvc_attrs
{
struct usbg_f_uvc_format_attrs **formats;
};

enum usbg_f_uvc_frame_attr {
USBG_F_UVC_FRAME_ATTR_MIN = 0,
USBG_F_UVC_FRAME_INDEX = USBG_F_UVC_FRAME_ATTR_MIN,
USBG_F_UVC_FRAME_CAPABILITIES,
USBG_F_UVC_FRAME_MIN_BITRATE,
USBG_F_UVC_FRAME_MAX_BITRATE,
USBG_F_UVC_FRAME_MAX_VIDEO_BUFFERSIZE,
USBG_F_UVC_FRAME_DEFAULT_INTERVAL,
USBG_F_UVC_FRAME_INTERVAL,
USBG_F_UVC_FRAME_HEIGHT,
USBG_F_UVC_FRAME_WIDTH,
USBG_F_UVC_FRAME_ATTR_MAX
};

enum usbg_f_uvc_format_attr {
USBG_F_UVC_FORMAT_ATTR_MIN = 0,
USBG_F_UVC_FORMAT_CONTROLS = USBG_F_UVC_FORMAT_ATTR_MIN,
USBG_F_UVC_FORMAT_INTERFACE_FLAGS,
USBG_F_UVC_FORMAT_ASPECTRATIO_Y,
USBG_F_UVC_FORMAT_ASPECTRATIO_X,
USBG_F_UVC_FORMAT_DEFAULT_FRAME_INDEX,
USBG_F_UVC_FORMAT_FORMAT_INDEX,
USBG_F_UVC_FORMAT_ATTR_MAX
};


union usbg_f_uvc_frame_attr_val {
int bmCapabilities;
int dwMinBitRate;
int dwMaxBitRate;
int dwMaxVideoFrameBufferSize;
int dwDefaultFrameInterval;
int dwFrameInterval;
int wWidth;
int wHeight;
};

union usbg_f_uvc_format_attr_val {
int bmaControls;
int bFormatIndex;
int bDefaultFrameIndex;
int bAspectRatioX;
int bAspectRatioY;
int bmInterfaceFlags;
};

/**
* @brief Cast from generic function to uvc function
* @param[in] f function to be converted to uvc funciton.
Expand All @@ -63,17 +120,6 @@ usbg_function *usbg_from_uvc_function(usbg_f_uvc *ff);
*/
static inline void usbg_f_uvc_cleanup_attrs(struct usbg_f_uvc_attrs *attrs)
{
struct usbg_f_uvc_format_attrs **format_attrs;
int i;

if (attrs) {
for(format_attrs = attrs->formats, i = 0; format_attrs[i]; ++i) {
if (format_attrs[i]) {
free((char *)format_attrs[i]->dwFrameInterval);
format_attrs[i]->dwFrameInterval = NULL;
}
}
}
}

int usbg_f_uvc_get_attrs(usbg_f_uvc *uvcf, struct usbg_f_uvc_attrs *attrs);
Expand Down
Loading

0 comments on commit bfc19b5

Please sign in to comment.