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

📄 h26l.c

📁 网络MPEG4IP流媒体开发源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
                                // So this is a strictly conservative estimation                                // of the size of the bitstream buffer for one frame */                                                       /* ~DM  switch(input->of_mode) // init depending on NAL mode  {    case PAR_OF_26L:      // Current File Format      img->currentSlice = (Slice *) calloc(1, sizeof(Slice));      if ( (currSlice = img->currentSlice) == NULL)      {        snprintf (errortext, ET_SIZE, "Memory allocation for Slice datastruct in NAL-mode %d failed", input->of_mode);        error(errortext, 600);      }      if (input->symbol_mode == CABAC)      {        // create all context models        currSlice->mot_ctx = create_contexts_MotionInfo();        currSlice->tex_ctx = create_contexts_TextureInfo();      }      switch(input->partition_mode)      {      case PAR_DP_1:        currSlice->max_part_nr = 1;        break;      case PAR_DP_3:        error("Data Partitioning not supported with bit stream file format",600);        break;      default:        error("Data Partitioning Mode not supported!",600);        break;      }      currSlice->partArr = (DataPartition *) calloc(currSlice->max_part_nr, sizeof(DataPartition));      if (currSlice->partArr == NULL)      {        snprintf(errortext, ET_SIZE, "Memory allocation for Data Partition datastruct in NAL-mode %d failed", input->of_mode);        error(errortext, 100);      }      for (i=0; i<currSlice->max_part_nr; i++) // loop over all data partitions      {        dataPart = &(currSlice->partArr[i]);        dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));        if (dataPart->bitstream == NULL)        {          snprintf(errortext, ET_SIZE, "Memory allocation for Bitstream datastruct in NAL-mode %d failed", input->of_mode);          error (errortext, 100);        }        dataPart->bitstream->streamBuffer = (byte *) calloc(buffer_size, sizeof(byte));        if (dataPart->bitstream->streamBuffer == NULL)        {          snprintf(errortext, ET_SIZE, "Memory allocation for bitstream buffer in NAL-mode %d failed", input->of_mode);          error (errortext, 100);        }        // Initialize storage of bitstream parameters        dataPart->bitstream->stored_bits_to_go = 8;        dataPart->bitstream->stored_byte_pos = 0;        dataPart->bitstream->stored_byte_buf = 0;      }      return;    case PAR_OF_RTP:      // RTP packet file format      img->currentSlice = (Slice *) calloc(1, sizeof(Slice));      if ( (currSlice = img->currentSlice) == NULL)      {        snprintf(errortext, ET_SIZE, "Memory allocation for Slice datastruct in NAL-mode %d failed", input->of_mode);        error(errortext, 100);      }      if (input->symbol_mode == CABAC)      {        // create all context models        currSlice->mot_ctx = create_contexts_MotionInfo();        currSlice->tex_ctx = create_contexts_TextureInfo();      }      switch(input->partition_mode)      {      case PAR_DP_1:        currSlice->max_part_nr = 1;        break;      case PAR_DP_3:        currSlice->max_part_nr = 3;        break;      default:        error("Data Partitioning Mode not supported!",600);        break;      }      currSlice->partArr = (DataPartition *) calloc(currSlice->max_part_nr, sizeof(DataPartition));      if (currSlice->partArr == NULL)      {        snprintf(errortext, ET_SIZE, "Memory allocation for Data Partition datastruct in NAL-mode %d failed", input->of_mode);        error(errortext, 100);      }      for (i=0; i<currSlice->max_part_nr; i++) // loop over all data partitions      {        dataPart = &(currSlice->partArr[i]);        dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));        if (dataPart->bitstream == NULL)        {          snprintf(errortext, ET_SIZE, "Memory allocation for Bitstream datastruct in NAL-mode %d failed", input->of_mode);          error(errortext, 100);        }        dataPart->bitstream->streamBuffer = (byte *) calloc(buffer_size, sizeof(byte));        if (dataPart->bitstream->streamBuffer == NULL)        {          snprintf(errortext, ET_SIZE, "Memory allocation for bitstream buffer in NAL-mode %d failed", input->of_mode);          error(errortext, 100);        }        // Initialize storage of bitstream parameters        dataPart->bitstream->stored_bits_to_go = 8;        dataPart->bitstream->stored_byte_pos = 0;        dataPart->bitstream->stored_byte_buf = 0;      }      return;    default:      snprintf(errortext, ET_SIZE, "Output File Mode %d not supported", input->of_mode);      error(errortext, 600);  }}/*! ************************************************************************ * \brief *    Memory frees of the Slice structure and of its dependent *    data structures * \par Input: *    Input Parameters struct inp_par *inp,  struct img_par *img ************************************************************************ */void free_slice(){  int i;  DataPartition *dataPart;  Slice *currSlice = img->currentSlice;  for (i=0; i<currSlice->max_part_nr; i++) // loop over all data partitions  {    dataPart = &(currSlice->partArr[i]);    if (dataPart->bitstream->streamBuffer != NULL)      free(dataPart->bitstream->streamBuffer);    if (dataPart->bitstream != NULL)      free(dataPart->bitstream);  }  if (currSlice->partArr != NULL)    free(currSlice->partArr);  if (input->symbol_mode == CABAC)  {    // delete all context models    delete_contexts_MotionInfo(currSlice->mot_ctx);    delete_contexts_TextureInfo(currSlice->tex_ctx);  }  if (currSlice != NULL)    free(img->currentSlice);}/*! ************************************************************************ * \brief *    Initializes the Statistics structure with appropriate parameters * \par Input: *    Statistic Parameters struct stat_par *stat * \par Output: *    Statistic Parameters struct stat_par *stat ************************************************************************ */void init_stat(){  int i;  if ((h26lstat->mode_use_Bframe = (int *)malloc(sizeof(int)*41))==NULL)    no_mem_exit("init_stat: h26lstat->mode_use_Bframe");  if ((h26lstat->bit_use_mode_Bframe =  (int *)malloc(sizeof(int)*41))==NULL)    no_mem_exit("init_stat: h26lstat->bit_use_mode_Bframe");  for(i=0; i<41; i++)    h26lstat->mode_use_Bframe[i]=h26lstat->bit_use_mode_Bframe[i]=0;}/*! ************************************************************************ * \brief *    Reports the gathered information to appropriate outputs * \par Input: *    struct inp_par *inp,                                            \n *    struct img_par *img,                                            \n *    struct stat_par *stat,                                          \n *    struct stat_par *stat                                           \n * * \par Output: *    None ************************************************************************ */void report(){  int bit_use[2][2] ;  int i,j;  char name[20];  int bit_use_Bframe=0;  int total_bits;  float frame_rate;#ifndef WIN32  time_t now;  struct tm *l_time;  char string[1000];#else  char timebuf[128];#endif  bit_use[0][0]=1;  bit_use[1][0]=max(1,input->no_frames-1);  //  Accumulate bit usage for inter and intra frames  bit_use[0][1]=bit_use[1][1]=0;  for (i=0; i < 9; i++)    bit_use[1][1] += h26lstat->bit_use_mode_inter[i];  for (j=0;j<2;j++)  {    bit_use[j][1]+=h26lstat->bit_use_header[j];    bit_use[j][1]+=h26lstat->bit_use_mb_type[j];    bit_use[j][1]+=h26lstat->tmp_bit_use_cbp[j];    bit_use[j][1]+=h26lstat->bit_use_coeffY[j];    bit_use[j][1]+=h26lstat->bit_use_coeffC[j];    bit_use[j][1]+=h26lstat->bit_use_delta_quant[j];  }  // B pictures  if(Bframe_ctr!=0)  {    bit_use_Bframe=0;    for(i=0; i<41; i++)      bit_use_Bframe += h26lstat->bit_use_mode_Bframe[i]; // fw_predframe_no, blk_size    bit_use_Bframe += h26lstat->bit_use_header[2];    bit_use_Bframe += h26lstat->tmp_bit_use_cbp[2];    bit_use_Bframe += h26lstat->bit_use_coeffY[2];    bit_use_Bframe += h26lstat->bit_use_coeffC[2];    bit_use_Bframe += h26lstat->bit_use_delta_quant[2];    h26lstat->bitrate_P=(h26lstat->bit_ctr_0+h26lstat->bit_ctr_P)*(float)(img->framerate/(input->jumpd+1))/input->no_frames;#ifdef _ADAPT_LAST_GROUP_    h26lstat->bitrate_B=(h26lstat->bit_ctr_B)*(float)(img->framerate/(input->jumpd+1))*initial_Bframes/Bframe_ctr;#else    h26lstat->bitrate_B=(h26lstat->bit_ctr_B)*(float)(img->framerate/(input->jumpd+1))*input->successive_Bframe/Bframe_ctr;#endif  }  else  {    if (input->no_frames > 1)    {      h26lstat->bitrate=(bit_use[0][1]+bit_use[1][1])*(float)img->framerate/(input->no_frames*(input->jumpd+1));    }  }  fprintf(stdout,"--------------------------------------------------------------------------\n");  fprintf(stdout,   " Freq. for encoded bitstream       : %1.0f\n",(float)img->framerate/(float)(input->jumpd+1));  if(input->hadamard)    fprintf(stdout," Hadamard transform                : Used\n");  else    fprintf(stdout," Hadamard transform                : Not used\n");  fprintf(stdout," Image format                      : %dx%d\n",input->img_width,input->img_height);  if(input->intra_upd)    fprintf(stdout," Error robustness                  : On\n");  else    fprintf(stdout," Error robustness                  : Off\n");  fprintf(stdout,    " Search range                      : %d\n",input->search_range);  if(input->mv_res)    fprintf(stdout," MV resolution                     : 1/8-pel\n");  else    fprintf(stdout," MV resolution                     : 1/4-pel\n");#ifdef _ADDITIONAL_REFERENCE_FRAME_  if (input->add_ref_frame >= input->no_multpred)  {      fprintf(stdout,   " No of ref. frames used in P pred  : %d (+ no. %d)\n",input->no_multpred,input->add_ref_frame);      if(input->successive_Bframe != 0)        fprintf(stdout,   " No of ref. frames used in B pred  : %d (+ no. %d)\n",input->no_multpred,input->add_ref_frame);  }  else#endif  {    fprintf(stdout,   " No of ref. frames used in P pred  : %d\n",input->no_multpred);    if(input->successive_Bframe != 0)      fprintf(stdout,   " No of ref. frames used in B pred  : %d\n",input->no_multpred);  }  fprintf(stdout,   " Total encoding time for the seq.  : %.3f sec \n",tot_time*0.001);  // B pictures  fprintf(stdout, " Sequence type                     :" );  if(input->successive_Bframe==1)   fprintf(stdout, " IBPBP (QP: I %d, P %d, B %d) \n",    input->qp0, input->qpN, input->qpB);  else if(input->successive_Bframe==2) fprintf(stdout, " IBBPBBP (QP: I %d, P %d, B %d) \n",    input->qp0, input->qpN, input->qpB);  else if(input->successive_Bframe==0 && input->sp_periodicity==0) fprintf(stdout, " IPPP (QP: I %d, P %d) \n",   input->qp0, input->qpN);  else fprintf(stdout, " I-P-P-SP-P (QP: I %d, P %d, SP (%d, %d)) \n",  input->qp0, input->qpN, input->qpsp, input->qpsp_pred);  // report on entropy coding  method  if (input->symbol_mode == UVLC)    fprintf(stdout," Entropy coding method             : UVLC\n");  else    fprintf(stdout," Entropy coding method             : CABAC\n");#ifdef _FULL_SEARCH_RANGE_  if (input->full_search == 2)    fprintf(stdout," Search range restrictions         : none\n");  else if (input->full_search == 1)    fprintf(stdout," Search range restrictions         : older reference frames\n");  else    fprintf(stdout," Search range restrictions         : smaller blocks and older reference frames\n");#endif  if (input->rdopt)    fprintf(stdout," RD-optimized mode decision        : used\n");  else    fprintf(stdout," RD-optimized mode decision        : not used\n");  switch(input->partition_mode)    {    case PAR_DP_1:      fprintf(stdout," Data Partitioning Mode            : 1 partition \n");      break;    case PAR_DP_3:      fprintf(stdout," Data Partitioning Mode            : 3 partitions \n");      break;    default:      fprintf(stdout," Data Partitioning Mode            : not supported\n");      break;    }    switch(input->of_mode)    {    case PAR_OF_26L:      fprintf(stdout," Output File Format                : H.26L Bit Stream File Format \n");      break;    case PAR_OF_RTP:      fprintf(stdout," Output File Format                : RTP Packet File Format \n");      break;    default:      fprintf(stdout," Output File Format                : not supported\n");      break;    }  fprintf(stdout,"------------------ Average data all frames  ------------------------------\n");  fprintf(stdout," SNR Y(dB)                         : %5.2f\n",snr->snr_ya);  fprintf(stdout," SNR U(dB)                         : %5.2f\n",snr->snr_ua);  fprintf(stdout," SNR V(dB)                         : %5.2f\n",snr->snr_va);  if(Bframe_ctr!=0)  {    fprintf(stdout, " Total bits                        : %d (I %5d, P %5d, B %d) \n",            total_bits=h26lstat->bit_ctr_P + h26lstat->bit_ctr_0 + h26lstat->bit_ctr_B, h26lstat->bit_ctr_0, h26lstat->bit_ctr_P, h26lstat->bit_ctr_B);    frame_rate = (float)img->framerate / ( (float) (input->jumpd - input->successive_Bframe + 1) );    h26lstat->bitrate= ((float) total_bits * frame_rate)/((float) (input->no_frames + Bframe_ctr));    fprintf(stdout, " Bit rate (kbit/s)  @ %2.2f Hz     : %5.2f\n", frame_rate, h26lstat->bitrate/1000);  }  else if (input->sp_periodicity==0)  {    fprintf(stdout, " Total bits                        : %d (I %5d, P %5d) \n",    total_bits=h26lstat->bit_ctr_P + h26lstat->bit_ctr_0 , h26lstat->bit_ctr_0, h26lstat->bit_ctr_P);    frame_rate = (float)img->framerate / ( (float) (input->jumpd + 1) );    h26lstat->bitrate= ((float) total_bits * frame_rate)/((float) input->no_frames );    fprintf(stdout, " Bit rate (kbit/s)  @ %2.2f Hz     : %5.2f\n", frame_rate, h26lstat->bitrate/1000);  }else  {    fprintf(stdout, " Total bits                        : %d (I %5d, P %5d) \n",    total_bits=h26lstat->bit_ctr_P + h26lstat->bit_ctr_0 , h26lstat->bit_ctr_0, h26lstat->bit_ctr_P);    frame_rate = (float)img->framerate / ( (float) (input->jumpd + 1) );    h26lstat->bitrate= ((float) total_bits * frame_rate)/((float) input->no_frames );    fprintf(stdout, " Bit rate (kbit/s)  @ %2.2f Hz     : %5.2f\n", frame_rate, h26lstat->bitrate/1000);  }  fprintf(stdout,"--------------------------------------------------------------------------\n");  fprintf(stdout,"Exit TML %s encoder ver %s\n", TML, VERSION);  // status file  if ((p_stat=fopen("stat.dat","wb"))==0)  {    snprintf(errortext, ET_SIZE, "Error open file %s", "stat.dat");    error(errortext, 500);  }  fprintf(p_stat," -------------------------------------------------------------- \n");  fprintf(p_stat,"  This file contains statistics for the last encoded sequence   \n");  fprintf(p_stat," -------------------------------------------------------------- \n");  fprintf(p_stat,   " Sequence                     : %s\n",input->infile);  fprintf(p_stat,   " No.of coded pictures         : %d\n",input->no_frames+Bframe_ctr);  fprintf(p_stat,   " Freq. for encoded bitstream  : %3.0f\n",frame_rate);  // B pictures  if(input->successive_Bframe != 0)  {    fprintf(p_stat,   " BaseLayer Bitrate(kb/s)      : %6.2f\n", h26lstat->bitrate_P/1000);    fprintf(p_stat,   " EnhancedLyaer Bitrate(kb/s)  : %6.2f\n", h26lstat->bitrate_B/1000);  }  else    fprintf(p_stat,   " Bitrate(kb/s)                : %6.2f\n", h26lstat->bitrate/1000);  if(input->hadamard)    fprintf(p_stat," Hadamard transform           : Used\n");  else    fprintf(p_stat," Hadamard transform           : Not used\n");  fprintf(p_stat," Image format                 : %dx%d\n",input->img_width,input->img_height);  if(input->intra_upd)    fprintf(p_stat," Error robustness             : On\n");

⌨️ 快捷键说明

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