On Mon, Aug 13, 2012 at 10:13:38PM +0200, Luca Barbato wrote:
> From: Maksalov Boris <[email protected]>
> 
> Signed-off-by: Luca Barbato <[email protected]>
> ---
> Small cleanup over Kostya's
> 
>  libavcodec/proresenc.c |  177 
> ++++++++++++++++++++++++++++++------------------
>  1 files changed, 111 insertions(+), 66 deletions(-)
> 
> diff --git a/libavcodec/proresenc.c b/libavcodec/proresenc.c
> index 40644bb..460cc8a 100644
> --- a/libavcodec/proresenc.c
> +++ b/libavcodec/proresenc.c
> @@ -188,7 +188,9 @@ typedef struct ProresContext {
>      int mbs_per_slice;
>      int num_chroma_blocks, chroma_factor;
>      int slices_width;
> -    int num_slices;
> +    int slices_per_picture;
> +    int pictures_per_frame; // 1 for progressive, 2 for interlaced
> +    int cur_picture_idx;
>      int num_planes;
>      int bits_per_mb;
>      int force_quant;
> @@ -196,7 +198,7 @@ typedef struct ProresContext {
>      char *vendor;
>      int quant_sel;
>  
> -    int frame_size;
> +    int frame_size_upper_bound;
>  
>      int profile;
>      const struct prores_profile *profile_info;
> @@ -402,10 +404,15 @@ static int encode_slice(AVCodecContext *avctx, const 
> AVFrame *pic,
>      int total_size = 0;
>      const uint16_t *src;
>      int slice_width_factor = av_log2(mbs_per_slice);
> -    int num_cblocks, pwidth;
> +    int num_cblocks, pwidth, linesize, line_add;
>      int plane_factor, is_chroma;
>      uint16_t *qmat;
>  
> +    if (ctx->pictures_per_frame == 1)
> +        line_add = 0;
> +    else
> +        line_add = ctx->cur_picture_idx ^ !pic->top_field_first;
> +
>      if (ctx->force_quant) {
>          qmat = ctx->quants[0];
>      } else if (quant < MAX_STORED_Q) {
> @@ -432,12 +439,15 @@ static int encode_slice(AVCodecContext *avctx, const 
> AVFrame *pic,
>              num_cblocks = 2;
>              pwidth      = avctx->width >> 1;
>          }
> -        src = (const uint16_t*)(pic->data[i] + yp * pic->linesize[i]) + xp;
>  
> -        get_slice_data(ctx, src, pic->linesize[i], xp, yp,
> +        linesize = pic->linesize[i] * ctx->pictures_per_frame;
> +        src = (const uint16_t*)(pic->data[i] + yp * linesize +
> +                                line_add * pic->linesize[i]) + xp;
> +
> +        get_slice_data(ctx, src, linesize, xp, yp,
>                         pwidth, avctx->height, ctx->blocks[0], ctx->emu_buf,
>                         mbs_per_slice, num_cblocks, is_chroma);
> -        sizes[i] = encode_slice_plane(ctx, pb, src, pic->linesize[i],
> +        sizes[i] = encode_slice_plane(ctx, pb, src, linesize,
>                                        mbs_per_slice, ctx->blocks[0],
>                                        num_cblocks, plane_factor,
>                                        qmat);
> @@ -570,7 +580,12 @@ static int find_slice_quant(AVCodecContext *avctx, const 
> AVFrame *pic,
>      int slice_bits[TRELLIS_WIDTH], slice_score[TRELLIS_WIDTH];
>      int overquant;
>      uint16_t *qmat;
> +    int linesize[4], line_add;
>  
> +    if (ctx->pictures_per_frame == 1)
> +        line_add = 0;
> +    else
> +        line_add = ctx->cur_picture_idx ^ !pic->top_field_first;
>      mbs = x + mbs_per_slice;
>  
>      for (i = 0; i < ctx->num_planes; i++) {
> @@ -589,9 +604,12 @@ static int find_slice_quant(AVCodecContext *avctx, const 
> AVFrame *pic,
>              num_cblocks[i] = 2;
>              pwidth         = avctx->width >> 1;
>          }
> -        src = (const uint16_t*)(pic->data[i] + yp * pic->linesize[i]) + xp;
>  
> -        get_slice_data(ctx, src, pic->linesize[i], xp, yp,
> +        linesize[i] = pic->linesize[i] * ctx->pictures_per_frame;
> +        src = (const uint16_t*)(pic->data[i] + yp * linesize[i] +
> +                                line_add * pic->linesize[i]) + xp;
> +
> +        get_slice_data(ctx, src, linesize[i], xp, yp,
>                         pwidth, avctx->height, td->blocks[i], td->emu_buf,

Here (and in the next call to get_slice_data()) argument should be
avctx->height / ctx->pictures_per_frame, otherwise it would read garbage on
non-multiple-of-32 heights in interlaced mode (this was pointed by the patch
author). Otherwise LGTM.
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to