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

📄 output.c

📁 此code含H.264解码需要的 lib和 src
💻 C
📖 第 1 页 / 共 2 页
字号:
} 


//#endif

/*!
************************************************************************
* \brief
*    Writes out a storable picture
* \param p
*    Picture to be written
* \param p_out
*    Output file
************************************************************************
*/
// void write_out_picture(StorablePicture *p, int p_out)
// {
//   static int SubWidthC  [4]= { 1, 2, 2, 1};
//   static int SubHeightC [4]= { 1, 2, 1, 1};
// 
//   int crop_left, crop_right, crop_top, crop_bottom;
//   int symbol_size_in_bytes = (img->pic_unit_bitsize_on_disk >> 3);
//   Boolean rgb_output = (Boolean) (active_sps->vui_seq_parameters.matrix_coefficients==0);
//   unsigned char *buf;
// 
//   if (p->non_existing)
//     return;
// 
// #ifdef ENABLE_OUTPUT_TONEMAPPING
//   // note: this tone-mapping is working for RGB format only. Sharp
//   if (p->seiHasTone_mapping && rgb_output)
//   {
//     //printf("output frame %d with tone model id %d\n",  p->frame_num, p->tone_mapping_model_id);
//     symbol_size_in_bytes = (p->tonemapped_bit_depth>8)? 2 : 1;
//     tone_map(p->imgY, p->tone_mapping_lut, p->size_x, p->size_y);
//     tone_map(p->imgUV[0], p->tone_mapping_lut, p->size_x_cr, p->size_y_cr);
//     tone_map(p->imgUV[1], p->tone_mapping_lut, p->size_x_cr, p->size_y_cr);
//   }
// #endif
// 
//   if (p->frame_cropping_flag)
//   {
//     crop_left   = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_left_offset;
//     crop_right  = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_right_offset;
//     crop_top    = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset;
//     crop_bottom = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset;
//   }
//   else
//   {
//     crop_left = crop_right = crop_top = crop_bottom = 0;
//   }
// 
//   //printf ("write frame size: %dx%d\n", p->size_x-crop_left-crop_right,p->size_y-crop_top-crop_bottom );
// 
//   // KS: this buffer should actually be allocated only once, but this is still much faster than the previous version
//   buf = malloc (p->size_x*p->size_y*symbol_size_in_bytes);
//   if (NULL==buf)
//   {
//     no_mem_exit("write_out_picture: buf");
//   }
// 
//   if(rgb_output)
//   {
//     crop_left   = p->frame_cropping_rect_left_offset;
//     crop_right  = p->frame_cropping_rect_right_offset;
//     crop_top    = ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset;
//     crop_bottom = ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset;
// 
//     img2buf (p->imgUV[1], buf, p->size_x_cr, p->size_y_cr, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom);
//     write(p_out, buf, (p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)*symbol_size_in_bytes);
// 
//     if (p->frame_cropping_flag)
//     {
//       crop_left   = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_left_offset;
//       crop_right  = SubWidthC[p->chroma_format_idc] * p->frame_cropping_rect_right_offset;
//       crop_top    = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset;
//       crop_bottom = SubHeightC[p->chroma_format_idc]*( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset;
//     }
//     else
//     {
//       crop_left = crop_right = crop_top = crop_bottom = 0;
//     }
//   }
// 
//   img2buf (p->imgY, buf, p->size_x, p->size_y, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom);
//   write(p_out, buf, (p->size_y-crop_bottom-crop_top)*(p->size_x-crop_right-crop_left)*symbol_size_in_bytes);
// 
//   if (p->chroma_format_idc!=YUV400)
//   {
//     crop_left   = p->frame_cropping_rect_left_offset;
//     crop_right  = p->frame_cropping_rect_right_offset;
//     crop_top    = ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_top_offset;
//     crop_bottom = ( 2 - p->frame_mbs_only_flag ) * p->frame_cropping_rect_bottom_offset;
// 
//     img2buf (p->imgUV[0], buf, p->size_x_cr, p->size_y_cr, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom);
//     write(p_out, buf, (p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)* symbol_size_in_bytes);
// 
//     if (!rgb_output)
//     {
//       img2buf (p->imgUV[1], buf, p->size_x_cr, p->size_y_cr, symbol_size_in_bytes, crop_left, crop_right, crop_top, crop_bottom);
//       write(p_out, buf, (p->size_y_cr-crop_bottom-crop_top)*(p->size_x_cr-crop_right-crop_left)*symbol_size_in_bytes);
//     }
//   }
//   else
//   {
//     if (input->write_uv)
//     {
//       int i,j;
//       imgpel cr_val = (imgpel) (1<<(img->bitdepth_luma - 1));
// 
//       get_mem3Dpel (&(p->imgUV), 1, p->size_y/2, p->size_x/2);
//       for (j=0; j<p->size_y/2; j++)
//         for (i=0; i<p->size_x/2; i++)
//           p->imgUV[0][j][i]=cr_val;
// 
//       // fake out U=V=128 to make a YUV 4:2:0 stream
//       img2buf (p->imgUV[0], buf, p->size_x/2, p->size_y/2, symbol_size_in_bytes, crop_left/2, crop_right/2, crop_top/2, crop_bottom/2);
// 
//       write(p_out, buf, symbol_size_in_bytes * (p->size_y-crop_bottom-crop_top)/2 * (p->size_x-crop_right-crop_left)/2 );
//       write(p_out, buf, symbol_size_in_bytes * (p->size_y-crop_bottom-crop_top)/2 * (p->size_x-crop_right-crop_left)/2 );
// 
//       free_mem3Dpel(p->imgUV, 1);
//       p->imgUV=NULL;
//     }
//   }
// 
//   free(buf);
// 
// //  fsync(p_out);
// }

/*!
 ************************************************************************
 * \brief
 *    Initialize output buffer for direct output
 ************************************************************************
 */
// void init_out_buffer()
// {
//   out_buffer = alloc_frame_store();
// #ifdef PAIR_FIELDS_IN_OUTPUT
//   pending_output = calloc (sizeof(StorablePicture), 1);
//   if (NULL==pending_output) no_mem_exit("init_out_buffer");
//   pending_output->imgUV = NULL;
//   pending_output->imgY  = NULL;
// #endif
// }

/*!
 ************************************************************************
 * \brief
 *    Uninitialize output buffer for direct output
 ************************************************************************
 */
// void uninit_out_buffer()
// {
//   free_frame_store(out_buffer);
//   out_buffer=NULL;
// #ifdef PAIR_FIELDS_IN_OUTPUT
//   flush_pending_output(p_out);
//   free (pending_output);
// #endif
// }

/*!
 ************************************************************************
 * \brief
 *    Initialize picture memory with (Y:0,U:128,V:128)
 ************************************************************************
 */
//void clear_picture(StorablePicture *p)
//{
//  int i,j;
//
//  for(i=0;i<p->size_y;i++)
//  {
//    for (j=0; j<p->size_x; j++)
//      p->imgY[i][j] = (imgpel) img->dc_pred_value_luma;
//  }
//  for(i=0;i<p->size_y_cr;i++)
//  {
//    for (j=0; j<p->size_x_cr; j++)
//      p->imgUV[0][i][j] = (imgpel) img->dc_pred_value_chroma;
//  }
//  for(i=0;i<p->size_y_cr;i++)
//  {
//    for (j=0; j<p->size_x_cr; j++)
//      p->imgUV[1][i][j] = (imgpel) img->dc_pred_value_chroma;
//  }
//
//}

/*!
 ************************************************************************
 * \brief
 *    Write out not paired direct output fields. A second empty field is generated
 *    and combined into the frame buffer.
 * \param fs
 *    FrameStore that contains a single field
 * \param p_out
 *    Output file
 ************************************************************************
 */
void write_unpaired_field(FrameStore* fs/*, int p_out*/)
{
  StorablePicture *p;
  assert (fs->is_used<3);

  if(fs->is_used & 0x01)
  {
    // we have a top field
    // construct an empty bottom field
    p = fs->top_field;

    fs->bottom_field = alloc_storable_picture(BOTTOM_FIELD, p->size_x, 2*p->size_y, p->size_x_cr, 2*p->size_y_cr);	

    fs->bottom_field->chroma_format_idc = p->chroma_format_idc;
//    clear_picture(fs->bottom_field);
    dpb_combine_field_yuv(fs);

//    write_picture (fs->frame, /*p_out,*/ TOP_FIELD);
	write_picture (fs->top_field, TOP_FIELD);
  }

  if(fs->is_used & 0x02)
  {
    // we have a bottom field
    // construct an empty top field
    p = fs->bottom_field;

    fs->top_field = alloc_storable_picture(TOP_FIELD, p->size_x, 2*p->size_y, p->size_x_cr, 2*p->size_y_cr);	

    fs->top_field->chroma_format_idc = p->chroma_format_idc;
//    clear_picture(fs->top_field);
    fs ->top_field->frame_cropping_flag = fs->bottom_field->frame_cropping_flag;
    if(fs ->top_field->frame_cropping_flag)
    {
      fs ->top_field->frame_cropping_rect_top_offset = fs->bottom_field->frame_cropping_rect_top_offset;
      fs ->top_field->frame_cropping_rect_bottom_offset = fs->bottom_field->frame_cropping_rect_bottom_offset;
      fs ->top_field->frame_cropping_rect_left_offset = fs->bottom_field->frame_cropping_rect_left_offset;
      fs ->top_field->frame_cropping_rect_right_offset = fs->bottom_field->frame_cropping_rect_right_offset;
    }
    dpb_combine_field_yuv(fs);

//    write_picture (fs->frame, /*p_out,*/ BOTTOM_FIELD);
    write_picture (fs->bottom_field, BOTTOM_FIELD);
  }

  fs->is_used = 3;
}

/*!
 ************************************************************************
 * \brief
 *    Write out unpaired fields from output buffer.
 * \param p_out
 *    Output file
 ************************************************************************
 */
// void flush_direct_output(int p_out)
// {
//   write_unpaired_field(out_buffer, p_out);
// 
//   free_storable_picture(out_buffer->frame);
//   out_buffer->frame = NULL;
//   free_storable_picture(out_buffer->top_field);
//   out_buffer->top_field = NULL;
//   free_storable_picture(out_buffer->bottom_field);
//   out_buffer->bottom_field = NULL;
//   out_buffer->is_used = 0;
// }


/*!
 ************************************************************************
 * \brief
 *    Write a frame (from FrameStore)
 * \param fs
 *    FrameStore containing the frame
 * \param p_out
 *    Output file
 ************************************************************************
 */
void write_stored_frame( FrameStore *fs/*, int p_out*/)
{
  // make sure no direct output field is pending
//  flush_direct_output(p_out);

  if (fs->is_used<3)
  {
    write_unpaired_field(fs/*, p_out*/);
  }
  else
  {
    if (fs->recovery_frame)
      recovery_flag = 1;
    if ((!non_conforming_stream) || recovery_flag)
      write_picture(fs->frame, /*p_out,*/ FRAME);
  }

  fs->is_output = 1;
}

/*!
 ************************************************************************
 * \brief
 *    Directly output a picture without storing it in the DPB. Fields
 *    are buffered before they are written to the file.
 * \param p
 *    Picture for output
 * \param p_out
 *    Output file
 ************************************************************************
 */
// void direct_output(StorablePicture *p, int p_out)
// {
//   if (p->structure==FRAME)
//   {
//     // we have a frame (or complementary field pair)
//     // so output it directly
//     flush_direct_output(p_out);
//     write_picture (p, p_out, FRAME);
//     if (-1!=p_ref && !input->silent)
//       find_snr(snr, p, p_ref);
//     free_storable_picture(p);
//     return;
//   }
// 
//   if (p->structure == TOP_FIELD)
//   {
//     if (out_buffer->is_used &1)
//       flush_direct_output(p_out);
//     out_buffer->top_field = p;
//     out_buffer->is_used |= 1;
//   }
// 
//   if (p->structure == BOTTOM_FIELD)
//   {
//     if (out_buffer->is_used &2)
//       flush_direct_output(p_out);
//     out_buffer->bottom_field = p;
//     out_buffer->is_used |= 2;
//   }
// 
//   if (out_buffer->is_used == 3)
//   {
//     // we have both fields, so output them
//     dpb_combine_field_yuv(out_buffer);
//     write_picture (out_buffer->frame, p_out, FRAME);
// 
//     if (-1!=p_ref && !input->silent)
//       find_snr(snr, out_buffer->frame, p_ref);
//     free_storable_picture(out_buffer->frame);
//     out_buffer->frame = NULL;
//     free_storable_picture(out_buffer->top_field);
//     out_buffer->top_field = NULL;
//     free_storable_picture(out_buffer->bottom_field);
//     out_buffer->bottom_field = NULL;
//     out_buffer->is_used = 0;
//   }
// }

/*!
 ************************************************************************
 * \brief
 *    Directly output a picture without storing it in the DPB. Fields
 *    are NOT buffered before they are written to the file. 
 * \param p
 *    Picture for output
 * \param p_out
 *    Output file
 ************************************************************************
 */
void direct_output(StorablePicture *p/*, int p_out*/)
{
  write_picture (p, /*p_out,*/ p->structure);
  free_storable_picture(p);
  return;
}

⌨️ 快捷键说明

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