Browse code

shorten: K&R formatting cosmetics

Luca Barbato authored on 2013/03/06 00:11:28
Showing 1 changed files
... ...
@@ -108,10 +108,10 @@ typedef struct ShortenContext {
108 108
     int got_quit_command;
109 109
 } ShortenContext;
110 110
 
111
-static av_cold int shorten_decode_init(AVCodecContext * avctx)
111
+static av_cold int shorten_decode_init(AVCodecContext *avctx)
112 112
 {
113 113
     ShortenContext *s = avctx->priv_data;
114
-    s->avctx = avctx;
114
+    s->avctx          = avctx;
115 115
     avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
116 116
 
117 117
     return 0;
... ...
@@ -123,17 +123,20 @@ static int allocate_buffers(ShortenContext *s)
123 123
     int *coeffs;
124 124
     void *tmp_ptr;
125 125
 
126
-    for (chan=0; chan<s->channels; chan++) {
127
-        if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){
126
+    for (chan = 0; chan < s->channels; chan++) {
127
+        if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
128 128
             av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
129 129
             return -1;
130 130
         }
131
-        if(s->blocksize + s->nwrap >= UINT_MAX/sizeof(int32_t) || s->blocksize + s->nwrap <= (unsigned)s->nwrap){
132
-            av_log(s->avctx, AV_LOG_ERROR, "s->blocksize + s->nwrap too large\n");
131
+        if (s->blocksize + s->nwrap >= UINT_MAX / sizeof(int32_t) ||
132
+            s->blocksize + s->nwrap <= (unsigned)s->nwrap) {
133
+            av_log(s->avctx, AV_LOG_ERROR,
134
+                   "s->blocksize + s->nwrap too large\n");
133 135
             return -1;
134 136
         }
135 137
 
136
-        tmp_ptr = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean));
138
+        tmp_ptr =
139
+            av_realloc(s->offset[chan], sizeof(int32_t) * FFMAX(1, s->nmean));
137 140
         if (!tmp_ptr)
138 141
             return AVERROR(ENOMEM);
139 142
         s->offset[chan] = tmp_ptr;
... ...
@@ -143,7 +146,7 @@ static int allocate_buffers(ShortenContext *s)
143 143
         if (!tmp_ptr)
144 144
             return AVERROR(ENOMEM);
145 145
         s->decoded_base[chan] = tmp_ptr;
146
-        for (i=0; i<s->nwrap; i++)
146
+        for (i = 0; i < s->nwrap; i++)
147 147
             s->decoded_base[chan][i] = 0;
148 148
         s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
149 149
     }
... ...
@@ -156,7 +159,6 @@ static int allocate_buffers(ShortenContext *s)
156 156
     return 0;
157 157
 }
158 158
 
159
-
160 159
 static inline unsigned int get_uint(ShortenContext *s, int k)
161 160
 {
162 161
     if (s->version != 0)
... ...
@@ -164,7 +166,6 @@ static inline unsigned int get_uint(ShortenContext *s, int k)
164 164
     return get_ur_golomb_shorten(&s->gb, k);
165 165
 }
166 166
 
167
-
168 167
 static void fix_bitshift(ShortenContext *s, int32_t *buffer)
169 168
 {
170 169
     int i;
... ...
@@ -174,22 +175,20 @@ static void fix_bitshift(ShortenContext *s, int32_t *buffer)
174 174
             buffer[i] <<= s->bitshift;
175 175
 }
176 176
 
177
-
178 177
 static int init_offset(ShortenContext *s)
