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

📄 parset.c

📁 此code含H.264解码需要的 lib和 src
💻 C
📖 第 1 页 / 共 3 页
字号:
        }
      }
    }
    // SPSConsistencyCheck (pps);
    MakeSPSavailable (sps->seq_parameter_set_id, sps);
    img->profile_idc = sps->profile_idc; //ADD-VG
  }

  FreePartition (dp, 1);
  FreeSPS (sps);
}


void ProcessPPS (NALU_t *nalu)
{
  DataPartition *dp;
  pic_parameter_set_rbsp_t *pps;
  int dummy;

  dp = AllocPartition(1);
  pps = AllocPPS();
  memcpy (dp->bitstream->streamBuffer, &nalu->buf[1], nalu->len-1);
  dp->bitstream->code_len = dp->bitstream->bitstream_length = RBSPtoSODB (dp->bitstream->streamBuffer, nalu->len-1);
  dp->bitstream->ei_flag = 0;
  dp->bitstream->read_len = dp->bitstream->frame_bitoffset = 0;
  
  dummy = InterpretPPS (dp, pps);

  // PPSConsistencyCheck (pps);
  if (active_pps)
  {
    if (pps->pic_parameter_set_id == active_pps->pic_parameter_set_id)
    {
      if (!pps_is_equal(pps, active_pps))
      {
        if (dec_picture)
        {
          // this may only happen on slice loss
          exit_picture();
        }
        active_pps = NULL;
      }
    }
  }
  MakePPSavailable (pps->pic_parameter_set_id, pps);
  FreePartition (dp, 1);
  FreePPS (pps);
}

extern FILE *fpic_mem;

void config_sps(seq_parameter_set_rbsp_t *active_sps)
{
	int data;

	// profile_level_idc
	data = (active_sps->profile_idc<<8) | (active_sps->level_idc);
	write_reg(0x60, data);  

	// log2_max_frame_num_minus4
	data = active_sps->log2_max_frame_num_minus4;
    write_reg(0x64, data);
    
	// poc_order_type
	data = (active_sps->delta_pic_order_always_zero_flag << 16) | 
		   (active_sps->pic_order_cnt_type << 8) |
		   (active_sps->log2_max_pic_order_cnt_lsb_minus4 & 0xff);
	write_reg(0x68, data);

	// pic_size_in_mbs_minus1
	data = (active_sps->pic_height_in_map_units_minus1 << 8) |
		   active_sps->pic_width_in_mbs_minus1;
	write_reg(0x6c, data);

	// frame_mbs_only_flag
	data = (active_sps->frame_mbs_only_flag<<8) | active_sps->mb_adaptive_frame_field_flag;
	write_reg(0x70, data);
	
	// direct_8x8_inference_flag
	data = active_sps->direct_8x8_inference_flag;
	write_reg(0x74, data);

	return;
}

void config_pps(pic_parameter_set_rbsp_t *active_pps)
{
	int data;

	// entropy_coding_mode_flag
    data = active_pps->entropy_coding_mode_flag;
	write_reg(0x80, data);
	
	// pic_order_present_flag
    data = active_pps->pic_order_present_flag;
	write_reg(0x84, data);
	
	// (num_ref_idx_active
	data = (active_pps->num_ref_idx_l1_active_minus1 << 8) | 
		   (active_pps->num_ref_idx_l0_active_minus1 & 0xff);
	write_reg(0x88, data);	
	
	// weighted_pred
	data = (active_pps->weighted_pred_flag << 8) | 
		   (active_pps->weighted_bipred_idc & 0xff);
	write_reg(0x8c, data);
		
	// pic_init_qp_minus26
	data = (active_pps->pic_init_qp_minus26 << 8) | 
		   (active_pps->chroma_qp_index_offset & 0xff);
	write_reg(0x90, data);
	
	// deblocking_filter_control_present_flag
	data = active_pps->deblocking_filter_control_present_flag;
	write_reg(0x94, data);

	// (constrained_intra_pred_flag
	data = active_pps->constrained_intra_pred_flag;
	write_reg(0x98, data);
	
	return;
}

