wavpack: cosmetics: K&R pretty-printing

This commit is contained in:
Justin Ruggles
2012-01-02 00:14:16 -05:00
parent c88d53199b
commit 513c238fa9

View File

@@ -18,11 +18,13 @@
* License along with Libav; if not, write to the Free Software * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define BITSTREAM_READER_LE #define BITSTREAM_READER_LE
#include "libavutil/audioconvert.h"
#include "avcodec.h" #include "avcodec.h"
#include "get_bits.h" #include "get_bits.h"
#include "unary.h" #include "unary.h"
#include "libavutil/audioconvert.h"
/** /**
* @file * @file
@@ -217,10 +219,12 @@ static av_always_inline int wp_log2(int32_t val)
if (samples && in) { \ if (samples && in) { \
if ((samples ^ in) < 0) { \ if ((samples ^ in) < 0) { \
weight -= delta; \ weight -= delta; \
if(weight < -1024) weight = -1024; \ if (weight < -1024) \
weight = -1024; \
} else { \ } else { \
weight += delta; \ weight += delta; \
if(weight > 1024) weight = 1024; \ if (weight > 1024) \
weight = 1024; \
} \ } \
} }
@@ -229,13 +233,13 @@ static av_always_inline int get_tail(GetBitContext *gb, int k)
{ {
int p, e, res; int p, e, res;
if(k<1)return 0; if (k < 1)
return 0;
p = av_log2(k); p = av_log2(k);
e = (1 << (p + 1)) - k - 1; e = (1 << (p + 1)) - k - 1;
res = p ? get_bits(gb, p) : 0; res = p ? get_bits(gb, p) : 0;
if(res >= e){ if (res >= e)
res = (res << 1) - e + get_bits1(gb); res = (res << 1) - e + get_bits1(gb);
}
return res; return res;
} }
@@ -273,7 +277,8 @@ static void update_error_limit(WavpackFrameContext *ctx)
} }
} }
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last) static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb,
int channel, int *last)
{ {
int t, t2; int t, t2;
int sign, base, add, ret; int sign, base, add, ret;
@@ -281,7 +286,8 @@ static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel
*last = 0; *last = 0;
if((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) && !ctx->zero && !ctx->one){ if ((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) &&
!ctx->zero && !ctx->one) {
if (ctx->zeroes) { if (ctx->zeroes) {
ctx->zeroes--; ctx->zeroes--;
if (ctx->zeroes) { if (ctx->zeroes) {
@@ -391,7 +397,8 @@ error:
return 0; return 0;
} }
static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, int S) static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc,
int S)
{ {
int bit; int bit;
@@ -437,26 +444,26 @@ static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
if (sign) if (sign)
S = -S; S = -S;
if (S >= 0x1000000) { if (S >= 0x1000000) {
if(s->got_extra_bits && get_bits1(&s->gb_extra_bits)){ if (s->got_extra_bits && get_bits1(&s->gb_extra_bits))
S = get_bits(&s->gb_extra_bits, 23); S = get_bits(&s->gb_extra_bits, 23);
}else{ else
S = 0; S = 0;
}
exp = 255; exp = 255;
} else if (exp) { } else if (exp) {
int shift = 23 - av_log2(S); int shift = 23 - av_log2(S);
exp = s->float_max_exp; exp = s->float_max_exp;
if(exp <= shift){ if (exp <= shift)
shift = --exp; shift = --exp;
}
exp -= shift; exp -= shift;
if (shift) { if (shift) {
S <<= shift; S <<= shift;
if ((s->float_flag & WV_FLT_SHIFT_ONES) || if ((s->float_flag & WV_FLT_SHIFT_ONES) ||
(s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SAME) && get_bits1(&s->gb_extra_bits)) ){ (s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SAME) &&
get_bits1(&s->gb_extra_bits))) {
S |= (1 << shift) - 1; S |= (1 << shift) - 1;
} else if(s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SENT)){ } else if (s->got_extra_bits &&
(s->float_flag & WV_FLT_SHIFT_SENT)) {
S |= get_bits(&s->gb_extra_bits, shift); S |= get_bits(&s->gb_extra_bits, shift);
} }
} }
@@ -492,7 +499,8 @@ static void wv_reset_saved_context(WavpackFrameContext *s)
s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF; s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF;
} }
static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type) static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb,
void *dst, const int type)
{ {
int i, j, count = 0; int i, j, count = 0;
int last, t; int last, t;
@@ -508,9 +516,11 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo
s->one = s->zero = s->zeroes = 0; s->one = s->zero = s->zeroes = 0;
do { do {
L = wv_get_value(s, gb, 0, &last); L = wv_get_value(s, gb, 0, &last);
if(last) break; if (last)
break;
R = wv_get_value(s, gb, 1, &last); R = wv_get_value(s, gb, 1, &last);
if(last) break; if (last)
break;
for (i = 0; i < s->terms; i++) { for (i = 0; i < s->terms; i++) {
t = s->decorr[i].value; t = s->decorr[i].value;
if (t > 0) { if (t > 0) {
@@ -611,7 +621,8 @@ static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, vo
return count * 2; return count * 2;
} }
static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type) static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb,
void *dst, const int type)
{ {
int i, j, count = 0; int i, j, count = 0;
int last, t; int last, t;
@@ -628,7 +639,8 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void
do { do {
T = wv_get_value(s, gb, 0, &last); T = wv_get_value(s, gb, 0, &last);
S = 0; S = 0;
if(last) break; if (last)
break;
for (i = 0; i < s->terms; i++) { for (i = 0; i < s->terms; i++) {
t = s->decorr[i].value; t = s->decorr[i].value;
if (t > 8) { if (t > 8) {
@@ -646,7 +658,8 @@ static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void
S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10); S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
else else
S = T + ((s->decorr[i].weightA * A + 512) >> 10); S = T + ((s->decorr[i].weightA * A + 512) >> 10);
if(A && T) s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta; if (A && T)
s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
s->decorr[i].samplesA[j] = T = S; s->decorr[i].samplesA[j] = T = S;
} }
pos = (pos + 1) & 7; pos = (pos + 1) & 7;
@@ -704,7 +717,8 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx)
else else
avctx->sample_fmt = AV_SAMPLE_FMT_S32; avctx->sample_fmt = AV_SAMPLE_FMT_S32;
if (avctx->channels <= 2 && !avctx->channel_layout) if (avctx->channels <= 2 && !avctx->channel_layout)
avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO :
AV_CH_LAYOUT_MONO;
s->multichannel = avctx->channels > 2; s->multichannel = avctx->channels > 2;
/* lavf demuxer does not provide extradata, Matroska stores 0x403 /* lavf demuxer does not provide extradata, Matroska stores 0x403
@@ -744,8 +758,8 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
WavpackFrameContext *s; WavpackFrameContext *s;
void *samples = data; void *samples = data;
int samplecount; int samplecount;
int got_terms = 0, got_weights = 0, got_samples = 0, got_entropy = 0, got_bs = 0, got_float = 0; int got_terms = 0, got_weights = 0, got_samples = 0,
int got_hybrid = 0; got_entropy = 0, got_bs = 0, got_float = 0; got_hybrid = 0;
const uint8_t *orig_buf = buf; const uint8_t *orig_buf = buf;
const uint8_t *buf_end = buf + buf_size; const uint8_t *buf_end = buf + buf_size;
int i, j, id, size, ssize, weights, t; int i, j, id, size, ssize, weights, t;
@@ -792,7 +806,8 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
s->hybrid = s->frame_flags & WV_HYBRID_MODE; s->hybrid = s->frame_flags & WV_HYBRID_MODE;
s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE; s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
s->hybrid_maxclip = (1LL << ((((s->frame_flags & 0x03) + 1) << 3) - 1)) - 1; s->hybrid_maxclip = (1LL << ((((s->frame_flags & 0x03) + 1) << 3) - 1)) - 1;
s->post_shift = 8 * (bpp-1-(s->frame_flags&0x03)) + ((s->frame_flags >> 13) & 0x1f); s->post_shift = 8 * (bpp - 1 - (s->frame_flags & 0x03)) +
((s->frame_flags >> 13) & 0x1f);
s->CRC = AV_RL32(buf); buf += 4; s->CRC = AV_RL32(buf); buf += 4;
if (wc->mkv_mode) if (wc->mkv_mode)
buf += 4; //skip block size; buf += 4; //skip block size;
@@ -809,7 +824,8 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
} }
size <<= 1; // size is specified in words size <<= 1; // size is specified in words
ssize = size; ssize = size;
if(id & WP_IDF_ODD) size--; if (id & WP_IDF_ODD)
size--;
if (size < 0) { if (size < 0) {
av_log(avctx, AV_LOG_ERROR, "Got incorrect block %02X with size %i\n", id, size); av_log(avctx, AV_LOG_ERROR, "Got incorrect block %02X with size %i\n", id, size);
break; break;
@@ -853,12 +869,14 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
t = (int8_t)(*buf++); t = (int8_t)(*buf++);
s->decorr[s->terms - i - 1].weightA = t << 3; s->decorr[s->terms - i - 1].weightA = t << 3;
if (s->decorr[s->terms - i - 1].weightA > 0) if (s->decorr[s->terms - i - 1].weightA > 0)
s->decorr[s->terms - i - 1].weightA += (s->decorr[s->terms - i - 1].weightA + 64) >> 7; s->decorr[s->terms - i - 1].weightA +=
(s->decorr[s->terms - i - 1].weightA + 64) >> 7;
if (s->stereo_in) { if (s->stereo_in) {
t = (int8_t)(*buf++); t = (int8_t)(*buf++);
s->decorr[s->terms - i - 1].weightB = t << 3; s->decorr[s->terms - i - 1].weightB = t << 3;
if (s->decorr[s->terms - i - 1].weightB > 0) if (s->decorr[s->terms - i - 1].weightB > 0)
s->decorr[s->terms - i - 1].weightB += (s->decorr[s->terms - i - 1].weightB + 64) >> 7; s->decorr[s->terms - i - 1].weightB +=
(s->decorr[s->terms - i - 1].weightB + 64) >> 7;
} }
} }
got_weights = 1; got_weights = 1;
@@ -869,7 +887,7 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
continue; continue;
} }
t = 0; t = 0;
for(i = s->terms - 1; (i >= 0) && (t < size); i--) { for i = s->terms - 1; (i >= 0) && (t < size); i--) {
if (s->decorr[i].value > 8) { if (s->decorr[i].value > 8) {
s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2; s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2;
s->decorr[i].samplesA[1] = wp_exp2(AV_RL16(buf)); buf += 2; s->decorr[i].samplesA[1] = wp_exp2(AV_RL16(buf)); buf += 2;
@@ -886,10 +904,9 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
} else { } else {
for (j = 0; j < s->decorr[i].value; j++) { for (j = 0; j < s->decorr[i].value; j++) {
s->decorr[i].samplesA[j] = wp_exp2(AV_RL16(buf)); buf += 2; s->decorr[i].samplesA[j] = wp_exp2(AV_RL16(buf)); buf += 2;
if(s->stereo_in){ if (s->stereo_in)
s->decorr[i].samplesB[j] = wp_exp2(AV_RL16(buf)); buf += 2; s->decorr[i].samplesB[j] = wp_exp2(AV_RL16(buf)); buf += 2;
} }
}
t += s->decorr[i].value * 2 * (s->stereo_in + 1); t += s->decorr[i].value * 2 * (s->stereo_in + 1);
} }
} }
@@ -897,7 +914,8 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
break; break;
case WP_ID_ENTROPY: case WP_ID_ENTROPY:
if (size != 6 * (s->stereo_in + 1)) { if (size != 6 * (s->stereo_in + 1)) {
av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, got %i", 6 * (s->stereo_in + 1), size); av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, "
"got %i", 6 * (s->stereo_in + 1), size);
buf += ssize; buf += ssize;
continue; continue;
} }
@@ -974,7 +992,8 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
break; break;
case WP_ID_EXTRABITS: case WP_ID_EXTRABITS:
if (size <= 4) { if (size <= 4) {
av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n", size); av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n",
size);
buf += size; buf += size;
continue; continue;
} }
@@ -992,30 +1011,24 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
} }
chan = *buf++; chan = *buf++;
switch (size - 2) { switch (size - 2) {
case 0: case 0: chmask = *buf; break;
chmask = *buf; case 1: chmask = AV_RL16(buf); break;
break; case 2: chmask = AV_RL24(buf); break;
case 1: case 3: chmask = AV_RL32(buf); break;
chmask = AV_RL16(buf);
break;
case 2:
chmask = AV_RL24(buf);
break;
case 3:
chmask = AV_RL32(buf);
break;
case 5: case 5:
chan |= (buf[1] & 0xF) << 8; chan |= (buf[1] & 0xF) << 8;
chmask = AV_RL24(buf + 2); chmask = AV_RL24(buf + 2);
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n", size); av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
size);
chan = avctx->channels; chan = avctx->channels;
chmask = avctx->channel_layout; chmask = avctx->channel_layout;
} }
if (chan != avctx->channels) { if (chan != avctx->channels) {
av_log(avctx, AV_LOG_ERROR, "Block reports total %d channels, decoder believes it's %d channels\n", av_log(avctx, AV_LOG_ERROR, "Block reports total %d channels, "
chan, avctx->channels); "decoder believes it's %d channels\n", chan,
avctx->channels);
return -1; return -1;
} }
if (!avctx->channel_layout) if (!avctx->channel_layout)
@@ -1025,7 +1038,8 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
default: default:
buf += size; buf += size;
} }
if(id & WP_IDF_ODD) buf++; if (id & WP_IDF_ODD)
buf++;
} }
if (!got_terms) { if (!got_terms) {
@@ -1193,13 +1207,14 @@ static int wavpack_decode_frame(AVCodecContext *avctx, void *data,
} }
} }
if (frame_size < 0 || frame_size > buf_size) { if (frame_size < 0 || frame_size > buf_size) {
av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d vs. %d bytes left)\n", av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d "
s->block, frame_size, buf_size); "vs. %d bytes left)\n", s->block, frame_size, buf_size);
wavpack_decode_flush(avctx); wavpack_decode_flush(avctx);
return -1; return -1;
} }
if((samplecount = wavpack_decode_block(avctx, s->block, s->frame.data[0], if ((samplecount = wavpack_decode_block(avctx, s->block,
got_frame_ptr, buf, frame_size)) < 0) { s->frame.data[0], got_frame_ptr,
buf, frame_size)) < 0) {
wavpack_decode_flush(avctx); wavpack_decode_flush(avctx);
return -1; return -1;
} }