Browse code

shorten: separate processing of audio commands from non-audio commands

Justin Ruggles authored on 2011/09/15 07:46:37
Showing 1 changed files
... ...
@@ -69,6 +69,9 @@
69 69
 #define FN_ZERO         8
70 70
 #define FN_VERBATIM     9
71 71
 
72
+/** indicates if the FN_* command is audio or non-audio */
73
+static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 };
74
+
72 75
 #define VERBATIM_CKSIZE_SIZE 5
73 76
 #define VERBATIM_BYTE_SIZE 8
74 77
 #define CANONICAL_HEADER_SIZE 44
... ...
@@ -388,14 +391,42 @@ static int shorten_decode_frame(AVCodecContext *avctx,
388 388
         int cmd;
389 389
         int len;
390 390
         cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
391
-        switch (cmd) {
392
-            case FN_ZERO:
393
-            case FN_DIFF0:
394
-            case FN_DIFF1:
395
-            case FN_DIFF2:
396
-            case FN_DIFF3:
397
-            case FN_QLPC:
398
-                {
391
+
392
+        if (cmd > FN_VERBATIM) {
393
+            av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
394
+            if (s->bitstream_size > 0) {
395
+                s->bitstream_index++;
396
+                s->bitstream_size--;
397
+            }
398
+            return -1;
399
+        }
400
+
401
+        if (!is_audio_command[cmd]) {
402
+            /* process non-audio command */
403
+            switch (cmd) {
404
+                case FN_VERBATIM:
405
+                    len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
406
+                    while (len--) {
407
+                        get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
408
+                    }
409
+                    break;
410
+                case FN_BITSHIFT:
411
+                    s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
412
+                    break;
413
+                case FN_BLOCKSIZE: {
414
+                    int blocksize = get_uint(s, av_log2(s->blocksize));
415
+                    if (blocksize > s->blocksize) {
416
+                        av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n");
417
+                        return AVERROR_PATCHWELCOME;
418
+                    }
419
+                    s->blocksize = blocksize;
420
+                    break;
421
+                }
422
+                case FN_QUIT:
423
+                    goto frame_done;
424
+            }
425
+        } else {
426
+            /* process audio command */
399 427
                     int residual_size = 0;
400 428
                     int channel = s->cur_chan;
401 429
                     int32_t coffset;
... ...
@@ -481,32 +512,6 @@ static int shorten_decode_frame(AVCodecContext *avctx,
481 481
                         s->cur_chan = 0;
482 482
                         goto frame_done;
483 483
                     }
484
-                }
485
-                break;
486
-            case FN_VERBATIM:
487
-                len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
488
-                while (len--) {
489
-                    get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
490
-                }
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, "Increasing block size is not supported\n");
499
-                    return AVERROR_PATCHWELCOME;
500
-                }
501
-                s->blocksize = blocksize;
502
-                break;
503
-            }
504
-            case FN_QUIT:
505
-                *data_size = 0;
506
-                return buf_size;
507
-            default:
508
-                av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
509
-                return -1;
510 484
         }
511 485
     }
512 486
 frame_done: