svq3: stop using H264Context.gb

This commit is contained in:
Anton Khirnov 2016-03-23 13:16:32 +01:00
parent ea6ab02a17
commit 1848a154a4
1 changed files with 31 additions and 30 deletions

View File

@ -79,6 +79,7 @@ typedef struct SVQ3Context {
H264Picture *next_pic;
H264Picture *last_pic;
GetBitContext gb;
GetBitContext gb_slice;
uint8_t *slice_buf;
int slice_size;
int halfpel_flag;
@ -527,8 +528,8 @@ static inline int svq3_mc_dir(SVQ3Context *s, int size, int mode,
if (mode == PREDICT_MODE) {
dx = dy = 0;
} else {
dy = svq3_get_se_golomb(&h->gb);
dx = svq3_get_se_golomb(&h->gb);
dy = svq3_get_se_golomb(&s->gb_slice);
dx = svq3_get_se_golomb(&s->gb_slice);
if (dx == INVALID_VLC || dy == INVALID_VLC) {
av_log(h->avctx, AV_LOG_ERROR, "invalid MV vlc\n");
@ -736,10 +737,10 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
mb_type = MB_TYPE_16x16;
}
} else if (mb_type < 8) { /* INTER */
if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&h->gb))
if (s->thirdpel_flag && s->halfpel_flag == !get_bits1(&s->gb_slice))
mode = THIRDPEL_MODE;
else if (s->halfpel_flag &&
s->thirdpel_flag == !get_bits1(&h->gb))
s->thirdpel_flag == !get_bits1(&s->gb_slice))
mode = HALFPEL_MODE;
else
mode = FULLPEL_MODE;
@ -841,7 +842,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
/* decode prediction codes for luma blocks */
for (i = 0; i < 16; i += 2) {
vlc = svq3_get_ue_golomb(&h->gb);
vlc = svq3_get_ue_golomb(&s->gb_slice);
if (vlc >= 25) {
av_log(h->avctx, AV_LOG_ERROR,
@ -919,7 +920,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
if (!IS_INTRA16x16(mb_type) &&
(!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) {
if ((vlc = svq3_get_ue_golomb(&h->gb)) >= 48) {
if ((vlc = svq3_get_ue_golomb(&s->gb_slice)) >= 48) {
av_log(h->avctx, AV_LOG_ERROR, "cbp_vlc=%"PRIu32"\n", vlc);
return -1;
}
@ -929,7 +930,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
}
if (IS_INTRA16x16(mb_type) ||
(s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) {
s->qscale += svq3_get_se_golomb(&h->gb);
s->qscale += svq3_get_se_golomb(&s->gb_slice);
if (s->qscale > 31u) {
av_log(h->avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale);
@ -939,7 +940,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
if (IS_INTRA16x16(mb_type)) {
AV_ZERO128(s->mb_luma_dc[0] + 0);
AV_ZERO128(s->mb_luma_dc[0] + 8);
if (svq3_decode_block(&h->gb, s->mb_luma_dc[0], 0, 1)) {
if (svq3_decode_block(&s->gb_slice, s->mb_luma_dc[0], 0, 1)) {
av_log(h->avctx, AV_LOG_ERROR,
"error while decoding intra luma dc\n");
return -1;
@ -958,7 +959,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
: (4 * i + j);
s->non_zero_count_cache[scan8[k]] = 1;
if (svq3_decode_block(&h->gb, &s->mb[16 * k], index, type)) {
if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], index, type)) {
av_log(h->avctx, AV_LOG_ERROR,
"error while decoding block\n");
return -1;
@ -968,7 +969,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
if ((cbp & 0x30)) {
for (i = 1; i < 3; ++i)
if (svq3_decode_block(&h->gb, &s->mb[16 * 16 * i], 0, 3)) {
if (svq3_decode_block(&s->gb_slice, &s->mb[16 * 16 * i], 0, 3)) {
av_log(h->avctx, AV_LOG_ERROR,
"error while decoding chroma dc block\n");
return -1;
@ -980,7 +981,7 @@ static int svq3_decode_mb(SVQ3Context *s, unsigned int mb_type)
k = 16 * i + j;
s->non_zero_count_cache[scan8[k]] = 1;
if (svq3_decode_block(&h->gb, &s->mb[16 * k], 1, 1)) {
if (svq3_decode_block(&s->gb_slice, &s->mb[16 * k], 1, 1)) {
av_log(h->avctx, AV_LOG_ERROR,
"error while decoding chroma ac block\n");
return -1;
@ -1036,11 +1037,11 @@ static int svq3_decode_slice_header(AVCodecContext *avctx)
memcpy(s->slice_buf, s->gb.buffer + s->gb.index / 8, slice_bytes);
init_get_bits(&h->gb, s->slice_buf, slice_bits);
init_get_bits(&s->gb_slice, s->slice_buf, slice_bits);
if (s->watermark_key) {
uint32_t header = AV_RL32(&h->gb.buffer[1]);
AV_WL32(&h->gb.buffer[1], header ^ s->watermark_key);
uint32_t header = AV_RL32(&s->gb_slice.buffer[1]);
AV_WL32(&s->gb_slice.buffer[1], header ^ s->watermark_key);
}
if (length > 0) {
memcpy(s->slice_buf, &s->slice_buf[slice_length], length - 1);
@ -1048,7 +1049,7 @@ static int svq3_decode_slice_header(AVCodecContext *avctx)
skip_bits_long(&s->gb, slice_bytes * 8);
}
if ((slice_id = svq3_get_ue_golomb(&h->gb)) >= 3) {
if ((slice_id = svq3_get_ue_golomb(&s->gb_slice)) >= 3) {
av_log(h->avctx, AV_LOG_ERROR, "illegal slice type %u \n", slice_id);
return -1;
}
@ -1057,26 +1058,26 @@ static int svq3_decode_slice_header(AVCodecContext *avctx)
if ((header & 0x9F) == 2) {
i = (s->mb_num < 64) ? 6 : (1 + av_log2(s->mb_num - 1));
get_bits(&h->gb, i);
get_bits(&s->gb_slice, i);
} else {
skip_bits1(&h->gb);
skip_bits1(&s->gb_slice);
}
s->slice_num = get_bits(&h->gb, 8);
s->qscale = get_bits(&h->gb, 5);
s->adaptive_quant = get_bits1(&h->gb);
s->slice_num = get_bits(&s->gb_slice, 8);
s->qscale = get_bits(&s->gb_slice, 5);
s->adaptive_quant = get_bits1(&s->gb_slice);
/* unknown fields */
skip_bits1(&h->gb);
skip_bits1(&s->gb_slice);
if (s->unknown_flag)
skip_bits1(&h->gb);
skip_bits1(&s->gb_slice);
skip_bits1(&h->gb);
skip_bits(&h->gb, 2);
skip_bits1(&s->gb_slice);
skip_bits(&s->gb_slice, 2);
while (get_bits1(&h->gb))
skip_bits(&h->gb, 8);
while (get_bits1(&s->gb_slice))
skip_bits(&s->gb_slice, 8);
/* reset intra predictors and invalidate motion vector references */
if (s->mb_x > 0) {
@ -1508,9 +1509,9 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
unsigned mb_type;
s->mb_xy = s->mb_x + s->mb_y * s->mb_stride;
if ((get_bits_left(&h->gb)) <= 7) {
if (((get_bits_count(&h->gb) & 7) == 0 ||
show_bits(&h->gb, get_bits_left(&h->gb) & 7) == 0)) {
if ((get_bits_left(&s->gb_slice)) <= 7) {
if (((get_bits_count(&s->gb_slice) & 7) == 0 ||
show_bits(&s->gb_slice, get_bits_left(&s->gb_slice) & 7) == 0)) {
if (svq3_decode_slice_header(avctx))
return -1;
@ -1518,7 +1519,7 @@ static int svq3_decode_frame(AVCodecContext *avctx, void *data,
/* TODO: support s->mb_skip_run */
}
mb_type = svq3_get_ue_golomb(&h->gb);
mb_type = svq3_get_ue_golomb(&s->gb_slice);
if (s->pict_type == AV_PICTURE_TYPE_I)
mb_type += 8;