Ejemplo n.º 1
0
/*!
 ************************************************************************
 *  \brief
 *     This function generates the slice (and partition) header(s) 
 *
 *  \return number of bits used for the slice (and partition) header(s)
 *
 *  \par Side effects:
 *      Adds slice/partition header symbols to the symbol buffer
 *      increments Picture->no_slices, allocates memory for the
 *      slice, sets img->currSlice
 ************************************************************************
*/
int start_slice()
{
  EncodingEnvironmentPtr eep;
  Slice *currSlice = img->currentSlice;
  Bitstream *currStream;
  int header_len = 0;
  int i;
  int NumberOfPartitions = (input->partition_mode == PAR_DP_1?1:3);

  init_ref_pic_list_reordering();

  RTPUpdateTimestamp (img->tr);   // this has no side effects, just leave it for all NALs

  for (i=0; i<NumberOfPartitions; i++)
  {
    currStream = (currSlice->partArr[i]).bitstream;

    currStream->write_flag = 0;
    if (i==0)     // First partition
      header_len += SliceHeader (0);
    else          // Second/Third partition
      header_len += Partition_BC_Header(i);
     
    //! Initialize CABAC
    if (input->symbol_mode == CABAC)
    {
      eep = &((currSlice->partArr[i]).ee_cabac);
      if (currStream->bits_to_go != 8)
        header_len+=currStream->bits_to_go;
      writeVlcByteAlign(currStream);
      arienco_start_encoding(eep, currStream->streamBuffer, &(currStream->byte_pos)/*, &(currStream->last_startcode)*/,img->type);
    } else 
    {
      // Initialize CA-VLC
      CAVLC_init();
    }
  }
  if(input->symbol_mode == CABAC)
  {
    init_contexts();
  }
  return header_len;
}
Ejemplo n.º 2
0
void c_avs_enc:: bot_field(Picture *pic)
{
  myboolean end_of_picture = myfalse;
  int_32_t CurrentMbNumber=0;
  int_32_t MBRowSize = img->width / MB_BLOCK_SIZE;
  int_32_t slice_nr =0;
  int_32_t slice_qp = img->qp;
  int_32_t len;

  img->top_bot = 1; //Yulj 2004.07.20
  while (end_of_picture == myfalse) // loop over macroblocks
  {
    set_MB_parameters (CurrentMbNumber);
    if (input->slice_row_nr && (img->current_mb_nr ==0
      ||(img->current_mb_nr>0 && img->mb_data[img->current_mb_nr].slice_nr != img->mb_data[img->current_mb_nr-1].slice_nr)))
    {
      // slice header start  jlzheng 7.11
      start_slice ();
      img->current_slice_qp = img->qp;
      img->current_slice_start_mb = img->current_mb_nr;
      len = SliceHeader(slice_nr, slice_qp);
      stat->bit_slice += len;
      slice_nr++;
      // slice header end
    }

    img->current_mb_nr_fld = img->current_mb_nr+img->total_number_mb;
    start_macroblock ();
    (this->*encode_one_macroblock) ();
    write_one_macroblock (1);
    terminate_macroblock (&end_of_picture);
    proceed2nextMacroblock ();
    CurrentMbNumber++;
  }

  terminate_picture ();
  if(!input->loop_filter_disable)
  DeblockFrame (img, imgY, imgUV);

  pic->bits_per_picture = 8 * (currBitStream->byte_pos);
}
Ejemplo n.º 3
0
void c_avs_enc:: picture_data( )
{
  myboolean end_of_picture = myfalse;
  int_32_t CurrentMbNumber=0;
  int_32_t MBRowSize = img->img_width_in_mb;
  int_32_t slice_nr = 0;
  int_32_t slice_qp = img->qp;
  int_32_t len, i;
  //init the intra pred mode
  for(i=0; i<img->width/B8_SIZE+100; i++)
  {
    memset(img->ipredmode[i], -1, (img->height/B8_SIZE+100)*sizeof(int_32_t));
  }

  for(i=0; i<img->total_number_mb; i++)
  {
    img->mb_data[i].slice_nr = -1;
  }
  if (input->rdopt)
  {
    switch(img->type)
    {
    case INTRA_IMG:
      encode_one_macroblock = &c_avs_enc::encode_one_intra_macroblock_rdo;
      break;
    case INTER_IMG:
      encode_one_macroblock = &c_avs_enc::encode_one_inter_macroblock_rdo;
      break;
    case B_IMG:
      encode_one_macroblock = &c_avs_enc::encode_one_b_frame_macroblock_rdo;
      break;
    }
  }
  else
  {
    // xzhao
    //img->type=INTRA_IMG;
    switch(img->type)
    {
    case INTRA_IMG:
      encode_one_macroblock = &c_avs_enc::encode_one_intra_macroblock_not_rdo;
      break;
    case INTER_IMG:
      encode_one_macroblock = &c_avs_enc::encode_one_inter_macroblock_not_rdo;
      break;
    case B_IMG:
      encode_one_macroblock = &c_avs_enc::encode_one_b_frame_macroblock_not_rdo;
      break;
    }
  }

  while (end_of_picture == myfalse) // loop over macroblocks
  {
    set_MB_parameters(CurrentMbNumber);
    if (input->slice_row_nr && (img->current_mb_nr ==0 ||(img->current_mb_nr>0 && img->mb_data[img->current_mb_nr].slice_nr != img->mb_data[img->current_mb_nr-1].slice_nr)))
    {
#ifdef _ME_FOR_RATE_CONTROL_
      if (glb_me_for_rate_control_flag)
      {
        start_slice ();
      }
#else
      start_slice ();
#endif
      img->current_slice_qp = img->qp;
      img->current_slice_start_mb = img->current_mb_nr;

      len = SliceHeader(slice_nr, slice_qp);

      img->current_slice_nr = slice_nr;
      stat->bit_slice += len;
      slice_nr++;
    }
    start_macroblock();
    (this->*encode_one_macroblock)();

    write_one_macroblock(1);
    terminate_macroblock (&end_of_picture);

    proceed2nextMacroblock ();
    CurrentMbNumber++;
  }

  terminate_picture ();
  DeblockFrame (img, imgY, imgUV);
}