コード例 #1
0
ファイル: SEIwrite.cpp プロジェクト: ArineYao/openHEVC
Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei)
{
  Int i, nalOrVcl;
  TComVUI *vui = sei.m_sps->getVuiParameters();
  WRITE_UVLC( sei.m_seqParameterSetId, "seq_parameter_set_id" );
  if( !vui->getSubPicCpbParamsPresentFlag() )
  {
    WRITE_FLAG( sei.m_altCpbParamsPresentFlag, "alt_cpb_params_present_flag" );
  }
  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
  {
    if( ( ( nalOrVcl == 0 ) && ( vui->getNalHrdParametersPresentFlag() ) ) ||
        ( ( nalOrVcl == 1 ) && ( vui->getVclHrdParametersPresentFlag() ) ) )
    {
      for( i = 0; i < ( vui->getCpbCntMinus1( 0 ) + 1 ); i ++ )
      {
        WRITE_CODE( sei.m_initialCpbRemovalDelay[i][nalOrVcl],( vui->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,           "initial_cpb_removal_delay" );
        WRITE_CODE( sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl],( vui->getInitialCpbRemovalDelayLengthMinus1() + 1 ),      "initial_cpb_removal_delay_offset" );
        if( vui->getSubPicCpbParamsPresentFlag() || sei.m_altCpbParamsPresentFlag )
        {
          WRITE_CODE( sei.m_initialAltCpbRemovalDelay[i][nalOrVcl], ( vui->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,     "initial_alt_cpb_removal_delay" );
          WRITE_CODE( sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl], ( vui->getInitialCpbRemovalDelayLengthMinus1() + 1 ),"initial_alt_cpb_removal_delay_offset" );
        }
      }
    }
  }
  xWriteByteAlign();
}
コード例 #2
0
ファイル: SEIwrite.cpp プロジェクト: ArineYao/openHEVC
/**
 * marshal a decoded picture hash SEI message, storing the marshalled
 * representation in bitstream bs.
 */
Void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
{
  UInt val;

  WRITE_CODE(sei.method, 8, "hash_type");

  for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++)
  {
    if(sei.method == SEIDecodedPictureHash::MD5)
    {
      for (UInt i = 0; i < 16; i++)
      {
        WRITE_CODE(sei.digest[yuvIdx][i], 8, "picture_md5");
      }
    }
    else if(sei.method == SEIDecodedPictureHash::CRC)
    {
      val = (sei.digest[yuvIdx][0] << 8)  + sei.digest[yuvIdx][1];
      WRITE_CODE(val, 16, "picture_crc");
    }
    else if(sei.method == SEIDecodedPictureHash::CHECKSUM)
    {
      val = (sei.digest[yuvIdx][0] << 24)  + (sei.digest[yuvIdx][1] << 16) + (sei.digest[yuvIdx][2] << 8) + sei.digest[yuvIdx][3];
      WRITE_CODE(val, 32, "picture_checksum");
    }
  }
}
コード例 #3
0
ファイル: SEIwrite.cpp プロジェクト: ArineYao/openHEVC
Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei)
{
  Int i;
  TComVUI *vui = sei.m_sps->getVuiParameters();

  if( !vui->getNalHrdParametersPresentFlag() && !vui->getVclHrdParametersPresentFlag() )
    return;

  WRITE_CODE( sei.m_auCpbRemovalDelay, ( vui->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay" );
  WRITE_CODE( sei.m_picDpbOutputDelay, ( vui->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
  if( sei.m_sps->getVuiParameters()->getSubPicCpbParamsPresentFlag() )
  {
    WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
    WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
    if( sei.m_duCommonCpbRemovalDelayFlag )
    {
      WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( vui->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
    }
    else
    {
      for( i = 0; i < ( sei.m_numDecodingUnitsMinus1 + 1 ); i ++ )
      {
        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
        WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( vui->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
      }
    }
  }
  xWriteByteAlign();
}
コード例 #4
0
ファイル: SEIwrite.cpp プロジェクト: Kosyl/H265Lib
/**
 * marshal all SEI messages in provided list into one bitstream bs
 */
Void SEIWriter::writeSEImessages(TComBitIf& bs, const SEIMessages &seiList, const TComSPS *sps, Bool isNested)
{
#if ENC_DEC_TRACE
  if (g_HLSTraceEnable)
    xTraceSEIHeader();
#endif

  TComBitCounter bs_count;

  for (SEIMessages::const_iterator sei=seiList.begin(); sei!=seiList.end(); sei++)
  {
    // calculate how large the payload data is
    // TODO: this would be far nicer if it used vectored buffers
    bs_count.resetBits();
    setBitstream(&bs_count);

#if ENC_DEC_TRACE
    Bool traceEnable = g_HLSTraceEnable;
    g_HLSTraceEnable = false;
#endif
    xWriteSEIpayloadData(bs_count, **sei, sps);
#if ENC_DEC_TRACE
    g_HLSTraceEnable = traceEnable;
#endif
    UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
    assert(0 == payload_data_num_bits % 8);

    setBitstream(&bs);
    UInt payloadType = (*sei)->payloadType();
    for (; payloadType >= 0xff; payloadType -= 0xff)
    {
      WRITE_CODE(0xff, 8, "payload_type");
    }
    WRITE_CODE(payloadType, 8, "payload_type");

    UInt payloadSize = payload_data_num_bits/8;
    for (; payloadSize >= 0xff; payloadSize -= 0xff)
    {
      WRITE_CODE(0xff, 8, "payload_size");
    }
    WRITE_CODE(payloadSize, 8, "payload_size");

    /* payloadData */
#if ENC_DEC_TRACE
    if (g_HLSTraceEnable)
      xTraceSEIMessageType((*sei)->payloadType());
#endif

    xWriteSEIpayloadData(bs, **sei, sps);
  }
  if (!isNested)
  {
    xWriteRbspTrailingBits();
  }
}
コード例 #5
0
ファイル: SEIwrite.cpp プロジェクト: leobsoares/HM-16.0
/**
 * marshal a user_data_unregistered SEI message sei, storing the marshalled
 * representation in bitstream bs.
 */
Void SEIWriter::xWriteSEIuserDataUnregistered(const SEIuserDataUnregistered &sei)
{
  for (UInt i = 0; i < ISO_IEC_11578_LEN; i++)
  {
    WRITE_CODE(sei.uuid_iso_iec_11578[i], 8 , "sei.uuid_iso_iec_11578[i]");
  }

  for (UInt i = 0; i < sei.userDataLength; i++)
  {
    WRITE_CODE(sei.userData[i], 8 , "user_data");
  }
}
コード例 #6
0
ファイル: SEIwrite.cpp プロジェクト: leobsoares/HM-16.0
/**
 * marshal a single SEI message sei, storing the marshalled representation
 * in bitstream bs.
 */
Void SEIWriter::writeSEImessage(TComBitIf& bs, const SEI& sei, TComSPS *sps)
{
  /* calculate how large the payload data is */
  /* TODO: this would be far nicer if it used vectored buffers */
  TComBitCounter bs_count;
  bs_count.resetBits();
  setBitstream(&bs_count);


#if ENC_DEC_TRACE
  Bool traceEnable = g_HLSTraceEnable;
  g_HLSTraceEnable = false;
#endif
  xWriteSEIpayloadData(bs_count, sei, sps);
#if ENC_DEC_TRACE
  g_HLSTraceEnable = traceEnable;
#endif

  UInt payload_data_num_bits = bs_count.getNumberOfWrittenBits();
  assert(0 == payload_data_num_bits % 8);

  setBitstream(&bs);

#if ENC_DEC_TRACE
  if (g_HLSTraceEnable)
  xTraceSEIHeader();
#endif

  UInt payloadType = sei.payloadType();
  for (; payloadType >= 0xff; payloadType -= 0xff)
  {
    WRITE_CODE(0xff, 8, "payload_type");
  }
  WRITE_CODE(payloadType, 8, "payload_type");

  UInt payloadSize = payload_data_num_bits/8;
  for (; payloadSize >= 0xff; payloadSize -= 0xff)
  {
    WRITE_CODE(0xff, 8, "payload_size");
  }
  WRITE_CODE(payloadSize, 8, "payload_size");

  /* payloadData */
#if ENC_DEC_TRACE
  if (g_HLSTraceEnable)
  xTraceSEIMessageType(sei.payloadType());
#endif

  xWriteSEIpayloadData(bs, sei, sps);
}
コード例 #7
0
ファイル: SEIwrite.cpp プロジェクト: GregDobby/16.4pgr
Void SEIWriter::xWriteSEIDecodingUnitInfo(const SEIDecodingUnitInfo& sei, const TComSPS *sps)
{
  const TComVUI *vui = sps->getVuiParameters();
  WRITE_UVLC(sei.m_decodingUnitIdx, "decoding_unit_idx");
  if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag())
  {
    WRITE_CODE( sei.m_duSptCpbRemovalDelay, (vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1), "du_spt_cpb_removal_delay");
  }
  WRITE_FLAG( sei.m_dpbOutputDuDelayPresentFlag, "dpb_output_du_delay_present_flag");
  if(sei.m_dpbOutputDuDelayPresentFlag)
  {
    WRITE_CODE(sei.m_picSptDpbOutputDuDelay, vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, "pic_spt_dpb_output_du_delay");
  }
}
コード例 #8
0
ファイル: SEIwrite.cpp プロジェクト: fsq120/HM
Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
{
  WRITE_CODE(sei.activeVPSId,     4, "active_vps_id");
#if L0047_APS_FLAGS
  WRITE_FLAG(sei.m_fullRandomAccessFlag, "full_random_access_flag");
  WRITE_FLAG(sei.m_noParamSetUpdateFlag, "no_param_set_update_flag");
#endif
  WRITE_UVLC(sei.numSpsIdsMinus1,    "num_sps_ids_minus1");

  assert (sei.activeSeqParamSetId.size() == (sei.numSpsIdsMinus1 + 1));

  for (Int i = 0; i < sei.activeSeqParamSetId.size(); i++)
  {
    WRITE_UVLC(sei.activeSeqParamSetId[i], "active_seq_param_set_id"); 
  }

  UInt uiBits = m_pcBitIf->getNumberOfWrittenBits();
  UInt uiAlignedBits = ( 8 - (uiBits&7) ) % 8;  
  if(uiAlignedBits) 
  {
    WRITE_FLAG(1, "alignment_bit" );
    uiAlignedBits--; 
    while(uiAlignedBits--)
    {
      WRITE_FLAG(0, "alignment_bit" );
    }
  }
}
コード例 #9
0
ファイル: SEIwrite.cpp プロジェクト: fsq120/HM
Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei,  TComSPS *sps)
{
  Int i;
  TComVUI *vui = sps->getVuiParameters();
  TComHRD *hrd = vui->getHrdParameters();

#if !L0045_CONDITION_SIGNALLING
  // This condition was probably OK before the pic_struct, progressive_source_idc, duplicate_flag were added
  if( !hrd->getNalHrdParametersPresentFlag() && !hrd->getVclHrdParametersPresentFlag() )
    return;
#endif
  if( vui->getFrameFieldInfoPresentFlag() )
  {
    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
#if L0046_RENAME_PROG_SRC_IDC
    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
#else
    WRITE_CODE( sei.m_progressiveSourceIdc, 2,   "progressive_source_idc" );
#endif
    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
  }

#if L0045_CONDITION_SIGNALLING
  if( hrd->getCpbDpbDelaysPresentFlag() )
  {
#endif
    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
#if L0044_DU_DPB_OUTPUT_DELAY_HRD
    if(hrd->getSubPicCpbParamsPresentFlag())
    {
      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
    }
#endif
    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
    {
      WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
      WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
      if( sei.m_duCommonCpbRemovalDelayFlag )
      {
        WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
      }
      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
      {
        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
        {
          WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
        }
      }
    }
#if L0045_CONDITION_SIGNALLING
  }
#endif
  xWriteByteAlign();
}
コード例 #10
0
ファイル: SEIwrite.cpp プロジェクト: leobsoares/HM-16.0
Void SEIWriter::xWriteSEIFramePacking(const SEIFramePacking& sei)
{
  WRITE_UVLC( sei.m_arrangementId,                  "frame_packing_arrangement_id" );
  WRITE_FLAG( sei.m_arrangementCancelFlag,          "frame_packing_arrangement_cancel_flag" );

  if( sei.m_arrangementCancelFlag == 0 ) {
    WRITE_CODE( sei.m_arrangementType, 7,           "frame_packing_arrangement_type" );

    WRITE_FLAG( sei.m_quincunxSamplingFlag,         "quincunx_sampling_flag" );
    WRITE_CODE( sei.m_contentInterpretationType, 6, "content_interpretation_type" );
    WRITE_FLAG( sei.m_spatialFlippingFlag,          "spatial_flipping_flag" );
    WRITE_FLAG( sei.m_frame0FlippedFlag,            "frame0_flipped_flag" );
    WRITE_FLAG( sei.m_fieldViewsFlag,               "field_views_flag" );
    WRITE_FLAG( sei.m_currentFrameIsFrame0Flag,     "current_frame_is_frame0_flag" );

    WRITE_FLAG( sei.m_frame0SelfContainedFlag,      "frame0_self_contained_flag" );
    WRITE_FLAG( sei.m_frame1SelfContainedFlag,      "frame1_self_contained_flag" );

    if(sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5)
    {
      WRITE_CODE( sei.m_frame0GridPositionX, 4,     "frame0_grid_position_x" );
      WRITE_CODE( sei.m_frame0GridPositionY, 4,     "frame0_grid_position_y" );
      WRITE_CODE( sei.m_frame1GridPositionX, 4,     "frame1_grid_position_x" );
      WRITE_CODE( sei.m_frame1GridPositionY, 4,     "frame1_grid_position_y" );
    }

    WRITE_CODE( sei.m_arrangementReservedByte, 8,   "frame_packing_arrangement_reserved_byte" );
    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "frame_packing_arrangement_persistence_flag" );
  }

  WRITE_FLAG( sei.m_upsampledAspectRatio,           "upsampled_aspect_ratio" );

  xWriteByteAlign();
}
コード例 #11
0
ファイル: SEIwrite.cpp プロジェクト: GregDobby/16.4pgr
Void SEIWriter::xWriteSEISegmentedRectFramePacking(const SEISegmentedRectFramePacking& sei)
{
  WRITE_FLAG( sei.m_arrangementCancelFlag,          "segmented_rect_frame_packing_arrangement_cancel_flag" );
  if( sei.m_arrangementCancelFlag == 0 ) 
  {
    WRITE_CODE( sei.m_contentInterpretationType, 2, "segmented_rect_content_interpretation_type" );
    WRITE_FLAG( sei.m_arrangementPersistenceFlag,   "segmented_rect_frame_packing_arrangement_persistence" );
  }
}
コード例 #12
0
ファイル: SEIwrite.cpp プロジェクト: leobsoares/HM-16.0
/**
 * marshal a decoded picture hash SEI message, storing the marshalled
 * representation in bitstream bs.
 */
Void SEIWriter::xWriteSEIDecodedPictureHash(const SEIDecodedPictureHash& sei)
{
  const Char *traceString="\0";
  switch (sei.method)
  {
    case SEIDecodedPictureHash::MD5: traceString="picture_md5"; break;
    case SEIDecodedPictureHash::CRC: traceString="picture_crc"; break;
    case SEIDecodedPictureHash::CHECKSUM: traceString="picture_checksum"; break;
    default: assert(false); break;
  }

  if (traceString != 0) //use of this variable is needed to avoid a compiler error with G++ 4.6.1
  {
    WRITE_CODE(sei.method, 8, "hash_type");
    for(UInt i=0; i<UInt(sei.m_digest.hash.size()); i++)
    {
      WRITE_CODE(sei.m_digest.hash[i], 8, traceString);
    }
  }
}
コード例 #13
0
ファイル: SEIwrite.cpp プロジェクト: GregDobby/16.4pgr
Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
{
  WRITE_CODE(sei.activeVPSId,     4,         "active_video_parameter_set_id");
  WRITE_FLAG(sei.m_selfContainedCvsFlag,     "self_contained_cvs_flag");
  WRITE_FLAG(sei.m_noParameterSetUpdateFlag, "no_parameter_set_update_flag");
  WRITE_UVLC(sei.numSpsIdsMinus1,            "num_sps_ids_minus1");

  assert (sei.activeSeqParameterSetId.size() == (sei.numSpsIdsMinus1 + 1));

  for (Int i = 0; i < sei.activeSeqParameterSetId.size(); i++)
  {
    WRITE_UVLC(sei.activeSeqParameterSetId[i], "active_seq_parameter_set_id"); 
  }
}
コード例 #14
0
ファイル: SEIwrite.cpp プロジェクト: ArineYao/openHEVC
Void SEIWriter::xWriteSEIActiveParameterSets(const SEIActiveParameterSets& sei)
{
  WRITE_CODE(sei.activeVPSId, 4, "active_vps_id");
  WRITE_CODE(sei.activeSPSIdPresentFlag, 1, "active_sps_id_present_flag");

  if (sei.activeSPSIdPresentFlag) 
  {
    WRITE_UVLC(sei.activeSeqParamSetId, "active_seq_param_set_id"); 
  }

  WRITE_CODE(sei.activeParamSetSEIExtensionFlag, 1, "active_param_set_sei_extension_flag"); 

  UInt uiBits = m_pcBitIf->getNumberOfWrittenBits();
  UInt uiAlignedBits = ( 8 - (uiBits&7) ) % 8;  
  if(uiAlignedBits) 
  {
    WRITE_FLAG(1, "alignment_bit" );
    uiAlignedBits--; 
    while(uiAlignedBits--)
    {
      WRITE_FLAG(0, "alignment_bit" );
    }
  }
}
コード例 #15
0
ファイル: SEIwrite.cpp プロジェクト: fsq120/HM
Void SEIWriter::xWriteSEIDisplayOrientation(const SEIDisplayOrientation &sei)
{
  WRITE_FLAG( sei.cancelFlag,           "display_orientation_cancel_flag" );
  if( !sei.cancelFlag )
  {
    WRITE_FLAG( sei.horFlip,                   "hor_flip" );
    WRITE_FLAG( sei.verFlip,                   "ver_flip" );
    WRITE_CODE( sei.anticlockwiseRotation, 16, "anticlockwise_rotation" );
#if L0045_PERSISTENCE_FLAGS
    WRITE_FLAG( sei.persistenceFlag,          "display_orientation_persistence_flag" );
#else
    WRITE_UVLC( sei.repetitionPeriod,          "display_orientation_repetition_period" );
#endif
#if !REMOVE_SINGLE_SEI_EXTENSION_FLAGS
    WRITE_FLAG( sei.extensionFlag,             "display_orientation_extension_flag" );
    assert( !sei.extensionFlag );
#endif
  }
  xWriteByteAlign();
}
コード例 #16
0
ファイル: SEIwrite.cpp プロジェクト: leobsoares/HM-16.0
Void SEIWriter::xWriteSEIPictureTiming(const SEIPictureTiming& sei,  TComSPS *sps)
{
  Int i;
  TComVUI *vui = sps->getVuiParameters();
  TComHRD *hrd = vui->getHrdParameters();

  if( vui->getFrameFieldInfoPresentFlag() )
  {
    WRITE_CODE( sei.m_picStruct, 4,              "pic_struct" );
    WRITE_CODE( sei.m_sourceScanType, 2,         "source_scan_type" );
    WRITE_FLAG( sei.m_duplicateFlag ? 1 : 0,     "duplicate_flag" );
  }

  if( hrd->getCpbDpbDelaysPresentFlag() )
  {
    WRITE_CODE( sei.m_auCpbRemovalDelay - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ),                                         "au_cpb_removal_delay_minus1" );
    WRITE_CODE( sei.m_picDpbOutputDelay, ( hrd->getDpbOutputDelayLengthMinus1() + 1 ),                                          "pic_dpb_output_delay" );
    if(hrd->getSubPicCpbParamsPresentFlag())
    {
      WRITE_CODE(sei.m_picDpbOutputDuDelay, hrd->getDpbOutputDelayDuLengthMinus1()+1, "pic_dpb_output_du_delay" );
    }
    if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() )
    {
      WRITE_UVLC( sei.m_numDecodingUnitsMinus1,     "num_decoding_units_minus1" );
      WRITE_FLAG( sei.m_duCommonCpbRemovalDelayFlag, "du_common_cpb_removal_delay_flag" );
      if( sei.m_duCommonCpbRemovalDelayFlag )
      {
        WRITE_CODE( sei.m_duCommonCpbRemovalDelayMinus1, ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                       "du_common_cpb_removal_delay_minus1" );
      }
      for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ )
      {
        WRITE_UVLC( sei.m_numNalusInDuMinus1[ i ],  "num_nalus_in_du_minus1");
        if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) )
        {
          WRITE_CODE( sei.m_duCpbRemovalDelayMinus1[ i ], ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ),                        "du_cpb_removal_delay_minus1" );
        }
      }
    }
  }
  xWriteByteAlign();
}
コード例 #17
0
ファイル: SEIwrite.cpp プロジェクト: fsq120/HM
Void SEIWriter::xWriteSEIBufferingPeriod(const SEIBufferingPeriod& sei, TComSPS *sps)
{
  Int i, nalOrVcl;
  TComVUI *vui = sps->getVuiParameters();
  TComHRD *hrd = vui->getHrdParameters();

  WRITE_UVLC( sei.m_bpSeqParameterSetId, "bp_seq_parameter_set_id" );
  if( !hrd->getSubPicCpbParamsPresentFlag() )
  {
    WRITE_FLAG( sei.m_rapCpbParamsPresentFlag, "rap_cpb_params_present_flag" );
  }
#if L0328_SPLICING
  WRITE_FLAG( sei.m_concatenationFlag, "concatenation_flag");
  WRITE_CODE( sei.m_auCpbRemovalDelayDelta - 1, ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), "au_cpb_removal_delay_delta_minus1" );
