diff options
Diffstat (limited to 'src/libffmpeg/libavcodec/h264.c')
-rw-r--r-- | src/libffmpeg/libavcodec/h264.c | 99 |
1 files changed, 42 insertions, 57 deletions
diff --git a/src/libffmpeg/libavcodec/h264.c b/src/libffmpeg/libavcodec/h264.c index 96f0925d7..43ed13e99 100644 --- a/src/libffmpeg/libavcodec/h264.c +++ b/src/libffmpeg/libavcodec/h264.c @@ -643,7 +643,7 @@ static inline int check_intra4x4_pred_mode(H264Context *h){ for(i=0; i<4; i++){ int status= top[ h->intra4x4_pred_mode_cache[scan8[0] + i] ]; if(status<0){ - fprintf(stderr, "top block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y); return -1; } else if(status){ h->intra4x4_pred_mode_cache[scan8[0] + i]= status; @@ -655,7 +655,7 @@ static inline int check_intra4x4_pred_mode(H264Context *h){ for(i=0; i<4; i++){ int status= left[ h->intra4x4_pred_mode_cache[scan8[0] + 8*i] ]; if(status<0){ - fprintf(stderr, "left block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra4x4 mode %d at %d %d\n", status, s->mb_x, s->mb_y); return -1; } else if(status){ h->intra4x4_pred_mode_cache[scan8[0] + 8*i]= status; @@ -677,7 +677,7 @@ static inline int check_intra_pred_mode(H264Context *h, int mode){ if(!(h->top_samples_available&0x8000)){ mode= top[ mode ]; if(mode<0){ - fprintf(stderr, "top block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "top block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y); return -1; } } @@ -685,7 +685,7 @@ static inline int check_intra_pred_mode(H264Context *h, int mode){ if(!(h->left_samples_available&0x8000)){ mode= left[ mode ]; if(mode<0){ - fprintf(stderr, "left block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "left block unavailable for requested intra mode at %d %d\n", s->mb_x, s->mb_y); return -1; } } @@ -1001,8 +1001,6 @@ static uint8_t *decode_nal(H264Context *h, uint8_t *src, int *dst_length, int *c return dst; } -#ifdef CONFIG_ENCODERS - /** * @param src the data which should be escaped * @param dst the target buffer, dst+1 == src is allowed as a special case @@ -1076,8 +1074,6 @@ static void encode_rbsp_trailing(PutBitContext *pb){ if(length) put_bits(pb, length, 0); } -#endif - /** * identifies the exact end of the bitstream * @return the length of the trailing, or 0 if damaged @@ -1136,7 +1132,6 @@ static void h264_luma_dc_dequant_idct_c(DCTELEM *block, int qp){ } } -#if 0 /** * dct tranforms the 16 dc values. * @param qp quantization parameter ??? FIXME @@ -1174,8 +1169,6 @@ static void h264_luma_dc_dct_c(DCTELEM *block/*, int qp*/){ block[stride*10+offset]= (z0 - z3)>>1; } } -#endif - #undef xStride #undef stride @@ -1201,7 +1194,6 @@ static void chroma_dc_dequant_idct_c(DCTELEM *block, int qp){ block[stride*1 + xStride*1]= ((e-b)*qmul + 0)>>1; } -#if 0 static void chroma_dc_dct_c(DCTELEM *block){ const int stride= 16*2; const int xStride= 16; @@ -1222,7 +1214,6 @@ static void chroma_dc_dct_c(DCTELEM *block){ block[stride*1 + xStride*0]= (a-c); block[stride*1 + xStride*1]= (e-b); } -#endif /** * gets the chroma qp. @@ -1292,7 +1283,6 @@ static void h264_add_idct_c(uint8_t *dst, DCTELEM *block, int stride){ #endif } -#if 0 static void h264_diff_dct_c(DCTELEM *block, uint8_t *src1, uint8_t *src2, int stride){ int i; //FIXME try int temp instead of block @@ -1325,7 +1315,6 @@ static void h264_diff_dct_c(DCTELEM *block, uint8_t *src1, uint8_t *src2, int st block[3*4 + i]= z3 - 2*z2; } } -#endif //FIXME need to check that this doesnt overflow signed 32 bit for low qp, iam not sure, its very close //FIXME check that gcc inlines this (and optimizes intra & seperate_dc stuff away) @@ -2169,6 +2158,7 @@ static void common_init(H264Context *h){ init_pred_ptrs(h); + s->unrestricted_mv=1; s->decode=1; //FIXME } @@ -2343,11 +2333,9 @@ static void hl_decode_mb(H264Context *h){ } } -#if 0 static void decode_mb_cabac(H264Context *h){ // MpegEncContext * const s = &h->s; } -#endif /** * fills the default_ref_list. @@ -2460,7 +2448,7 @@ static int decode_ref_pic_list_reordering(H264Context *h){ if(index >= h->ref_count[list]){ - fprintf(stderr, "reference count overflow\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "reference count overflow\n"); return -1; } @@ -2469,7 +2457,7 @@ static int decode_ref_pic_list_reordering(H264Context *h){ const int abs_diff_pic_num= get_ue_golomb(&s->gb) + 1; if(abs_diff_pic_num >= h->max_pic_num){ - fprintf(stderr, "abs_diff_pic_num overflow\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "abs_diff_pic_num overflow\n"); return -1; } @@ -2491,7 +2479,7 @@ static int decode_ref_pic_list_reordering(H264Context *h){ } if(i < index){ - fprintf(stderr, "reference picture missing during reorder\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "reference picture missing during reorder\n"); memset(&h->ref_list[list][index], 0, sizeof(Picture)); //FIXME }else if(i > index){ Picture tmp= h->ref_list[list][i]; @@ -2503,7 +2491,7 @@ static int decode_ref_pic_list_reordering(H264Context *h){ }else if(reordering_of_pic_nums_idc==3) break; else{ - fprintf(stderr, "illegal reordering_of_pic_nums_idc\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "illegal reordering_of_pic_nums_idc\n"); return -1; } } @@ -2573,12 +2561,12 @@ static Picture * remove_short(H264Context *h, int frame_num){ int i; if(s->avctx->debug&FF_DEBUG_MMCO) - printf("remove short %d count %d\n", frame_num, h->short_ref_count); + av_log(h->s.avctx, AV_LOG_DEBUG, "remove short %d count %d\n", frame_num, h->short_ref_count); for(i=0; i<h->short_ref_count; i++){ Picture *pic= h->short_ref[i]; if(s->avctx->debug&FF_DEBUG_MMCO) - printf("%d %d %p\n", i, pic->frame_num, pic); + av_log(h->s.avctx, AV_LOG_DEBUG, "%d %d %p\n", i, pic->frame_num, pic); if(pic->frame_num == frame_num){ h->short_ref[i]= NULL; memmove(&h->short_ref[i], &h->short_ref[i+1], (h->short_ref_count - i - 1)*sizeof(Picture*)); @@ -2617,11 +2605,11 @@ static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ Picture *pic; if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) - printf("no mmco here\n"); + av_log(h->s.avctx, AV_LOG_DEBUG, "no mmco here\n"); for(i=0; i<mmco_count; i++){ if(s->avctx->debug&FF_DEBUG_MMCO) - printf("mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_frame_num, h->mmco[i].long_index); + av_log(h->s.avctx, AV_LOG_DEBUG, "mmco:%d %d %d\n", h->mmco[i].opcode, h->mmco[i].short_frame_num, h->mmco[i].long_index); switch(mmco[i].opcode){ case MMCO_SHORT2UNUSED: @@ -2679,7 +2667,7 @@ static int execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ pic= remove_short(h, s->current_picture_ptr->frame_num); if(pic){ pic->reference=0; - fprintf(stderr, "illegal short term buffer state detected\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); } if(h->short_ref_count) @@ -2722,13 +2710,13 @@ static int decode_ref_pic_marking(H264Context *h){ if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){ h->mmco[i].long_index= get_ue_golomb(&s->gb); if(/*h->mmco[i].long_index >= h->long_ref_count || h->long_ref[ h->mmco[i].long_index ] == NULL*/ h->mmco[i].long_index >= 16){ - fprintf(stderr, "illegal long ref in memory management control operation %d\n", opcode); + av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); return -1; } } if(opcode > MMCO_LONG){ - fprintf(stderr, "illegal memory management control operation %d\n", opcode); + av_log(h->s.avctx, AV_LOG_ERROR, "illegal memory management control operation %d\n", opcode); return -1; } } @@ -2848,7 +2836,7 @@ static int decode_slice_header(H264Context *h){ h->slice_type= get_ue_golomb(&s->gb); if(h->slice_type > 9){ - fprintf(stderr, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "slice type too large (%d) at %d %d\n", h->slice_type, s->mb_x, s->mb_y); } if(h->slice_type > 4){ h->slice_type -= 5; @@ -2862,18 +2850,18 @@ static int decode_slice_header(H264Context *h){ pps_id= get_ue_golomb(&s->gb); if(pps_id>255){ - fprintf(stderr, "pps_id out of range\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "pps_id out of range\n"); return -1; } h->pps= h->pps_buffer[pps_id]; if(h->pps.slice_group_count == 0){ - fprintf(stderr, "non existing PPS referenced\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "non existing PPS referenced\n"); return -1; } h->sps= h->sps_buffer[ h->pps.sps_id ]; if(h->sps.log2_max_frame_num == 0){ - fprintf(stderr, "non existing SPS referenced\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "non existing SPS referenced\n"); return -1; } @@ -2932,11 +2920,9 @@ static int decode_slice_header(H264Context *h){ h->max_pic_num= 1<<(h->sps.log2_max_frame_num + 1); } -#if 0 if(h->nal_unit_type == NAL_IDR_SLICE){ get_ue_golomb(&s->gb); /* idr_pic_id */ } -#endif if(h->sps.poc_type==0){ h->poc_lsb= get_bits(&s->gb, h->sps.log2_max_poc_lsb); @@ -2975,7 +2961,7 @@ static int decode_slice_header(H264Context *h){ h->ref_count[1]= get_ue_golomb(&s->gb) + 1; if(h->ref_count[0] > 32 || h->ref_count[1] > 32){ - fprintf(stderr, "reference overflow\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); return -1; } } @@ -2997,14 +2983,12 @@ static int decode_slice_header(H264Context *h){ s->qscale = h->pps.init_qp + get_se_golomb(&s->gb); //slice_qp_delta //FIXME qscale / qp ... stuff -#if 0 if(h->slice_type == SP_TYPE){ get_bits1(&s->gb); /* sp_for_switch_flag */ } if(h->slice_type==SP_TYPE || h->slice_type == SI_TYPE){ get_se_golomb(&s->gb); /* slice_qs_delta */ } -#endif if( h->pps.deblocking_filter_parameters_present ) { h->disable_deblocking_filter_idc= get_ue_golomb(&s->gb); @@ -3021,7 +3005,7 @@ static int decode_slice_header(H264Context *h){ #endif if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - printf("mb:%d %c pps:%d frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d\n", + av_log(h->s.avctx, AV_LOG_DEBUG, "mb:%d %c pps:%d frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d\n", first_mb_in_slice, av_get_pict_type_char(h->slice_type), pps_id, h->frame_num, @@ -3123,7 +3107,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in level_code= (prefix<<suffix_length) + get_bits(gb, 12); //part if(suffix_length==0) level_code+=15; //FIXME doesnt make (much)sense }else{ - fprintf(stderr, "prefix too large at %d %d\n", s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "prefix too large at %d %d\n", s->mb_x, s->mb_y); return -1; } @@ -3164,7 +3148,7 @@ static int decode_residual(H264Context *h, GetBitContext *gb, DCTELEM *block, in } if(zeros_left<0){ - fprintf(stderr, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "negative number of zero coeffs at %d %d\n", s->mb_x, s->mb_y); return -1; } @@ -3274,7 +3258,7 @@ static int decode_mb(H264Context *h){ assert(h->slice_type == I_TYPE); decode_intra_mb: if(mb_type > 25){ - fprintf(stderr, "mb_type %d in %c slice to large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice to large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y); return -1; } partition_count=0; @@ -3370,7 +3354,7 @@ decode_intra_mb: for(i=0; i<4; i++){ h->sub_mb_type[i]= get_ue_golomb(&s->gb); if(h->sub_mb_type[i] >=13){ - fprintf(stderr, "B sub_mb_type %d out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "B sub_mb_type %d out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); return -1; } sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; @@ -3381,7 +3365,7 @@ decode_intra_mb: for(i=0; i<4; i++){ h->sub_mb_type[i]= get_ue_golomb(&s->gb); if(h->sub_mb_type[i] >=4){ - fprintf(stderr, "P sub_mb_type %d out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "P sub_mb_type %d out of range at %d %d\n", h->sub_mb_type[i], s->mb_x, s->mb_y); return -1; } sub_partition_count[i]= p_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; @@ -3525,7 +3509,7 @@ decode_intra_mb: if(!IS_INTRA16x16(mb_type)){ cbp= get_ue_golomb(&s->gb); if(cbp > 47){ - fprintf(stderr, "cbp too large (%d) at %d %d\n", cbp, s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%d) at %d %d\n", cbp, s->mb_x, s->mb_y); return -1; } @@ -3554,7 +3538,7 @@ decode_intra_mb: dquant= get_se_golomb(&s->gb); if( dquant > 25 || dquant < -26 ){ - fprintf(stderr, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); return -1; } @@ -3582,7 +3566,7 @@ decode_intra_mb: } } }else{ - memset(&h->non_zero_count_cache[8], 0, 8*4); //FIXME stupid & slow + fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); } }else{ for(i8x8=0; i8x8<4; i8x8++){ @@ -3651,7 +3635,7 @@ static int decode_slice(H264Context *h){ } if(ret<0){ - fprintf(stderr, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); + av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); return -1; @@ -3750,7 +3734,7 @@ static inline int decode_vui_parameters(H264Context *h, SPS *sps){ }else if(aspect_ratio_idc < 16){ sps->sar= pixel_aspect[aspect_ratio_idc]; }else{ - fprintf(stderr, "illegal aspect ratio\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "illegal aspect ratio\n"); return -1; } }else{ @@ -3842,7 +3826,7 @@ static inline int decode_seq_parameter_set(H264Context *h){ sps->offset_for_ref_frame[i]= get_se_golomb(&s->gb); } if(sps->poc_type > 2){ - fprintf(stderr, "illegal POC type %d\n", sps->poc_type); + av_log(h->s.avctx, AV_LOG_ERROR, "illegal POC type %d\n", sps->poc_type); return -1; } @@ -3865,7 +3849,7 @@ static inline int decode_seq_parameter_set(H264Context *h){ sps->crop_top = get_ue_golomb(&s->gb); sps->crop_bottom= get_ue_golomb(&s->gb); if(sps->crop_left || sps->crop_top){ - fprintf(stderr, "insane croping not completly supported, this could look slightly wrong ...\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completly supported, this could look slightly wrong ...\n"); } }else{ sps->crop_left = @@ -3879,7 +3863,7 @@ static inline int decode_seq_parameter_set(H264Context *h){ decode_vui_parameters(h, sps); if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - printf("sps:%d profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s\n", + av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%d profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s\n", sps_id, sps->profile_idc, sps->level_idc, sps->poc_type, sps->ref_frame_count, @@ -3905,7 +3889,7 @@ static inline int decode_picture_parameter_set(H264Context *h){ pps->slice_group_count= get_ue_golomb(&s->gb) + 1; if(pps->slice_group_count > 1 ){ pps->mb_slice_group_map_type= get_ue_golomb(&s->gb); -fprintf(stderr, "FMO not supported\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "FMO not supported\n"); switch(pps->mb_slice_group_map_type){ case 0: #if 0 @@ -3943,7 +3927,7 @@ fprintf(stderr, "FMO not supported\n"); pps->ref_count[0]= get_ue_golomb(&s->gb) + 1; pps->ref_count[1]= get_ue_golomb(&s->gb) + 1; if(pps->ref_count[0] > 32 || pps->ref_count[1] > 32){ - fprintf(stderr, "reference overflow (pps)\n"); + av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow (pps)\n"); return -1; } @@ -3957,7 +3941,7 @@ fprintf(stderr, "FMO not supported\n"); pps->redundant_pic_cnt_present = get_bits1(&s->gb); if(s->avctx->debug&FF_DEBUG_PICT_INFO){ - printf("pps:%d sps:%d %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d %s %s %s\n", + av_log(h->s.avctx, AV_LOG_DEBUG, "pps:%d sps:%d %s slice_groups:%d ref:%d/%d %s qp:%d/%d/%d %s %s %s\n", pps_id, pps->sps_id, pps->cabac ? "CABAC" : "CAVLC", pps->slice_group_count, @@ -4033,7 +4017,7 @@ static int decode_nal_units(H264Context *h, uint8_t *buf, int buf_size){ bit_length= 8*dst_length - decode_rbsp_trailing(ptr + dst_length - 1); if(s->avctx->debug&FF_DEBUG_STARTCODE){ - printf("NAL %d at %d length %d\n", h->nal_unit_type, buf_index, dst_length); + av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d length %d\n", h->nal_unit_type, buf_index, dst_length); } buf_index += consumed; @@ -4147,6 +4131,7 @@ static int decode_frame(AVCodecContext *avctx, int buf_index; s->flags= avctx->flags; + s->flags2= avctx->flags2; *data_size = 0; @@ -4183,12 +4168,12 @@ static int decode_frame(AVCodecContext *avctx, } #endif if(!s->current_picture_ptr){ - fprintf(stderr, "error, NO frame\n"); + av_log(h->s.avctx, AV_LOG_DEBUG, "error, NO frame\n"); return -1; } *pict= *(AVFrame*)&s->current_picture; //FIXME - ff_print_debug_info(s, s->current_picture_ptr); + ff_print_debug_info(s, pict); assert(pict->data[0]); //printf("out %d\n", (int)pict->data[0]); #if 0 //? |