Skip to content
Snippets Groups Projects
Commit 8dbd8ab2 authored by Ezequiel Garcia's avatar Ezequiel Garcia
Browse files

libv4l-rockchip_v2: Update to a our mainline-based interface

parent 7f38f222
Branches
No related tags found
No related merge requests found
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#define PLUGIN_PUBLIC #define PLUGIN_PUBLIC
#endif #endif
#define RK3288_VPU_NAME "rk3288-vpu-enc"
#define HANTRO_VPU_NAME "hantro-vpu"
#define DEFAULT_FRAME_RATE 30 #define DEFAULT_FRAME_RATE 30
#define DEFAULT_BITRATE 1000000 #define DEFAULT_BITRATE 1000000
#define PENDING_BUFFER_QUEUE_SIZE VIDEO_MAX_FRAME #define PENDING_BUFFER_QUEUE_SIZE VIDEO_MAX_FRAME
...@@ -92,7 +94,7 @@ struct pending_buffer_queue { ...@@ -92,7 +94,7 @@ struct pending_buffer_queue {
* when the parameters to pass together with the source buffer are * when the parameters to pass together with the source buffer are
* ready; those params are received on dequeing the previous * ready; those params are received on dequeing the previous
* destination buffer. * destination buffer.
* @get_param_payload: Payload of V4L2_CID_PRIVATE_ROCKCHIP_GET_PARAMS. This is * @get_param_payload: Payload of V4L2_CID_PRIVATE_HANTRO_RET_PARAMS. This is
* used to update the encoder configuration by * used to update the encoder configuration by
* rk_vepu_update_config(). * rk_vepu_update_config().
* @get_param_payload_size: The size of get_param_payload. * @get_param_payload_size: The size of get_param_payload.
...@@ -183,7 +185,7 @@ static struct pending_buffer *queue_back(struct pending_buffer_queue *queue); ...@@ -183,7 +185,7 @@ static struct pending_buffer *queue_back(struct pending_buffer_queue *queue);
bool is_rockchip_encoder(int fd); bool is_rockchip_encoder(int fd);
/* Set encoder configuration to the driver. */ /* Set encoder configuration to the driver. */
int set_encoder_config_locked(struct encoder_context *ctx, int fd, int set_encoder_config_locked(struct encoder_context *ctx, int fd,
uint32_t buffer_index, size_t num_ctrls, uint32_t ctrls_ids[], size_t num_ctrls, uint32_t ctrls_ids[],
void **payloads, uint32_t payload_sizes[]); void **payloads, uint32_t payload_sizes[]);
/* QBUF a buffer from the pending buffer queue if it is not empty. */ /* QBUF a buffer from the pending buffer queue if it is not empty. */
static int qbuf_if_pending_buffer_exists_locked(struct encoder_context *ctx, static int qbuf_if_pending_buffer_exists_locked(struct encoder_context *ctx,
...@@ -226,7 +228,7 @@ static void *plugin_init(int fd) ...@@ -226,7 +228,7 @@ static void *plugin_init(int fd)
queue_init(&ctx->pending_buffers); queue_init(&ctx->pending_buffers);
memset(&ext_ctrl, 0, sizeof(ext_ctrl)); memset(&ext_ctrl, 0, sizeof(ext_ctrl));
ext_ctrl.id = V4L2_CID_PRIVATE_ROCKCHIP_GET_PARAMS; ext_ctrl.id = V4L2_CID_PRIVATE_HANTRO_RET_PARAMS;
ret = SYS_IOCTL(fd, VIDIOC_QUERY_EXT_CTRL, &ext_ctrl); ret = SYS_IOCTL(fd, VIDIOC_QUERY_EXT_CTRL, &ext_ctrl);
if (ret) { if (ret) {
goto fail; goto fail;
...@@ -400,12 +402,11 @@ static int ioctl_qbuf_locked(struct encoder_context *ctx, int fd, ...@@ -400,12 +402,11 @@ static int ioctl_qbuf_locked(struct encoder_context *ctx, int fd,
return -EIO; return -EIO;
} }
/* Set the encoder configuration to the driver. */ /* Set the encoder configuration to the driver. */
ret = set_encoder_config_locked(ctx, fd, buffer->index, num_ctrls, ctrl_ids, ret = set_encoder_config_locked(ctx, fd, num_ctrls, ctrl_ids,
payloads, payload_sizes); payloads, payload_sizes);
if (ret) if (ret)
return ret; return ret;
buffer->config_store = buffer->index + 1;
ret = SYS_IOCTL(fd, VIDIOC_QBUF, buffer); ret = SYS_IOCTL(fd, VIDIOC_QBUF, buffer);
if (ret == 0) if (ret == 0)
ctx->can_qbuf = false; ctx->can_qbuf = false;
...@@ -440,7 +441,7 @@ static int ioctl_dqbuf_locked(struct encoder_context *ctx, int fd, ...@@ -440,7 +441,7 @@ static int ioctl_dqbuf_locked(struct encoder_context *ctx, int fd,
memset(ctx->get_param_payload, 0, ctx->get_param_payload_size); memset(ctx->get_param_payload, 0, ctx->get_param_payload_size);
memset(&v4l2_ctrl, 0, sizeof(v4l2_ctrl)); memset(&v4l2_ctrl, 0, sizeof(v4l2_ctrl));
v4l2_ctrl.id = V4L2_CID_PRIVATE_ROCKCHIP_GET_PARAMS; v4l2_ctrl.id = V4L2_CID_PRIVATE_HANTRO_RET_PARAMS;
v4l2_ctrl.size = ctx->get_param_payload_size; v4l2_ctrl.size = ctx->get_param_payload_size;
v4l2_ctrl.ptr = ctx->get_param_payload; v4l2_ctrl.ptr = ctx->get_param_payload;
memset(&ext_ctrls, 0, sizeof(ext_ctrls)); memset(&ext_ctrls, 0, sizeof(ext_ctrls));
...@@ -708,11 +709,12 @@ bool is_rockchip_encoder(int fd) { ...@@ -708,11 +709,12 @@ bool is_rockchip_encoder(int fd) {
if (ret) if (ret)
return false; return false;
VLOG_FD(1, "driver name return %s\n", (char*)cap.card); VLOG_FD(1, "driver name return %s\n", (char*)cap.card);
return strstr((const char *)cap.card, "-enc") != NULL; return strcmp(RK3288_VPU_NAME, (const char *)cap.driver) == 0 ||
strcmp(HANTRO_VPU_NAME, (const char *)cap.driver) == 0;
} }
int set_encoder_config_locked(struct encoder_context *ctx, int fd, int set_encoder_config_locked(struct encoder_context *ctx, int fd,
uint32_t buffer_index, size_t num_ctrls, uint32_t ctrl_ids[], size_t num_ctrls, uint32_t ctrl_ids[],
void **payloads, uint32_t payload_sizes[]) void **payloads, uint32_t payload_sizes[])
{ {
size_t i; size_t i;
...@@ -727,7 +729,6 @@ int set_encoder_config_locked(struct encoder_context *ctx, int fd, ...@@ -727,7 +729,6 @@ int set_encoder_config_locked(struct encoder_context *ctx, int fd,
return -EIO; return -EIO;
} }
memset(&ext_ctrls, 0, sizeof(ext_ctrls)); memset(&ext_ctrls, 0, sizeof(ext_ctrls));
ext_ctrls.config_store = buffer_index + 1;
ext_ctrls.count = num_ctrls; ext_ctrls.count = num_ctrls;
ext_ctrls.controls = ctx->v4l2_ctrls; ext_ctrls.controls = ctx->v4l2_ctrls;
memset(ctx->v4l2_ctrls, 0, sizeof(ctx->v4l2_ctrls)); memset(ctx->v4l2_ctrls, 0, sizeof(ctx->v4l2_ctrls));
...@@ -799,6 +800,15 @@ static int initialize_libvpu(struct encoder_context *ctx, int fd) ...@@ -799,6 +800,15 @@ static int initialize_libvpu(struct encoder_context *ctx, int fd)
init_param.output_format = format.fmt.pix_mp.pixelformat; init_param.output_format = format.fmt.pix_mp.pixelformat;
/* Get the cropped size. */ /* Get the cropped size. */
#if 0
struct v4l2_crop crop;
memset(&crop, 0, sizeof(crop));
crop.type = ctx->output_streamon_type;
ret = SYS_IOCTL(fd, VIDIOC_G_CROP, &crop);
if (ret)
return ret;
#endif
init_param.width = ctx->crop_width; init_param.width = ctx->crop_width;
init_param.height = ctx->crop_height; init_param.height = ctx->crop_height;
......
...@@ -490,7 +490,7 @@ static int h264e_init(struct rk_venc *ictx, ...@@ -490,7 +490,7 @@ static int h264e_init(struct rk_venc *ictx,
if (ctx->pps.transform_8x8_mode_flag == 2) if (ctx->pps.transform_8x8_mode_flag == 2)
ctx->pps.transform_8x8_mode_flag = 1; ctx->pps.transform_8x8_mode_flag = 1;
ctx->rk_ctrl_ids[0] = V4L2_CID_PRIVATE_ROCKCHIP_REG_PARAMS; ctx->rk_ctrl_ids[0] = V4L2_CID_PRIVATE_HANTRO_REG_PARAMS;
h264e_build_stream_header(ictx); h264e_build_stream_header(ictx);
......
...@@ -17,12 +17,11 @@ ...@@ -17,12 +17,11 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
/* TODO(wuchengli): Remove these after the header is updated. */ #define V4L2_CID_USER_HANTRO_ENCODER_BASE (V4L2_CID_USER_BASE + 0x2000)
#define V4L2_CID_CUSTOM_BASE (V4L2_CID_USER_BASE | 0x1000) #define V4L2_CID_PRIVATE_HANTRO_HEADER (V4L2_CID_USER_HANTRO_ENCODER_BASE + 0)
#define V4L2_CID_PRIVATE_ROCKCHIP_HEADER (V4L2_CID_CUSTOM_BASE) #define V4L2_CID_PRIVATE_HANTRO_REG_PARAMS (V4L2_CID_USER_HANTRO_ENCODER_BASE + 1)
#define V4L2_CID_PRIVATE_ROCKCHIP_REG_PARAMS (V4L2_CID_CUSTOM_BASE + 1) #define V4L2_CID_PRIVATE_HANTRO_HW_PARAMS (V4L2_CID_USER_HANTRO_ENCODER_BASE + 2)
#define V4L2_CID_PRIVATE_ROCKCHIP_HW_PARAMS (V4L2_CID_CUSTOM_BASE + 2) #define V4L2_CID_PRIVATE_HANTRO_RET_PARAMS (V4L2_CID_USER_HANTRO_ENCODER_BASE + 3)
#define V4L2_CID_PRIVATE_ROCKCHIP_GET_PARAMS (V4L2_CID_CUSTOM_BASE + 3)
#ifndef V4L2_CID_MPEG_VIDEO_H264_SPS_PPS_BEFORE_IDR #ifndef V4L2_CID_MPEG_VIDEO_H264_SPS_PPS_BEFORE_IDR
#define V4L2_CID_MPEG_VIDEO_H264_SPS_PPS_BEFORE_IDR (V4L2_CID_MPEG_BASE+388) #define V4L2_CID_MPEG_VIDEO_H264_SPS_PPS_BEFORE_IDR (V4L2_CID_MPEG_BASE+388)
......
...@@ -88,9 +88,9 @@ static int vp8e_init(struct rk_venc *ictx, ...@@ -88,9 +88,9 @@ static int vp8e_init(struct rk_venc *ictx,
return -1; return -1;
} }
ctx->rk_ctrl_ids[0] = V4L2_CID_PRIVATE_ROCKCHIP_HEADER; ctx->rk_ctrl_ids[0] = V4L2_CID_PRIVATE_HANTRO_HEADER;
ctx->rk_ctrl_ids[1] = V4L2_CID_PRIVATE_ROCKCHIP_REG_PARAMS; ctx->rk_ctrl_ids[1] = V4L2_CID_PRIVATE_HANTRO_REG_PARAMS;
ctx->rk_ctrl_ids[2] = V4L2_CID_PRIVATE_ROCKCHIP_HW_PARAMS; ctx->rk_ctrl_ids[2] = V4L2_CID_PRIVATE_HANTRO_HW_PARAMS;
return 0; return 0;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment