Example #1
0
/*!
 ************************************************************************
 * \brief
 *    Free allocated memory of frame size related global buffers
 *    buffers are defined in global.h, allocated memory is allocated in
 *    int init_global_buffers()
 *
 * \par Input:
 *    Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
 *
 * \par Output:
 *    none
 *
 ************************************************************************
 */
void free_global_buffers(struct inp_par *inp, struct img_par *img)
{
  free_mem2D (imgY_ref);
  free_mem3D (imgUV_ref,2);

#ifndef STATIC_ALLOC
  // CAVLC free mem
  free_mem3Dint(img->nz_coeff, img->FrameSizeInMbs);
  free_mem2Dint(img->siblock);

  // free mem, allocated for structure img
  if (img->mb_data       != NULL) free(img->mb_data);

  free (img->intra_block);
  free_mem2Dint (img->ipredmode);
#endif

  free_mem2Dint(img->field_anchor);

  free_mem3Dint(img->wp_weight, 2);
  free_mem3Dint(img->wp_offset, 2);
  free_mem4Dint(img->wbp_weight, 2, MAX_REFERENCE_PICTURES);

  global_init_done = 0;

}
/*!
 ************************************************************************
 * \brief
 *    Free allocated memory of frame size related global buffers
 *    buffers are defined in global.h, allocated memory is allocated in
 *    int init_global_buffers()
 *
 * \par Input:
 *    Input Parameters struct inp_par *inp, Image Parameters struct img_par *img
 *
 * \par Output:
 *    none
 *
 ************************************************************************
 */
void free_global_buffers()
{
  free_mem2D (imgY_ref);
  free_mem3D (imgUV_ref,2);

  // CAVLC free mem
  free_mem3Dint(img->nz_coeff, img->oldFrameSizeInMbs);

  free_mem2Dint(img->siblock);

  // free mem, allocated for structure img
  if (img->mb_data       != NULL) free(img->mb_data);

  free (img->intra_block);

  free_mem2Dint (img->ipredmode);

  free_mem2Dint(img->field_anchor);

  free_mem3Dint(img->wp_weight, 2);
  free_mem3Dint(img->wp_offset, 6);
  free_mem4Dint(img->wbp_weight, 6, MAX_REFERENCE_PICTURES);

  global_init_done = 0;

}
Example #3
0
File: output.c Project: VVer/JM86
/*!
 ************************************************************************
 * \brief
 *    output the pending frame buffer
 * \param p_out
 *    Output file
 ************************************************************************
 */
void flush_pending_output(FILE *p_out)
{
  if (pending_output_state!=FRAME)
  {
    write_out_picture(pending_output, p_out);
  }
  
  if (pending_output->imgY)
  {
    free_mem2D (pending_output->imgY);
    pending_output->imgY=NULL;
  }
  if (pending_output->imgUV)
  {
    free_mem3D (pending_output->imgUV, 2);
    pending_output->imgUV=NULL;
  }

  pending_output_state = FRAME;
}
Example #4
0
/*!
 ************************************************************************
 *  \brief
 *     Interpret the spare picture SEI message
 *  \param payload
 *     a pointer that point to the sei payload
 *  \param size
 *     the size of the sei message
 *  \param img
 *     the image pointer
 *    
 ************************************************************************
 */
