Browse code

Merge commit 'a2ad554def214d2d03b7c16f68dc081a8622f9ca'

* commit 'a2ad554def214d2d03b7c16f68dc081a8622f9ca':
shorten: K&R formatting cosmetics

Conflicts:
libavcodec/shorten.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/03/07 07:39:52
Showing 1 changed files
... ...
@@ -112,10 +112,10 @@ typedef struct ShortenContext {
112 112
     int got_quit_command;
113 113
 } ShortenContext;
114 114
 
115
-static av_cold int shorten_decode_init(AVCodecContext * avctx)
115
+static av_cold int shorten_decode_init(AVCodecContext *avctx)
116 116
 {
117 117
     ShortenContext *s = avctx->priv_data;
118
-    s->avctx = avctx;
118
+    s->avctx          = avctx;
119 119
 
120 120
     return 0;
121 121
 }
... ...
@@ -126,17 +126,20 @@ static int allocate_buffers(ShortenContext *s)
126 126
     int *coeffs;
127 127
     void *tmp_ptr;
128 128
 
129
-    for (chan=0; chan<s->channels; chan++) {
130
-        if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){
129
+    for (chan = 0; chan < s->channels; chan++) {
130
+        if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
131 131
             av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
132 132
             return AVERROR_INVALIDDATA;
133 133
         }
134
-        if(s->blocksize + s->nwrap >= UINT_MAX/sizeof(int32_t) || s->blocksize + s->nwrap <= (unsigned)s->nwrap){
135
-            av_log(s->avctx, AV_LOG_ERROR, "s->blocksize + s->nwrap too large\n");
134
+        if (s->blocksize + s->nwrap >= UINT_MAX / sizeof(int32_t) ||
135
+            s->blocksize + s->nwrap <= (unsigned)s->nwrap) {
136
+            av_log(s->avctx, AV_LOG_ERROR,
137
+                   "s->blocksize + s->nwrap too large\n");
136 138
             return AVERROR_INVALIDDATA;
137 139
         }
138 140
 
139
-        tmp_ptr = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean));
141
+        tmp_ptr =
142
+            av_realloc(s->offset[chan], sizeof(int32_t) * FFMAX(1, s->nmean));
140 143
         if (!tmp_ptr)
141 144
             return AVERROR(ENOMEM);
142 145
         s->offset[chan] = tmp_ptr;
... ...
@@ -146,7 +149,7 @@ static int allocate_buffers(ShortenContext *s)
146 146
         if (!tmp_ptr)
147 147
             return AVERROR(ENOMEM);
148 148
         s->decoded_base[chan] = tmp_ptr;
149
-        for (i=0; i<s->nwrap; i++)
149
+        for (i = 0; i < s->nwrap; i++)
150 150
             s->decoded_base[chan][i] = 0;
151 151
         s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
152 152
     }
... ...
@@ -159,7 +162,6 @@ static int allocate_buffers(ShortenContext *s)
159 159
     return 0;
160 160
 }
161 161
 
162
-
163 162
 static inline unsigned int get_uint(ShortenContext *s, int k)
164 163
 {
165 164
     if (s->version != 0)
... ...
@@ -167,7 +169,6 @@ static inline unsigned int get_uint(ShortenContext *s, int k)
167 167
     return get_ur_golomb_shorten(&s->gb, k);
168 168
 }
169 169
 
170
-
171 170
 static void fix_bitshift(ShortenContext *s, int32_t *buffer)
172 171
 {
173 172
     int i;
... ...
@@ -177,26 +178,24 @@ static void fix_bitshift(ShortenContext *s, int32_t *buffer)
177 177
             buffer[i] <<= s->bitshift;
178 178
 }
179 179
 
180
-
181 180
 static int init_offset(ShortenContext *s)
