Revision 943f69a6 libavcodec/h264.c

View differences:

libavcodec/h264.c
726 726
    return;
727 727
}
728 728

  
729
static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){
730
    int poc0 = h->ref_list[0][i].poc;
731
    int td = av_clip(poc1 - poc0, -128, 127);
732
    if(td == 0 || h->ref_list[0][i].long_ref){
733
        return 256;
734
    }else{
735
        int tb = av_clip(poc - poc0, -128, 127);
736
        int tx = (16384 + (FFABS(td) >> 1)) / td;
737
        return av_clip((tb*tx + 32) >> 6, -1024, 1023);
738
    }
739
}
740

  
741
static inline void direct_dist_scale_factor(H264Context * const h){
742
    MpegEncContext * const s = &h->s;
743
    const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ];
744
    const int poc1 = h->ref_list[1][0].poc;
745
    int i, field;
746
    for(field=0; field<2; field++){
747
        const int poc  = h->s.current_picture_ptr->field_poc[field];
748
        const int poc1 = h->ref_list[1][0].field_poc[field];
749
        for(i=0; i < 2*h->ref_count[0]; i++)
750
            h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16);
751
    }
752

  
753
    for(i=0; i<h->ref_count[0]; i++){
754
        h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i);
755
    }
756
}
757

  
758
static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){
759
    MpegEncContext * const s = &h->s;
760
    Picture * const ref1 = &h->ref_list[1][0];
761
    int j, old_ref, rfield;
762
    int start= mbafi ? 16                      : 0;
763
    int end  = mbafi ? 16+2*h->ref_count[list] : h->ref_count[list];
764
    int interl= mbafi || s->picture_structure != PICT_FRAME;
765

  
766
    /* bogus; fills in for missing frames */
767
    memset(map[list], 0, sizeof(map[list]));
768

  
769
    for(rfield=0; rfield<2; rfield++){
770
        for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){
771
            int poc = ref1->ref_poc[colfield][list][old_ref];
772

  
773
            if     (!interl)
774
                poc |= 3;
775
            else if( interl && (poc&3) == 3) //FIXME store all MBAFF references so this isnt needed
776
                poc= (poc&~3) + rfield + 1;
777

  
778
            for(j=start; j<end; j++){
779
                if(4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3) == poc){
780
                    int cur_ref= mbafi ? (j-16)^field : j;
781
                    map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
782
                    if(rfield == field)
783
                        map[list][old_ref] = cur_ref;
784
                    break;
785
                }
786
            }
787
        }
788
    }
789
}
790

  
791
static inline void direct_ref_list_init(H264Context * const h){
792
    MpegEncContext * const s = &h->s;
793
    Picture * const ref1 = &h->ref_list[1][0];
794
    Picture * const cur = s->current_picture_ptr;
795
    int list, j, field;
796
    int sidx= (s->picture_structure&1)^1;
797
    int ref1sidx= (ref1->reference&1)^1;
798

  
799
    for(list=0; list<2; list++){
800
        cur->ref_count[sidx][list] = h->ref_count[list];
801
        for(j=0; j<h->ref_count[list]; j++)
802
            cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3);
803
    }
804

  
805
    if(s->picture_structure == PICT_FRAME){
806
        memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
807
        memcpy(cur->ref_poc  [1], cur->ref_poc  [0], sizeof(cur->ref_poc  [0]));
808
    }
809

  
810
    cur->mbaff= FRAME_MBAFF;
811

  
812
    if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
813
        return;
814

  
815
    for(list=0; list<2; list++){
816
        fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0);
817
        for(field=0; field<2; field++)
818
            fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1);
819
    }
820
}
821

  
822
static inline void pred_direct_motion(H264Context * const h, int *mb_type){
823
    MpegEncContext * const s = &h->s;
824
    int b8_stride = h->b8_stride;
825
    int b4_stride = h->b_stride;
826
    int mb_xy = h->mb_xy;
827
    int mb_type_col[2];
828
    const int16_t (*l1mv0)[2], (*l1mv1)[2];
829
    const int8_t *l1ref0, *l1ref1;
830
    const int is_b8x8 = IS_8X8(*mb_type);
831
    unsigned int sub_mb_type;
832
    int i8, i4;
833

  
834
    assert(h->ref_list[1][0].reference&3);
835

  
836
#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
837

  
838
    if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
839
        if(!IS_INTERLACED(*mb_type)){                    //     AFR/FR    -> AFL/FL
840
            int cur_poc = s->current_picture_ptr->poc;
841
            int *col_poc = h->ref_list[1]->field_poc;
842
            int col_parity = FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc);
843
            mb_xy= s->mb_x + ((s->mb_y&~1) + col_parity)*s->mb_stride;
844
            b8_stride = 0;
845
        }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){// FL -> FL & differ parity
846
            int fieldoff= 2*(h->ref_list[1][0].reference)-3;
847
            mb_xy += s->mb_stride*fieldoff;
848
        }
849
        goto single_col;
850
    }else{                                               // AFL/AFR/FR/FL -> AFR/FR
851
        if(IS_INTERLACED(*mb_type)){                     // AFL       /FL -> AFR/FR
852
            mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
853
            mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
854
            mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
855
            b8_stride *= 3;
856
            b4_stride *= 6;
857
            //FIXME IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag
858
            if(    (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
859
                && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
860
                && !is_b8x8){
861
                sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
862
                *mb_type   |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2; /* B_16x8 */
863
            }else{
864
                sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
865
                *mb_type   |= MB_TYPE_8x8|MB_TYPE_L0L1;
866
            }
867
        }else{                                           //     AFR/FR    -> AFR/FR
868
single_col:
869
            mb_type_col[0] =
870
            mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
871
            if(IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag){
872
                /* FIXME save sub mb types from previous frames (or derive from MVs)
873
                * so we know exactly what block size to use */
874
                sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */
875
                *mb_type   |= MB_TYPE_8x8|MB_TYPE_L0L1;
876
            }else if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
877
                sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
878
                *mb_type   |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */
879
            }else{
880
                sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
881
                *mb_type   |= MB_TYPE_8x8|MB_TYPE_L0L1;
882
            }
883
        }
884
    }
885

  
886
    l1mv0  = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
887
    l1mv1  = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
888
    l1ref0 = &h->ref_list[1][0].ref_index [0][h->mb2b8_xy[mb_xy]];
889
    l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]];
890
    if(!b8_stride){
891
        if(s->mb_y&1){
892
            l1ref0 += h->b8_stride;
893
            l1ref1 += h->b8_stride;
894
            l1mv0  +=  2*b4_stride;
895
            l1mv1  +=  2*b4_stride;
896
        }
897
    }
898

  
899
    if(h->direct_spatial_mv_pred){
900
        int ref[2];
901
        int mv[2][2];
902
        int list;
903

  
904
        /* FIXME interlacing + spatial direct uses wrong colocated block positions */
905

  
906
        /* ref = min(neighbors) */
907
        for(list=0; list<2; list++){
908
            int refa = h->ref_cache[list][scan8[0] - 1];
909
            int refb = h->ref_cache[list][scan8[0] - 8];
910
            int refc = h->ref_cache[list][scan8[0] - 8 + 4];
911
            if(refc == PART_NOT_AVAILABLE)
912
                refc = h->ref_cache[list][scan8[0] - 8 - 1];
913
            ref[list] = FFMIN3((unsigned)refa, (unsigned)refb, (unsigned)refc);
914
            if(ref[list] < 0)
915
                ref[list] = -1;
916
        }
917

  
918
        if(ref[0] < 0 && ref[1] < 0){
919
            ref[0] = ref[1] = 0;
920
            mv[0][0] = mv[0][1] =
921
            mv[1][0] = mv[1][1] = 0;
922
        }else{
923
            for(list=0; list<2; list++){
924
                if(ref[list] >= 0)
925
                    pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]);
926
                else
927
                    mv[list][0] = mv[list][1] = 0;
928
            }
929
        }
930

  
931
        if(ref[1] < 0){
932
            if(!is_b8x8)
933
                *mb_type &= ~MB_TYPE_L1;
934
            sub_mb_type &= ~MB_TYPE_L1;
935
        }else if(ref[0] < 0){
936
            if(!is_b8x8)
937
                *mb_type &= ~MB_TYPE_L0;
938
            sub_mb_type &= ~MB_TYPE_L0;
939
        }
940

  
941
        if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
942
            for(i8=0; i8<4; i8++){
943
                int x8 = i8&1;
944
                int y8 = i8>>1;
945
                int xy8 = x8+y8*b8_stride;
946
                int xy4 = 3*x8+y8*b4_stride;
947
                int a=0, b=0;
948

  
949
                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
950
                    continue;
951
                h->sub_mb_type[i8] = sub_mb_type;
952

  
953
                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
954
                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
955
                if(!IS_INTRA(mb_type_col[y8])
956
                   && (   (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
957
                       || (l1ref0[xy8]  < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){
958
                    if(ref[0] > 0)
959
                        a= pack16to32(mv[0][0],mv[0][1]);
960
                    if(ref[1] > 0)
961
                        b= pack16to32(mv[1][0],mv[1][1]);
962
                }else{
963
                    a= pack16to32(mv[0][0],mv[0][1]);
964
                    b= pack16to32(mv[1][0],mv[1][1]);
965
                }
966
                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
967
                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
968
            }
969
        }else if(IS_16X16(*mb_type)){
970
            int a=0, b=0;
971

  
972
            fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
973
            fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
974
            if(!IS_INTRA(mb_type_col[0])
975
               && (   (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
976
                   || (l1ref0[0]  < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
977
                       && (h->x264_build>33 || !h->x264_build)))){
978
                if(ref[0] > 0)
979
                    a= pack16to32(mv[0][0],mv[0][1]);
980
                if(ref[1] > 0)
981
                    b= pack16to32(mv[1][0],mv[1][1]);
982
            }else{
983
                a= pack16to32(mv[0][0],mv[0][1]);
984
                b= pack16to32(mv[1][0],mv[1][1]);
985
            }
986
            fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
987
            fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
988
        }else{
989
            for(i8=0; i8<4; i8++){
990
                const int x8 = i8&1;
991
                const int y8 = i8>>1;
992

  
993
                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
994
                    continue;
995
                h->sub_mb_type[i8] = sub_mb_type;
996

  
997
                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4);
998
                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4);
999
                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
1000
                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
1001

  
1002
                /* col_zero_flag */
1003
                if(!IS_INTRA(mb_type_col[0]) && (   l1ref0[x8 + y8*b8_stride] == 0
1004
                                              || (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0
1005
                                                  && (h->x264_build>33 || !h->x264_build)))){
1006
                    const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1;
1007
                    if(IS_SUB_8X8(sub_mb_type)){
1008
                        const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
1009
                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
1010
                            if(ref[0] == 0)
1011
                                fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
1012
                            if(ref[1] == 0)
1013
                                fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
1014
                        }
1015
                    }else
1016
                    for(i4=0; i4<4; i4++){
1017
                        const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
1018
                        if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
1019
                            if(ref[0] == 0)
1020
                                *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0;
1021
                            if(ref[1] == 0)
1022
                                *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0;
1023
                        }
1024
                    }
1025
                }
1026
            }
1027
        }
1028
    }else{ /* direct temporal mv pred */
1029
        const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
1030
        const int *dist_scale_factor = h->dist_scale_factor;
1031
        int ref_offset= 0;
1032

  
1033
        if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){
1034
            map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0];
1035
            map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1];
1036
            dist_scale_factor   =h->dist_scale_factor_field[s->mb_y&1];
1037
        }
1038
        if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0]))
1039
            ref_offset += 16;
1040

  
1041
        if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
1042
            /* FIXME assumes direct_8x8_inference == 1 */
1043
            int y_shift  = 2*!IS_INTERLACED(*mb_type);
1044

  
1045
            for(i8=0; i8<4; i8++){
1046
                const int x8 = i8&1;
1047
                const int y8 = i8>>1;
1048
                int ref0, scale;
1049
                const int16_t (*l1mv)[2]= l1mv0;
1050

  
1051
                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
1052
                    continue;
1053
                h->sub_mb_type[i8] = sub_mb_type;
1054

  
1055
                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
1056
                if(IS_INTRA(mb_type_col[y8])){
1057
                    fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
1058
                    fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
1059
                    fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
1060
                    continue;
1061
                }
1062

  
1063
                ref0 = l1ref0[x8 + y8*b8_stride];
1064
                if(ref0 >= 0)
1065
                    ref0 = map_col_to_list0[0][ref0 + ref_offset];
1066
                else{
1067
                    ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
1068
                    l1mv= l1mv1;
1069
                }
1070
                scale = dist_scale_factor[ref0];
1071
                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
1072

  
1073
                {
1074
                    const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
1075
                    int my_col = (mv_col[1]<<y_shift)/2;
1076
                    int mx = (scale * mv_col[0] + 128) >> 8;
1077
                    int my = (scale * my_col + 128) >> 8;
1078
                    fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
1079
                    fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
1080
                }
1081
            }
1082
            return;
1083
        }
1084

  
1085
        /* one-to-one mv scaling */