179 178
 {
180 179
     int32_t mean = 0;
181
-    int  chan, i;
180
+    int chan, i;
182 181
     int nblock = FFMAX(1, s->nmean);
183 182
     /* initialise offset */
184
-    switch (s->internal_ftype)
185
-    {
186
-        case TYPE_S16HL:
187
-        case TYPE_S16LH:
188
-            mean = 0;
189
-            break;
190
-        default:
191
-            av_log(s->avctx, AV_LOG_ERROR, "unknown audio type");
192
-            return AVERROR_INVALIDDATA;
183
+    switch (s->internal_ftype) {
184
+    case TYPE_S16HL:
185
+    case TYPE_S16LH:
186
+        mean = 0;
187
+        break;
188
+    default:
189
+        av_log(s->avctx, AV_LOG_ERROR, "unknown audio type");
190
+        return AVERROR_INVALIDDATA;
193 191
     }
194 192
 
195 193
     for (chan = 0; chan < s->channels; chan++)
... ...
@@ -204,21 +203,20 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
204 204
     int len;
205 205
     short wave_format;
206 206
 
207
-
208
-    if (bytestream_get_le32(&header) != MKTAG('R','I','F','F')) {
207
+    if (bytestream_get_le32(&header) != MKTAG('R', 'I', 'F', 'F')) {
209 208
         av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
210 209
         return -1;
211 210
     }
212 211
 
213
-    header += 4; /* chunk size */;
212
+    header += 4; /* chunk size */
214 213
 
215
-    if (bytestream_get_le32(&header) != MKTAG('W','A','V','E')) {
214
+    if (bytestream_get_le32(&header) != MKTAG('W', 'A', 'V', 'E')) {
216 215
         av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
217 216
         return -1;
218 217
     }
219 218
 
220
-    while (bytestream_get_le32(&header) != MKTAG('f','m','t',' ')) {
221
-        len = bytestream_get_le32(&header);
219
+    while (bytestream_get_le32(&header) != MKTAG('f', 'm', 't', ' ')) {
220
+        len     = bytestream_get_le32(&header);
222 221
         header += len;
223 222
     }
224 223
     len = bytestream_get_le32(&header);
... ...
@@ -231,11 +229,11 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
231 231
     wave_format = bytestream_get_le16(&header);
232 232
 
233 233
     switch (wave_format) {
234
-        case WAVE_FORMAT_PCM:
235
-            break;
236
-        default:
237
-            av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
238
-            return -1;
234
+    case WAVE_FORMAT_PCM:
235
+        break;
236
+    default:
237
+        av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
238
+        return -1;
239 239
     }
240 240
 
241 241
     header += 2;        // skip channels    (already got from shorten header)
... ...
@@ -284,11 +282,12 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
284 284
         /* read/validate prediction order */
285 285
         pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
286 286
         if (pred_order > s->nwrap) {
287
-            av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", pred_order);
287
+            av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n",
288
+                   pred_order);
288 289
             return AVERROR(EINVAL);
289 290
         }
290 291
         /* read LPC coefficients */
291
-        for (i=0; i<pred_order; i++)
292
+        for (i = 0; i < pred_order; i++)
292 293
             s->coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
293 294
         coeffs = s->coeffs;
294 295
 
... ...
@@ -296,7 +295,7 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
296 296
     } else {
297 297
         /* fixed LPC coeffs */
298 298
         pred_order = command;
299
-        coeffs     = fixed_coeffs[pred_order-1];
299
+        coeffs     = fixed_coeffs[pred_order - 1];
300 300
         qshift     = 0;
301 301
     }
302 302
 
... ...
@@ -307,11 +306,12 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
307 307
 
308 308
     /* decode residual and do LPC prediction */
309 309
     init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;
310
-    for (i=0; i < s->blocksize; i++) {
310
+    for (i = 0; i < s->blocksize; i++) {
311 311
         sum = init_sum;
312
-        for (j=0; j<pred_order; j++)
313
-            sum += coeffs[j] * s->decoded[channel][i-j-1];
314
-        s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> qshift);
312
+        for (j = 0; j < pred_order; j++)
313
+            sum += coeffs[j] * s->decoded[channel][i - j - 1];
314
+        s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) +
315
+                                 (sum >> qshift);
315 316
     }
316 317
 
317 318
     /* add offset to current samples */
... ...
@@ -332,10 +332,10 @@ static int read_header(ShortenContext *s)
332 332
         return -1;
333 333
     }
334 334
 
335
-    s->lpcqoffset = 0;
336
-    s->blocksize = DEFAULT_BLOCK_SIZE;
337
-    s->nmean = -1;
338
-    s->version = get_bits(&s->gb, 8);
335
+    s->lpcqoffset     = 0;
336
+    s->blocksize      = DEFAULT_BLOCK_SIZE;
337
+    s->nmean          = -1;
338
+    s->version        = get_bits(&s->gb, 8);
339 339
     s->internal_ftype = get_uint(s, TYPESIZE);
340 340
 
341 341
     s->channels = get_uint(s, CHANSIZE);
... ...
@@ -352,19 +352,19 @@ static int read_header(ShortenContext *s)
352 352
 
353 353
         blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
354 354
         if (!blocksize || blocksize > MAX_BLOCKSIZE) {
355
-            av_log(s->avctx, AV_LOG_ERROR, "invalid or unsupported block size: %d\n",
355
+            av_log(s->avctx, AV_LOG_ERROR,
356
+                   "invalid or unsupported block size: %d\n",
356 357
                    blocksize);
357 358
             return AVERROR(EINVAL);
358 359
         }
359 360
         s->blocksize = blocksize;
360 361
 
361
-        maxnlpc = get_uint(s, LPCQSIZE);
362
+        maxnlpc  = get_uint(s, LPCQSIZE);
362 363
         s->nmean = get_uint(s, 0);
363 364
 
364 365
         skip_bytes = get_uint(s, NSKIPSIZE);
365
-        for (i=0; i<skip_bytes; i++) {
366
+        for (i = 0; i < skip_bytes; i++)
366 367
             skip_bits(&s->gb, 8);
367
-        }
368 368
     }
369 369
     s->nwrap = FFMAX(NWRAP, maxnlpc);
370 370
 
... ...
@@ -378,17 +378,20 @@ static int read_header(ShortenContext *s)
378 378
         s->lpcqoffset = V2LPCQOFFSET;
379 379
 
380 380
     if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
381
-        av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n");
381
+        av_log(s->avctx, AV_LOG_ERROR,
382
+               "missing verbatim section at beginning of stream\n");
382 383
         return -1;
383 384
     }
