History

vc1dec: interlaced B-frames

Sebastian Sandberg committed 13 years ago

Commit db8403d1 parent d244a611 file · +418 −57Browse files

Unified · Split

libavcodec/vc1dec.c+418−57
@@ -350,6 +350,7 @@ static void vc1_mc_1mv(VC1Context *v, int dir) · 349 unmodified lines
350350 int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
351351 int off, off_uv;
352352 int v_edge_pos = s->v_edge_pos >> v->field_mode;
353+ int i;
353354
354355 if ((!v->field_mode ||
355356 (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&
@@ -361,8 +362,10 @@ static void vc1_mc_1mv(VC1Context *v, int dir) · 5 unmodified lines
361362
362363 // store motion vectors for further use in B frames
363364 if (s->pict_type == AV_PICTURE_TYPE_P) {
364− s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][0] = mx;
365− s->current_picture.motion_val[1][s->block_index[0] + v->blocks_off][1] = my;
365+ for (i = 0; i < 4; i++) {
366+ s->current_picture.motion_val[1][s->block_index[i] + v->blocks_off][0] = mx;
367+ s->current_picture.motion_val[1][s->block_index[i] + v->blocks_off][1] = my;
368+ }
366369 }
367370
368371 uvmx = (mx + ((mx & 3) == 3)) >> 1;
@@ -553,7 +556,7 @@ static inline int median4(int a, int b, int c, int d) · 184 unmodified lines
553556
554557 /** Do motion compensation for 4-MV macroblock - luminance block
555558 */
556−static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
559+static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir, int avg)
557560 {
558561 MpegEncContext *s = &v->s;
559562 uint8_t *srcY;
@@ -629,6 +632,10 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir) · 69 unmodified lines
629632 int qx, qy;
630633 int width = s->avctx->coded_width;
631634 int height = s->avctx->coded_height >> 1;
635+ if (s->pict_type == AV_PICTURE_TYPE_P) {
636+ s->current_picture.motion_val[1][s->block_index[n] + v->blocks_off][0] = mx;
637+ s->current_picture.motion_val[1][s->block_index[n] + v->blocks_off][1] = my;
638+ }
632639 qx = (s->mb_x * 16) + (mx >> 2);
633640 qy = (s->mb_y * 8) + (my >> 3);
634641
@@ -716,7 +723,10 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir) · 81 unmodified lines
716723
717724 if (s->mspel) {
718725 dxy = ((my & 3) << 2) | (mx & 3);
719− v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);
726+ if (avg)
727+ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);
728+ else
729+ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd);
720730 } else { // hpel mc - always used for luma
721731 dxy = (my & 2) | ((mx & 2) >> 1);
722732 if (!v->rnd)
@@ -1622,7 +1632,7 @@ static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, · 899 unmodified lines
16221632 /** Predict and set motion vector for interlaced frame picture MBs
16231633 */
16241634 static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y,
1625− int mvn, int r_x, int r_y, uint8_t* is_intra)
1635+ int mvn, int r_x, int r_y, uint8_t* is_intra, int dir)
16261636 {
16271637 MpegEncContext *s = &v->s;
16281638 int xy, wrap, off = 0;
@@ -1664,14 +1674,14 @@ static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, · 35 unmodified lines
16641674 if (s->mb_x || (n == 1) || (n == 3)) {
16651675 if ((v->blk_mv_type[xy]) // current block (MB) has a field MV
16661676 || (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) { // or both have frame MV
1667− A[0] = s->current_picture.motion_val[0][xy - 1][0];
1668− A[1] = s->current_picture.motion_val[0][xy - 1][1];
1677+ A[0] = s->current_picture.motion_val[dir][xy - 1][0];
1678+ A[1] = s->current_picture.motion_val[dir][xy - 1][1];
16691679 a_valid = 1;
16701680 } else { // current block has frame mv and cand. has field MV (so average)
1671− A[0] = (s->current_picture.motion_val[0][xy - 1][0]
1672− + s->current_picture.motion_val[0][xy - 1 + off * wrap][0] + 1) >> 1;
1673− A[1] = (s->current_picture.motion_val[0][xy - 1][1]
1674− + s->current_picture.motion_val[0][xy - 1 + off * wrap][1] + 1) >> 1;
1681+ A[0] = (s->current_picture.motion_val[dir][xy - 1][0]
1682+ + s->current_picture.motion_val[dir][xy - 1 + off * wrap][0] + 1) >> 1;
1683+ A[1] = (s->current_picture.motion_val[dir][xy - 1][1]
1684+ + s->current_picture.motion_val[dir][xy - 1 + off * wrap][1] + 1) >> 1;
16751685 a_valid = 1;
16761686 }
16771687 if (!(n & 1) && v->is_intra[s->mb_x - 1]) {
@@ -1691,11 +1701,11 @@ static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, · 13 unmodified lines
16911701 if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) {
16921702 n_adj = (n & 2) | (n & 1);
16931703 }
1694− B[0] = s->current_picture.motion_val[0][s->block_index[n_adj] - 2 * wrap][0];
1695− B[1] = s->current_picture.motion_val[0][s->block_index[n_adj] - 2 * wrap][1];
1704+ B[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap][0];
1705+ B[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap][1];
16961706 if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) {
1697− B[0] = (B[0] + s->current_picture.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
1698− B[1] = (B[1] + s->current_picture.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
1707+ B[0] = (B[0] + s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1;
1708+ B[1] = (B[1] + s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1;
16991709 }
17001710 }
17011711 if (s->mb_width > 1) {
@@ -1706,11 +1716,11 @@ static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, · 4 unmodified lines
17061716 if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
17071717 n_adj = n & 2;
17081718 }
1709− C[0] = s->current_picture.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][0];
1710− C[1] = s->current_picture.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][1];
1719+ C[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][0];
1720+ C[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap + 2][1];
17111721 if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
1712− C[0] = (1 + C[0] + (s->current_picture.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
1713− C[1] = (1 + C[1] + (s->current_picture.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
1722+ C[0] = (1 + C[0] + (s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1;
1723+ C[1] = (1 + C[1] + (s->current_picture.motion_val[dir][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1;
17141724 }
17151725 if (s->mb_x == s->mb_width - 1) {
17161726 if (!v->is_intra[s->mb_x - s->mb_stride - 1]) {
@@ -1720,11 +1730,11 @@ static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, · 3 unmodified lines
17201730 if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) {
17211731 n_adj = n | 1;
17221732 }
1723− C[0] = s->current_picture.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][0];
1724− C[1] = s->current_picture.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][1];
1733+ C[0] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][0];
1734+ C[1] = s->current_picture.motion_val[dir][s->block_index[n_adj] - 2 * wrap - 2][1];
17251735 if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) {
1726− C[0] = (1 + C[0] + s->current_picture.motion_val[0][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
1727− C[1] = (1 + C[1] + s->current_picture.motion_val[0][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
1736+ C[0] = (1 + C[0] + s->current_picture.motion_val[dir][s->block_index[1] - 2 * wrap - 2][0]) >> 1;
1737+ C[1] = (1 + C[1] + s->current_picture.motion_val[dir][s->block_index[1] - 2 * wrap - 2][1]) >> 1;
17281738 }
17291739 } else
17301740 c_valid = 0;
@@ -1735,12 +1745,12 @@ static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, · 4 unmodified lines
17351745 } else {
17361746 pos_b = s->block_index[1];
17371747 b_valid = 1;
1738− B[0] = s->current_picture.motion_val[0][pos_b][0];
1739− B[1] = s->current_picture.motion_val[0][pos_b][1];
1748+ B[0] = s->current_picture.motion_val[dir][pos_b][0];
1749+ B[1] = s->current_picture.motion_val[dir][pos_b][1];
17401750 pos_c = s->block_index[0];
17411751 c_valid = 1;
1742− C[0] = s->current_picture.motion_val[0][pos_c][0];
1743− C[1] = s->current_picture.motion_val[0][pos_c][1];
1752+ C[0] = s->current_picture.motion_val[dir][pos_c][0];
1753+ C[1] = s->current_picture.motion_val[dir][pos_c][1];
17441754 }
17451755
17461756 total_valid = a_valid + b_valid + c_valid;
@@ -1829,20 +1839,20 @@ static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, · 82 unmodified lines
18291839 }
18301840
18311841 /* store MV using signed modulus of MV range defined in 4.11 */
1832− s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
1833− s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
1842+ s->mv[dir][n][0] = s->current_picture.motion_val[dir][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x;
1843+ s->mv[dir][n][1] = s->current_picture.motion_val[dir][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y;
18341844 if (mvn == 1) { /* duplicate motion data for 1-MV block */
1835− s->current_picture.motion_val[0][xy + 1 ][0] = s->current_picture.motion_val[0][xy][0];
1836− s->current_picture.motion_val[0][xy + 1 ][1] = s->current_picture.motion_val[0][xy][1];
1837− s->current_picture.motion_val[0][xy + wrap ][0] = s->current_picture.motion_val[0][xy][0];
1838− s->current_picture.motion_val[0][xy + wrap ][1] = s->current_picture.motion_val[0][xy][1];
1839− s->current_picture.motion_val[0][xy + wrap + 1][0] = s->current_picture.motion_val[0][xy][0];
1840− s->current_picture.motion_val[0][xy + wrap + 1][1] = s->current_picture.motion_val[0][xy][1];
1845+ s->current_picture.motion_val[dir][xy + 1 ][0] = s->current_picture.motion_val[dir][xy][0];
1846+ s->current_picture.motion_val[dir][xy + 1 ][1] = s->current_picture.motion_val[dir][xy][1];
1847+ s->current_picture.motion_val[dir][xy + wrap ][0] = s->current_picture.motion_val[dir][xy][0];
1848+ s->current_picture.motion_val[dir][xy + wrap ][1] = s->current_picture.motion_val[dir][xy][1];
1849+ s->current_picture.motion_val[dir][xy + wrap + 1][0] = s->current_picture.motion_val[dir][xy][0];
1850+ s->current_picture.motion_val[dir][xy + wrap + 1][1] = s->current_picture.motion_val[dir][xy][1];
18411851 } else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */
1842− s->current_picture.motion_val[0][xy + 1][0] = s->current_picture.motion_val[0][xy][0];
1843− s->current_picture.motion_val[0][xy + 1][1] = s->current_picture.motion_val[0][xy][1];
1844− s->mv[0][n + 1][0] = s->mv[0][n][0];
1845− s->mv[0][n + 1][1] = s->mv[0][n][1];
1852+ s->current_picture.motion_val[dir][xy + 1][0] = s->current_picture.motion_val[dir][xy][0];
1853+ s->current_picture.motion_val[dir][xy + 1][1] = s->current_picture.motion_val[dir][xy][1];
1854+ s->mv[dir][n + 1][0] = s->mv[dir][n][0];
1855+ s->mv[dir][n + 1][1] = s->mv[dir][n][1];
18461856 }
18471857 }
18481858
@@ -3588,7 +3598,7 @@ static int vc1_decode_p_mb(VC1Context *v) · 1739 unmodified lines
35883598 }
35893599 vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
35903600 if (!s->mb_intra)
3591− vc1_mc_4mv_luma(v, i, 0);
3601+ vc1_mc_4mv_luma(v, i, 0, 0);
35923602 intra_count += s->mb_intra;
35933603 is_intra[i] = s->mb_intra;
35943604 is_coded[i] = mb_has_coeffs;
@@ -3678,7 +3688,7 @@ static int vc1_decode_p_mb(VC1Context *v) · 83 unmodified lines
36783688 }
36793689 for (i = 0; i < 4; i++) {
36803690 vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0);
3681− vc1_mc_4mv_luma(v, i, 0);
3691+ vc1_mc_4mv_luma(v, i, 0, 0);
36823692 }
36833693 vc1_mc_4mv_chroma(v, 0);
36843694 s->current_picture.qscale_table[mb_pos] = 0;
@@ -3756,8 +3766,10 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) · 71 unmodified lines
37563766 break;
37573767 }
37583768 if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) { // intra MB
3759− s->current_picture.motion_val[1][s->block_index[0]][0] = 0;
3760− s->current_picture.motion_val[1][s->block_index[0]][1] = 0;
3769+ for (i = 0; i < 4; i++) {
3770+ s->current_picture.motion_val[1][s->block_index[i]][0] = 0;
3771+ s->current_picture.motion_val[1][s->block_index[i]][1] = 0;
3772+ }
37613773 s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
37623774 s->mb_intra = v->is_intra[s->mb_x] = 1;
37633775 for (i = 0; i < 6; i++)
@@ -3826,8 +3838,8 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) · 62 unmodified lines
38263838 if (val) {
38273839 get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
38283840 }
3829− vc1_pred_mv_intfr(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]);
3830− vc1_mc_4mv_luma(v, i, 0);
3841+ vc1_pred_mv_intfr(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0);
3842+ vc1_mc_4mv_luma(v, i, 0, 0);
38313843 } else if (i == 4) {
38323844 vc1_mc_4mv_chroma4(v);
38333845 }
@@ -3838,16 +3850,16 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) · 4 unmodified lines
38383850 if (mvbp & 2) {
38393851 get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
38403852 }
3841− vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0]);
3842− vc1_mc_4mv_luma(v, 0, 0);
3843− vc1_mc_4mv_luma(v, 1, 0);
3853+ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], 0);
3854+ vc1_mc_4mv_luma(v, 0, 0, 0);
3855+ vc1_mc_4mv_luma(v, 1, 0, 0);
38443856 dmv_x = dmv_y = 0;
38453857 if (mvbp & 1) {
38463858 get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
38473859 }
3848− vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0]);
3849− vc1_mc_4mv_luma(v, 2, 0);
3850− vc1_mc_4mv_luma(v, 3, 0);
3860+ vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], 0);
3861+ vc1_mc_4mv_luma(v, 2, 0, 0);
3862+ vc1_mc_4mv_luma(v, 3, 0, 0);
38513863 vc1_mc_4mv_chroma4(v);
38523864 } else {
38533865 mvbp = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][2];
@@ -3855,7 +3867,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) · 1 unmodified line
38553867 if (mvbp) {
38563868 get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
38573869 }
3858− vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]);
3870+ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0);
38593871 vc1_mc_1mv(v, 0);
38603872 }
38613873 if (cbp)
@@ -3895,7 +3907,7 @@ static int vc1_decode_p_mb_intfr(VC1Context *v) · 33 unmodified lines
38953907 v->blk_mv_type[s->block_index[1]] = 0;
38963908 v->blk_mv_type[s->block_index[2]] = 0;
38973909 v->blk_mv_type[s->block_index[3]] = 0;
3898− vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]);
3910+ vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0);
38993911 vc1_mc_1mv(v, 0);
39003912 }
39013913 if (s->mb_x == s->mb_width - 1)
@@ -3982,7 +3994,7 @@ static int vc1_decode_p_mb_intfi(VC1Context *v) · 80 unmodified lines
39823994 get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag);
39833995 }
39843996 vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0);
3985− vc1_mc_4mv_luma(v, i, 0);
3997+ vc1_mc_4mv_luma(v, i, 0, 0);
39863998 } else if (i == 4)
39873999 vc1_mc_4mv_chroma(v, 0);
39884000 }
@@ -4291,7 +4303,7 @@ static void vc1_decode_b_mb_intfi(VC1Context *v) · 302 unmodified lines
42914303 &pred_flag[bmvtype == BMV_TYPE_BACKWARD]);
42924304 }
42934305 vc1_pred_b_mv_intfi(v, i, dmv_x, dmv_y, 0, pred_flag);
4294− vc1_mc_4mv_luma(v, i, bmvtype == BMV_TYPE_BACKWARD);
4306+ vc1_mc_4mv_luma(v, i, bmvtype == BMV_TYPE_BACKWARD, 0);
42954307 } else if (i == 4)
42964308 vc1_mc_4mv_chroma(v, bmvtype == BMV_TYPE_BACKWARD);
42974309 }
@@ -4325,6 +4337,355 @@ static void vc1_decode_b_mb_intfi(VC1Context *v) · 27 unmodified lines
43254337 }
43264338 }
43274339
4340+/** Decode one B-frame MB (in interlaced frame B picture)
4341+ */
4342+static int vc1_decode_b_mb_intfr(VC1Context *v)
4343+{
4344+ MpegEncContext *s = &v->s;
4345+ GetBitContext *gb = &s->gb;
4346+ int i, j;
4347+ int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
4348+ int cbp = 0; /* cbp decoding stuff */
4349+ int mqdiff, mquant; /* MB quantization */
4350+ int ttmb = v->ttfrm; /* MB Transform type */
4351+ int mvsw = 0; /* motion vector switch */
4352+ int mb_has_coeffs = 1; /* last_flag */
4353+ int dmv_x, dmv_y; /* Differential MV components */
4354+ int val; /* temp value */
4355+ int first_block = 1;
4356+ int dst_idx, off;
4357+ int skipped, direct, twomv = 0;
4358+ int block_cbp = 0, pat, block_tt = 0;
4359+ int idx_mbmode = 0, mvbp;
4360+ int stride_y, fieldtx;
4361+ int bmvtype = BMV_TYPE_BACKWARD;
4362+ int dir, dir2;
4363+
4364+ mquant = v->pq; /* Lossy initialization */
4365+ s->mb_intra = 0;
4366+ if (v->skip_is_raw)
4367+ skipped = get_bits1(gb);
4368+ else
4369+ skipped = v->s.mbskip_table[mb_pos];
4370+
4371+ if (!skipped) {
4372+ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2);
4373+ if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD)
4374+ {
4375+ twomv = 1;
4376+ v->blk_mv_type[s->block_index[0]] = 1;
4377+ v->blk_mv_type[s->block_index[1]] = 1;
4378+ v->blk_mv_type[s->block_index[2]] = 1;
4379+ v->blk_mv_type[s->block_index[3]] = 1;
4380+ } else {
4381+ v->blk_mv_type[s->block_index[0]] = 0;
4382+ v->blk_mv_type[s->block_index[1]] = 0;
4383+ v->blk_mv_type[s->block_index[2]] = 0;
4384+ v->blk_mv_type[s->block_index[3]] = 0;
4385+ }
4386+ }
4387+
4388+ if (v->dmb_is_raw)
4389+ direct = get_bits1(gb);
4390+ else
4391+ direct = v->direct_mb_plane[mb_pos];
4392+
4393+ if (direct) {
4394+ s->mv[0][0][0] = s->current_picture.motion_val[0][s->block_index[0]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][0], v->bfraction, 0, s->quarter_sample);
4395+ s->mv[0][0][1] = s->current_picture.motion_val[0][s->block_index[0]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][1], v->bfraction, 0, s->quarter_sample);
4396+ s->mv[1][0][0] = s->current_picture.motion_val[1][s->block_index[0]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][0], v->bfraction, 1, s->quarter_sample);
4397+ s->mv[1][0][1] = s->current_picture.motion_val[1][s->block_index[0]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[0]][1], v->bfraction, 1, s->quarter_sample);
4398+
4399+ if (twomv) {
4400+ s->mv[0][2][0] = s->current_picture.motion_val[0][s->block_index[2]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][0], v->bfraction, 0, s->quarter_sample);
4401+ s->mv[0][2][1] = s->current_picture.motion_val[0][s->block_index[2]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][1], v->bfraction, 0, s->quarter_sample);
4402+ s->mv[1][2][0] = s->current_picture.motion_val[1][s->block_index[2]][0] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][0], v->bfraction, 1, s->quarter_sample);
4403+ s->mv[1][2][1] = s->current_picture.motion_val[1][s->block_index[2]][1] = scale_mv(s->next_picture.motion_val[1][s->block_index[2]][1], v->bfraction, 1, s->quarter_sample);
4404+
4405+ for (i = 1; i < 4; i+=2) {
4406+ s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = s->mv[0][i-1][0];
4407+ s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = s->mv[0][i-1][1];
4408+ s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = s->mv[1][i-1][0];
4409+ s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = s->mv[1][i-1][1];
4410+ }
4411+ } else {
4412+ for (i = 1; i < 4; i++) {
4413+ s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = s->mv[0][0][0];
4414+ s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = s->mv[0][0][1];
4415+ s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = s->mv[1][0][0];
4416+ s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = s->mv[1][0][1];
4417+ }
4418+ }
4419+ }
4420+
4421+ if (ff_vc1_mbmode_intfrp[0][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) { // intra MB
4422+ for (i = 0; i < 4; i++) {
4423+ s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0] = 0;
4424+ s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1] = 0;
4425+ s->mv[1][i][0] = s->current_picture.motion_val[1][s->block_index[i]][0] = 0;
4426+ s->mv[1][i][1] = s->current_picture.motion_val[1][s->block_index[i]][1] = 0;
4427+ }
4428+ s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA;
4429+ s->mb_intra = v->is_intra[s->mb_x] = 1;
4430+ for (i = 0; i < 6; i++)
4431+ v->mb_type[0][s->block_index[i]] = 1;
4432+ fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb);
4433+ mb_has_coeffs = get_bits1(gb);
4434+ if (mb_has_coeffs)
4435+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
4436+ v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb);
4437+ GET_MQUANT();
4438+ s->current_picture.qscale_table[mb_pos] = mquant;
4439+ /* Set DC scale - y and c use the same (not sure if necessary here) */
4440+ s->y_dc_scale = s->y_dc_scale_table[mquant];
4441+ s->c_dc_scale = s->c_dc_scale_table[mquant];
4442+ dst_idx = 0;
4443+ for (i = 0; i < 6; i++) {
4444+ s->dc_val[0][s->block_index[i]] = 0;
4445+ dst_idx += i >> 2;
4446+ val = ((cbp >> (5 - i)) & 1);
4447+ v->mb_type[0][s->block_index[i]] = s->mb_intra;
4448+ v->a_avail = v->c_avail = 0;
4449+ if (i == 2 || i == 3 || !s->first_slice_line)
4450+ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]];
4451+ if (i == 1 || i == 3 || s->mb_x)
4452+ v->c_avail = v->mb_type[0][s->block_index[i] - 1];
4453+
4454+ vc1_decode_intra_block(v, s->block[i], i, val, mquant,
4455+ (i & 4) ? v->codingset2 : v->codingset);
4456+ if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue;
4457+ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]);
4458+ if (i < 4) {
4459+ stride_y = s->linesize << fieldtx;
4460+ off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize;
4461+ } else {
4462+ stride_y = s->uvlinesize;
4463+ off = 0;
4464+ }
4465+ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, stride_y);
4466+ }
4467+ } else {
4468+ s->mb_intra = v->is_intra[s->mb_x] = 0;
4469+ if (!direct) {
4470+ if (skipped || !s->mb_intra) {
4471+ bmvtype = decode012(gb);
4472+ switch (bmvtype) {
4473+ case 0:
4474+ bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD;
4475+ break;
4476+ case 1:
4477+ bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD;
4478+ break;
4479+ case 2:
4480+ bmvtype = BMV_TYPE_INTERPOLATED;
4481+ }
4482+ }
4483+
4484+ if (twomv && bmvtype != BMV_TYPE_INTERPOLATED)
4485+ mvsw = get_bits1(gb);
4486+ }
4487+
4488+ if (!skipped) { // inter MB
4489+ mb_has_coeffs = ff_vc1_mbmode_intfrp[0][idx_mbmode][3];
4490+ if (mb_has_coeffs)
4491+ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
4492+ if (!direct) {
4493+ if (bmvtype == BMV_TYPE_INTERPOLATED & twomv) {
4494+ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1);
4495+ }
4496+ else if (bmvtype == BMV_TYPE_INTERPOLATED | twomv) {
4497+ v->twomvbp = get_vlc2(gb, v->twomvbp_vlc->table, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1);
4498+ }
4499+ }
4500+
4501+ for (i = 0; i < 6; i++)
4502+ v->mb_type[0][s->block_index[i]] = 0;
4503+ fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[0][idx_mbmode][1];
4504+ /* for all motion vector read MVDATA and motion compensate each block */
4505+ dst_idx = 0;
4506+ if (direct) {
4507+ if (twomv) {
4508+ for (i = 0; i < 4; i++) {
4509+ vc1_mc_4mv_luma(v, i, 0, 0);
4510+ vc1_mc_4mv_luma(v, i, 1, 1);
4511+ }
4512+ vc1_mc_4mv_chroma4(v);
4513+ } else {
4514+ vc1_mc_1mv(v, 0);
4515+ vc1_interp_mc(v);
4516+ }
4517+ } else if (twomv && bmvtype == BMV_TYPE_INTERPOLATED) {
4518+ mvbp = v->fourmvbp;
4519+ for (i = 0; i < 4; i++) {
4520+ dir = i==1 || i==3;
4521+ dmv_x = dmv_y = 0;
4522+ val = ((mvbp >> (3 - i)) & 1);
4523+ if (val) {
4524+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
4525+ }
4526+ j = i > 1 ? 2 : 0;
4527+ vc1_pred_mv_intfr(v, j, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir);
4528+ vc1_mc_4mv_luma(v, j, dir, dir);
4529+ vc1_mc_4mv_luma(v, j+1, dir, dir);
4530+ }
4531+
4532+ vc1_mc_4mv_chroma4(v);
4533+ } else if (bmvtype == BMV_TYPE_INTERPOLATED) {
4534+ mvbp = v->twomvbp;
4535+ dmv_x = dmv_y = 0;
4536+ if (mvbp & 2) {
4537+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
4538+ }
4539+
4540+ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0);
4541+ vc1_mc_1mv(v, 0);
4542+
4543+ dmv_x = dmv_y = 0;
4544+ if (mvbp & 1) {
4545+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
4546+ }
4547+
4548+ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 1);
4549+ vc1_interp_mc(v);
4550+ } else if (twomv) {
4551+ dir = bmvtype == BMV_TYPE_BACKWARD;
4552+ dir2 = dir;
4553+ if (mvsw)
4554+ dir2 = !dir;
4555+ mvbp = v->twomvbp;
4556+ dmv_x = dmv_y = 0;
4557+ if (mvbp & 2) {
4558+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
4559+ }
4560+ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir);
4561+
4562+ dmv_x = dmv_y = 0;
4563+ if (mvbp & 1) {
4564+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
4565+ }
4566+ vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0], dir2);
4567+
4568+ if (mvsw) {
4569+ for (i = 0; i<2; i++) {
4570+ s->mv[dir][i+2][0] = s->mv[dir][i][0] = s->current_picture.motion_val[dir][s->block_index[i+2]][0] = s->current_picture.motion_val[dir][s->block_index[i]][0];
4571+ s->mv[dir][i+2][1] = s->mv[dir][i][1] = s->current_picture.motion_val[dir][s->block_index[i+2]][1] = s->current_picture.motion_val[dir][s->block_index[i]][1];
4572+ s->mv[dir2][i+2][0] = s->mv[dir2][i][0] = s->current_picture.motion_val[dir2][s->block_index[i]][0] = s->current_picture.motion_val[dir2][s->block_index[i+2]][0];
4573+ s->mv[dir2][i+2][1] = s->mv[dir2][i][1] = s->current_picture.motion_val[dir2][s->block_index[i]][1] = s->current_picture.motion_val[dir2][s->block_index[i+2]][1];
4574+ }
4575+ } else {
4576+ vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, v->mb_type[0], !dir);
4577+ vc1_pred_mv_intfr(v, 2, 0, 0, 2, v->range_x, v->range_y, v->mb_type[0], !dir);
4578+ }
4579+
4580+ vc1_mc_4mv_luma(v, 0, dir, 0);
4581+ vc1_mc_4mv_luma(v, 1, dir, 0);
4582+ vc1_mc_4mv_luma(v, 2, dir2, 0);
4583+ vc1_mc_4mv_luma(v, 3, dir2, 0);
4584+ vc1_mc_4mv_chroma4(v);
4585+ } else {
4586+ dir = bmvtype == BMV_TYPE_BACKWARD;
4587+
4588+ mvbp = ff_vc1_mbmode_intfrp[0][idx_mbmode][2];
4589+ dmv_x = dmv_y = 0;
4590+ if (mvbp) {
4591+ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0);
4592+ }
4593+
4594+ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], dir);
4595+ v->blk_mv_type[s->block_index[0]] = 1;
4596+ v->blk_mv_type[s->block_index[1]] = 1;
4597+ v->blk_mv_type[s->block_index[2]] = 1;
4598+ v->blk_mv_type[s->block_index[3]] = 1;
4599+ vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, 0, !dir);
4600+ for (i = 0; i<2; i++) {
4601+ s->mv[!dir][i+2][0] = s->mv[!dir][i][0] = s->current_picture.motion_val[!dir][s->block_index[i+2]][0] = s->current_picture.motion_val[!dir][s->block_index[i]][0];
4602+ s->mv[!dir][i+2][1] = s->mv[!dir][i][1] = s->current_picture.motion_val[!dir][s->block_index[i+2]][1] = s->current_picture.motion_val[!dir][s->block_index[i]][1];
4603+ }
4604+ vc1_mc_1mv(v, dir);
4605+ }
4606+
4607+ if (cbp)
4608+ GET_MQUANT(); // p. 227
4609+ s->current_picture.qscale_table[mb_pos] = mquant;
4610+ if (!v->ttmbf && cbp)
4611+ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2);
4612+ for (i = 0; i < 6; i++) {
4613+ s->dc_val[0][s->block_index[i]] = 0;
4614+ dst_idx += i >> 2;
4615+ val = ((cbp >> (5 - i)) & 1);
4616+ if (!fieldtx)
4617+ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize);
4618+ else
4619+ off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize));
4620+ if (val) {
4621+ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb,
4622+ first_block, s->dest[dst_idx] + off,
4623+ (i & 4) ? s->uvlinesize : (s->linesize << fieldtx),
4624+ (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt);
4625+ block_cbp |= pat << (i << 2);
4626+ if (!v->ttmbf && ttmb < 8)
4627+ ttmb = -1;
4628+ first_block = 0;
4629+ }
4630+ }
4631+
4632+ } else { // skipped
4633+ dir = 0;
4634+ for (i = 0; i < 6; i++) {
4635+ v->mb_type[0][s->block_index[i]] = 0;
4636+ s->dc_val[0][s->block_index[i]] = 0;
4637+ }
4638+ s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP;
4639+ s->current_picture.qscale_table[mb_pos] = 0;
4640+ v->blk_mv_type[s->block_index[0]] = 0;
4641+ v->blk_mv_type[s->block_index[1]] = 0;
4642+ v->blk_mv_type[s->block_index[2]] = 0;
4643+ v->blk_mv_type[s->block_index[3]] = 0;
4644+
4645+ if (!direct) {
4646+ if (bmvtype == BMV_TYPE_INTERPOLATED) {
4647+ vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0);
4648+ vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 1);
4649+ } else {
4650+ dir = bmvtype == BMV_TYPE_BACKWARD;
4651+ vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], dir);
4652+ if (mvsw) {
4653+ int dir2 = dir;
4654+ if (mvsw)
4655+ dir2 = !dir;
4656+ for (i = 0; i<2; i++) {
4657+ s->mv[dir][i+2][0] = s->mv[dir][i][0] = s->current_picture.motion_val[dir][s->block_index[i+2]][0] = s->current_picture.motion_val[dir][s->block_index[i]][0];
4658+ s->mv[dir][i+2][1] = s->mv[dir][i][1] = s->current_picture.motion_val[dir][s->block_index[i+2]][1] = s->current_picture.motion_val[dir][s->block_index[i]][1];
4659+ s->mv[dir2][i+2][0] = s->mv[dir2][i][0] = s->current_picture.motion_val[dir2][s->block_index[i]][0] = s->current_picture.motion_val[dir2][s->block_index[i+2]][0];
4660+ s->mv[dir2][i+2][1] = s->mv[dir2][i][1] = s->current_picture.motion_val[dir2][s->block_index[i]][1] = s->current_picture.motion_val[dir2][s->block_index[i+2]][1];
4661+ }
4662+ } else {
4663+ v->blk_mv_type[s->block_index[0]] = 1;
4664+ v->blk_mv_type[s->block_index[1]] = 1;
4665+ v->blk_mv_type[s->block_index[2]] = 1;
4666+ v->blk_mv_type[s->block_index[3]] = 1;
4667+ vc1_pred_mv_intfr(v, 0, 0, 0, 2, v->range_x, v->range_y, 0, !dir);
4668+ for (i = 0; i<2; i++) {
4669+ s->mv[!dir][i+2][0] = s->mv[!dir][i][0] = s->current_picture.motion_val[!dir][s->block_index[i+2]][0] = s->current_picture.motion_val[!dir][s->block_index[i]][0];
4670+ s->mv[!dir][i+2][1] = s->mv[!dir][i][1] = s->current_picture.motion_val[!dir][s->block_index[i+2]][1] = s->current_picture.motion_val[!dir][s->block_index[i]][1];
4671+ }
4672+ }
4673+ }
4674+ }
4675+
4676+ vc1_mc_1mv(v, dir);
4677+ if (direct || bmvtype == BMV_TYPE_INTERPOLATED) {
4678+ vc1_interp_mc(v);
4679+ }
4680+ }
4681+ }
4682+ if (s->mb_x == s->mb_width - 1)
4683+ memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0])*s->mb_stride);
4684+ v->cbp[s->mb_x] = block_cbp;
4685+ v->ttblk[s->mb_x] = block_tt;
4686+ return 0;
4687+}
4688+
43284689 /** Decode blocks of I-frame
43294690 */
43304691 static void vc1_decode_i_blocks(VC1Context *v)
@@ -4714,6 +5075,8 @@ static void vc1_decode_b_blocks(VC1Context *v) · 383 unmodified lines
47145075
47155076 if (v->fcm == ILACE_FIELD)
47165077 vc1_decode_b_mb_intfi(v);
5078+ else if (v->fcm == ILACE_FRAME)
5079+ vc1_decode_b_mb_intfr(v);
47175080 else
47185081 vc1_decode_b_mb(v);
47195082 if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) {
@@ -5639,8 +6002,6 @@ static int vc1_decode_frame(AVCodecContext *avctx, void *data, · 919 unmodified lines
56396002 } else {
56406003 int header_ret = 0;
56416004
5642− if (v->fcm == ILACE_FRAME && s->pict_type == AV_PICTURE_TYPE_B)
5643− goto err; // This codepath is still incomplete thus it is disabled
56446005
56456006 ff_mpeg_er_frame_start(s);
56466007

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t