Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: vicodec: split off v4l2 specific parts for the codec

Split off the decode and encode functions into a separate
source that can be reused elsewhere.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Hans Verkuil and committed by
Mauro Carvalho Chehab
cd12b401 21abebf0

+458 -382
+1 -1
drivers/media/platform/vicodec/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 - vicodec-objs := vicodec-core.o codec-fwht.o 2 + vicodec-objs := vicodec-core.o codec-fwht.o codec-v4l2-fwht.o 3 3 4 4 obj-$(CONFIG_VIDEO_VICODEC) += vicodec.o
+325
drivers/media/platform/vicodec/codec-v4l2-fwht.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* 3 + * A V4L2 frontend for the FWHT codec 4 + * 5 + * Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved. 6 + */ 7 + 8 + #include <linux/errno.h> 9 + #include <linux/string.h> 10 + #include <linux/videodev2.h> 11 + #include "codec-v4l2-fwht.h" 12 + 13 + static const struct v4l2_fwht_pixfmt_info v4l2_fwht_pixfmts[] = { 14 + { V4L2_PIX_FMT_YUV420, 1, 3, 2, 1, 1, 2, 2 }, 15 + { V4L2_PIX_FMT_YVU420, 1, 3, 2, 1, 1, 2, 2 }, 16 + { V4L2_PIX_FMT_YUV422P, 1, 2, 1, 1, 1, 2, 1 }, 17 + { V4L2_PIX_FMT_NV12, 1, 3, 2, 1, 2, 2, 2 }, 18 + { V4L2_PIX_FMT_NV21, 1, 3, 2, 1, 2, 2, 2 }, 19 + { V4L2_PIX_FMT_NV16, 1, 2, 1, 1, 2, 2, 1 }, 20 + { V4L2_PIX_FMT_NV61, 1, 2, 1, 1, 2, 2, 1 }, 21 + { V4L2_PIX_FMT_NV24, 1, 3, 1, 1, 2, 1, 1 }, 22 + { V4L2_PIX_FMT_NV42, 1, 3, 1, 1, 2, 1, 1 }, 23 + { V4L2_PIX_FMT_YUYV, 2, 2, 1, 2, 4, 2, 1 }, 24 + { V4L2_PIX_FMT_YVYU, 2, 2, 1, 2, 4, 2, 1 }, 25 + { V4L2_PIX_FMT_UYVY, 2, 2, 1, 2, 4, 2, 1 }, 26 + { V4L2_PIX_FMT_VYUY, 2, 2, 1, 2, 4, 2, 1 }, 27 + { V4L2_PIX_FMT_BGR24, 3, 3, 1, 3, 3, 1, 1 }, 28 + { V4L2_PIX_FMT_RGB24, 3, 3, 1, 3, 3, 1, 1 }, 29 + { V4L2_PIX_FMT_HSV24, 3, 3, 1, 3, 3, 1, 1 }, 30 + { V4L2_PIX_FMT_BGR32, 4, 4, 1, 4, 4, 1, 1 }, 31 + { V4L2_PIX_FMT_XBGR32, 4, 4, 1, 4, 4, 1, 1 }, 32 + { V4L2_PIX_FMT_RGB32, 4, 4, 1, 4, 4, 1, 1 }, 33 + { V4L2_PIX_FMT_XRGB32, 4, 4, 1, 4, 4, 1, 1 }, 34 + { V4L2_PIX_FMT_HSV32, 4, 4, 1, 4, 4, 1, 1 }, 35 + }; 36 + 37 + const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat) 38 + { 39 + unsigned int i; 40 + 41 + for (i = 0; i < ARRAY_SIZE(v4l2_fwht_pixfmts); i++) 42 + if (v4l2_fwht_pixfmts[i].id == pixelformat) 43 + return v4l2_fwht_pixfmts + i; 44 + return NULL; 45 + } 46 + 47 + const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx) 48 + { 49 + if (idx >= ARRAY_SIZE(v4l2_fwht_pixfmts)) 50 + return NULL; 51 + return v4l2_fwht_pixfmts + idx; 52 + } 53 + 54 + unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state, 55 + u8 *p_in, u8 *p_out) 56 + { 57 + unsigned int size = state->width * state->height; 58 + const struct v4l2_fwht_pixfmt_info *info = state->info; 59 + struct fwht_cframe_hdr *p_hdr; 60 + struct fwht_cframe cf; 61 + struct fwht_raw_frame rf; 62 + u32 encoding; 63 + u32 flags = 0; 64 + 65 + rf.width = state->width; 66 + rf.height = state->height; 67 + rf.luma = p_in; 68 + rf.width_div = info->width_div; 69 + rf.height_div = info->height_div; 70 + rf.luma_step = info->luma_step; 71 + rf.chroma_step = info->chroma_step; 72 + 73 + switch (info->id) { 74 + case V4L2_PIX_FMT_YUV420: 75 + rf.cb = rf.luma + size; 76 + rf.cr = rf.cb + size / 4; 77 + break; 78 + case V4L2_PIX_FMT_YVU420: 79 + rf.cr = rf.luma + size; 80 + rf.cb = rf.cr + size / 4; 81 + break; 82 + case V4L2_PIX_FMT_YUV422P: 83 + rf.cb = rf.luma + size; 84 + rf.cr = rf.cb + size / 2; 85 + break; 86 + case V4L2_PIX_FMT_NV12: 87 + case V4L2_PIX_FMT_NV16: 88 + case V4L2_PIX_FMT_NV24: 89 + rf.cb = rf.luma + size; 90 + rf.cr = rf.cb + 1; 91 + break; 92 + case V4L2_PIX_FMT_NV21: 93 + case V4L2_PIX_FMT_NV61: 94 + case V4L2_PIX_FMT_NV42: 95 + rf.cr = rf.luma + size; 96 + rf.cb = rf.cr + 1; 97 + break; 98 + case V4L2_PIX_FMT_YUYV: 99 + rf.cb = rf.luma + 1; 100 + rf.cr = rf.cb + 2; 101 + break; 102 + case V4L2_PIX_FMT_YVYU: 103 + rf.cr = rf.luma + 1; 104 + rf.cb = rf.cr + 2; 105 + break; 106 + case V4L2_PIX_FMT_UYVY: 107 + rf.cb = rf.luma; 108 + rf.cr = rf.cb + 2; 109 + rf.luma++; 110 + break; 111 + case V4L2_PIX_FMT_VYUY: 112 + rf.cr = rf.luma; 113 + rf.cb = rf.cr + 2; 114 + rf.luma++; 115 + break; 116 + case V4L2_PIX_FMT_RGB24: 117 + case V4L2_PIX_FMT_HSV24: 118 + rf.cr = rf.luma; 119 + rf.cb = rf.cr + 2; 120 + rf.luma++; 121 + break; 122 + case V4L2_PIX_FMT_BGR24: 123 + rf.cb = rf.luma; 124 + rf.cr = rf.cb + 2; 125 + rf.luma++; 126 + break; 127 + case V4L2_PIX_FMT_RGB32: 128 + case V4L2_PIX_FMT_XRGB32: 129 + case V4L2_PIX_FMT_HSV32: 130 + rf.cr = rf.luma + 1; 131 + rf.cb = rf.cr + 2; 132 + rf.luma += 2; 133 + break; 134 + case V4L2_PIX_FMT_BGR32: 135 + case V4L2_PIX_FMT_XBGR32: 136 + rf.cb = rf.luma; 137 + rf.cr = rf.cb + 2; 138 + rf.luma++; 139 + break; 140 + } 141 + 142 + cf.width = state->width; 143 + cf.height = state->height; 144 + cf.i_frame_qp = state->i_frame_qp; 145 + cf.p_frame_qp = state->p_frame_qp; 146 + cf.rlc_data = (__be16 *)(p_out + sizeof(*p_hdr)); 147 + 148 + encoding = fwht_encode_frame(&rf, &state->ref_frame, &cf, 149 + !state->gop_cnt, 150 + state->gop_cnt == state->gop_size - 1); 151 + if (!(encoding & FWHT_FRAME_PCODED)) 152 + state->gop_cnt = 0; 153 + if (++state->gop_cnt >= state->gop_size) 154 + state->gop_cnt = 0; 155 + 156 + p_hdr = (struct fwht_cframe_hdr *)p_out; 157 + p_hdr->magic1 = FWHT_MAGIC1; 158 + p_hdr->magic2 = FWHT_MAGIC2; 159 + p_hdr->version = htonl(FWHT_VERSION); 160 + p_hdr->width = htonl(cf.width); 161 + p_hdr->height = htonl(cf.height); 162 + if (encoding & FWHT_LUMA_UNENCODED) 163 + flags |= FWHT_FL_LUMA_IS_UNCOMPRESSED; 164 + if (encoding & FWHT_CB_UNENCODED) 165 + flags |= FWHT_FL_CB_IS_UNCOMPRESSED; 166 + if (encoding & FWHT_CR_UNENCODED) 167 + flags |= FWHT_FL_CR_IS_UNCOMPRESSED; 168 + if (rf.height_div == 1) 169 + flags |= FWHT_FL_CHROMA_FULL_HEIGHT; 170 + if (rf.width_div == 1) 171 + flags |= FWHT_FL_CHROMA_FULL_WIDTH; 172 + p_hdr->flags = htonl(flags); 173 + p_hdr->colorspace = htonl(state->colorspace); 174 + p_hdr->xfer_func = htonl(state->xfer_func); 175 + p_hdr->ycbcr_enc = htonl(state->ycbcr_enc); 176 + p_hdr->quantization = htonl(state->quantization); 177 + p_hdr->size = htonl(cf.size); 178 + state->ref_frame.width = cf.width; 179 + state->ref_frame.height = cf.height; 180 + return cf.size + sizeof(*p_hdr); 181 + } 182 + 183 + int v4l2_fwht_decode(struct v4l2_fwht_state *state, 184 + u8 *p_in, u8 *p_out) 185 + { 186 + unsigned int size = state->width * state->height; 187 + unsigned int chroma_size = size; 188 + unsigned int i; 189 + u32 flags; 190 + struct fwht_cframe_hdr *p_hdr; 191 + struct fwht_cframe cf; 192 + u8 *p; 193 + 194 + p_hdr = (struct fwht_cframe_hdr *)p_in; 195 + cf.width = ntohl(p_hdr->width); 196 + cf.height = ntohl(p_hdr->height); 197 + flags = ntohl(p_hdr->flags); 198 + state->colorspace = ntohl(p_hdr->colorspace); 199 + state->xfer_func = ntohl(p_hdr->xfer_func); 200 + state->ycbcr_enc = ntohl(p_hdr->ycbcr_enc); 201 + state->quantization = ntohl(p_hdr->quantization); 202 + cf.rlc_data = (__be16 *)(p_in + sizeof(*p_hdr)); 203 + 204 + if (p_hdr->magic1 != FWHT_MAGIC1 || 205 + p_hdr->magic2 != FWHT_MAGIC2 || 206 + ntohl(p_hdr->version) != FWHT_VERSION || 207 + (cf.width & 7) || (cf.height & 7)) 208 + return -EINVAL; 209 + 210 + /* TODO: support resolution changes */ 211 + if (cf.width != state->width || cf.height != state->height) 212 + return -EINVAL; 213 + 214 + if (!(flags & FWHT_FL_CHROMA_FULL_WIDTH)) 215 + chroma_size /= 2; 216 + if (!(flags & FWHT_FL_CHROMA_FULL_HEIGHT)) 217 + chroma_size /= 2; 218 + 219 + fwht_decode_frame(&cf, &state->ref_frame, flags); 220 + 221 + switch (state->info->id) { 222 + case V4L2_PIX_FMT_YUV420: 223 + case V4L2_PIX_FMT_YUV422P: 224 + memcpy(p_out, state->ref_frame.luma, size); 225 + p_out += size; 226 + memcpy(p_out, state->ref_frame.cb, chroma_size); 227 + p_out += chroma_size; 228 + memcpy(p_out, state->ref_frame.cr, chroma_size); 229 + break; 230 + case V4L2_PIX_FMT_YVU420: 231 + memcpy(p_out, state->ref_frame.luma, size); 232 + p_out += size; 233 + memcpy(p_out, state->ref_frame.cr, chroma_size); 234 + p_out += chroma_size; 235 + memcpy(p_out, state->ref_frame.cb, chroma_size); 236 + break; 237 + case V4L2_PIX_FMT_NV12: 238 + case V4L2_PIX_FMT_NV16: 239 + case V4L2_PIX_FMT_NV24: 240 + memcpy(p_out, state->ref_frame.luma, size); 241 + p_out += size; 242 + for (i = 0, p = p_out; i < chroma_size; i++) { 243 + *p++ = state->ref_frame.cb[i]; 244 + *p++ = state->ref_frame.cr[i]; 245 + } 246 + break; 247 + case V4L2_PIX_FMT_NV21: 248 + case V4L2_PIX_FMT_NV61: 249 + case V4L2_PIX_FMT_NV42: 250 + memcpy(p_out, state->ref_frame.luma, size); 251 + p_out += size; 252 + for (i = 0, p = p_out; i < chroma_size; i++) { 253 + *p++ = state->ref_frame.cr[i]; 254 + *p++ = state->ref_frame.cb[i]; 255 + } 256 + break; 257 + case V4L2_PIX_FMT_YUYV: 258 + for (i = 0, p = p_out; i < size; i += 2) { 259 + *p++ = state->ref_frame.luma[i]; 260 + *p++ = state->ref_frame.cb[i / 2]; 261 + *p++ = state->ref_frame.luma[i + 1]; 262 + *p++ = state->ref_frame.cr[i / 2]; 263 + } 264 + break; 265 + case V4L2_PIX_FMT_YVYU: 266 + for (i = 0, p = p_out; i < size; i += 2) { 267 + *p++ = state->ref_frame.luma[i]; 268 + *p++ = state->ref_frame.cr[i / 2]; 269 + *p++ = state->ref_frame.luma[i + 1]; 270 + *p++ = state->ref_frame.cb[i / 2]; 271 + } 272 + break; 273 + case V4L2_PIX_FMT_UYVY: 274 + for (i = 0, p = p_out; i < size; i += 2) { 275 + *p++ = state->ref_frame.cb[i / 2]; 276 + *p++ = state->ref_frame.luma[i]; 277 + *p++ = state->ref_frame.cr[i / 2]; 278 + *p++ = state->ref_frame.luma[i + 1]; 279 + } 280 + break; 281 + case V4L2_PIX_FMT_VYUY: 282 + for (i = 0, p = p_out; i < size; i += 2) { 283 + *p++ = state->ref_frame.cr[i / 2]; 284 + *p++ = state->ref_frame.luma[i]; 285 + *p++ = state->ref_frame.cb[i / 2]; 286 + *p++ = state->ref_frame.luma[i + 1]; 287 + } 288 + break; 289 + case V4L2_PIX_FMT_RGB24: 290 + case V4L2_PIX_FMT_HSV24: 291 + for (i = 0, p = p_out; i < size; i++) { 292 + *p++ = state->ref_frame.cr[i]; 293 + *p++ = state->ref_frame.luma[i]; 294 + *p++ = state->ref_frame.cb[i]; 295 + } 296 + break; 297 + case V4L2_PIX_FMT_BGR24: 298 + for (i = 0, p = p_out; i < size; i++) { 299 + *p++ = state->ref_frame.cb[i]; 300 + *p++ = state->ref_frame.luma[i]; 301 + *p++ = state->ref_frame.cr[i]; 302 + } 303 + break; 304 + case V4L2_PIX_FMT_RGB32: 305 + case V4L2_PIX_FMT_XRGB32: 306 + case V4L2_PIX_FMT_HSV32: 307 + for (i = 0, p = p_out; i < size; i++) { 308 + *p++ = 0; 309 + *p++ = state->ref_frame.cr[i]; 310 + *p++ = state->ref_frame.luma[i]; 311 + *p++ = state->ref_frame.cb[i]; 312 + } 313 + break; 314 + case V4L2_PIX_FMT_BGR32: 315 + case V4L2_PIX_FMT_XBGR32: 316 + for (i = 0, p = p_out; i < size; i++) { 317 + *p++ = state->ref_frame.cb[i]; 318 + *p++ = state->ref_frame.luma[i]; 319 + *p++ = state->ref_frame.cr[i]; 320 + *p++ = 0; 321 + } 322 + break; 323 + } 324 + return 0; 325 + }
+50
drivers/media/platform/vicodec/codec-v4l2-fwht.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Copyright 2018 Cisco Systems, Inc. and/or its affiliates. All rights reserved. 4 + */ 5 + 6 + #ifndef CODEC_V4L2_FWHT_H 7 + #define CODEC_V4L2_FWHT_H 8 + 9 + #include "codec-fwht.h" 10 + 11 + struct v4l2_fwht_pixfmt_info { 12 + u32 id; 13 + unsigned int bytesperline_mult; 14 + unsigned int sizeimage_mult; 15 + unsigned int sizeimage_div; 16 + unsigned int luma_step; 17 + unsigned int chroma_step; 18 + /* Chroma plane subsampling */ 19 + unsigned int width_div; 20 + unsigned int height_div; 21 + }; 22 + 23 + struct v4l2_fwht_state { 24 + const struct v4l2_fwht_pixfmt_info *info; 25 + unsigned int width; 26 + unsigned int height; 27 + unsigned int gop_size; 28 + unsigned int gop_cnt; 29 + u16 i_frame_qp; 30 + u16 p_frame_qp; 31 + 32 + enum v4l2_colorspace colorspace; 33 + enum v4l2_ycbcr_encoding ycbcr_enc; 34 + enum v4l2_xfer_func xfer_func; 35 + enum v4l2_quantization quantization; 36 + 37 + struct fwht_raw_frame ref_frame; 38 + u8 *compressed_frame; 39 + }; 40 + 41 + const struct v4l2_fwht_pixfmt_info *v4l2_fwht_find_pixfmt(u32 pixelformat); 42 + const struct v4l2_fwht_pixfmt_info *v4l2_fwht_get_pixfmt(u32 idx); 43 + 44 + unsigned int v4l2_fwht_encode(struct v4l2_fwht_state *state, 45 + u8 *p_in, u8 *p_out); 46 + 47 + int v4l2_fwht_decode(struct v4l2_fwht_state *state, 48 + u8 *p_in, u8 *p_out); 49 + 50 + #endif
+82 -381
drivers/media/platform/vicodec/vicodec-core.c
··· 23 23 #include <media/v4l2-event.h> 24 24 #include <media/videobuf2-vmalloc.h> 25 25 26 - #include "codec-fwht.h" 26 + #include "codec-v4l2-fwht.h" 27 27 28 28 MODULE_DESCRIPTION("Virtual codec device"); 29 29 MODULE_AUTHOR("Hans Verkuil <hans.verkuil@cisco.com>"); ··· 60 60 unsigned int height_div; 61 61 }; 62 62 63 - static const struct pixfmt_info pixfmts[] = { 64 - { V4L2_PIX_FMT_YUV420, 1, 3, 2, 1, 1, 2, 2 }, 65 - { V4L2_PIX_FMT_YVU420, 1, 3, 2, 1, 1, 2, 2 }, 66 - { V4L2_PIX_FMT_YUV422P, 1, 2, 1, 1, 1, 2, 1 }, 67 - { V4L2_PIX_FMT_NV12, 1, 3, 2, 1, 2, 2, 2 }, 68 - { V4L2_PIX_FMT_NV21, 1, 3, 2, 1, 2, 2, 2 }, 69 - { V4L2_PIX_FMT_NV16, 1, 2, 1, 1, 2, 2, 1 }, 70 - { V4L2_PIX_FMT_NV61, 1, 2, 1, 1, 2, 2, 1 }, 71 - { V4L2_PIX_FMT_NV24, 1, 3, 1, 1, 2, 1, 1 }, 72 - { V4L2_PIX_FMT_NV42, 1, 3, 1, 1, 2, 1, 1 }, 73 - { V4L2_PIX_FMT_YUYV, 2, 2, 1, 2, 4, 2, 1 }, 74 - { V4L2_PIX_FMT_YVYU, 2, 2, 1, 2, 4, 2, 1 }, 75 - { V4L2_PIX_FMT_UYVY, 2, 2, 1, 2, 4, 2, 1 }, 76 - { V4L2_PIX_FMT_VYUY, 2, 2, 1, 2, 4, 2, 1 }, 77 - { V4L2_PIX_FMT_BGR24, 3, 3, 1, 3, 3, 1, 1 }, 78 - { V4L2_PIX_FMT_RGB24, 3, 3, 1, 3, 3, 1, 1 }, 79 - { V4L2_PIX_FMT_HSV24, 3, 3, 1, 3, 3, 1, 1 }, 80 - { V4L2_PIX_FMT_BGR32, 4, 4, 1, 4, 4, 1, 1 }, 81 - { V4L2_PIX_FMT_XBGR32, 4, 4, 1, 4, 4, 1, 1 }, 82 - { V4L2_PIX_FMT_RGB32, 4, 4, 1, 4, 4, 1, 1 }, 83 - { V4L2_PIX_FMT_XRGB32, 4, 4, 1, 4, 4, 1, 1 }, 84 - { V4L2_PIX_FMT_HSV32, 4, 4, 1, 4, 4, 1, 1 }, 85 - }; 86 - 87 - static const struct pixfmt_info pixfmt_fwht = { 63 + static const struct v4l2_fwht_pixfmt_info pixfmt_fwht = { 88 64 V4L2_PIX_FMT_FWHT, 0, 3, 1, 1, 1, 1, 1 89 65 }; 90 66 ··· 79 103 unsigned int height; 80 104 unsigned int sizeimage; 81 105 unsigned int sequence; 82 - const struct pixfmt_info *info; 106 + const struct v4l2_fwht_pixfmt_info *info; 83 107 }; 84 108 85 109 enum { ··· 111 135 spinlock_t *lock; 112 136 113 137 struct v4l2_ctrl_handler hdl; 114 - unsigned int gop_size; 115 - unsigned int gop_cnt; 116 - u16 i_frame_qp; 117 - u16 p_frame_qp; 118 138 119 139 /* Abort requested by m2m */ 120 140 int aborting; 121 141 struct vb2_v4l2_buffer *last_src_buf; 122 142 struct vb2_v4l2_buffer *last_dst_buf; 123 143 124 - enum v4l2_colorspace colorspace; 125 - enum v4l2_ycbcr_encoding ycbcr_enc; 126 - enum v4l2_xfer_func xfer_func; 127 - enum v4l2_quantization quantization; 128 - 129 144 /* Source and destination queue data */ 130 145 struct vicodec_q_data q_data[2]; 131 - struct fwht_raw_frame ref_frame; 132 - u8 *compressed_frame; 146 + struct v4l2_fwht_state state; 147 + 133 148 u32 cur_buf_offset; 134 149 u32 comp_max_size; 135 150 u32 comp_size; ··· 152 185 return NULL; 153 186 } 154 187 155 - static void encode(struct vicodec_ctx *ctx, 156 - struct vicodec_q_data *q_data, 157 - u8 *p_in, u8 *p_out, u32 flags) 158 - { 159 - unsigned int size = q_data->width * q_data->height; 160 - const struct pixfmt_info *info = q_data->info; 161 - struct fwht_cframe_hdr *p_hdr; 162 - struct fwht_cframe cf; 163 - struct fwht_raw_frame rf; 164 - u32 encoding; 165 - 166 - rf.width = q_data->width; 167 - rf.height = q_data->height; 168 - rf.luma = p_in; 169 - rf.width_div = info->width_div; 170 - rf.height_div = info->height_div; 171 - rf.luma_step = info->luma_step; 172 - rf.chroma_step = info->chroma_step; 173 - 174 - switch (info->id) { 175 - case V4L2_PIX_FMT_YUV420: 176 - rf.cb = rf.luma + size; 177 - rf.cr = rf.cb + size / 4; 178 - break; 179 - case V4L2_PIX_FMT_YVU420: 180 - rf.cr = rf.luma + size; 181 - rf.cb = rf.cr + size / 4; 182 - break; 183 - case V4L2_PIX_FMT_YUV422P: 184 - rf.cb = rf.luma + size; 185 - rf.cr = rf.cb + size / 2; 186 - break; 187 - case V4L2_PIX_FMT_NV12: 188 - case V4L2_PIX_FMT_NV16: 189 - case V4L2_PIX_FMT_NV24: 190 - rf.cb = rf.luma + size; 191 - rf.cr = rf.cb + 1; 192 - break; 193 - case V4L2_PIX_FMT_NV21: 194 - case V4L2_PIX_FMT_NV61: 195 - case V4L2_PIX_FMT_NV42: 196 - rf.cr = rf.luma + size; 197 - rf.cb = rf.cr + 1; 198 - break; 199 - case V4L2_PIX_FMT_YUYV: 200 - rf.cb = rf.luma + 1; 201 - rf.cr = rf.cb + 2; 202 - break; 203 - case V4L2_PIX_FMT_YVYU: 204 - rf.cr = rf.luma + 1; 205 - rf.cb = rf.cr + 2; 206 - break; 207 - case V4L2_PIX_FMT_UYVY: 208 - rf.cb = rf.luma; 209 - rf.cr = rf.cb + 2; 210 - rf.luma++; 211 - break; 212 - case V4L2_PIX_FMT_VYUY: 213 - rf.cr = rf.luma; 214 - rf.cb = rf.cr + 2; 215 - rf.luma++; 216 - break; 217 - case V4L2_PIX_FMT_RGB24: 218 - case V4L2_PIX_FMT_HSV24: 219 - rf.cr = rf.luma; 220 - rf.cb = rf.cr + 2; 221 - rf.luma++; 222 - break; 223 - case V4L2_PIX_FMT_BGR24: 224 - rf.cb = rf.luma; 225 - rf.cr = rf.cb + 2; 226 - rf.luma++; 227 - break; 228 - case V4L2_PIX_FMT_RGB32: 229 - case V4L2_PIX_FMT_XRGB32: 230 - case V4L2_PIX_FMT_HSV32: 231 - rf.cr = rf.luma + 1; 232 - rf.cb = rf.cr + 2; 233 - rf.luma += 2; 234 - break; 235 - case V4L2_PIX_FMT_BGR32: 236 - case V4L2_PIX_FMT_XBGR32: 237 - rf.cb = rf.luma; 238 - rf.cr = rf.cb + 2; 239 - rf.luma++; 240 - break; 241 - } 242 - 243 - cf.width = q_data->width; 244 - cf.height = q_data->height; 245 - cf.i_frame_qp = ctx->i_frame_qp; 246 - cf.p_frame_qp = ctx->p_frame_qp; 247 - cf.rlc_data = (__be16 *)(p_out + sizeof(*p_hdr)); 248 - 249 - encoding = fwht_encode_frame(&rf, &ctx->ref_frame, &cf, !ctx->gop_cnt, 250 - ctx->gop_cnt == ctx->gop_size - 1); 251 - if (!(encoding & FWHT_FRAME_PCODED)) 252 - ctx->gop_cnt = 0; 253 - if (++ctx->gop_cnt >= ctx->gop_size) 254 - ctx->gop_cnt = 0; 255 - 256 - p_hdr = (struct fwht_cframe_hdr *)p_out; 257 - p_hdr->magic1 = FWHT_MAGIC1; 258 - p_hdr->magic2 = FWHT_MAGIC2; 259 - p_hdr->version = htonl(FWHT_VERSION); 260 - p_hdr->width = htonl(cf.width); 261 - p_hdr->height = htonl(cf.height); 262 - if (encoding & FWHT_LUMA_UNENCODED) 263 - flags |= FWHT_FL_LUMA_IS_UNCOMPRESSED; 264 - if (encoding & FWHT_CB_UNENCODED) 265 - flags |= FWHT_FL_CB_IS_UNCOMPRESSED; 266 - if (encoding & FWHT_CR_UNENCODED) 267 - flags |= FWHT_FL_CR_IS_UNCOMPRESSED; 268 - if (rf.height_div == 1) 269 - flags |= FWHT_FL_CHROMA_FULL_HEIGHT; 270 - if (rf.width_div == 1) 271 - flags |= FWHT_FL_CHROMA_FULL_WIDTH; 272 - p_hdr->flags = htonl(flags); 273 - p_hdr->colorspace = htonl(ctx->colorspace); 274 - p_hdr->xfer_func = htonl(ctx->xfer_func); 275 - p_hdr->ycbcr_enc = htonl(ctx->ycbcr_enc); 276 - p_hdr->quantization = htonl(ctx->quantization); 277 - p_hdr->size = htonl(cf.size); 278 - ctx->ref_frame.width = cf.width; 279 - ctx->ref_frame.height = cf.height; 280 - } 281 - 282 - static int decode(struct vicodec_ctx *ctx, 283 - struct vicodec_q_data *q_data, 284 - u8 *p_in, u8 *p_out) 285 - { 286 - unsigned int size = q_data->width * q_data->height; 287 - unsigned int chroma_size = size; 288 - unsigned int i; 289 - u32 flags; 290 - struct fwht_cframe_hdr *p_hdr; 291 - struct fwht_cframe cf; 292 - u8 *p; 293 - 294 - p_hdr = (struct fwht_cframe_hdr *)p_in; 295 - cf.width = ntohl(p_hdr->width); 296 - cf.height = ntohl(p_hdr->height); 297 - flags = ntohl(p_hdr->flags); 298 - ctx->colorspace = ntohl(p_hdr->colorspace); 299 - ctx->xfer_func = ntohl(p_hdr->xfer_func); 300 - ctx->ycbcr_enc = ntohl(p_hdr->ycbcr_enc); 301 - ctx->quantization = ntohl(p_hdr->quantization); 302 - cf.rlc_data = (__be16 *)(p_in + sizeof(*p_hdr)); 303 - 304 - if (p_hdr->magic1 != FWHT_MAGIC1 || 305 - p_hdr->magic2 != FWHT_MAGIC2 || 306 - ntohl(p_hdr->version) != FWHT_VERSION || 307 - cf.width < MIN_WIDTH || 308 - cf.width > MAX_WIDTH || 309 - cf.height < MIN_HEIGHT || 310 - cf.height > MAX_HEIGHT || 311 - (cf.width & 7) || (cf.height & 7)) 312 - return -EINVAL; 313 - 314 - /* TODO: support resolution changes */ 315 - if (cf.width != q_data->width || cf.height != q_data->height) 316 - return -EINVAL; 317 - 318 - if (!(flags & FWHT_FL_CHROMA_FULL_WIDTH)) 319 - chroma_size /= 2; 320 - if (!(flags & FWHT_FL_CHROMA_FULL_HEIGHT)) 321 - chroma_size /= 2; 322 - 323 - fwht_decode_frame(&cf, &ctx->ref_frame, flags); 324 - 325 - switch (q_data->info->id) { 326 - case V4L2_PIX_FMT_YUV420: 327 - case V4L2_PIX_FMT_YUV422P: 328 - memcpy(p_out, ctx->ref_frame.luma, size); 329 - p_out += size; 330 - memcpy(p_out, ctx->ref_frame.cb, chroma_size); 331 - p_out += chroma_size; 332 - memcpy(p_out, ctx->ref_frame.cr, chroma_size); 333 - break; 334 - case V4L2_PIX_FMT_YVU420: 335 - memcpy(p_out, ctx->ref_frame.luma, size); 336 - p_out += size; 337 - memcpy(p_out, ctx->ref_frame.cr, chroma_size); 338 - p_out += chroma_size; 339 - memcpy(p_out, ctx->ref_frame.cb, chroma_size); 340 - break; 341 - case V4L2_PIX_FMT_NV12: 342 - case V4L2_PIX_FMT_NV16: 343 - case V4L2_PIX_FMT_NV24: 344 - memcpy(p_out, ctx->ref_frame.luma, size); 345 - p_out += size; 346 - for (i = 0, p = p_out; i < chroma_size; i++) { 347 - *p++ = ctx->ref_frame.cb[i]; 348 - *p++ = ctx->ref_frame.cr[i]; 349 - } 350 - break; 351 - case V4L2_PIX_FMT_NV21: 352 - case V4L2_PIX_FMT_NV61: 353 - case V4L2_PIX_FMT_NV42: 354 - memcpy(p_out, ctx->ref_frame.luma, size); 355 - p_out += size; 356 - for (i = 0, p = p_out; i < chroma_size; i++) { 357 - *p++ = ctx->ref_frame.cr[i]; 358 - *p++ = ctx->ref_frame.cb[i]; 359 - } 360 - break; 361 - case V4L2_PIX_FMT_YUYV: 362 - for (i = 0, p = p_out; i < size; i += 2) { 363 - *p++ = ctx->ref_frame.luma[i]; 364 - *p++ = ctx->ref_frame.cb[i / 2]; 365 - *p++ = ctx->ref_frame.luma[i + 1]; 366 - *p++ = ctx->ref_frame.cr[i / 2]; 367 - } 368 - break; 369 - case V4L2_PIX_FMT_YVYU: 370 - for (i = 0, p = p_out; i < size; i += 2) { 371 - *p++ = ctx->ref_frame.luma[i]; 372 - *p++ = ctx->ref_frame.cr[i / 2]; 373 - *p++ = ctx->ref_frame.luma[i + 1]; 374 - *p++ = ctx->ref_frame.cb[i / 2]; 375 - } 376 - break; 377 - case V4L2_PIX_FMT_UYVY: 378 - for (i = 0, p = p_out; i < size; i += 2) { 379 - *p++ = ctx->ref_frame.cb[i / 2]; 380 - *p++ = ctx->ref_frame.luma[i]; 381 - *p++ = ctx->ref_frame.cr[i / 2]; 382 - *p++ = ctx->ref_frame.luma[i + 1]; 383 - } 384 - break; 385 - case V4L2_PIX_FMT_VYUY: 386 - for (i = 0, p = p_out; i < size; i += 2) { 387 - *p++ = ctx->ref_frame.cr[i / 2]; 388 - *p++ = ctx->ref_frame.luma[i]; 389 - *p++ = ctx->ref_frame.cb[i / 2]; 390 - *p++ = ctx->ref_frame.luma[i + 1]; 391 - } 392 - break; 393 - case V4L2_PIX_FMT_RGB24: 394 - case V4L2_PIX_FMT_HSV24: 395 - for (i = 0, p = p_out; i < size; i++) { 396 - *p++ = ctx->ref_frame.cr[i]; 397 - *p++ = ctx->ref_frame.luma[i]; 398 - *p++ = ctx->ref_frame.cb[i]; 399 - } 400 - break; 401 - case V4L2_PIX_FMT_BGR24: 402 - for (i = 0, p = p_out; i < size; i++) { 403 - *p++ = ctx->ref_frame.cb[i]; 404 - *p++ = ctx->ref_frame.luma[i]; 405 - *p++ = ctx->ref_frame.cr[i]; 406 - } 407 - break; 408 - case V4L2_PIX_FMT_RGB32: 409 - case V4L2_PIX_FMT_XRGB32: 410 - case V4L2_PIX_FMT_HSV32: 411 - for (i = 0, p = p_out; i < size; i++) { 412 - *p++ = 0; 413 - *p++ = ctx->ref_frame.cr[i]; 414 - *p++ = ctx->ref_frame.luma[i]; 415 - *p++ = ctx->ref_frame.cb[i]; 416 - } 417 - break; 418 - case V4L2_PIX_FMT_BGR32: 419 - case V4L2_PIX_FMT_XBGR32: 420 - for (i = 0, p = p_out; i < size; i++) { 421 - *p++ = ctx->ref_frame.cb[i]; 422 - *p++ = ctx->ref_frame.luma[i]; 423 - *p++ = ctx->ref_frame.cr[i]; 424 - *p++ = 0; 425 - } 426 - break; 427 - } 428 - return 0; 429 - } 430 - 431 188 static int device_process(struct vicodec_ctx *ctx, 432 189 struct vb2_v4l2_buffer *in_vb, 433 190 struct vb2_v4l2_buffer *out_vb) 434 191 { 435 192 struct vicodec_dev *dev = ctx->dev; 436 193 struct vicodec_q_data *q_out, *q_cap; 194 + struct v4l2_fwht_state *state = &ctx->state; 437 195 u8 *p_in, *p_out; 438 196 int ret; 439 197 ··· 167 475 if (ctx->is_enc) 168 476 p_in = vb2_plane_vaddr(&in_vb->vb2_buf, 0); 169 477 else 170 - p_in = ctx->compressed_frame; 478 + p_in = state->compressed_frame; 171 479 p_out = vb2_plane_vaddr(&out_vb->vb2_buf, 0); 172 480 if (!p_in || !p_out) { 173 481 v4l2_err(&dev->v4l2_dev, ··· 176 484 } 177 485 178 486 if (ctx->is_enc) { 179 - struct fwht_cframe_hdr *p_hdr = (struct fwht_cframe_hdr *)p_out; 487 + unsigned int size = v4l2_fwht_encode(state, p_in, p_out); 180 488 181 - encode(ctx, q_out, p_in, p_out, 0); 182 - vb2_set_plane_payload(&out_vb->vb2_buf, 0, 183 - sizeof(*p_hdr) + ntohl(p_hdr->size)); 489 + vb2_set_plane_payload(&out_vb->vb2_buf, 0, size); 184 490 } else { 185 - ret = decode(ctx, q_cap, p_in, p_out); 491 + ret = v4l2_fwht_decode(state, p_in, p_out); 186 492 if (ret) 187 493 return ret; 188 494 vb2_set_plane_payload(&out_vb->vb2_buf, 0, q_cap->sizeimage); ··· 309 619 copy = sizeof(magic) - ctx->comp_magic_cnt; 310 620 if (p_out + sz - p < copy) 311 621 copy = p_out + sz - p; 312 - memcpy(ctx->compressed_frame + ctx->comp_magic_cnt, 622 + memcpy(ctx->state.compressed_frame + ctx->comp_magic_cnt, 313 623 p, copy); 314 624 ctx->comp_magic_cnt += copy; 315 - if (!memcmp(ctx->compressed_frame, magic, ctx->comp_magic_cnt)) { 625 + if (!memcmp(ctx->state.compressed_frame, magic, 626 + ctx->comp_magic_cnt)) { 316 627 p += copy; 317 628 state = VB2_BUF_STATE_DONE; 318 629 break; ··· 328 637 } 329 638 if (ctx->comp_size < sizeof(struct fwht_cframe_hdr)) { 330 639 struct fwht_cframe_hdr *p_hdr = 331 - (struct fwht_cframe_hdr *)ctx->compressed_frame; 640 + (struct fwht_cframe_hdr *)ctx->state.compressed_frame; 332 641 u32 copy = sizeof(struct fwht_cframe_hdr) - ctx->comp_size; 333 642 334 643 if (copy > p_out + sz - p) 335 644 copy = p_out + sz - p; 336 - memcpy(ctx->compressed_frame + ctx->comp_size, 645 + memcpy(ctx->state.compressed_frame + ctx->comp_size, 337 646 p, copy); 338 647 p += copy; 339 648 ctx->comp_size += copy; ··· 350 659 351 660 if (copy > p_out + sz - p) 352 661 copy = p_out + sz - p; 353 - memcpy(ctx->compressed_frame + ctx->comp_size, 662 + memcpy(ctx->state.compressed_frame + ctx->comp_size, 354 663 p, copy); 355 664 p += copy; 356 665 ctx->comp_size += copy; ··· 385 694 * video ioctls 386 695 */ 387 696 388 - static const struct pixfmt_info *find_fmt(u32 fmt) 697 + static const struct v4l2_fwht_pixfmt_info *find_fmt(u32 fmt) 389 698 { 390 - unsigned int i; 699 + const struct v4l2_fwht_pixfmt_info *info = 700 + v4l2_fwht_find_pixfmt(fmt); 391 701 392 - for (i = 0; i < ARRAY_SIZE(pixfmts); i++) 393 - if (pixfmts[i].id == fmt) 394 - return &pixfmts[i]; 395 - return &pixfmts[0]; 702 + if (!info) 703 + info = v4l2_fwht_get_pixfmt(0); 704 + return info; 396 705 } 397 706 398 707 static int vidioc_querycap(struct file *file, void *priv, ··· 418 727 return -EINVAL; 419 728 if (!V4L2_TYPE_IS_MULTIPLANAR(f->type) && multiplanar) 420 729 return -EINVAL; 421 - if (f->index >= (is_uncomp ? ARRAY_SIZE(pixfmts) : 1)) 422 - return -EINVAL; 423 730 424 - if (is_uncomp) 425 - f->pixelformat = pixfmts[f->index].id; 426 - else 731 + if (is_uncomp) { 732 + const struct v4l2_fwht_pixfmt_info *info = 733 + v4l2_fwht_get_pixfmt(f->index); 734 + 735 + if (!info) 736 + return -EINVAL; 737 + f->pixelformat = info->id; 738 + } else { 739 + if (f->index) 740 + return -EINVAL; 427 741 f->pixelformat = V4L2_PIX_FMT_FWHT; 742 + } 428 743 return 0; 429 744 } 430 745 ··· 456 759 struct vicodec_q_data *q_data; 457 760 struct v4l2_pix_format_mplane *pix_mp; 458 761 struct v4l2_pix_format *pix; 459 - const struct pixfmt_info *info; 762 + const struct v4l2_fwht_pixfmt_info *info; 460 763 461 764 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type); 462 765 if (!vq) ··· 477 780 pix->pixelformat = info->id; 478 781 pix->bytesperline = q_data->width * info->bytesperline_mult; 479 782 pix->sizeimage = q_data->sizeimage; 480 - pix->colorspace = ctx->colorspace; 481 - pix->xfer_func = ctx->xfer_func; 482 - pix->ycbcr_enc = ctx->ycbcr_enc; 483 - pix->quantization = ctx->quantization; 783 + pix->colorspace = ctx->state.colorspace; 784 + pix->xfer_func = ctx->state.xfer_func; 785 + pix->ycbcr_enc = ctx->state.ycbcr_enc; 786 + pix->quantization = ctx->state.quantization; 484 787 break; 485 788 486 789 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: ··· 496 799 pix_mp->plane_fmt[0].bytesperline = 497 800 q_data->width * info->bytesperline_mult; 498 801 pix_mp->plane_fmt[0].sizeimage = q_data->sizeimage; 499 - pix_mp->colorspace = ctx->colorspace; 500 - pix_mp->xfer_func = ctx->xfer_func; 501 - pix_mp->ycbcr_enc = ctx->ycbcr_enc; 502 - pix_mp->quantization = ctx->quantization; 802 + pix_mp->colorspace = ctx->state.colorspace; 803 + pix_mp->xfer_func = ctx->state.xfer_func; 804 + pix_mp->ycbcr_enc = ctx->state.ycbcr_enc; 805 + pix_mp->quantization = ctx->state.quantization; 503 806 memset(pix_mp->reserved, 0, sizeof(pix_mp->reserved)); 504 807 memset(pix_mp->plane_fmt[0].reserved, 0, 505 808 sizeof(pix_mp->plane_fmt[0].reserved)); ··· 527 830 struct v4l2_pix_format_mplane *pix_mp; 528 831 struct v4l2_pix_format *pix; 529 832 struct v4l2_plane_pix_format *plane; 530 - const struct pixfmt_info *info = &pixfmt_fwht; 833 + const struct v4l2_fwht_pixfmt_info *info = &pixfmt_fwht; 531 834 532 835 switch (f->type) { 533 836 case V4L2_BUF_TYPE_VIDEO_CAPTURE: ··· 586 889 pix = &f->fmt.pix; 587 890 pix->pixelformat = ctx->is_enc ? V4L2_PIX_FMT_FWHT : 588 891 find_fmt(f->fmt.pix.pixelformat)->id; 589 - pix->colorspace = ctx->colorspace; 590 - pix->xfer_func = ctx->xfer_func; 591 - pix->ycbcr_enc = ctx->ycbcr_enc; 592 - pix->quantization = ctx->quantization; 892 + pix->colorspace = ctx->state.colorspace; 893 + pix->xfer_func = ctx->state.xfer_func; 894 + pix->ycbcr_enc = ctx->state.ycbcr_enc; 895 + pix->quantization = ctx->state.quantization; 593 896 break; 594 897 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 595 898 if (!multiplanar) ··· 597 900 pix_mp = &f->fmt.pix_mp; 598 901 pix_mp->pixelformat = ctx->is_enc ? V4L2_PIX_FMT_FWHT : 599 902 find_fmt(pix_mp->pixelformat)->id; 600 - pix_mp->colorspace = ctx->colorspace; 601 - pix_mp->xfer_func = ctx->xfer_func; 602 - pix_mp->ycbcr_enc = ctx->ycbcr_enc; 603 - pix_mp->quantization = ctx->quantization; 903 + pix_mp->colorspace = ctx->state.colorspace; 904 + pix_mp->xfer_func = ctx->state.xfer_func; 905 + pix_mp->ycbcr_enc = ctx->state.ycbcr_enc; 906 + pix_mp->quantization = ctx->state.quantization; 604 907 break; 605 908 default: 606 909 return -EINVAL; ··· 740 1043 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 741 1044 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 742 1045 pix = &f->fmt.pix; 743 - ctx->colorspace = pix->colorspace; 744 - ctx->xfer_func = pix->xfer_func; 745 - ctx->ycbcr_enc = pix->ycbcr_enc; 746 - ctx->quantization = pix->quantization; 1046 + ctx->state.colorspace = pix->colorspace; 1047 + ctx->state.xfer_func = pix->xfer_func; 1048 + ctx->state.ycbcr_enc = pix->ycbcr_enc; 1049 + ctx->state.quantization = pix->quantization; 747 1050 break; 748 1051 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE: 749 1052 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE: 750 1053 pix_mp = &f->fmt.pix_mp; 751 - ctx->colorspace = pix_mp->colorspace; 752 - ctx->xfer_func = pix_mp->xfer_func; 753 - ctx->ycbcr_enc = pix_mp->ycbcr_enc; 754 - ctx->quantization = pix_mp->quantization; 1054 + ctx->state.colorspace = pix_mp->colorspace; 1055 + ctx->state.xfer_func = pix_mp->xfer_func; 1056 + ctx->state.ycbcr_enc = pix_mp->ycbcr_enc; 1057 + ctx->state.quantization = pix_mp->quantization; 755 1058 break; 756 1059 default: 757 1060 break; ··· 994 1297 { 995 1298 struct vicodec_ctx *ctx = vb2_get_drv_priv(q); 996 1299 struct vicodec_q_data *q_data = get_q_data(ctx, q->type); 1300 + struct v4l2_fwht_state *state = &ctx->state; 997 1301 unsigned int size = q_data->width * q_data->height; 998 - const struct pixfmt_info *info = q_data->info; 1302 + const struct v4l2_fwht_pixfmt_info *info = q_data->info; 999 1303 unsigned int chroma_div = info->width_div * info->height_div; 1000 1304 1001 1305 q_data->sequence = 0; ··· 1004 1306 if (!V4L2_TYPE_IS_OUTPUT(q->type)) 1005 1307 return 0; 1006 1308 1007 - ctx->ref_frame.width = ctx->ref_frame.height = 0; 1008 - ctx->ref_frame.luma = kvmalloc(size + 2 * size / chroma_div, GFP_KERNEL); 1309 + state->width = q_data->width; 1310 + state->height = q_data->height; 1311 + state->ref_frame.width = state->ref_frame.height = 0; 1312 + state->ref_frame.luma = kvmalloc(size + 2 * size / chroma_div, 1313 + GFP_KERNEL); 1009 1314 ctx->comp_max_size = size + 2 * size / chroma_div + 1010 1315 sizeof(struct fwht_cframe_hdr); 1011 - ctx->compressed_frame = kvmalloc(ctx->comp_max_size, GFP_KERNEL); 1012 - if (!ctx->ref_frame.luma || !ctx->compressed_frame) { 1013 - kvfree(ctx->ref_frame.luma); 1014 - kvfree(ctx->compressed_frame); 1316 + state->compressed_frame = kvmalloc(ctx->comp_max_size, GFP_KERNEL); 1317 + if (!state->ref_frame.luma || !state->compressed_frame) { 1318 + kvfree(state->ref_frame.luma); 1319 + kvfree(state->compressed_frame); 1015 1320 vicodec_return_bufs(q, VB2_BUF_STATE_QUEUED); 1016 1321 return -ENOMEM; 1017 1322 } 1018 - ctx->ref_frame.cb = ctx->ref_frame.luma + size; 1019 - ctx->ref_frame.cr = ctx->ref_frame.cb + size / chroma_div; 1323 + state->ref_frame.cb = state->ref_frame.luma + size; 1324 + state->ref_frame.cr = state->ref_frame.cb + size / chroma_div; 1020 1325 ctx->last_src_buf = NULL; 1021 1326 ctx->last_dst_buf = NULL; 1022 - ctx->gop_cnt = 0; 1327 + state->gop_cnt = 0; 1023 1328 ctx->cur_buf_offset = 0; 1024 1329 ctx->comp_size = 0; 1025 1330 ctx->comp_magic_cnt = 0; ··· 1040 1339 if (!V4L2_TYPE_IS_OUTPUT(q->type)) 1041 1340 return; 1042 1341 1043 - kvfree(ctx->ref_frame.luma); 1044 - kvfree(ctx->compressed_frame); 1342 + kvfree(ctx->state.ref_frame.luma); 1343 + kvfree(ctx->state.compressed_frame); 1045 1344 } 1046 1345 1047 1346 static const struct vb2_ops vicodec_qops = { ··· 1101 1400 1102 1401 switch (ctrl->id) { 1103 1402 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: 1104 - ctx->gop_size = ctrl->val; 1403 + ctx->state.gop_size = ctrl->val; 1105 1404 return 0; 1106 1405 case VICODEC_CID_I_FRAME_QP: 1107 - ctx->i_frame_qp = ctrl->val; 1406 + ctx->state.i_frame_qp = ctrl->val; 1108 1407 return 0; 1109 1408 case VICODEC_CID_P_FRAME_QP: 1110 - ctx->p_frame_qp = ctrl->val; 1409 + ctx->state.p_frame_qp = ctrl->val; 1111 1410 return 0; 1112 1411 } 1113 1412 return -EINVAL; 1114 1413 } 1115 1414 1116 - static const struct v4l2_ctrl_ops vicodec_ctrl_ops = { 1415 + static struct v4l2_ctrl_ops vicodec_ctrl_ops = { 1117 1416 .s_ctrl = vicodec_s_ctrl, 1118 1417 }; 1119 1418 ··· 1181 1480 v4l2_ctrl_handler_setup(hdl); 1182 1481 1183 1482 ctx->q_data[V4L2_M2M_SRC].info = 1184 - ctx->is_enc ? pixfmts : &pixfmt_fwht; 1483 + ctx->is_enc ? v4l2_fwht_get_pixfmt(0) : &pixfmt_fwht; 1185 1484 ctx->q_data[V4L2_M2M_SRC].width = 1280; 1186 1485 ctx->q_data[V4L2_M2M_SRC].height = 720; 1187 1486 size = 1280 * 720 * ctx->q_data[V4L2_M2M_SRC].info->sizeimage_mult / ··· 1189 1488 ctx->q_data[V4L2_M2M_SRC].sizeimage = size; 1190 1489 ctx->q_data[V4L2_M2M_DST] = ctx->q_data[V4L2_M2M_SRC]; 1191 1490 ctx->q_data[V4L2_M2M_DST].info = 1192 - ctx->is_enc ? &pixfmt_fwht : pixfmts; 1491 + ctx->is_enc ? &pixfmt_fwht : v4l2_fwht_get_pixfmt(0); 1193 1492 size = 1280 * 720 * ctx->q_data[V4L2_M2M_DST].info->sizeimage_mult / 1194 1493 ctx->q_data[V4L2_M2M_DST].info->sizeimage_div; 1195 1494 ctx->q_data[V4L2_M2M_DST].sizeimage = size; 1196 - ctx->colorspace = V4L2_COLORSPACE_REC709; 1495 + ctx->state.colorspace = V4L2_COLORSPACE_REC709; 1197 1496 1198 1497 size += sizeof(struct fwht_cframe_hdr); 1199 1498 if (ctx->is_enc) {