comparison h264.c @ 11627:56591b8041ea libavcodec

Move static function fill_filter_caches() from h264.h to h264.c. The function is only used within that file, so it makes sense to place it there. This fixes many warnings of the type: h264.h:1170: warning: ¡Æfill_filter_caches¡Ç defined but not used
author diego
date Tue, 13 Apr 2010 22:15:49 +0000
parents 66f3d2ff88b7
children 9a5c269f31f5
comparison
equal deleted inserted replaced
11626:4c120a633832 11627:56591b8041ea
2204 case FF_SI_TYPE: return 4; 2204 case FF_SI_TYPE: return 4;
2205 default: return -1; 2205 default: return -1;
2206 } 2206 }
2207 } 2207 }
2208 2208
2209 /**
2210 *
2211 * @return non zero if the loop filter can be skiped
2212 */
2213 static int fill_filter_caches(H264Context *h, int mb_type){
2214 MpegEncContext * const s = &h->s;
2215 const int mb_xy= h->mb_xy;
2216 int top_xy, left_xy[2];
2217 int top_type, left_type[2];
2218
2219 top_xy = mb_xy - (s->mb_stride << MB_FIELD);
2220
2221 //FIXME deblocking could skip the intra and nnz parts.
2222
2223 /* Wow, what a mess, why didn't they simplify the interlacing & intra
2224 * stuff, I can't imagine that these complex rules are worth it. */
2225
2226 left_xy[1] = left_xy[0] = mb_xy-1;
2227 if(FRAME_MBAFF){
2228 const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]);
2229 const int curr_mb_field_flag = IS_INTERLACED(mb_type);
2230 if(s->mb_y&1){
2231 if (left_mb_field_flag != curr_mb_field_flag) {
2232 left_xy[0] -= s->mb_stride;
2233 }
2234 }else{
2235 if(curr_mb_field_flag){
2236 top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1);
2237 }
2238 if (left_mb_field_flag != curr_mb_field_flag) {
2239 left_xy[1] += s->mb_stride;
2240 }
2241 }
2242 }
2243
2244 h->top_mb_xy = top_xy;
2245 h->left_mb_xy[0] = left_xy[0];
2246 h->left_mb_xy[1] = left_xy[1];
2247 {
2248 //for sufficiently low qp, filtering wouldn't do anything
2249 //this is a conservative estimate: could also check beta_offset and more accurate chroma_qp
2250 int qp_thresh = h->qp_thresh; //FIXME strictly we should store qp_thresh for each mb of a slice
2251 int qp = s->current_picture.qscale_table[mb_xy];
2252 if(qp <= qp_thresh
2253 && (left_xy[0]<0 || ((qp + s->current_picture.qscale_table[left_xy[0]] + 1)>>1) <= qp_thresh)
2254 && (top_xy < 0 || ((qp + s->current_picture.qscale_table[top_xy ] + 1)>>1) <= qp_thresh)){
2255 if(!FRAME_MBAFF)
2256 return 1;
2257 if( (left_xy[0]< 0 || ((qp + s->current_picture.qscale_table[left_xy[1] ] + 1)>>1) <= qp_thresh)
2258 && (top_xy < s->mb_stride || ((qp + s->current_picture.qscale_table[top_xy -s->mb_stride] + 1)>>1) <= qp_thresh))
2259 return 1;
2260 }
2261 }
2262
2263 top_type = s->current_picture.mb_type[top_xy] ;
2264 left_type[0] = s->current_picture.mb_type[left_xy[0]];
2265 left_type[1] = s->current_picture.mb_type[left_xy[1]];
2266 if(h->deblocking_filter == 2){
2267 if(h->slice_table[top_xy ] != h->slice_num) top_type= 0;
2268 if(h->slice_table[left_xy[0] ] != h->slice_num) left_type[0]= left_type[1]= 0;
2269 }else{
2270 if(h->slice_table[top_xy ] == 0xFFFF) top_type= 0;
2271 if(h->slice_table[left_xy[0] ] == 0xFFFF) left_type[0]= left_type[1] =0;
2272 }
2273 h->top_type = top_type ;
2274 h->left_type[0]= left_type[0];
2275 h->left_type[1]= left_type[1];
2276
2277 if(IS_INTRA(mb_type))
2278 return 0;
2279
2280 AV_COPY64(&h->non_zero_count_cache[0+8*1], &h->non_zero_count[mb_xy][ 0]);
2281 AV_COPY64(&h->non_zero_count_cache[0+8*2], &h->non_zero_count[mb_xy][ 8]);
2282 AV_COPY32(&h->non_zero_count_cache[0+8*5], &h->non_zero_count[mb_xy][16]);
2283 AV_COPY32(&h->non_zero_count_cache[4+8*3], &h->non_zero_count[mb_xy][20]);
2284 AV_COPY64(&h->non_zero_count_cache[0+8*4], &h->non_zero_count[mb_xy][24]);
2285
2286 h->cbp= h->cbp_table[mb_xy];
2287
2288 {
2289 int list;
2290 for(list=0; list<h->list_count; list++){
2291 int8_t *ref;
2292 int y, b_stride;
2293 int16_t (*mv_dst)[2];
2294 int16_t (*mv_src)[2];
2295
2296 if(!USES_LIST(mb_type, list)){
2297 fill_rectangle( h->mv_cache[list][scan8[0]], 4, 4, 8, pack16to32(0,0), 4);
2298 AV_WN32A(&h->ref_cache[list][scan8[ 0]], ((LIST_NOT_USED)&0xFF)*0x01010101u);
2299 AV_WN32A(&h->ref_cache[list][scan8[ 2]], ((LIST_NOT_USED)&0xFF)*0x01010101u);
2300 AV_WN32A(&h->ref_cache[list][scan8[ 8]], ((LIST_NOT_USED)&0xFF)*0x01010101u);
2301 AV_WN32A(&h->ref_cache[list][scan8[10]], ((LIST_NOT_USED)&0xFF)*0x01010101u);
2302 continue;
2303 }
2304
2305 ref = &s->current_picture.ref_index[list][4*mb_xy];
2306 {
2307 int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
2308 AV_WN32A(&h->ref_cache[list][scan8[ 0]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101);
2309 AV_WN32A(&h->ref_cache[list][scan8[ 2]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101);
2310 ref += 2;
2311 AV_WN32A(&h->ref_cache[list][scan8[ 8]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101);
2312 AV_WN32A(&h->ref_cache[list][scan8[10]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101);
2313 }
2314
2315 b_stride = h->b_stride;
2316 mv_dst = &h->mv_cache[list][scan8[0]];
2317 mv_src = &s->current_picture.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride];
2318 for(y=0; y<4; y++){
2319 AV_COPY128(mv_dst + 8*y, mv_src + y*b_stride);
2320 }
2321
2322 }
2323 }
2324
2325
2326 /*
2327 0 . T T. T T T T
2328 1 L . .L . . . .
2329 2 L . .L . . . .
2330 3 . T TL . . . .
2331 4 L . .L . . . .
2332 5 L . .. . . . .
2333 */
2334 //FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec)
2335 if(top_type){
2336 AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]);
2337 }
2338
2339 if(left_type[0]){
2340 h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][7+0*8];
2341 h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][7+1*8];
2342 h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[0]][7+2*8];
2343 h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[0]][7+3*8];
2344 }
2345
2346 // CAVLC 8x8dct requires NNZ values for residual decoding that differ from what the loop filter needs
2347 if(!CABAC && h->pps.transform_8x8_mode){
2348 if(IS_8x8DCT(top_type)){
2349 h->non_zero_count_cache[4+8*0]=
2350 h->non_zero_count_cache[5+8*0]= h->cbp_table[top_xy] & 4;
2351 h->non_zero_count_cache[6+8*0]=
2352 h->non_zero_count_cache[7+8*0]= h->cbp_table[top_xy] & 8;
2353 }
2354 if(IS_8x8DCT(left_type[0])){
2355 h->non_zero_count_cache[3+8*1]=
2356 h->non_zero_count_cache[3+8*2]= h->cbp_table[left_xy[0]]&2; //FIXME check MBAFF
2357 }
2358 if(IS_8x8DCT(left_type[1])){
2359 h->non_zero_count_cache[3+8*3]=
2360 h->non_zero_count_cache[3+8*4]= h->cbp_table[left_xy[1]]&8; //FIXME check MBAFF
2361 }
2362
2363 if(IS_8x8DCT(mb_type)){
2364 h->non_zero_count_cache[scan8[0 ]]= h->non_zero_count_cache[scan8[1 ]]=
2365 h->non_zero_count_cache[scan8[2 ]]= h->non_zero_count_cache[scan8[3 ]]= h->cbp & 1;
2366
2367 h->non_zero_count_cache[scan8[0+ 4]]= h->non_zero_count_cache[scan8[1+ 4]]=
2368 h->non_zero_count_cache[scan8[2+ 4]]= h->non_zero_count_cache[scan8[3+ 4]]= h->cbp & 2;
2369
2370 h->non_zero_count_cache[scan8[0+ 8]]= h->non_zero_count_cache[scan8[1+ 8]]=
2371 h->non_zero_count_cache[scan8[2+ 8]]= h->non_zero_count_cache[scan8[3+ 8]]= h->cbp & 4;
2372
2373 h->non_zero_count_cache[scan8[0+12]]= h->non_zero_count_cache[scan8[1+12]]=
2374 h->non_zero_count_cache[scan8[2+12]]= h->non_zero_count_cache[scan8[3+12]]= h->cbp & 8;
2375 }
2376 }
2377
2378 if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){
2379 int list;
2380 for(list=0; list<h->list_count; list++){
2381 if(USES_LIST(top_type, list)){
2382 const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride;
2383 const int b8_xy= 4*top_xy + 2;
2384 int (*ref2frm)[64] = h->ref2frm[ h->slice_table[top_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
2385 AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]);
2386 h->ref_cache[list][scan8[0] + 0 - 1*8]=
2387 h->ref_cache[list][scan8[0] + 1 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 0]];
2388 h->ref_cache[list][scan8[0] + 2 - 1*8]=
2389 h->ref_cache[list][scan8[0] + 3 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 1]];
2390 }else{
2391 AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]);
2392 AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((LIST_NOT_USED)&0xFF)*0x01010101u);
2393 }
2394
2395 if(!IS_INTERLACED(mb_type^left_type[0])){
2396 if(USES_LIST(left_type[0], list)){
2397 const int b_xy= h->mb2b_xy[left_xy[0]] + 3;
2398 const int b8_xy= 4*left_xy[0] + 1;
2399 int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[0]]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
2400 AV_COPY32(h->mv_cache[list][scan8[0] - 1 + 0 ], s->current_picture.motion_val[list][b_xy + h->b_stride*0]);
2401 AV_COPY32(h->mv_cache[list][scan8[0] - 1 + 8 ], s->current_picture.motion_val[list][b_xy + h->b_stride*1]);
2402 AV_COPY32(h->mv_cache[list][scan8[0] - 1 +16 ], s->current_picture.motion_val[list][b_xy + h->b_stride*2]);
2403 AV_COPY32(h->mv_cache[list][scan8[0] - 1 +24 ], s->current_picture.motion_val[list][b_xy + h->b_stride*3]);
2404 h->ref_cache[list][scan8[0] - 1 + 0 ]=
2405 h->ref_cache[list][scan8[0] - 1 + 8 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 2*0]];
2406 h->ref_cache[list][scan8[0] - 1 +16 ]=
2407 h->ref_cache[list][scan8[0] - 1 +24 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 2*1]];
2408 }else{
2409 AV_ZERO32(h->mv_cache [list][scan8[0] - 1 + 0 ]);
2410 AV_ZERO32(h->mv_cache [list][scan8[0] - 1 + 8 ]);
2411 AV_ZERO32(h->mv_cache [list][scan8[0] - 1 +16 ]);
2412 AV_ZERO32(h->mv_cache [list][scan8[0] - 1 +24 ]);
2413 h->ref_cache[list][scan8[0] - 1 + 0 ]=
2414 h->ref_cache[list][scan8[0] - 1 + 8 ]=
2415 h->ref_cache[list][scan8[0] - 1 + 16 ]=
2416 h->ref_cache[list][scan8[0] - 1 + 24 ]= LIST_NOT_USED;
2417 }
2418 }
2419 }
2420 }
2421
2422 return 0;
2423 }
2424
2209 static void loop_filter(H264Context *h){ 2425 static void loop_filter(H264Context *h){
2210 MpegEncContext * const s = &h->s; 2426 MpegEncContext * const s = &h->s;
2211 uint8_t *dest_y, *dest_cb, *dest_cr; 2427 uint8_t *dest_y, *dest_cb, *dest_cr;
2212 int linesize, uvlinesize, mb_x, mb_y; 2428 int linesize, uvlinesize, mb_x, mb_y;
2213 const int end_mb_y= s->mb_y + FRAME_MBAFF; 2429 const int end_mb_y= s->mb_y + FRAME_MBAFF;