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

📄 gethdr.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的外部设备的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
          break;
        case PICTURE_DISPLAY_EXTENSION_ID:
          picture_display_extension(livp,lph);
          break;
        case PICTURE_CODING_EXTENSION_ID:
          picture_coding_extension(livp,lph);
          break;
        case COPYRIGHT_EXTENSION_ID:
          copyright_extension(livp,lph);
          break;
        default:
          break;
      }
    }
    code = find_start_code(livp);
  }
} /* extension_and_user_data() */
    

static void sequence_extension(tm2MpegDecInstVars_t *livp, tmMPEGHdr_t *lph)
{
  int horizontal_size_extension;
  int vertical_size_extension;
  int bit_rate_extension;
  int vbv_buffer_size_extension;

  lph->MPEG2_Flag                   = 1;
  lph->profile_and_level_indication = Get_Bits(8);
  lph->progressive_sequence         = Get_Bits(1);
  lph->chroma_format                = Get_Bits(2);
  horizontal_size_extension         = Get_Bits(2);
  vertical_size_extension           = Get_Bits(2);
  bit_rate_extension                = Get_Bits(12);
  marker_bit(livp,"sequence_extension");
  vbv_buffer_size_extension         = Get_Bits(8);
  lph->low_delay                    = Get_Bits(1);
  lph->frame_rate_extension_n       = Get_Bits(2);
  lph->frame_rate_extension_d       = Get_Bits(5);


 
  lph->horizontal_size = (horizontal_size_extension<<12) | (lph->horizontal_size&0x0fff);
  lph->vertical_size = (vertical_size_extension<<12) | (lph->vertical_size&0x0fff);

  lph->bit_rate_value += (bit_rate_extension << 18);

  lph->vbv_buffer_size += (vbv_buffer_size_extension << 10);
}

static void sequence_display_extension(tm2MpegDecInstVars_t *livp, tmMPEGHdr_t *lph)
{
  lph->video_format      = Get_Bits(3);
  lph->color_description = Get_Bits(1);

  if (lph->color_description)
  {
    lph->color_primaries          = Get_Bits(8);
    lph->transfer_characteristics = Get_Bits(8);
    lph->matrix_coefficients      = Get_Bits(8);
  }

  lph->display_horizontal_size = Get_Bits(14);
  marker_bit(livp,"sequence_display_extension");
  lph->display_vertical_size   = Get_Bits(14);
}

static void quant_matrix_extension(tm2MpegDecInstVars_t *livp, tmMPEGHdr_t *lph)
{
  int i;
  int load_chroma_intra_quantizer_matrix;
  int load_chroma_non_intra_quantizer_matrix;

  if((lph->load_intra_quantizer_matrix = Get_Bits(1))) {
    for (i=0; i<64; i++) {
      lph->intra_quantizer_matrix[scan[ZIG_ZAG][i]]
      = Get_Bits(8);
    }
  }

  if((lph->load_non_intra_quantizer_matrix = Get_Bits(1))) {
    for (i=0; i<64; i++) {
      lph->non_intra_quantizer_matrix[scan[ZIG_ZAG][i]]
      = Get_Bits(8);
    }
  }

  if((load_chroma_intra_quantizer_matrix = Get_Bits(1))) {
    printf("Load Chrom Intra Quantizer Matrix Not Supported for 420\n");
    for (i=0; i<64; i++) Get_Bits(8);
  }

  if((load_chroma_non_intra_quantizer_matrix = Get_Bits(1))) {
    printf("Load Chrom Non Intra Quantizer Matrix Not Supported for 420\n");
    for (i=0; i<64; i++) Get_Bits(8);
  }
}

static void picture_display_extension(tm2MpegDecInstVars_t *livp, tmMPEGHdr_t *lph)
{
  int i;
  int number_of_frame_center_offsets;

  /* derive number_of_frame_center_offsets */
  if(lph->progressive_sequence)
  {
    if(lph->repeat_first_field)
    {
      if(lph->top_field_first)
        number_of_frame_center_offsets = 3;
      else
        number_of_frame_center_offsets = 2;
    }
    else
    {
      number_of_frame_center_offsets = 1;
    }
  }
  else
  {
    if(lph->picture_structure!=FRAME_PICTURE)
    {
      number_of_frame_center_offsets = 1;
    }
    else
    {
      if(lph->repeat_first_field)
        number_of_frame_center_offsets = 3;
      else
        number_of_frame_center_offsets = 2;
    }
  }


  /* now parse */
  for (i=0; i<number_of_frame_center_offsets; i++)
  {
    lph->frame_center_horizontal_offset[i] = Get_Bits(16);
    marker_bit(livp,"picture_display_extension, first marker bit");
    
    lph->frame_center_vertical_offset[i]   = Get_Bits(16);
    marker_bit(livp,"picture_display_extension, lph->second marker bit");
  }
}


/* decode picture coding extension */
static void picture_coding_extension(tm2MpegDecInstVars_t *livp, tmMPEGHdr_t *lph)
{
  lph->f_code[0][0] = Get_Bits(4);
  lph->f_code[0][1] = Get_Bits(4);
  lph->f_code[1][0] = Get_Bits(4);
  lph->f_code[1][1] = Get_Bits(4);

  lph->intra_dc_precision         = Get_Bits(2);
  lph->picture_structure          = Get_Bits(2);
  lph->top_field_first            = Get_Bits(1);
  lph->frame_pred_frame_dct       = Get_Bits(1);
  lph->concealment_motion_vectors = Get_Bits(1);
  lph->q_scale_type               = Get_Bits(1);
  lph->intra_vlc_format           = Get_Bits(1);
  lph->alternate_scan             = Get_Bits(1);
  lph->repeat_first_field         = Get_Bits(1);
  lph->chroma_420_type            = Get_Bits(1);
  lph->progressive_frame          = Get_Bits(1);
  lph->composite_display_flag     = Get_Bits(1);

  if (lph->composite_display_flag) {
    lph->v_axis            = Get_Bits(1);
    lph->field_sequence    = Get_Bits(3);
    lph->sub_carrier       = Get_Bits(1);
    lph->burst_amplitude   = Get_Bits(7);
    lph->sub_carrier_phase = Get_Bits(8);
  }
}

static int extra_bit_information(tm2MpegDecInstVars_t *livp)
{
  int Byte_Count = 0;

  while (Get_Bits(1)) {
    Flush_Buffer(8);
    Byte_Count++;
  }
  return(Byte_Count);
}


static void copyright_extension(tm2MpegDecInstVars_t *livp, tmMPEGHdr_t *lph)
{
  int reserved_data;

  lph->copyright_flag =       Get_Bits(1); 
  lph->copyright_identifier = Get_Bits(8);
  lph->original_or_copy =     Get_Bits(1);
  
  /* reserved */
  reserved_data = Get_Bits(7);

  marker_bit(livp,"copyright_extension(), first marker bit");
  lph->copyright_number_1 =   Get_Bits(20);
  marker_bit(livp,"copyright_extension(), lph->second marker bit");
  lph->copyright_number_2 =   Get_Bits(22);
  marker_bit(livp,"copyright_extension(), third marker bit");
  lph->copyright_number_3 =   Get_Bits(22);
}

static void 
Initialize_Sequence(tm2MpegDecInstVars_t *livp)
{
  unsigned ysize,usize,msize,i,j;

  if (!livp->ph.MPEG2_Flag) {
    livp->ph.progressive_sequence       = 1;
    livp->ph.progressive_frame          = 1;
    livp->ph.picture_structure          = FRAME_PICTURE;
    livp->ph.frame_pred_frame_dct       = 1;
    livp->ph.chroma_format              = CHROMA420;
    livp->ph.matrix_coefficients        = 5;
    livp->ph.concealment_motion_vectors = 0;
  }

  livp->MBWidth = (livp->ph.horizontal_size+15)/16;
  livp->MBHeight = (livp->ph.MPEG2_Flag && !livp->ph.progressive_sequence) ? 
              2*((livp->ph.vertical_size+31)/32):(livp->ph.vertical_size+15)/16;

  
  livp->ph.horizontal_size >>=  (livp->halfResMode == 1); 
  livp->codedPictureWidth  = livp->MBWidth<<(4-livp->halfResMode);   
  livp->codedPictureHeight = livp->MBHeight<<4;

  mpGetValidLineSize(livp->pipeInstance, livp->codedPictureWidth, (UInt32*) &livp->lineSize);

  ysize = livp->lineSize*livp->codedPictureHeight>>1;
  usize = ysize>>1;

  PRINT(("WxH = %d x %d; MB_WxMB_H = %d x %d\n",
	 livp->ph.horizontal_size,
	 livp->ph.vertical_size, livp->MBWidth, livp->MBHeight));

  for(i=0; i < 2; i++){
    msize = ysize;
    for(j=0; j < 2; j++){
      if(livp->backwardReferenceFrame[i][j] != NULL)
	_cache_free(livp->backwardReferenceFrame[i][j]);
      
      if(livp->forwardReferenceFrame[i][j] != NULL)
	_cache_free(livp->forwardReferenceFrame[i][j]);
      
      if(livp->bFrame1[i][j] != NULL)
	_cache_free(livp->bFrame1[i][j]);


      if(livp->bFrame2[i][j] != NULL)
	_cache_free(livp->bFrame2[i][j]);


      livp->backwardReferenceFrame[i][j] =(UInt32 *)(_cache_malloc(msize,-1));
      _cache_copyback(livp->backwardReferenceFrame[i][j],(msize)); 
      
      livp->forwardReferenceFrame[i][j]  =(UInt32 *)(_cache_malloc(msize,-1));
      _cache_copyback(livp->forwardReferenceFrame[i][j],(msize));    

      livp->bFrame1[i][j]               =(UInt32 *)(_cache_malloc(msize,-1));
      _cache_copyback(livp->bFrame1[i][j],(msize)); 
      

      livp->bFrame2[i][j]               =(UInt32 *)(_cache_malloc(msize,-1));
      _cache_copyback(livp->bFrame2[i][j],(msize)); 

      msize = usize;
    }
  }

#ifdef DEBUG
  for(i=0; i < 2; i++) {
    PRINT(("buffer= %08x %08x %08x %08x %08x %08x %08x %08x\n",
      livp->backwardReferenceFrame[0][i],
      livp->backwardReferenceFrame[1][i],
      livp->forwardReferenceFrame[0][i],
      livp->forwardReferenceFrame[1][i],
      livp->bFrame1[0][i],
      livp->bFrame1[1][i],
      livp->bFrame2[0][i],
      livp->bFrame2[1][i]));
  }
#endif
  livp->secondField       = 0;

} /* Initialize_Sequence() */

static void Update_Picture_Buffers(tm2MpegDecInstVars_t *livp)
{                           
  int cc;              /* color component index */
  unsigned long *tmp;  /* temporary swap pointer */
  int field;           /* top or bottom field */

  for(field=0; field < 2; field++){
    for (cc=0; cc<2; cc++) {
      if (livp->ph.picture_coding_type==B_TYPE) {
	tmp = livp->bFrame2[field][cc];
	livp->bFrame2[field][cc] = livp->bFrame1[field][cc];
	livp->bFrame1[field][cc] = tmp;
	livp->currentFrame[field][cc] = livp->bFrame1[field][cc];
      }
      else {
	if (!livp->secondField) {
	  tmp = livp->forwardReferenceFrame[field][cc];
	  livp->forwardReferenceFrame[field][cc] = livp->backwardReferenceFrame[field][cc];
	  livp->backwardReferenceFrame[field][cc] = tmp;
	}
	livp->currentFrame[field][cc] = livp->backwardReferenceFrame[field][cc];
      }
    }
  }
}

⌨️ 快捷键说明

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