annotate h264_direct.c @ 10893:2aafcafbe1f0 libavcodec

Replace cabac checks in inline functions from h264.h with constants. No benchmark because its just replacing variables with litteral constants (so no risk for slowdown outside gcc silliness) and i need sleep.
author michael
date Sat, 16 Jan 2010 05:41:33 +0000
parents e3f5eb016712
children b847f02d5b03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
1 /*
10857
b20434143fd5 Split direct mode (macro)block decoding off h264.c.
michael
parents: 10854
diff changeset
2 * H.26L/H.264/AVC/JVT/14496-10/... direct mb/block decoding
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
4 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3927
diff changeset
5 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3927
diff changeset
6 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3927
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3927
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
11 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3927
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
15 * Lesser General Public License for more details.
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
16 *
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3927
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 3029
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
20 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2962
diff changeset
21
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
22 /**
10857
b20434143fd5 Split direct mode (macro)block decoding off h264.c.
michael
parents: 10854
diff changeset
23 * @file libavcodec/h264_direct.c
b20434143fd5 Split direct mode (macro)block decoding off h264.c.
michael
parents: 10854
diff changeset
24 * H.264 / AVC / MPEG4 part10 direct mb/block decoding.
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
25 * @author Michael Niedermayer <michaelni@gmx.at>
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
26 */
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
27
9012
15a3df8c01fd More approved hunks for VAAPI & our new and cleaner hwaccel API.
michael
parents: 9004
diff changeset
28 #include "internal.h"
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
29 #include "dsputil.h"
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
30 #include "avcodec.h"
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
31 #include "mpegvideo.h"
4975
9a6a0818e93f split h264.c to move parser in its own file
aurel
parents: 4931
diff changeset
32 #include "h264.h"
10864
e3f5eb016712 Split motion vector prediction off h264.c/h.
michael
parents: 10857
diff changeset
33 #include "h264_mvpred.h"
6020
c531defb03ee Make fill_rectangle() available for other decoders
kostya
parents: 6019
diff changeset
34 #include "rectangle.h"
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
35
8590
7a463923ecd1 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 8565
diff changeset
36 #if ARCH_X86
8430
7768bdfd4f7b Rename libavcodec/i386/ --> libavcodec/x86/.
diego
parents: 8424
diff changeset
37 #include "x86/h264_i386.h"
6604
e226f34ca284 Redo r12838, this time using svn copy to create h264_i386.h from cabac.h.
heydowns
parents: 6603
diff changeset
38 #endif
1908
e20fd60b215c h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents: 1899
diff changeset
39
3284
a224d9752912 don't force asserts in release builds. 2% faster h264.
lorenm
parents: 3219
diff changeset
40 //#undef NDEBUG
1168
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
41 #include <assert.h>
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
42
5af9aeadbdc3 H264 decoder & demuxer
michaelni
parents:
diff changeset
43
7898
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
44 static int get_scale_factor(H264Context * const h, int poc, int poc1, int i){
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
45 int poc0 = h->ref_list[0][i].poc;
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
46 int td = av_clip(poc1 - poc0, -128, 127);
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
47 if(td == 0 || h->ref_list[0][i].long_ref){
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
48 return 256;
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
49 }else{
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
50 int tb = av_clip(poc - poc0, -128, 127);
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
51 int tx = (16384 + (FFABS(td) >> 1)) / td;
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
52 return av_clip((tb*tx + 32) >> 6, -1024, 1023);
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
53 }
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
54 }
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
55
10857
b20434143fd5 Split direct mode (macro)block decoding off h264.c.
michael
parents: 10854
diff changeset
56 void ff_h264_direct_dist_scale_factor(H264Context * const h){
7462
5cbf11f56c02 Picture.ref_count/ref_poc have to be stored per field (actually also per
michael
parents: 7450
diff changeset
57 MpegEncContext * const s = &h->s;
5cbf11f56c02 Picture.ref_count/ref_poc have to be stored per field (actually also per
michael
parents: 7450
diff changeset
58 const int poc = h->s.current_picture_ptr->field_poc[ s->picture_structure == PICT_BOTTOM_FIELD ];
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
59 const int poc1 = h->ref_list[1][0].poc;
7898
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
60 int i, field;
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
61 for(field=0; field<2; field++){
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
62 const int poc = h->s.current_picture_ptr->field_poc[field];
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
63 const int poc1 = h->ref_list[1][0].field_poc[field];
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
64 for(i=0; i < 2*h->ref_count[0]; i++)
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
65 h->dist_scale_factor_field[field][i^field] = get_scale_factor(h, poc, poc1, i+16);
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
66 }
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
67
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
68 for(i=0; i<h->ref_count[0]; i++){
7898
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
69 h->dist_scale_factor[i] = get_scale_factor(h, poc, poc1, i);
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
70 }
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
71 }
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
72
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
73 static void fill_colmap(H264Context *h, int map[2][16+32], int list, int field, int colfield, int mbafi){
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
74 MpegEncContext * const s = &h->s;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
75 Picture * const ref1 = &h->ref_list[1][0];
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
76 int j, old_ref, rfield;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
77 int start= mbafi ? 16 : 0;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
78 int end = mbafi ? 16+2*h->ref_count[list] : h->ref_count[list];
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
79 int interl= mbafi || s->picture_structure != PICT_FRAME;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
80
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
81 /* bogus; fills in for missing frames */
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
82 memset(map[list], 0, sizeof(map[list]));
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
83
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
84 for(rfield=0; rfield<2; rfield++){
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
85 for(old_ref=0; old_ref<ref1->ref_count[colfield][list]; old_ref++){
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
86 int poc = ref1->ref_poc[colfield][list][old_ref];
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
87
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
88 if (!interl)
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
89 poc |= 3;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
90 else if( interl && (poc&3) == 3) //FIXME store all MBAFF references so this isnt needed
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
91 poc= (poc&~3) + rfield + 1;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
92
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
93 for(j=start; j<end; j++){
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
94 if(4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3) == poc){
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
95 int cur_ref= mbafi ? (j-16)^field : j;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
96 map[list][2*old_ref + (rfield^field) + 16] = cur_ref;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
97 if(rfield == field)
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
98 map[list][old_ref] = cur_ref;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
99 break;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
100 }
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
101 }
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
102 }
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
103 }
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
104 }
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
105
10857
b20434143fd5 Split direct mode (macro)block decoding off h264.c.
michael
parents: 10854
diff changeset
106 void ff_h264_direct_ref_list_init(H264Context * const h){
2537
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
107 MpegEncContext * const s = &h->s;
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
108 Picture * const ref1 = &h->ref_list[1][0];
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
109 Picture * const cur = s->current_picture_ptr;
7928
7d897cb94a31 Remove unused variable.
diego
parents: 7926
diff changeset
110 int list, j, field;
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
111 int sidx= (s->picture_structure&1)^1;
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
112 int ref1sidx= (ref1->reference&1)^1;
7907
8eb69709a934 A few empty lines for readability.
michael
parents: 7906
diff changeset
113
2537
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
114 for(list=0; list<2; list++){
7462
5cbf11f56c02 Picture.ref_count/ref_poc have to be stored per field (actually also per
michael
parents: 7450
diff changeset
115 cur->ref_count[sidx][list] = h->ref_count[list];
2537
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
116 for(j=0; j<h->ref_count[list]; j++)
7487
13937730e79d Use frame_num and reference instead of poc for matching frames for direct
michael
parents: 7486
diff changeset
117 cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3);
2537
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
118 }
7907
8eb69709a934 A few empty lines for readability.
michael
parents: 7906
diff changeset
119
7482
ecf3c774f5e1 Fill ref_count/ref_poc for both fields of frames.
michael
parents: 7481
diff changeset
120 if(s->picture_structure == PICT_FRAME){
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
121 memcpy(cur->ref_count[1], cur->ref_count[0], sizeof(cur->ref_count[0]));
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
122 memcpy(cur->ref_poc [1], cur->ref_poc [0], sizeof(cur->ref_poc [0]));
7482
ecf3c774f5e1 Fill ref_count/ref_poc for both fields of frames.
michael
parents: 7481
diff changeset
123 }
7907
8eb69709a934 A few empty lines for readability.
michael
parents: 7906
diff changeset
124
7902
8b8be8f2b647 Fix ref_shift so that it is correct for more/all? MBAFF/PAFF mixes.
michael
parents: 7901
diff changeset
125 cur->mbaff= FRAME_MBAFF;
7907
8eb69709a934 A few empty lines for readability.
michael
parents: 7906
diff changeset
126
6481
493dc59d469a add FF_ prefix to all (frame)_TYPE usage
aurel
parents: 6429
diff changeset
127 if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
2537
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
128 return;
7907
8eb69709a934 A few empty lines for readability.
michael
parents: 7906
diff changeset
129
2537
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
130 for(list=0; list<2; list++){
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
131 fill_colmap(h, h->map_col_to_list0, list, sidx, ref1sidx, 0);
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
132 for(field=0; field<2; field++)
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
133 fill_colmap(h, h->map_col_to_list0_field[field], list, field, field, 1);
2537
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
134 }
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
135 }
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
136
10857
b20434143fd5 Split direct mode (macro)block decoding off h264.c.
michael
parents: 10854
diff changeset
137 void ff_h264_pred_direct_motion(H264Context * const h, int *mb_type){
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
138 MpegEncContext * const s = &h->s;
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
139 int b8_stride = h->b8_stride;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
140 int b4_stride = h->b_stride;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
141 int mb_xy = h->mb_xy;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
142 int mb_type_col[2];
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
143 const int16_t (*l1mv0)[2], (*l1mv1)[2];
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
144 const int8_t *l1ref0, *l1ref1;
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
145 const int is_b8x8 = IS_8X8(*mb_type);
4365
9cebff821565 checking bitstream values and other related changes
michael
parents: 4364
diff changeset
146 unsigned int sub_mb_type;
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
147 int i8, i4;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
148
9416
d863de897b41 Assert that the first list1 entry is a reference frame.
michael
parents: 9415
diff changeset
149 assert(h->ref_list[1][0].reference&3);
d863de897b41 Assert that the first list1 entry is a reference frame.
michael
parents: 9415
diff changeset
150
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
151 #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
152
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
153 if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
7900
37f62a3dc645 Correct comment in the direct mode code.
michael
parents: 7899
diff changeset
154 if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL
7901
michael
parents: 7900
diff changeset
155 int cur_poc = s->current_picture_ptr->poc;
michael
parents: 7900
diff changeset
156 int *col_poc = h->ref_list[1]->field_poc;
michael
parents: 7900
diff changeset
157 int col_parity = FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc);
michael
parents: 7900
diff changeset
158 mb_xy= s->mb_x + ((s->mb_y&~1) + col_parity)*s->mb_stride;
michael
parents: 7900
diff changeset
159 b8_stride = 0;
7918
84b37de61d98 Field -> MBAFF direct mode can use data from fields that are not
michael
parents: 7907
diff changeset
160 }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){// FL -> FL & differ parity
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
161 int fieldoff= 2*(h->ref_list[1][0].reference)-3;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
162 mb_xy += s->mb_stride*fieldoff;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
163 }
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
164 goto single_col;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
165 }else{ // AFL/AFR/FR/FL -> AFR/FR
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
166 if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
167 mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
168 mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
169 mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
170 b8_stride *= 3;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
171 b4_stride *= 6;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
172 //FIXME IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
173 if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
174 && (mb_type_col[1] & MB_TYPE_16x16_OR_INTRA)
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
175 && !is_b8x8){
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
176 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
177 *mb_type |= MB_TYPE_16x8 |MB_TYPE_L0L1|MB_TYPE_DIRECT2; /* B_16x8 */
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
178 }else{
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
179 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
180 *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
181 }
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
182 }else{ // AFR/FR -> AFR/FR
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
183 single_col:
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
184 mb_type_col[0] =
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
185 mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy];
7494
michael
parents: 7493
diff changeset
186 if(IS_8X8(mb_type_col[0]) && !h->sps.direct_8x8_inference_flag){
michael
parents: 7493
diff changeset
187 /* FIXME save sub mb types from previous frames (or derive from MVs)
michael
parents: 7493
diff changeset
188 * so we know exactly what block size to use */
michael
parents: 7493
diff changeset
189 sub_mb_type = MB_TYPE_8x8|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_4x4 */
michael
parents: 7493
diff changeset
190 *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
michael
parents: 7493
diff changeset
191 }else if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){
michael
parents: 7493
diff changeset
192 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
michael
parents: 7493
diff changeset
193 *mb_type |= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_16x16 */
michael
parents: 7493
diff changeset
194 }else{
michael
parents: 7493
diff changeset
195 sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */
michael
parents: 7493
diff changeset
196 *mb_type |= MB_TYPE_8x8|MB_TYPE_L0L1;
michael
parents: 7493
diff changeset
197 }
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
198 }
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
199 }
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
200
7497
michael
parents: 7496
diff changeset
201 l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
michael
parents: 7496
diff changeset
202 l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
michael
parents: 7496
diff changeset
203 l1ref0 = &h->ref_list[1][0].ref_index [0][h->mb2b8_xy[mb_xy]];
michael
parents: 7496
diff changeset
204 l1ref1 = &h->ref_list[1][0].ref_index [1][h->mb2b8_xy[mb_xy]];
7496
f96c14041e48 Simplify l1mv/l1ref calculation.
michael
parents: 7495
diff changeset
205 if(!b8_stride){
f96c14041e48 Simplify l1mv/l1ref calculation.
michael
parents: 7495
diff changeset
206 if(s->mb_y&1){
f96c14041e48 Simplify l1mv/l1ref calculation.
michael
parents: 7495
diff changeset
207 l1ref0 += h->b8_stride;
f96c14041e48 Simplify l1mv/l1ref calculation.
michael
parents: 7495
diff changeset
208 l1ref1 += h->b8_stride;
f96c14041e48 Simplify l1mv/l1ref calculation.
michael
parents: 7495
diff changeset
209 l1mv0 += 2*b4_stride;
f96c14041e48 Simplify l1mv/l1ref calculation.
michael
parents: 7495
diff changeset
210 l1mv1 += 2*b4_stride;
f96c14041e48 Simplify l1mv/l1ref calculation.
michael
parents: 7495
diff changeset
211 }
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
212 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2962
diff changeset
213
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
214 if(h->direct_spatial_mv_pred){
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
215 int ref[2];
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
216 int mv[2][2];
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
217 int list;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
218
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
219 /* FIXME interlacing + spatial direct uses wrong colocated block positions */
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
220
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
221 /* ref = min(neighbors) */
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
222 for(list=0; list<2; list++){
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
223 int refa = h->ref_cache[list][scan8[0] - 1];
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
224 int refb = h->ref_cache[list][scan8[0] - 8];
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
225 int refc = h->ref_cache[list][scan8[0] - 8 + 4];
7445
a202753ce99d Use #define instead of a constant. Patch by Paul Kendall.
darkshikari
parents: 7444
diff changeset
226 if(refc == PART_NOT_AVAILABLE)
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
227 refc = h->ref_cache[list][scan8[0] - 8 - 1];
7336
aaf3e396f094 Simplify spatial direct ref selection with FFMIN3()
michael
parents: 7332
diff changeset
228 ref[list] = FFMIN3((unsigned)refa, (unsigned)refb, (unsigned)refc);
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
229 if(ref[list] < 0)
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
230 ref[list] = -1;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
231 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
232
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
233 if(ref[0] < 0 && ref[1] < 0){
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
234 ref[0] = ref[1] = 0;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
235 mv[0][0] = mv[0][1] =
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
236 mv[1][0] = mv[1][1] = 0;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
237 }else{
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
238 for(list=0; list<2; list++){
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
239 if(ref[list] >= 0)
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
240 pred_motion(h, 0, 4, list, ref[list], &mv[list][0], &mv[list][1]);
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
241 else
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
242 mv[list][0] = mv[list][1] = 0;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
243 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
244 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
245
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
246 if(ref[1] < 0){
6309
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
247 if(!is_b8x8)
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
248 *mb_type &= ~MB_TYPE_L1;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
249 sub_mb_type &= ~MB_TYPE_L1;
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
250 }else if(ref[0] < 0){
6309
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
251 if(!is_b8x8)
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
252 *mb_type &= ~MB_TYPE_L0;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
253 sub_mb_type &= ~MB_TYPE_L0;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
254 }
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
255
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
256 if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
6309
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
257 for(i8=0; i8<4; i8++){
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
258 int x8 = i8&1;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
259 int y8 = i8>>1;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
260 int xy8 = x8+y8*b8_stride;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
261 int xy4 = 3*x8+y8*b4_stride;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
262 int a=0, b=0;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
263
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
264 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
265 continue;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
266 h->sub_mb_type[i8] = sub_mb_type;
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
267
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
268 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
269 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
270 if(!IS_INTRA(mb_type_col[y8])
6309
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
271 && ( (l1ref0[xy8] == 0 && FFABS(l1mv0[xy4][0]) <= 1 && FFABS(l1mv0[xy4][1]) <= 1)
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
272 || (l1ref0[xy8] < 0 && l1ref1[xy8] == 0 && FFABS(l1mv1[xy4][0]) <= 1 && FFABS(l1mv1[xy4][1]) <= 1))){
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
273 if(ref[0] > 0)
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
274 a= pack16to32(mv[0][0],mv[0][1]);
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
275 if(ref[1] > 0)
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
276 b= pack16to32(mv[1][0],mv[1][1]);
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
277 }else{
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
278 a= pack16to32(mv[0][0],mv[0][1]);
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
279 b= pack16to32(mv[1][0],mv[1][1]);
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
280 }
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
281 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, a, 4);
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
282 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, b, 4);
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
283 }
af4b8e1f9b6c mbaff spatial direct
lorenm
parents: 6216
diff changeset
284 }else if(IS_16X16(*mb_type)){
4540
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
285 int a=0, b=0;
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
286
3001
b52d8ee430f6 fix some potential arithmetic overflows in pred_direct_motion() and
lorenm
parents: 2979
diff changeset
287 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, (uint8_t)ref[0], 1);
b52d8ee430f6 fix some potential arithmetic overflows in pred_direct_motion() and
lorenm
parents: 2979
diff changeset
288 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, (uint8_t)ref[1], 1);
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
289 if(!IS_INTRA(mb_type_col[0])
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 4000
diff changeset
290 && ( (l1ref0[0] == 0 && FFABS(l1mv0[0][0]) <= 1 && FFABS(l1mv0[0][1]) <= 1)
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 4000
diff changeset
291 || (l1ref0[0] < 0 && l1ref1[0] == 0 && FFABS(l1mv1[0][0]) <= 1 && FFABS(l1mv1[0][1]) <= 1
2834
fd5d7c732c6b kill a bunch of compiler warnings
mru
parents: 2815
diff changeset
292 && (h->x264_build>33 || !h->x264_build)))){
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
293 if(ref[0] > 0)
4540
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
294 a= pack16to32(mv[0][0],mv[0][1]);
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
295 if(ref[1] > 0)
4540
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
296 b= pack16to32(mv[1][0],mv[1][1]);
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
297 }else{
4540
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
298 a= pack16to32(mv[0][0],mv[0][1]);
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
299 b= pack16to32(mv[1][0],mv[1][1]);
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
300 }
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
301 fill_rectangle(&h->mv_cache[0][scan8[0]], 4, 4, 8, a, 4);
d81e41071424 factorize fill_rectangle() calls
michael
parents: 4534
diff changeset
302 fill_rectangle(&h->mv_cache[1][scan8[0]], 4, 4, 8, b, 4);
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
303 }else{
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
304 for(i8=0; i8<4; i8++){
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
305 const int x8 = i8&1;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
306 const int y8 = i8>>1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2962
diff changeset
307
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
308 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
309 continue;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
310 h->sub_mb_type[i8] = sub_mb_type;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2962
diff changeset
311
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
312 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mv[0][0],mv[0][1]), 4);
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
313 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mv[1][0],mv[1][1]), 4);
3001
b52d8ee430f6 fix some potential arithmetic overflows in pred_direct_motion() and
lorenm
parents: 2979
diff changeset
314 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[0], 1);
b52d8ee430f6 fix some potential arithmetic overflows in pred_direct_motion() and
lorenm
parents: 2979
diff changeset
315 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, (uint8_t)ref[1], 1);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2962
diff changeset
316
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
317 /* col_zero_flag */
7498
e7006afcb1c6 Use local variabes for *stride, where local variables exist.
michael
parents: 7497
diff changeset
318 if(!IS_INTRA(mb_type_col[0]) && ( l1ref0[x8 + y8*b8_stride] == 0
e7006afcb1c6 Use local variabes for *stride, where local variables exist.
michael
parents: 7497
diff changeset
319 || (l1ref0[x8 + y8*b8_stride] < 0 && l1ref1[x8 + y8*b8_stride] == 0
2834
fd5d7c732c6b kill a bunch of compiler warnings
mru
parents: 2815
diff changeset
320 && (h->x264_build>33 || !h->x264_build)))){
7498
e7006afcb1c6 Use local variabes for *stride, where local variables exist.
michael
parents: 7497
diff changeset
321 const int16_t (*l1mv)[2]= l1ref0[x8 + y8*b8_stride] == 0 ? l1mv0 : l1mv1;
3002
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
322 if(IS_SUB_8X8(sub_mb_type)){
7498
e7006afcb1c6 Use local variabes for *stride, where local variables exist.
michael
parents: 7497
diff changeset
323 const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 4000
diff changeset
324 if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
3002
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
325 if(ref[0] == 0)
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
326 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
327 if(ref[1] == 0)
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
328 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
329 }
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
330 }else
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
331 for(i4=0; i4<4; i4++){
7498
e7006afcb1c6 Use local variabes for *stride, where local variables exist.
michael
parents: 7497
diff changeset
332 const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 4000
diff changeset
333 if(FFABS(mv_col[0]) <= 1 && FFABS(mv_col[1]) <= 1){
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
334 if(ref[0] == 0)
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
335 *(uint32_t*)h->mv_cache[0][scan8[i8*4+i4]] = 0;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
336 if(ref[1] == 0)
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
337 *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] = 0;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
338 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
339 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
340 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
341 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
342 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
343 }else{ /* direct temporal mv pred */
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
344 const int *map_col_to_list0[2] = {h->map_col_to_list0[0], h->map_col_to_list0[1]};
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
345 const int *dist_scale_factor = h->dist_scale_factor;
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
346 int ref_offset= 0;
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
347
7494
michael
parents: 7493
diff changeset
348 if(FRAME_MBAFF && IS_INTERLACED(*mb_type)){
7898
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
349 map_col_to_list0[0] = h->map_col_to_list0_field[s->mb_y&1][0];
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
350 map_col_to_list0[1] = h->map_col_to_list0_field[s->mb_y&1][1];
a33287a39a55 Make MBAFF temporal direct mode closer to the spec.
michael
parents: 7897
diff changeset
351 dist_scale_factor =h->dist_scale_factor_field[s->mb_y&1];
7902
8b8be8f2b647 Fix ref_shift so that it is correct for more/all? MBAFF/PAFF mixes.
michael
parents: 7901
diff changeset
352 }
8b8be8f2b647 Fix ref_shift so that it is correct for more/all? MBAFF/PAFF mixes.
michael
parents: 7901
diff changeset
353 if(h->ref_list[1][0].mbaff && IS_INTERLACED(mb_type_col[0]))
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
354 ref_offset += 16;
7902
8b8be8f2b647 Fix ref_shift so that it is correct for more/all? MBAFF/PAFF mixes.
michael
parents: 7901
diff changeset
355
7494
michael
parents: 7493
diff changeset
356 if(IS_INTERLACED(*mb_type) != IS_INTERLACED(mb_type_col[0])){
michael
parents: 7493
diff changeset
357 /* FIXME assumes direct_8x8_inference == 1 */
7495
2090d67bbf16 simplify y_shift/ref_shift code
michael
parents: 7494
diff changeset
358 int y_shift = 2*!IS_INTERLACED(*mb_type);
7494
michael
parents: 7493
diff changeset
359
michael
parents: 7493
diff changeset
360 for(i8=0; i8<4; i8++){
michael
parents: 7493
diff changeset
361 const int x8 = i8&1;
michael
parents: 7493
diff changeset
362 const int y8 = i8>>1;
michael
parents: 7493
diff changeset
363 int ref0, scale;
michael
parents: 7493
diff changeset
364 const int16_t (*l1mv)[2]= l1mv0;
michael
parents: 7493
diff changeset
365
michael
parents: 7493
diff changeset
366 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
michael
parents: 7493
diff changeset
367 continue;
michael
parents: 7493
diff changeset
368 h->sub_mb_type[i8] = sub_mb_type;
michael
parents: 7493
diff changeset
369
michael
parents: 7493
diff changeset
370 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
michael
parents: 7493
diff changeset
371 if(IS_INTRA(mb_type_col[y8])){
michael
parents: 7493
diff changeset
372 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
michael
parents: 7493
diff changeset
373 fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
michael
parents: 7493
diff changeset
374 fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
michael
parents: 7493
diff changeset
375 continue;
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
376 }
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
377
7494
michael
parents: 7493
diff changeset
378 ref0 = l1ref0[x8 + y8*b8_stride];
michael
parents: 7493
diff changeset
379 if(ref0 >= 0)
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
380 ref0 = map_col_to_list0[0][ref0 + ref_offset];
7494
michael
parents: 7493
diff changeset
381 else{
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
382 ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
7494
michael
parents: 7493
diff changeset
383 l1mv= l1mv1;
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
384 }
7494
michael
parents: 7493
diff changeset
385 scale = dist_scale_factor[ref0];
michael
parents: 7493
diff changeset
386 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
michael
parents: 7493
diff changeset
387
michael
parents: 7493
diff changeset
388 {
michael
parents: 7493
diff changeset
389 const int16_t *mv_col = l1mv[x8*3 + y8*b4_stride];
michael
parents: 7493
diff changeset
390 int my_col = (mv_col[1]<<y_shift)/2;
michael
parents: 7493
diff changeset
391 int mx = (scale * mv_col[0] + 128) >> 8;
michael
parents: 7493
diff changeset
392 int my = (scale * my_col + 128) >> 8;
michael
parents: 7493
diff changeset
393 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
michael
parents: 7493
diff changeset
394 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-my_col), 4);
michael
parents: 7493
diff changeset
395 }
michael
parents: 7493
diff changeset
396 }
michael
parents: 7493
diff changeset
397 return;
michael
parents: 7493
diff changeset
398 }
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
399
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
400 /* one-to-one mv scaling */
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
401
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
402 if(IS_16X16(*mb_type)){
4541
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
403 int ref, mv0, mv1;
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
404
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
405 fill_rectangle(&h->ref_cache[1][scan8[0]], 4, 4, 8, 0, 1);
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
406 if(IS_INTRA(mb_type_col[0])){
4541
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
407 ref=mv0=mv1=0;
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
408 }else{
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
409 const int ref0 = l1ref0[0] >= 0 ? map_col_to_list0[0][l1ref0[0] + ref_offset]
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
410 : map_col_to_list0[1][l1ref1[0] + ref_offset];
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
411 const int scale = dist_scale_factor[ref0];
2809
75400dfbe117 fixing colocated mv if colocated block is L1 predicted for the temporal direct case
michael
parents: 2808
diff changeset
412 const int16_t *mv_col = l1ref0[0] >= 0 ? l1mv0[0] : l1mv1[0];
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
413 int mv_l0[2];
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
414 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
415 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
4541
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
416 ref= ref0;
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
417 mv0= pack16to32(mv_l0[0],mv_l0[1]);
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
418 mv1= pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
419 }
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
420 fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
421 fill_rectangle(&h-> mv_cache[0][scan8[0]], 4, 4, 8, mv0, 4);
1c8bc533da57 factorize more calls to fill_rectangle()
michael
parents: 4540
diff changeset
422 fill_rectangle(&h-> mv_cache[1][scan8[0]], 4, 4, 8, mv1, 4);
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
423 }else{
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
424 for(i8=0; i8<4; i8++){
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
425 const int x8 = i8&1;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
426 const int y8 = i8>>1;
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
427 int ref0, scale;
2834
fd5d7c732c6b kill a bunch of compiler warnings
mru
parents: 2815
diff changeset
428 const int16_t (*l1mv)[2]= l1mv0;
2809
75400dfbe117 fixing colocated mv if colocated block is L1 predicted for the temporal direct case
michael
parents: 2808
diff changeset
429
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
430 if(is_b8x8 && !IS_DIRECT(h->sub_mb_type[i8]))
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
431 continue;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
432 h->sub_mb_type[i8] = sub_mb_type;
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
433 fill_rectangle(&h->ref_cache[1][scan8[i8*4]], 2, 2, 8, 0, 1);
7493
e5b93d01b472 Factorize some code between temporal and spatial direct mode.
michael
parents: 7488
diff changeset
434 if(IS_INTRA(mb_type_col[0])){
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
435 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, 0, 1);
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
436 fill_rectangle(&h-> mv_cache[0][scan8[i8*4]], 2, 2, 8, 0, 4);
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
437 fill_rectangle(&h-> mv_cache[1][scan8[i8*4]], 2, 2, 8, 0, 4);
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
438 continue;
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
439 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2962
diff changeset
440
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
441 ref0 = l1ref0[x8 + y8*b8_stride] + ref_offset;
2537
14fef0f3f532 H.264: decode arbitrary frame orders and allow B-frames as references.
lorenm
parents: 2536
diff changeset
442 if(ref0 >= 0)
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
443 ref0 = map_col_to_list0[0][ref0];
2809
75400dfbe117 fixing colocated mv if colocated block is L1 predicted for the temporal direct case
michael
parents: 2808
diff changeset
444 else{
7906
5be944626072 Another try to fix temporal direct mode references.
michael
parents: 7902
diff changeset
445 ref0 = map_col_to_list0[1][l1ref1[x8 + y8*b8_stride] + ref_offset];
2809
75400dfbe117 fixing colocated mv if colocated block is L1 predicted for the temporal direct case
michael
parents: 2808
diff changeset
446 l1mv= l1mv1;
75400dfbe117 fixing colocated mv if colocated block is L1 predicted for the temporal direct case
michael
parents: 2808
diff changeset
447 }
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
448 scale = dist_scale_factor[ref0];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2962
diff changeset
449
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
450 fill_rectangle(&h->ref_cache[0][scan8[i8*4]], 2, 2, 8, ref0, 1);
3002
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
451 if(IS_SUB_8X8(sub_mb_type)){
7498
e7006afcb1c6 Use local variabes for *stride, where local variables exist.
michael
parents: 7497
diff changeset
452 const int16_t *mv_col = l1mv[x8*3 + y8*3*b4_stride];
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
453 int mx = (scale * mv_col[0] + 128) >> 8;
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
454 int my = (scale * mv_col[1] + 128) >> 8;
3002
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
455 fill_rectangle(&h->mv_cache[0][scan8[i8*4]], 2, 2, 8, pack16to32(mx,my), 4);
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
456 fill_rectangle(&h->mv_cache[1][scan8[i8*4]], 2, 2, 8, pack16to32(mx-mv_col[0],my-mv_col[1]), 4);
68d252a8ecd2 fix direct_8x8_inference_flag with 4x4 mvs.
lorenm
parents: 3001
diff changeset
457 }else
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
458 for(i4=0; i4<4; i4++){
7498
e7006afcb1c6 Use local variabes for *stride, where local variables exist.
michael
parents: 7497
diff changeset
459 const int16_t *mv_col = l1mv[x8*2 + (i4&1) + (y8*2 + (i4>>1))*b4_stride];
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
460 int16_t *mv_l0 = h->mv_cache[0][scan8[i8*4+i4]];
3316
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
461 mv_l0[0] = (scale * mv_col[0] + 128) >> 8;
7278f730af27 h264: MBAFF interlaced decoding
lorenm
parents: 3315
diff changeset
462 mv_l0[1] = (scale * mv_col[1] + 128) >> 8;
2396
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
463 *(uint32_t*)h->mv_cache[1][scan8[i8*4+i4]] =
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
464 pack16to32(mv_l0[0]-mv_col[0],mv_l0[1]-mv_col[1]);
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
465 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
466 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
467 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
468 }
7e360068b653 implement B_DIRECT and B_SKIP macroblock types.
lorenm
parents: 2395
diff changeset
469 }