comparison h264.c @ 7374:6d718739ee8e libavcodec

misc spelling/grammar fixes
author diego
date Thu, 24 Jul 2008 10:55:36 +0000
parents 443fdc440854
children eee233178dd6
comparison
equal deleted inserted replaced
7373:266d4949aa15 7374:6d718739ee8e
131 : (!curr_mb_frame_flag && !topleft_mb_frame_flag) // top macroblock 131 : (!curr_mb_frame_flag && !topleft_mb_frame_flag) // top macroblock
132 ) { 132 ) {
133 topleft_xy -= s->mb_stride; 133 topleft_xy -= s->mb_stride;
134 } else if(bottom && curr_mb_frame_flag && !left_mb_frame_flag) { 134 } else if(bottom && curr_mb_frame_flag && !left_mb_frame_flag) {
135 topleft_xy += s->mb_stride; 135 topleft_xy += s->mb_stride;
136 // take topleft mv from the middle of the mb, as opposed to all other modes which use the bottom-right partition 136 // take top left mv from the middle of the mb, as opposed to all other modes which use the bottom right partition
137 topleft_partition = 0; 137 topleft_partition = 0;
138 } 138 }
139 if (bottom 139 if (bottom
140 ? !curr_mb_frame_flag // bottom macroblock 140 ? !curr_mb_frame_flag // bottom macroblock
141 : (!curr_mb_frame_flag && !topright_mb_frame_flag) // top macroblock 141 : (!curr_mb_frame_flag && !topright_mb_frame_flag) // top macroblock
290 2 L . .L . . . . 290 2 L . .L . . . .
291 3 . T TL . . . . 291 3 . T TL . . . .
292 4 L . .L . . . . 292 4 L . .L . . . .
293 5 L . .. . . . . 293 5 L . .. . . . .
294 */ 294 */
295 //FIXME constraint_intra_pred & partitioning & nnz (lets hope this is just a typo in the spec) 295 //FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec)
296 if(top_type){ 296 if(top_type){
297 h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][4]; 297 h->non_zero_count_cache[4+8*0]= h->non_zero_count[top_xy][4];
298 h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][5]; 298 h->non_zero_count_cache[5+8*0]= h->non_zero_count[top_xy][5];
299 h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][6]; 299 h->non_zero_count_cache[6+8*0]= h->non_zero_count[top_xy][6];
300 h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3]; 300 h->non_zero_count_cache[7+8*0]= h->non_zero_count[top_xy][3];
671 *(uint16_t*)&h->non_zero_count[mb_xy][14] = v; 671 *(uint16_t*)&h->non_zero_count[mb_xy][14] = v;
672 } 672 }
673 } 673 }
674 674
675 /** 675 /**
676 * gets the predicted number of non zero coefficients. 676 * gets the predicted number of non-zero coefficients.
677 * @param n block index 677 * @param n block index
678 */ 678 */
679 static inline int pred_non_zero_count(H264Context *h, int n){ 679 static inline int pred_non_zero_count(H264Context *h, int n){
680 const int index8= scan8[n]; 680 const int index8= scan8[n];
681 const int left= h->non_zero_count_cache[index8 - 1]; 681 const int left= h->non_zero_count_cache[index8 - 1];
726 SET_DIAG_MV(*2, >>1, s->mb_x*4-1, (s->mb_y|1)*4+(s->mb_y&1)*2+(i>>4)-1); 726 SET_DIAG_MV(*2, >>1, s->mb_x*4-1, (s->mb_y|1)*4+(s->mb_y&1)*2+(i>>4)-1);
727 } 727 }
728 if(MB_FIELD 728 if(MB_FIELD
729 && !IS_INTERLACED(mb_types[h->left_mb_xy[0]]) 729 && !IS_INTERLACED(mb_types[h->left_mb_xy[0]])
730 && i >= scan8[0]+8){ 730 && i >= scan8[0]+8){
731 // leftshift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's ok. 731 // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
732 SET_DIAG_MV(/2, <<1, s->mb_x*4-1, (s->mb_y&~1)*4 - 1 + ((i-scan8[0])>>3)*2); 732 SET_DIAG_MV(/2, <<1, s->mb_x*4-1, (s->mb_y&~1)*4 - 1 + ((i-scan8[0])>>3)*2);
733 } 733 }
734 } 734 }
735 #undef SET_DIAG_MV 735 #undef SET_DIAG_MV
736 } 736 }
1452 } 1452 }
1453 return 0; 1453 return 0;
1454 } 1454 }
1455 1455
1456 /** 1456 /**
1457 * idct tranforms the 16 dc values and dequantize them. 1457 * IDCT transforms the 16 dc values and dequantizes them.
1458 * @param qp quantization parameter 1458 * @param qp quantization parameter
1459 */ 1459 */
1460 static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp, int qmul){ 1460 static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp, int qmul){
1461 #define stride 16 1461 #define stride 16
1462 int i; 1462 int i;
1484 const int z0= temp[4*0+i] + temp[4*2+i]; 1484 const int z0= temp[4*0+i] + temp[4*2+i];
1485 const int z1= temp[4*0+i] - temp[4*2+i]; 1485 const int z1= temp[4*0+i] - temp[4*2+i];
1486 const int z2= temp[4*1+i] - temp[4*3+i]; 1486 const int z2= temp[4*1+i] - temp[4*3+i];
1487 const int z3= temp[4*1+i] + temp[4*3+i]; 1487 const int z3= temp[4*1+i] + temp[4*3+i];
1488 1488
1489 block[stride*0 +offset]= ((((z0 + z3)*qmul + 128 ) >> 8)); //FIXME think about merging this into decode_resdual 1489 block[stride*0 +offset]= ((((z0 + z3)*qmul + 128 ) >> 8)); //FIXME think about merging this into decode_residual
1490 block[stride*2 +offset]= ((((z1 + z2)*qmul + 128 ) >> 8)); 1490 block[stride*2 +offset]= ((((z1 + z2)*qmul + 128 ) >> 8));
1491 block[stride*8 +offset]= ((((z1 - z2)*qmul + 128 ) >> 8)); 1491 block[stride*8 +offset]= ((((z1 - z2)*qmul + 128 ) >> 8));
1492 block[stride*10+offset]= ((((z0 - z3)*qmul + 128 ) >> 8)); 1492 block[stride*10+offset]= ((((z0 - z3)*qmul + 128 ) >> 8));
1493 } 1493 }
1494 } 1494 }
1495 1495
1496 #if 0 1496 #if 0
1497 /** 1497 /**
1498 * dct tranforms the 16 dc values. 1498 * DCT transforms the 16 dc values.
1499 * @param qp quantization parameter ??? FIXME 1499 * @param qp quantization parameter ??? FIXME
1500 */ 1500 */
1501 static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){ 1501 static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){
1502 // const int qmul= dequant_coeff[qp][0]; 1502 // const int qmul= dequant_coeff[qp][0];
1503 int i; 1503 int i;
1682 const int full_mx= mx>>2; 1682 const int full_mx= mx>>2;
1683 const int full_my= my>>2; 1683 const int full_my= my>>2;
1684 const int pic_width = 16*s->mb_width; 1684 const int pic_width = 16*s->mb_width;
1685 const int pic_height = 16*s->mb_height >> MB_FIELD; 1685 const int pic_height = 16*s->mb_height >> MB_FIELD;
1686 1686
1687 if(!pic->data[0]) //FIXME this is unacceptable, some senseable error concealment must be done for missing reference frames 1687 if(!pic->data[0]) //FIXME this is unacceptable, some sensible error concealment must be done for missing reference frames
1688 return; 1688 return;
1689 1689
1690 if(mx&7) extra_width -= 3; 1690 if(mx&7) extra_width -= 3;
1691 if(my&7) extra_height -= 3; 1691 if(my&7) extra_height -= 3;
1692 1692
2224 return -1; 2224 return -1;
2225 ff_er_frame_start(s); 2225 ff_er_frame_start(s);
2226 /* 2226 /*
2227 * MPV_frame_start uses pict_type to derive key_frame. 2227 * MPV_frame_start uses pict_type to derive key_frame.
2228 * This is incorrect for H.264; IDR markings must be used. 2228 * This is incorrect for H.264; IDR markings must be used.
2229 * Zero here; IDR markings per slice in frame or fields are OR'd in later. 2229 * Zero here; IDR markings per slice in frame or fields are ORed in later.
2230 * See decode_nal_units(). 2230 * See decode_nal_units().
2231 */ 2231 */
2232 s->current_picture_ptr->key_frame= 0; 2232 s->current_picture_ptr->key_frame= 0;
2233 2233
2234 assert(s->linesize && s->uvlinesize); 2234 assert(s->linesize && s->uvlinesize);
2254 if(FRAME_MBAFF || s->avctx->thread_count > 1) 2254 if(FRAME_MBAFF || s->avctx->thread_count > 1)
2255 memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(uint8_t)); 2255 memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(uint8_t));
2256 2256
2257 // s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1; 2257 // s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1;
2258 2258
2259 // We mark the current picture as non reference after allocating it, so 2259 // We mark the current picture as non-reference after allocating it, so
2260 // that if we break out due to an error it can be released automatically 2260 // that if we break out due to an error it can be released automatically
2261 // in the next MPV_frame_start(). 2261 // in the next MPV_frame_start().
2262 // SVQ3 as well as most other codecs have only last/next/current and thus 2262 // SVQ3 as well as most other codecs have only last/next/current and thus
2263 // get released even with set reference, besides SVQ3 and others do not 2263 // get released even with set reference, besides SVQ3 and others do not
2264 // mark frames as reference later "naturally". 2264 // mark frames as reference later "naturally".
2465 2465
2466 if (!simple && MB_FIELD) { 2466 if (!simple && MB_FIELD) {
2467 linesize = h->mb_linesize = s->linesize * 2; 2467 linesize = h->mb_linesize = s->linesize * 2;
2468 uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2; 2468 uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2;
2469 block_offset = &h->block_offset[24]; 2469 block_offset = &h->block_offset[24];
2470 if(mb_y&1){ //FIXME move out of this func? 2470 if(mb_y&1){ //FIXME move out of this function?
2471 dest_y -= s->linesize*15; 2471 dest_y -= s->linesize*15;
2472 dest_cb-= s->uvlinesize*7; 2472 dest_cb-= s->uvlinesize*7;
2473 dest_cr-= s->uvlinesize*7; 2473 dest_cr-= s->uvlinesize*7;
2474 } 2474 }
2475 if(FRAME_MBAFF) { 2475 if(FRAME_MBAFF) {
2874 int len[2]; 2874 int len[2];
2875 int short_len[2]; 2875 int short_len[2];
2876 int out_i; 2876 int out_i;
2877 int limit= INT_MIN; 2877 int limit= INT_MIN;
2878 2878
2879 /* sort frame according to poc in B slice */ 2879 /* sort frame according to POC in B slice */
2880 for(out_i=0; out_i<h->short_ref_count; out_i++){ 2880 for(out_i=0; out_i<h->short_ref_count; out_i++){
2881 int best_i=INT_MIN; 2881 int best_i=INT_MIN;
2882 int best_poc=INT_MAX; 2882 int best_poc=INT_MAX;
2883 2883
2884 for(i=0; i<h->short_ref_count; i++){ 2884 for(i=0; i<h->short_ref_count; i++){
2901 } 2901 }
2902 } 2902 }
2903 2903
2904 tprintf(h->s.avctx, "current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current); 2904 tprintf(h->s.avctx, "current poc: %d, smallest_poc_greater_than_current: %d\n", s->current_picture_ptr->poc, smallest_poc_greater_than_current);
2905 2905
2906 // find the largest poc 2906 // find the largest POC
2907 for(list=0; list<2; list++){ 2907 for(list=0; list<2; list++){
2908 int index = 0; 2908 int index = 0;
2909 int j= -99; 2909 int j= -99;
2910 int step= list ? -1 : 1; 2910 int step= list ? -1 : 1;
2911 2911
3031 MpegEncContext * const s = &h->s; 3031 MpegEncContext * const s = &h->s;
3032 int list, index, pic_structure; 3032 int list, index, pic_structure;
3033 3033
3034 print_short_term(h); 3034 print_short_term(h);
3035 print_long_term(h); 3035 print_long_term(h);
3036 if(h->slice_type_nos==FF_I_TYPE) return 0; //FIXME move before func 3036 if(h->slice_type_nos==FF_I_TYPE) return 0; //FIXME move before function
3037 3037
3038 for(list=0; list<h->list_count; list++){ 3038 for(list=0; list<h->list_count; list++){
3039 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]); 3039 memcpy(h->ref_list[list], h->default_ref_list[list], sizeof(Picture)*h->ref_count[list]);
3040 3040
3041 if(get_bits1(&s->gb)){ 3041 if(get_bits1(&s->gb)){
3076 assert(ref->reference); 3076 assert(ref->reference);
3077 assert(!ref->long_ref); 3077 assert(!ref->long_ref);
3078 if(ref->data[0] != NULL && 3078 if(ref->data[0] != NULL &&
3079 ref->frame_num == frame_num && 3079 ref->frame_num == frame_num &&
3080 (ref->reference & pic_structure) && 3080 (ref->reference & pic_structure) &&
3081 ref->long_ref == 0) // ignore non existing pictures by testing data[0] pointer 3081 ref->long_ref == 0) // ignore non-existing pictures by testing data[0] pointer
3082 break; 3082 break;
3083 } 3083 }
3084 if(i>=0) 3084 if(i>=0)
3085 ref->pic_id= pred; 3085 ref->pic_id= pred;
3086 }else{ 3086 }else{
3918 default_ref_list_done = 1; 3918 default_ref_list_done = 1;
3919 } 3919 }
3920 h->slice_type= slice_type; 3920 h->slice_type= slice_type;
3921 h->slice_type_nos= slice_type & 3; 3921 h->slice_type_nos= slice_type & 3;
3922 3922
3923 s->pict_type= h->slice_type; // to make a few old func happy, it's wrong though 3923 s->pict_type= h->slice_type; // to make a few old functions happy, it's wrong though
3924 if (s->pict_type == FF_B_TYPE && s0->last_picture_ptr == NULL) { 3924 if (s->pict_type == FF_B_TYPE && s0->last_picture_ptr == NULL) {
3925 av_log(h->s.avctx, AV_LOG_ERROR, 3925 av_log(h->s.avctx, AV_LOG_ERROR,
3926 "B picture before any references, skipping\n"); 3926 "B picture before any references, skipping\n");
3927 return -1; 3927 return -1;
3928 } 3928 }
3931 if(pps_id>=MAX_PPS_COUNT){ 3931 if(pps_id>=MAX_PPS_COUNT){
3932 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); 3932 av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n");
3933 return -1; 3933 return -1;
3934 } 3934 }
3935 if(!h0->pps_buffers[pps_id]) { 3935 if(!h0->pps_buffers[pps_id]) {
3936 av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\n"); 3936 av_log(h->s.avctx, AV_LOG_ERROR, "non-existing PPS referenced\n");
3937 return -1; 3937 return -1;
3938 } 3938 }
3939 h->pps= *h0->pps_buffers[pps_id]; 3939 h->pps= *h0->pps_buffers[pps_id];
3940 3940
3941 if(!h0->sps_buffers[h->pps.sps_id]) { 3941 if(!h0->sps_buffers[h->pps.sps_id]) {
3942 av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n"); 3942 av_log(h->s.avctx, AV_LOG_ERROR, "non-existing SPS referenced\n");
3943 return -1; 3943 return -1;
3944 } 3944 }
3945 h->sps = *h0->sps_buffers[h->pps.sps_id]; 3945 h->sps = *h0->sps_buffers[h->pps.sps_id];
3946 3946
3947 if(h == h0 && h->dequant_coeff_pps != pps_id){ 3947 if(h == h0 && h->dequant_coeff_pps != pps_id){
4128 4128
4129 if(h->pps.redundant_pic_cnt_present){ 4129 if(h->pps.redundant_pic_cnt_present){
4130 h->redundant_pic_count= get_ue_golomb(&s->gb); 4130 h->redundant_pic_count= get_ue_golomb(&s->gb);
4131 } 4131 }
4132 4132
4133 //set defaults, might be overriden a few line later 4133 //set defaults, might be overridden a few lines later
4134 h->ref_count[0]= h->pps.ref_count[0]; 4134 h->ref_count[0]= h->pps.ref_count[0];
4135 h->ref_count[1]= h->pps.ref_count[1]; 4135 h->ref_count[1]= h->pps.ref_count[1];
4136 4136
4137 if(h->slice_type_nos != FF_I_TYPE){ 4137 if(h->slice_type_nos != FF_I_TYPE){
4138 if(h->slice_type_nos == FF_B_TYPE){ 4138 if(h->slice_type_nos == FF_B_TYPE){
4522 h->prev_mb_skipped= 1; 4522 h->prev_mb_skipped= 1;
4523 } 4523 }
4524 4524
4525 /** 4525 /**
4526 * decodes a macroblock 4526 * decodes a macroblock
4527 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed 4527 * @returns 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed
4528 */ 4528 */
4529 static int decode_mb_cavlc(H264Context *h){ 4529 static int decode_mb_cavlc(H264Context *h){
4530 MpegEncContext * const s = &h->s; 4530 MpegEncContext * const s = &h->s;
4531 int mb_xy; 4531 int mb_xy;
4532 int partition_count; 4532 int partition_count;
5640 return; 5640 return;
5641 } 5641 }
5642 5642
5643 /** 5643 /**
5644 * decodes a macroblock 5644 * decodes a macroblock
5645 * @returns 0 if ok, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed 5645 * @returns 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed
5646 */ 5646 */
5647 static int decode_mb_cabac(H264Context *h) { 5647 static int decode_mb_cabac(H264Context *h) {
5648 MpegEncContext * const s = &h->s; 5648 MpegEncContext * const s = &h->s;
5649 int mb_xy; 5649 int mb_xy;
5650 int mb_type, partition_count, cbp = 0; 5650 int mb_type, partition_count, cbp = 0;
7694 if (err < 0) 7694 if (err < 0)
7695 av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n"); 7695 av_log(h->s.avctx, AV_LOG_ERROR, "decode_slice_header error\n");
7696 else if(err == 1) { 7696 else if(err == 1) {
7697 /* Slice could not be decoded in parallel mode, copy down 7697 /* Slice could not be decoded in parallel mode, copy down
7698 * NAL unit stuff to context 0 and restart. Note that 7698 * NAL unit stuff to context 0 and restart. Note that
7699 * rbsp_buffer is not transfered, but since we no longer 7699 * rbsp_buffer is not transferred, but since we no longer
7700 * run in parallel mode this should not be an issue. */ 7700 * run in parallel mode this should not be an issue. */
7701 h->nal_unit_type = hx->nal_unit_type; 7701 h->nal_unit_type = hx->nal_unit_type;
7702 h->nal_ref_idc = hx->nal_ref_idc; 7702 h->nal_ref_idc = hx->nal_ref_idc;
7703 hx = h; 7703 hx = h;
7704 goto again; 7704 goto again;
7729 int buf_index; 7729 int buf_index;
7730 7730
7731 s->flags= avctx->flags; 7731 s->flags= avctx->flags;
7732 s->flags2= avctx->flags2; 7732 s->flags2= avctx->flags2;
7733 7733
7734 /* end of stream, output whats still in the buffers */ 7734 /* end of stream, output what is still in the buffers */
7735 if (buf_size == 0) { 7735 if (buf_size == 0) {
7736 Picture *out; 7736 Picture *out;
7737 int i, out_idx; 7737 int i, out_idx;
7738 7738
7739 //FIXME factorize this with the output code below 7739 //FIXME factorize this with the output code below