comparison h264.c @ 8079:2d3c7cd7d143 libavcodec

Replace literally hardcoded max slice number by named constant.
author michael
date Tue, 28 Oct 2008 22:50:16 +0000
parents e70975d5ff80
children e61f76efc9f3
comparison
equal deleted inserted replaced
8078:c23f2088d7c0 8079:2d3c7cd7d143
176 h->left_mb_xy[0] = left_xy[0]; 176 h->left_mb_xy[0] = left_xy[0];
177 h->left_mb_xy[1] = left_xy[1]; 177 h->left_mb_xy[1] = left_xy[1];
178 if(for_deblock){ 178 if(for_deblock){
179 topleft_type = 0; 179 topleft_type = 0;
180 topright_type = 0; 180 topright_type = 0;
181 top_type = h->slice_table[top_xy ] < 255 ? s->current_picture.mb_type[top_xy] : 0; 181 top_type = h->slice_table[top_xy ] < 0xFFFF ? s->current_picture.mb_type[top_xy] : 0;
182 left_type[0] = h->slice_table[left_xy[0] ] < 255 ? s->current_picture.mb_type[left_xy[0]] : 0; 182 left_type[0] = h->slice_table[left_xy[0] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[0]] : 0;
183 left_type[1] = h->slice_table[left_xy[1] ] < 255 ? s->current_picture.mb_type[left_xy[1]] : 0; 183 left_type[1] = h->slice_table[left_xy[1] ] < 0xFFFF ? s->current_picture.mb_type[left_xy[1]] : 0;
184 184
185 if(MB_MBAFF && !IS_INTRA(mb_type)){ 185 if(MB_MBAFF && !IS_INTRA(mb_type)){
186 int list; 186 int list;
187 for(list=0; list<h->list_count; list++){ 187 for(list=0; list<h->list_count; list++){
188 //These values where changed for ease of performing MC, we need to change them back 188 //These values where changed for ease of performing MC, we need to change them back
2118 int x,y; 2118 int x,y;
2119 2119
2120 CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t)) 2120 CHECKED_ALLOCZ(h->intra4x4_pred_mode, big_mb_num * 8 * sizeof(uint8_t))
2121 2121
2122 CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t)) 2122 CHECKED_ALLOCZ(h->non_zero_count , big_mb_num * 16 * sizeof(uint8_t))
2123 CHECKED_ALLOCZ(h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(uint8_t)) 2123 CHECKED_ALLOCZ(h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base))
2124 CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t)) 2124 CHECKED_ALLOCZ(h->cbp_table, big_mb_num * sizeof(uint16_t))
2125 2125
2126 CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t)) 2126 CHECKED_ALLOCZ(h->chroma_pred_mode_table, big_mb_num * sizeof(uint8_t))
2127 CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t)); 2127 CHECKED_ALLOCZ(h->mvd_table[0], 32*big_mb_num * sizeof(uint16_t));
2128 CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t)); 2128 CHECKED_ALLOCZ(h->mvd_table[1], 32*big_mb_num * sizeof(uint16_t));
2129 CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t)); 2129 CHECKED_ALLOCZ(h->direct_table, 32*big_mb_num * sizeof(uint8_t));
2130 2130
2131 memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(uint8_t)); 2131 memset(h->slice_table_base, -1, (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base));
2132 h->slice_table= h->slice_table_base + s->mb_stride*2 + 1; 2132 h->slice_table= h->slice_table_base + s->mb_stride*2 + 1;
2133 2133
2134 CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint32_t)); 2134 CHECKED_ALLOCZ(h->mb2b_xy , big_mb_num * sizeof(uint32_t));
2135 CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint32_t)); 2135 CHECKED_ALLOCZ(h->mb2b8_xy , big_mb_num * sizeof(uint32_t));
2136 for(y=0; y<s->mb_height; y++){ 2136 for(y=0; y<s->mb_height; y++){
2276 if(!h->thread_context[i]->s.obmc_scratchpad) 2276 if(!h->thread_context[i]->s.obmc_scratchpad)
2277 h->thread_context[i]->s.obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize); 2277 h->thread_context[i]->s.obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize);
2278 2278
2279 /* some macroblocks will be accessed before they're available */ 2279 /* some macroblocks will be accessed before they're available */
2280 if(FRAME_MBAFF || s->avctx->thread_count > 1) 2280 if(FRAME_MBAFF || s->avctx->thread_count > 1)
2281 memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(uint8_t)); 2281 memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(*h->slice_table));
2282 2282
2283 // s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1; 2283 // s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1;
2284 2284
2285 // We mark the current picture as non-reference after allocating it, so 2285 // We mark the current picture as non-reference after allocating it, so
2286 // that if we break out due to an error it can be released automatically 2286 // that if we break out due to an error it can be released automatically
4018 slice_group_change_cycle= get_bits(&s->gb, ?); 4018 slice_group_change_cycle= get_bits(&s->gb, ?);
4019 #endif 4019 #endif
4020 4020
4021 h0->last_slice_type = slice_type; 4021 h0->last_slice_type = slice_type;
4022 h->slice_num = ++h0->current_slice; 4022 h->slice_num = ++h0->current_slice;
4023 if(h->slice_num >= MAX_SLICES){
4024 av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\n");
4025 }
4023 4026
4024 for(j=0; j<2; j++){ 4027 for(j=0; j<2; j++){
4025 int *ref2frm= h->ref2frm[h->slice_num&15][j]; 4028 int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j];
4026 ref2frm[0]= 4029 ref2frm[0]=
4027 ref2frm[1]= -1; 4030 ref2frm[1]= -1;
4028 for(i=0; i<16; i++) 4031 for(i=0; i<16; i++)
4029 ref2frm[i+2]= 4*h->ref_list[j][i].frame_num 4032 ref2frm[i+2]= 4*h->ref_list[j][i].frame_num
4030 +(h->ref_list[j][i].reference&3); 4033 +(h->ref_list[j][i].reference&3);
6357 } 6360 }
6358 } 6361 }
6359 6362
6360 if (FRAME_MBAFF 6363 if (FRAME_MBAFF
6361 // left mb is in picture 6364 // left mb is in picture
6362 && h->slice_table[mb_xy-1] != 255 6365 && h->slice_table[mb_xy-1] != 0xFFFF
6363 // and current and left pair do not have the same interlaced type 6366 // and current and left pair do not have the same interlaced type
6364 && (IS_INTERLACED(mb_type) != IS_INTERLACED(s->current_picture.mb_type[mb_xy-1])) 6367 && (IS_INTERLACED(mb_type) != IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]))
6365 // and left mb is in the same slice if deblocking_filter == 2 6368 // and left mb is in the same slice if deblocking_filter == 2
6366 && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_table[mb_xy])) { 6369 && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_table[mb_xy])) {
6367 /* First vertical edge is different in MBAFF frames 6370 /* First vertical edge is different in MBAFF frames
6421 for( dir = 0; dir < 2; dir++ ) 6424 for( dir = 0; dir < 2; dir++ )
6422 { 6425 {
6423 int edge; 6426 int edge;
6424 const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy; 6427 const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy;
6425 const int mbm_type = s->current_picture.mb_type[mbm_xy]; 6428 const int mbm_type = s->current_picture.mb_type[mbm_xy];
6426 int (*ref2frm) [64] = h->ref2frm[ h->slice_num &15 ][0] + (MB_MBAFF ? 20 : 2); 6429 int (*ref2frm) [64] = h->ref2frm[ h->slice_num &(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
6427 int (*ref2frmm)[64] = h->ref2frm[ h->slice_table[mbm_xy]&15 ][0] + (MB_MBAFF ? 20 : 2); 6430 int (*ref2frmm)[64] = h->ref2frm[ h->slice_table[mbm_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2);
6428 int start = h->slice_table[mbm_xy] == 255 ? 1 : 0; 6431 int start = h->slice_table[mbm_xy] == 0xFFFF ? 1 : 0;
6429 6432
6430 const int edges = (mb_type & (MB_TYPE_16x16|MB_TYPE_SKIP)) 6433 const int edges = (mb_type & (MB_TYPE_16x16|MB_TYPE_SKIP))
6431 == (MB_TYPE_16x16|MB_TYPE_SKIP) ? 1 : 4; 6434 == (MB_TYPE_16x16|MB_TYPE_SKIP) ? 1 : 4;
6432 // how often to recheck mv-based bS when iterating between edges 6435 // how often to recheck mv-based bS when iterating between edges
6433 const int mask_edge = (mb_type & (MB_TYPE_16x16 | (MB_TYPE_16x8 << dir))) ? 3 : 6436 const int mask_edge = (mb_type & (MB_TYPE_16x16 | (MB_TYPE_16x8 << dir))) ? 3 :