示例#1
0
/*!
 ***********************************************************************
 * \brief
 *    Allocate the Video Parameters structure
 * \par  Output:
 *    Video Parameters VideoParameters *p_Vid
 ***********************************************************************
 */
static void alloc_video_params( VideoParameters **p_Vid)
{
  int i;
  if ((*p_Vid   =  (VideoParameters *) calloc(1, sizeof(VideoParameters)))==NULL) 
    no_mem_exit("alloc_video_params: p_Vid");

  if (((*p_Vid)->old_slice = (OldSliceParams *) calloc(1, sizeof(OldSliceParams)))==NULL) 
    no_mem_exit("alloc_video_params: p_Vid->old_slice");

  if (((*p_Vid)->snr =  (SNRParameters *)calloc(1, sizeof(SNRParameters)))==NULL) 
    no_mem_exit("alloc_video_params: p_Vid->snr");  

  // Allocate new dpb buffer
  for (i = 0; i < MAX_NUM_DPB_LAYERS; i++)
  {
    if(((*p_Vid)->p_EncodePar[i] = (CodingParameters *)calloc(1, sizeof(CodingParameters))) == NULL)
      no_mem_exit("alloc_video_params:p_Vid->p_EncodePar[i]");
    ((*p_Vid)->p_EncodePar[i])->layer_id = i;
  }
  (*p_Vid)->global_init_done[0] = (*p_Vid)->global_init_done[1] = 0;

  if(((*p_Vid)->ppSliceList = (Slice **) calloc(MAX_NUM_DECSLICES, sizeof(Slice *))) == NULL)
  {
    no_mem_exit("alloc_video_params: p_Vid->ppSliceList");
  }
  (*p_Vid)->iNumOfSlicesAllocated = MAX_NUM_DECSLICES;
  (*p_Vid)->pNextSlice = NULL;
  (*p_Vid)->nalu = AllocNALU(MAX_CODED_FRAME_SIZE);
  (*p_Vid)->pNextPPS = AllocPPS();
  (*p_Vid)->first_sps = TRUE;
}
/*! 
 *************************************************************************************
 * \brief
 *    generates a sequence and picture parameter set and stores these in global
 *    active_sps and active_pps
 *
 * \return
 *    A NALU containing the Sequence ParameterSet
 *
 *************************************************************************************
*/
void GenerateParameterSets ()
{
  seq_parameter_set_rbsp_t *sps = NULL; 
  pic_parameter_set_rbsp_t *pps = NULL;

  sps = AllocSPS();
  pps = AllocPPS();

  FillParameterSetStructures (sps, pps);
  
  active_sps = sps;
  active_pps = pps;
}
/*! 
 *************************************************************************************
 * \brief
 *    generates a sequence and picture parameter set and stores these in global
 *    active_sps and active_pps
 *
 * \return
 *    A NALU containing the Sequence ParameterSet
 *
 *************************************************************************************
*/
void GenerateParameterSets ()
{
  seq_parameter_set_rbsp_t *sps = NULL; 
  pic_parameter_set_rbsp_t *pps = NULL;

  sps = AllocSPS();
  pps = AllocPPS();

  GenerateSequenceParameterSet(sps, 0);

  if (input->GenerateMultiplePPS)
  {
    if (sps->profile_idc >= FREXT_HP)
    {
      GeneratePictureParameterSet( pps, sps, 0, 0, 0, input->cb_qp_index_offset, input->cr_qp_index_offset);
      memcpy (&PicParSet[0], pps, sizeof (pic_parameter_set_rbsp_t));
      GeneratePictureParameterSet( pps, sps, 1, 1, 1, input->cb_qp_index_offset, input->cr_qp_index_offset);
      memcpy (&PicParSet[1], pps, sizeof (pic_parameter_set_rbsp_t));
      GeneratePictureParameterSet( pps, sps, 2, 1, 2, input->cb_qp_index_offset, input->cr_qp_index_offset);
      memcpy (&PicParSet[2], pps, sizeof (pic_parameter_set_rbsp_t));

    }
    else
    {
      GeneratePictureParameterSet( pps, sps, 0, 0, 0, input->chroma_qp_index_offset, 0);
      memcpy (&PicParSet[0], pps, sizeof (pic_parameter_set_rbsp_t));
      GeneratePictureParameterSet( pps, sps, 1, 1, 1, input->chroma_qp_index_offset, 0);
      memcpy (&PicParSet[1], pps, sizeof (pic_parameter_set_rbsp_t));
      GeneratePictureParameterSet( pps, sps, 2, 1, 2, input->chroma_qp_index_offset, 0);
      memcpy (&PicParSet[2], pps, sizeof (pic_parameter_set_rbsp_t));
    }
  }
  else
  {
    if (sps->profile_idc >= FREXT_HP)
      GeneratePictureParameterSet( pps, sps, 0, input->WeightedPrediction, input->WeightedBiprediction, 
                                   input->cb_qp_index_offset, input->cr_qp_index_offset);
    else
      GeneratePictureParameterSet( pps, sps, 0, input->WeightedPrediction, input->WeightedBiprediction,
                                   input->chroma_qp_index_offset, 0);
    
    memcpy (&PicParSet[0], pps, sizeof (pic_parameter_set_rbsp_t));

  }

  active_sps = sps;
  active_pps = &PicParSet[0];
}
示例#4
0
/*!
 ***********************************************************************
 * \brief
 *    Allocate the Video Parameters structure
 * \par  Output:
 *    Video Parameters VideoParameters *p_Vid
 ***********************************************************************
 */
