History

avcodec/proresenc_kostya: Factor flushing PutBitContext out

The function to write an ordinary (luma or chroma) plane as well as the function for writing an alpha plane have some similarities: They record the initial bitposition (despite said position always being byte-aligned), flush the PutBitContext themselves and return the amount of bytes they wrote. This commit factors this out; it also replaces bitpositions by bytepositions and it avoids recording the initial byteposition because said information is already available from the position at the end of the last plane.

Andreas Rheinhardt committed 5 years ago

Commit f9d15281 parent df1c30f1 file · +13 −23Browse files

Unified · Split

libavcodec/proresenc_kostya.c+13−23
@@ -464,23 +464,17 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks, · 463 unmodified lines
464464 }
465465 }
466466
467−static int encode_slice_plane(ProresContext *ctx, PutBitContext *pb,
467+static void encode_slice_plane(ProresContext *ctx, PutBitContext *pb,
468468 const uint16_t *src, ptrdiff_t linesize,
469469 int mbs_per_slice, int16_t *blocks,
470470 int blocks_per_mb, int plane_size_factor,
471471 const int16_t *qmat)
472472 {
473− int blocks_per_slice, saved_pos;
474−
475− saved_pos = put_bits_count(pb);
476− blocks_per_slice = mbs_per_slice * blocks_per_mb;
473+ int blocks_per_slice = mbs_per_slice * blocks_per_mb;
477474
478475 encode_dcs(pb, blocks, blocks_per_slice, qmat[0]);
479476 encode_acs(pb, blocks, blocks_per_slice, plane_size_factor,
480477 ctx->scantable, qmat);
481− flush_put_bits(pb);
482−
483− return (put_bits_count(pb) - saved_pos) >> 3;
484478 }
485479
486480 static void put_alpha_diff(PutBitContext *pb, int cur, int prev, int abits)
@@ -516,14 +510,13 @@ static void put_alpha_run(PutBitContext *pb, int run) · 29 unmodified lines
516510 }
517511
518512 // todo alpha quantisation for high quants
519−static int encode_alpha_plane(ProresContext *ctx, PutBitContext *pb,
513+static void encode_alpha_plane(ProresContext *ctx, PutBitContext *pb,
520514 int mbs_per_slice, uint16_t *blocks,
521515 int quant)
522516 {
523517 const int abits = ctx->alpha_bits;
524518 const int mask = (1 << abits) - 1;
525519 const int num_coeffs = mbs_per_slice * 256;
526− int saved_pos = put_bits_count(pb);
527520 int prev = mask, cur;
528521 int idx = 0;
529522 int run = 0;
@@ -544,8 +537,6 @@ static int encode_alpha_plane(ProresContext *ctx, PutBitContext *pb, · 14 unmodified lines
544537 } while (idx < num_coeffs);
545538 if (run)
546539 put_alpha_run(pb, run);
547− flush_put_bits(pb);
548− return (put_bits_count(pb) - saved_pos) >> 3;
549540 }
550541
551542 static int encode_slice(AVCodecContext *avctx, const AVFrame *pic,
@@ -611,24 +602,23 @@ static int encode_slice(AVCodecContext *avctx, const AVFrame *pic, · 59 unmodified lines
611602 ctx->blocks[0], ctx->emu_buf,
612603 mbs_per_slice, num_cblocks, is_chroma);
613604 if (!is_chroma) {/* luma quant */
614− sizes[i] = encode_slice_plane(ctx, pb, src, linesize,
615− mbs_per_slice, ctx->blocks[0],
616− num_cblocks, plane_factor,
617− qmat);
605+ encode_slice_plane(ctx, pb, src, linesize,
606+ mbs_per_slice, ctx->blocks[0],
607+ num_cblocks, plane_factor, qmat);
618608 } else { /* chroma plane */
619− sizes[i] = encode_slice_plane(ctx, pb, src, linesize,
620− mbs_per_slice, ctx->blocks[0],
621− num_cblocks, plane_factor,
622− qmat_chroma);
609+ encode_slice_plane(ctx, pb, src, linesize,
610+ mbs_per_slice, ctx->blocks[0],
611+ num_cblocks, plane_factor, qmat_chroma);
623612 }
624613 } else {
625614 get_alpha_data(ctx, src, linesize, xp, yp,
626615 pwidth, avctx->height / ctx->pictures_per_frame,
627616 ctx->blocks[0], mbs_per_slice, ctx->alpha_bits);
628− sizes[i] = encode_alpha_plane(ctx, pb, mbs_per_slice,
629− ctx->blocks[0], quant);
617+ encode_alpha_plane(ctx, pb, mbs_per_slice, ctx->blocks[0], quant);
630618 }
631− total_size += sizes[i];
619+ flush_put_bits(pb);
620+ sizes[i] = put_bytes_output(pb) - total_size;
621+ total_size = put_bytes_output(pb);
632622 if (put_bits_left(pb) < 0) {
633623 av_log(avctx, AV_LOG_ERROR,
634624 "Underestimated required buffer size.\n");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t