Commit 14b41e06 authored by Rostislav Pehlivanov's avatar Rostislav Pehlivanov

vc2enc: macro out slice size rounding

Signed-off-by: 's avatarRostislav Pehlivanov <atomnuker@gmail.com>
parent 8dbffda0
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
* (COEF_LUT_TAB*MAX_QUANT_INDEX) since the sign is appended during encoding */ * (COEF_LUT_TAB*MAX_QUANT_INDEX) since the sign is appended during encoding */
#define COEF_LUT_TAB 2048 #define COEF_LUT_TAB 2048
/* The limited size resolution of each slice forces us to do this */
#define SSIZE_ROUND(b) (FFALIGN((b), s->size_scaler) + 4 + s->prefix_bytes)
/* Decides the cutoff point in # of slices to distribute the leftover bytes */ /* Decides the cutoff point in # of slices to distribute the leftover bytes */
#define SLICE_REDIST_TOTAL 150 #define SLICE_REDIST_TOTAL 150
...@@ -688,7 +691,7 @@ static int rate_control(AVCodecContext *avctx, void *arg) ...@@ -688,7 +691,7 @@ static int rate_control(AVCodecContext *avctx, void *arg)
bits_last = bits; bits_last = bits;
} }
slice_dat->quant_idx = av_clip(quant, 0, s->q_ceil-1); slice_dat->quant_idx = av_clip(quant, 0, s->q_ceil-1);
slice_dat->bytes = FFALIGN((bits >> 3), s->size_scaler) + 4 + s->prefix_bytes; slice_dat->bytes = SSIZE_ROUND(bits >> 3);
slice_dat->bytes_left = s->slice_max_bytes - slice_dat->bytes; slice_dat->bytes_left = s->slice_max_bytes - slice_dat->bytes;
return 0; return 0;
} }
...@@ -748,7 +751,7 @@ static int calc_slice_sizes(VC2EncContext *s) ...@@ -748,7 +751,7 @@ static int calc_slice_sizes(VC2EncContext *s)
prev_bytes = args->bytes; prev_bytes = args->bytes;
new_idx = FFMAX(args->quant_idx - 1, 0); new_idx = FFMAX(args->quant_idx - 1, 0);
bits = count_hq_slice(args, new_idx); bits = count_hq_slice(args, new_idx);
bytes = FFALIGN((bits >> 3), s->size_scaler) + 4 + s->prefix_bytes; bytes = SSIZE_ROUND(bits >> 3);
diff = bytes - prev_bytes; diff = bytes - prev_bytes;
if ((bytes_left - diff) > 0) { if ((bytes_left - diff) > 0) {
args->quant_idx = new_idx; args->quant_idx = new_idx;
...@@ -1016,16 +1019,16 @@ static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ...@@ -1016,16 +1019,16 @@ static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
/* Rate control */ /* Rate control */
max_frame_bytes = (av_rescale(r_bitrate, s->avctx->time_base.num, max_frame_bytes = (av_rescale(r_bitrate, s->avctx->time_base.num,
s->avctx->time_base.den) >> 3) - header_size; s->avctx->time_base.den) >> 3) - header_size;
s->slice_max_bytes = av_rescale(max_frame_bytes, 1, s->num_x*s->num_y);
/* Find an appropriate size scaler */ /* Find an appropriate size scaler */
while (sig_size > 255) { while (sig_size > 255) {
s->slice_max_bytes = FFALIGN(av_rescale(max_frame_bytes, 1, int r_size = SSIZE_ROUND(s->slice_max_bytes);
s->num_x*s->num_y), s->size_scaler); sig_size = r_size/s->size_scaler; /* Signalled slize size */
s->slice_max_bytes += 4 + s->prefix_bytes;
sig_size = s->slice_max_bytes/s->size_scaler; /* Signalled slize size */
s->size_scaler <<= 1; s->size_scaler <<= 1;
} }
s->slice_max_bytes = SSIZE_ROUND(s->slice_max_bytes);
s->slice_min_bytes = s->slice_max_bytes - s->slice_max_bytes*(s->tolerance/100.0f); s->slice_min_bytes = s->slice_max_bytes - s->slice_max_bytes*(s->tolerance/100.0f);
ret = encode_frame(s, avpkt, frame, aux_data, header_size, s->interlaced); ret = encode_frame(s, avpkt, frame, aux_data, header_size, s->interlaced);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment