⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errhandle.c

📁 davinci avs.......................................................
💻 C
字号:
/*!
 *************************************************************************************
 * \file 
 *    ErrHandle.c
 * \brief
 *    uncertion error handling such as illegal syntax elemenet, illegal memory access etc
 * \notes:
 *    Zhan MA  Huazhong Univ. of Science and Technology    <zhanuo@yahoo.com>
 *************************************************************************************
 */

#include <stdio.h>
#include <stdlib.h>
#include "global.h"
#include "nalu.h"
/*! 
 *************************************************************************************
 * \brief :
 *    Error handling procedure. Print error message to stderr and exit
 *    with supplied code.
 *************************************************************************************
 */
void error(char *text, int code)
{
  fprintf(stderr, "%s\n", text);
  exit(code);
}

/*! 
 *************************************************************************************
 * \brief :
 *    
 *************************************************************************************
 */
void CheckNALUValid(unsigned char nalu_header,FILE *error_file)
{
  int nal_unit_type,nal_ref_idc,forbidden_bit;
  nal_unit_type = (nalu_header & 0x1f);
  nal_ref_idc   = ((nalu_header >> 5) & 0x3);
  forbidden_bit = ((nalu_header >> 7) & 0x1); 
 
  if (forbidden_bit !=0 )
    fprintf(error_file,"NALU Header ERR: %d is inValid forbidded_zero_bit, should be 0, see FCD 7.2.1\n",forbidden_bit);

  switch (nal_unit_type)
  {
    case 2:
      if (nal_ref_idc == 0 )
        fprintf(error_file,"IDR Header ERR: %d is inValid  nal_ref_idc, should be [1:7], see FCD 7.2.1\n", nal_ref_idc);
      break;

    case 4:
      if (nal_ref_idc == 0 )
        fprintf(error_file,"SPS Header ERR: %d is inValid  nal_ref_idc, should be [1:7], see FCD 7.2.1\n", nal_ref_idc);
      break;

    case 5:
      if (nal_ref_idc == 0 )
        fprintf(error_file,"PPS Header ERR: %d is inValid  nal_ref_idc, should be [1:7], see FCD 7.2.1\n", nal_ref_idc);
      break;

    case 7:
      if (nal_ref_idc == 0 )
        fprintf(error_file,"RAPIR Header ERR: %d is inValid  nal_ref_idc, should be [1:7], see FCD 7.2.1\n", nal_ref_idc);
      break;

    case 6:
      if (nal_ref_idc != 0)
        fprintf(error_file,"SEI Header ERR: %d is inValid  nal_ref_idc, should be [1:7], see FCD 7.2.1\n", nal_ref_idc);
      break;

    case 1:
    case 3:
      if ((nal_unit_type == 1) && (nal_ref_idc) == 0)
      {
        if ((nal_unit_type == 3)&& (nal_ref_idc!=0))
          fprintf(error_file,"Slice Header ERR: %d is inValid  nal_ref_idc, should be [1:7], see FCD 7.2.1\n", nal_ref_idc);
      }
      else
      {
        if ((nal_unit_type == 3)&& (nal_ref_idc ==0))
          fprintf(error_file,"Slice Header ERR: %d is inValid  nal_ref_idc, should be [1:7], see FCD 7.2.1\n", nal_ref_idc);
      
      }
      break;

    default:
      fprintf(error_file,"NALU Header ERR: %d is inValid nal_unit_type, should be [1:7], see FCD 7.2.1",nal_unit_type);
      break;  
  }
}



/*! 
 *************************************************************************************
 * \brief :
 *    
 *************************************************************************************
 */

void CheckPPSValid(pic_parameter_set *PicParaSet)
{
#if ERR_REPORT
  if (PicParaSet->pic_parameter_set_id>127)
    fprintf(p_err,"PPS ERR: %d is Invalid pic_parameter_set_id, should be [0:127], see FCD 7.2.3\n",PicParaSet->pic_parameter_set_id);
   
  if (PicParaSet->seq_parameter_set_id>15)
    fprintf(p_err,"PPS ERR: %d is Invalid seq_parameter_set_id, should be [0:15], see FCD 7.2.3\n",PicParaSet->seq_parameter_set_id);
#endif
}


/*! 
 *************************************************************************************
 * \brief :
 *    
 *************************************************************************************
 */
void CheckSPSValid(seq_parameter_set *SeqParaSet)
{
#if ERR_REPORT
  int x1,y1,x2,y2;
  /* profile check */
  if (SeqParaSet->profile_idc != 0x10)
    fprintf(p_err,"SPS ERR: %d is Invalid Profile IDC, should be 0x10, see FCD B.1.1\n", SeqParaSet->profile_idc);

  /* level check */
  switch (SeqParaSet->level_idc)
  {
    case 10:
    case 12:
    case 14:
    case 16:
    case 30:
    case 32:
    case 34:
    case 50:
    case 52:
      break;

    default:
       fprintf(p_err,"SPS ERR: %d is Invalid Level IDC, should be [10,12,14,16,30,32,34,50,52], see FCD B.1.1\n",SeqParaSet->level_idc);
       break;
  }
 
  if (SeqParaSet->seq_parameter_set_id>15)
    fprintf(p_err,"SPS ERR: %d is Invalid seq_parameter_set_id, should be [0:15], see FCD 7.2.2 C.2.5\n", SeqParaSet->seq_parameter_set_id);
    
  if ( (SeqParaSet->num_ref_frames <0) || (SeqParaSet->num_ref_frames >2) )
    fprintf(p_err,"SPS ERR: %d is Invalid ref_frame_num, should be [0:2], see FCD 7.2.2\n", SeqParaSet->num_ref_frames);
 
  if ( (SeqParaSet->aspect_ratio <1) || (SeqParaSet->aspect_ratio >4) )
    fprintf(p_err,"SPS ERR: %d is Invalid aspect_ration, should be [1:4], see FCD 7.2.2\n", SeqParaSet->aspect_ratio);

  if (SeqParaSet->frame_cropping_flag)
  {
    x2 = (SeqParaSet->horizontal_size_minus1 + 1)*16 - (2*SeqParaSet->frame_crop_right_offset +1);
    y2 = (SeqParaSet->vertical_size_minus1 +1)*16 - (2*SeqParaSet->frame_crop_bottom_offset);
    x1 = 2*SeqParaSet->frame_cropping_left_offset;
    y1 = 2*SeqParaSet->frame_crop_top_offset;

    if ((x2<x1)||(y2<y1))
      fprintf(p_err,"SPS ERR: %d is Invalid frame_cropping_flag, should be [1:4], see FCD 7.2.2\n", SeqParaSet->frame_cropping_flag);
      
  }
#endif 
    
}

/*! 
 *************************************************************************************
 * \brief :
 *    
 *************************************************************************************
 */
void CheckPictureHeaderValid(picture_header *p,NALU_t *nalu)
{
#if ERR_REPORT

  if ( !((p->picture_coding_type == 0) || (p->picture_coding_type == 1)) )
    fprintf(p_err,"Picture Header ERR: %d is inValid picture_coding_type, should be [0:1], see FCD 7.2.6\n",p->picture_coding_type);

  if (p->frame_num == 0)
  {
    if (p->picture_distance !=0)
      fprintf(p_err,"Picture Header ERR: %d is inValid picture_distance in IDR picture, should be 0, see FCD 7.2.6\n",p->picture_distance);

    if(nalu->nal_unit_type != NALU_TYPE_IDR)
      fprintf(p_err,"Picture Header ERR: the first picture of a sequence must be an IDR picture, see FCD 3.38\n");
    else if (p->picture_coding_type != 0)
      fprintf(p_err,"Picture Header ERR:  an IDR picture must have (nal_unit_type = 2, picture_coding_type = 0), see FCD 7.2.6\n");
  }

  if (p->picture_distance_gap_minus1<0 || p->picture_distance_gap_minus1>31)
    fprintf(p_err,"Picture Header ERR: %d is inValid picture_distance_gap_minus1, should be [0:31], see FCD 7.2.6\n",p->picture_distance_gap_minus1);
      
  if ((p->alpha_ci_offset<-8) || (p->alpha_ci_offset>8))
    fprintf(p_err,"Picture Header ERR: %d is inValid alpha_ci_offset, should be [-8:8], see FCD 7.2.6\n",p->alpha_ci_offset);

  if ((p->cp_offset<-16) || (p->cp_offset>16))
    fprintf(p_err,"Picture Header ERR: %d is inValid cp_offset, should be [-16:16], see FCD 7.2.6\n",p->cp_offset);

  if ((p->loopfilter_qp_offset<-40) || (p->loopfilter_qp_offset>23))
    fprintf(p_err,"Picture Header ERR: %d is inValid loopfilter_qp_offset, should be [-40:23], see FCD 7.2.6\n",p->loopfilter_qp_offset);
  
#endif
}

/*! 
 *************************************************************************************
 * \brief :
 *    
 *************************************************************************************
 */
void CheckSliceHeaderValid(int first_mb_in_slice,int delta_qp)
{
#if ERR_REPORT
  if ((first_mb_in_slice<0)||(first_mb_in_slice>=pgImage->PicSizeInMbs))
    fprintf(p_err,"Slice Header ERR: %d is inValid first_mb_in_slice, should be [0:%d], see FCD 7.2.7.1",first_mb_in_slice,(pgImage->PicSizeInMbs-1));

  if ((delta_qp<-32)||(delta_qp>31))
    fprintf(p_err,"Slice Header ERR: %d is inValid delta_qp, should be [-32:31], see FCD 7.2.7.1",delta_qp);

#endif
}

/*! 
 *************************************************************************************
 * \brief :
 *    
 *************************************************************************************
 */
void CheckMbOverHeadValid(Macroblock *curMb)
{
#if ERR_REPORT
  int i,j,k;

  if ((curMb->mb_type<0)||(curMb->mb_type>5))
    fprintf(p_err,"MbOverHead ERR: %d is invalid mb_type, should be [0:5], see FCD 9.3.1\n",curMb->mb_type);

  if (IS_INTRA(curMb))
  {
    if ((curMb->c_ipred_mode<0)||(curMb->c_ipred_mode>2))
      fprintf(p_err,"MbOverHead ERR: %d is invalid intra_chroma_pred_mode, should be [0:2], see FCD 9.3.2\n",curMb->c_ipred_mode);

  }
  if ((curMb->delta_quant<-32)||(curMb->delta_quant>31))
    fprintf(p_err,"MbOverHead ERR: %d is invalid intra_chroma_pred_mode, should be [-32:31], see FCD 7.2.8\n",curMb->delta_quant);

  for (i=0;i<4;i++)
  {
    if ((curMb->sub_mb_type[i]<0)||(curMb->sub_mb_type[i]>3))
      fprintf(p_err,"MbOverHead ERR: %d is invalid sub_mb_type, should be [0:3], see FCD 7.2.8\n",curMb->sub_mb_type[i]);
  }

  for (j=0; j < BLOCK_MULTIPLE; j++)
    for (i=0; i < BLOCK_MULTIPLE; i++)
      for (k=0; k < 2; k++)
        if ((curMb->mvd[j][i][k]<-1024)||(curMb->mvd[j][i][k]>1023))
          fprintf(p_err,"MbOverHead ERR: %d is invalid mvd, should be [-1024:1023], see FCD 7.2.8\n",curMb->mvd[j][i][k]);
     

#endif
}

/*! 
 *************************************************************************************
 * \brief :
 *    Match the FCD 9.6
 *************************************************************************************
 */
void CheckQCoeffValid(int MbNr,int b8, int b4, int QCoeff)
{
#if ERR_REPORT
  if ((QCoeff > 1023) || (QCoeff < -1024))
    fprintf(p_err, "Q Coeff ERR: %d is inValid Quantized Coefficient at (%d,%d) in %d Macroblock, should be [-1024:1023], see FCD 9.5.2\n", QCoeff, b8, b4,MbNr);

#endif
}

void CheckDCTCoeffValid(int MbNr,int b8, int b4, int DCTCoeff)
{
#if ERR_REPORT
  if ((DCTCoeff > 2047) || (DCTCoeff < -2048))
    fprintf(p_err, "DCT Coeff ERR: %d is inValid  inverse quantized DCT Coefficient at (%d,%d) in %d Macroblock, should be [-2048:2047], see FCD 9.5.2\n", DCTCoeff, b8, b4,MbNr);
#endif
}

void CheckHCoeffValid(int MbNr,int b8, int b4, int HCoeff)
{
#if ERR_REPORT
   if ((HCoeff > 32751) || (HCoeff < -32768))
     fprintf(p_err, "IDCT H Coeff ERR: %d is inValid H Coefficient at (%d,%d) in %d Macroblock, should be [-8192:8188], see FCD 9.6\n", HCoeff, b8, b4,MbNr);
#endif
}

/*! 
 *************************************************************************************
 * \brief :
 *    
 *************************************************************************************
 */
