summaryrefslogtreecommitdiff
path: root/libavcodec/vc2enc.c
diff options
context:
space:
mode:
authorRostislav Pehlivanov <atomnuker@gmail.com>2016-03-23 17:46:23 +0000
committerRostislav Pehlivanov <atomnuker@gmail.com>2016-03-23 17:52:53 +0000
commit14b41e061db641150bee90e476bf86731be89a6e (patch)
tree1a2a493337408a337fedd6a77992c961e3fe870b /libavcodec/vc2enc.c
parent8dbffda0f9401644467111c85090fa0e8091e08a (diff)
vc2enc: macro out slice size rounding
Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
Diffstat (limited to 'libavcodec/vc2enc.c')
-rw-r--r--libavcodec/vc2enc.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
index 209413f1e4..3f65424e35 100644
--- a/libavcodec/vc2enc.c
+++ b/libavcodec/vc2enc.c
@@ -36,6 +36,9 @@
* (COEF_LUT_TAB*MAX_QUANT_INDEX) since the sign is appended during encoding */
#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 */
#define SLICE_REDIST_TOTAL 150
@@ -688,7 +691,7 @@ static int rate_control(AVCodecContext *avctx, void *arg)
bits_last = bits;
}
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;
return 0;
}
@@ -748,7 +751,7 @@ static int calc_slice_sizes(VC2EncContext *s)
prev_bytes = args->bytes;
new_idx = FFMAX(args->quant_idx - 1, 0);
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;
if ((bytes_left - diff) > 0) {
args->quant_idx = new_idx;
@@ -1016,16 +1019,16 @@ static av_cold int vc2_encode_frame(AVCodecContext *avctx, AVPacket *avpkt,
/* Rate control */
max_frame_bytes = (av_rescale(r_bitrate, s->avctx->time_base.num,
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 */
while (sig_size > 255) {
- s->slice_max_bytes = FFALIGN(av_rescale(max_frame_bytes, 1,
- s->num_x*s->num_y), s->size_scaler);
- s->slice_max_bytes += 4 + s->prefix_bytes;
- sig_size = s->slice_max_bytes/s->size_scaler; /* Signalled slize size */
+ int r_size = SSIZE_ROUND(s->slice_max_bytes);
+ sig_size = r_size/s->size_scaler; /* Signalled slize size */
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);
ret = encode_frame(s, avpkt, frame, aux_data, header_size, s->interlaced);