182 181
 {
183 182
     int32_t mean = 0;
184
-    int  chan, i;
183
+    int chan, i;
185 184
     int nblock = FFMAX(1, s->nmean);
186 185
     /* initialise offset */
187
-    switch (s->internal_ftype)
188
-    {
189
-        case TYPE_U8:
190
-            s->avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
191
-            mean = 0x80;
192
-            break;
193
-        case TYPE_S16HL:
194
-        case TYPE_S16LH:
195
-            s->avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
196
-            break;
197
-        default:
198
-            av_log(s->avctx, AV_LOG_ERROR, "unknown audio type\n");
199
-            return AVERROR_PATCHWELCOME;
186
+    switch (s->internal_ftype) {
187
+    case TYPE_U8:
188
+        s->avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
189
+        mean = 0x80;
190
+        break;
191
+    case TYPE_S16HL:
192
+    case TYPE_S16LH:
193
+        s->avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
194
+        break;
195
+    default:
196
+        av_log(s->avctx, AV_LOG_ERROR, "unknown audio type\n");
197
+        return AVERROR_PATCHWELCOME;
200 198
     }
201 199
 
202 200
     for (chan = 0; chan < s->channels; chan++)
... ...
@@ -212,21 +211,21 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
212 212
     short wave_format;
213 213
     const uint8_t *end= header + header_size;
214 214
 
215
-    if (bytestream_get_le32(&header) != MKTAG('R','I','F','F')) {
215
+    if (bytestream_get_le32(&header) != MKTAG('R', 'I', 'F', 'F')) {
216 216
         av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
217 217
         return AVERROR_INVALIDDATA;
218 218
     }
219 219
 
220
-    header += 4; /* chunk size */;
220
+    header += 4; /* chunk size */
221 221
 
222
-    if (bytestream_get_le32(&header) != MKTAG('W','A','V','E')) {
222
+    if (bytestream_get_le32(&header) != MKTAG('W', 'A', 'V', 'E')) {
223 223
         av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
224 224
         return AVERROR_INVALIDDATA;
225 225
     }
226 226
 
227
-    while (bytestream_get_le32(&header) != MKTAG('f','m','t',' ')) {
228
-        len = bytestream_get_le32(&header);
229
-        if(len<0 || end - header - 8 < len)
227
+    while (bytestream_get_le32(&header) != MKTAG('f', 'm', 't', ' ')) {
228
+        len     = bytestream_get_le32(&header);
229
+        if (len<0 || end - header - 8 < len)
230 230
             return AVERROR_INVALIDDATA;
231 231
         header += len;
232 232
     }
... ...
@@ -240,11 +239,11 @@ static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
240 240
     wave_format = bytestream_get_le16(&header);
241 241
 
242 242
     switch (wave_format) {
243
-        case WAVE_FORMAT_PCM:
244
-            break;
245
-        default:
246
-            av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
247
-            return AVERROR_PATCHWELCOME;
243
+    case WAVE_FORMAT_PCM:
244
+        break;
245
+    default:
246
+        av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
247
+        return AVERROR_PATCHWELCOME;
248 248
     }
249 249
 
250 250
     header += 2;        // skip channels    (already got from shorten header)
... ...
@@ -282,11 +281,12 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
282 282
         /* read/validate prediction order */
283 283
         pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
284 284
         if (pred_order > s->nwrap) {
285
-            av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", pred_order);
285
+            av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n",
286
+                   pred_order);
286 287
             return AVERROR(EINVAL);
287 288
         }
288 289
         /* read LPC coefficients */
289
-        for (i=0; i<pred_order; i++)
290
+        for (i = 0; i < pred_order; i++)
290 291
             s->coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
291 292
         coeffs = s->coeffs;
292 293
 
... ...
@@ -294,7 +294,7 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
294 294
     } else {
295 295
         /* fixed LPC coeffs */
296 296
         pred_order = command;
297
-        coeffs     = fixed_coeffs[pred_order-1];
297
+        coeffs     = fixed_coeffs[pred_order - 1];
298 298
         qshift     = 0;
299 299
     }
300 300
 
... ...
@@ -305,11 +305,12 @@ static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
305 305
 
306 306
     /* decode residual and do LPC prediction */
307 307
     init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;
308
-    for (i=0; i < s->blocksize; i++) {
308
+    for (i = 0; i < s->blocksize; i++) {
309 309
         sum = init_sum;
310
-        for (j=0; j<pred_order; j++)
311
-            sum += coeffs[j] * s->decoded[channel][i-j-1];
312
-        s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> qshift);
310
+        for (j = 0; j < pred_order; j++)
311
+            sum += coeffs[j] * s->decoded[channel][i - j - 1];
312
+        s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) +
313
+                                 (sum >> qshift);
313 314
     }
314 315
 
315 316
     /* add offset to current samples */
... ...
@@ -330,10 +331,10 @@ static int read_header(ShortenContext *s)
330 330
         return AVERROR_INVALIDDATA;
331 331
     }
332 332
 
333
-    s->lpcqoffset = 0;
334
-    s->blocksize = DEFAULT_BLOCK_SIZE;
335
-    s->nmean = -1;
336
-    s->version = get_bits(&s->gb, 8);
333
+    s->lpcqoffset     = 0;
334
+    s->blocksize      = DEFAULT_BLOCK_SIZE;
335
+    s->nmean          = -1;
336
+    s->version        = get_bits(&s->gb, 8);
337 337
     s->internal_ftype = get_uint(s, TYPESIZE);
338 338
 
339 339
     s->channels = get_uint(s, CHANSIZE);
... ...
@@ -350,19 +351,19 @@ static int read_header(ShortenContext *s)
350 350
 
351 351
         blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
352 352
         if (!blocksize || blocksize > (unsigned)MAX_BLOCKSIZE) {
353
-            av_log(s->avctx, AV_LOG_ERROR, "invalid or unsupported block size: %d\n",
353
+            av_log(s->avctx, AV_LOG_ERROR,
354
+                   "invalid or unsupported block size: %d\n",
354 355
                    blocksize);
355 356
             return AVERROR(EINVAL);
356 357
         }
357 358
         s->blocksize = blocksize;
358 359
 
359
-        maxnlpc = get_uint(s, LPCQSIZE);
360
+        maxnlpc  = get_uint(s, LPCQSIZE);
360 361
         s->nmean = get_uint(s, 0);
361 362
 
362 363
         skip_bytes = get_uint(s, NSKIPSIZE);
363
-        for (i=0; i<skip_bytes; i++) {
364
+        for (i = 0; i < skip_bytes; i++)
364 365
             skip_bits(&s->gb, 8);
365
-        }
366 366
     }
367 367
     s->nwrap = FFMAX(NWRAP, maxnlpc);
368 368
 
... ...
@@ -376,17 +377,20 @@ static int read_header(ShortenContext *s)
376 376
         s->lpcqoffset = V2LPCQOFFSET;
377 377
 
378 378
     if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
379
-        av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n");
379
+        av_log(s->avctx, AV_LOG_ERROR,
380
+               "missing verbatim section at beginning of stream\n");
380 381
         return AVERROR_INVALIDDATA;
381 382
     }
