Add support to more pixel formats in vicodec
v2 cover Add support to more pixel formats in vicodec
The new supported formats areV4L2_PIX_FMT_GREY, V4L2_PIX_FMT_ARGB32, V4L2_PIX_FMT_ABGR32.
The returned encoded format is chaned to support various numbers of planes instead of assuming 3 planes.
The first patch adds new fields to structs.
The second patch adds support for V4L2_PIX_FMT_GREY.
The third patch adds support for V4L2_PIX_FMT_ARGB32, V4L2_PIX_FMT_ABGR32.
Changes from v1:
- support both version 1,2
- when needed, replace the test 'number of comonents > 1' to 'number of components >= 3''
- use luma_alpha_step field for both luma and alpha planes
- some cleanups
Dafna Hirschfeld (3):
media: vicodec: prepare support for various number of planes
media: vicodec: Add support of greyscale format
media: vicodec: Add support for 4 planes formats
drivers/media/platform/vicodec/codec-fwht.c | 73 +++++++++----- drivers/media/platform/vicodec/codec-fwht.h | 15 ++- drivers/media/platform/vicodec/codec-v4l2-fwht.c | 123 +++++++++++++++++------ drivers/media/platform/vicodec/codec-v4l2-fwht.h | 3 +- drivers/media/platform/vicodec/vicodec-core.c | 35 +++++-- 5 files changed, 182 insertions(+), 67 deletions(-)
Signature · 1 line
2.7.4
PATCH v2 1/3 media: vicodec: prepare support for various number of planes
From: Dafna Hirschfeld <[email protected]>
Add fields to the structs fwht_raw_frame, v4l2_fwht_pixfmts to support various number of planes - formats
with alpha channel that have 4 planes and greyscale formats that have 1 plane.
--- drivers/media/platform/vicodec/codec-fwht.c | 2 +- drivers/media/platform/vicodec/codec-fwht.h | 5 ++- drivers/media/platform/vicodec/codec-v4l2-fwht.c | 47 +++++++++++++----------- drivers/media/platform/vicodec/codec-v4l2-fwht.h | 3 +- drivers/media/platform/vicodec/vicodec-core.c | 2 +- 5 files changed, 32 insertions(+), 27 deletions(-)
drivers/media/platform/vicodec/codec-fwht.c +1 -1
@@ -760,7 +760,7 @@ u32 fwht_encode_frame(struct fwht_raw_frame *frm, rlco_max = rlco + size /2 -256 ; encoding =encode_plane (frm->luma, ref_frm->luma, &rlco, rlco_max, cf, frm->height, frm->width, - frm->luma_step, is_intra, next_is_intra); + frm->luma_alpha_step, is_intra, next_is_intra);if (encoding &FWHT_FRAME_UNENCODED ) encoding |=FWHT_LUMA_UNENCODED ; encoding &= ~FWHT_FRAME_UNENCODED ;
drivers/media/platform/vicodec/codec-fwht.h +3 -2
@@ -104,9 +104,10 @@ struct fwht_raw_frame {unsigned int width, height;unsigned int width_div;unsigned int height_div; -unsigned int luma_step; +unsigned int luma_alpha_step;unsigned int chroma_step; -u8 *luma, *cb, *cr; +unsigned int components_num; +u8 *luma, *cb, *cr, *alpha; };#define FWHT_FRAME_PCODED BIT(0)
drivers/media/platform/vicodec/codec-v4l2-fwht.c +25 -22
60 lines not on this page · raw message
drivers/media/platform/vicodec/codec-v4l2-fwht.h +2 -1
@@ -13,11 +13,12 @@ struct v4l2_fwht_pixfmt_info {unsigned int bytesperline_mult;unsigned int sizeimage_mult;unsigned int sizeimage_div; -unsigned int luma_step; +unsigned int luma_alpha_step;unsigned int chroma_step;/* Chroma plane subsampling */ unsigned int width_div;unsigned int height_div; +unsigned int components_num; };struct v4l2_fwht_state {
drivers/media/platform/vicodec/vicodec-core.c +1 -1
@@ -61,7 +61,7 @@ struct pixfmt_info { };static const struct v4l2_fwht_pixfmt_info pixfmt_fwht = { -V4L2_PIX_FMT_FWHT ,0 ,3 ,1 ,1 ,1 ,1 ,1 +V4L2_PIX_FMT_FWHT ,0 ,3 ,1 ,1 ,1 ,1 ,1 ,0 };static void vicodec_dev_release (struct device *dev)
Signature · 1 line
2.7.4
PATCH v2 2/3 media: vicodec: Add support of greyscale format
In reply to kamomilFrom: Dafna Hirschfeld <[email protected]>
Add support for single plane greyscale format V4L2_PIX_FMT_GREY. Also change the header of the encoded file to include the number of components.
--- drivers/media/platform/vicodec/codec-fwht.c | 56 ++++++++++++++---------- drivers/media/platform/vicodec/codec-fwht.h | 8 +++- drivers/media/platform/vicodec/codec-v4l2-fwht.c | 44 +++++++++++++++---- drivers/media/platform/vicodec/vicodec-core.c | 21 ++++++--- 4 files changed, 89 insertions(+), 40 deletions(-)
drivers/media/platform/vicodec/codec-fwht.c +32 -24
@@ -753,9 +753,6 @@ u32 fwht_encode_frame(struct fwht_raw_frame *frm,__be16 *rlco = cf->rlc_data;__be16 *rlco_max;u32 encoding; -u32 chroma_h = frm->height / frm->height_div; -u32 chroma_w = frm->width / frm->width_div; -unsigned int chroma_size = chroma_h * chroma_w; rlco_max = rlco + size /2 -256 ; encoding = encode_plane(frm->luma, ref_frm->luma, &rlco, rlco_max, cf,
@@ -764,20 +761,27 @@ u32 fwht_encode_frame(struct fwht_raw_frame *frm,if (encoding &FWHT_FRAME_UNENCODED ) encoding |=FWHT_LUMA_UNENCODED ; encoding &= ~FWHT_FRAME_UNENCODED ; - rlco_max = rlco + chroma_size /2 -256 ; - encoding |=encode_plane (frm->cb, ref_frm->cb, &rlco, rlco_max, cf, + +if (frm->components_num >=3 ) { +u32 chroma_h = frm->height / frm->height_div; +u32 chroma_w = frm->width / frm->width_div; +unsigned int chroma_size = chroma_h * chroma_w; + + rlco_max = rlco + chroma_size /2 -256 ; + encoding |=encode_plane (frm->cb, ref_frm->cb, &rlco, rlco_max, cf, chroma_h, chroma_w, frm->chroma_step, is_intra, next_is_intra); -if (encoding &FWHT_FRAME_UNENCODED ) - encoding |=FWHT_CB_UNENCODED ; - encoding &= ~FWHT_FRAME_UNENCODED ; - rlco_max = rlco + chroma_size /2 -256 ; - encoding |=encode_plane (frm->cr, ref_frm->cr, &rlco, rlco_max, cf, +if (encoding &FWHT_FRAME_UNENCODED ) + encoding |=FWHT_CB_UNENCODED ; + encoding &= ~FWHT_FRAME_UNENCODED ; + rlco_max = rlco + chroma_size /2 -256 ; + encoding |=encode_plane (frm->cr, ref_frm->cr, &rlco, rlco_max, cf, chroma_h, chroma_w, frm->chroma_step, is_intra, next_is_intra); -if (encoding &FWHT_FRAME_UNENCODED ) - encoding |=FWHT_CR_UNENCODED ; - encoding &= ~FWHT_FRAME_UNENCODED ; +if (encoding &FWHT_FRAME_UNENCODED ) + encoding |=FWHT_CR_UNENCODED ; + encoding &= ~FWHT_FRAME_UNENCODED ; + } cf->size = (rlco - cf->rlc_data) *sizeof (*rlco);return encoding; }
@@ -836,20 +840,24 @@ static void decode_plane(struct fwht_cframe *cf, const __be16 **rlco, u8 *ref, }void fwht_decode_frame (struct fwht_cframe *cf,struct fwht_raw_frame *ref, -u32 hdr_flags) +u32 hdr_flags,unsigned int components_num) {const __be16 *rlco = cf->rlc_data; -u32 h = cf->height /2 ; -u32 w = cf->width /2 ; -if (hdr_flags &FWHT_FL_CHROMA_FULL_HEIGHT ) - h *=2 ; -if (hdr_flags &FWHT_FL_CHROMA_FULL_WIDTH ) - w *=2 ;decode_plane (cf, &rlco, ref->luma, cf->height, cf->width, hdr_flags &FWHT_FL_LUMA_IS_UNCOMPRESSED ); -decode_plane (cf, &rlco, ref->cb, h, w, - hdr_flags &FWHT_FL_CB_IS_UNCOMPRESSED ); -decode_plane (cf, &rlco, ref->cr, h, w, - hdr_flags &FWHT_FL_CR_IS_UNCOMPRESSED ); + +if (components_num >=3 ) { +u32 h = cf->height; +u32 w = cf->width; + +if (!(hdr_flags &FWHT_FL_CHROMA_FULL_HEIGHT )) + h /=2 ; +if (!(hdr_flags &FWHT_FL_CHROMA_FULL_WIDTH )) + w /=2 ; +decode_plane (cf, &rlco, ref->cb, h, w, + hdr_flags &FWHT_FL_CB_IS_UNCOMPRESSED ); +decode_plane (cf, &rlco, ref->cr, h, w, + hdr_flags &FWHT_FL_CR_IS_UNCOMPRESSED ); + } }
drivers/media/platform/vicodec/codec-fwht.h +6 -2
@@ -56,7 +56,7 @@#define FWHT_MAGIC1 0x4f4f4f4f#define FWHT_MAGIC2 0xffffffff -#define FWHT_VERSION 1 +#define FWHT_VERSION 2/* Set if this is an interlaced format */ #define FWHT_FL_IS_INTERLACED BIT(0)
@@ -76,6 +76,10 @@#define FWHT_FL_CHROMA_FULL_HEIGHT BIT(7)#define FWHT_FL_CHROMA_FULL_WIDTH BIT(8) +/* A 4-values flag - the number of components - 1 */ +#define FWHT_FL_COMPONENTS_NUM_BIT0 BIT(16) +#define FWHT_FL_COMPONENTS_NUM_BIT1 BIT(17) +struct fwht_cframe_hdr {u32 magic1;u32 magic2;
@@ -121,6 +125,6 @@ u32 fwht_encode_frame(struct fwht_raw_frame *frm,struct fwht_cframe *cf, bool is_intra, bool next_is_intra);void fwht_decode_frame (struct fwht_cframe *cf,struct fwht_raw_frame *ref, -u32 hdr_flags); +u32 hdr_flags,unsigned int components_num);#endif
drivers/media/platform/vicodec/codec-v4l2-fwht.c +36 -8
90 lines not on this page · raw message
drivers/media/platform/vicodec/vicodec-core.c +15 -6
@@ -993,6 +993,12 @@ static int vicodec_start_streaming(struct vb2_queue *q,unsigned int size = q_data->width * q_data->height;const struct v4l2_fwht_pixfmt_info *info = q_data->info;unsigned int chroma_div = info->width_div * info->height_div; +unsigned int total_planes_size; + +if (info->components_num >=3 ) + total_planes_size = size +2 * (size / chroma_div); +else + total_planes_size = size; q_data->sequence =0 ;
@@ -1002,10 +1008,8 @@ static int vicodec_start_streaming(struct vb2_queue *q, state->width = q_data->width; state->height = q_data->height; state->ref_frame.width = state->ref_frame.height =0 ; - state->ref_frame.luma =kvmalloc (size +2 * size / chroma_div, -GFP_KERNEL ); - ctx->comp_max_size = size +2 * size / chroma_div + -sizeof (struct fwht_cframe_hdr ); + state->ref_frame.luma =kvmalloc (total_planes_size,GFP_KERNEL ); + ctx->comp_max_size = total_planes_size +sizeof (struct fwht_cframe_hdr ); state->compressed_frame =kvmalloc (ctx->comp_max_size,GFP_KERNEL );if (!state->ref_frame.luma || !state->compressed_frame) {kvfree (state->ref_frame.luma);
@@ -1013,8 +1017,13 @@ static int vicodec_start_streaming(struct vb2_queue *q,vicodec_return_bufs (q,VB2_BUF_STATE_QUEUED );return -ENOMEM ; } - state->ref_frame.cb = state->ref_frame.luma + size; - state->ref_frame.cr = state->ref_frame.cb + size / chroma_div; +if (info->id ==V4L2_PIX_FMT_FWHT || info->components_num >=3 ) { + state->ref_frame.cb = state->ref_frame.luma + size; + state->ref_frame.cr = state->ref_frame.cb + size / chroma_div; + }else { + state->ref_frame.cb =NULL ; + state->ref_frame.cr =NULL ; + } ctx->last_src_buf =NULL ; ctx->last_dst_buf =NULL ; state->gop_cnt =0 ;
Signature · 1 line
2.7.4
PATCH v2 3/3 media: vicodec: Add support for 4 planes formats
In reply to kamomilFrom: Dafna Hirschfeld <[email protected]>
Add support for formats with 4 planes: V4L2_PIX_FMT_ABGR32, V4L2_PIX_FMT_ARGB32.
Also add alpha plane related flags to the header of the encoded file.
--- drivers/media/platform/vicodec/codec-fwht.c | 15 +++++++++++ drivers/media/platform/vicodec/codec-fwht.h | 2 ++ drivers/media/platform/vicodec/codec-v4l2-fwht.c | 32 ++++++++++++++++++++++++ drivers/media/platform/vicodec/vicodec-core.c | 14 ++++++++++- 4 files changed, 62 insertions(+), 1 deletion(-)
drivers/media/platform/vicodec/codec-fwht.c +15 -0
@@ -782,6 +782,17 @@ u32 fwht_encode_frame(struct fwht_raw_frame *frm, encoding |=FWHT_CR_UNENCODED ; encoding &= ~FWHT_FRAME_UNENCODED ; } + +if (frm->components_num ==4 ) { + rlco_max = rlco + size /2 -256 ; + encoding =encode_plane (frm->alpha, ref_frm->alpha, &rlco, rlco_max, cf, + frm->height, frm->width, + frm->luma_alpha_step, is_intra, next_is_intra); +if (encoding &FWHT_FRAME_UNENCODED ) + encoding |=FWHT_ALPHA_UNENCODED ; + encoding &= ~FWHT_FRAME_UNENCODED ; + } + cf->size = (rlco - cf->rlc_data) *sizeof (*rlco);return encoding; }
@@ -860,4 +871,8 @@ void fwht_decode_frame(struct fwht_cframe *cf, struct fwht_raw_frame *ref,decode_plane (cf, &rlco, ref->cr, h, w, hdr_flags &FWHT_FL_CR_IS_UNCOMPRESSED ); } + +if (components_num ==4 ) +decode_plane (cf, &rlco, ref->alpha, cf->height, cf->width, + hdr_flags &FWHT_FL_ALPHA_IS_UNCOMPRESSED ); }
drivers/media/platform/vicodec/codec-fwht.h +2 -0
@@ -75,6 +75,7 @@#define FWHT_FL_CR_IS_UNCOMPRESSED BIT(6)#define FWHT_FL_CHROMA_FULL_HEIGHT BIT(7)#define FWHT_FL_CHROMA_FULL_WIDTH BIT(8) +#define FWHT_FL_ALPHA_IS_UNCOMPRESSED BIT(9)/* A 4-values flag - the number of components - 1 */ #define FWHT_FL_COMPONENTS_NUM_BIT0 BIT(16)
@@ -119,6 +120,7 @@ struct fwht_raw_frame {#define FWHT_LUMA_UNENCODED BIT(2)#define FWHT_CB_UNENCODED BIT(3)#define FWHT_CR_UNENCODED BIT(4) +#define FWHT_ALPHA_UNENCODED BIT(5) u32 fwht_encode_frame(struct fwht_raw_frame *frm, struct fwht_raw_frame *ref_frm,
drivers/media/platform/vicodec/codec-v4l2-fwht.c +32 -0
@@ -33,6 +33,8 @@ static const struct v4l2_fwht_pixfmt_info v4l2_fwht_pixfmts[] = { { V4L2_PIX_FMT_RGB32, 4, 4, 1, 4, 4, 1, 1, 3}, { V4L2_PIX_FMT_XRGB32, 4, 4, 1, 4, 4, 1, 1, 3}, { V4L2_PIX_FMT_HSV32, 4, 4, 1, 4, 4, 1, 1, 3}, + { V4L2_PIX_FMT_ARGB32, 4, 4, 1, 4, 4, 1, 1, 4}, + { V4L2_PIX_FMT_ABGR32, 4, 4, 1, 4, 4, 1, 1, 4}, };
@@ -146,6 +148,18 @@ int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out) rf.cr = rf.cb +2 ; rf.luma++;break ; +case V4L2_PIX_FMT_ARGB32 : + rf.alpha = rf.luma; + rf.cr = rf.luma +1 ; + rf.cb = rf.cr +2 ; + rf.luma +=2 ; +break ; +case V4L2_PIX_FMT_ABGR32 : + rf.cb = rf.luma; + rf.cr = rf.cb +2 ; + rf.luma++; + rf.alpha = rf.cr +1 ; +break ;default :return -EINVAL ; }
@@ -180,6 +194,8 @@ int v4l2_fwht_encode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out) flags |=FWHT_FL_CB_IS_UNCOMPRESSED ;if (encoding &FWHT_CR_UNENCODED ) flags |=FWHT_FL_CR_IS_UNCOMPRESSED ; +if (encoding &FWHT_ALPHA_UNENCODED ) + flags |=FWHT_FL_ALPHA_IS_UNCOMPRESSED ;if (rf.height_div ==1 ) flags |=FWHT_FL_CHROMA_FULL_HEIGHT ;if (rf.width_div ==1 )
@@ -356,6 +372,22 @@ int v4l2_fwht_decode(struct v4l2_fwht_state *state, u8 *p_in, u8 *p_out) *p++ =0 ; }break ; +case V4L2_PIX_FMT_ARGB32 : +for (i =0 , p = p_out; i < size; i++) { + *p++ = state->ref_frame.alpha[i]; + *p++ = state->ref_frame.cr[i]; + *p++ = state->ref_frame.luma[i]; + *p++ = state->ref_frame.cb[i]; + } +break ; +case V4L2_PIX_FMT_ABGR32 : +for (i =0 , p = p_out; i < size; i++) { + *p++ = state->ref_frame.cb[i]; + *p++ = state->ref_frame.luma[i]; + *p++ = state->ref_frame.cr[i]; + *p++ = state->ref_frame.alpha[i]; + } +break ;default :return -EINVAL ; }
drivers/media/platform/vicodec/vicodec-core.c +13 -1
@@ -995,7 +995,13 @@ static int vicodec_start_streaming(struct vb2_queue *q,unsigned int chroma_div = info->width_div * info->height_div;unsigned int total_planes_size; -if (info->components_num >=3 ) +/* +* we don't know ahead how many components are in the encoding type +* V4L2_PIX_FMT_FWHT, so we will allocate space for 4 planes. +*/ +if (info->id ==V4L2_PIX_FMT_FWHT || info->components_num ==4 ) + total_planes_size =2 * size +2 * (size / chroma_div); +else if (info->components_num ==3 ) total_planes_size = size +2 * (size / chroma_div);else total_planes_size = size;
@@ -1024,6 +1030,12 @@ static int vicodec_start_streaming(struct vb2_queue *q, state->ref_frame.cb =NULL ; state->ref_frame.cr =NULL ; } + +if (info->id ==V4L2_PIX_FMT_FWHT || info->components_num ==4 ) + state->ref_frame.alpha = state->ref_frame.cr + size / chroma_div; +else + state->ref_frame.alpha =NULL ; + ctx->last_src_buf =NULL ; ctx->last_dst_buf =NULL ; state->gop_cnt =0 ;
Signature · 1 line
2.7.4