static void alloc_video_params( VideoParameters **p_Vid)
{
  int i;
  if ((*p_Vid   =  (VideoParameters *) mem_calloc(1, sizeof(VideoParameters)))==NULL) 
    no_mem_exit("alloc_video_params: p_Vid");

  if (((*p_Vid)->old_slice = (OldSliceParams *) mem_calloc(1, sizeof(OldSliceParams)))==NULL) 
    no_mem_exit("alloc_video_params: p_Vid->old_slice");

  if (((*p_Vid)->snr =  (SNRParameters *)mem_calloc(1, sizeof(SNRParameters)))==NULL) 
    no_mem_exit("alloc_video_params: p_Vid->snr");  

  // Allocate new dpb buffer
  for (i = 0; i < MAX_NUM_DPB_LAYERS; i++)
  {
    if (((*p_Vid)->p_Dpb_layer[i] =  (DecodedPictureBuffer*)mem_calloc(1, sizeof(DecodedPictureBuffer)))==NULL) 
      no_mem_exit("alloc_video_params: p_Vid->p_Dpb_layer[i]");
    (*p_Vid)->p_Dpb_layer[i]->layer_id = i;
    reset_dpb(*p_Vid, (*p_Vid)->p_Dpb_layer[i]);
    if(((*p_Vid)->p_EncodePar[i] = (CodingParameters *)mem_calloc(1, sizeof(CodingParameters))) == NULL)
      no_mem_exit("alloc_video_params:p_Vid->p_EncodePar[i]");
    ((*p_Vid)->p_EncodePar[i])->layer_id = i;
    if(((*p_Vid)->p_LayerPar[i] = (LayerParameters *)mem_calloc(1, sizeof(LayerParameters))) == NULL)
      no_mem_exit("alloc_video_params:p_Vid->p_LayerPar[i]");
    ((*p_Vid)->p_LayerPar[i])->layer_id = i;
  }
  (*p_Vid)->global_init_done[0] = (*p_Vid)->global_init_done[1] = 0;

#if (ENABLE_OUTPUT_TONEMAPPING)  
  if (((*p_Vid)->seiToneMapping =  (ToneMappingSEI*)mem_calloc(1, sizeof(ToneMappingSEI)))==NULL) 
    no_mem_exit("alloc_video_params: (*p_Vid)->seiToneMapping");  
#endif

  if(((*p_Vid)->ppSliceList = (Slice **) mem_calloc(MAX_NUM_DECSLICES, sizeof(Slice *))) == NULL)
  {
    no_mem_exit("alloc_video_params: p_Vid->ppSliceList");
  }
  (*p_Vid)->iNumOfSlicesAllocated = MAX_NUM_DECSLICES;
  //(*p_Vid)->currentSlice = NULL;
  (*p_Vid)->pNextSlice = NULL;
  (*p_Vid)->nalu = AllocNALU(MAX_CODED_FRAME_SIZE);
  (*p_Vid)->nalu0 = AllocNALU(MAX_CODED_FRAME_SIZE);
  (*p_Vid)->nalu1 = AllocNALU(MAX_CODED_FRAME_SIZE);
  (*p_Vid)->pDecOuputPic = (DecodedPicList *)mem_calloc(1, sizeof(DecodedPicList));
  (*p_Vid)->pNextPPS = AllocPPS();
  (*p_Vid)->first_sps = TRUE;
}
示例#5
0
/*!
 ***********************************************************************
 * \brief
 *    Allocate the Image structure
 * \par  Output:
 *    Image Parameters VideoParameters *p_Vid
 ***********************************************************************
 */