382 383
 
383 384
     s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
384
-    if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) {
385
-        av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size);
385
+    if (s->header_size >= OUT_BUFFER_SIZE ||
386
+        s->header_size < CANONICAL_HEADER_SIZE) {
387
+        av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n",
388
+               s->header_size);
386 389
         return AVERROR_INVALIDDATA;
387 390
     }
388 391
 
389
-    for (i=0; i<s->header_size; i++)
392
+    for (i = 0; i < s->header_size; i++)
390 393
         s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
391 394
 
392 395
     if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0)
... ...
@@ -405,15 +409,15 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
405 405
 {
406 406
     AVFrame *frame     = data;
407 407
     const uint8_t *buf = avpkt->data;
408
-    int buf_size = avpkt->size;
409
-    ShortenContext *s = avctx->priv_data;
408
+    int buf_size       = avpkt->size;
409
+    ShortenContext *s  = avctx->priv_data;
410 410
     int i, input_buf_size = 0;
411 411
     int ret;
412 412
 
413 413
     /* allocate internal bitstream buffer */
414
-    if(s->max_framesize == 0){
414
+    if (s->max_framesize == 0) {
415 415
         void *tmp_ptr;
416
-        s->max_framesize= 8192; // should hopefully be enough for the first header
416
+        s->max_framesize = 8192; // should hopefully be enough for the first header
417 417
         tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size,
418 418
                                   s->max_framesize);
419 419
         if (!tmp_ptr) {
... ...
@@ -424,29 +428,32 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
424 424
     }
425 425
 
426 426
     /* append current packet data to bitstream buffer */
427
-    if(1 && s->max_framesize){//FIXME truncated
428
-        buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size);
429
-        input_buf_size= buf_size;
430
-
431
-        if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){
432
-            memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size);
433
-            s->bitstream_index=0;
427
+    if (1 && s->max_framesize) { //FIXME truncated
428
+        buf_size       = FFMIN(buf_size, s->max_framesize - s->bitstream_size);
429
+        input_buf_size = buf_size;
430
+
431
+        if (s->bitstream_index + s->bitstream_size + buf_size >
432
+            s->allocated_bitstream_size) {
433
+            memmove(s->bitstream, &s->bitstream[s->bitstream_index],
434
+                    s->bitstream_size);
435
+            s->bitstream_index = 0;
434 436
         }
435 437
         if (buf)
436
-            memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size);
437
-        buf= &s->bitstream[s->bitstream_index];
438
-        buf_size += s->bitstream_size;
439
-        s->bitstream_size= buf_size;
438
+            memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf,
439
+                   buf_size);
440
+        buf               = &s->bitstream[s->bitstream_index];
441
+        buf_size         += s->bitstream_size;
442
+        s->bitstream_size = buf_size;
440 443
 
