Mercurial > libavcodec.hg
annotate h264_mvpred.h @ 10917:895df334c326 libavcodec
Set h->cbp for ff_h264_filter_mb_fast().
author | michael |
---|---|
date | Mon, 18 Jan 2010 16:11:13 +0000 |
parents | 5d34ab807e91 |
children | 84c0a4d9d7f5 |
rev | line source |
---|---|
1168 | 1 /* |
10864 | 2 * H.26L/H.264/AVC/JVT/14496-10/... motion vector predicion |
1168 | 3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at> |
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 | 8 * modify it under the terms of the GNU Lesser General Public |
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 | 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 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
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 | 20 */ |
2967 | 21 |
1168 | 22 /** |
10864 | 23 * @file libavcodec/h264_mvpred.h |
24 * H.264 / AVC / MPEG4 part10 motion vector predicion. | |
1168 | 25 * @author Michael Niedermayer <michaelni@gmx.at> |
26 */ | |
27 | |
10882
5d34ab807e91
Add forgotton multiple inclusion guards to h264_mvpred.h.
michael
parents:
10864
diff
changeset
|
28 #ifndef AVCODEC_H264_MVPRED_H |
5d34ab807e91
Add forgotton multiple inclusion guards to h264_mvpred.h.
michael
parents:
10864
diff
changeset
|
29 #define AVCODEC_H264_MVPRED_H |
5d34ab807e91
Add forgotton multiple inclusion guards to h264_mvpred.h.
michael
parents:
10864
diff
changeset
|
30 |
9012
15a3df8c01fd
More approved hunks for VAAPI & our new and cleaner hwaccel API.
michael
parents:
9004
diff
changeset
|
31 #include "internal.h" |
1168 | 32 #include "avcodec.h" |
4975 | 33 #include "h264.h" |
1908
e20fd60b215c
h264 - progressive I frame CABAC support patch by (Laurent Aimar <fenrir at via dot ecp dot fr>)
michael
parents:
1899
diff
changeset
|
34 |
3284
a224d9752912
don't force asserts in release builds. 2% faster h264.
lorenm
parents:
3219
diff
changeset
|
35 //#undef NDEBUG |
1168 | 36 #include <assert.h> |
37 | |
10864 | 38 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ |
39 const int topright_ref= h->ref_cache[list][ i - 8 + part_width ]; | |
40 MpegEncContext *s = &h->s; | |
7481 | 41 |
10864 | 42 /* there is no consistent mapping of mvs to neighboring locations that will |
43 * make mbaff happy, so we can't move all this logic to fill_caches */ | |
44 if(FRAME_MBAFF){ | |
45 const uint32_t *mb_types = s->current_picture_ptr->mb_type; | |
46 const int16_t *mv; | |
47 *(uint32_t*)h->mv_cache[list][scan8[0]-2] = 0; | |
48 *C = h->mv_cache[list][scan8[0]-2]; | |
8443 | 49 |
10864 | 50 if(!MB_FIELD |
51 && (s->mb_y&1) && i < scan8[0]+8 && topright_ref != PART_NOT_AVAILABLE){ | |
52 int topright_xy = s->mb_x + (s->mb_y-1)*s->mb_stride + (i == scan8[0]+3); | |
53 if(IS_INTERLACED(mb_types[topright_xy])){ | |
54 #define SET_DIAG_MV(MV_OP, REF_OP, X4, Y4)\ | |
55 const int x4 = X4, y4 = Y4;\ | |
56 const int mb_type = mb_types[(x4>>2)+(y4>>2)*s->mb_stride];\ | |
57 if(!USES_LIST(mb_type,list))\ | |
58 return LIST_NOT_USED;\ | |
59 mv = s->current_picture_ptr->motion_val[list][x4 + y4*h->b_stride];\ | |
60 h->mv_cache[list][scan8[0]-2][0] = mv[0];\ | |
61 h->mv_cache[list][scan8[0]-2][1] = mv[1] MV_OP;\ | |
62 return s->current_picture_ptr->ref_index[list][(x4>>1) + (y4>>1)*h->b8_stride] REF_OP; | |
2967 | 63 |
10864 | 64 SET_DIAG_MV(*2, >>1, s->mb_x*4+(i&7)-4+part_width, s->mb_y*4-1); |
65 } | |
2551
615995277bc5
MBAFF I slice no deblocking patch by (Loic >>lll+ffmpeg m4x org<<)
michael
parents:
2548
diff
changeset
|
66 } |
10864 | 67 if(topright_ref == PART_NOT_AVAILABLE |
68 && ((s->mb_y&1) || i >= scan8[0]+8) && (i&7)==4 | |
69 && h->ref_cache[list][scan8[0]-1] != PART_NOT_AVAILABLE){ | |
70 if(!MB_FIELD | |
71 && IS_INTERLACED(mb_types[h->left_mb_xy[0]])){ | |
72 SET_DIAG_MV(*2, >>1, s->mb_x*4-1, (s->mb_y|1)*4+(s->mb_y&1)*2+(i>>4)-1); | |
73 } | |
74 if(MB_FIELD | |
75 && !IS_INTERLACED(mb_types[h->left_mb_xy[0]]) | |
76 && i >= scan8[0]+8){ | |
77 // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK. | |
78 SET_DIAG_MV(/2, <<1, s->mb_x*4-1, (s->mb_y&~1)*4 - 1 + ((i-scan8[0])>>3)*2); | |
2551
615995277bc5
MBAFF I slice no deblocking patch by (Loic >>lll+ffmpeg m4x org<<)
michael
parents:
2548
diff
changeset
|
79 } |
615995277bc5
MBAFF I slice no deblocking patch by (Loic >>lll+ffmpeg m4x org<<)
michael
parents:
2548
diff
changeset
|
80 } |
10864 | 81 #undef SET_DIAG_MV |
1168 | 82 } |
83 | |
10864 | 84 if(topright_ref != PART_NOT_AVAILABLE){ |
85 *C= h->mv_cache[list][ i - 8 + part_width ]; | |
86 return topright_ref; | |
87 }else{ | |
88 tprintf(s->avctx, "topright MV not available\n"); | |
89 | |
90 *C= h->mv_cache[list][ i - 8 - 1 ]; | |
91 return h->ref_cache[list][ i - 8 - 1 ]; | |
92 } | |
93 } | |
94 | |
95 /** | |
96 * gets the predicted MV. | |
97 * @param n the block index | |
98 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) | |
99 * @param mx the x component of the predicted motion vector | |
100 * @param my the y component of the predicted motion vector | |
101 */ | |
102 static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){ | |
103 const int index8= scan8[n]; | |
104 const int top_ref= h->ref_cache[list][ index8 - 8 ]; | |
105 const int left_ref= h->ref_cache[list][ index8 - 1 ]; | |
106 const int16_t * const A= h->mv_cache[list][ index8 - 1 ]; | |
107 const int16_t * const B= h->mv_cache[list][ index8 - 8 ]; | |
108 const int16_t * C; | |
109 int diagonal_ref, match_count; | |
3316 | 110 |
10864 | 111 assert(part_width==1 || part_width==2 || part_width==4); |
112 | |
113 /* mv_cache | |
114 B . . A T T T T | |
115 U . . L . . , . | |
116 U . . L . . . . | |
117 U . . L . . , . | |
118 . . . L . . . . | |
119 */ | |
120 | |
121 diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width); | |
122 match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref); | |
123 tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count); | |
124 if(match_count > 1){ //most common | |
125 *mx= mid_pred(A[0], B[0], C[0]); | |
126 *my= mid_pred(A[1], B[1], C[1]); | |
127 }else if(match_count==1){ | |
128 if(left_ref==ref){ | |
129 *mx= A[0]; | |
130 *my= A[1]; | |
131 }else if(top_ref==ref){ | |
132 *mx= B[0]; | |
133 *my= B[1]; | |
134 }else{ | |
135 *mx= C[0]; | |
136 *my= C[1]; | |
3316 | 137 } |
2449 | 138 }else{ |
10864 | 139 if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){ |
140 *mx= A[0]; | |
141 *my= A[1]; | |
7532 | 142 }else{ |
10864 | 143 *mx= mid_pred(A[0], B[0], C[0]); |
144 *my= mid_pred(A[1], B[1], C[1]); | |
2551
615995277bc5
MBAFF I slice no deblocking patch by (Loic >>lll+ffmpeg m4x org<<)
michael
parents:
2548
diff
changeset
|
145 } |
615995277bc5
MBAFF I slice no deblocking patch by (Loic >>lll+ffmpeg m4x org<<)
michael
parents:
2548
diff
changeset
|
146 } |
615995277bc5
MBAFF I slice no deblocking patch by (Loic >>lll+ffmpeg m4x org<<)
michael
parents:
2548
diff
changeset
|
147 |
10864 | 148 tprintf(h->s.avctx, "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list); |
1168 | 149 } |
150 | |
151 /** | |
152 * gets the directionally predicted 16x8 MV. | |
153 * @param n the block index | |
154 * @param mx the x component of the predicted motion vector | |
155 * @param my the y component of the predicted motion vector | |
156 */ | |
157 static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ | |
158 if(n==0){ | |
159 const int top_ref= h->ref_cache[list][ scan8[0] - 8 ]; | |
160 const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; | |
161 | |
4600 | 162 tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], h->s.mb_x, h->s.mb_y, n, list); |
2967 | 163 |
1168 | 164 if(top_ref == ref){ |
165 *mx= B[0]; | |
166 *my= B[1]; | |
167 return; | |
168 } | |
169 }else{ | |
170 const int left_ref= h->ref_cache[list][ scan8[8] - 1 ]; | |
171 const int16_t * const A= h->mv_cache[list][ scan8[8] - 1 ]; | |
2967 | 172 |
4600 | 173 tprintf(h->s.avctx, "pred_16x8: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); |
1168 | 174 |
175 if(left_ref == ref){ | |
176 *mx= A[0]; | |
177 *my= A[1]; | |
178 return; | |
179 } | |
180 } | |
181 | |
182 //RARE | |
183 pred_motion(h, n, 4, list, ref, mx, my); | |
184 } | |
185 | |
186 /** | |
187 * gets the directionally predicted 8x16 MV. | |
188 * @param n the block index | |
189 * @param mx the x component of the predicted motion vector | |
190 * @param my the y component of the predicted motion vector | |
191 */ | |
192 static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ | |
193 if(n==0){ | |
194 const int left_ref= h->ref_cache[list][ scan8[0] - 1 ]; | |
195 const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; | |
2967 | 196 |
4600 | 197 tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", left_ref, A[0], A[1], h->s.mb_x, h->s.mb_y, n, list); |
1168 | 198 |
199 if(left_ref == ref){ | |
200 *mx= A[0]; | |
201 *my= A[1]; | |
202 return; | |
203 } | |
204 }else{ | |
1169 | 205 const int16_t * C; |
206 int diagonal_ref; | |
207 | |
208 diagonal_ref= fetch_diagonal_mv(h, &C, scan8[4], list, 2); | |
2967 | 209 |
4600 | 210 tprintf(h->s.avctx, "pred_8x16: (%2d %2d %2d) at %2d %2d %d list %d\n", diagonal_ref, C[0], C[1], h->s.mb_x, h->s.mb_y, n, list); |
1168 | 211 |
2967 | 212 if(diagonal_ref == ref){ |
1168 | 213 *mx= C[0]; |
214 *my= C[1]; | |
215 return; | |
216 } | |
217 } | |
218 | |
219 //RARE | |
220 pred_motion(h, n, 2, list, ref, mx, my); | |
221 } | |
222 | |
223 static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){ | |
224 const int top_ref = h->ref_cache[0][ scan8[0] - 8 ]; | |
225 const int left_ref= h->ref_cache[0][ scan8[0] - 1 ]; | |
226 | |
4600 | 227 tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y); |
1168 | 228 |
229 if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE | |
8454 | 230 || !( top_ref | *(uint32_t*)h->mv_cache[0][ scan8[0] - 8 ]) |
231 || !(left_ref | *(uint32_t*)h->mv_cache[0][ scan8[0] - 1 ])){ | |
2967 | 232 |
1168 | 233 *mx = *my = 0; |
234 return; | |
235 } | |
2967 | 236 |
1168 | 237 pred_motion(h, 0, 4, 0, 0, mx, my); |
238 | |
239 return; | |
240 } | |
10882
5d34ab807e91
Add forgotton multiple inclusion guards to h264_mvpred.h.
michael
parents:
10864
diff
changeset
|
241 |
5d34ab807e91
Add forgotton multiple inclusion guards to h264_mvpred.h.
michael
parents:
10864
diff
changeset
|
242 #endif /* AVCODEC_H264_MVPRED_H */ |