1086

  
1087
        if(IS_16X16(*mb_type)){
1088
            int ref, mv0, mv1;
1089

  
1090
            fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
1091
            if(IS_INTRA(mb_type_col[0])){
1092
                ref=mv0=mv1=0;
1093
            }else{
1094
                const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
1095
                                                : map_col_to_list0[1][l1ref1[0] + ref_offset];
1096
                const int scale = dist_scale_factor[ref0];
1097
                const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
1098
                int mv_l0[2];
1099
                mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
1100
                mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
1101
                ref= ref0;
1102
                mv0= pack16to32(mv_l0[0],mv_l0[1]);
1103
                mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
1104
            }
1105
            fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
1106
            fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
1107
            fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
1108
        }else{
1109
            for(i8=0; i8<4; i8++){
1110
                const int x8 = i8&1;
1111
                const int y8 = i8>>1;
1112
                int ref0, scale;
1113
                const int16_t (*l1mv)[2]= l1mv0;
1114

  
1115
                if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
1116
                    continue;
1117
                h->sub_mb_type[i8] = sub_mb_type;
1118
                fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
1119
                if(IS_INTRA(mb_type_col[0])){
1120
                    fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
1121
                    fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
1122
                    fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
1123
                    continue;
1124
                }
1125

  
1126
                ref0 = l1ref0[x8 + y8*b8_stride] + ref_offset;
1127
                if(ref0 >= 0)
1128
                    ref0 = map_col_to_list0[0][ref0];
1129
                else{
1130
                    ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
1131
                    l1mv= l1mv1;
1132
                }
1133
                scale = dist_scale_factor[ref0];
1134

  
1135
                fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
1136
                if(IS_SUB_8X8(sub_mb_type)){
1137
                    const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
1138
                    int mx = (scale * mv_col[0] + 128) >> 8;
1139
                    int my = (scale * mv_col[1] + 128) >> 8;
1140
                    fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
1141
                    fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4);
1142
                }else
1143
                for(i4=0; i4<4; i4++){
1144
                    const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
1145
                    int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]];
1146
                    mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
1147
                    mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
1148
                    *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] =
1149
                        pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
1150
                }
1151
            }
1152
        }
1153
    }
1154
}
1155

  
1156 729
static inline void write_back_motion(H264Context *h, int mb_type){
1157 730
    MpegEncContext * const s = &h->s;
1158 731
    const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride;
......
3871 3444
        fill_mbaff_ref_list(h);
3872 3445

  
3873 3446
    if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred)
3874
        direct_dist_scale_factor(h);
3875
    direct_ref_list_init(h);
3447
        ff_h264_direct_dist_scale_factor(h);
3448
    ff_h264_direct_ref_list_init(h);
3876 3449

  
3877 3450
    if( h->slice_type_nos != FF_I_TYPE && h->pps.cabac ){
3878 3451
        tmp = get_ue_golomb_31(&s->gb);
......
4239 3812
        mb_type|= MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP;
4240 3813

  
4241 3814
        fill_caches(h, mb_type, 0); //FIXME check what is needed and what not ...
4242
        pred_direct_motion(h, &mb_type);
3815
        ff_h264_pred_direct_motion(h, &mb_type);
4243 3816
        mb_type|= MB_TYPE_SKIP;
4244 3817
    }
4245 3818
    else
......
4417 3990
            }
4418 3991
            if(   IS_DIRECT(h->sub_mb_type[0]) || IS_DIRECT(h->sub_mb_type[1])
4419 3992
               || IS_DIRECT(h->sub_mb_type[2]) || IS_DIRECT(h->sub_mb_type[3])) {
4420
                pred_direct_motion(h, &mb_type);
3993
                ff_h264_pred_direct_motion(h, &mb_type);
4421 3994
                h->ref_cache[0][scan8[4]] =
4422 3995
                h->ref_cache[1][scan8[4]] =
4423 3996
                h->ref_cache[0][scan8[12]] =
......
4508 4081
            }
4509 4082
        }
4510 4083
    }else if(IS_DIRECT(mb_type)){
4511
        pred_direct_motion(h, &mb_type);
4084
        ff_h264_pred_direct_motion(h, &mb_type);
4512 4085
        dct8x8_allowed &= h->sps.direct_8x8_inference_flag;
4513 4086
    }else{
4514 4087
        int list, mx, my, i;
......
5514 5087
            }
5515 5088
            if( IS_DIRECT(h->sub_mb_type[0] | h->sub_mb_type[1] |
5516 5089
                          h->sub_mb_type[2] | h->sub_mb_type[3]) ) {
5517
                pred_direct_motion(h, &mb_type);
5090
                ff_h264_pred_direct_motion(h, &mb_type);
5518 5091
                h->ref_cache[0][scan8[4]] =
5519 5092
                h->ref_cache[1][scan8[4]] =
5520 5093
                h->ref_cache[0][scan8[12]] =
......
5617 5190
            }
5618 5191
        }
5619 5192
    } else if( IS_DIRECT(mb_type) ) {
5620
        pred_direct_motion(h, &mb_type);
5193
        ff_h264_pred_direct_motion(h, &mb_type);
5621 5194
        fill_rectangle(h->mvd_cache[0][scan8[0]], 4, 4, 8, 0, 4);
5622 5195
        fill_rectangle(h->mvd_cache[1][scan8[0]], 4, 4, 8, 0, 4);
5623 5196
        dct8x8_allowed &= h->sps.direct_8x8_inference_flag;

Also available in: Unified diff