void CheckBitstreamStatus(FILE *error_file)
{
#if ERR_REPORT
  fprintf(p_err,"\n\n-----------------------------------------------------------------------\n");
  fprintf(p_err,"--------------           Bitstream Statistics             -------------\n");
  fprintf(p_err,"-----------------------------------------------------------------------\n");

  /* Seq Parameter Check */
  fprintf(p_err,"total frame nums               \t  =  %d\n", stat_parameter->tot_frame_number);
  fprintf(p_err,"picture_width                  \t  =  %d\n", stat_parameter->img_width);
  fprintf(p_err,"picture_height                 \t  =  %d\n", stat_parameter->img_height);
  fprintf(p_err,"delta_time_picture_distance_1  \t  =  %d\n", stat_parameter->delta_time_picture_distance_1);
  fprintf(p_err,"frame_skip                     \t  =  %d\n", stat_parameter->frame_skip);
  fprintf(p_err,"num_ref_frames                 \t  =  %d\n", stat_parameter->ref_frame_number);
  fprintf(p_err,"frame_cropping_flag            \t  =  %d\n", stat_parameter->frame_cropping_flag);

  /* Pic Parameter Check */
  fprintf(p_err,"picture_reference_flag        \t  =  %d\n", stat_parameter->picture_reference_flag);
  fprintf(p_err,"skip_mode_flag                \t  =  %d\n", stat_parameter->skip_mode_flag);
  fprintf(p_err,"loop_filter_disable_flag      \t  =  %d\n", stat_parameter->loop_filter_disable_flag);
  fprintf(p_err,"loop_filter_parameter_flag    \t  =  %d\n", stat_parameter->loop_filter_parameter_flag);
  fprintf(p_err,"constrained_intra_pred_flag   \t  =  %d\n", stat_parameter->constrained_intra_pred_flag);
  fprintf(p_err,"half_pixel_mv_flag            \t  =  %d\n", stat_parameter->half_pixel_mv_flag);
  
  /*Picture Header Check */
  fprintf(p_err,"loop_filter_alpha_ci_offset   \t  =  %d\n", stat_parameter->alpha_ci_offset);
  fprintf(p_err,"loop_fiter_qp_offset          \t  =  %d\n", stat_parameter->loop_fiter_qp_offset);
  fprintf(p_err,"loop_fiter_qp_offset          \t  =  %d\n", stat_parameter->loop_fiter_qp_offset);

  /* MbOverhead Check */
  fprintf(p_err,"\nMb_type:\n   0  1  2  3  4  5\n");
  fprintf(p_err,"   %d  %d  %d  %d  %d  %d\n",stat_parameter->mb_type[0],stat_parameter->mb_type[1],\
                                              stat_parameter->mb_type[2],stat_parameter->mb_type[3],\
                                              stat_parameter->mb_type[4],stat_parameter->mb_type[5]);
  

  fprintf(p_err,"\nintra_luma_pred_mode:\n   0  1  2  3  4  5  6  7  8\n");
  fprintf(p_err,"   %d  %d  %d  %d  %d  %d  %d  %d  %d\n",stat_parameter->intra_luma_pred_mode[0],stat_parameter->intra_luma_pred_mode[1],\
                                                          stat_parameter->intra_luma_pred_mode[2],stat_parameter->intra_luma_pred_mode[3],\
                                                          stat_parameter->intra_luma_pred_mode[4],stat_parameter->intra_luma_pred_mode[5],\
                                                          stat_parameter->intra_luma_pred_mode[6],stat_parameter->intra_luma_pred_mode[7],\
                                                          stat_parameter->intra_luma_pred_mode[8]);

  fprintf(p_err,"\nintra_chroma_pred_mode:\n 0  1  2 \n %d  %d  %d \n",stat_parameter->intra_chroma_pred_mode[0],\
                                                                       stat_parameter->intra_chroma_pred_mode[1],\
                                                                       stat_parameter->intra_chroma_pred_mode[2]);
  

  fprintf(p_err,"\nmv_x                          \t  =  [%4d:%4d]\n", stat_parameter->min_mv[0],stat_parameter->max_mv[0]);
  fprintf(p_err,"mv_y                          \t  =  [%4d:%4d]\n", stat_parameter->min_mv[1],stat_parameter->max_mv[1]);

#endif

}

⌨️ 快捷键说明

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