384 385
 
385 386
     s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
386
-    if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) {
387
-        av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size);
387
+    if (s->header_size >= OUT_BUFFER_SIZE ||
388
+        s->header_size < CANONICAL_HEADER_SIZE) {
389
+        av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n",
390
+               s->header_size);
388 391
         return -1;
389 392
     }
390 393
 
391
-    for (i=0; i<s->header_size; i++)
394
+    for (i = 0; i < s->header_size; i++)
392 395
         s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
393 396
 
394 397
     if (decode_wave_header(s->avctx, s->header, s->header_size) < 0)
... ...
@@ -407,15 +410,15 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
407 407
 {
408 408
     AVFrame *frame     = data;
409 409
     const uint8_t *buf = avpkt->data;
410
-    int buf_size = avpkt->size;
411
-    ShortenContext *s = avctx->priv_data;
410
+    int buf_size       = avpkt->size;
411
+    ShortenContext *s  = avctx->priv_data;
412 412
     int i, input_buf_size = 0;
413 413
     int ret;
414 414
 
415 415
     /* allocate internal bitstream buffer */
416
-    if(s->max_framesize == 0){
416
+    if (s->max_framesize == 0) {
417 417
         void *tmp_ptr;
418
-        s->max_framesize= 1024; // should hopefully be enough for the first header
418
+        s->max_framesize = 1024; // should hopefully be enough for the first header
419 419
         tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size,
420 420
                                   s->max_framesize);
421 421
         if (!tmp_ptr) {
... ...
@@ -426,29 +429,32 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
426 426
     }
427 427
 
428 428
     /* append current packet data to bitstream buffer */
429
-    if(1 && s->max_framesize){//FIXME truncated
430
-        buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size);
431
-        input_buf_size= buf_size;
432
-
433
-        if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){
434
-            memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
435
-            s->bitstream_index=0;
429
+    if (1 && s->max_framesize) { //FIXME truncated
430
+        buf_size       = FFMIN(buf_size, s->max_framesize - s->bitstream_size);
431
+        input_buf_size = buf_size;
432
+
433
+        if (s->bitstream_index + s->bitstream_size + buf_size >
434
+            s->allocated_bitstream_size) {
435
+            memmove(s->bitstream, &s->bitstream[s->bitstream_index],
436
+                    s->bitstream_size);
437
+            s->bitstream_index = 0;
436 438
         }
437 439
         if (buf)
438
-            memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
439
-        buf= &s->bitstream[s->bitstream_index];
440
-        buf_size += s->bitstream_size;
441
-        s->bitstream_size= buf_size;
440
+            memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf,
441
+                   buf_size);
442
+        buf               = &s->bitstream[s->bitstream_index];
443
+        buf_size         += s->bitstream_size;
444
+        s->bitstream_size = buf_size;
442 445
 
443 446
         /* do not decode until buffer has at least max_framesize bytes or
444
-           the end of the file has been reached */
447
+         * the end of the file has been reached */
445 448
         if (buf_size < s->max_framesize && avpkt->data) {
446 449
             *got_frame_ptr = 0;
447 450
             return input_buf_size;
448 451
         }
449 452
     }
450 453
     /* init and position bitstream reader */
451
-    init_get_bits(&s->gb, buf, buf_size*8);
454
+    init_get_bits(&s->gb, buf, buf_size * 8);
452 455
     skip_bits(&s->gb, s->bitindex);
453 456
 
454 457
     /* process header or next subblock */
... ...
@@ -470,7 +476,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
470 470
         unsigned cmd;
471 471
         int len;
472 472
 
473
-        if (get_bits_left(&s->gb) < 3+FNSIZE) {
473
+        if (get_bits_left(&s->gb) < 3 + FNSIZE) {
474 474
             *got_frame_ptr = 0;
475 475
             break;
476 476
         }
... ...
@@ -486,32 +492,32 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
486 486
         if (!is_audio_command[cmd]) {
487 487
             /* process non-audio command */
488 488
             switch (cmd) {
489
-                case FN_VERBATIM:
490
-                    len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
491
-                    while (len--) {
492
-                        get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
493
-                    }
494
-                    break;
495
-                case FN_BITSHIFT:
496
-                    s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
497
-                    break;
498
-                case FN_BLOCKSIZE: {
499
-                    int blocksize = get_uint(s, av_log2(s->blocksize));
500
-                    if (blocksize > s->blocksize) {
501
-                        av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n");
502
-                        return AVERROR_PATCHWELCOME;
503
-                    }
504
-                    if (!blocksize || blocksize > MAX_BLOCKSIZE) {
505
-                        av_log(avctx, AV_LOG_ERROR, "invalid or unsupported "
506
-                               "block size: %d\n", blocksize);
507
-                        return AVERROR(EINVAL);
508
-                    }
509
-                    s->blocksize = blocksize;
510
-                    break;
489
+            case FN_VERBATIM:
490
+                len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
491
+                while (len--)
492
+                    get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
493
+                break;
494
+            case FN_BITSHIFT:
495
+                s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
496
+                break;
497
+            case FN_BLOCKSIZE: {
498
+                int blocksize = get_uint(s, av_log2(s->blocksize));
499
+                if (blocksize > s->blocksize) {
500
+                    av_log(avctx, AV_LOG_ERROR,
501
+                           "Increasing block size is not supported\n");
502
+                    return AVERROR_PATCHWELCOME;
511 503
                 }
512
-                case FN_QUIT:
513
-                    s->got_quit_command = 1;
514
-                    break;
504
+                if (!blocksize || blocksize > MAX_BLOCKSIZE) {
505
+                    av_log(avctx, AV_LOG_ERROR, "invalid or unsupported "
506
+                                                "block size: %d\n", blocksize);
507
+                    return AVERROR(EINVAL);
508
+                }
509
+                s->blocksize = blocksize;
510
+                break;
511
+            }
512
+            case FN_QUIT:
513
+                s->got_quit_command = 1;
514
+                break;
515 515
             }
516 516
             if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) {
517 517
                 *got_frame_ptr = 0;
... ...
@@ -537,7 +543,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
537 537
                 coffset = s->offset[channel][0];
538 538
             else {
539 539
                 int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
540
-                for (i=0; i<s->nmean; i++)
540
+                for (i = 0; i < s->nmean; i++)
541 541
                     sum += s->offset[channel][i];
542 542
                 coffset = sum / s->nmean;
543 543
                 if (s->version >= 2)
... ...
@@ -546,21 +552,22 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
546 546
 
547 547
             /* decode samples for this channel */
548 548
             if (cmd == FN_ZERO) {
549
-                for (i=0; i<s->blocksize; i++)
549
+                for (i = 0; i < s->blocksize; i++)
550 550
                     s->decoded[channel][i] = 0;
551 551
             } else {
552
-                if ((ret = decode_subframe_lpc(s, cmd, channel, residual_size, coffset)) < 0)
552
+                if ((ret = decode_subframe_lpc(s, cmd, channel,
553
+                                               residual_size, coffset)) < 0)
553 554
                     return ret;
554 555
             }
555 556
 
556 557
             /* update means with info from the current block */
557 558
             if (s->nmean > 0) {
558 559
                 int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
559
-                for (i=0; i<s->blocksize; i++)
560
+                for (i = 0; i < s->blocksize; i++)
560 561
                     sum += s->decoded[channel][i];
561 562
 
562
-                for (i=1; i<s->nmean; i++)
563
-                    s->offset[channel][i-1] = s->offset[channel][i];
563
+                for (i = 1; i < s->nmean; i++)
564
+                    s->offset[channel][i - 1] = s->offset[channel][i];
564 565
 
565 566
                 if (s->version < 2)
566 567
                     s->offset[channel][s->nmean - 1] = sum / s->blocksize;
... ...
@@ -569,11 +576,11 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
569 569
             }
570 570
 
571 571
             /* copy wrap samples for use with next block */
572
-            for (i=-s->nwrap; i<0; i++)
572
+            for (i = -s->nwrap; i < 0; i++)
573 573
                 s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
574 574
 
575 575
             /* shift samples to add in unused zero bits which were removed
576
-               during encoding */
576
+             * during encoding */
577 577
             fix_bitshift(s, s->decoded[channel]);
578 578
 
579 579
             /* if this is the last channel in the block, output the samples */
... ...
@@ -597,12 +604,12 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
597 597
         *got_frame_ptr = 0;
598 598
 
599 599
 finish_frame:
600
-    s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8);
601
-    i= (get_bits_count(&s->gb))/8;
600
+    s->bitindex = get_bits_count(&s->gb) - 8 * (get_bits_count(&s->gb) / 8);
601
+    i           = get_bits_count(&s->gb) / 8;
602 602
     if (i > buf_size) {
603 603
         av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
604
-        s->bitstream_size=0;
605
-        s->bitstream_index=0;
604
+        s->bitstream_size  = 0;
605
+        s->bitstream_index = 0;
606 606
         return -1;
607 607
     }
608 608
     if (s->bitstream_size) {