flacdec: cosmetics: use consistent coding style (K&R)

Originally committed as revision 16761 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Justin Ruggles 16 years ago
parent 62560865ff
commit 1bec121f9e
  1. 105
      libavcodec/flacdec.c

@ -89,7 +89,8 @@ static const int blocksize_table[] = {
256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7 256<<0, 256<<1, 256<<2, 256<<3, 256<<4, 256<<5, 256<<6, 256<<7
}; };
static int64_t get_utf8(GetBitContext *gb){ static int64_t get_utf8(GetBitContext *gb)
{
int64_t val; int64_t val;
GET_UTF8(val, get_bits(gb, 8), return -1;) GET_UTF8(val, get_bits(gb, 8), return -1;)
return val; return val;
@ -127,7 +128,8 @@ static void dump_headers(AVCodecContext *avctx, FLACStreaminfo *s)
av_log(avctx, AV_LOG_DEBUG, " Bits: %d\n", s->bps); av_log(avctx, AV_LOG_DEBUG, " Bits: %d\n", s->bps);
} }
static void allocate_buffers(FLACContext *s){ static void allocate_buffers(FLACContext *s)
{
int i; int i;
assert(s->max_blocksize); assert(s->max_blocksize);
@ -136,8 +138,7 @@ static void allocate_buffers(FLACContext *s){
s->max_framesize= (s->channels * s->bps * s->max_blocksize + 7)/ 8; //FIXME header overhead s->max_framesize= (s->channels * s->bps * s->max_blocksize + 7)/ 8; //FIXME header overhead
} }
for (i = 0; i < s->channels; i++) for (i = 0; i < s->channels; i++) {
{
s->decoded[i] = av_realloc(s->decoded[i], sizeof(int32_t)*s->max_blocksize); s->decoded[i] = av_realloc(s->decoded[i], sizeof(int32_t)*s->max_blocksize);
} }
@ -239,17 +240,13 @@ static int decode_residuals(FLACContext *s, int channel, int pred_order)
sample= sample=
i= pred_order; i= pred_order;
for (partition = 0; partition < (1 << rice_order); partition++) for (partition = 0; partition < (1 << rice_order); partition++) {
{
tmp = get_bits(&s->gb, method_type == 0 ? 4 : 5); tmp = get_bits(&s->gb, method_type == 0 ? 4 : 5);
if (tmp == (method_type == 0 ? 15 : 31)) if (tmp == (method_type == 0 ? 15 : 31)) {
{
tmp = get_bits(&s->gb, 5); tmp = get_bits(&s->gb, 5);
for (; i < samples; i++, sample++) for (; i < samples; i++, sample++)
s->decoded[channel][sample] = get_sbits(&s->gb, tmp); s->decoded[channel][sample] = get_sbits(&s->gb, tmp);
} } else {
else
{
for (; i < samples; i++, sample++) { for (; i < samples; i++, sample++) {
s->decoded[channel][sample] = get_sr_golomb_flac(&s->gb, tmp, INT_MAX, 0); s->decoded[channel][sample] = get_sr_golomb_flac(&s->gb, tmp, INT_MAX, 0);
} }
@ -267,8 +264,7 @@ static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order)
int a, b, c, d, i; int a, b, c, d, i;
/* warm up samples */ /* warm up samples */
for (i = 0; i < pred_order; i++) for (i = 0; i < pred_order; i++) {
{
decoded[i] = get_sbits(&s->gb, s->curr_bps); decoded[i] = get_sbits(&s->gb, s->curr_bps);
} }
@ -284,8 +280,7 @@ static int decode_subframe_fixed(FLACContext *s, int channel, int pred_order)
if (pred_order > 3) if (pred_order > 3)
d = c - decoded[pred_order-2] + 2*decoded[pred_order-3] - decoded[pred_order-4]; d = c - decoded[pred_order-2] + 2*decoded[pred_order-3] - decoded[pred_order-4];
switch(pred_order) switch (pred_order) {
{
case 0: case 0:
break; break;
case 1: case 1:
@ -320,14 +315,12 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order)
int32_t *decoded = s->decoded[channel]; int32_t *decoded = s->decoded[channel];
/* warm up samples */ /* warm up samples */
for (i = 0; i < pred_order; i++) for (i = 0; i < pred_order; i++) {
{
decoded[i] = get_sbits(&s->gb, s->curr_bps); decoded[i] = get_sbits(&s->gb, s->curr_bps);
} }
coeff_prec = get_bits(&s->gb, 4) + 1; coeff_prec = get_bits(&s->gb, 4) + 1;
if (coeff_prec == 16) if (coeff_prec == 16) {
{
av_log(s->avctx, AV_LOG_ERROR, "invalid coeff precision\n"); av_log(s->avctx, AV_LOG_ERROR, "invalid coeff precision\n");
return -1; return -1;
} }
@ -337,8 +330,7 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order)
return -1; return -1;
} }
for (i = 0; i < pred_order; i++) for (i = 0; i < pred_order; i++) {
{
coeffs[i] = get_sbits(&s->gb, coeff_prec); coeffs[i] = get_sbits(&s->gb, coeff_prec);
} }
@ -347,21 +339,18 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order)
if (s->bps > 16) { if (s->bps > 16) {
int64_t sum; int64_t sum;
for (i = pred_order; i < s->blocksize; i++) for (i = pred_order; i < s->blocksize; i++) {
{
sum = 0; sum = 0;
for (j = 0; j < pred_order; j++) for (j = 0; j < pred_order; j++)
sum += (int64_t)coeffs[j] * decoded[i-j-1]; sum += (int64_t)coeffs[j] * decoded[i-j-1];
decoded[i] += sum >> qlevel; decoded[i] += sum >> qlevel;
} }
} else { } else {
for (i = pred_order; i < s->blocksize-1; i += 2) for (i = pred_order; i < s->blocksize-1; i += 2) {
{
int c; int c;
int d = decoded[i-pred_order]; int d = decoded[i-pred_order];
int s0 = 0, s1 = 0; int s0 = 0, s1 = 0;
for (j = pred_order-1; j > 0; j--) for (j = pred_order-1; j > 0; j--) {
{
c = coeffs[j]; c = coeffs[j];
s0 += c*d; s0 += c*d;
d = decoded[i-j]; d = decoded[i-j];
@ -373,8 +362,7 @@ static int decode_subframe_lpc(FLACContext *s, int channel, int pred_order)
s1 += c*d; s1 += c*d;
decoded[i+1] += s1 >> qlevel; decoded[i+1] += s1 >> qlevel;
} }
if (i < s->blocksize) if (i < s->blocksize) {
{
int sum = 0; int sum = 0;
for (j = 0; j < pred_order; j++) for (j = 0; j < pred_order; j++)
sum += coeffs[j] * decoded[i-j-1]; sum += coeffs[j] * decoded[i-j-1];
@ -399,15 +387,13 @@ static inline int decode_subframe(FLACContext *s, int channel)
s->curr_bps++; s->curr_bps++;
} }
if (get_bits1(&s->gb)) if (get_bits1(&s->gb)) {
{
av_log(s->avctx, AV_LOG_ERROR, "invalid subframe padding\n"); av_log(s->avctx, AV_LOG_ERROR, "invalid subframe padding\n");
return -1; return -1;
} }
type = get_bits(&s->gb, 6); type = get_bits(&s->gb, 6);
if (get_bits1(&s->gb)) if (get_bits1(&s->gb)) {
{
wasted = 1; wasted = 1;
while (!get_bits1(&s->gb)) while (!get_bits1(&s->gb))
wasted++; wasted++;
@ -415,35 +401,25 @@ static inline int decode_subframe(FLACContext *s, int channel)
} }
//FIXME use av_log2 for types //FIXME use av_log2 for types
if (type == 0) if (type == 0) {
{
tmp = get_sbits(&s->gb, s->curr_bps); tmp = get_sbits(&s->gb, s->curr_bps);
for (i = 0; i < s->blocksize; i++) for (i = 0; i < s->blocksize; i++)
s->decoded[channel][i] = tmp; s->decoded[channel][i] = tmp;
} } else if (type == 1) {
else if (type == 1)
{
for (i = 0; i < s->blocksize; i++) for (i = 0; i < s->blocksize; i++)
s->decoded[channel][i] = get_sbits(&s->gb, s->curr_bps); s->decoded[channel][i] = get_sbits(&s->gb, s->curr_bps);
} } else if ((type >= 8) && (type <= 12)) {
else if ((type >= 8) && (type <= 12))
{
if (decode_subframe_fixed(s, channel, type & ~0x8) < 0) if (decode_subframe_fixed(s, channel, type & ~0x8) < 0)
return -1; return -1;
} } else if (type >= 32) {
else if (type >= 32)
{
if (decode_subframe_lpc(s, channel, (type & ~0x20)+1) < 0) if (decode_subframe_lpc(s, channel, (type & ~0x20)+1) < 0)
return -1; return -1;
} } else {
else
{
av_log(s->avctx, AV_LOG_ERROR, "invalid coding type\n"); av_log(s->avctx, AV_LOG_ERROR, "invalid coding type\n");
return -1; return -1;
} }
if (wasted) if (wasted) {
{
int i; int i;
for (i = 0; i < s->blocksize; i++) for (i = 0; i < s->blocksize; i++)
s->decoded[channel][i] <<= wasted; s->decoded[channel][i] <<= wasted;
@ -466,8 +442,7 @@ static int decode_frame(FLACContext *s, int alloc_data_size)
decorrelation = INDEPENDENT; decorrelation = INDEPENDENT;
else if (assignment >=8 && assignment < 11 && s->channels == 2) else if (assignment >=8 && assignment < 11 && s->channels == 2)
decorrelation = LEFT_SIDE + assignment - 8; decorrelation = LEFT_SIDE + assignment - 8;
else else {
{
av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", assignment, s->channels); av_log(s->avctx, AV_LOG_ERROR, "unsupported channel assignment %d (channels=%d)\n", assignment, s->channels);
return -1; return -1;
} }
@ -477,14 +452,12 @@ static int decode_frame(FLACContext *s, int alloc_data_size)
bps= s->bps; bps= s->bps;
else if ((sample_size_code != 3) && (sample_size_code != 7)) else if ((sample_size_code != 3) && (sample_size_code != 7))
bps = sample_size_table[sample_size_code]; bps = sample_size_table[sample_size_code];
else else {
{
av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n", sample_size_code); av_log(s->avctx, AV_LOG_ERROR, "invalid sample size code (%d)\n", sample_size_code);
return -1; return -1;
} }
if (get_bits1(&s->gb)) if (get_bits1(&s->gb)) {
{
av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n"); av_log(s->avctx, AV_LOG_ERROR, "broken stream, invalid padding\n");
return -1; return -1;
} }
@ -511,9 +484,9 @@ static int decode_frame(FLACContext *s, int alloc_data_size)
if (blocksize * s->channels * sizeof(int16_t) > alloc_data_size) if (blocksize * s->channels * sizeof(int16_t) > alloc_data_size)
return -1; return -1;
if (sample_rate_code == 0){ if (sample_rate_code == 0)
samplerate= s->samplerate; samplerate= s->samplerate;
}else if (sample_rate_code < 12) else if (sample_rate_code < 12)
samplerate = sample_rate_table[sample_rate_code]; samplerate = sample_rate_table[sample_rate_code];
else if (sample_rate_code == 12) else if (sample_rate_code == 12)
samplerate = get_bits(&s->gb, 8) * 1000; samplerate = get_bits(&s->gb, 8) * 1000;
@ -542,8 +515,7 @@ static int decode_frame(FLACContext *s, int alloc_data_size)
// dump_headers(s->avctx, (FLACStreaminfo *)s); // dump_headers(s->avctx, (FLACStreaminfo *)s);
/* subframes */ /* subframes */
for (i = 0; i < s->channels; i++) for (i = 0; i < s->channels; i++) {
{
if (decode_subframe(s, i) < 0) if (decode_subframe(s, i) < 0)
return -1; return -1;
} }
@ -619,8 +591,7 @@ static int flac_decode_frame(AVCodecContext *avctx,
#define DECORRELATE(left, right)\ #define DECORRELATE(left, right)\
assert(s->channels == 2);\ assert(s->channels == 2);\
for (i = 0; i < s->blocksize; i++)\ for (i = 0; i < s->blocksize; i++) {\
{\
int a= s->decoded[0][i];\ int a= s->decoded[0][i];\
int b= s->decoded[1][i];\ int b= s->decoded[1][i];\
*samples++ = ((left) << (24 - s->bps)) >> 8;\ *samples++ = ((left) << (24 - s->bps)) >> 8;\
@ -628,11 +599,9 @@ static int flac_decode_frame(AVCodecContext *avctx,
}\ }\
break; break;
switch(s->decorrelation) switch (s->decorrelation) {
{
case INDEPENDENT: case INDEPENDENT:
for (j = 0; j < s->blocksize; j++) for (j = 0; j < s->blocksize; j++) {
{
for (i = 0; i < s->channels; i++) for (i = 0; i < s->channels; i++)
*samples++ = (s->decoded[i][j] << (24 - s->bps)) >> 8; *samples++ = (s->decoded[i][j] << (24 - s->bps)) >> 8;
} }
@ -669,8 +638,7 @@ static av_cold int flac_decode_close(AVCodecContext *avctx)
FLACContext *s = avctx->priv_data; FLACContext *s = avctx->priv_data;
int i; int i;
for (i = 0; i < s->channels; i++) for (i = 0; i < s->channels; i++) {
{
av_freep(&s->decoded[i]); av_freep(&s->decoded[i]);
} }
av_freep(&s->bitstream); av_freep(&s->bitstream);
@ -678,7 +646,8 @@ static av_cold int flac_decode_close(AVCodecContext *avctx)
return 0; return 0;
} }
static void flac_flush(AVCodecContext *avctx){ static void flac_flush(AVCodecContext *avctx)
{
FLACContext *s = avctx->priv_data; FLACContext *s = avctx->priv_data;
s->bitstream_size= s->bitstream_size=

Loading…
Cancel
Save