#endif
#if L0044_CPB_DPB_DELAY_OFFSET
  if( sei.m_rapCpbParamsPresentFlag )
  {
    WRITE_CODE( sei.m_cpbDelayOffset, hrd->getCpbRemovalDelayLengthMinus1() + 1, "cpb_delay_offset" );
    WRITE_CODE( sei.m_dpbDelayOffset, hrd->getDpbOutputDelayLengthMinus1()  + 1, "dpb_delay_offset" );
  }
#endif
  for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ )
  {
    if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) ||
        ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) )
    {
      for( i = 0; i < ( hrd->getCpbCntMinus1( 0 ) + 1 ); i ++ )
      {
        WRITE_CODE( sei.m_initialCpbRemovalDelay[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,           "initial_cpb_removal_delay" );
        WRITE_CODE( sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl],( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),      "initial_cpb_removal_delay_offset" );
        if( hrd->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag )
        {
          WRITE_CODE( sei.m_initialAltCpbRemovalDelay[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ) ,     "initial_alt_cpb_removal_delay" );
          WRITE_CODE( sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl], ( hrd->getInitialCpbRemovalDelayLengthMinus1() + 1 ),"initial_alt_cpb_removal_delay_offset" );
        }
      }
    }
  }
  xWriteByteAlign();
}
コード例 #18
0
bool ImportScript( const char* szFileName )
{
	char* str;
	int len;
	SCRIPT_OP* op;
	DWORD* cp = &code[0];
	BOOL bResult = FALSE;
	int line = 1;


	void* file = ReadInTextFile( szFileName );
	if( file == NULL ) goto lbl_end;


	// destroy previous string table
	micro_alloc_destroy();


//////////////////////////////////////////////////////////////
/************************************************************/
/************************************************************/
/////////////// part 1: compile /////////////////////////////
		
	str = (char*)file;

	// start off with 2 NULL entries just like the game
	WRITE_CODE( 0 ); WRITE_CODE( 0 );

	while( *str != '\0' )
	{	
		// get command
		len = GetTok( str );
		if( len != 0 )
		{
			op = in_command_set( str, len );
			if( op == NULL )
			{
				darkomen::detour::trace( "WHMTG: line %d: Unknown command. %s", line, str );
				goto lbl_end;
			}

			if( op->address != 0 ) // if not label
			{
				WRITE_CODE( op->address );
			}
			str += len; 

			// do args
			int count = 0;
			while( len = GetTok( str ) ) // loop until end of line
			{
				if( count < op->arg_cnt )
				{
					switch( op->arg_type[count] )
					{
						case 1: // int
						{
							DWORD dw;
							if( !my_atoi( str, len, &dw ) )
							{
								darkomen::detour::trace("WHMTG: line %d: bad formatting, expected integer value. Arg# %d.", line, count + 1);
								goto lbl_end;
							}
							WRITE_CODE( dw );
							str += len;
							break;
						}
						case 2: // text
						{

							if( str[0] != '\"' ) 
							{
								darkomen::detour::trace("WHMTG: line %d: bad formatting, expected text value."
									" Text must be enclosed within double quote(\") characters. Arg# %d.", line, count + 1 );
								goto lbl_end;
							}

							// find ending quote
							if( str[ len-1 ] != '\"' )
							{
								while( ( str[len] != '\"' ) && ( str[len] != '\r' ) && ( str[len] != '\n' ) && ( str[len] != '\0' ) )
								{
									len++;
								}
								if( str[len] == '\"' ) len++;
								else
								{
									darkomen::detour::trace("WHMTG: line %d: bad formatting, expected text value."
											" Text must be enclosed within double quote(\") characters. Arg# %d.", line, count + 1 );
									goto lbl_end;
								}
							}

							char* text = (char*) micro_alloc( len-1 );
							if( text == NULL )
							{
								darkomen::detour::trace("WHMTG: Internal Error (script line %d): Failed to allocate %d bytes. Arg# %d.", line, len - 1, count + 1);
								goto lbl_end;
							}
							memcpy( text, &str[1], len-2 );
							WRITE_CODE( (uintptr_t)text );
							str += len;
							break;
						}
						case 3: // jmp
						{
							char* text = (char*) micro_alloc( len+1 );
							if( text == NULL )
							{
								darkomen::detour::trace("WHMTG: Internal Error (script line %d): Failed to allocate %d bytes. Arg# %d.", line, len + 1, count + 1);
								goto lbl_end;
							}
							LABEL_ENTRY* le = (LABEL_ENTRY*) micro_alloc( sizeof(LABEL_ENTRY) );
							if( le == NULL )
							{
								darkomen::detour::trace("WHMTG: Internal Error (script line %d): Failed to allocate %d bytes. Arg# %d.", line, sizeof(LABEL_ENTRY), count + 1);
								goto lbl_end;
							}
							memcpy( text, str, len );
							le->name_len = len;
							le->name = text;
							le->addr = cp;
							le->next = jmps;
							jmps = le;
							WRITE_CODE( (uintptr_t)le->name ); // place-holder
							str += len;
							break;
						}
						case 4: // var
						{
							DWORD dw;			
							if( ( len < 4 ) || ( str[0] != 'v' ) || ( str[1] != 'a' ) || ( str[2] != 'r' ) || ( str[3] != '_' ) )
							{
								darkomen::detour::trace("WHMTG: line %d: bad formatting, expected var_ keyword. Arg# %d.", line, count + 1);
								goto lbl_end;
							}
							if( !my_atoi( &str[4], len - 4, &dw ) )
							{
								darkomen::detour::trace("WHMTG: line %d: bad formatting, unrecognized var. Arg# %d.", line, count + 1);
								goto lbl_end;
							}
							if( dw > 23 ) 
							{
								darkomen::detour::trace("WHMTG: line %d: var index is outside of range. Arg# %d.", line, count + 1);
								goto lbl_end;
							}
							WRITE_CODE( ( var_base + dw * 4 ) );
							str += len;
							break;
						}
						case 5: // cmp
						{
							DWORD dw = -1;
							if( len == 2 )
							{
								if( str[1] == '=' )
								{
									switch( *str )
									{
										case '=':
											dw = 1; 
											break;
										case '/': // fall-thru
										case '!':
											dw = 2;
											break;
									}
								}
								else
								{
									if( ( str[0] == '<' ) && ( str[1] == '>' ) )
									{	
										dw = 2;
									}
								}
							}
							if( len == 1 )
							{
								switch( *str )
								{
									case '=':
										dw = 1;
										break;
									case '<':
										dw = 3;
										break;
									case '>':
										dw = 4;
										break;
								}
							}
							if( dw == -1 )
							{
								darkomen::detour::trace("WHMTG: line %d: bad formatting, unrecognized relationship/comparision operator. Arg# %d.", line, count);
								goto lbl_end;
							}
							WRITE_CODE( dw );
							str += len;
							break;
						}
						case 6: // var_arg ( WHMTG_Speak )
						{
							DWORD num_arg_groups = 0;
							DWORD i = 0;
							for(;;)
							{
								DWORD dw;
								if( !my_atoi( str, len, &dw ) )
								{
									darkomen::detour::trace("WHMTG: line %d: bad formatting, expected integer value. Arg# %d.", line, i);
									goto lbl_end;
								}
								if( i == 0 ) num_arg_groups = dw;
								WRITE_CODE( dw );
								str += len;
								i++;
								if( i >= ( 2 + num_arg_groups * 4 ) ) break; // exit loop

								// else get next arg
								len = GetTok( str );
								if( len == 0 )
								{
									darkomen::detour::trace("WHMTG: line %d: %s, expected %d arguments, found %d.", line, op->name, 2 + (num_arg_groups * 4), i);
									goto lbl_end;
								}
							}
							break;
						}
						case 7: // label
						{	
							char* text = (char*) micro_alloc( len+1 );
							if( text == NULL )
							{
								darkomen::detour::trace("WHMTG: Internal Error (script line %d): Failed to allocate %d bytes. Arg# %d.", line, len + 1, count);
								goto lbl_end;
							}
							LABEL_ENTRY* le = (LABEL_ENTRY*) micro_alloc( sizeof(LABEL_ENTRY) );
							if( le == NULL )
							{
								darkomen::detour::trace("WHMTG: Internal Error (script line %d): Failed to allocate %d bytes. Arg# %d.", line, sizeof(LABEL_ENTRY), count);
								goto lbl_end;
							}
							memcpy( text, str, len );

							// jmp targets are aligned to 8
							if( (DWORD)cp & 4 ) WRITE_CODE( 0 ); // pad as per the game

							le->name_len = len;
							le->name = text;
							le->addr = cp;
							le->next = targets;
							targets = le;
							str += len;
							break;
						}
						default:
						{
								   darkomen::detour::trace("WHMTG: Internal Error (script line %d): unknown arg type. Arg# %d.", line, count);
							goto lbl_end;
						}
					}
				}
				count++;
			}
			if( count != op->arg_cnt )
			{
				darkomen::detour::trace("WHMTG: line %d: %s, expected %d arguments, found %d.", line, op->name, op->arg_cnt, count);
				goto lbl_end;
			}
		}

		// next line
		if( *str == '\r' ) str++;
		if( *str == '\n' ) str++;
		line++;
	}

	if( cp >= &code[_countof(code) - 1] )
	{
		darkomen::detour::trace("WHMTG: Error: Byte-code exceeds maximum size of %d bytes.", sizeof(code));
		goto lbl_end;
	}

	// end with a NULL entry because that is what the game does
	WRITE_CODE( 0 );

	EP_EndScript = cp - 1;
	EP_StartScript = &code[0];

//////////////////////////////////////////////////////////////
/************************************************************/
/************************************************************/
/////////////// part 2: link  ////////////////////////////////


	// find the entry points
	EP_NewGame = NULL;
	EP_Tutorial = NULL;
	EP_TheLivingGem = NULL;
	EP_HandyMan = NULL;
	EP_RideTheSrorm = NULL;
	EP_YouAndI = NULL;
	for( LABEL_ENTRY* t = targets; t != NULL; t = t->next ) 
	{
		switch( t->name_len ) 
		{
			case 7:
				if( !memcmp( t->name, "NEWGAME", 7 ) ) EP_NewGame = t->addr;
				else if( !memcmp( t->name, "YOUANDI", 7 ) ) EP_YouAndI = t->addr;
				break;
			case 8:
				if( !memcmp( t->name, "TUTORIAL", 8 ) ) EP_Tutorial = t->addr;
				else if( !memcmp( t->name, "HANDYMAN", 8 ) ) EP_HandyMan = t->addr;
				break;
			case 12:
				if( !memcmp( t->name, "THELIVINGGEM", 12 ) ) EP_TheLivingGem = t->addr;
				else if( !memcmp( t->name, "RIDETHESTORM", 12 ) ) EP_RideTheSrorm = t->addr;
				break;
		}
	}
	if( EP_NewGame == NULL ) EP_NewGame = EP_StartScript;
	if( EP_Tutorial == NULL ) EP_Tutorial = EP_NewGame;
	if( EP_TheLivingGem == NULL ) EP_TheLivingGem = EP_NewGame;
	if( EP_HandyMan == NULL ) EP_HandyMan = EP_NewGame;
	if( EP_RideTheSrorm == NULL ) EP_RideTheSrorm = EP_NewGame;
	if( EP_YouAndI == NULL ) EP_YouAndI = EP_NewGame;


	// link jmps with targets
	for( LABEL_ENTRY* j = jmps; j != NULL; j = j->next )
	{
		LABEL_ENTRY* t;
		for( t = targets; t != NULL; t = t->next ) 
		{
			if( j->name_len == t->name_len )
			{
				if( !memcmp( j->name, t->name, t->name_len ) )
				{
					//OutputDebugString("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" );
					*j->addr = (DWORD)t->addr;
					break;
				}
			}
		}
		if( t == NULL )
		{
			darkomen::detour::trace("WHMTG: Error: LABEL %s not found.", j->name);
			goto lbl_end;
		}
	}


//////////////////////////////////////////////////////////////
/************************************************************/
/************************************************************/
/////////////// part 3: hook-in /////////////////////////////

	DWORD dwPrevProtect;

	// .text section
	if( VirtualProtect( (void*)0x0040E000, 0x1F000, PAGE_READWRITE, &dwPrevProtect ) )
	{
		*( (DWORD**)0x0040EFB4 ) = EP_StartScript;
		*( (DWORD**)0x0040EFCC ) = EP_EndScript;
		*( (DWORD**)0x0040EFAA ) = EP_StartScript;

		*( (DWORD**)0x00420F56 ) = EP_StartScript;
		*( (DWORD**)0x00420F8E ) = EP_EndScript;

		*( (DWORD**)0x00421B83 ) = EP_StartScript;
		*( (DWORD**)0x00421BC6 ) = EP_EndScript;

		*( (DWORD**)0x0042943F ) = EP_Tutorial;
		*( (DWORD**)0x0042C4F7 ) = EP_NewGame;

		VirtualProtect( (void*)0x0040E000, 0x1F000, dwPrevProtect, &dwPrevProtect );
	}

	// .data section
	*( (DWORD**)0x004D7134 ) = EP_TheLivingGem;
	*( (DWORD**)0x004D715C ) = EP_HandyMan;
	*( (DWORD**)0x004D7184 ) = EP_RideTheSrorm;
	*( (DWORD**)0x004D71AC ) = EP_YouAndI;

	bResult = TRUE;

	/*
		HANDLE hFile = CreateFile("dump.bin", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
		DWORD Written;
		WriteFile(hFile, code, sizeof( code ), &Written, NULL);
		CloseHandle(hFile);
	*/

lbl_end:
	if( file != NULL ) VirtualFree( file, 0, MEM_RELEASE );
	return !!bResult;
}
コード例 #19
0
ファイル: disasm.c プロジェクト: daniele-rapagnani/um-32
void write_source_code(Operation* op, FILE* output)
{
	switch(op->standard.number)
	{
		case 0:
			WRITE_CODE(op, "cmove", output);
			break;

		case 1:
			WRITE_CODE(op, "get", output);
			break;

		case 2:
			WRITE_CODE(op, "set", output);
			break;

		case 3:
			WRITE_CODE(op, "add", output);
			break;

		case 4:
			WRITE_CODE(op, "mult", output);
			break;

		case 5:
			WRITE_CODE(op, "div", output);
			break;

		case 6:
			WRITE_CODE(op, "nand", output);
			break;

		case 7:
			WRITE_CODE(op, "halt", output);
			break;

		case 8:
			WRITE_CODE(op, "allocate", output);
			break;

		case 9:
			WRITE_CODE(op, "free", output);
			break;

		case 10:
			WRITE_CODE(op, "out", output);
			break;

		case 11:
			WRITE_CODE(op, "in", output);
			break;

		case 12:
			WRITE_CODE(op, "load", output);
			break;

		case 13:
			WRITE_CODE_PUT(op, "put", output);
			break;

		default:
			fprintf(output, "# Wrong opcode detected: %d\n", op->standard.number);
			break;
	}
}
コード例 #20
0
ファイル: SEIwrite.cpp プロジェクト: leobsoares/HM-16.0
Void SEIWriter::xWriteSEIToneMappingInfo(const SEIToneMappingInfo& sei)
{
  Int i;
  WRITE_UVLC( sei.m_toneMapId,                    "tone_map_id" );
  WRITE_FLAG( sei.m_toneMapCancelFlag,            "tone_map_cancel_flag" );
  if( !sei.m_toneMapCancelFlag )
  {
    WRITE_FLAG( sei.m_toneMapPersistenceFlag,     "tone_map_persistence_flag" );
    WRITE_CODE( sei.m_codedDataBitDepth,    8,    "coded_data_bit_depth" );
    WRITE_CODE( sei.m_targetBitDepth,       8,    "target_bit_depth" );
    WRITE_UVLC( sei.m_modelId,                    "model_id" );
    switch(sei.m_modelId)
    {
    case 0:
      {
        WRITE_CODE( sei.m_minValue,  32,        "min_value" );
        WRITE_CODE( sei.m_maxValue, 32,         "max_value" );
        break;
      }
    case 1:
      {
        WRITE_CODE( sei.m_sigmoidMidpoint, 32,  "sigmoid_midpoint" );
        WRITE_CODE( sei.m_sigmoidWidth,    32,  "sigmoid_width"    );
        break;
      }
    case 2:
      {
        UInt num = 1u << sei.m_targetBitDepth;
        for(i = 0; i < num; i++)
        {
          WRITE_CODE( sei.m_startOfCodedInterval[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,  "start_of_coded_interval" );
        }
        break;
      }
    case 3:
      {
        WRITE_CODE( sei.m_numPivots, 16,          "num_pivots" );
        for(i = 0; i < sei.m_numPivots; i++ )
        {
          WRITE_CODE( sei.m_codedPivotValue[i], (( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3,       "coded_pivot_value" );
          WRITE_CODE( sei.m_targetPivotValue[i], (( sei.m_targetBitDepth + 7 ) >> 3 ) << 3,         "target_pivot_value");
        }
        break;
      }
    case 4:
      {
        WRITE_CODE( sei.m_cameraIsoSpeedIdc,    8,    "camera_iso_speed_idc" );
        if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO
        {
          WRITE_CODE( sei.m_cameraIsoSpeedValue,    32,    "camera_iso_speed_value" );
        }
        WRITE_CODE( sei.m_exposureIndexIdc,     8,    "exposure_index_idc" );
        if( sei.m_exposureIndexIdc == 255) //Extended_ISO
        {
          WRITE_CODE( sei.m_exposureIndexValue,     32,    "exposure_index_value" );
        }
        WRITE_FLAG( sei.m_exposureCompensationValueSignFlag,           "exposure_compensation_value_sign_flag" );
        WRITE_CODE( sei.m_exposureCompensationValueNumerator,     16,  "exposure_compensation_value_numerator" );
        WRITE_CODE( sei.m_exposureCompensationValueDenomIdc,      16,  "exposure_compensation_value_denom_idc" );
        WRITE_CODE( sei.m_refScreenLuminanceWhite,                32,  "ref_screen_luminance_white" );
        WRITE_CODE( sei.m_extendedRangeWhiteLevel,                32,  "extended_range_white_level" );
        WRITE_CODE( sei.m_nominalBlackLevelLumaCodeValue,         16,  "nominal_black_level_luma_code_value" );
        WRITE_CODE( sei.m_nominalWhiteLevelLumaCodeValue,         16,  "nominal_white_level_luma_code_value" );
        WRITE_CODE( sei.m_extendedWhiteLevelLumaCodeValue,        16,  "extended_white_level_luma_code_value" );
        break;
      }
    default:
      {
        assert(!"Undefined SEIToneMapModelId");
        break;
      }
    }//switch m_modelId
  }//if(!sei.m_toneMapCancelFlag)
コード例 #21
0
ファイル: SEIwrite.cpp プロジェクト: fsq120/HM
Void SEIWriter::xWriteSEITemporalLevel0Index(const SEITemporalLevel0Index &sei)
{
  WRITE_CODE( sei.tl0Idx, 8 , "tl0_idx" );
  WRITE_CODE( sei.rapIdx, 8 , "rap_idx" );
  xWriteByteAlign();
}