static void alloc_img( VideoParameters **p_Vid)
{
  if ((*p_Vid   =  (VideoParameters *) calloc(1, sizeof(VideoParameters)))==NULL) 
    no_mem_exit("alloc_img: p_Vid");

  if (((*p_Vid)->old_slice = (OldSliceParams *) calloc(1, sizeof(OldSliceParams)))==NULL) 
    no_mem_exit("alloc_img: p_Vid->old_slice");

  if (((*p_Vid)->snr =  (SNRParameters *)calloc(1, sizeof(SNRParameters)))==NULL) 
    no_mem_exit("alloc_img: p_Vid->snr");  

  if (((*p_Vid)->p_Dpb =  (DecodedPictureBuffer*)calloc(1, sizeof(DecodedPictureBuffer)))==NULL) 
    no_mem_exit("alloc_img: p_Vid->p_Dpb");  

  (*p_Vid)->p_Dpb->p_Vid = (*p_Vid);

  (*p_Vid)->p_Dpb->init_done = 0;
  
  (*p_Vid)->global_init_done = 0;

#if (ENABLE_OUTPUT_TONEMAPPING)  
  if (((*p_Vid)->seiToneMapping =  (ToneMappingSEI*)calloc(1, sizeof(ToneMappingSEI)))==NULL) 
    no_mem_exit("alloc_img: (*p_Vid)->seiToneMapping");  
#endif

  if(((*p_Vid)->ppSliceList = (Slice **) calloc(MAX_NUM_DECSLICES, sizeof(Slice *))) == NULL)
  {
    no_mem_exit("alloc_img: p_Vid->ppSliceList");
  }
  (*p_Vid)->iNumOfSlicesAllocated = MAX_NUM_DECSLICES;
  //(*p_Vid)->currentSlice = NULL;
  (*p_Vid)->pNextSlice = NULL;
  (*p_Vid)->nalu = AllocNALU(MAX_CODED_FRAME_SIZE);
  (*p_Vid)->pDecOuputPic = (DecodedPicList *)calloc(1, sizeof(DecodedPicList));
  (*p_Vid)->pNextPPS = AllocPPS();
}
示例#6
0
int main(int argc, char **argv)
{
	int Flag = TRUE;

	//long ftell_position;//, expected_slice_type;
	//int ret;
	NALU_t *nalu;
	
	h264_decoder* dec_params;
	char *ptr;
	
	ptr =  (  char*)malloc(10 * sizeof(char)); 

    if ((dec_params =  (  h264_decoder*)h264_malloc(1 * sizeof(h264_decoder)))==NULL) 
 //	if ((dec_params =  (  h264_decoder*)h264_malloc(1 * 100))==NULL) 
	{
		Flag=FALSE;
	}

  	if ((dec_params->input =  (InputParameters *)h264_malloc(1 * sizeof(InputParameters)))==NULL) 
	{
		printf("main: input");
		exit(0);
	}
	if ((dec_params->img   =  (ImageParameters *)h264_malloc(1 * sizeof(ImageParameters)))==NULL) 
	{
		printf("main: img");
		exit(0);
	}

	////////// ADDED INITIALIZATIONS //////
	dec_params->active_sps       = NULL;
	dec_params->active_pps       = NULL;
 	dec_params->Co_located       = NULL;
	dec_params->dec_picture     = NULL;
	dec_params->global_init_done = 0;
	dec_params->dpb.init_done	 = 0;
	dec_params->img->DeblockCall = 0;
//	dec_params->img->structure   = 0;
	dec_params->MapUnitToSliceGroupMap = NULL;
	dec_params->MbToSliceGroupMap      = NULL;
	dec_params->img->errorConcealmentFlag = 0;			// ERROR CONCEALMENT FLAG SET TO ZERO , NO ERROR CONCEALMENT
	dec_params->img->no_output_of_prior_pics_flag = -1;

	///////////////////////////////////////
	Initializations(dec_params);
	
	Configure ( argc, argv,dec_params );
	
		
	init_old_slice(dec_params);
	
	switch (dec_params->input->FileFormat)
	{
	case 0:
		OpenBitstreamFile (dec_params->input->infile,dec_params);
		break;
	case 1:
		OpenRTPFile (dec_params->input->infile,dec_params);
		break;
	default:
		printf ("Unsupported file format %d, exit\n", dec_params->input->FileFormat);
	}
	
	// Allocate Slice data struct
	malloc_slice(dec_params->input,dec_params->img,dec_params);
	
	init(dec_params->img,dec_params);
	
	dec_params->dec_picture = NULL;
	
	dec_params->dpb.init_done = 0;
	//dec_params->g_nFrame = 0;
	
//	init_out_buffer(dec_params);
	
  //dec_params->img->idr_psnr_number=dec_params->input->ref_offset;
  //dec_params->img->psnr_number=0;
	
	dec_params->img->number=0;
	dec_params->img->type = I_SLICE;
	dec_params->img->dec_ref_pic_marking_buffer = NULL;
	
	// B pictures
	dec_params->Bframe_ctr=0;

	// time for total decoding session
	dec_params->tot_time = 0;

	dec_params->nalu = AllocNALU(MAX_CODED_FRAME_SIZE,dec_params);
	nalu = dec_params->nalu;

	dec_params->dp   = AllocPartition(1, dec_params,1024);
	dec_params->sps  = AllocSPS();
	dec_params->pps  = AllocPPS();


	{
		while ( decode_one_frame( dec_params ) != EOS );
	}	
	//report( dec_params->input, dec_params->img, dec_params->snr,dec_params,);
	report( dec_params->input, dec_params->img,dec_params);
	free_slice( dec_params->input,dec_params->img);

	FreeNALU(dec_params->nalu);
	FreePartition (dec_params->dp, 1);
	FreeSPS (dec_params->sps);
    if (dec_params->PicParSet[dec_params->pps->pic_parameter_set_id].Valid == TRUE && dec_params->PicParSet[dec_params->pps->pic_parameter_set_id].slice_group_id != NULL)
	{
		h264_free (dec_params->PicParSet[dec_params->pps->pic_parameter_set_id].slice_group_id);
		dec_params->PicParSet[dec_params->pps->pic_parameter_set_id].slice_group_id = NULL;
	}
	
	// IF FMO PRESENT
	if (dec_params->active_pps->num_slice_groups_minus1) 
	{
	FmoFinit(dec_params);
	}	

	FreePPS (dec_params->pps);
	
	
	free_global_buffers_baseline(dec_params);
	
	flush_dpb(dec_params);
	
#ifdef PAIR_FIELDS_IN_OUTPUT
	flush_pending_output(dec_params->p_out);
#endif
	
	CloseBitstreamFile(dec_params);
	
	//close(dec_params->p_out);
	fclose (dec_params->f_out);
	//  fclose(p_out2);

#if TRACE
	fclose(p_trace);
#endif
	
	//ercClose(dec_params->erc_errorVar,dec_params);
	ercClose(dec_params);
	
	free_dpb(dec_params);
//	uninit_out_buffer(dec_params);
	
	free_colocated(dec_params);
	if(dec_params->dec_picture != NULL)
	{
		free (dec_params->dec_picture);
		dec_params->dec_picture = NULL;
	}
	if(dec_params->input != NULL)
	{
		h264_free (dec_params->input);
		dec_params->input = NULL;
	}
	if(dec_params->img != NULL)
	{
		h264_free (dec_params->img);
		dec_params->img = NULL;
	}
	if(dec_params != NULL)
	{
		h264_free (dec_params);
		dec_params = NULL;
	}
	return 0;
}