On 1/16/19 4:25 PM, Dafna Hirschfeld wrote: > If the the queues are not streaming then the first resolution > change is handled in the buf_queue callback. > The following resolution change events are handled in job_ready. > > Signed-off-by: Dafna Hirschfeld <dafna3@xxxxxxxxx> > --- > drivers/media/platform/vicodec/vicodec-core.c | 381 ++++++++++++++---- > 1 file changed, 304 insertions(+), 77 deletions(-) > <snip> > @@ -1087,73 +1296,80 @@ static int vicodec_start_streaming(struct vb2_queue *q, > struct vicodec_q_data *q_data = get_q_data(ctx, q->type); > struct v4l2_fwht_state *state = &ctx->state; > const struct v4l2_fwht_pixfmt_info *info = q_data->info; > - unsigned int size = q_data->coded_width * q_data->coded_height; > - unsigned int chroma_div = info->width_div * info->height_div; > - unsigned int total_planes_size; > > - /* > - * 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; > + if (!info) > + return -EINVAL; > > q_data->sequence = 0; > > - if (!V4L2_TYPE_IS_OUTPUT(q->type)) { > - if (!ctx->is_enc) { > - state->visible_width = q_data->visible_width; > - state->visible_height = q_data->visible_height; > - state->coded_width = q_data->coded_width; > - state->coded_height = q_data->coded_height; > - state->stride = q_data->coded_width * info->bytesperline_mult; > + ctx->last_src_buf = NULL; > + ctx->last_dst_buf = NULL; > + state->gop_cnt = 0; > + > + if ((!V4L2_TYPE_IS_OUTPUT(q->type) && !ctx->is_enc) || > + (V4L2_TYPE_IS_OUTPUT(q->type) && ctx->is_enc)) { You can simplify this by doing: if ((V4L2_TYPE_IS_OUTPUT(q->type) && !ctx->is_enc) || (!V4L2_TYPE_IS_OUTPUT(q->type) && ctx->is_enc)) return 0; And the remainder can be shifted one tab to the left. Regards, Hans > + unsigned int size = q_data->coded_width * q_data->coded_height; > + unsigned int chroma_div = info->width_div * info->height_div; > + unsigned int total_planes_size; > + u8 *new_comp_frame; > + > + if (!info || info->id == V4L2_PIX_FMT_FWHT) { > + vicodec_return_bufs(q, VB2_BUF_STATE_QUEUED); > + return -EINVAL; > } > - return 0; > - } > + if (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; > > - if (ctx->is_enc) { > state->visible_width = q_data->visible_width; > state->visible_height = q_data->visible_height; > state->coded_width = q_data->coded_width; > state->coded_height = q_data->coded_height; > state->stride = q_data->coded_width * info->bytesperline_mult; > - } > - state->ref_frame.luma = kvmalloc(total_planes_size, GFP_KERNEL); > - ctx->comp_max_size = total_planes_size; > - state->compressed_frame = kvmalloc(ctx->comp_max_size, GFP_KERNEL); > - if (!state->ref_frame.luma || !state->compressed_frame) { > - kvfree(state->ref_frame.luma); > - kvfree(state->compressed_frame); > - vicodec_return_bufs(q, VB2_BUF_STATE_QUEUED); > - return -ENOMEM; > - } > - 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; > - } > > - 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; > + state->ref_frame.luma = kvmalloc(total_planes_size, GFP_KERNEL); > + ctx->comp_max_size = total_planes_size; > + new_comp_frame = kvmalloc(ctx->comp_max_size, GFP_KERNEL); > > - ctx->last_src_buf = NULL; > - ctx->last_dst_buf = NULL; > - state->gop_cnt = 0; > - ctx->cur_buf_offset = 0; > - ctx->comp_size = 0; > - ctx->header_size = 0; > - ctx->comp_magic_cnt = 0; > - ctx->comp_has_frame = false; > + if (!state->ref_frame.luma || !new_comp_frame) { > + kvfree(state->ref_frame.luma); > + kvfree(new_comp_frame); > + vicodec_return_bufs(q, VB2_BUF_STATE_QUEUED); > + return -ENOMEM; > + } > + /* > + * if state->compressed_frame was already allocated then > + * it contain data of the first frame of the new resolution > + */ > + if (state->compressed_frame) { > + if (ctx->comp_size > ctx->comp_max_size) { > + ctx->comp_size = ctx->comp_max_size; > + ctx->comp_frame_size = ctx->comp_max_size; > + } > + memcpy(new_comp_frame, > + state->compressed_frame, ctx->comp_size); > + } > + > + kvfree(state->compressed_frame); > + state->compressed_frame = new_comp_frame; > + > + if (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; > + } > > + if (info->components_num == 4) > + state->ref_frame.alpha = > + state->ref_frame.cr + size / chroma_div; > + else > + state->ref_frame.alpha = NULL; > + } > return 0; > } > > @@ -1163,11 +1379,21 @@ static void vicodec_stop_streaming(struct vb2_queue *q) > > vicodec_return_bufs(q, VB2_BUF_STATE_ERROR); > > - if (!V4L2_TYPE_IS_OUTPUT(q->type)) > - return; > - > - kvfree(ctx->state.ref_frame.luma); > - kvfree(ctx->state.compressed_frame); > + if ((!V4L2_TYPE_IS_OUTPUT(q->type) && !ctx->is_enc) || > + (V4L2_TYPE_IS_OUTPUT(q->type) && ctx->is_enc)) { > + kvfree(ctx->state.ref_frame.luma); > + ctx->source_changed = false; > + } > + if (V4L2_TYPE_IS_OUTPUT(q->type) && !ctx->is_enc) { > + ctx->cur_buf_offset = 0; > + ctx->comp_max_size = 0; > + ctx->comp_size = 0; > + ctx->header_size = 0; > + ctx->comp_magic_cnt = 0; > + ctx->comp_frame_size = 0; > + ctx->comp_has_frame = 0; > + ctx->comp_has_next_frame = 0; > + } > } > > static const struct vb2_ops vicodec_qops = { > @@ -1319,16 +1545,17 @@ static int vicodec_open(struct file *file) > else > ctx->q_data[V4L2_M2M_SRC].sizeimage = > size + sizeof(struct fwht_cframe_hdr); > - ctx->q_data[V4L2_M2M_DST] = ctx->q_data[V4L2_M2M_SRC]; > - ctx->q_data[V4L2_M2M_DST].info = > - ctx->is_enc ? &pixfmt_fwht : v4l2_fwht_get_pixfmt(0); > - size = 1280 * 720 * ctx->q_data[V4L2_M2M_DST].info->sizeimage_mult / > - ctx->q_data[V4L2_M2M_DST].info->sizeimage_div; > - if (ctx->is_enc) > - ctx->q_data[V4L2_M2M_DST].sizeimage = > - size + sizeof(struct fwht_cframe_hdr); > - else > - ctx->q_data[V4L2_M2M_DST].sizeimage = size; > + if (ctx->is_enc) { > + ctx->q_data[V4L2_M2M_DST] = ctx->q_data[V4L2_M2M_SRC]; > + ctx->q_data[V4L2_M2M_DST].info = &pixfmt_fwht; > + ctx->q_data[V4L2_M2M_DST].sizeimage = 1280 * 720 * > + ctx->q_data[V4L2_M2M_DST].info->sizeimage_mult / > + ctx->q_data[V4L2_M2M_DST].info->sizeimage_div + > + sizeof(struct fwht_cframe_hdr); > + } else { > + ctx->q_data[V4L2_M2M_DST].info = NULL; > + } > + > ctx->state.colorspace = V4L2_COLORSPACE_REC709; > > if (ctx->is_enc) { >