ffglobals.cpp.svn-base

来自「ffshow源码」· SVN-BASE 代码 · 共 1,552 行 · 第 1/3 页

SVN-BASE
1,552
字号
 pict.setSize(dx,dy); int aspect_ratio_info=get_bits(&gb, 4); if(!mpeg2)  {   static const float mpeg1_aspect[16]=    {     0.0000f,     1.0000f,     0.6735f,     0.7031f,         0.7615f,     0.8055f,     0.8437f,     0.8935f,     0.9157f,     0.9815f,     1.0255f,     1.0695f,     1.0950f,     1.1575f,     1.2015f,    };   float aspect1=mpeg1_aspect[aspect_ratio_info];   if(aspect1!=0.0)    pict.setSar(Rational(1/aspect1,16384));   else    pict.setSar(Rational(1,1));  } else  {   /*   static const float mpeg2_aspect[16]=    {     0,     1.0,     -3.0/4.0,     -9.0/16.0,     -1.0/2.21,    };   */    switch (aspect_ratio_info)    {     case 1:pict.setSar(Rational(1,1));break;     case 2:pict.setDar(Rational(4,3));break;     case 3:pict.setDar(Rational(16,9));break;     case 4:pict.setDar(Rational(221,100));break;     default:pict.setSar(Rational(1,1));break;    }    /*   aspect=mpeg2_aspect[aspect_ratio_info];   if(aspect>0.0)      aspect_ratio= *width/(aspect**height);   else if(aspect<0.0) aspect_ratio= -1.0/aspect;   */  }  return true;}static inline void decode_hrd_parameters(GetBitContext &gb){    int cpb_count, i;    cpb_count = get_ue_golomb(&gb) + 1;    get_bits(&gb, 4); /* bit_rate_scale */    get_bits(&gb, 4); /* cpb_size_scale */    for(i=0; i<cpb_count; i++){        get_ue_golomb(&gb); /* bit_rate_value_minus1 */        get_ue_golomb(&gb); /* cpb_size_value_minus1 */        get_bits1(&gb);     /* cbr_flag */    }    get_bits(&gb, 5); /* initial_cpb_removal_delay_length_minus1 */    get_bits(&gb, 5); /* cpb_removal_delay_length_minus1 */    get_bits(&gb, 5); /* dpb_output_delay_length_minus1 */    get_bits(&gb, 5); /* time_offset_length */}static void decode_scaling_list(GetBitContext &gb, uint8_t *factors, int size/*, const uint8_t *default_list*/){    int i, last = 8, next = 8;static const uint8_t zigzag_scan8x8[64]={ 0+0*8, 1+0*8, 0+1*8, 0+2*8, 1+1*8, 2+0*8, 3+0*8, 2+1*8, 1+2*8, 0+3*8, 0+4*8, 1+3*8, 2+2*8, 3+1*8, 4+0*8, 5+0*8, 4+1*8, 3+2*8, 2+3*8, 1+4*8, 0+5*8, 0+6*8, 1+5*8, 2+4*8, 3+3*8, 4+2*8, 5+1*8, 6+0*8, 7+0*8, 6+1*8, 5+2*8, 4+3*8, 3+4*8, 2+5*8, 1+6*8, 0+7*8, 1+7*8, 2+6*8, 3+5*8, 4+4*8, 5+3*8, 6+2*8, 7+1*8, 7+2*8, 6+3*8, 5+4*8, 4+5*8, 3+6*8, 2+7*8, 3+7*8, 4+6*8, 5+5*8, 6+4*8, 7+3*8, 7+4*8, 6+5*8, 5+6*8, 4+7*8, 5+7*8, 6+6*8, 7+5*8, 7+6*8, 6+7*8, 7+7*8,};static const uint8_t zigzag_scan[16]={ 0+0*4, 1+0*4, 0+1*4, 0+2*4,  1+1*4, 2+0*4, 3+0*4, 2+1*4,  1+2*4, 0+3*4, 1+3*4, 2+2*4,  3+1*4, 3+2*4, 2+3*4, 3+3*4, };        const uint8_t *scan = size == 16 ? zigzag_scan : zigzag_scan8x8;    if(!get_bits1(&gb)) /* matrix not written, we use the default one */        ;//memcpy(factors, default_list, size*sizeof(uint8_t));     else    for(i=0;i<size;i++){        if(next)            next = (last + get_se_golomb(&gb)) & 0xff;        if(!i && !next){ /* matrix not written, we use the default one */            ;//memcpy(factors, default_list, size*sizeof(uint8_t));             break;        }        last = factors[scan[i]] = uint8_t(next ? next : last);    }}bool decodeH264SPS(const unsigned char *hdr,size_t len,TffPictBase &pict){ int sync=sync_video_packet(hdr,len); if((sync&~0x60) == 0x107 && sync != 0x107)  // H.264  {   hdr+=2;len-=2;  }    static const int NAL_SPS=7;    if ((hdr[2]&0x1F)!=NAL_SPS)     return false;    int profile_idc, level_idc;    int sps_id, i;    struct     {      int profile_idc,level_idc,log2_max_frame_num,poc_type,log2_max_poc_lsb,offset_for_non_ref_pic,offset_for_top_to_bottom_field,poc_cycle_length,delta_pic_order_always_zero_flag,offset_for_ref_frame[256],ref_frame_count,gaps_in_frame_num_allowed_flag,frame_mbs_only_flag,mb_aff,mb_width,mb_height,direct_8x8_inference_flag,crop_left,crop_top,crop_right,crop_bottom,crop,vui_parameters_present_flag,timing_info_present_flag,num_units_in_tick,time_scale,fixed_frame_rate_flag,bitstream_restriction_flag,num_reorder_frames,transform_bypass,scaling_matrix_present;      Rational sar;     } _sps,*sps=&_sps;    GetBitContext gb;init_get_bits(&gb,hdr,(int)len*8);    skip_bits(&gb,24);    profile_idc= get_bits(&gb, 8);    get_bits1(&gb);   //constraint_set0_flag    get_bits1(&gb);   //constraint_set1_flag    get_bits1(&gb);   //constraint_set2_flag    get_bits1(&gb);   //constraint_set3_flag    get_bits(&gb, 4); // reserved    level_idc= get_bits(&gb, 8);    sps_id= get_ue_golomb(&gb);        sps->profile_idc= profile_idc;    sps->level_idc= level_idc;    if(sps->profile_idc >= 100){ //high profile        if(get_ue_golomb(&gb) == 3) //chroma_format_idc            get_bits1(&gb);  //residual_color_transform_flag        get_ue_golomb(&gb);  //bit_depth_luma_minus8        get_ue_golomb(&gb);  //bit_depth_chroma_minus8        sps->transform_bypass = get_bits1(&gb);        if(get_bits1(&gb)){  //seq_scaling_matrix_present_flag            //decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8);//av_log(h->s.avctx, AV_LOG_ERROR, "custom scaling matrix not implemented\n");            if(get_bits1(&gb)){                sps->scaling_matrix_present = 1;                uint8_t scaling_matrix4[6][16];                uint8_t scaling_matrix8[2][64];                decode_scaling_list(gb,scaling_matrix4[0],16); // Intra, Y                decode_scaling_list(gb,scaling_matrix4[1],16); // Intra, Cr                decode_scaling_list(gb,scaling_matrix4[2],16); // Intra, Cb                decode_scaling_list(gb,scaling_matrix4[3],16); // Inter, Y                decode_scaling_list(gb,scaling_matrix4[4],16); // Inter, Cr                decode_scaling_list(gb,scaling_matrix4[5],16); // Inter, Cb                if(/*is_sps*/1){                    decode_scaling_list(gb,scaling_matrix8[0],64);  // Intra, Y                    decode_scaling_list(gb,scaling_matrix8[1],64);  // Inter, Y                }            }        }    }    else         sps->scaling_matrix_present=0;        sps->log2_max_frame_num= get_ue_golomb(&gb) + 4;    sps->poc_type= get_ue_golomb(&gb);        if(sps->poc_type == 0){ //FIXME #define        sps->log2_max_poc_lsb= get_ue_golomb(&gb) + 4;    } else if(sps->poc_type == 1){//FIXME #define        sps->delta_pic_order_always_zero_flag= get_bits1(&gb);        sps->offset_for_non_ref_pic= get_se_golomb(&gb);        sps->offset_for_top_to_bottom_field= get_se_golomb(&gb);        sps->poc_cycle_length= get_ue_golomb(&gb);                for(i=0; i<sps->poc_cycle_length; i++)            sps->offset_for_ref_frame[i]= get_se_golomb(&gb);    }    if(sps->poc_type > 2){        //DPRINTF("illegal POC type %d\n", sps->poc_type);        return false;    }    sps->ref_frame_count= get_ue_golomb(&gb);    static const int MAX_PICTURE_COUNT=32;    if(sps->ref_frame_count > MAX_PICTURE_COUNT-2){        //DPRINTF("too many reference frames\n");    }    sps->gaps_in_frame_num_allowed_flag= get_bits1(&gb);    sps->mb_width= get_ue_golomb(&gb) + 1;    sps->mb_height= get_ue_golomb(&gb) + 1;    if((unsigned)sps->mb_width >= INT_MAX/16 || (unsigned)sps->mb_height >= INT_MAX/16 /*||        avcodec_check_dimensions(NULL, 16*sps->mb_width, 16*sps->mb_height)*/)        return false;    sps->frame_mbs_only_flag= get_bits1(&gb);    if(!sps->frame_mbs_only_flag)        sps->mb_aff= get_bits1(&gb);    else        sps->mb_aff= 0;    sps->direct_8x8_inference_flag= get_bits1(&gb);    sps->crop= get_bits1(&gb);    if(sps->crop){        sps->crop_left  = get_ue_golomb(&gb);        sps->crop_right = get_ue_golomb(&gb);        sps->crop_top   = get_ue_golomb(&gb);        sps->crop_bottom= get_ue_golomb(&gb);        if(sps->crop_left || sps->crop_top){            //DPRINTF("insane cropping not completely supported, this could look slightly wrong ...\n");        }    }else{        sps->crop_left  =         sps->crop_right =         sps->crop_top   =         sps->crop_bottom= 0;    }    sps->vui_parameters_present_flag= get_bits1(&gb);    if( sps->vui_parameters_present_flag ) {        int aspect_ratio_info_present_flag, aspect_ratio_idc;        int nal_hrd_parameters_present_flag, vcl_hrd_parameters_present_flag;        aspect_ratio_info_present_flag= get_bits1(&gb);                if( aspect_ratio_info_present_flag ) {            aspect_ratio_idc= get_bits(&gb, 8);            static const int EXTENDED_SAR=255;            if( aspect_ratio_idc == EXTENDED_SAR ) {                sps->sar.num= get_bits(&gb, 16);                sps->sar.den= get_bits(&gb, 16);            }else if(aspect_ratio_idc < 16){                static const AVRational pixel_aspect[14]={                 {0, 1},                 {1, 1},                 {12, 11},                 {10, 11},                 {16, 11},                 {40, 33},                 {24, 11},                 {20, 11},                 {32, 11},                 {80, 33},                 {18, 11},                 {15, 11},                 {64, 33},                 {160,99},                };                sps->sar=  pixel_aspect[aspect_ratio_idc];            }else{                //DPRINTF("illegal aspect ratio\n");                return false;            }            if (sps->sar.num && sps->sar.den)                pict.setSar(sps->sar);        }else{            sps->sar.num=             sps->sar.den= 0;        }                if(get_bits1(&gb)){      /* overscan_info_present_flag */            get_bits1(&gb);      /* overscan_appropriate_flag */        }        if(get_bits1(&gb)){      /* video_signal_type_present_flag */            get_bits(&gb, 3);    /* video_format */            get_bits1(&gb);      /* video_full_range_flag */            if(get_bits1(&gb)){  /* colour_description_present_flag */                get_bits(&gb, 8); /* colour_primaries */                get_bits(&gb, 8); /* transfer_characteristics */                get_bits(&gb, 8); /* matrix_coefficients */            }        }        if(get_bits1(&gb)){      /* chroma_location_info_present_flag */            get_ue_golomb(&gb);  /* chroma_sample_location_type_top_field */            get_ue_golomb(&gb);  /* chroma_sample_location_type_bottom_field */        }        sps->timing_info_present_flag = get_bits1(&gb);        if(sps->timing_info_present_flag){            sps->num_units_in_tick = get_bits_long(&gb, 32);            sps->time_scale = get_bits_long(&gb, 32);            sps->fixed_frame_rate_flag = get_bits1(&gb);        }        nal_hrd_parameters_present_flag = get_bits1(&gb);        if(nal_hrd_parameters_present_flag)            decode_hrd_parameters(gb);        vcl_hrd_parameters_present_flag = get_bits1(&gb);        if(vcl_hrd_parameters_present_flag)            decode_hrd_parameters(gb);        if(nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag)            get_bits1(&gb);     /* low_delay_hrd_flag */        get_bits1(&gb);         /* pic_struct_present_flag */        sps->bitstream_restriction_flag = get_bits1(&gb);        if(sps->bitstream_restriction_flag){            get_bits1(&gb);     /* motion_vectors_over_pic_boundaries_flag */            get_ue_golomb(&gb); /* max_bytes_per_pic_denom */            get_ue_golomb(&gb); /* max_bits_per_mb_denom */            get_ue_golomb(&gb); /* log2_max_mv_length_horizontal */            get_ue_golomb(&gb); /* log2_max_mv_length_vertical */            sps->num_reorder_frames = get_ue_golomb(&gb);            get_ue_golomb(&gb); /* max_dec_frame_buffering */        }        }/*            //=============== PPS ================    skip_bits(&gb,24);    struct      {      int sps_id,pic_order_present,slice_group_count,mb_slice_group_map_type,ref_count[2],cabac,weighted_pred,weighted_bipred_idc,init_qp,init_qs,chroma_qp_index_offset,deblocking_filter_parameters_present,constrained_intra_pred,redundant_pic_cnt_present;     } _pps, *pps=&_pps;    pps->sps_id= get_ue_golomb(&gb);    pps->cabac= get_bits1(&gb);    pps->pic_order_present= get_bits1(&gb);    pps->slice_group_count= get_ue_golomb(&gb) + 1;    if(pps->slice_group_count > 1 ){        pps->mb_slice_group_map_type= get_ue_golomb(&gb);        //DPRINTF("FMO not supported\n");        switch(pps->mb_slice_group_map_type){        case 0:#if 0|   for( i = 0; i <= num_slice_groups_minus1; i++ ) |   |        ||    run_length[ i ]                                |1  |ue(v)   |#endif            break;        case 2:#if 0|   for( i = 0; i < num_slice_groups_minus1; i++ )  |   |        ||{                                                  |   |        ||    top_left_mb[ i ]                               |1  |ue(v)   ||    bottom_right_mb[ i ]                           |1  |ue(v)   ||   }                                               |   |        |#endif            break;        case 3:        case 4:        case 5:#if 0|   slice_group_change_direction_flag               |1  |u(1)    ||   slice_group_change_rate_minus1                  |1  |ue(v)   |#endif            break;        case 6:#if 0|   slice_group_id_cnt_minus1                       |1  |ue(v)   ||   for( i = 0; i <= slice_group_id_cnt_minus1; i++ |   |        ||)                                                  |   |        ||    slice_group_id[ i ]                            |1  |u(v)    |#endif            break;        }    }    pps->ref_count[0]= get_ue_golomb(&gb) + 1;    pps->ref_count[1]= get_ue_golomb(&gb) + 1;    if(pps->ref_count[0] > 32 || pps->ref_count[1] > 32){        //DPRINTF("reference overflow (pps)\n");        return false;    }        pps->weighted_pred= get_bits1(&gb);    pps->weighted_bipred_idc= get_bits(&gb, 2);    pps->init_qp= get_se_golomb(&gb) + 26;    pps->init_qs= get_se_golomb(&gb) + 26;    pps->chroma_qp_index_offset= get_se_golomb(&gb);    pps->deblocking_filter_parameters_present= get_bits1(&gb);    pps->constrained_intra_pred= get_bits1(&gb);    pps->redundant_pic_cnt_present = get_bits1(&gb);*/        return true;}void* memsetd(void *dest,uint32_t c,size_t bytes){#if !defined(__GNUC__) && !defined(WIN64) __asm  {   mov eax, c   mov ecx, bytes   shr ecx, 2   mov edi, dest   cld   rep stosd  } return dest; #else uint32_t *dest2=(uint32_t*)dest; for (;bytes>=sizeof(uint32_t);dest2++,bytes-=sizeof(uint32_t))  *dest2=c; return dest2; #endif  }void saveFrame(unsigned int num,const unsigned char *buf,size_t len){ char_t flnm[MAX_PATH];tsprintf(flnm,_l("c:\\ffdshow_frame_%06u.raw"),num); FILE *f=fopen(flnm,_l("wb")); fwrite(buf,1,len,f); fclose(f);}void dumpBytes(const char_t *flnm,const unsigned char *buf,size_t len){ FILE *f=fopen(flnm,_l("wb")); fwrite(buf,1,len,f); fflush(f);fclose(f);}char_t *readTextFile(const char_t *filename){ int b_error=0; char_t *buf; TstreamFile fh(filename,false,false); if (!fh)  return NULL; b_error|=fh.seek( 0, SEEK_END )<0; long i_size; b_error|=(i_size=fh.tell())<=0; b_error|=fh.seek( 0, SEEK_SET )<0; if (b_error)  return NULL; buf=(char_t*)malloc((i_size+2)*sizeof(char_t)); if (buf==NULL)  return NULL; char_t *buf1=buf;  while (fh.fgets(buf1,i_size))  buf1=strchr(buf1,'\0');    //b_error|=fh.read(buf,1,i_size)!=i_size; if (buf[i_size-1]!='\n')     buf[i_size++]='\n'; buf[i_size]=0; //fclose(fh); if (b_error)  {   free(buf);   return NULL;  } return buf;}static BOOL CALLBACK getChildWindowsEnum(HWND h,LPARAM lst){ ((THWNDs*)lst)->push_back(h); return TRUE;}void getChildWindows(HWND h,THWNDs &lst){ lst.clear(); EnumChildWindows(h,getChildWindowsEnum,LPARAM(&lst));}void randomize(void){ srand((unsigned int)time(NULL));}struct MPEG4context{ int vo_type; int aspect_ratio_info; int aspected_width,aspected_height;};static const uint16_t pixel_aspect[16][2]={ {0, 0}, {1, 1}, {12, 11}, {10, 11}, {16, 11}, {40, 33}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},};static int decode_vol_header(MPEG4context *s, GetBitContext *gb){ int /*width, height,*/ vo_ver_id; /* vol header */ skip_bits(gb, 1); /* random access */ s->vo_type= get_bits(gb, 8); if (get_bits1(gb) != 0) { /* is_ol_id */   vo_ver_id = get_bits(gb, 4); /* vo_ver_id */   skip_bits(gb, 3); /* vo_priority */ } else {   vo_ver_id = 1; } //printf("vo type:%d\n",s->vo_type); s->aspect_ratio_info= get_bits(gb, 4);	if(s->aspect_ratio_info == FF_ASPECT_EXTENDED){	       s->aspected_width = get_bits(gb, 8); // par_width   s->aspected_height = get_bits(gb, 8); // par_height }else{

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?