441 444
         /* do not decode until buffer has at least max_framesize bytes or
442
-           the end of the file has been reached */
445
+         * the end of the file has been reached */
443 446
         if (buf_size < s->max_framesize && avpkt->data) {
444 447
             *got_frame_ptr = 0;
445 448
             return input_buf_size;
446 449
         }
447 450
     }
448 451
     /* init and position bitstream reader */
449
-    init_get_bits(&s->gb, buf, buf_size*8);
452
+    init_get_bits(&s->gb, buf, buf_size * 8);
450 453
     skip_bits(&s->gb, s->bitindex);
451 454
 
452 455
     /* process header or next subblock */
... ...
@@ -468,7 +475,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
468 468
         unsigned cmd;
469 469
         int len;
470 470
 
471
-        if (get_bits_left(&s->gb) < 3+FNSIZE) {
471
+        if (get_bits_left(&s->gb) < 3 + FNSIZE) {
472 472
             *got_frame_ptr = 0;
473 473
             break;
474 474
         }
... ...
@@ -484,32 +491,32 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
484 484
         if (!is_audio_command[cmd]) {
485 485
             /* process non-audio command */
486 486
             switch (cmd) {
487
-                case FN_VERBATIM:
488
-                    len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
489
-                    while (len--) {
490
-                        get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
491
-                    }
492
-                    break;
493
-                case FN_BITSHIFT:
494
-                    s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
495
-                    break;
496
-                case FN_BLOCKSIZE: {
497
-                    int blocksize = get_uint(s, av_log2(s->blocksize));
498
-                    if (blocksize > s->blocksize) {
499
-                        av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n");
500
-                        return AVERROR_PATCHWELCOME;
501
-                    }
502
-                    if (!blocksize || blocksize > (unsigned)MAX_BLOCKSIZE) {
503
-                        av_log(avctx, AV_LOG_ERROR, "invalid or unsupported "
504
-                               "block size: %d\n", blocksize);
505
-                        return AVERROR(EINVAL);
506
-                    }
507
-                    s->blocksize = blocksize;
508
-                    break;
487
+            case FN_VERBATIM:
488
+                len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
489
+                while (len--)
490
+                    get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
491
+                break;
492
+            case FN_BITSHIFT:
493
+                s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
494
+                break;
495
+            case FN_BLOCKSIZE: {
496
+                int blocksize = get_uint(s, av_log2(s->blocksize));
497
+                if (blocksize > s->blocksize) {
498
+                    av_log(avctx, AV_LOG_ERROR,
499
+                           "Increasing block size is not supported\n");
500
+                    return AVERROR_PATCHWELCOME;
509 501
                 }
510
-                case FN_QUIT:
511
-                    s->got_quit_command = 1;
512
-                    break;
502
+                if (!blocksize || blocksize > (unsigned)MAX_BLOCKSIZE) {
503
+                    av_log(avctx, AV_LOG_ERROR, "invalid or unsupported "
504
+                                                "block size: %d\n", blocksize);
505
+                    return AVERROR(EINVAL);
506
+                }
507
+                s->blocksize = blocksize;
508
+                break;
509
+            }
510
+            case FN_QUIT:
511
+                s->got_quit_command = 1;
512
+                break;
513 513
             }
514 514
             if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) {
515 515
                 *got_frame_ptr = 0;
... ...
@@ -535,7 +542,7 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
535 535
                 coffset = s->offset[channel][0];
536 536
             else {
537 537
                 int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
538
-                for (i=0; i<s->nmean; i++)
538
+                for (i = 0; i < s->nmean; i++)
539 539
                     sum += s->offset[channel][i];
540 540
                 coffset = sum / s->nmean;
541 541
                 if (s->version >= 2)
... ...
@@ -544,21 +551,22 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
544 544
 
545 545
             /* decode samples for this channel */
546 546
             if (cmd == FN_ZERO) {
547
-                for (i=0; i<s->blocksize; i++)
547
+                for (i = 0; i < s->blocksize; i++)
548 548
                     s->decoded[channel][i] = 0;
549 549
             } else {
550
-                if ((ret = decode_subframe_lpc(s, cmd, channel, residual_size, coffset)) < 0)
550
+                if ((ret = decode_subframe_lpc(s, cmd, channel,
551
+                                               residual_size, coffset)) < 0)
551 552
                     return ret;
552 553
             }
553 554
 
554 555
             /* update means with info from the current block */
555 556
             if (s->nmean > 0) {
556 557
                 int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
557
-                for (i=0; i<s->blocksize; i++)
558
+                for (i = 0; i < s->blocksize; i++)
558 559
                     sum += s->decoded[channel][i];
559 560
 
560
-                for (i=1; i<s->nmean; i++)
561
-                    s->offset[channel][i-1] = s->offset[channel][i];
561
+                for (i = 1; i < s->nmean; i++)
562
+                    s->offset[channel][i - 1] = s->offset[channel][i];
562 563
 
563 564
                 if (s->version < 2)
564 565
                     s->offset[channel][s->nmean - 1] = sum / s->blocksize;
... ...
@@ -567,11 +575,11 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
567 567
             }
568 568
 
569 569
             /* copy wrap samples for use with next block */
570
-            for (i=-s->nwrap; i<0; i++)
570
+            for (i = -s->nwrap; i < 0; i++)
571 571
                 s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
572 572
 
573 573
             /* shift samples to add in unused zero bits which were removed
574
-               during encoding */
574
+             * during encoding */
575 575
             fix_bitshift(s, s->decoded[channel]);
576 576
 
577 577
             /* if this is the last channel in the block, output the samples */
... ...
@@ -612,12 +620,12 @@ static int shorten_decode_frame(AVCodecContext *avctx, void *data,
612 612
         *got_frame_ptr = 0;
613 613
 
614 614
 finish_frame:
615
-    s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8);
616
-    i= (get_bits_count(&s->gb))/8;
615
+    s->bitindex = get_bits_count(&s->gb) - 8 * (get_bits_count(&s->gb) / 8);
616
+    i           = get_bits_count(&s->gb) / 8;
617 617
     if (i > buf_size) {
618 618
         av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
619
-        s->bitstream_size=0;
620
-        s->bitstream_index=0;
619
+        s->bitstream_size  = 0;
620
+        s->bitstream_index = 0;
621 621
         return AVERROR_INVALIDDATA;
622 622
     }
623 623
     if (s->bitstream_size) {