henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 1 | /* Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 6 | #include <assert.h> |
| 7 | #include <errno.h> |
| 8 | #include <linux/videodev2.h> |
| 9 | #include <pthread.h> |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 10 | #include <unistd.h> |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 11 | #include <stdbool.h> |
| 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <string.h> |
| 15 | #include <sys/queue.h> |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 16 | #include <sys/syscall.h> |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 17 | #include "config.h" /* For HAVE_VISIBILITY */ |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 18 | #include "libv4l-plugin.h" |
Alpha Lin | fa5caae | 2014-11-17 09:48:35 +0800 | [diff] [blame] | 19 | #include "libvpu/rk_vepu_debug.h" |
Wu-Cheng Li | dcec433 | 2014-11-13 15:49:21 +0800 | [diff] [blame] | 20 | #include "libvpu/rk_vepu_interface.h" |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 21 | |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 22 | #define VLOG(log_level, str, ...) ((g_log_level >= log_level) ? \ |
| 23 | (void) fprintf(stderr, "%s: " str "\n", __func__, ##__VA_ARGS__) \ |
| 24 | : (void) 0) |
| 25 | |
| 26 | #define VLOG_FD(log_level, str, ...) ((g_log_level >= log_level) ? \ |
| 27 | (void) fprintf(stderr, \ |
| 28 | "%s: fd=%d. " str "\n", __func__, fd, ##__VA_ARGS__) : (void) 0) |
| 29 | |
| 30 | #define SYS_IOCTL(fd, cmd, arg) ({ \ |
| 31 | int ret = syscall(SYS_ioctl, (int)(fd), (unsigned long)(cmd), \ |
| 32 | (void *)(arg)); \ |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 33 | if ((ret && errno != EAGAIN) || g_log_level >= 2) \ |
| 34 | fprintf(stderr, "SYS_ioctl: %s(%lu): fd=%d, ret=%d, errno=%d\n",\ |
| 35 | v4l_cmd2str(cmd), _IOC_NR((unsigned long)cmd), fd, ret, \ |
| 36 | errno); \ |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 37 | ret; \ |
| 38 | }) |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 39 | |
| 40 | #if HAVE_VISIBILITY |
| 41 | #define PLUGIN_PUBLIC __attribute__ ((__visibility__("default"))) |
| 42 | #else |
| 43 | #define PLUGIN_PUBLIC |
| 44 | #endif |
| 45 | |
Wu-Cheng Li | 11ae3aa | 2014-12-18 17:11:48 +0800 | [diff] [blame] | 46 | #define RK3288_VPU_NAME "rk3288-vpu-enc" |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 47 | #define DEFAULT_FRAME_RATE 30 |
| 48 | #define DEFAULT_BITRATE 1000000 |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 49 | #define PENDING_BUFFER_QUEUE_SIZE VIDEO_MAX_FRAME |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 50 | |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 51 | /* |
| 52 | * struct pending_buffer - A v4l2 buffer pending for QBUF. |
| 53 | * @buffer: v4l2 buffer for QBUF. |
| 54 | * @planes: plane info of v4l2 buffer. |
| 55 | * @next_runtime_param: runtime parameters like framerate, bitrate, and |
| 56 | * keyframe for the next buffer. |
| 57 | */ |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 58 | struct pending_buffer { |
| 59 | struct v4l2_buffer buffer; |
| 60 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 61 | struct rk_vepu_runtime_param next_runtime_param; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 62 | }; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * struct pending_buffer_queue - a ring buffer of pending buffers. |
| 66 | * @count: the number of buffers stored in the array. |
| 67 | * @front: the index of the first ready buffer. |
| 68 | * @buf_array: pending buffer array. |
| 69 | */ |
| 70 | struct pending_buffer_queue { |
| 71 | uint32_t count; |
| 72 | int32_t front; |
| 73 | struct pending_buffer buf_array[PENDING_BUFFER_QUEUE_SIZE]; |
| 74 | }; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * struct encoder_context - the context of an encoder instance. |
| 78 | * @enc: Encoder instance returned from rk_vepu_create(). |
| 79 | * @mutex: The mutex to protect encoder_context. |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 80 | * @output_streamon_type: Type of output interface when it streams on. |
| 81 | * @capture_streamon_type: Type of capture interface when it streams on. |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 82 | * @init_param: Encoding parameters like input format, resolution, and etc. |
| 83 | * These parameters will be passed to encoder at libvpu |
| 84 | * initialization. |
| 85 | * @runtime_param: Runtime parameters like framerate, bitrate, and |
| 86 | * keyframe. This is only used for receiving ext_ctrls |
| 87 | * before streamon and pending buffer queue is empty. |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 88 | * @pending_buffers: The pending v4l2 buffers waiting for the encoding |
| 89 | * configuration. After a previous buffer is dequeued, |
| 90 | * one buffer from the queue can be queued. |
| 91 | * @can_qbuf: Indicate that we can queue one source buffer. This is true only |
| 92 | * when the parameters to pass together with the source buffer are |
| 93 | * ready; those params are received on dequeing the previous |
| 94 | * destination buffer. |
| 95 | * @get_param_payload: Payload of V4L2_CID_PRIVATE_RK3288_GET_PARAMS. This is |
| 96 | * used to update the encoder configuration by |
| 97 | * rk_vepu_update_config(). |
| 98 | * @get_param_payload_size: The size of get_param_payload. |
| 99 | * @v4l2_ctrls: v4l2 controls for VIDIOC_S_EXT_CTRLS. |
| 100 | */ |
| 101 | struct encoder_context { |
| 102 | void *enc; |
| 103 | pthread_mutex_t mutex; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 104 | enum v4l2_buf_type output_streamon_type; |
| 105 | enum v4l2_buf_type capture_streamon_type; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 106 | struct rk_vepu_init_param init_param; |
| 107 | struct rk_vepu_runtime_param runtime_param; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 108 | struct pending_buffer_queue pending_buffers; |
| 109 | bool can_qbuf; |
| 110 | void *get_param_payload; |
| 111 | size_t get_param_payload_size; |
| 112 | struct v4l2_ext_control v4l2_ctrls[MAX_NUM_GET_CONFIG_CTRLS]; |
| 113 | }; |
| 114 | |
| 115 | static void *plugin_init(int fd); |
| 116 | static void plugin_close(void *dev_ops_priv); |
| 117 | static int plugin_ioctl(void *dev_ops_priv, int fd, unsigned long int cmd, |
| 118 | void *arg); |
| 119 | |
| 120 | /* Functions to handle various ioctl. */ |
| 121 | static int ioctl_streamon_locked( |
| 122 | struct encoder_context *ctx, int fd, enum v4l2_buf_type *type); |
| 123 | static int ioctl_streamoff_locked( |
| 124 | struct encoder_context *ctx, int fd, enum v4l2_buf_type *type); |
| 125 | static int ioctl_qbuf_locked(struct encoder_context *ctx, int fd, |
| 126 | struct v4l2_buffer *buffer); |
| 127 | static int ioctl_dqbuf_locked(struct encoder_context *ctx, int fd, |
| 128 | struct v4l2_buffer *buffer); |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 129 | static int ioctl_s_ext_ctrls_locked(struct encoder_context *ctx, int fd, |
| 130 | struct v4l2_ext_controls *ext_ctrls); |
| 131 | static int ioctl_s_parm_locked(struct encoder_context *ctx, int fd, |
| 132 | struct v4l2_streamparm *parms); |
| 133 | static int ioctl_reqbufs_locked(struct encoder_context *ctx, int fd, |
| 134 | struct v4l2_requestbuffers *reqbufs); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 135 | |
| 136 | /* Helper functions to manipulate the pending buffer queue. */ |
| 137 | |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 138 | static void queue_init(struct pending_buffer_queue *queue); |
| 139 | static bool queue_empty(struct pending_buffer_queue *queue); |
| 140 | static bool queue_full(struct pending_buffer_queue *queue); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 141 | /* Insert a buffer to the tail of the queue. */ |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 142 | static int queue_push_back(struct pending_buffer_queue *queue, |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 143 | struct v4l2_buffer *buffer); |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 144 | /* Remove a buffer from the head of the queue. */ |
| 145 | static void queue_pop_front(struct pending_buffer_queue *queue); |
| 146 | static struct pending_buffer *queue_front(struct pending_buffer_queue *queue); |
| 147 | static struct pending_buffer *queue_back(struct pending_buffer_queue *queue); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 148 | |
Wu-Cheng Li | 11ae3aa | 2014-12-18 17:11:48 +0800 | [diff] [blame] | 149 | /* Returns true if the fd is Rockchip encoder device. */ |
| 150 | bool is_rockchip_encoder(int fd); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 151 | /* Set encoder configuration to the driver. */ |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 152 | int set_encoder_config_locked(struct encoder_context *ctx, int fd, |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 153 | uint32_t buffer_index, size_t num_ctrls, uint32_t ctrls_ids[], |
| 154 | void **payloads, uint32_t payload_sizes[]); |
| 155 | /* QBUF a buffer from the pending buffer queue if it is not empty. */ |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 156 | static int qbuf_if_pending_buffer_exists_locked(struct encoder_context *ctx, |
| 157 | int fd); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 158 | /* Get the encoder parameters using G_FMT and initialize libvpu. */ |
| 159 | static int initialize_libvpu(struct encoder_context *ctx, int fd); |
| 160 | /* Return the string represenation of a libv4l command for debugging. */ |
| 161 | static const char *v4l_cmd2str(unsigned long int cmd); |
Alpha Lin | fa5caae | 2014-11-17 09:48:35 +0800 | [diff] [blame] | 162 | /* Get the log level from the environment variable LIBV4L_PLUGIN_LOG_LEVEL. */ |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 163 | static void get_log_level(); |
| 164 | static pthread_once_t g_get_log_level_once = PTHREAD_ONCE_INIT; |
| 165 | |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 166 | static void *plugin_init(int fd) |
| 167 | { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 168 | int ret; |
| 169 | struct v4l2_query_ext_ctrl ext_ctrl; |
| 170 | |
| 171 | pthread_once(&g_get_log_level_once, get_log_level); |
| 172 | |
| 173 | VLOG_FD(1, ""); |
Wu-Cheng Li | 11ae3aa | 2014-12-18 17:11:48 +0800 | [diff] [blame] | 174 | if (!is_rockchip_encoder(fd)) |
| 175 | return NULL; |
| 176 | |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 177 | struct encoder_context *ctx = (struct encoder_context *) |
| 178 | calloc(1, sizeof(struct encoder_context)); |
| 179 | if (ctx == NULL) { |
| 180 | errno = ENOMEM; |
| 181 | goto fail; |
| 182 | } |
| 183 | ret = pthread_mutex_init(&ctx->mutex, NULL); |
| 184 | if (ret) |
| 185 | goto fail; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 186 | queue_init(&ctx->pending_buffers); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 187 | |
| 188 | memset(&ext_ctrl, 0, sizeof(ext_ctrl)); |
| 189 | ext_ctrl.id = V4L2_CID_PRIVATE_RK3288_GET_PARAMS; |
| 190 | ret = SYS_IOCTL(fd, VIDIOC_QUERY_EXT_CTRL, &ext_ctrl); |
| 191 | if (ret) { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 192 | goto fail; |
| 193 | } |
| 194 | ctx->get_param_payload_size = ext_ctrl.elem_size; |
| 195 | ctx->get_param_payload = calloc(1, ctx->get_param_payload_size); |
| 196 | if (ctx->get_param_payload == NULL) { |
| 197 | errno = ENOMEM; |
| 198 | goto fail; |
| 199 | } |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 200 | ctx->runtime_param.framerate_numer = DEFAULT_FRAME_RATE; |
| 201 | ctx->runtime_param.framerate_denom = 1; |
| 202 | ctx->runtime_param.bitrate = DEFAULT_BITRATE; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 203 | VLOG_FD(1, "Success. ctx=%p", ctx); |
| 204 | return ctx; |
| 205 | |
| 206 | fail: |
| 207 | plugin_close(ctx); |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | static void plugin_close(void *dev_ops_priv) |
| 212 | { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 213 | struct encoder_context *ctx = (struct encoder_context *)dev_ops_priv; |
| 214 | |
| 215 | VLOG(1, "ctx=%p", ctx); |
| 216 | if (ctx == NULL) |
| 217 | return; |
| 218 | |
| 219 | pthread_mutex_lock(&ctx->mutex); |
| 220 | if (ctx->enc) |
| 221 | rk_vepu_deinit(ctx->enc); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 222 | free(ctx->get_param_payload); |
| 223 | ctx->get_param_payload = NULL; |
| 224 | pthread_mutex_unlock(&ctx->mutex); |
| 225 | pthread_mutex_destroy(&ctx->mutex); |
| 226 | |
| 227 | free(ctx); |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int plugin_ioctl(void *dev_ops_priv, int fd, |
| 231 | unsigned long int cmd, void *arg) |
| 232 | { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 233 | int ret; |
| 234 | struct encoder_context *ctx = (struct encoder_context *)dev_ops_priv; |
| 235 | |
| 236 | VLOG_FD(1, "%s(%lu)", v4l_cmd2str(cmd), _IOC_NR(cmd)); |
| 237 | |
| 238 | pthread_mutex_lock(&ctx->mutex); |
| 239 | switch (cmd) { |
| 240 | case VIDIOC_STREAMON: |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 241 | ret = ioctl_streamon_locked(ctx, fd, arg); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 242 | break; |
| 243 | |
| 244 | case VIDIOC_STREAMOFF: |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 245 | ret = ioctl_streamoff_locked(ctx, fd, arg); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 246 | break; |
| 247 | |
| 248 | case VIDIOC_QBUF: |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 249 | ret = ioctl_qbuf_locked(ctx, fd, arg); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 250 | break; |
| 251 | |
| 252 | case VIDIOC_DQBUF: |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 253 | ret = ioctl_dqbuf_locked(ctx, fd, arg); |
| 254 | break; |
| 255 | |
| 256 | case VIDIOC_S_EXT_CTRLS: |
| 257 | ret = ioctl_s_ext_ctrls_locked(ctx, fd, arg); |
| 258 | break; |
| 259 | |
| 260 | case VIDIOC_S_PARM: |
| 261 | ret = ioctl_s_parm_locked(ctx, fd, arg); |
| 262 | break; |
| 263 | |
| 264 | case VIDIOC_REQBUFS: |
| 265 | ret = ioctl_reqbufs_locked(ctx, fd, arg); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 266 | break; |
| 267 | |
| 268 | default: |
| 269 | ret = SYS_IOCTL(fd, cmd, arg); |
| 270 | break; |
| 271 | } |
| 272 | pthread_mutex_unlock(&ctx->mutex); |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | static int ioctl_streamon_locked( |
| 277 | struct encoder_context *ctx, int fd, enum v4l2_buf_type *type) |
| 278 | { |
| 279 | int ret = SYS_IOCTL(fd, VIDIOC_STREAMON, type); |
| 280 | if (ret) |
| 281 | return ret; |
| 282 | |
| 283 | if (V4L2_TYPE_IS_OUTPUT(*type)) |
| 284 | ctx->output_streamon_type = *type; |
| 285 | else |
| 286 | ctx->capture_streamon_type = *type; |
| 287 | if (ctx->output_streamon_type && ctx->capture_streamon_type) { |
| 288 | ret = initialize_libvpu(ctx, fd); |
| 289 | if (ret) |
| 290 | return ret; |
| 291 | ctx->can_qbuf = true; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 292 | return qbuf_if_pending_buffer_exists_locked(ctx, fd); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 293 | } |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static int ioctl_streamoff_locked( |
| 298 | struct encoder_context *ctx, int fd, enum v4l2_buf_type *type) |
| 299 | { |
| 300 | int ret = SYS_IOCTL(fd, VIDIOC_STREAMOFF, type); |
| 301 | if (ret) |
| 302 | return ret; |
| 303 | |
| 304 | if (V4L2_TYPE_IS_OUTPUT(*type)) |
| 305 | ctx->output_streamon_type = 0; |
| 306 | else |
| 307 | ctx->capture_streamon_type = 0; |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | static int ioctl_qbuf_locked(struct encoder_context *ctx, int fd, |
| 312 | struct v4l2_buffer *buffer) |
| 313 | { |
| 314 | size_t num_ctrls = 0; |
| 315 | uint32_t *ctrl_ids = NULL, *payload_sizes = NULL; |
| 316 | void **payloads = NULL; |
| 317 | int ret; |
| 318 | |
| 319 | if (!V4L2_TYPE_IS_OUTPUT(buffer->type)) { |
| 320 | return SYS_IOCTL(fd, VIDIOC_QBUF, buffer); |
| 321 | } |
| 322 | |
| 323 | if (!ctx->can_qbuf) { |
| 324 | VLOG_FD(1, "Put buffer (%d) in the pending queue.", |
| 325 | buffer->index); |
| 326 | /* |
| 327 | * The last frame is not encoded yet. Put the buffer to the |
| 328 | * pending queue. |
| 329 | */ |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 330 | return queue_push_back(&ctx->pending_buffers, buffer); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 331 | } |
| 332 | /* Get the encoder configuration from the library. */ |
| 333 | if (rk_vepu_get_config(ctx->enc, &num_ctrls, &ctrl_ids, &payloads, |
| 334 | &payload_sizes)) { |
| 335 | VLOG_FD(0, "rk_vepu_get_config failed"); |
| 336 | return -EIO; |
| 337 | } |
| 338 | /* Set the encoder configuration to the driver. */ |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 339 | ret = set_encoder_config_locked(ctx, fd, buffer->index, num_ctrls, ctrl_ids, |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 340 | payloads, payload_sizes); |
| 341 | if (ret) |
| 342 | return ret; |
| 343 | |
Heng-Ruey Hsu | 61eb2ec | 2016-05-20 18:11:53 +0800 | [diff] [blame] | 344 | buffer->config_store = buffer->index + 1; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 345 | ret = SYS_IOCTL(fd, VIDIOC_QBUF, buffer); |
| 346 | if (ret == 0) |
| 347 | ctx->can_qbuf = false; |
| 348 | else |
| 349 | VLOG(0, "QBUF failed. errno=%d", errno); |
| 350 | return ret; |
| 351 | } |
| 352 | |
| 353 | static int ioctl_dqbuf_locked(struct encoder_context *ctx, int fd, |
| 354 | struct v4l2_buffer *buffer) |
| 355 | { |
| 356 | struct v4l2_ext_controls ext_ctrls; |
| 357 | struct v4l2_ext_control v4l2_ctrl; |
| 358 | int ret; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 359 | uint32_t bytesused; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 360 | |
| 361 | if (V4L2_TYPE_IS_OUTPUT(buffer->type)) { |
| 362 | return SYS_IOCTL(fd, VIDIOC_DQBUF, buffer); |
| 363 | } |
| 364 | |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 365 | ret = SYS_IOCTL(fd, VIDIOC_DQBUF, buffer); |
| 366 | if (ret) |
| 367 | return ret; |
| 368 | |
Wu-Cheng Li | f1e616b | 2014-11-21 15:11:34 +0800 | [diff] [blame] | 369 | assert(!ctx->can_qbuf); |
| 370 | |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 371 | /* Get the encoder configuration and update the library. */ |
| 372 | memset(ctx->get_param_payload, 0, ctx->get_param_payload_size); |
| 373 | memset(&v4l2_ctrl, 0, sizeof(v4l2_ctrl)); |
| 374 | v4l2_ctrl.id = V4L2_CID_PRIVATE_RK3288_GET_PARAMS; |
| 375 | v4l2_ctrl.size = ctx->get_param_payload_size; |
Wu-Cheng Li | adc8ec8 | 2014-11-21 15:51:59 +0800 | [diff] [blame] | 376 | v4l2_ctrl.ptr = ctx->get_param_payload; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 377 | memset(&ext_ctrls, 0, sizeof(ext_ctrls)); |
| 378 | /* TODO: change this to config_store after the header is updated. */ |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 379 | ext_ctrls.ctrl_class = 0; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 380 | ext_ctrls.count = 1; |
| 381 | ext_ctrls.controls = &v4l2_ctrl; |
| 382 | ret = SYS_IOCTL(fd, VIDIOC_G_EXT_CTRLS, &ext_ctrls); |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 383 | if (ret) |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 384 | return ret; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 385 | bytesused = V4L2_TYPE_IS_MULTIPLANAR(buffer->type) ? |
| 386 | buffer->m.planes[0].bytesused : buffer->bytesused; |
| 387 | |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 388 | if (rk_vepu_update_config(ctx->enc, v4l2_ctrl.ptr, v4l2_ctrl.size, |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 389 | bytesused)) { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 390 | VLOG_FD(0, "rk_vepu_update_config failed."); |
| 391 | return -EIO; |
| 392 | } |
| 393 | ctx->can_qbuf = true; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 394 | return qbuf_if_pending_buffer_exists_locked(ctx, fd); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 395 | } |
| 396 | |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 397 | static int ioctl_s_ext_ctrls_locked(struct encoder_context *ctx, int fd, |
| 398 | struct v4l2_ext_controls *ext_ctrls) |
| 399 | { |
| 400 | size_t i; |
| 401 | struct rk_vepu_runtime_param *runtime_param_ptr; |
| 402 | |
| 403 | bool no_pending_buffer = queue_empty(&ctx->pending_buffers); |
| 404 | /* |
| 405 | * If buffer queue is empty, update parameters directly. |
| 406 | * If buffer queue is not empty, save parameters to the last buffer. And |
| 407 | * these values will be sent again when the buffer is ready to deliver. |
| 408 | */ |
| 409 | if (!no_pending_buffer) { |
| 410 | struct pending_buffer *element = queue_back(&ctx->pending_buffers); |
| 411 | runtime_param_ptr = &element->next_runtime_param; |
| 412 | } else { |
| 413 | runtime_param_ptr = &ctx->runtime_param; |
| 414 | } |
| 415 | |
| 416 | /* |
| 417 | * Check each extension control to update keyframe and bitrate |
| 418 | * parameters. |
| 419 | */ |
| 420 | for (i = 0; i < ext_ctrls->count; i++) { |
| 421 | switch (ext_ctrls->controls[i].id) { |
Heng-Ruey Hsu | 61eb2ec | 2016-05-20 18:11:53 +0800 | [diff] [blame] | 422 | case V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME: |
| 423 | runtime_param_ptr->keyframe_request = true; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 424 | break; |
| 425 | case V4L2_CID_MPEG_VIDEO_BITRATE: |
| 426 | runtime_param_ptr->bitrate = ext_ctrls->controls[i].value; |
| 427 | break; |
| 428 | default: |
| 429 | break; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | if (no_pending_buffer && ctx->enc) { |
| 434 | if (rk_vepu_update_parameter(ctx->enc, runtime_param_ptr)) { |
| 435 | VLOG_FD(0, "rk_vepu_update_parameter failed."); |
| 436 | return -EIO; |
| 437 | } |
| 438 | memset(runtime_param_ptr, 0, sizeof(struct rk_vepu_runtime_param)); |
| 439 | } |
| 440 | /* Driver should ignore keyframe and bitrate controls */ |
| 441 | return SYS_IOCTL(fd, VIDIOC_S_EXT_CTRLS, ext_ctrls); |
| 442 | } |
| 443 | |
| 444 | static int ioctl_s_parm_locked(struct encoder_context *ctx, int fd, |
| 445 | struct v4l2_streamparm *parms) |
| 446 | { |
| 447 | if (V4L2_TYPE_IS_OUTPUT(parms->type) |
| 448 | && parms->parm.output.timeperframe.denominator) { |
| 449 | struct rk_vepu_runtime_param *runtime_param_ptr; |
| 450 | bool no_pending_buffer = queue_empty(&ctx->pending_buffers); |
| 451 | struct pending_buffer *element = queue_back(&ctx->pending_buffers); |
| 452 | |
| 453 | runtime_param_ptr = no_pending_buffer ? &ctx->runtime_param : |
| 454 | &element->next_runtime_param; |
| 455 | runtime_param_ptr->framerate_numer = |
| 456 | parms->parm.output.timeperframe.denominator; |
| 457 | runtime_param_ptr->framerate_denom = |
| 458 | parms->parm.output.timeperframe.numerator; |
| 459 | |
| 460 | if (!no_pending_buffer || !ctx->enc) |
| 461 | return 0; |
| 462 | if (rk_vepu_update_parameter(ctx->enc, runtime_param_ptr)) { |
| 463 | VLOG_FD(0, "rk_vepu_update_parameter failed."); |
| 464 | return -EIO; |
| 465 | } |
| 466 | memset(runtime_param_ptr, 0, sizeof(struct rk_vepu_runtime_param)); |
| 467 | return 0; |
| 468 | } |
| 469 | return SYS_IOCTL(fd, VIDIOC_S_PARM, parms); |
| 470 | } |
| 471 | |
| 472 | static int ioctl_reqbufs_locked(struct encoder_context *ctx, int fd, |
| 473 | struct v4l2_requestbuffers *reqbufs) |
| 474 | { |
| 475 | int ret = SYS_IOCTL(fd, VIDIOC_REQBUFS, reqbufs); |
| 476 | if (ret) |
| 477 | return ret; |
| 478 | queue_init(&ctx->pending_buffers); |
| 479 | return 0; |
| 480 | } |
| 481 | |
Wu-Cheng Li | 11ae3aa | 2014-12-18 17:11:48 +0800 | [diff] [blame] | 482 | bool is_rockchip_encoder(int fd) { |
| 483 | struct v4l2_capability cap; |
| 484 | memset(&cap, 0, sizeof(cap)); |
| 485 | int ret = SYS_IOCTL(fd, VIDIOC_QUERYCAP, &cap); |
| 486 | if (ret) |
| 487 | return false; |
Alpha Lin | fa5caae | 2014-11-17 09:48:35 +0800 | [diff] [blame] | 488 | return strcmp(RK3288_VPU_NAME, (const char *)cap.driver) == 0; |
Wu-Cheng Li | 11ae3aa | 2014-12-18 17:11:48 +0800 | [diff] [blame] | 489 | } |
| 490 | |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 491 | int set_encoder_config_locked(struct encoder_context *ctx, int fd, |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 492 | uint32_t buffer_index, size_t num_ctrls, uint32_t ctrl_ids[], |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 493 | void **payloads, uint32_t payload_sizes[]) |
| 494 | { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 495 | size_t i; |
| 496 | struct v4l2_ext_controls ext_ctrls; |
| 497 | |
| 498 | if (num_ctrls <= 0) |
| 499 | return 0; |
| 500 | |
| 501 | assert(num_ctrls <= MAX_NUM_GET_CONFIG_CTRLS); |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 502 | if (num_ctrls > MAX_NUM_GET_CONFIG_CTRLS) { |
| 503 | VLOG_FD(0, "The number of controls exceeds limit."); |
| 504 | return -EIO; |
| 505 | } |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 506 | memset(&ext_ctrls, 0, sizeof(ext_ctrls)); |
| 507 | /* TODO: change this to config_store after the header is updated. */ |
| 508 | ext_ctrls.ctrl_class = buffer_index + 1; |
| 509 | ext_ctrls.count = num_ctrls; |
| 510 | ext_ctrls.controls = ctx->v4l2_ctrls; |
| 511 | memset(ctx->v4l2_ctrls, 0, sizeof(ctx->v4l2_ctrls)); |
| 512 | for (i = 0; i < num_ctrls; ++i) { |
| 513 | ctx->v4l2_ctrls[i].id = ctrl_ids[i]; |
| 514 | ctx->v4l2_ctrls[i].ptr = payloads[i]; |
| 515 | ctx->v4l2_ctrls[i].size = payload_sizes[i]; |
| 516 | } |
| 517 | int ret = SYS_IOCTL(fd, VIDIOC_S_EXT_CTRLS, &ext_ctrls); |
| 518 | if (ret) { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 519 | return ret; |
| 520 | } |
| 521 | return 0; |
| 522 | } |
| 523 | |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 524 | static int qbuf_if_pending_buffer_exists_locked(struct encoder_context *ctx, |
| 525 | int fd) |
| 526 | { |
| 527 | if (!queue_empty(&ctx->pending_buffers)) { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 528 | int ret; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 529 | struct pending_buffer *element = queue_front(&ctx->pending_buffers); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 530 | VLOG_FD(1, "QBUF a buffer (%d) from the pending queue.", |
| 531 | element->buffer.index); |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 532 | if (rk_vepu_update_parameter(ctx->enc, &element->next_runtime_param)) { |
| 533 | VLOG_FD(0, "rk_vepu_update_parameter failed."); |
| 534 | return -EIO; |
| 535 | } |
Tomasz Figa | aed2ed9 | 2015-02-25 14:05:53 +0900 | [diff] [blame] | 536 | memset(&element->next_runtime_param, 0, |
| 537 | sizeof(element->next_runtime_param)); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 538 | ret = ioctl_qbuf_locked(ctx, fd, &element->buffer); |
| 539 | if (ret) |
| 540 | return ret; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 541 | queue_pop_front(&ctx->pending_buffers); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 542 | } |
| 543 | return 0; |
| 544 | } |
| 545 | |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 546 | static int initialize_libvpu(struct encoder_context *ctx, int fd) |
| 547 | { |
| 548 | struct rk_vepu_init_param init_param; |
| 549 | memset(&init_param, 0, sizeof(init_param)); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 550 | |
Alpha Lin | fa5caae | 2014-11-17 09:48:35 +0800 | [diff] [blame] | 551 | /* Get the input format. */ |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 552 | struct v4l2_format format; |
| 553 | memset(&format, 0, sizeof(format)); |
| 554 | format.type = ctx->output_streamon_type; |
| 555 | int ret = SYS_IOCTL(fd, VIDIOC_G_FMT, &format); |
Alpha Lin | fa5caae | 2014-11-17 09:48:35 +0800 | [diff] [blame] | 556 | if (ret) |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 557 | return ret; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 558 | init_param.input_format = format.fmt.pix_mp.pixelformat; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 559 | |
Alpha Lin | fa5caae | 2014-11-17 09:48:35 +0800 | [diff] [blame] | 560 | /* Get the output format. */ |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 561 | memset(&format, 0, sizeof(format)); |
| 562 | format.type = ctx->capture_streamon_type; |
| 563 | ret = SYS_IOCTL(fd, VIDIOC_G_FMT, &format); |
Alpha Lin | fa5caae | 2014-11-17 09:48:35 +0800 | [diff] [blame] | 564 | if (ret) |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 565 | return ret; |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 566 | init_param.output_format = format.fmt.pix_mp.pixelformat; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 567 | |
Alpha Lin | fa5caae | 2014-11-17 09:48:35 +0800 | [diff] [blame] | 568 | /* Get the cropped size. */ |
| 569 | struct v4l2_crop crop; |
| 570 | memset(&crop, 0, sizeof(crop)); |
| 571 | crop.type = ctx->output_streamon_type; |
| 572 | ret = SYS_IOCTL(fd, VIDIOC_G_CROP, &crop); |
| 573 | if (ret) |
| 574 | return ret; |
| 575 | init_param.width = crop.c.width; |
| 576 | init_param.height = crop.c.height; |
| 577 | |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 578 | /* |
| 579 | * If the encoder library has initialized and parameters have not |
| 580 | * changed, skip the initialization. |
| 581 | */ |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 582 | if (ctx->enc && memcmp(&init_param, &ctx->init_param, sizeof(init_param))) { |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 583 | rk_vepu_deinit(ctx->enc); |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 584 | ctx->enc = NULL; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 585 | } |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 586 | if (!ctx->enc) { |
| 587 | memcpy(&ctx->init_param, &init_param, sizeof(init_param)); |
| 588 | ctx->enc = rk_vepu_init(&init_param); |
| 589 | if (ctx->enc == NULL) { |
| 590 | VLOG_FD(0, "Failed to initialize encoder library."); |
| 591 | return -EIO; |
| 592 | } |
| 593 | } |
| 594 | if (rk_vepu_update_parameter(ctx->enc, &ctx->runtime_param)) { |
| 595 | VLOG_FD(0, "rk_vepu_update_parameter failed."); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 596 | return -EIO; |
| 597 | } |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 598 | memset(&ctx->runtime_param, 0, sizeof(struct rk_vepu_runtime_param)); |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 599 | return 0; |
| 600 | } |
| 601 | |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 602 | static void queue_init(struct pending_buffer_queue *queue) |
| 603 | { |
| 604 | memset(queue, 0, sizeof(struct pending_buffer_queue)); |
| 605 | } |
| 606 | |
| 607 | static bool queue_empty(struct pending_buffer_queue *queue) |
| 608 | { |
| 609 | return queue->count == 0; |
| 610 | } |
| 611 | |
| 612 | static bool queue_full(struct pending_buffer_queue *queue) |
| 613 | { |
| 614 | return queue->count == PENDING_BUFFER_QUEUE_SIZE; |
| 615 | } |
| 616 | |
| 617 | static int queue_push_back(struct pending_buffer_queue *queue, |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 618 | struct v4l2_buffer *buffer) |
| 619 | { |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 620 | if (queue_full(queue)) |
| 621 | return -ENOMEM; |
| 622 | int rear = (queue->front + queue->count) % PENDING_BUFFER_QUEUE_SIZE; |
| 623 | queue->count++; |
| 624 | struct pending_buffer *entry = &queue->buf_array[rear]; |
| 625 | memset(entry, 0, sizeof(struct pending_buffer)); |
| 626 | |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 627 | memcpy(&entry->buffer, buffer, sizeof(*buffer)); |
| 628 | if (V4L2_TYPE_IS_MULTIPLANAR(buffer->type)) { |
| 629 | memset(entry->planes, 0, |
| 630 | sizeof(struct v4l2_plane) * VIDEO_MAX_PLANES); |
| 631 | memcpy(entry->planes, buffer->m.planes, |
| 632 | sizeof(struct v4l2_plane) * buffer->length); |
| 633 | entry->buffer.m.planes = entry->planes; |
| 634 | } |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 638 | static void queue_pop_front(struct pending_buffer_queue *queue) |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 639 | { |
henryhsu | c7c06f9 | 2014-11-24 15:57:08 +0800 | [diff] [blame] | 640 | assert(!queue_empty(queue)); |
| 641 | queue->count--; |
| 642 | queue->front = (queue->front + 1) % PENDING_BUFFER_QUEUE_SIZE; |
| 643 | } |
| 644 | |
| 645 | static struct pending_buffer *queue_front(struct pending_buffer_queue *queue) |
| 646 | { |
| 647 | if (queue_empty(queue)) |
| 648 | return NULL; |
| 649 | return &queue->buf_array[queue->front]; |
| 650 | } |
| 651 | |
| 652 | static struct pending_buffer *queue_back(struct pending_buffer_queue *queue) |
| 653 | { |
| 654 | if (queue_empty(queue)) |
| 655 | return NULL; |
| 656 | return &queue->buf_array[(queue->front + queue->count - 1) % |
| 657 | PENDING_BUFFER_QUEUE_SIZE]; |
Wu-Cheng Li | ce8947e | 2014-11-13 17:34:16 +0800 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | static void get_log_level() |
| 661 | { |
| 662 | char *log_level_str = getenv("LIBV4L_PLUGIN_LOG_LEVEL"); |
| 663 | if (log_level_str != NULL) |
| 664 | g_log_level = strtol(log_level_str, NULL, 10); |
| 665 | } |
| 666 | |
| 667 | static const char* v4l_cmd2str(unsigned long int cmd) |
| 668 | { |
| 669 | switch (cmd) { |
| 670 | case VIDIOC_QUERYCAP: |
| 671 | return "VIDIOC_QUERYCAP"; |
| 672 | case VIDIOC_TRY_FMT: |
| 673 | return "VIDIOC_TRY_FMT"; |
| 674 | case VIDIOC_S_FMT: |
| 675 | return "VIDIOC_S_FMT"; |
| 676 | case VIDIOC_G_FMT: |
| 677 | return "VIDIOC_G_FMT"; |
| 678 | case VIDIOC_ENUM_FMT: |
| 679 | return "VIDIOC_ENUM_FMT"; |
| 680 | case VIDIOC_S_PARM: |
| 681 | return "VIDIOC_S_PARM"; |
| 682 | case VIDIOC_G_PARM: |
| 683 | return "VIDIOC_G_PARM"; |
| 684 | case VIDIOC_QBUF: |
| 685 | return "VIDIOC_QBUF"; |
| 686 | case VIDIOC_DQBUF: |
| 687 | return "VIDIOC_DQBUF"; |
| 688 | case VIDIOC_PREPARE_BUF: |
| 689 | return "VIDIOC_PREPARE_BUF"; |
| 690 | case VIDIOC_CREATE_BUFS: |
| 691 | return "VIDIOC_CREATE_BUFS"; |
| 692 | case VIDIOC_REQBUFS: |
| 693 | return "VIDIOC_REQBUFS"; |
| 694 | case VIDIOC_STREAMON: |
| 695 | return "VIDIOC_STREAMON"; |
| 696 | case VIDIOC_STREAMOFF: |
| 697 | return "VIDIOC_STREAMOFF"; |
| 698 | case VIDIOC_S_CROP: |
| 699 | return "VIDIOC_S_CROP"; |
| 700 | case VIDIOC_S_CTRL: |
| 701 | return "VIDIOC_S_CTRL"; |
| 702 | case VIDIOC_G_EXT_CTRLS: |
| 703 | return "VIDIOC_G_EXT_CTRLS"; |
| 704 | case VIDIOC_S_EXT_CTRLS: |
| 705 | return "VIDIOC_S_EXT_CTRLS"; |
| 706 | case VIDIOC_QUERYBUF: |
| 707 | return "VIDIOC_QUERYBUF"; |
| 708 | default: |
| 709 | return "UNKNOWN"; |
| 710 | } |
henryhsu | 58be50c | 2014-10-30 11:49:19 +0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | PLUGIN_PUBLIC const struct libv4l_dev_ops libv4l2_plugin = { |
| 714 | .init = &plugin_init, |
| 715 | .close = &plugin_close, |
| 716 | .ioctl = &plugin_ioctl, |
| 717 | }; |