comparison h264.c @ 2645:42528c1f0246 libavcodec

More spelling errors patch by (Kevin Baragona (kevinmb500 gawab com>)
author michael
date Thu, 05 May 2005 14:17:28 +0000
parents c337f851d0f9
children c3a06b0b00e2
comparison
equal deleted inserted replaced
2644:6ff5dc0dbaf0 2645:42528c1f0246
225 225
226 PPS pps_buffer[MAX_PPS_COUNT]; 226 PPS pps_buffer[MAX_PPS_COUNT];
227 /** 227 /**
228 * current pps 228 * current pps
229 */ 229 */
230 PPS pps; //FIXME move tp Picture perhaps? (->no) do we need that? 230 PPS pps; //FIXME move to Picture perhaps? (->no) do we need that?
231 231
232 int slice_num; 232 int slice_num;
233 uint8_t *slice_table_base; 233 uint8_t *slice_table_base;
234 uint8_t *slice_table; ///< slice_table_base + mb_stride + 1 234 uint8_t *slice_table; ///< slice_table_base + mb_stride + 1
235 int slice_type; 235 int slice_type;
368 368
369 w *= size; 369 w *= size;
370 stride *= size; 370 stride *= size;
371 371
372 assert((((int)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0); 372 assert((((int)vp)&(FFMIN(w, STRIDE_ALIGN)-1)) == 0);
373 //FIXME check what gcc generates for 64 bit on x86 and possible write a 32 bit ver of it 373 //FIXME check what gcc generates for 64 bit on x86 and possibly write a 32 bit ver of it
374 if(w==2 && h==2){ 374 if(w==2 && h==2){
375 *(uint16_t*)(p + 0)= 375 *(uint16_t*)(p + 0)=
376 *(uint16_t*)(p + stride)= size==4 ? val : val*0x0101; 376 *(uint16_t*)(p + stride)= size==4 ? val : val*0x0101;
377 }else if(w==2 && h==4){ 377 }else if(w==2 && h==4){
378 *(uint16_t*)(p + 0*stride)= 378 *(uint16_t*)(p + 0*stride)=
432 // the actual condition is whether we're on the edge of a slice, 432 // the actual condition is whether we're on the edge of a slice,
433 // and even then the intra and nnz parts are unnecessary. 433 // and even then the intra and nnz parts are unnecessary.
434 if(for_deblock && h->slice_num == 1) 434 if(for_deblock && h->slice_num == 1)
435 return; 435 return;
436 436
437 //wow what a mess, why didnt they simplify the interlacing&intra stuff, i cant imagine that these complex rules are worth it 437 //wow what a mess, why didn't they simplify the interlacing&intra stuff, i can't imagine that these complex rules are worth it
438 438
439 top_xy = mb_xy - s->mb_stride; 439 top_xy = mb_xy - s->mb_stride;
440 topleft_xy = top_xy - 1; 440 topleft_xy = top_xy - 1;
441 topright_xy= top_xy + 1; 441 topright_xy= top_xy + 1;
442 left_xy[1] = left_xy[0] = mb_xy-1; 442 left_xy[1] = left_xy[0] = mb_xy-1;
753 } 753 }
754 754
755 755
756 h->ref_cache[list][scan8[5 ]+1] = 756 h->ref_cache[list][scan8[5 ]+1] =
757 h->ref_cache[list][scan8[7 ]+1] = 757 h->ref_cache[list][scan8[7 ]+1] =
758 h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewher else) 758 h->ref_cache[list][scan8[13]+1] = //FIXME remove past 3 (init somewhere else)
759 h->ref_cache[list][scan8[4 ]] = 759 h->ref_cache[list][scan8[4 ]] =
760 h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; 760 h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE;
761 *(uint32_t*)h->mv_cache [list][scan8[5 ]+1]= 761 *(uint32_t*)h->mv_cache [list][scan8[5 ]+1]=
762 *(uint32_t*)h->mv_cache [list][scan8[7 ]+1]= 762 *(uint32_t*)h->mv_cache [list][scan8[7 ]+1]=
763 *(uint32_t*)h->mv_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) 763 *(uint32_t*)h->mv_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewhere else)
764 *(uint32_t*)h->mv_cache [list][scan8[4 ]]= 764 *(uint32_t*)h->mv_cache [list][scan8[4 ]]=
765 *(uint32_t*)h->mv_cache [list][scan8[12]]= 0; 765 *(uint32_t*)h->mv_cache [list][scan8[12]]= 0;
766 766
767 if( h->pps.cabac ) { 767 if( h->pps.cabac ) {
768 /* XXX beurk, Load mvd */ 768 /* XXX beurk, Load mvd */
801 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 2*8]= 801 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 2*8]=
802 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 3*8]= 0; 802 *(uint32_t*)h->mvd_cache [list][scan8[0] - 1 + 3*8]= 0;
803 } 803 }
804 *(uint32_t*)h->mvd_cache [list][scan8[5 ]+1]= 804 *(uint32_t*)h->mvd_cache [list][scan8[5 ]+1]=
805 *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]= 805 *(uint32_t*)h->mvd_cache [list][scan8[7 ]+1]=
806 *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewher else) 806 *(uint32_t*)h->mvd_cache [list][scan8[13]+1]= //FIXME remove past 3 (init somewhere else)
807 *(uint32_t*)h->mvd_cache [list][scan8[4 ]]= 807 *(uint32_t*)h->mvd_cache [list][scan8[4 ]]=
808 *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0; 808 *(uint32_t*)h->mvd_cache [list][scan8[12]]= 0;
809 809
810 if(h->slice_type == B_TYPE){ 810 if(h->slice_type == B_TYPE){
811 fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1); 811 fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, 0, 1);
1361 int list; 1361 int list;
1362 1362
1363 for(list=0; list<2; list++){ 1363 for(list=0; list<2; list++){
1364 int y; 1364 int y;
1365 if(!USES_LIST(mb_type, list)){ 1365 if(!USES_LIST(mb_type, list)){
1366 if(1){ //FIXME skip or never read if mb_type doesnt use it 1366 if(1){ //FIXME skip or never read if mb_type doesn't use it
1367 for(y=0; y<4; y++){ 1367 for(y=0; y<4; y++){
1368 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]= 1368 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 0 + y*h->b_stride]=
1369 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= 0; 1369 *(uint64_t*)s->current_picture.motion_val[list][b_xy + 2 + y*h->b_stride]= 0;
1370 } 1370 }
1371 if( h->pps.cabac ) { 1371 if( h->pps.cabac ) {
1409 1409
1410 /** 1410 /**
1411 * Decodes a network abstraction layer unit. 1411 * Decodes a network abstraction layer unit.
1412 * @param consumed is the number of bytes used as input 1412 * @param consumed is the number of bytes used as input
1413 * @param length is the length of the array 1413 * @param length is the length of the array
1414 * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp ttailing? 1414 * @param dst_length is the number of decoded bytes FIXME here or a decode rbsp tailing?
1415 * @returns decoded bytes, might be src+1 if no escapes 1415 * @returns decoded bytes, might be src+1 if no escapes
1416 */ 1416 */
1417 static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){ 1417 static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *consumed, int length){
1418 int i, si, di; 1418 int i, si, di;
1419 uint8_t *dst; 1419 uint8_t *dst;
1446 } 1446 }
1447 1447
1448 h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length); 1448 h->rbsp_buffer= av_fast_realloc(h->rbsp_buffer, &h->rbsp_buffer_size, length);
1449 dst= h->rbsp_buffer; 1449 dst= h->rbsp_buffer;
1450 1450
1451 //printf("deoding esc\n"); 1451 //printf("decoding esc\n");
1452 si=di=0; 1452 si=di=0;
1453 while(si<length){ 1453 while(si<length){
1454 //remove escapes (very rare 1:2^22) 1454 //remove escapes (very rare 1:2^22)
1455 if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){ 1455 if(si+2<length && src[si]==0 && src[si+1]==0 && src[si+2]<=3){
1456 if(src[si+2]==3){ //escape 1456 if(src[si+2]==3){ //escape
1734 block[3*4 + i]= z3 - 2*z2; 1734 block[3*4 + i]= z3 - 2*z2;
1735 } 1735 }
1736 } 1736 }
1737 #endif 1737 #endif
1738 1738
1739 //FIXME need to check that this doesnt overflow signed 32 bit for low qp, iam not sure, its very close 1739 //FIXME need to check that this doesnt overflow signed 32 bit for low qp, i am not sure, it's very close
1740 //FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away) 1740 //FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away)
1741 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int seperate_dc){ 1741 static inline int quantize_c(DCTELEM *block, uint8_t *scantable, int qscale, int intra, int seperate_dc){
1742 int i; 1742 int i;
1743 const int * const quant_table= quant_coeff[qscale]; 1743 const int * const quant_table= quant_coeff[qscale];
1744 const int bias= intra ? (1<<QUANT_SHIFT)/3 : (1<<QUANT_SHIFT)/6; 1744 const int bias= intra ? (1<<QUANT_SHIFT)/3 : (1<<QUANT_SHIFT)/6;
2640 av_freep(&h->s.obmc_scratchpad); 2640 av_freep(&h->s.obmc_scratchpad);
2641 } 2641 }
2642 2642
2643 /** 2643 /**
2644 * allocates tables. 2644 * allocates tables.
2645 * needs widzh/height 2645 * needs width/height
2646 */ 2646 */
2647 static int alloc_tables(H264Context *h){ 2647 static int alloc_tables(H264Context *h){
2648 MpegEncContext * const s = &h->s; 2648 MpegEncContext * const s = &h->s;
2649 const int big_mb_num= s->mb_stride * (s->mb_height+1); 2649 const int big_mb_num= s->mb_stride * (s->mb_height+1);
2650 int x,y; 2650 int x,y;
2765 2765
2766 src_y -= linesize; 2766 src_y -= linesize;
2767 src_cb -= uvlinesize; 2767 src_cb -= uvlinesize;
2768 src_cr -= uvlinesize; 2768 src_cr -= uvlinesize;
2769 2769
2770 // There is two lines saved, the line above the the top macroblock of a pair, 2770 // There are two lines saved, the line above the the top macroblock of a pair,
2771 // and the line above the bottom macroblock 2771 // and the line above the bottom macroblock
2772 h->left_border[0]= h->top_borders[0][s->mb_x][15]; 2772 h->left_border[0]= h->top_borders[0][s->mb_x][15];
2773 for(i=1; i<17; i++){ 2773 for(i=1; i<17; i++){
2774 h->left_border[i]= src_y[15+i* linesize]; 2774 h->left_border[i]= src_y[15+i* linesize];
2775 } 2775 }
2837 2837
2838 src_y -= 2 * linesize; 2838 src_y -= 2 * linesize;
2839 src_cb -= 2 * uvlinesize; 2839 src_cb -= 2 * uvlinesize;
2840 src_cr -= 2 * uvlinesize; 2840 src_cr -= 2 * uvlinesize;
2841 2841
2842 // There is two lines saved, the line above the the top macroblock of a pair, 2842 // There are two lines saved, the line above the the top macroblock of a pair,
2843 // and the line above the bottom macroblock 2843 // and the line above the bottom macroblock
2844 h->left_border[0]= h->top_borders[0][s->mb_x][15]; 2844 h->left_border[0]= h->top_borders[0][s->mb_x][15];
2845 h->left_border[1]= h->top_borders[1][s->mb_x][15]; 2845 h->left_border[1]= h->top_borders[1][s->mb_x][15];
2846 for(i=2; i<34; i++){ 2846 for(i=2; i<34; i++){
2847 h->left_border[i]= src_y[15+i* linesize]; 2847 h->left_border[i]= src_y[15+i* linesize];
3118 backup_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize); 3118 backup_pair_border(h, pair_dest_y, pair_dest_cb, pair_dest_cr, s->linesize, s->uvlinesize);
3119 // TODO deblock a pair 3119 // TODO deblock a pair
3120 // top 3120 // top
3121 s->mb_y--; 3121 s->mb_y--;
3122 tprintf("call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y); 3122 tprintf("call mbaff filter_mb mb_x:%d mb_y:%d pair_dest_y = %p, dest_y = %p\n", mb_x, mb_y, pair_dest_y, dest_y);
3123 fill_caches(h, mb_type_top, 1); //FIXME dont fill stuff which isnt used by filter_mb 3123 fill_caches(h, mb_type_top, 1); //FIXME don't fill stuff which isn't used by filter_mb
3124 filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize); 3124 filter_mb(h, mb_x, mb_y, pair_dest_y, pair_dest_cb, pair_dest_cr, linesize, uvlinesize);
3125 if (tmp != s->current_picture.data[1][384]) { 3125 if (tmp != s->current_picture.data[1][384]) {
3126 tprintf("modified pixel 8,1 (1)\n"); 3126 tprintf("modified pixel 8,1 (1)\n");
3127 } 3127 }
3128 // bottom 3128 // bottom
3129 s->mb_y++; 3129 s->mb_y++;
3130 tprintf("call mbaff filter_mb\n"); 3130 tprintf("call mbaff filter_mb\n");
3131 fill_caches(h, mb_type_bottom, 1); //FIXME dont fill stuff which isnt used by filter_mb 3131 fill_caches(h, mb_type_bottom, 1); //FIXME don't fill stuff which isn't used by filter_mb
3132 filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize); 3132 filter_mb(h, mb_x, mb_y+1, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
3133 if (tmp != s->current_picture.data[1][384]) { 3133 if (tmp != s->current_picture.data[1][384]) {
3134 tprintf("modified pixel 8,1 (2)\n"); 3134 tprintf("modified pixel 8,1 (2)\n");
3135 } 3135 }
3136 } else { 3136 } else {
3137 tprintf("call filter_mb\n"); 3137 tprintf("call filter_mb\n");
3138 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize); 3138 backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
3139 fill_caches(h, mb_type, 1); //FIXME dont fill stuff which isnt used by filter_mb 3139 fill_caches(h, mb_type, 1); //FIXME don't fill stuff which isn't used by filter_mb
3140 filter_mb(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); 3140 filter_mb(h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize);
3141 } 3141 }
3142 } 3142 }
3143 } 3143 }
3144 3144
3263 MpegEncContext * const s = &h->s; 3263 MpegEncContext * const s = &h->s;
3264 int list; 3264 int list;
3265 3265
3266 print_short_term(h); 3266 print_short_term(h);
3267 print_long_term(h); 3267 print_long_term(h);
3268 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move beofre func 3268 if(h->slice_type==I_TYPE || h->slice_type==SI_TYPE) return 0; //FIXME move before func
3269 3269
3270 for(list=0; list<2; list++){ 3270 for(list=0; list<2; list++){
3271 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); 3271 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]);
3272 3272
3273 if(get_bits1(&s->gb)){ 3273 if(get_bits1(&s->gb)){
3467 idr(h); 3467 idr(h);
3468 } 3468 }
3469 3469
3470 /** 3470 /**
3471 * 3471 *
3472 * @return the removed picture or NULL if an error occures 3472 * @return the removed picture or NULL if an error occurs
3473 */ 3473 */
3474 static Picture * remove_short(H264Context *h, int frame_num){ 3474 static Picture * remove_short(H264Context *h, int frame_num){
3475 MpegEncContext * const s = &h->s; 3475 MpegEncContext * const s = &h->s;
3476 int i; 3476 int i;
3477 3477
3492 return NULL; 3492 return NULL;
3493 } 3493 }
3494 3494
3495 /** 3495 /**
3496 * 3496 *
3497 * @return the removed picture or NULL if an error occures 3497 * @return the removed picture or NULL if an error occurs
3498 */ 3498 */
3499 static Picture * remove_long(H264Context *h, int i){ 3499 static Picture * remove_long(H264Context *h, int i){
3500 Picture *pic; 3500 Picture *pic;
3501 3501
3502 pic= h->long_ref[i]; 3502 pic= h->long_ref[i];
3797 || (h->slice_num != 0 && slice_type == h->slice_type) ) { 3797 || (h->slice_num != 0 && slice_type == h->slice_type) ) {
3798 default_ref_list_done = 1; 3798 default_ref_list_done = 1;
3799 } 3799 }
3800 h->slice_type= slice_type; 3800 h->slice_type= slice_type;
3801 3801
3802 s->pict_type= h->slice_type; // to make a few old func happy, its wrong though 3802 s->pict_type= h->slice_type; // to make a few old func happy, it's wrong though
3803 3803
3804 pps_id= get_ue_golomb(&s->gb); 3804 pps_id= get_ue_golomb(&s->gb);
3805 if(pps_id>255){ 3805 if(pps_id>255){
3806 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); 3806 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n");
3807 return -1; 3807 return -1;
4089 level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part 4089 level_code= (prefix<<suffix_length) + get_bits(gb, suffix_length); //part
4090 else 4090 else
4091 level_code= prefix + get_bits(gb, 4); //part 4091 level_code= prefix + get_bits(gb, 4); //part
4092 }else if(prefix==15){ 4092 }else if(prefix==15){
4093 level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part 4093 level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part
4094 if(suffix_length==0) level_code+=15; //FIXME doesnt make (much)sense 4094 if(suffix_length==0) level_code+=15; //FIXME doesn't make (much)sense
4095 }else{ 4095 }else{
4096 av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y); 4096 av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y);
4097 return -1; 4097 return -1;
4098 } 4098 }
4099 4099
4224 static int decode_mb_cavlc(H264Context *h){ 4224 static int decode_mb_cavlc(H264Context *h){
4225 MpegEncContext * const s = &h->s; 4225 MpegEncContext * const s = &h->s;
4226 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; 4226 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
4227 int mb_type, partition_count, cbp; 4227 int mb_type, partition_count, cbp;
4228 4228
4229 s->dsp.clear_blocks(h->mb); //FIXME avoid if allready clear (move after skip handlong? 4229 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?
4230 4230
4231 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); 4231 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
4232 cbp = 0; /* avoid warning. FIXME: find a solution without slowing 4232 cbp = 0; /* avoid warning. FIXME: find a solution without slowing
4233 down the code */ 4233 down the code */
4234 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){ 4234 if(h->slice_type != I_TYPE && h->slice_type != SI_TYPE){
4311 tprintf("CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8)); 4311 tprintf("CHROMA V ICPM LEVEL (%3d)\n", show_bits(&s->gb, 8));
4312 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8); 4312 h->mb[index + (x&3) + 16*(x>>2)]= get_bits(&s->gb, 8);
4313 } 4313 }
4314 } 4314 }
4315 4315
4316 // In deblocking, the quantiser is 0 4316 // In deblocking, the quantizer is 0
4317 s->current_picture.qscale_table[mb_xy]= 0; 4317 s->current_picture.qscale_table[mb_xy]= 0;
4318 h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 0); 4318 h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 0);
4319 // All coeffs are presents 4319 // All coeffs are present
4320 memset(h->non_zero_count[mb_xy], 16, 16); 4320 memset(h->non_zero_count[mb_xy], 16, 16);
4321 4321
4322 return 0; 4322 return 0;
4323 } 4323 }
4324 4324
4580 } 4580 }
4581 4581
4582 h->chroma_qp= chroma_qp= get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale); 4582 h->chroma_qp= chroma_qp= get_chroma_qp(h->pps.chroma_qp_index_offset, s->qscale);
4583 if(IS_INTRA16x16(mb_type)){ 4583 if(IS_INTRA16x16(mb_type)){
4584 if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, s->qscale, 16) < 0){ 4584 if( decode_residual(h, h->intra_gb_ptr, h->mb, LUMA_DC_BLOCK_INDEX, dc_scan, s->qscale, 16) < 0){
4585 return -1; //FIXME continue if partotioned and other retirn -1 too 4585 return -1; //FIXME continue if partitioned and other return -1 too
4586 } 4586 }
4587 4587
4588 assert((cbp&15) == 0 || (cbp&15) == 15); 4588 assert((cbp&15) == 0 || (cbp&15) == 15);
4589 4589
4590 if(cbp&15){ 4590 if(cbp&15){
5199 static int decode_mb_cabac(H264Context *h) { 5199 static int decode_mb_cabac(H264Context *h) {
5200 MpegEncContext * const s = &h->s; 5200 MpegEncContext * const s = &h->s;
5201 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; 5201 const int mb_xy= s->mb_x + s->mb_y*s->mb_stride;
5202 int mb_type, partition_count, cbp = 0; 5202 int mb_type, partition_count, cbp = 0;
5203 5203
5204 s->dsp.clear_blocks(h->mb); //FIXME avoid if allready clear (move after skip handlong?) 5204 s->dsp.clear_blocks(h->mb); //FIXME avoid if already clear (move after skip handlong?)
5205 5205
5206 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); 5206 tprintf("pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y);
5207 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) { 5207 if( h->slice_type != I_TYPE && h->slice_type != SI_TYPE ) {
5208 /* read skip flags */ 5208 /* read skip flags */
5209 if( decode_cabac_mb_skip( h ) ) { 5209 if( decode_cabac_mb_skip( h ) ) {
5294 } 5294 }
5295 } 5295 }
5296 5296
5297 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); 5297 ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr);
5298 5298
5299 // All blocks are presents 5299 // All blocks are present
5300 h->cbp_table[mb_xy] = 0x1ef; 5300 h->cbp_table[mb_xy] = 0x1ef;
5301 h->chroma_pred_mode_table[mb_xy] = 0; 5301 h->chroma_pred_mode_table[mb_xy] = 0;
5302 // In deblocking, the quantiser is 0 5302 // In deblocking, the quantizer is 0
5303 s->current_picture.qscale_table[mb_xy]= 0; 5303 s->current_picture.qscale_table[mb_xy]= 0;
5304 h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 0); 5304 h->chroma_qp = get_chroma_qp(h->pps.chroma_qp_index_offset, 0);
5305 // All coeffs are presents 5305 // All coeffs are present
5306 memset(h->non_zero_count[mb_xy], 16, 16); 5306 memset(h->non_zero_count[mb_xy], 16, 16);
5307 return 0; 5307 return 0;
5308 } 5308 }
5309 5309
5310 fill_caches(h, mb_type, 0); 5310 fill_caches(h, mb_type, 0);
5983 // and current and left pair do not have the same interlaced type 5983 // and current and left pair do not have the same interlaced type
5984 && (IS_INTERLACED(s->current_picture.mb_type[mb_xy]) != IS_INTERLACED(s->current_picture.mb_type[mb_xy-1])) 5984 && (IS_INTERLACED(s->current_picture.mb_type[mb_xy]) != IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]))
5985 // and left mb is in the same slice if deblocking_filter == 2 5985 // and left mb is in the same slice if deblocking_filter == 2
5986 && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_table[mb_xy])) { 5986 && (h->deblocking_filter!=2 || h->slice_table[mb_xy-1] == h->slice_table[mb_xy])) {
5987 /* First vertical edge is different in MBAFF frames 5987 /* First vertical edge is different in MBAFF frames
5988 * There are 8 differents bS to compute and 2 differents Qp 5988 * There are 8 different bS to compute and 2 different Qp
5989 */ 5989 */
5990 int bS[8]; 5990 int bS[8];
5991 int qp[2]; 5991 int qp[2];
5992 int chroma_qp[2]; 5992 int chroma_qp[2];
5993 5993
6018 } 6018 }
6019 } 6019 }
6020 } 6020 }
6021 } 6021 }
6022 if(bS[0]+bS[1]+bS[2]+bS[3] != 0) { 6022 if(bS[0]+bS[1]+bS[2]+bS[3] != 0) {
6023 // Do not use s->qscale as luma quantiser because it has not the same 6023 // Do not use s->qscale as luma quantizer because it has not the same
6024 // value in IPCM macroblocks. 6024 // value in IPCM macroblocks.
6025 qp[0] = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[h->left_mb_xy[0]] + 1 ) >> 1; 6025 qp[0] = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[h->left_mb_xy[0]] + 1 ) >> 1;
6026 chroma_qp[0] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy] ) + 6026 chroma_qp[0] = ( get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[mb_xy] ) +
6027 get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[h->left_mb_xy[0]] ) + 1 ) >> 1; 6027 get_chroma_qp( h->pps.chroma_qp_index_offset, s->current_picture.qscale_table[h->left_mb_xy[0]] ) + 1 ) >> 1;
6028 qp[1] = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[h->left_mb_xy[1]] + 1 ) >> 1; 6028 qp[1] = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[h->left_mb_xy[1]] + 1 ) >> 1;
6052 if (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_table[mb_xy]) 6052 if (h->deblocking_filter==2 && h->slice_table[mbm_xy] != h->slice_table[mb_xy])
6053 start = 1; 6053 start = 1;
6054 6054
6055 /* Calculate bS */ 6055 /* Calculate bS */
6056 for( edge = start; edge < 4; edge++ ) { 6056 for( edge = start; edge < 4; edge++ ) {
6057 /* mbn_xy: neighbour macroblock */ 6057 /* mbn_xy: neighbor macroblock */
6058 int mbn_xy = edge > 0 ? mb_xy : mbm_xy; 6058 int mbn_xy = edge > 0 ? mb_xy : mbm_xy;
6059 int bS[4]; 6059 int bS[4];
6060 int qp; 6060 int qp;
6061 6061
6062 if (h->mb_aff_frame && (dir == 1) && (edge == 0) && ((mb_y & 1) == 0) 6062 if (h->mb_aff_frame && (dir == 1) && (edge == 0) && ((mb_y & 1) == 0)
6079 } else { 6079 } else {
6080 // TODO 6080 // TODO
6081 assert(0); 6081 assert(0);
6082 } 6082 }
6083 /* Filter edge */ 6083 /* Filter edge */
6084 // Do not use s->qscale as luma quantiser because it has not the same 6084 // Do not use s->qscale as luma quantizer because it has not the same
6085 // value in IPCM macroblocks. 6085 // value in IPCM macroblocks.
6086 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; 6086 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
6087 tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); 6087 tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);
6088 { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); } 6088 { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }
6089 filter_mb_edgeh( h, &img_y[0], tmp_linesize, bS, qp ); 6089 filter_mb_edgeh( h, &img_y[0], tmp_linesize, bS, qp );
6100 } else { 6100 } else {
6101 // TODO 6101 // TODO
6102 assert(0); 6102 assert(0);
6103 } 6103 }
6104 /* Filter edge */ 6104 /* Filter edge */
6105 // Do not use s->qscale as luma quantiser because it has not the same 6105 // Do not use s->qscale as luma quantizer because it has not the same
6106 // value in IPCM macroblocks. 6106 // value in IPCM macroblocks.
6107 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; 6107 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
6108 tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); 6108 tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize);
6109 { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); } 6109 { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }
6110 filter_mb_edgeh( h, &img_y[linesize], tmp_linesize, bS, qp ); 6110 filter_mb_edgeh( h, &img_y[linesize], tmp_linesize, bS, qp );
6159 if(bS[0]+bS[1]+bS[2]+bS[3] == 0) 6159 if(bS[0]+bS[1]+bS[2]+bS[3] == 0)
6160 continue; 6160 continue;
6161 } 6161 }
6162 6162
6163 /* Filter edge */ 6163 /* Filter edge */
6164 // Do not use s->qscale as luma quantiser because it has not the same 6164 // Do not use s->qscale as luma quantizer because it has not the same
6165 // value in IPCM macroblocks. 6165 // value in IPCM macroblocks.
6166 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; 6166 qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1;
6167 //tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]); 6167 //tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp, s->current_picture.qscale_table[mbn_xy]);
6168 tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); 6168 tprintf("filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize);
6169 { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); } 6169 { int i; for (i = 0; i < 4; i++) tprintf(" bS[%d]:%d", i, bS[i]); tprintf("\n"); }
6739 if( s->hurry_up == 1 && h->nal_ref_idc == 0 ) 6739 if( s->hurry_up == 1 && h->nal_ref_idc == 0 )
6740 continue; 6740 continue;
6741 6741
6742 switch(h->nal_unit_type){ 6742 switch(h->nal_unit_type){
6743 case NAL_IDR_SLICE: 6743 case NAL_IDR_SLICE:
6744 idr(h); //FIXME ensure we dont loose some frames if there is reordering 6744 idr(h); //FIXME ensure we don't loose some frames if there is reordering
6745 case NAL_SLICE: 6745 case NAL_SLICE:
6746 init_get_bits(&s->gb, ptr, bit_length); 6746 init_get_bits(&s->gb, ptr, bit_length);
6747 h->intra_gb_ptr= 6747 h->intra_gb_ptr=
6748 h->inter_gb_ptr= &s->gb; 6748 h->inter_gb_ptr= &s->gb;
6749 s->data_partitioning = 0; 6749 s->data_partitioning = 0;
6818 6818
6819 return buf_index; 6819 return buf_index;
6820 } 6820 }
6821 6821
6822 /** 6822 /**
6823 * retunrs the number of bytes consumed for building the current frame 6823 * returns the number of bytes consumed for building the current frame
6824 */ 6824 */
6825 static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){ 6825 static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){
6826 if(s->flags&CODEC_FLAG_TRUNCATED){ 6826 if(s->flags&CODEC_FLAG_TRUNCATED){
6827 pos -= s->parse_context.last_index; 6827 pos -= s->parse_context.last_index;
6828 if(pos<0) pos=0; // FIXME remove (uneeded?) 6828 if(pos<0) pos=0; // FIXME remove (unneeded?)
6829 6829
6830 return pos; 6830 return pos;
6831 }else{ 6831 }else{
6832 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...) 6832 if(pos==0) pos=1; //avoid infinite loops (i doubt thats needed but ...)
6833 if(pos+10>buf_size) pos=buf_size; // oops ;) 6833 if(pos+10>buf_size) pos=buf_size; // oops ;)