Browse code

Dirac: Removed goto + some code make up (cherry picked from commit 8db434f8a6d210f7fd2f28ba325927d7a5dd04b9)

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

Jordi Ortiz authored on 2011/11/04 03:15:08
Showing 1 changed files
... ...
@@ -349,8 +349,8 @@ static int alloc_sequence_buffers(DiracContext *s)
349 349
     s->blmotion = av_malloc(sbwidth * sbheight * 4 * sizeof(*s->blmotion));
350 350
     s->edge_emu_buffer_base = av_malloc((w+64)*MAX_BLOCKSIZE);
351 351
 
352
-    s->mctmp    = av_malloc((w+64+MAX_BLOCKSIZE) * (h*MAX_BLOCKSIZE) * sizeof(*s->mctmp));
353
-    s->mcscratch= av_malloc((w+64)*MAX_BLOCKSIZE);
352
+    s->mctmp     = av_malloc((w+64+MAX_BLOCKSIZE) * (h*MAX_BLOCKSIZE) * sizeof(*s->mctmp));
353
+    s->mcscratch = av_malloc((w+64)*MAX_BLOCKSIZE);
354 354
 
355 355
     if (!s->sbsplit || !s->blmotion)
356 356
         return AVERROR(ENOMEM);
... ...
@@ -446,8 +446,8 @@ static inline void coeff_unpack_arith(DiracArith *c, int qfactor, int qoffset,
446 446
 
447 447
     coeff = dirac_get_arith_uint(c, pred_ctx, CTX_COEFF_DATA);
448 448
     if (coeff) {
449
-        coeff = (coeff*qfactor + qoffset + 2)>>2;
450
-        sign = dirac_get_arith_bit(c, SIGN_CTX(sign_pred));
449
+        coeff = (coeff * qfactor + qoffset + 2) >> 2;
450
+        sign  = dirac_get_arith_bit(c, SIGN_CTX(sign_pred));
451 451
         coeff = (coeff ^ -sign) + sign;
452 452
     }
453 453
     *buf = coeff;
... ...
@@ -459,8 +459,8 @@ static inline int coeff_unpack_golomb(GetBitContext *gb, int qfactor, int qoffse
459 459
 
460 460
     coeff = svq3_get_ue_golomb(gb);
461 461
     if (coeff) {
462
-        coeff = (coeff*qfactor + qoffset + 2)>>2;
463
-        sign = get_bits1(gb);
462
+        coeff = (coeff * qfactor + qoffset + 2) >> 2;
463
+        sign  = get_bits1(gb);
464 464
         coeff = (coeff ^ -sign) + sign;
465 465
     }
466 466
     return coeff;
... ...
@@ -506,7 +506,7 @@ static inline void codeblock(DiracContext *s, SubBand *b,
506 506
     else
507 507
         qoffset = qoffset_inter_tab[b->quant];
508 508
 
509
-    buf = b->ibuf + top*b->stride;
509
+    buf = b->ibuf + top * b->stride;
510 510
     for (y = top; y < bottom; y++) {
511 511
         for (x = left; x < right; x++) {
512 512
             /* [DIRAC_STD] 13.4.4 Subband coefficients. coeff_unpack() */
... ...
@@ -537,7 +537,7 @@ static inline void intra_dc_prediction(SubBand *b)
537 537
 
538 538
         for (x = 1; x < b->width; x++) {
539 539
             int pred = buf[x - 1] + buf[x - b->stride] + buf[x - b->stride-1];
540
-            buf[x] += divide3(pred);
540
+            buf[x]  += divide3(pred);
541 541
         }
542 542
         buf += b->stride;
543 543
     }
... ...
@@ -547,8 +547,7 @@ static inline void intra_dc_prediction(SubBand *b)
547 547
  * Dirac Specification ->
548 548
  * 13.4.2 Non-skipped subbands.  subband_coeffs()
549 549
  */
550
-static av_always_inline
551
-void decode_subband_internal(DiracContext *s, SubBand *b, int is_arith)
550
+static av_always_inline void decode_subband_internal(DiracContext *s, SubBand *b, int is_arith)
552 551
 {
553 552
     int cb_x, cb_y, left, right, top, bottom;
554 553
     DiracArith c;
... ...
@@ -591,7 +590,7 @@ static int decode_subband_arith(AVCodecContext *avctx, void *b)
591 591
 static int decode_subband_golomb(AVCodecContext *avctx, void *arg)
592 592
 {
593 593
     DiracContext *s = avctx->priv_data;
594
-    SubBand **b = arg;
594
+    SubBand **b     = arg;
595 595
     decode_subband_internal(s, *b, 0);
596 596
     return 0;
597 597
 }
... ...
@@ -640,16 +639,16 @@ static void lowdelay_subband(DiracContext *s, GetBitContext *gb, int quant,
640 640
                              int slice_x, int slice_y, int bits_end,
641 641
                              SubBand *b1, SubBand *b2)
642 642
 {
643
-    int left   = b1->width * slice_x    / s->lowdelay.num_x;
644
-    int right  = b1->width *(slice_x+1) / s->lowdelay.num_x;
645
-    int top    = b1->height* slice_y    / s->lowdelay.num_y;
646
-    int bottom = b1->height*(slice_y+1) / s->lowdelay.num_y;
643
+    int left   = b1->width  * slice_x    / s->lowdelay.num_x;
644
+    int right  = b1->width  *(slice_x+1) / s->lowdelay.num_x;
645
+    int top    = b1->height * slice_y    / s->lowdelay.num_y;
646
+    int bottom = b1->height *(slice_y+1) / s->lowdelay.num_y;
647 647
 
648 648
     int qfactor = qscale_tab[FFMIN(quant, MAX_QUANT)];
649 649
     int qoffset = qoffset_intra_tab[FFMIN(quant, MAX_QUANT)];
650 650
 
651
-    IDWTELEM *buf1 =      b1->ibuf + top*b1->stride;
652
-    IDWTELEM *buf2 = b2 ? b2->ibuf + top*b2->stride : NULL;
651
+    IDWTELEM *buf1 =      b1->ibuf + top * b1->stride;
652
+    IDWTELEM *buf2 = b2 ? b2->ibuf + top * b2->stride : NULL;
653 653
     int x, y;
654 654
     /* we have to constantly check for overread since the spec explictly
655 655
        requires this, with the meaning that all remaining coeffs are set to 0 */
... ...
@@ -694,7 +693,7 @@ static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg)
694 694
     int level, quant, chroma_bits, chroma_end;
695 695
 
696 696
     int quant_base  = get_bits(gb, 7); /*[DIRAC_STD] qindex */
697
-    int length_bits = av_log2(8*slice->bytes)+1;
697
+    int length_bits = av_log2(8 * slice->bytes)+1;
698 698
     int luma_bits   = get_bits_long(gb, length_bits);
699 699
     int luma_end    = get_bits_count(gb) + FFMIN(luma_bits, get_bits_left(gb));
700 700
 
... ...
@@ -710,7 +709,7 @@ static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg)
710 710
     skip_bits_long(gb, get_bits_count(gb) - luma_end);
711 711
 
712 712
     chroma_bits = 8*slice->bytes - 7 - length_bits - luma_bits;
713
-    chroma_end = get_bits_count(gb) + FFMIN(chroma_bits, get_bits_left(gb));
713
+    chroma_end  = get_bits_count(gb) + FFMIN(chroma_bits, get_bits_left(gb));
714 714
     /* [DIRAC_STD] 13.5.5.3 chroma_slice_band */
715 715
     for (level = 0; level < s->wavelet_depth; level++)
716 716
         for (orientation = !!level; orientation < 4; orientation++) {
... ...
@@ -742,10 +741,10 @@ static void decode_lowdelay(DiracContext *s)
742 742
     buf = s->gb.buffer + get_bits_count(&s->gb)/8;
743 743
     bufsize = get_bits_left(&s->gb);
744 744
 
745
-    for (slice_y = 0; slice_y < s->lowdelay.num_y; slice_y++)
746
-        for (slice_x = 0; slice_x < s->lowdelay.num_x; slice_x++) {
745
+    for (slice_y = 0; bufsize > 0 && slice_y < s->lowdelay.num_y; slice_y++)
746
+        for (slice_x = 0; bufsize > 0 && slice_x < s->lowdelay.num_x; slice_x++) {
747 747
             bytes = (slice_num+1) * s->lowdelay.bytes.num / s->lowdelay.bytes.den
748
-                - slice_num    * s->lowdelay.bytes.num / s->lowdelay.bytes.den;
748
+                   - slice_num    * s->lowdelay.bytes.num / s->lowdelay.bytes.den;
749 749
 
750 750
             slices[slice_num].bytes   = bytes;
751 751
             slices[slice_num].slice_x = slice_x;
... ...
@@ -755,10 +754,7 @@ static void decode_lowdelay(DiracContext *s)
755 755
 
756 756
             buf     += bytes;
757 757
             bufsize -= bytes*8;
758
-            if (bufsize <= 0)
759
-                goto end;
760 758
         }
761
-end:
762 759
 
763 760
     avctx->execute(avctx, decode_lowdelay_slice, slices, NULL, slice_num,
764 761
                    sizeof(struct lowdelay_slice)); /* [DIRAC_STD] 13.5.2 Slices */
... ...
@@ -775,8 +771,8 @@ static void init_planes(DiracContext *s)
775 775
     for (i = 0; i < 3; i++) {
776 776
         Plane *p = &s->plane[i];
777 777
 
778
-        p->width  = s->source.width  >> (i ? s->chroma_x_shift : 0);
779
-        p->height = s->source.height >> (i ? s->chroma_y_shift : 0);
778
+        p->width       = s->source.width  >> (i ? s->chroma_x_shift : 0);
779
+        p->height      = s->source.height >> (i ? s->chroma_y_shift : 0);
780 780
         p->idwt_width  = w = CALC_PADDING(p->width , s->wavelet_depth);
781 781
         p->idwt_height = h = CALC_PADDING(p->height, s->wavelet_depth);
782 782
         p->idwt_stride = FFALIGN(p->idwt_width, 8);
... ...
@@ -890,7 +886,7 @@ static int dirac_unpack_prediction_parameters(DiracContext *s)
890 890
             /* [DIRAC_STD] zoom_rotate_shear(gparams)
891 891
                zoom/rotation/shear parameters */
892 892
             if (get_bits1(gb)) {
893
-                s->globalmc[ref].zrs_exp = svq3_get_ue_golomb(gb);
893
+                s->globalmc[ref].zrs_exp   = svq3_get_ue_golomb(gb);
894 894
                 s->globalmc[ref].zrs[0][0] = dirac_get_se_golomb(gb);
895 895
                 s->globalmc[ref].zrs[0][1] = dirac_get_se_golomb(gb);
896 896
                 s->globalmc[ref].zrs[1][0] = dirac_get_se_golomb(gb);
... ...
@@ -902,8 +898,8 @@ static int dirac_unpack_prediction_parameters(DiracContext *s)
902 902
             /* [DIRAC_STD] perspective(gparams) */
903 903
             if (get_bits1(gb)) {
904 904
                 s->globalmc[ref].perspective_exp = svq3_get_ue_golomb(gb);
905
-                s->globalmc[ref].perspective[0] = dirac_get_se_golomb(gb);
906
-                s->globalmc[ref].perspective[1] = dirac_get_se_golomb(gb);
905
+                s->globalmc[ref].perspective[0]  = dirac_get_se_golomb(gb);
906
+                s->globalmc[ref].perspective[1]  = dirac_get_se_golomb(gb);
907 907
             }
908 908
         }
909 909
     }
... ...
@@ -1105,15 +1101,15 @@ static inline void pred_mv(DiracBlock *block, int stride, int x, int y, int ref)
1105 1105
 
1106 1106
 static void global_mv(DiracContext *s, DiracBlock *block, int x, int y, int ref)
1107 1107
 {
1108
-    int ez = s->globalmc[ref].zrs_exp;
1109
-    int ep = s->globalmc[ref].perspective_exp;
1108
+    int ez      = s->globalmc[ref].zrs_exp;
1109
+    int ep      = s->globalmc[ref].perspective_exp;
1110 1110
     int (*A)[2] = s->globalmc[ref].zrs;
1111
-    int *b = s->globalmc[ref].pan_tilt;
1112
-    int *c = s->globalmc[ref].perspective;
1111
+    int *b      = s->globalmc[ref].pan_tilt;
1112
+    int *c      = s->globalmc[ref].perspective;
1113 1113
 
1114
-    int m = (1<<ep) - (c[0]*x + c[1]*y);
1115
-    int mx = m*((A[0][0]*x + A[0][1]*y) + (1<<ez)*b[0]);
1116
-    int my = m*((A[1][0]*x + A[1][1]*y) + (1<<ez)*b[1]);
1114
+    int m       = (1<<ep) - (c[0]*x + c[1]*y);
1115
+    int mx      = m * ((A[0][0] * x + A[0][1]*y) + (1<<ez) * b[0]);
1116
+    int my      = m * ((A[1][0] * x + A[1][1]*y) + (1<<ez) * b[1]);
1117 1117
 
1118 1118
     block->u.mv[ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep);
1119 1119
     block->u.mv[ref][1] = (my + (1<<(ez+ep))) >> (ez+ep);
... ...
@@ -1124,7 +1120,7 @@ static void decode_block_params(DiracContext *s, DiracArith arith[8], DiracBlock
1124 1124
 {
1125 1125
     int i;
1126 1126
 
1127
-    block->ref = pred_block_mode(block, stride, x, y, DIRAC_REF_MASK_REF1);
1127
+    block->ref  = pred_block_mode(block, stride, x, y, DIRAC_REF_MASK_REF1);
1128 1128
     block->ref ^= dirac_get_arith_bit(arith, CTX_PMODE_REF1);
1129 1129
 
1130 1130
     if (s->num_refs == 2) {
... ...
@@ -1150,8 +1146,8 @@ static void decode_block_params(DiracContext *s, DiracArith arith[8], DiracBlock
1150 1150
                 global_mv(s, block, x, y, i);
1151 1151
             } else {
1152 1152
                 pred_mv(block, stride, x, y, i);
1153
-                block->u.mv[i][0] += dirac_get_arith_int(arith+4+2*i, CTX_MV_F1, CTX_MV_DATA);
1154
-                block->u.mv[i][1] += dirac_get_arith_int(arith+5+2*i, CTX_MV_F1, CTX_MV_DATA);
1153
+                block->u.mv[i][0] += dirac_get_arith_int(arith + 4 + 2 * i, CTX_MV_F1, CTX_MV_DATA);
1154
+                block->u.mv[i][1] += dirac_get_arith_int(arith + 5 + 2 * i, CTX_MV_F1, CTX_MV_DATA);
1155 1155
             }
1156 1156
         }
1157 1157
 }
... ...
@@ -1190,15 +1186,15 @@ static void dirac_unpack_block_motion_data(DiracContext *s)
1190 1190
     /* [DIRAC_STD] 11.2.4 and 12.2.1 Number of blocks and superblocks */
1191 1191
     s->sbwidth  = DIVRNDUP(s->source.width,  4*s->plane[0].xbsep);
1192 1192
     s->sbheight = DIVRNDUP(s->source.height, 4*s->plane[0].ybsep);
1193
-    s->blwidth  = 4*s->sbwidth;
1194
-    s->blheight = 4*s->sbheight;
1193
+    s->blwidth  = 4 * s->sbwidth;
1194
+    s->blheight = 4 * s->sbheight;
1195 1195
 
1196 1196
     /* [DIRAC_STD] 12.3.1 Superblock splitting modes. superblock_split_modes()
1197 1197
        decode superblock split modes */
1198 1198
     ff_dirac_init_arith_decoder(arith, gb, svq3_get_ue_golomb(gb));     /* svq3_get_ue_golomb(gb) is the length */
1199 1199
     for (y = 0; y < s->sbheight; y++) {
1200 1200
         for (x = 0; x < s->sbwidth; x++) {
1201
-            int split = dirac_get_arith_uint(arith, CTX_SB_F1, CTX_SB_DATA);
1201
+            int split  = dirac_get_arith_uint(arith, CTX_SB_F1, CTX_SB_DATA);
1202 1202
             sbsplit[x] = (split + pred_sbsplit(sbsplit+x, s->sbwidth, x, y)) % 3;
1203 1203
         }
1204 1204
         sbsplit += s->sbwidth;
... ...
@@ -1207,21 +1203,21 @@ static void dirac_unpack_block_motion_data(DiracContext *s)
1207 1207
     /* setup arith decoding */
1208 1208
     ff_dirac_init_arith_decoder(arith, gb, svq3_get_ue_golomb(gb));
1209 1209
     for (i = 0; i < s->num_refs; i++) {
1210
-        ff_dirac_init_arith_decoder(arith+4+2*i, gb, svq3_get_ue_golomb(gb));
1211
-        ff_dirac_init_arith_decoder(arith+5+2*i, gb, svq3_get_ue_golomb(gb));
1210
+        ff_dirac_init_arith_decoder(arith + 4 + 2 * i, gb, svq3_get_ue_golomb(gb));
1211
+        ff_dirac_init_arith_decoder(arith + 5 + 2 * i, gb, svq3_get_ue_golomb(gb));
1212 1212
     }
1213 1213
     for (i = 0; i < 3; i++)
1214 1214
         ff_dirac_init_arith_decoder(arith+1+i, gb, svq3_get_ue_golomb(gb));
1215 1215
 
1216 1216
     for (y = 0; y < s->sbheight; y++)
1217 1217
         for (x = 0; x < s->sbwidth; x++) {
1218
-            int blkcnt = 1 << s->sbsplit[y*s->sbwidth + x];
1219
-            int step   = 4 >> s->sbsplit[y*s->sbwidth + x];
1218
+            int blkcnt = 1 << s->sbsplit[y * s->sbwidth + x];
1219
+            int step   = 4 >> s->sbsplit[y * s->sbwidth + x];
1220 1220
 
1221 1221
             for (q = 0; q < blkcnt; q++)
1222 1222
                 for (p = 0; p < blkcnt; p++) {
1223
-                    int bx = 4*x + p*step;
1224
-                    int by = 4*y + q*step;
1223
+                    int bx = 4 * x + p*step;
1224
+                    int by = 4 * y + q*step;
1225 1225
                     DiracBlock *block = &s->blmotion[by*s->blwidth + bx];
1226 1226
                     decode_block_params(s, arith, block, s->blwidth, bx, by);
1227 1227
                     propagate_block_data(block, s->blwidth, step);
... ...
@@ -1328,14 +1324,14 @@ static int mc_subpel(DiracContext *s, DiracBlock *block, const uint8_t *src[5],
1328 1328
         motion_y >>= s->chroma_y_shift;
1329 1329
     }
1330 1330
 
1331
-    mx = motion_x & ~(-1 << s->mv_precision);
1332
-    my = motion_y & ~(-1 << s->mv_precision);
1331
+    mx         = motion_x & ~(-1 << s->mv_precision);
1332
+    my         = motion_y & ~(-1 << s->mv_precision);
1333 1333
     motion_x >>= s->mv_precision;
1334 1334
     motion_y >>= s->mv_precision;
1335 1335
     /* normalize subpel coordinates to epel */
1336 1336
     /* TODO: template this function? */
1337
-    mx <<= 3-s->mv_precision;
1338
-    my <<= 3-s->mv_precision;
1337
+    mx      <<= 3 - s->mv_precision;
1338
+    my      <<= 3 - s->mv_precision;
1339 1339
 
1340 1340
     x += motion_x;
1341 1341
     y += motion_y;
... ...
@@ -1418,8 +1414,8 @@ static void add_dc(uint16_t *dst, int dc, int stride,
1418 1418
             dst[x  ] += dc * obmc_weight[x  ];
1419 1419
             dst[x+1] += dc * obmc_weight[x+1];
1420 1420
         }
1421
-        dst         += stride;
1422
-        obmc_weight += MAX_BLOCKSIZE;
1421
+        dst          += stride;
1422
+        obmc_weight  += MAX_BLOCKSIZE;
1423 1423
     }
1424 1424
 }
1425 1425
 
... ...
@@ -1521,7 +1517,7 @@ static void interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, in
1521 1521
                                       ref->hpel[plane][3], ref->hpel[plane][0],
1522 1522
                                       ref->avframe.linesize[plane], width, height);
1523 1523
         s->dsp.draw_edges(ref->hpel[plane][1], ref->avframe.linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM);
1524
-        s->dsp.draw_edges(ref->hpel[plane][2], ref->avframe.linesize[plane], width, height, edge, edge,  EDGE_TOP | EDGE_BOTTOM);
1524
+        s->dsp.draw_edges(ref->hpel[plane][2], ref->avframe.linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM);
1525 1525
         s->dsp.draw_edges(ref->hpel[plane][3], ref->avframe.linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM);
1526 1526
     }
1527 1527
     ref->interpolated[plane] = 1;
... ...
@@ -1547,7 +1543,7 @@ static int dirac_decode_frame_internal(DiracContext *s)
1547 1547
     }
1548 1548
 
1549 1549
     for (comp = 0; comp < 3; comp++) {
1550
-        Plane *p = &s->plane[comp];
1550
+        Plane *p       = &s->plane[comp];
1551 1551
         uint8_t *frame = s->current_picture->avframe.data[comp];
1552 1552
 
1553 1553
         /* FIXME: small resolutions */
... ...
@@ -1581,8 +1577,9 @@ static int dirac_decode_frame_internal(DiracContext *s)
1581 1581
 
1582 1582
             dsty = -p->yoffset;
1583 1583
             for (y = 0; y < s->blheight; y++) {
1584
-                int h = 0, start = FFMAX(dsty, 0);
1585
-                uint16_t *mctmp = s->mctmp + y*rowheight;
1584
+                int h     = 0,
1585
+                    start = FFMAX(dsty, 0);
1586
+                uint16_t *mctmp    = s->mctmp + y*rowheight;
1586 1587
                 DiracBlock *blocks = s->blmotion + y*s->blwidth;
1587 1588
 
1588 1589
                 init_obmc_weights(s, p, y);
... ...
@@ -1692,12 +1689,12 @@ static int dirac_decode_picture_header(DiracContext *s)
1692 1692
 static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *data_size)
1693 1693
 {
1694 1694
     DiracFrame *out = s->delay_frames[0];
1695
-    int i, out_idx = 0;
1695
+    int i, out_idx  = 0;
1696 1696
 
1697 1697
     /* find frame with lowest picture number */
1698 1698
     for (i = 1; s->delay_frames[i]; i++)
1699 1699
         if (s->delay_frames[i]->avframe.display_picture_number < out->avframe.display_picture_number) {
1700
-            out = s->delay_frames[i];
1700
+            out     = s->delay_frames[i];
1701 1701
             out_idx = i;
1702 1702
         }
1703 1703
 
... ...
@@ -1724,8 +1721,8 @@ static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *data_size)
1724 1724
    inside the function parse_sequence() */
1725 1725
 static int dirac_decode_data_unit(AVCodecContext *avctx, const uint8_t *buf, int size)
1726 1726
 {
1727
-    DiracContext *s = avctx->priv_data;
1728
-    DiracFrame *pic = NULL;
1727
+    DiracContext *s   = avctx->priv_data;
1728
+    DiracFrame *pic   = NULL;
1729 1729
     int i, parse_code = buf[4];
1730 1730
 
1731 1731
     if (size < DATA_UNIT_HEADER_SIZE)
... ...
@@ -1806,10 +1803,10 @@ static int dirac_decode_data_unit(AVCodecContext *avctx, const uint8_t *buf, int
1806 1806
 
1807 1807
 static int dirac_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt)
1808 1808
 {
1809
-    DiracContext *s = avctx->priv_data;
1809
+    DiracContext *s     = avctx->priv_data;
1810 1810
     DiracFrame *picture = data;
1811
-    uint8_t *buf = pkt->data;
1812
-    int buf_size = pkt->size;
1811
+    uint8_t *buf        = pkt->data;
1812
+    int buf_size        = pkt->size;
1813 1813
     int i, data_unit_size, buf_idx = 0;
1814 1814
 
1815 1815
     /* release unused frames */