void activate_sps (seq_parameter_set_rbsp_t *sps)
{
  if (active_sps != sps)
  {
    if (dec_picture)
    {
      // this may only happen on slice loss
      exit_picture();
    }
    active_sps = sps;

    img->bitdepth_chroma = 0;
    img->width_cr        = 0;
    img->height_cr       = 0;

    // Fidelity Range Extensions stuff (part 1)
    img->bitdepth_luma       = sps->bit_depth_luma_minus8 + 8;
    img->bitdepth_scale[0]   = 1 << sps->bit_depth_luma_minus8;
    if (sps->chroma_format_idc != YUV400)
    {
      img->bitdepth_chroma   = sps->bit_depth_chroma_minus8 + 8;
      img->bitdepth_scale[1] = 1 << sps->bit_depth_chroma_minus8;
    }

    img->MaxFrameNum = 1<<(sps->log2_max_frame_num_minus4+4);
    img->PicWidthInMbs = (sps->pic_width_in_mbs_minus1 +1);
    img->PicHeightInMapUnits = (sps->pic_height_in_map_units_minus1 +1);
    img->FrameHeightInMbs = ( 2 - sps->frame_mbs_only_flag ) * img->PicHeightInMapUnits;
    img->FrameSizeInMbs = img->PicWidthInMbs * img->FrameHeightInMbs;

    img->yuv_format=sps->chroma_format_idc;

    img->width = img->PicWidthInMbs * MB_BLOCK_SIZE;
    img->height = img->FrameHeightInMbs * MB_BLOCK_SIZE;

    if (sps->chroma_format_idc == YUV420)
    {
      img->width_cr = img->width >>1;
      img->height_cr = img->height >>1;
    }
    else if (sps->chroma_format_idc == YUV422)
    {
      img->width_cr = img->width >>1;
      img->height_cr = img->height;
    }
    else if (sps->chroma_format_idc == YUV444)
    {
      //YUV444
      img->width_cr = img->width;
      img->height_cr = img->height;
    }

    img->width_cr_m1 = img->width_cr - 1;
    init_frext(img);
    init_global_buffers();
    if (!img->no_output_of_prior_pics_flag)
    {
      flush_dpb();
    }

	{
		memory_operation[memory_operation_size].action = RESTART;
		memory_operation[memory_operation_size].memory_start = 0;
		memory_operation[memory_operation_size].frame_field = IS_FRAME;
		memory_operation_size++;
	}

    init_dpb();

	{
		img->new_info.dpb_size = dpb.size;
		img->new_info.width = img->width;
		img->new_info.height = img->height;
	}
	
	config_sps(active_sps);

	//fprintf(fpic_mem, "dpb.size = %d\n\n", dpb.size);

//    if (NULL!=Co_located)
//    {
//      free_colocated(Co_located);
//    }

//    Co_located = alloc_colocated (img->width, img->height,sps->mb_adaptive_frame_field_flag);
//    ercInit(img->width, img->height, 1);
  }
}

void activate_pps(pic_parameter_set_rbsp_t *pps)
{
  if (active_pps != pps)
  {
    if (dec_picture)
    {
      // this may only happen on slice loss
      exit_picture();
    }

    active_pps = pps;

    // Fidelity Range Extensions stuff (part 2)
    img->Transform8x8Mode = pps->transform_8x8_mode_flag;

    config_pps(active_pps);
  }
}

void UseParameterSet (int PicParsetId)
{
  seq_parameter_set_rbsp_t *sps = &SeqParSet[PicParSet[PicParsetId].seq_parameter_set_id];
  pic_parameter_set_rbsp_t *pps = &PicParSet[PicParsetId];
//  int i;


  if (PicParSet[PicParsetId].Valid != TRUE)
    printf ("Trying to use an invalid (uninitialized) Picture Parameter Set with ID %d, expect the unexpected...\n", PicParsetId);
  if (SeqParSet[PicParSet[PicParsetId].seq_parameter_set_id].Valid != TRUE)
    printf ("PicParset %d references an invalid (uninitialized) Sequence Parameter Set with ID %d, expect the unexpected...\n", PicParsetId, PicParSet[PicParsetId].seq_parameter_set_id);

  sps =  &SeqParSet[PicParSet[PicParsetId].seq_parameter_set_id];


  // In theory, and with a well-designed software, the lines above
  // are everything necessary.  In practice, we need to patch many values
  // in img-> (but no more in inp-> -- these have been taken care of)

  // Sequence Parameter Set Stuff first

//  printf ("Using Picture Parameter set %d and associated Sequence Parameter Set %d\n", PicParsetId, PicParSet[PicParsetId].seq_parameter_set_id);

  if ((int) sps->pic_order_cnt_type < 0 || sps->pic_order_cnt_type > 2)  // != 1
  {
 //   printf ("invalid sps->pic_order_cnt_type = %d\n", sps->pic_order_cnt_type);
 //   error ("pic_order_cnt_type != 1", -1000);
  }

  if (sps->pic_order_cnt_type == 1)
  {
    if(sps->num_ref_frames_in_pic_order_cnt_cycle >= MAXnum_ref_frames_in_pic_order_cnt_cycle)
    {
  //    error("num_ref_frames_in_pic_order_cnt_cycle too large",-1011);
    }
  }

  activate_sps(sps);
  activate_pps(pps);


  // currSlice->dp_mode is set by read_new_slice (NALU first byte available there)
//  if (pps->entropy_coding_mode_flag == UVLC)
//  {
//    nal_startcode_follows = uvlc_startcode_follows;
//    for (i=0; i<3; i++)
//    {
//      img->currentSlice->partArr[i].readSyntaxElement = readSyntaxElement_UVLC;
//    }
//  }
//  else
//  {
//    nal_startcode_follows = cabac_startcode_follows;
//    for (i=0; i<3; i++)
//    {
//      img->currentSlice->partArr[i].readSyntaxElement = readSyntaxElement_CABAC;
//    }
//  }

}

⌨️ 快捷键说明

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