179 lines
4.8 KiB
C
Executable File
179 lines
4.8 KiB
C
Executable File
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* uvc-gadget API
|
|
*
|
|
* Copyright (C) 2020 Rockchip Electronics Co., Ltd.
|
|
*
|
|
* Author: Bin Yang <yangbin@rock-chips.com>
|
|
*/
|
|
|
|
#ifndef __UVC_GADGET_H__
|
|
#define __UVC_GADGET_H__
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include <stdbool.h>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <linux/videodev2.h>
|
|
#include "list.h"
|
|
#include "tools.h"
|
|
|
|
/* SRC_Args bit map */
|
|
#define SRC_INITIALIZE_FLAG BIT(0)
|
|
#define SRC_FILL_TYPE_IS_V4L2 BIT(1)
|
|
#define SRC_MEM_TYPE_IS_MMAP BIT(2)
|
|
#define SRC_FMT_TYPE_IS_YUYV BIT(3)
|
|
#define SRC_BUF_TYPE_IS_ENC BIT(4)
|
|
#define SRC_BUF_ASYNC_PROCESS BIT(5)
|
|
#define SRC_BUF_SYNC_PROCESS BIT(6)
|
|
#define SRC_FIXED_RESOLUTION BIT(7)
|
|
#define SRC_MEDIA_LINK BIT(8)
|
|
#define SRC_ENABLE_RKAIQ BIT(9)
|
|
#define SRC_ENABLE_CROP BIT(10)
|
|
|
|
#define SINK_USER_SET_MODE BIT(16)
|
|
#define SINK_TRAN_MODE_BULK BIT(17)
|
|
#define SINK_BULK_BUF_STATIC BIT(18)
|
|
#define SINK_FMT_OUTPUT_H265 BIT(19)
|
|
|
|
enum src_func_type {
|
|
SRC_DEVICE_OPEN = 0,
|
|
SRC_DEVICE_CLOSE,
|
|
SRC_STREAM_ON,
|
|
SRC_STREAM_OFF,
|
|
SRC_START_CTRL,
|
|
SRC_RGA_INIT,
|
|
SRC_RGA_DEINIT,
|
|
SRC_RGA_PROC
|
|
};
|
|
|
|
enum uvc_gadget_state {
|
|
UVC_STA_START = 0,
|
|
UVC_STA_DONE,
|
|
UVC_STA_RESET,
|
|
UVC_STA_STOP,
|
|
UVC_STA_ERR
|
|
};
|
|
|
|
struct uvc_pix_size {
|
|
unsigned int width;
|
|
unsigned int height;
|
|
};
|
|
|
|
struct uvc_src_size {
|
|
struct uvc_pix_size src;
|
|
struct uvc_pix_size max;
|
|
struct uvc_pix_size pre;
|
|
};
|
|
|
|
/*
|
|
*
|
|
* struct video_buffer - Video buffer information
|
|
* @index: Zero-based buffer index, limited to the number of buffers minus one
|
|
* @size: Size of the video memory, in bytes
|
|
* @bytesused: Number of bytes used by video data, smaller or equal to @size
|
|
* @timestamp: Time stamp at which the buffer has been captured
|
|
* @error: True if an error occured while capturing video data for the buffer
|
|
* @allocated: True if memory for the buffer has been allocated
|
|
* @mem: Video data memory
|
|
* @dmabuf: Video data dmabuf handle
|
|
*/
|
|
struct video_buffer {
|
|
void *rga_ctx;
|
|
void *allocator;
|
|
struct v4l2_pix_format *fmt;
|
|
unsigned int index;
|
|
unsigned int size;
|
|
unsigned int bytesused;
|
|
struct timeval timestamp;
|
|
bool error;
|
|
void *mem;
|
|
int dmabuf;
|
|
bool readable;
|
|
struct list_entry list;
|
|
};
|
|
|
|
struct rga_video_buffer {
|
|
struct video_buffer *src;
|
|
struct video_buffer *dest;
|
|
};
|
|
|
|
struct video_source {
|
|
char *cap_device;
|
|
struct video_source *psrc;
|
|
const struct video_source_ops *ops;
|
|
struct events *events;
|
|
pthread_mutex_t mutex;
|
|
pthread_cond_t cond;
|
|
unsigned int width;
|
|
unsigned int height;
|
|
unsigned int max_width;
|
|
unsigned int max_height;
|
|
unsigned int index;
|
|
bool pre_flag;
|
|
bool crop;
|
|
};
|
|
|
|
struct uvc_source {
|
|
struct video_source *src;
|
|
const struct video_encode_ops *enc_ops;
|
|
FILE *source_fp;
|
|
void *func;
|
|
void *context;
|
|
void *udev;
|
|
pthread_mutex_t mutex;
|
|
pthread_cond_t cond;
|
|
enum uvc_gadget_state uvc_state;
|
|
unsigned int SRC_Args;
|
|
int log_level;
|
|
bool stream_on;
|
|
};
|
|
|
|
struct video_encode_ops {
|
|
int(*init)(struct uvc_source *src, struct v4l2_pix_format *fmt);
|
|
int(*exit)(struct uvc_source *src);
|
|
int(*process)(struct uvc_source *src, struct video_buffer *src_buffer,
|
|
struct video_buffer *sink_buffer);
|
|
};
|
|
|
|
#define to_first_source(s) ((s) ? s->src : NULL)
|
|
#define to_pre_source(s) ((s && s->src) ? s->src->psrc : NULL)
|
|
|
|
typedef int(*uvc_source_func_t)(struct uvc_source *, void *);
|
|
int uvc_source_func_register(struct uvc_source *src,
|
|
enum src_func_type type,
|
|
uvc_source_func_t func);
|
|
void uvc_source_func_unregister(struct uvc_source *src);
|
|
struct uvc_source *uvc_source_create(unsigned int SRC_Args, char *cap_device);
|
|
void uvc_source_destroy(struct uvc_source *src);
|
|
int uvc_set_source_size(struct uvc_source *src, struct uvc_src_size src_size);
|
|
int uvc_gadget_create(struct uvc_source *src);
|
|
int uvc_gadget_wait_complete(struct uvc_source *src, bool force);
|
|
int uvc_buffer_export(struct uvc_source *src, int imagesize, int flags,
|
|
struct video_buffer **buffer);
|
|
int uvc_buffer_submit(struct uvc_source *src, struct video_buffer *buf);
|
|
int uvc_stream_get(struct uvc_source *src, unsigned int index,
|
|
struct video_buffer **buffer);
|
|
void uvc_set_source_log_level(struct uvc_source *src, int log_level);
|
|
struct v4l2_pix_format *uvc_get_format(struct uvc_source *src);
|
|
struct v4l2_pix_format *uvc_get_dest_format(struct uvc_source *src);
|
|
struct v4l2_pix_format *uvc_get_uvc_format(struct uvc_source *src);
|
|
int uvc_get_frame_rate(struct uvc_source *src);
|
|
char *uvc_get_device(struct uvc_source *src);
|
|
bool uvc_get_stream_on(struct uvc_source *src);
|
|
void uvc_gadget_fixed_function(bool fixed_uvc);
|
|
void uvc_use_dma_buffer(struct uvc_source *src);
|
|
bool uvc_get_dma_buffer(struct uvc_source *src);
|
|
int uvc_video_buffer_alloc(struct uvc_source *src, size_t size,
|
|
struct video_buffer **buf);
|
|
void uvc_video_buffer_free(struct uvc_source *src, struct video_buffer *buf);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* __UVC_GADGET_H__ */
|