void interpret_spare_pic( byte* payload, int size, ImageParameters *img )
{
  int i,x,y;
  Bitstream* buf;
  int bit0, bit1, bitc, no_bit0;
  int target_frame_num;
  int num_spare_pics;
  int delta_spare_frame_num, CandidateSpareFrameNum, SpareFrameNum = 0;
  int ref_area_indicator;

  int m, n, left, right, top, bottom,directx, directy;
  byte ***map;

#ifdef WRITE_MAP_IMAGE
  int  j, k, i0, j0, tmp, kk;
  char filename[20] = "map_dec.yuv";
  FILE *fp;
  byte** Y;
  static int old_pn=-1;
  static int first = 1;

  printf("Spare picture SEI message\n");
#endif

  UsedBits = 0;

  assert( payload!=NULL);
  assert( img!=NULL);
#ifdef ESLCPP
  buf = (Bitstream*)malloc(sizeof(Bitstream));
#else
  buf = malloc(sizeof(Bitstream));
#endif
  buf->bitstream_length = size;
  buf->streamBuffer = payload;
  buf->frame_bitoffset = 0;

  target_frame_num = ue_v("SEI: target_frame_num", buf);

#ifdef WRITE_MAP_IMAGE
  printf( "target_frame_num is %d\n", target_frame_num );
#endif

  num_spare_pics = 1 + ue_v("SEI: num_spare_pics_minus1", buf);

#ifdef WRITE_MAP_IMAGE
  printf( "num_spare_pics is %d\n", num_spare_pics );
#endif

  get_mem3D(&map, num_spare_pics, img->height/16, img->width/16);

  for (i=0; i<num_spare_pics; i++)
  {
    if (i==0) 
    {
      CandidateSpareFrameNum = target_frame_num - 1;
      if ( CandidateSpareFrameNum < 0 ) CandidateSpareFrameNum = MAX_FN - 1;
    }
    else
      CandidateSpareFrameNum = SpareFrameNum;

    delta_spare_frame_num = ue_v("SEI: delta_spare_frame_num", buf);

    SpareFrameNum = CandidateSpareFrameNum - delta_spare_frame_num;
    if( SpareFrameNum < 0 )
      SpareFrameNum = MAX_FN + SpareFrameNum;

    ref_area_indicator = ue_v("SEI: ref_area_indicator", buf);

    switch ( ref_area_indicator )
    {
    case 0:   // The whole frame can serve as spare picture
      for (y=0; y<img->height/16; y++)
        for (x=0; x<img->width/16; x++)
          map[i][y][x] = 0;
      break;
    case 1:   // The map is not compressed
      for (y=0; y<img->height/16; y++)
        for (x=0; x<img->width/16; x++)
        {
          map[i][y][x] = u_1("SEI: ref_mb_indicator", buf);
        }
      break;
    case 2:   // The map is compressed
              //!KS: could not check this function, description is unclear (as stated in Ed. Note)
      bit0 = 0;
      bit1 = 1;
      bitc = bit0;
      no_bit0 = -1;

      x = ( img->width/16 - 1 ) / 2;
      y = ( img->height/16 - 1 ) / 2;
      left = right = x;
      top = bottom = y;
      directx = 0;
      directy = 1;

      for (m=0; m<img->height/16; m++)
        for (n=0; n<img->width/16; n++)
        {

          if (no_bit0<0)
          {
            no_bit0 = ue_v("SEI: zero_run_length", buf);
          }
          if (no_bit0>0) map[i][y][x] = bit0;
          else map[i][y][x] = bit1;
          no_bit0--;

          // go to the next mb:
          if ( directx == -1 && directy == 0 )
          {
            if (x > left) x--;
            else if (x == 0)
            {
              y = bottom + 1;
              bottom++;
              directx = 1;
              directy = 0;
            }
            else if (x == left)
            {
              x--;
              left--;
              directx = 0;
              directy = 1;
            }
          }
          else if ( directx == 1 && directy == 0 )
          {
            if (x < right) x++;
            else if (x == img->width/16 - 1)
            {
              y = top - 1;
              top--;
              directx = -1;
              directy = 0;
            }
            else if (x == right)
            {
              x++;
              right++;
              directx = 0;
              directy = -1;
            }
          }
          else if ( directx == 0 && directy == -1 )
          {
            if ( y > top) y--;
            else if (y == 0)
            {
              x = left - 1;
              left--;
              directx = 0;
              directy = 1;
            }
            else if (y == top)
            {
              y--;
              top--;
              directx = -1;
              directy = 0;
            }
          }
          else if ( directx == 0 && directy == 1 )
          {
            if (y < bottom) y++;
            else if (y == img->height/16 - 1)
            {
              x = right+1;
              right++;
              directx = 0;
              directy = -1;
            }
            else if (y == bottom)
            {
              y++;
              bottom++;
              directx = 1;
              directy = 0;
            }
          }


        }
      break;
    default:
      printf( "Wrong ref_area_indicator %d!\n", ref_area_indicator );
      exit(0);
      break;
    }

  } // end of num_spare_pics

#ifdef WRITE_MAP_IMAGE
  // begin to write map seq
  if ( old_pn != img->number )
  {
    old_pn = img->number;
    get_mem2D(&Y, img->height, img->width);
    if (first)
    {
      fp = fopen( filename, "wb" );
      first = 0;
    }
    else
      fp = fopen( filename, "ab" );
    assert( fp != NULL );
    for (kk=0; kk<num_spare_pics; kk++)
    {
      for (i=0; i < img->height/16; i++)
        for (j=0; j < img->width/16; j++)
        {
          tmp=map[kk][i][j]==0? 255 : 0;
          for (i0=0; i0<16; i0++)
            for (j0=0; j0<16; j0++)
              Y[i*16+i0][j*16+j0]=tmp;
        }

      // write the map image
      for (i=0; i < img->height; i++)
        for (j=0; j < img->width; j++)
          fputc(Y[i][j], fp);

      for (k=0; k < 2; k++)
        for (i=0; i < img->height/2; i++)
          for (j=0; j < img->width/2; j++)
            fputc(128, fp);
    }
    fclose( fp );
    free_mem2D( Y );
  }
  // end of writing map image
#undef WRITE_MAP_IMAGE
#endif

  free_mem3D( map, num_spare_pics );

  free(buf);
}
Example #5
0
/*!
**************************************************************************************
* \brief 
*      free memory of error resilient RDO.  
**************************************************************************************
*/
void free_errdo_mem(VideoParameters *p_Vid)
{
  //for shared memory
  if (p_Vid->p_decs->res_img)
  {
    free_mem3Dint(p_Vid->p_decs->res_img);
    p_Vid->p_decs->res_img         = NULL;
  }
  if (p_Vid->p_decs->res_mb_best8x8)
  {
    free_mem3Dint(p_Vid->p_decs->res_mb_best8x8);
    p_Vid->p_decs->res_mb_best8x8         = NULL;
  }

  //for RMPC
  if (p_Vid->p_decs->RCD_bestY_mb)
  {
    free_mem2Dint(p_Vid->p_decs->RCD_bestY_mb);
    p_Vid->p_decs->RCD_bestY_mb         = NULL;
  }
  if (p_Vid->p_decs->RCD_bestY_b8x8)
  {
    free_mem3Dint(p_Vid->p_decs->RCD_bestY_b8x8);
    p_Vid->p_decs->RCD_bestY_b8x8         = NULL;
  }
  if (p_Vid->p_decs->MVCD_bestY_mb)
  {
    free_mem2Dint(p_Vid->p_decs->MVCD_bestY_mb);
    p_Vid->p_decs->MVCD_bestY_mb         = NULL;
  }
  if (p_Vid->p_decs->MVCD_bestY_b8x8)
  {
    free_mem3Dint(p_Vid->p_decs->MVCD_bestY_b8x8);
    p_Vid->p_decs->MVCD_bestY_b8x8         = NULL;
  }
  if (p_Vid->p_decs->flag_bestY_mb)
  {
    free_mem2D(p_Vid->p_decs->flag_bestY_mb);
    p_Vid->p_decs->flag_bestY_mb         = NULL;
  }
  if (p_Vid->p_decs->flag_bestY_b8x8)
  {
    free_mem3D(p_Vid->p_decs->flag_bestY_b8x8);
    p_Vid->p_decs->flag_bestY_b8x8         = NULL;
  }
  if (p_Vid->p_decs->flag_wo_res)
  {
    free_mem2D(p_Vid->p_decs->flag_wo_res);
    p_Vid->p_decs->flag_wo_res         = NULL;
  }
  if (p_Vid->p_decs->flag_wo_res_bestY_b8x8)
  {
    free_mem3D(p_Vid->p_decs->flag_wo_res_bestY_b8x8);
    p_Vid->p_decs->flag_wo_res_bestY_b8x8         = NULL;
  }
  if (p_Vid->p_decs->trans_dist_bestY_mb)
  {
    free_mem2Dint(p_Vid->p_decs->trans_dist_bestY_mb);
    p_Vid->p_decs->trans_dist_bestY_mb         = NULL;
  }
  if (p_Vid->p_decs->trans_dist_bestY_b8x8)
  {
    free_mem3Dint(p_Vid->p_decs->trans_dist_bestY_b8x8);
    p_Vid->p_decs->trans_dist_bestY_b8x8         = NULL;
  }
  if (p_Vid->p_decs->trans_dist_wo_res)
  {
    free_mem2Dint(p_Vid->p_decs->trans_dist_wo_res);
    p_Vid->p_decs->trans_dist_wo_res         = NULL;   //it is used for P8x8, where residual may be set to 0
  }
  if (p_Vid->p_decs->trans_dist_wo_res_bestY_b8x8)
  {
    free_mem3Dint(p_Vid->p_decs->trans_dist_wo_res_bestY_b8x8);
    p_Vid->p_decs->trans_dist_wo_res_bestY_b8x8   = NULL;   //it is used for P8x8, where residual may be set to 0
  }
  if (p_Vid->p_decs->trans_err_bestY_mb)
  {
    free_mem2Dint(p_Vid->p_decs->trans_err_bestY_mb);
    p_Vid->p_decs->trans_err_bestY_mb         = NULL;
  }
  if (p_Vid->p_decs->trans_err_bestY_b8x8)
  {
    free_mem3Dint(p_Vid->p_decs->trans_err_bestY_b8x8);
    p_Vid->p_decs->trans_err_bestY_b8x8         = NULL;
  }
  if (p_Vid->p_decs->trans_err_wo_res)
  {
    free_mem2Dint(p_Vid->p_decs->trans_err_wo_res);
    p_Vid->p_decs->trans_err_wo_res         = NULL;   //it is used for P8x8, where residual may be set to 0
  }
  if (p_Vid->p_decs->trans_err_wo_res_bestY_b8x8)
  {   
    free_mem3Dint(p_Vid->p_decs->trans_err_wo_res_bestY_b8x8);
    p_Vid->p_decs->trans_err_wo_res_bestY_b8x8   = NULL;   //it is used for P8x8, where residual may be set to 0
  }

  //for LLN
  if (p_Vid->p_decs->dec_mb_pred)
  {
    free_mem3Dpel(p_Vid->p_decs->dec_mb_pred);
    p_Vid->p_decs->dec_mb_pred         = NULL;
  }
  if (p_Vid->p_decs->dec_mbY_best)
  {
    free_mem3Dpel(p_Vid->p_decs->dec_mbY_best);
    p_Vid->p_decs->dec_mbY_best        = NULL;
  }
  if (p_Vid->p_decs->dec_mbY_best8x8)
  {   
    free_mem4Dpel(p_Vid->p_decs->dec_mbY_best8x8);
    p_Vid->p_decs->dec_mb_pred_best8x8 = NULL;
  }
  if (p_Vid->p_decs->dec_mb_pred_best8x8)
  {
    free_mem4Dpel(p_Vid->p_decs->dec_mb_pred_best8x8);
    p_Vid->p_decs->dec_mbY_best8x8     = NULL;
  }

  //for ROPE
  if (p_Vid->p_decs->first_moment_bestY_mb)
  {
    free_mem2Dpel(p_Vid->p_decs->first_moment_bestY_mb);
    p_Vid->p_decs->first_moment_bestY_mb         = NULL;
  }
  if (p_Vid->p_decs->first_moment_bestY_b8x8)
  {
    free_mem3Dpel(p_Vid->p_decs->first_moment_bestY_b8x8);
    p_Vid->p_decs->first_moment_bestY_b8x8       = NULL;
  }
  if (p_Vid->p_decs->first_moment_pred_bestY_b8x8)
  {
    free_mem3Dpel(p_Vid->p_decs->first_moment_pred_bestY_b8x8);
    p_Vid->p_decs->first_moment_pred_bestY_b8x8       = NULL;
  }
  if (p_Vid->p_decs->first_moment_pred)
  {
    free_mem2Dpel(p_Vid->p_decs->first_moment_pred);
    p_Vid->p_decs->first_moment_pred       = NULL;
  }
  if (p_Vid->p_decs->second_moment_bestY_mb)
  {
    free_mem2Duint16(p_Vid->p_decs->second_moment_bestY_mb);
    p_Vid->p_decs->second_moment_bestY_mb        = NULL;
  }
  if (p_Vid->p_decs->second_moment_bestY_b8x8)
  {
    free_mem3Duint16(p_Vid->p_decs->second_moment_bestY_b8x8);
    p_Vid->p_decs->second_moment_bestY_b8x8      = NULL;
  }
  if (p_Vid->p_decs->second_moment_pred_bestY_b8x8)
  {
    free_mem3Duint16(p_Vid->p_decs->second_moment_pred_bestY_b8x8);
    p_Vid->p_decs->second_moment_pred_bestY_b8x8      = NULL;
  }
  if (p_Vid->p_decs->second_moment_pred)
  {
    free_mem2Duint16(p_Vid->p_decs->second_moment_pred);
    p_Vid->p_decs->second_moment_pred      = NULL;
  }


  if ( p_Vid->p_decs != NULL )
  {
    free( p_Vid->p_decs );
    p_Vid->p_decs = NULL;
  }
}
Example #6
0
/*!
 *************************************************************************************
 * \brief
 *    free storable picture memory for errdo
 *
 *************************************************************************************
 */
void errdo_free_storable_picture(StorablePicture* s)
{
  int nplane;
  Dist_Estm *p = s->de_mem;
  //free memory for RMPC and extended RMPC algorithms
  if (p->res_con_diff_Y)
  {
    free_mem2Dint(p->res_con_diff_Y);
    p->res_con_diff_Y   = NULL;
  }
  if (p->res_con_diff_UV)
  {
    free_mem3Dint(p->res_con_diff_UV);
    p->res_con_diff_UV   = NULL;
  }
  for (nplane = 0; nplane < 3; nplane++)
  {
    p->p_res_con_diff[nplane] = NULL;
  }

  if (p->MV_con_diff_Y)
  {
    free_mem2Dint(p->MV_con_diff_Y);
    p->MV_con_diff_Y   = NULL;
  }
  if (p->MV_con_diff_UV)
  {
    free_mem3Dint(p->MV_con_diff_UV);
    p->MV_con_diff_UV   = NULL;
  }
  for (nplane = 0; nplane < 3; nplane++)
  {
    p->p_MV_con_diff[nplane] = NULL;
  }

  if (p->error_sign_flag_Y)
  {
    free_mem2D(p->error_sign_flag_Y);
    p->error_sign_flag_Y   = NULL;
  } 
  if (p->error_sign_flag_UV)
  {
    free_mem3D(p->error_sign_flag_UV);
    p->error_sign_flag_UV   = NULL;
  }
  for (nplane = 0; nplane < 3; nplane++)
  {
    p->p_error_sign_flag[nplane] = NULL;
  }

  if (p->transmission_dist_Y)
  {
    free_mem2Dint(p->transmission_dist_Y);
    p->transmission_dist_Y   = NULL;
  }
  if (p->transmission_dist_UV)
  {
    free_mem3Dint(p->transmission_dist_UV);
    p->transmission_dist_UV   = NULL;
  }
  for (nplane = 0; nplane < 3; nplane++)
  {
    p->p_transmission_dist[nplane] = NULL;
  }

  if (p->transmission_err_Y)
  {
    free_mem2Dint(p->transmission_err_Y);
    p->transmission_err_Y   = NULL;
  }
  if (p->transmission_err_UV)
  {
    free_mem3Dint(p->transmission_err_UV);
    p->transmission_err_UV   = NULL;
  }
  for (nplane = 0; nplane < 3; nplane++)
  {
    p->p_transmission_err[nplane] = NULL;
  }

  //free memory for LLN and Faster LLN algorithms
  if (p->dec_imgY)
  {
    free_mem3Dpel(p->dec_imgY);
    p->dec_imgY   = NULL;
  }
  if (p->dec_imgUV)
  {
    free_mem4Dpel(p->dec_imgUV);
    p->dec_imgUV  = NULL;
  }
  for (nplane = 0; nplane < 3; nplane++)
  {
    if (p->p_dec_img[nplane])
    {  
      free(p->p_dec_img[nplane]);
      p->p_dec_img[nplane] = NULL;
    }
  }
  if (p->mb_error_map)
  {
    free_mem3D(p->mb_error_map);
    p->mb_error_map = NULL;
  }


  //free memory for ROPE and extended ROPE algorithms
  if (p->first_moment_Y)
  {
    free_mem2Dpel(p->first_moment_Y);
    p->first_moment_Y   = NULL;
  }
  if (p->first_moment_UV)
  {
    free_mem3Dpel(p->first_moment_UV);
    p->first_moment_UV  = NULL;
  }
  for (nplane = 0; nplane < 3; nplane++)
  {
    p->p_first_moment[nplane] = NULL;
  }
  if (p->second_moment_Y)
  {
    free_mem2Duint16(p->second_moment_Y);
    p->second_moment_Y   = NULL;
  }
  if (p->second_moment_UV)
  {
    free_mem3Duint16(p->second_moment_UV);
    p->second_moment_UV  = NULL;
  }
  for (nplane = 0; nplane < 3; nplane++)
  {
    p->p_second_moment[nplane] = NULL;
  }

  if (s->de_mem)
  {
    free(s->de_mem);
    s->de_mem   = NULL;
  }
}