Commit 872ff063 authored by faust3's avatar faust3

Simplify run level decoding:

- remove unneeded vlc code < 0 check
- reorder vlc code handling so that the unlikely escape decoding
  part comes last
- move overflow check out of the decode loop
- branchless sign conversion


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@19234 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent c0227ef6
...@@ -470,23 +470,24 @@ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb, ...@@ -470,23 +470,24 @@ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
int num_coefs, int block_len, int frame_len_bits, int num_coefs, int block_len, int frame_len_bits,
int coef_nb_bits) int coef_nb_bits)
{ {
int code, run, level, sign; int code, level, sign;
WMACoef* eptr = ptr + num_coefs; const unsigned int coef_mask = block_len - 1;
ptr += offset; for (; offset < num_coefs; offset++) {
for(;;) {
code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX); code = get_vlc2(gb, vlc->table, VLCBITS, VLCMAX);
if (code < 0) if (code > 1) {
return -1; /** normal code */
if (code == 1) { offset += run_table[code];
level = level_table[code];
} else if (code == 1) {
/* EOB */ /* EOB */
break; break;
} else if (code == 0) { } else {
/* escape */ /* escape */
if (!version) { if (!version) {
level = get_bits(gb, coef_nb_bits); level = get_bits(gb, coef_nb_bits);
/* NOTE: this is rather suboptimal. reading /* NOTE: this is rather suboptimal. reading
block_len_bits would be better */ block_len_bits would be better */
run = get_bits(gb, frame_len_bits); offset += get_bits(gb, frame_len_bits);
} else { } else {
level = ff_wma_get_large_val(gb); level = ff_wma_get_large_val(gb);
/** escape decode */ /** escape decode */
...@@ -497,31 +498,21 @@ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb, ...@@ -497,31 +498,21 @@ int ff_wma_run_level_decode(AVCodecContext* avctx, GetBitContext* gb,
"broken escape sequence\n"); "broken escape sequence\n");
return -1; return -1;
} else } else
run = get_bits(gb, frame_len_bits) + 4; offset += get_bits(gb, frame_len_bits) + 4;
} else } else
run = get_bits(gb, 2) + 1; offset += get_bits(gb, 2) + 1;
} else }
run = 0;
} }
} else {
/* normal code */
run = run_table[code];
level = level_table[code];
}
sign = get_bits1(gb);
if (!sign)
level = -level;
ptr += run;
if (ptr >= eptr)
{
av_log(NULL, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
break;
} }
*ptr++ = level; sign = get_bits1(gb) - 1;
/* NOTE: EOB can be omitted */ ptr[offset & coef_mask] = (level^sign) - sign;
if (ptr >= eptr)
break;
} }
/** NOTE: EOB can be omitted */
if (offset > num_coefs) {
av_log(avctx, AV_LOG_ERROR, "overflow in spectral RLE, ignoring\n");
return -1;
}
return 0; return 0;
} }
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