Changeset 540 in SHVCSoftware for trunk/source/Lib/TLibEncoder


Ignore:
Timestamp:
9 Jan 2014, 05:04:17 (11 years ago)
Author:
seregin
Message:

merge SHM-4.1-dev branch

Location:
trunk
Files:
24 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/source

  • trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp

    r442 r540  
    5858
    5959TEncAnalyze             m_gcAnalyzeAll_in;
     60
    6061//! \}
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.h

    r442 r540  
    160160  }
    161161 
     162 
    162163  Void    printSummary(Char ch)
    163164  {
     
    207208
    208209extern TEncAnalyze             m_gcAnalyzeAll_in;
     210
    209211//! \}
    210212
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r494 r540  
    220220    }
    221221  }
     222
     223#if SCALINGLIST_INFERRING
     224  if( pcPPS->getLayerId() > 0 )
     225  {
     226    WRITE_FLAG( pcPPS->getInferScalingListFlag() ? 1 : 0, "pps_infer_scaling_list_flag" );
     227  }
     228
     229  if( pcPPS->getInferScalingListFlag() )
     230  {
     231    // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     232    assert( pcPPS->getScalingListRefLayerId() <= 62 );
     233
     234    WRITE_UVLC( pcPPS->getScalingListRefLayerId(), "pps_scaling_list_ref_layer_id" );
     235  }
     236  else
     237  {
     238#endif
     239
    222240  WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" );
    223 
    224 #if IL_SL_SIGNALLING_N0371
    225   pcPPS->setPPS( pcPPS->getLayerId(), pcPPS ); 
    226 #endif
    227 
    228241  if( pcPPS->getScalingListPresentFlag() )
    229242  {
    230 #if SCALING_LIST_OUTPUT_RESULT
    231     printf("PPS\n");
    232 #endif
    233 
    234 #if IL_SL_SIGNALLING_N0371
    235     m_pcSlice->getScalingList()->setLayerId( pcPPS->getLayerId() );
    236 
    237     if( pcPPS->getLayerId() > 0 )
    238     {
    239       WRITE_FLAG( pcPPS->getPredScalingListFlag() ? 1 : 0,                          "pps_pred_scaling_list_flag" );
    240       m_pcSlice->getScalingList()->setPredScalingListFlag( pcPPS->getPredScalingListFlag() );
    241 
    242       if( pcPPS->getPredScalingListFlag() )
    243       {
    244         // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
    245         assert( /*pcPPS->getScalingListRefLayerId() >= 0 &&*/ pcPPS->getScalingListRefLayerId() <= 62 );
    246 
    247         // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of pps_scaling_list_ref_layer_id shall be greater than 0
    248         if( pcPPS->getSPS()->getVPS()->getAvcBaseLayerFlag() )
    249         {
    250           assert( pcPPS->getScalingListRefLayerId() > 0 );
    251         }
    252 
    253         // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
    254         // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
    255         assert( pcPPS->getPPS( pcPPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
    256 
    257         // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
    258         // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
    259         assert( pcPPS->getSPS()->getVPS()->getScalingListLayerDependency( pcPPS->getLayerId(), pcPPS->getScalingListRefLayerId() ) == true );
    260        
    261         WRITE_UVLC( pcPPS->getScalingListRefLayerId(),                            "scaling_list_pps_ref_layer_id" );
    262         m_pcSlice->getScalingList()->setScalingListRefLayerId( pcPPS->getScalingListRefLayerId() );
    263         codeScalingList( m_pcSlice->getScalingList() );
    264       }
    265       else
    266       {
    267         codeScalingList( m_pcSlice->getScalingList() );
    268       }
    269     }
    270     else
    271     {
    272       codeScalingList( m_pcSlice->getScalingList() );
    273     }
    274 #else
    275243    codeScalingList( m_pcSlice->getScalingList() );
    276 #endif
    277 
    278   }
     244  }
     245
     246#if SCALINGLIST_INFERRING
     247  }
     248#endif
     249
    279250  WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
    280251  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
     
    471442    WRITE_FLAG( pcSPS->getUpdateRepFormatFlag(), "update_rep_format_flag" );
    472443  }
     444#if O0096_REP_FORMAT_INDEX
     445  if( pcSPS->getLayerId() == 0 )
     446#else
    473447  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     448#endif
    474449  {
    475450#endif
     
    486461#if REPN_FORMAT_IN_VPS
    487462  }
     463#if O0096_REP_FORMAT_INDEX
     464  else if (pcSPS->getUpdateRepFormatFlag())
     465  {
     466    WRITE_CODE( pcSPS->getUpdateRepFormatIndex(), 8,   "update_rep_format_index");
     467  }
     468#endif
    488469#endif
    489470  Window conf = pcSPS->getConformanceWindow();
     
    499480
    500481#if REPN_FORMAT_IN_VPS
     482#if O0096_REP_FORMAT_INDEX
     483  if( pcSPS->getLayerId() == 0 )
     484#else
    501485  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     486#endif 
    502487  {
    503488    assert( pcSPS->getBitDepthY() >= 8 );
     
    532517  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
    533518  WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" );
    534 
    535 #if IL_SL_SIGNALLING_N0371
    536   pcSPS->setSPS( pcSPS->getLayerId(), pcSPS );
    537 #endif
    538 
    539519  if(pcSPS->getScalingListFlag())
    540520  {
     521#if SCALINGLIST_INFERRING
     522    if( pcSPS->getLayerId() > 0 )
     523    {
     524      WRITE_FLAG( pcSPS->getInferScalingListFlag() ? 1 : 0, "sps_infer_scaling_list_flag" );
     525    }
     526
     527    if( pcSPS->getInferScalingListFlag() )
     528    {
     529      // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     530      assert( pcSPS->getScalingListRefLayerId() <= 62 );
     531
     532      WRITE_UVLC( pcSPS->getScalingListRefLayerId(), "sps_scaling_list_ref_layer_id" );
     533    }
     534    else
     535    {
     536#endif
    541537    WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" );
    542538    if(pcSPS->getScalingListPresentFlag())
    543539    {
    544 #if SCALING_LIST_OUTPUT_RESULT
    545     printf("SPS\n");
    546 #endif
    547 
    548 #if IL_SL_SIGNALLING_N0371
    549     m_pcSlice->getScalingList()->setLayerId( pcSPS->getLayerId() );
    550 
    551     if( pcSPS->getLayerId() > 0 )
    552     {
    553       WRITE_FLAG( pcSPS->getPredScalingListFlag() ? 1 : 0,                          "sps_pred_scaling_list_flag" );
    554       m_pcSlice->getScalingList()->setPredScalingListFlag( pcSPS->getPredScalingListFlag() );
    555 
    556       if( pcSPS->getPredScalingListFlag() )
    557       {
    558 
    559         // The value of sps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
    560         assert( /*pcSPS->getScalingListRefLayerId() >= 0 &&*/ pcSPS->getScalingListRefLayerId() <= 62 );
    561        
    562         // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
    563         if( pcSPS->getVPS()->getAvcBaseLayerFlag() )
    564         {
    565           assert( pcSPS->getScalingListRefLayerId() > 0 );
    566         }
    567 
    568         // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
    569         // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
    570         assert( pcSPS->getSPS( pcSPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
    571 
    572         // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
    573         // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
    574         assert( pcSPS->getVPS()->getScalingListLayerDependency( pcSPS->getLayerId(), pcSPS->getScalingListRefLayerId() ) == true );
    575 
    576         WRITE_UVLC( pcSPS->getScalingListRefLayerId(),                            "scaling_list_sps_ref_layer_id" );
    577         m_pcSlice->getScalingList()->setScalingListRefLayerId( pcSPS->getScalingListRefLayerId() );
    578         codeScalingList( m_pcSlice->getScalingList() );
    579       }
    580       else
    581       {
    582         codeScalingList( m_pcSlice->getScalingList() );
    583       }
    584     }
    585     else
    586     {
    587540      codeScalingList( m_pcSlice->getScalingList() );
    588541    }
    589 #else
    590       codeScalingList( m_pcSlice->getScalingList() );
    591 #endif
    592 
    593     }
     542#if SCALINGLIST_INFERRING
     543    }
     544#endif
    594545  }
    595546  WRITE_FLAG( pcSPS->getUseAMP() ? 1 : 0,                                            "amp_enabled_flag" );
     
    648599  if( 1 )   // if( sps_extension_flag )
    649600  {
     601#if O0142_CONDITIONAL_SPS_EXTENSION
     602    UInt spsExtensionTypeFlag[8] = { 0, 1, 0, 0, 0, 0, 0, 0 };
     603    for (UInt i = 0; i < 8; i++)
     604    {
     605      WRITE_FLAG( spsExtensionTypeFlag[i], "sps_extension_type_flag" );
     606    }
     607    if (spsExtensionTypeFlag[1])
     608    {
     609      codeSPSExtension( pcSPS );
     610    }
     611#else
    650612    codeSPSExtension( pcSPS );
    651613    WRITE_FLAG( 0, "sps_extension2_flag" );
     614#endif
    652615  }
    653616#else
     
    670633    {
    671634      Window scaledWindow = pcSPS->getScaledRefLayerWindow(i);
     635#if O0098_SCALED_REF_LAYER_ID
     636      WRITE_CODE( pcSPS->getScaledRefLayerId(i), 6,          "scaled_ref_layer_id" );
     637#endif
    672638      WRITE_SVLC( scaledWindow.getWindowLeftOffset()   >> 1, "scaled_ref_layer_left_offset" );
    673639      WRITE_SVLC( scaledWindow.getWindowTopOffset()    >> 1, "scaled_ref_layer_top_offset" );
     
    891857    }
    892858  }
     859#endif
     860#if VPS_TSLAYERS
     861    WRITE_FLAG( vps->getMaxTSLayersPresentFlag(), "vps_sub_layers_max_minus1_present_flag");
     862    if (vps->getMaxTSLayersPresentFlag())
     863    {
     864        for( i = 0; i < vps->getMaxLayers() - 1; i++)
     865        {
     866            WRITE_CODE(vps->getMaxTSLayersMinus1(i), 3, "sub_layers_vps_max_minus1[i]" );
     867        }
     868    }
    893869#endif
    894870#if JCTVC_M0203_INTERLAYER_PRED_IDC
     
    982958  }
    983959
     960#if O0153_ALT_OUTPUT_LAYER_FLAG
     961  if( vps->getMaxLayers() > 1 )
     962  {
     963    WRITE_FLAG( vps->getAltOuputLayerFlag(), "alt_output_layer_flag" );   
     964  }
     965#endif
     966
    984967#if REPN_FORMAT_IN_VPS
    985968  WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag");
     
    987970  if( vps->getRepFormatIdxPresentFlag() )
    988971  {
     972#if O0096_REP_FORMAT_INDEX
     973    WRITE_CODE( vps->getVpsNumRepFormats() - 1, 8, "vps_num_rep_formats_minus1" );
     974#else
    989975    WRITE_CODE( vps->getVpsNumRepFormats() - 1, 4, "vps_num_rep_formats_minus1" );
     976#endif
    990977  }
    991978  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
     
    1001988      if( vps->getVpsNumRepFormats() > 1 )
    1002989      {
     990#if O0096_REP_FORMAT_INDEX
     991        WRITE_CODE( vps->getVpsRepFormatIdx(i), 8, "vps_rep_format_idx[i]" );
     992#else
    1003993        WRITE_CODE( vps->getVpsRepFormatIdx(i), 4, "vps_rep_format_idx[i]" );
     994#endif
    1004995      }
    1005996    }
     
    10251016  WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
    10261017#endif
     1018#if VPS_DPB_SIZE_TABLE
     1019  for(i = 1; i < vps->getNumOutputLayerSets(); i++)
     1020  {
     1021    WRITE_FLAG( vps->getSubLayerFlagInfoPresentFlag( i ), "sub_layer_flag_info_present_flag[i]"); 
     1022    for(j = 0; j < vps->getMaxTLayers(); j++)
     1023    {
     1024      if( j > 0 && vps->getSubLayerFlagInfoPresentFlag(i) )
     1025      {
     1026        WRITE_FLAG( vps->getSubLayerDpbInfoPresentFlag( i, j), "sub_layer_dpb_info_present_flag[i]"); 
     1027      }
     1028      if( vps->getSubLayerDpbInfoPresentFlag(i, j) )
     1029      {
     1030        for(Int k = 0; k < vps->getNumSubDpbs(i); k++)
     1031        {
     1032          WRITE_UVLC( vps->getMaxVpsDecPicBufferingMinus1( i, k, j), "max_vps_dec_pic_buffering_minus1[i][k][j]" );
     1033        }
     1034        WRITE_UVLC( vps->getMaxVpsNumReorderPics( i, j), "max_vps_num_reorder_pics[i][j]" );             
     1035        WRITE_UVLC( vps->getMaxVpsLatencyIncreasePlus1( i, j), "max_vps_latency_increase_plus1[i][j]" );       
     1036      }
     1037    }
     1038  }
     1039#endif
    10271040#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
    10281041  WRITE_UVLC( vps->getDirectDepTypeLen()-2,                           "direct_dep_type_len_minus2");
     1042#if O0096_DEFAULT_DEPENDENCY_TYPE
     1043  WRITE_FLAG(vps->getDefaultDirectDependencyTypeFlag(), "default_direct_dependency_flag");
     1044  if (vps->getDefaultDirectDependencyTypeFlag())
     1045  {
     1046    WRITE_CODE( vps->getDefaultDirectDependencyType(), vps->getDirectDepTypeLen(), "default_direct_dependency_type" );
     1047  }
     1048  else
     1049  {
     1050    for(i = 1; i < vps->getMaxLayers(); i++)
     1051    {
     1052      for(j = 0; j < i; j++)
     1053      {
     1054        if (vps->getDirectDependencyFlag(i, j))
     1055        {
     1056          WRITE_CODE( vps->getDirectDependencyType(i, j), vps->getDirectDepTypeLen(), "direct_dependency_type[i][j]" );
     1057        }
     1058      }
     1059    }
     1060  }
     1061#else
    10291062  for(i = 1; i < vps->getMaxLayers(); i++)
    10301063  {
     
    10371070    }
    10381071  }
    1039 
    1040 #if IL_SL_SIGNALLING_N0371
    1041   for(i = 1; i < vps->getMaxLayers(); i++)
    1042   {
    1043     for(j = 0; j < i; j++)
    1044     {
    1045       vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
    1046     }
    1047   }
    1048 #endif
    1049 
     1072#endif
    10501073#endif
    10511074#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    10521075  WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" );
    10531076#endif
     1077#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1078  WRITE_FLAG(vps->getHigherLayerIrapSkipFlag(), "higher_layer_irap_skip_flag" );
     1079#endif
    10541080
    10551081#if !VPS_VUI
     
    10711097Void  TEncCavlc::codeRepFormat      ( RepFormat *repFormat )
    10721098{
     1099#if REPN_FORMAT_CONTROL_FLAG
     1100   WRITE_FLAG ( repFormat->getChromaAndBitDepthVpsPresentFlag(), "chroma_and_bit_depth_vps_presenet_flag");
     1101
     1102   WRITE_CODE ( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_in_luma_samples" );   
     1103   WRITE_CODE ( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_in_luma_samples" ); 
     1104
     1105   if ( repFormat->getChromaAndBitDepthVpsPresentFlag() )
     1106   {
     1107     WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );   
     1108
     1109     if( repFormat->getChromaFormatVpsIdc() == 3 )
     1110     {
     1111       WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_flag");     
     1112     }
     1113
     1114     assert( repFormat->getBitDepthVpsLuma() >= 8 );
     1115     assert( repFormat->getBitDepthVpsChroma() >= 8 );
     1116     WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
     1117     WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );
     1118   }
     1119#else
    10731120  WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );   
    10741121 
     
    10841131  assert( repFormat->getBitDepthVpsChroma() >= 8 );
    10851132  WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
    1086   WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );         
     1133  WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );
     1134#endif
    10871135
    10881136}
     
    10921140{
    10931141  Int i,j;
     1142#if O0223_PICTURE_TYPES_ALIGN_FLAG
     1143  WRITE_FLAG(vps->getCrossLayerPictureTypeAlignFlag(), "cross_layer_pic_type_aligned_flag");
     1144  if (!vps->getCrossLayerPictureTypeAlignFlag())
     1145  {
     1146#endif
    10941147#if IRAP_ALIGN_FLAG_IN_VPS_VUI
    1095       WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
     1148    WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
    10961149#endif
     1150#if O0223_PICTURE_TYPES_ALIGN_FLAG
     1151  }
     1152#endif
    10971153#if VPS_VUI_BITRATE_PICRATE
    10981154  WRITE_FLAG( vps->getBitRatePresentVpsFlag(),        "bit_rate_present_vps_flag" );
     
    11271183  }
    11281184#endif
     1185#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1186  UInt layerIdx;
     1187  WRITE_FLAG( vps->getTilesNotInUseFlag() ? 1 : 0 , "tiles_not_in_use_flag" );
     1188  if (!vps->getTilesNotInUseFlag())
     1189  {
     1190    for(i = 0; i < vps->getMaxLayers(); i++)
     1191    {
     1192      WRITE_FLAG( vps->getTilesInUseFlag(i) ? 1 : 0 , "tiles_in_use_flag[ i ]" );
     1193      if (vps->getTilesInUseFlag(i))
     1194      {
     1195        WRITE_FLAG( vps->getLoopFilterNotAcrossTilesFlag(i) ? 1 : 0 , "loop_filter_not_across_tiles_flag[ i ]" );
     1196      }
     1197    }
     1198#endif
    11291199#if TILE_BOUNDARY_ALIGNED_FLAG
    1130   for(i = 1; i < vps->getMaxLayers(); i++)
    1131   {
    1132     for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
    1133     {
    1134       WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
    1135     }
    1136   } 
    1137 #endif
     1200    for(i = 1; i < vps->getMaxLayers(); i++)
     1201    {
     1202      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
     1203      {
     1204#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1205        layerIdx = vps->getLayerIdInVps(vps->getRefLayerId(vps->getLayerIdInNuh(i), j));
     1206        if (vps->getTilesInUseFlag(i) && vps->getTilesInUseFlag(layerIdx)) {
     1207          WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
     1208        }
     1209#else
     1210        WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
     1211#endif
     1212      }
     1213    } 
     1214#endif
     1215#if VPS_VUI_TILES_NOT_IN_USE__FLAG
     1216  }
     1217#endif
     1218#if VPS_VUI_WPP_NOT_IN_USE__FLAG
     1219  WRITE_FLAG( vps->getWppNotInUseFlag() ? 1 : 0 , "wpp_not_in_use_flag" );
     1220  if (!vps->getWppNotInUseFlag())
     1221  {
     1222    for(i = 0; i < vps->getMaxLayers(); i++)
     1223    {
     1224      WRITE_FLAG( vps->getWppInUseFlag(i) ? 1 : 0 , "wpp_in_use_flag[ i ]" );
     1225    }
     1226  }
     1227#endif
    11381228#if N0160_VUI_EXT_ILP_REF
    11391229  WRITE_FLAG( vps->getNumIlpRestrictedRefLayers() ? 1 : 0 , "num_ilp_restricted_ref_layers" );   
     
    11591249  }
    11601250#endif
     1251#if VPS_VUI_VIDEO_SIGNAL
     1252    WRITE_FLAG( vps->getVideoSigPresentVpsFlag(), "video_signal_info_idx_present_flag" );
     1253    if (vps->getVideoSigPresentVpsFlag())
     1254    {
     1255        WRITE_CODE(vps->getNumVideoSignalInfo()-1, 4, "vps_num_video_signal_info_minus1" );
     1256    }
     1257   
     1258    for(i = 0; i < vps->getNumVideoSignalInfo(); i++)
     1259    {
     1260        WRITE_CODE(vps->getVideoVPSFormat(i), 3, "video_vps_format" );
     1261        WRITE_FLAG(vps->getVideoFullRangeVpsFlag(i), "video_full_range_vps_flag" );
     1262        WRITE_CODE(vps->getColorPrimaries(i), 8, "color_primaries_vps" );
     1263        WRITE_CODE(vps->getTransCharacter(i), 8, "transfer_characteristics_vps" );
     1264        WRITE_CODE(vps->getMaxtrixCoeff(i), 8, "matrix_coeffs_vps" );
     1265    }
     1266   
     1267    if (vps->getVideoSigPresentVpsFlag() && vps->getNumVideoSignalInfo() > 1 )
     1268    {
     1269        for (i=1; i < vps->getMaxLayers(); i++)
     1270            WRITE_CODE(vps->getVideoSignalInfoIdx(i), 4, "vps_video_signal_info_idx" );
     1271    }
     1272#endif
    11611273}
    11621274#endif
     
    12211333      iBits++;
    12221334    }
     1335#if O0149_CROSS_LAYER_BLA_FLAG
     1336    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits )
     1337    {
     1338      assert(!!"cross_layer_bla_flag");
     1339      WRITE_FLAG(pcSlice->getCrossLayerBLAFlag(), "cross_layer_bla_flag");
     1340      iBits++;
     1341    }
     1342#endif
    12231343    for ( ; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
    12241344    {
     
    12991419      TComReferencePictureSet* rps = pcSlice->getRPS();
    13001420     
    1301 #if FIX1071
    13021421      // check for bitstream restriction stating that:
    13031422      // If the current picture is a BLA or CRA picture, the value of NumPocTotalCurr shall be equal to 0.
     
    13131432        }
    13141433      }
    1315 #endif
    13161434
    13171435      if(pcSlice->getRPSidx() < 0)
     
    14671585      if (pcSlice->getSPS()->getUseSAO())
    14681586      {
    1469          WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );
     1587         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "slice_sao_luma_flag" );         
     1588#if AUXILIARY_PICTURES
     1589         if (pcSlice->getChromaFormatIdc() != CHROMA_400)
    14701590         {
     1591#endif
     1592#if HM_CLEANUP_SAO
     1593         WRITE_FLAG( pcSlice->getSaoEnabledFlagChroma(), "slice_sao_chroma_flag" );
     1594#else
     1595         {
     1596           SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
     1597           WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
     1598         }
     1599#endif
    14711600#if AUXILIARY_PICTURES
    1472            if (pcSlice->getChromaFormatIdc() != CHROMA_400)
    1473            {
    1474 #endif
    1475            SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam();
    1476           WRITE_FLAG( saoParam->bSaoFlag[1], "slice_sao_chroma_flag" );
    1477 #if AUXILIARY_PICTURES
    1478            }
    1479 #endif
    14801601         }
    1481       }
    1482     }
     1602#endif
     1603      }
     1604    }   
    14831605
    14841606    //check if numrefidxes match the defaults. If not, override
     
    20262148  Bool scalingListPredModeFlag;
    20272149
    2028 #if SCALING_LIST_OUTPUT_RESULT
    2029   Int startBit;
    2030   Int startTotalBit;
    2031   startBit = m_pcBitIf->getNumberOfWrittenBits();
    2032   startTotalBit = m_pcBitIf->getNumberOfWrittenBits();
    2033 #endif
    2034 
    20352150    //for each size
    20362151    for(sizeId = 0; sizeId < SCALING_LIST_SIZE_NUM; sizeId++)
     
    20382153      for(listId = 0; listId < g_scalingListNum[sizeId]; listId++)
    20392154      {
    2040 #if SCALING_LIST_OUTPUT_RESULT
    2041         startBit = m_pcBitIf->getNumberOfWrittenBits();
    2042 #endif
    2043 
    2044 #if IL_SL_SIGNALLING_N0371
    2045         if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2046         {
    2047           scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    2048           WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
    2049           if(!scalingListPredModeFlag)// Copy Mode
    2050           {
    2051             WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
    2052           }
    2053           else// DPCM Mode
    2054           {
    2055             xCodeScalingList(scalingList, sizeId, listId);
    2056           }
    2057         }
    2058         else
    2059         {
    2060           scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    2061           WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
    2062           if(!scalingListPredModeFlag)// Copy Mode
    2063           {
    2064             WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
    2065           }
    2066           else// DPCM Mode
    2067           {
    2068             xCodeScalingList(scalingList, sizeId, listId);
    2069           }
    2070         }
    2071 #else
    20722155        scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    20732156        WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
     
    20802163          xCodeScalingList(scalingList, sizeId, listId);
    20812164        }
    2082 #endif
    2083 
    2084 #if SCALING_LIST_OUTPUT_RESULT
    2085         printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit);
    2086 #endif
    2087 
    2088       }
    2089     }
    2090 #if SCALING_LIST_OUTPUT_RESULT
    2091   printf("Total Bit %d\n",m_pcBitIf->getNumberOfWrittenBits()-startTotalBit);
    2092 #endif
     2165      }
     2166    }
    20932167  return;
    20942168}
     
    21052179  Int data;
    21062180  Int *src = scalingList->getScalingListAddress(sizeId, listId);
    2107 
    2108     if( sizeId > SCALING_LIST_8x8 )
    2109     {
    2110 #if IL_SL_SIGNALLING_N0371
    2111       if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2112       {
    2113         ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
    2114         scalingList->setScalingListDC(sizeId,listId,ref_scalingListDC[scalingList->getScalingListRefLayerId()][sizeId][listId]);
    2115       }
    2116       else
    2117       {
    2118         WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
    2119         nextCoef = scalingList->getScalingListDC(sizeId,listId);
    2120         ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
    2121       }
    2122 #else
    2123       WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
    2124       nextCoef = scalingList->getScalingListDC(sizeId,listId);
    2125 #endif
    2126     }
    2127     for(Int i=0;i<coefNum;i++)
    2128     {
    2129 #if IL_SL_SIGNALLING_N0371
    2130       if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
    2131       {
    2132         ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = src[scan[i]];
    2133         src[scan[i]] = ref_scalingListCoef[scalingList->getScalingListRefLayerId()][sizeId][listId][i];
    2134       }
    2135       else
    2136       {
    2137         data = src[scan[i]] - nextCoef;
    2138         ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = src[scan[i]];
    2139         nextCoef = src[scan[i]];
    2140         if(data > 127)
    2141         {
    2142           data = data - 256;
    2143         }
    2144         if(data < -128)
    2145         {
    2146           data = data + 256;
    2147         }
    2148 
    2149         WRITE_SVLC( data,  "scaling_list_delta_coef");
    2150       }
    2151 #else
    2152       data = src[scan[i]] - nextCoef;
    2153       nextCoef = src[scan[i]];
    2154       if(data > 127)
    2155       {
    2156         data = data - 256;
    2157       }
    2158       if(data < -128)
    2159       {
    2160         data = data + 256;
    2161       }
    2162 
    2163       WRITE_SVLC( data,  "scaling_list_delta_coef");
    2164 #endif
    2165     }
     2181  if( sizeId > SCALING_LIST_8x8 )
     2182  {
     2183    WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
     2184    nextCoef = scalingList->getScalingListDC(sizeId,listId);
     2185  }
     2186  for(Int i=0;i<coefNum;i++)
     2187  {
     2188    data = src[scan[i]] - nextCoef;
     2189    nextCoef = src[scan[i]];
     2190    if(data > 127)
     2191    {
     2192      data = data - 256;
     2193    }
     2194    if(data < -128)
     2195    {
     2196      data = data + 256;
     2197    }
     2198
     2199    WRITE_SVLC( data,  "scaling_list_delta_coef");
     2200  }
    21662201}
    21672202Bool TEncCavlc::findMatchingLTRP ( TComSlice* pcSlice, UInt *ltrpsIndex, Int ltrpPOC, Bool usedFlag )
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r442 r540  
    109109 
    110110  Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList );
     111#if HM_CLEANUP_SAO
     112  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false){printf("only supported in CABAC"); assert(0); exit(-1);}
     113#else
    111114  Void codeSAOSign       ( UInt code   ) { printf("Not supported\n"); assert (0); }
    112115  Void codeSaoMaxUvlc    ( UInt   code, UInt maxSymbol ){printf("Not supported\n"); assert (0);}
     
    114117  Void codeSaoTypeIdx    ( UInt uiCode ){printf("Not supported\n"); assert (0);}
    115118  Void codeSaoUflc       ( UInt uiLength, UInt   uiCode ){ assert(uiCode < 32); printf("Not supported\n"); assert (0);}
    116 
     119#endif
    117120  Void codeCUTransquantBypassFlag( TComDataCU* pcCU, UInt uiAbsPartIdx );
    118121  Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r494 r540  
    196196  Int       m_maxNumOffsetsPerPic;
    197197  Bool      m_saoLcuBoundary;
     198#if !HM_CLEANUP_SAO
    198199  Bool      m_saoLcuBasedOptimization;
    199 
     200#endif
    200201  //====== Lossless ========
    201202  Bool      m_useLossless;
     
    328329  Int       m_TMVPModeId;
    329330  Int       m_signHideFlag;
    330 #if RATE_CONTROL_LAMBDA_DOMAIN
    331331  Bool      m_RCEnableRateControl;
    332332  Int       m_RCTargetBitrate;
    333 #if M0036_RC_IMPROVEMENT
    334333  Int       m_RCKeepHierarchicalBit;
    335 #else
    336   Bool      m_RCKeepHierarchicalBit;
    337 #endif
    338334  Bool      m_RCLCULevelRC;
    339335  Bool      m_RCUseLCUSeparateModel;
    340336  Int       m_RCInitialQP;
    341337  Bool      m_RCForceIntraQP;
    342 #else
    343   Bool      m_enableRateCtrl;                                ///< Flag for using rate control algorithm
    344   Int       m_targetBitrate;                                 ///< target bitrate
    345   Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be divided by the NumLCUInUnit
    346 #endif
    347338  Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
    348339  Bool      m_CUTransquantBypassFlagValue;                    ///< if transquant_bypass_enable_flag, the fixed value to use for the per-CU cu_transquant_bypass_flag.
     
    393384  Int       m_adaptiveResolutionChange;
    394385#endif
     386#if O0153_ALT_OUTPUT_LAYER_FLAG
     387  Bool      m_altOutputLayerFlag;
     388#endif
     389#if HIGHER_LAYER_IRAP_SKIP_FLAG
     390  Int       m_skipPictureAtArcSwitch;
     391#endif
     392#if O0149_CROSS_LAYER_BLA_FLAG
     393  Bool      m_crossLayerBLAFlag;
     394#endif
    395395#endif
    396396
     
    629629  Void  setSaoLcuBoundary              (Bool val)      { m_saoLcuBoundary = val; }
    630630  Bool  getSaoLcuBoundary              ()              { return m_saoLcuBoundary; }
     631#if !HM_CLEANUP_SAO
    631632  Void  setSaoLcuBasedOptimization               (Bool val)            { m_saoLcuBasedOptimization = val; }
    632633  Bool  getSaoLcuBasedOptimization               ()                    { return m_saoLcuBasedOptimization; }
     634#endif
    633635  Void  setLFCrossTileBoundaryFlag               ( Bool   val  )       { m_loopFilterAcrossTilesEnabledFlag = val; }
    634636  Bool  getLFCrossTileBoundaryFlag               ()                    { return m_loopFilterAcrossTilesEnabledFlag;   }
     
    806808  Void      setSignHideFlag( Int signHideFlag ) { m_signHideFlag = signHideFlag; }
    807809  Int       getSignHideFlag()                    { return m_signHideFlag; }
    808 #if RATE_CONTROL_LAMBDA_DOMAIN
    809810  Bool      getUseRateCtrl         ()              { return m_RCEnableRateControl;   }
    810811  Void      setUseRateCtrl         ( Bool b )      { m_RCEnableRateControl = b;      }
    811812  Int       getTargetBitrate       ()              { return m_RCTargetBitrate;       }
    812813  Void      setTargetBitrate       ( Int bitrate ) { m_RCTargetBitrate  = bitrate;   }
    813 #if M0036_RC_IMPROVEMENT
    814814  Int       getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
    815815  Void      setKeepHierBit         ( Int i )       { m_RCKeepHierarchicalBit = i;    }
    816 #else
    817   Bool      getKeepHierBit         ()              { return m_RCKeepHierarchicalBit; }
    818   Void      setKeepHierBit         ( Bool b )      { m_RCKeepHierarchicalBit = b;    }
    819 #endif
    820816  Bool      getLCULevelRC          ()              { return m_RCLCULevelRC; }
    821817  Void      setLCULevelRC          ( Bool b )      { m_RCLCULevelRC = b; }
     
    826822  Bool      getForceIntraQP        ()              { return m_RCForceIntraQP;        }
    827823  Void      setForceIntraQP        ( Bool b )      { m_RCForceIntraQP = b;           }
    828 #else
    829   Bool      getUseRateCtrl    ()                { return m_enableRateCtrl;    }
    830   Void      setUseRateCtrl    (Bool flag)       { m_enableRateCtrl = flag;    }
    831   Int       getTargetBitrate  ()                { return m_targetBitrate;     }
    832   Void      setTargetBitrate  (Int target)      { m_targetBitrate  = target;  }
    833   Int       getNumLCUInUnit   ()                { return m_numLCUInUnit;      }
    834   Void      setNumLCUInUnit   (Int numLCUs)     { m_numLCUInUnit   = numLCUs; }
    835 #endif
    836824  Bool      getTransquantBypassEnableFlag()           { return m_TransquantBypassEnableFlag; }
    837825  Void      setTransquantBypassEnableFlag(Bool flag)  { m_TransquantBypassEnableFlag = flag; }
     
    934922  Int       getAdaptiveResolutionChange()      { return m_adaptiveResolutionChange; }
    935923#endif
     924#if HIGHER_LAYER_IRAP_SKIP_FLAG
     925  Void      setSkipPictureAtArcSwitch(Int x) { m_skipPictureAtArcSwitch = x;    }
     926  Int       getSkipPictureAtArcSwitch()      { return m_skipPictureAtArcSwitch; }
     927#endif
    936928#if AUXILIARY_PICTURES
    937929  Void         setChromaFormatIDC(ChromaFormat x) { m_chromaFormatIDC = x;    }
    938930  ChromaFormat getChromaFormatIDC()               { return m_chromaFormatIDC; }
    939931#endif
     932#if O0153_ALT_OUTPUT_LAYER_FLAG
     933  Bool      getAltOuputLayerFlag() const { return m_altOutputLayerFlag; }
     934  Void      setAltOuputLayerFlag(Bool b) { m_altOutputLayerFlag = b;    }
     935#endif
     936#if O0149_CROSS_LAYER_BLA_FLAG
     937  Bool      getCrossLayerBLAFlag() const { return m_crossLayerBLAFlag; }
     938  Void      setCrossLayerBLAFlag(Bool b) { m_crossLayerBLAFlag = b;    }
     939#endif
    940940#endif
    941941};
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r494 r540  
    9595 
    9696  m_bEncodeDQP = false;
    97 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    98   m_LCUPredictionSAD = 0;
    99   m_addSADDepth      = 0;
    100   m_temporalSAD      = 0;
    101 #endif
    10297
    10398  // initialize partition order.
     
    243238  m_ppcBestCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    244239  m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    245 
    246 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    247   m_addSADDepth      = 0;
    248   m_LCUPredictionSAD = 0;
    249   m_temporalSAD      = 0;
    250 #endif
    251240
    252241#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     
    433422  }
    434423
    435 #if RATE_CONTROL_LAMBDA_DOMAIN
    436424  if ( m_pcEncCfg->getUseRateCtrl() )
    437425  {
     
    439427    iMaxQP = m_pcRateCtrl->getRCQP();
    440428  }
    441 #else
    442   if(m_pcEncCfg->getUseRateCtrl())
    443   {
    444     Int qp = m_pcRateCtrl->getUnitQP();
    445     iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
    446     iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
    447   }
    448 #endif
    449429
    450430  // If slice start or slice end is within this cu...
     
    460440  if(!bSliceEnd && !bSliceStart && bInsidePicture )
    461441  {
     442#if HIGHER_LAYER_IRAP_SKIP_FLAG
     443    if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange())
     444    {
     445      rpcTempCU->initEstData( uiDepth, iBaseQP );
     446     
     447      xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode, true );
     448    }
     449    else
     450    {
     451#endif
    462452#if (ENCODER_FAST_MODE)
    463453    Bool testInter = true;
     
    528518      }
    529519    }
    530 
    531 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    532     if ( uiDepth <= m_addSADDepth )
    533     {
    534       m_LCUPredictionSAD += m_temporalSAD;
    535       m_addSADDepth = uiDepth;
    536     }
    537 #endif
    538520
    539521    if(!earlyDetectionSkipMode)
     
    779761      bSubBranch = true;
    780762    }
     763#if HIGHER_LAYER_IRAP_SKIP_FLAG
     764    }
     765#endif
    781766  }
    782767  else if(!(bSliceEnd && bInsidePicture))
    783768  {
    784769    bBoundary = true;
    785 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    786     m_addSADDepth++;
    787 #endif
    788770  }
    789771
     
    829811    iMaxQP = iStartQP;
    830812  }
    831 #if RATE_CONTROL_LAMBDA_DOMAIN
    832813  if ( m_pcEncCfg->getUseRateCtrl() )
    833814  {
     
    835816    iMaxQP = m_pcRateCtrl->getRCQP();
    836817  }
    837 #else
    838   if(m_pcEncCfg->getUseRateCtrl())
    839   {
    840     Int qp = m_pcRateCtrl->getUnitQP();
    841     iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
    842     iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
    843   }
    844 #endif
    845818  for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++)
    846819  {
     
    11431116 
    11441117  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
     1118#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1119  if (m_pcEncCfg->getSkipPictureAtArcSwitch() && m_pcEncCfg->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncCfg->getAdaptiveResolutionChange())
     1120  {
     1121    pcCU->setSkipFlagSubParts(true, uiAbsPartIdx, uiDepth);
     1122  }
     1123#endif
    11451124  // If slice start is within this cu...
    11461125  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx &&
     
    12311210}
    12321211
    1233 #if RATE_CONTROL_INTRA
    12341212Int xCalcHADs8x8_ISlice(Pel *piOrg, Int iStrideOrg)
    12351213{
     
    13461324  return(iSumHad);
    13471325}
    1348 #endif
    13491326
    13501327/** check RD costs for a CU block encoded with merge
     
    13531330 * \returns Void
    13541331 */
     1332#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1333Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode, Bool bUseSkip )
     1334#else
    13551335Void TEncCu::xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode )
     1336#endif
    13561337{
    13571338  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
     
    13871368  }
    13881369
     1370#if HIGHER_LAYER_IRAP_SKIP_FLAG
     1371  for( UInt uiNoResidual = bUseSkip?1:0; uiNoResidual < iteration; ++uiNoResidual )
     1372#else
    13891373  for( UInt uiNoResidual = 0; uiNoResidual < iteration; ++uiNoResidual )
     1374#endif
    13901375  {
    13911376    for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
     
    15151500#endif
    15161501
    1517 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    1518   if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    1519   {
    1520     UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
    1521       m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
    1522       rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
    1523     m_temporalSAD = (Int)SAD;
    1524   }
    1525 #endif
    1526 
    15271502  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
    15281503  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
     
    15551530 
    15561531  m_pcEntropyCoder->resetBits();
    1557 
    15581532  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    15591533  {
     
    16091583
    16101584  m_pcEntropyCoder->resetBits();
    1611 
    16121585  if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag())
    16131586  {
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r494 r540  
    103103  Bool                    m_bUseSBACRD;
    104104  TEncRateCtrl*           m_pcRateCtrl;
    105 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    106   UInt                    m_LCUPredictionSAD;
    107   Int                     m_addSADDepth;
    108   Int                     m_temporalSAD;
    109 #endif
     105
    110106#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
    111107  Bool                    m_disableILP;
     
    128124 
    129125  Void setBitCounter        ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; }
    130 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
    131   UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
    132 #endif
    133 #if RATE_CONTROL_INTRA
    134126  Int   updateLCUDataISlice ( TComDataCU* pcCU, Int LCUIdx, Int width, Int height );
    135 #endif
    136 
    137127protected:
    138128  Void  finishCU            ( TComDataCU*  pcCU, UInt uiAbsPartIdx,           UInt uiDepth        );
     
    146136  Int   xComputeQP          ( TComDataCU* pcCU, UInt uiDepth );
    147137  Void  xCheckBestMode      ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth        );
    148  
     138#if HIGHER_LAYER_IRAP_SKIP_FLAG
     139  Void  xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode, Bool bUseSkip=false);
     140#else 
    149141  Void  xCheckRDCostMerge2Nx2N( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, Bool *earlyDetectionSkipMode);
     142#endif
    150143
    151144#if AMP_MRG
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r494 r540  
    5151Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice )
    5252{
     53#if !HM_CLEANUP_SAO
    5354  if (pcSlice->getSPS()->getUseSAO())
    5455  {
     
    5960    }
    6061  }
    61 
     62#endif
    6263  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
    6364  return;
     
    638639}
    639640
     641#if !HM_CLEANUP_SAO
    640642/** Encode SAO Offset
    641643 * \param  saoLcuParam SAO LCU paramters
     
    731733}
    732734
     735#endif
     736
    733737Int TEncEntropy::countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize )
    734738{
  • trunk/source/Lib/TLibEncoder/TEncEntropy.h

    r345 r540  
    105105  virtual Void codeCoeffNxN      ( TComDataCU* pcCU, TCoeff* pcCoef, UInt uiAbsPartIdx, UInt uiWidth, UInt uiHeight, UInt uiDepth, TextType eTType ) = 0;
    106106  virtual Void codeTransformSkipFlags ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt width, UInt height, TextType eTType ) = 0;
     107#if HM_CLEANUP_SAO
     108  virtual Void codeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail, Bool onlyEstMergeInfo = false)    =0;
     109#else
    107110  virtual Void codeSAOSign          ( UInt code   ) = 0;
    108111  virtual Void codeSaoMaxUvlc       ( UInt code, UInt maxSymbol ) = 0;
     
    110113  virtual Void codeSaoTypeIdx      ( UInt   uiCode) = 0;
    111114  virtual Void codeSaoUflc         ( UInt uiLength, UInt   uiCode ) = 0;
     115#endif
    112116  virtual Void estBit               (estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType) = 0;
    113117 
     
    188192 
    189193  Void estimateBit             ( estBitsSbacStruct* pcEstBitsSbac, Int width, Int height, TextType eTType);
     194#if HM_CLEANUP_SAO
     195  Void encodeSAOBlkParam(SAOBlkParam& saoBlkParam, Bool* sliceEnabled, Bool leftMergeAvail, Bool aboveMergeAvail){m_pcEntropyCoderIf->codeSAOBlkParam(saoBlkParam, sliceEnabled, leftMergeAvail, aboveMergeAvail, false);}
     196#else
    190197  Void    encodeSaoOffset(SaoLcuParam* saoLcuParam, UInt compIdx);
    191198  Void    encodeSaoUnitInterleaving(Int compIdx, Bool saoFlag, Int rx, Int ry, SaoLcuParam* saoLcuParam, Int cuAddrInSlice, Int cuAddrUpInSlice, Int allowMergeLeft, Int allowMergeUp);
     199#endif
    192200  static Int countNonZeroCoeffs( TCoeff* pcCoef, UInt uiSize );
    193201
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r494 r540  
    635635    }
    636636#endif
     637#if O0149_CROSS_LAYER_BLA_FLAG
     638    if( m_layerId == 0 && (getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP) )
     639    {
     640      pcSlice->setCrossLayerBLAFlag(m_pcEncTop->getCrossLayerBLAFlag());
     641    }
     642    else
     643    {
     644      pcSlice->setCrossLayerBLAFlag(false);
     645    }
     646#endif
     647#if NO_CLRAS_OUTPUT_FLAG
     648    if (m_layerId == 0 &&
     649        (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     650      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     651      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP
     652      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL
     653      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP
     654      || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
     655    {
     656      if (m_bFirst)
     657      {
     658        m_pcEncTop->setNoClrasOutputFlag(true);
     659      }
     660      else if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     661            || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL
     662            || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP)
     663      {
     664        m_pcEncTop->setNoClrasOutputFlag(true);
     665      }
     666#if O0149_CROSS_LAYER_BLA_FLAG
     667      else if ((pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP) &&
     668               pcSlice->getCrossLayerBLAFlag())
     669      {
     670        m_pcEncTop->setNoClrasOutputFlag(true);
     671      }
     672#endif
     673      else
     674      {
     675        m_pcEncTop->setNoClrasOutputFlag(false);
     676      }
     677      if (m_pcEncTop->getNoClrasOutputFlag())
     678      {
     679        for (UInt i = 0; i < m_pcCfg->getNumLayer(); i++)
     680        {
     681          m_ppcTEncTop[i]->setLayerInitializedFlag(false);
     682          m_ppcTEncTop[i]->setFirstPicInLayerDecodedFlag(false);
     683        }
     684      }
     685    }
     686#endif
    637687#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    638688    if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())
     
    661711#endif
    662712
    663 #if IL_SL_SIGNALLING_N0371
    664     m_pcEncTop->getScalingList()->setLayerId( m_layerId );
    665 #endif
    666 
    667713    pcSlice->setLastIDR(m_iLastIDR);
    668714    pcSlice->setSliceIdx(0);
     
    672718    if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
    673719    {
    674 #if IL_SL_SIGNALLING_N0371
    675       m_pcEncTop->getTrQuant()->setFlatScalingList( m_layerId );
    676 #else
    677720      m_pcEncTop->getTrQuant()->setFlatScalingList();
    678 #endif
    679721      m_pcEncTop->getTrQuant()->setUseScalingList(false);
    680722      m_pcEncTop->getSPS()->setScalingListPresentFlag(false);
     
    683725    else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT)
    684726    {
    685 #if IL_SL_SIGNALLING_N0371
    686       pcSlice->getScalingList()->setLayerId( m_layerId );
    687 #endif
    688 
    689 #if IL_SL_SIGNALLING_N0371
    690       pcSlice->setDefaultScalingList ( m_layerId );
    691 #else
     727#if SCALINGLIST_INFERRING
     728      // inferring of the scaling list can be moved to the config file
     729      UInt refLayerId = 0;
     730      if( m_layerId > 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
     731      {
     732        m_pcEncTop->getSPS()->setInferScalingListFlag( true );
     733        m_pcEncTop->getSPS()->setScalingListRefLayerId( refLayerId );
     734        m_pcEncTop->getSPS()->setScalingListPresentFlag( false );
     735        m_pcEncTop->getPPS()->setInferScalingListFlag( false );
     736        m_pcEncTop->getPPS()->setScalingListPresentFlag( false );
     737
     738        // infer the scaling list from the reference layer
     739        pcSlice->setScalingList ( m_ppcTEncTop[refLayerId]->getScalingList() );
     740      }
     741      else
     742      {
     743#endif
    692744      pcSlice->setDefaultScalingList ();
    693 #endif
    694 
    695745      m_pcEncTop->getSPS()->setScalingListPresentFlag(false);
    696746      m_pcEncTop->getPPS()->setScalingListPresentFlag(false);
     747
     748#if SCALINGLIST_INFERRING
     749      }
     750#endif
     751
    697752      m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList());
    698753      m_pcEncTop->getTrQuant()->setUseScalingList(true);
     
    700755    else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ)
    701756    {
    702 #if IL_SL_SIGNALLING_N0371
    703       pcSlice->getScalingList()->setLayerId( m_layerId );
     757#if SCALINGLIST_INFERRING
     758      // inferring of the scaling list can be moved to the config file
     759      UInt refLayerId = 0;
     760      if( m_layerId > 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() && m_pcEncTop->getVPS()->getRecursiveRefLayerFlag( m_layerId, refLayerId ) )
     761      {
     762        m_pcEncTop->getSPS()->setInferScalingListFlag( true );
     763        m_pcEncTop->getSPS()->setScalingListRefLayerId( refLayerId );
     764        m_pcEncTop->getSPS()->setScalingListPresentFlag( false );
     765        m_pcEncTop->getPPS()->setInferScalingListFlag( false );
     766        m_pcEncTop->getPPS()->setScalingListPresentFlag( false );
     767
     768        // infer the scaling list from the reference layer
     769        pcSlice->setScalingList ( m_ppcTEncTop[refLayerId]->getScalingList() );
     770      }
     771      else
     772      {
    704773#endif
    705774
    706775      if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile()))
    707776      {
    708 #if IL_SL_SIGNALLING_N0371
    709         pcSlice->setDefaultScalingList ( m_layerId );
    710 #else
    711777        pcSlice->setDefaultScalingList ();
    712 #endif
    713       }
    714 #if IL_SL_SIGNALLING_N0371
    715       pcSlice->getScalingList()->checkDcOfMatrix( m_layerId );
    716 #else
     778      }
     779
    717780      pcSlice->getScalingList()->checkDcOfMatrix();
    718 #endif
    719781      m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList());
    720 
    721 #if IL_SL_SIGNALLING_N0371
    722       if( m_layerId > 0 )
    723       {
    724         m_pcEncTop->getSPS()->setPredScalingListFlag  (true);
    725         m_pcEncTop->getSPS()->setScalingListRefLayerId( 0 );
    726       }
    727 #endif
    728 
    729782      m_pcEncTop->getPPS()->setScalingListPresentFlag(false);
    730783
    731 #if IL_SL_SIGNALLING_N0371
    732       if( m_layerId > 0 )
    733       {
    734         m_pcEncTop->getPPS()->setPredScalingListFlag  (false);
    735         m_pcEncTop->getPPS()->setScalingListRefLayerId( 0   );
    736       }
     784#if SCALINGLIST_INFERRING
     785    }
    737786#endif
    738787
     
    783832        }
    784833
     834#if O0098_SCALED_REF_LAYER_ID
     835        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
     836#else
    785837        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
     838#endif
    786839
    787840        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
     
    800853        if( pcPic->isSpatialEnhLayer(refLayerIdc))
    801854        {
     855/*#if O0098_SCALED_REF_LAYER_ID
     856          Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindowForLayer(pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc));
     857#else
     858          Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc);
     859#endif*/
    802860#if O0215_PHASE_ALIGNMENT
    803861#if O0194_JOINT_US_BITSHIFT
    804           m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
    805 #else
    806           m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc), pcSlice->getVPS()->getPhaseAlignFlag() );
     862          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
     863#else
     864          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL, pcSlice->getVPS()->getPhaseAlignFlag() );
    807865#endif
    808866#else
    809867#if O0194_JOINT_US_BITSHIFT
    810           m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
    811 #else
    812           m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
     868          m_pcPredSearch->upsampleBasePic( pcSlice, refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
     869#else
     870          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), scalEL );
    813871#endif
    814872#endif
     
    827885        pcSlice->setInterLayerPredLayerIdc( interLayerPredLayerIdcTmp[i], i );
    828886      }
     887
     888#if !O0225_TID_BASED_IL_RPS_DERIV
    829889      pcSlice->setActiveNumILRRefIdx( activeNumILRRefIdxTmp );
     890#endif
    830891      if ( pcSlice->getActiveNumILRRefIdx() == 0 )
    831892      {
     
    902963
    903964    // Do decoding refresh marking if any
     965#if NO_CLRAS_OUTPUT_FLAG
     966    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic, m_pcEncTop->getNoClrasOutputFlag());
     967#else
    904968    pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic);
     969#endif
    905970    m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid);
    906971    pcSlice->getRPS()->setNumberOfLongtermPictures(0);
    907972
    908 #if FIX1071
    909973    if ((pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) || (pcSlice->isIRAP()))
    910974    {
    911975      pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS(), pcSlice->isIRAP());
    912976    }
    913 #else
    914     if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0)
    915     {
    916       pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS());
    917     }
    918 #endif
    919977    pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS());
    920978
     
    934992            {
    935993              if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) ||
    936                   ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R )
     994                  ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R )
    937995                )
    938996              {
     
    9431001                else
    9441002                {
    945                   pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R );
     1003                  pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R );
    9461004                }
    9471005                oneRefLayerTSA = true;
     
    9751033            else
    9761034            {
    977               pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R );
     1035              pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R );
    9781036            }
    9791037          }
     
    9861044        else
    9871045        {
    988           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
     1046          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R);
    9891047        }
    9901048#endif
     
    13561414    pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag());
    13571415
    1358 #if RATE_CONTROL_LAMBDA_DOMAIN
    13591416    Double lambda            = 0.0;
    13601417    Int actualHeadBits       = 0;
     
    13891446      else if ( frameLevel == 0 )   // intra case, but use the model
    13901447      {
    1391 #if RATE_CONTROL_INTRA
    13921448        m_pcSliceEncoder->calCostSliceI(pcPic);
    1393 #endif
    13941449        if ( m_pcCfg->getIntraPeriod() != 1 )   // do not refine allocated bits for all intra case
    13951450        {
    13961451          Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits();
    1397 #if RATE_CONTROL_INTRA
    13981452          bits = m_pcRateCtrl->getRCPic()->getRefineBitsForIntra( bits );
    1399 #else
    1400           bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits );
    1401 #endif
    14021453          if ( bits < 200 )
    14031454          {
     
    14081459
    14091460        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
    1410 #if RATE_CONTROL_INTRA
    14111461        m_pcRateCtrl->getRCPic()->getLCUInitTargetBits();
    14121462        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
    1413 #else
    1414         lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
    1415 #endif
    14161463        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
    14171464      }
     
    14191466      {
    14201467        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
    1421 #if RATE_CONTROL_INTRA
    14221468        lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture, pcSlice->getSliceType());
    1423 #else
    1424         lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture );
    1425 #endif
    14261469        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
    14271470      }
     
    14361479      m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda );
    14371480    }
    1438 #endif
    14391481
    14401482    UInt uiNumSlices = 1;
     
    16471689
    16481690    // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas
     1691#if HM_CLEANUP_SAO
     1692    if( pcSlice->getSPS()->getUseSAO() && m_pcCfg->getSaoLcuBoundary() )
     1693    {
     1694      m_pcSAO->getPreDBFStatistics(pcPic);
     1695    }
     1696#else
    16491697    if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() )
    16501698    {
     
    16521700      m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic );
    16531701    }
    1654 
     1702#endif   
    16551703    //-- Loop filter
    16561704    Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag();
     
    16621710    m_pcLoopFilter->loopFilterPic( pcPic );
    16631711
     1712#if !HM_CLEANUP_SAO   
    16641713    pcSlice = pcPic->getSlice(0);
    16651714    if(pcSlice->getSPS()->getUseSAO())
     
    16811730      m_pcSAO->createPicSaoInfo(pcPic);
    16821731    }
    1683 
     1732#endif
    16841733    /////////////////////////////////////////////////////////////////////////////////////////////////// File writing
    16851734    // Set entropy coder
     
    17131762      writeRBSPTrailingBits(nalu.m_Bitstream);
    17141763      accessUnit.push_back(new NALUnitEBSP(nalu));
    1715 #if RATE_CONTROL_LAMBDA_DOMAIN
    17161764      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1717 #endif
    17181765#if SVC_EXTENSION
    17191766      }
     
    17221769#if SVC_EXTENSION
    17231770      nalu = NALUnit(NAL_UNIT_SPS, 0, m_layerId);
    1724 #if IL_SL_SIGNALLING_N0371
    1725       pcSlice->getSPS()->setVPS( pcSlice->getVPS() );
    1726 #endif
    17271771#else
    17281772      nalu = NALUnit(NAL_UNIT_SPS);
     
    17531797        pcSlice->getSPS()->getVuiParameters()->setHrdParametersPresentFlag( true );
    17541798      }
     1799#if O0092_0094_DEPENDENCY_CONSTRAINT
     1800      assert( pcSlice->getSPS()->getLayerId() == 0 || pcSlice->getSPS()->getLayerId() == m_layerId || m_pcEncTop->getVPS()->getRecursiveRefLayerFlag(m_layerId, pcSlice->getSPS()->getLayerId()) );
     1801#endif
    17551802      m_pcEntropyCoder->encodeSPS(pcSlice->getSPS());
    17561803      writeRBSPTrailingBits(nalu.m_Bitstream);
    17571804      accessUnit.push_back(new NALUnitEBSP(nalu));
    1758 #if RATE_CONTROL_LAMBDA_DOMAIN
    17591805      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1760 #endif
    17611806
    17621807#if SVC_EXTENSION
     
    17661811#endif
    17671812      m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     1813#if O0092_0094_DEPENDENCY_CONSTRAINT
     1814      assert( pcSlice->getPPS()->getPPSId() == 0 || pcSlice->getPPS()->getPPSId() == m_layerId || m_pcEncTop->getVPS()->getRecursiveRefLayerFlag(m_layerId, pcSlice->getPPS()->getPPSId()) );
     1815#endif
    17681816      m_pcEntropyCoder->encodePPS(pcSlice->getPPS());
    17691817      writeRBSPTrailingBits(nalu.m_Bitstream);
    17701818      accessUnit.push_back(new NALUnitEBSP(nalu));
    1771 #if RATE_CONTROL_LAMBDA_DOMAIN
    17721819      actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    1773 #endif
    17741820
    17751821      xCreateLeadingSEIMessages(accessUnit, pcSlice->getSPS());
     
    20912137          }
    20922138          m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
    2093 #if RATE_CONTROL_LAMBDA_DOMAIN
    20942139          tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
    2095 #endif
    2096 
    20972140          m_pcEntropyCoder->encodeSliceHeader(pcSlice);
    2098 
    2099 #if RATE_CONTROL_LAMBDA_DOMAIN
    21002141          actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting );
    2101 #endif
    21022142
    21032143          // is it needed?
     
    22202260          xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect);
    22212261          accessUnit.push_back(new NALUnitEBSP(nalu));
    2222 #if RATE_CONTROL_LAMBDA_DOMAIN
    22232262          actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8;
    2224 #endif
    22252263          bNALUAlignedWrittenToList = true;
    22262264          uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment
     
    22622300            // set entropy coder for RD
    22632301            m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice );
     2302#if HIGHER_LAYER_IRAP_SKIP_FLAG
     2303            if ( pcSlice->getSPS()->getUseSAO() && !( m_pcEncTop->getSkipPictureAtArcSwitch() && m_pcEncTop->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncTop->getAdaptiveResolutionChange()) )
     2304#else
    22642305            if ( pcSlice->getSPS()->getUseSAO() )
     2306#endif
    22652307            {
    22662308              m_pcEntropyCoder->resetEntropy();
    22672309              m_pcEntropyCoder->setBitstream( m_pcBitCounter );
     2310#if HM_CLEANUP_SAO
     2311              Bool sliceEnabled[NUM_SAO_COMPONENTS];
     2312              m_pcSAO->initRDOCabacCoder(m_pcEncTop->getRDGoOnSbacCoder(), pcSlice);
     2313              m_pcSAO->SAOProcess(pcPic
     2314                , sliceEnabled
     2315                , pcPic->getSlice(0)->getLambdas()
     2316#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     2317                , m_pcCfg->getSaoLcuBoundary()
     2318#endif
     2319              );
     2320              m_pcSAO->PCMLFDisableProcess(pcPic);   
     2321
     2322              //assign SAO slice header
     2323              for(Int s=0; s< uiNumSlices; s++)
     2324              {
     2325                pcPic->getSlice(s)->setSaoEnabledFlag(sliceEnabled[SAO_Y]);
     2326                assert(sliceEnabled[SAO_Cb] == sliceEnabled[SAO_Cr]);
     2327                pcPic->getSlice(s)->setSaoEnabledFlagChroma(sliceEnabled[SAO_Cb]);
     2328              }
     2329#else
    22682330              m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder());
    22692331              SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam();
    22702332
    2271 #if SAO_CHROMA_LAMBDA
    22722333#if SAO_ENCODING_CHOICE
    2273               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth());
     2334              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdas()[TEXT_LUMA], pcPic->getSlice(0)->getLambdas()[TEXT_CHROMA], pcPic->getSlice(0)->getDepth());
    22742335#else
    22752336              m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma());
    2276 #endif
    2277 #else
    2278               m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda());
    22792337#endif
    22802338              m_pcSAO->endSaoEnc();
    22812339              m_pcSAO->PCMLFDisableProcess(pcPic);
     2340#endif
    22822341            }
     2342#if !HM_CLEANUP_SAO         
    22832343#if SAO_RDO
    22842344            m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );
    22852345#endif
     2346#endif
    22862347            processingState = ENCODE_SLICE;
    2287 
     2348#if !HM_CLEANUP_SAO
     2349#if HIGHER_LAYER_IRAP_SKIP_FLAG
     2350            if ( ( m_pcEncTop->getSkipPictureAtArcSwitch() && m_pcEncTop->getAdaptiveResolutionChange() > 0 && pcSlice->getLayerId() == 1 && pcSlice->getPOC() == m_pcEncTop->getAdaptiveResolutionChange()) )
     2351            {
     2352              pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]=0;
     2353              pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[1]=0;
     2354            }
     2355#endif
    22882356            for(Int s=0; s< uiNumSlices; s++)
    22892357            {
     
    22932361              }
    22942362            }
     2363#endif
    22952364          }
    22962365          break;
     
    23032372        }
    23042373      } // end iteration over slices
    2305 
     2374#if !HM_CLEANUP_SAO   
    23062375      if(pcSlice->getSPS()->getUseSAO())
    23072376      {
     
    23122381        pcPic->destroyNonDBFilterInfo();
    23132382      }
    2314 
     2383#endif
    23152384      pcPic->compressMotion();
    23162385     
     
    24122481        }
    24132482      }
    2414 #if RATE_CONTROL_LAMBDA_DOMAIN
    24152483      if ( m_pcCfg->getUseRateCtrl() )
    24162484      {
    2417 #if !M0036_RC_IMPROVEMENT
    2418         Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage();
    2419 #endif
    24202485        Double avgQP     = m_pcRateCtrl->getRCPic()->calAverageQP();
    24212486        Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda();
     
    24242489          avgLambda = lambda;
    24252490        }
    2426 #if M0036_RC_IMPROVEMENT
    2427 #if RATE_CONTROL_INTRA
    24282491        m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, pcSlice->getSliceType());
    2429 #else
    2430         m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda );
    2431 #endif
    2432 #else
    2433         m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage );
    2434 #endif
    24352492        m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() );
    24362493
     
    24452502        }
    24462503      }
    2447 #else
    2448       if(m_pcCfg->getUseRateCtrl())
    2449       {
    2450         UInt  frameBits = m_vRVM_RP[m_vRVM_RP.size()-1];
    2451         m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType());
    2452       }
    2453 #endif
    24542504
    24552505      if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) &&
     
    26362686      delete[] pcSubstreamsOut;
    26372687  }
    2638 #if !RATE_CONTROL_LAMBDA_DOMAIN
    2639   if(m_pcCfg->getUseRateCtrl())
    2640   {
    2641     m_pcRateCtrl->updateRCGOPStatus();
    2642   }
    2643 #endif
    26442688  delete pcBitstreamRedirect;
    26452689
     
    27242768  m_pcEntropyCoder->resetEntropy    ();
    27252769  m_pcEntropyCoder->setBitstream    ( m_pcBitCounter );
     2770#if !HM_CLEANUP_SAO
    27262771  pcSlice = pcPic->getSlice(0);
    27272772  if(pcSlice->getSPS()->getUseSAO())
     
    27382783    pcPic->destroyNonDBFilterInfo();
    27392784  }
    2740  
     2785#endif
    27412786  m_pcEntropyCoder->resetEntropy    ();
    27422787  ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits();
     
    28102855      iterPicYuvRec--;
    28112856    }
     2857   
    28122858  }
    28132859 
     
    29052951    case NAL_UNIT_CODED_SLICE_TRAIL_R:    return "TRAIL_R";
    29062952    case NAL_UNIT_CODED_SLICE_TRAIL_N:    return "TRAIL_N";
    2907     case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
     2953    case NAL_UNIT_CODED_SLICE_TSA_R:      return "TSA_R";
    29082954    case NAL_UNIT_CODED_SLICE_TSA_N:      return "TSA_N";
    29092955    case NAL_UNIT_CODED_SLICE_STSA_R:     return "STSA_R";
     
    31403186    for (Int x = 0; x < width; x++)
    31413187    {
    3142       dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
    3143       dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     3188      dst[x] = isTff ? top[x] : bottom[x];
     3189      dst[stride+x] = isTff ? bottom[x] : top[x];
    31443190    }
    31453191    top += stride;
     
    32983344  delete pcRecInterlaced;
    32993345}
     3346
     3347
    33003348
    33013349/** Function for deciding the nal_unit_type.
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp

    r313 r540  
    4242using namespace std;
    4343
    44 #if RATE_CONTROL_LAMBDA_DOMAIN
    45 
    4644//sequence level
    4745TEncRCSeq::TEncRCSeq()
     
    6765  m_bitsLeft            = 0;
    6866  m_useLCUSeparateModel = false;
    69 #if M0036_RC_IMPROVEMENT
    7067  m_adaptiveBit         = 0;
    7168  m_lastLambda          = 0.0;
    72 #endif
    7369}
    7470
     
    7874}
    7975
    80 #if M0036_RC_IMPROVEMENT
    8176Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit )
    82 #else
    83 Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel )
    84 #endif
    8577{
    8678  destroy();
     
    109101    m_betaUpdate  = 0.025;
    110102  }
    111 #if M0036_RC_IMPROVEMENT
    112103  else if ( m_seqTargetBpp < 0.2 )
    113104  {
     
    125116    m_betaUpdate  = 0.2;
    126117  }
    127 #else
    128   else
    129   {
    130     m_alphaUpdate = 0.1;
    131     m_betaUpdate  = 0.05;
    132   }
    133 #endif
    134118  m_averageBits     = (Int)(m_targetBits / totalFrames);
    135119  Int picWidthInBU  = ( m_picWidth  % m_LCUWidth  ) == 0 ? m_picWidth  / m_LCUWidth  : m_picWidth  / m_LCUWidth  + 1;
     
    172156  m_framesLeft = m_totalFrames;
    173157  m_bitsLeft   = m_targetBits;
    174 #if M0036_RC_IMPROVEMENT
    175158  m_adaptiveBit = adaptiveBit;
    176159  m_lastLambda = 0.0;
    177 #endif
    178160}
    179161
     
    233215    for ( Int i=0; i<m_numberOfLevel; i++ )
    234216    {
    235 #if RATE_CONTROL_INTRA
    236217      if (i>0)
    237218      {
     
    244225        m_picPara[i].m_beta  = BETA2;
    245226      }
    246 #else
    247       m_picPara[i].m_alpha = 3.2003;
    248       m_picPara[i].m_beta  = -1.367;
    249 #endif
    250227    }
    251228  }
     
    271248      for ( Int j=0; j<m_numberOfLCU; j++)
    272249      {
    273 #if RATE_CONTROL_INTRA
    274250        m_LCUPara[i][j].m_alpha = m_picPara[i].m_alpha;
    275251        m_LCUPara[i][j].m_beta  = m_picPara[i].m_beta;
    276 #else
    277         m_LCUPara[i][j].m_alpha = 3.2003;
    278         m_LCUPara[i][j].m_beta  = -1.367;
    279 #endif
    280252      }
    281253    }
     
    299271}
    300272
    301 #if !RATE_CONTROL_INTRA
    302 Int TEncRCSeq::getRefineBitsForIntra( Int orgBits )
    303 {
    304   Double bpp = ( (Double)orgBits ) / m_picHeight / m_picHeight;
    305   if ( bpp > 0.2 )
    306   {
    307     return orgBits * 5;
    308   }
    309   if ( bpp > 0.1 )
    310   {
    311     return orgBits * 7;
    312   }
    313   return orgBits * 10;
    314 }
    315 #endif
    316 
    317 #if M0036_RC_IMPROVEMENT
    318273Void TEncRCSeq::setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB )
    319274{
     
    326281  delete[] bitsRatio;
    327282}
    328 #endif
    329283
    330284//GOP level
     
    349303  Int targetBits = xEstGOPTargetBits( encRCSeq, numPic );
    350304
    351 #if M0036_RC_IMPROVEMENT
    352305  if ( encRCSeq->getAdaptiveBits() > 0 && encRCSeq->getLastLambda() > 0.1 )
    353306  {
     
    409362    delete []equaCoeffB;
    410363  }
    411 #endif
    412364
    413365  m_picTargetBitInGOP = new Int[numPic];
     
    422374  {
    423375    currPicRatio = encRCSeq->getBitRatio( i );
    424 #if M0036_RC_IMPROVEMENT
    425376    m_picTargetBitInGOP[i] = (Int)( ((Double)targetBits) * currPicRatio / totalPicRatio );
    426 #else
    427     m_picTargetBitInGOP[i] = targetBits * currPicRatio / totalPicRatio;
    428 #endif
    429377  }
    430378
     
    436384}
    437385
    438 #if M0036_RC_IMPROVEMENT
    439386Void TEncRCGOP::xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize )
    440387{
     
    482429  return solution;
    483430}
    484 #endif
    485431
    486432Void TEncRCGOP::destroy()
     
    534480
    535481  m_LCUs         = NULL;
    536 #if !M0036_RC_IMPROVEMENT
    537   m_lastPicture  = NULL;
    538 #endif
    539482  m_picActualHeaderBits = 0;
    540 #if !M0036_RC_IMPROVEMENT
    541   m_totalMAD            = 0.0;
    542 #endif
    543483  m_picActualBits       = 0;
    544484  m_picQP               = 0;
     
    565505  }
    566506
    567 #if M0036_RC_IMPROVEMENT
    568507  targetBits  = Int( ((Double)GOPbitsLeft) * currPicRatio / totalPicRatio );
    569 #else
    570   targetBits  = Int( GOPbitsLeft * currPicRatio / totalPicRatio );
    571 #endif
    572508
    573509  if ( targetBits < 100 )
     
    665601      m_LCUs[LCUIdx].m_lambda     = 0.0;
    666602      m_LCUs[LCUIdx].m_targetBits = 0;
    667 #if M0036_RC_IMPROVEMENT
    668603      m_LCUs[LCUIdx].m_bitWeight  = 1.0;
    669 #else
    670       m_LCUs[LCUIdx].m_MAD        = 0.0;
    671 #endif
    672604      Int currWidth  = ( (i == picWidthInLCU -1) ? picWidth  - LCUWidth *(picWidthInLCU -1) : LCUWidth  );
    673605      Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
     
    676608  }
    677609  m_picActualHeaderBits = 0;
    678 #if !M0036_RC_IMPROVEMENT
    679   m_totalMAD            = 0.0;
    680 #endif
    681610  m_picActualBits       = 0;
    682611  m_picQP               = 0;
    683612  m_picLambda           = 0.0;
    684 
    685 #if !M0036_RC_IMPROVEMENT
    686   m_lastPicture = NULL;
    687   list<TEncRCPic*>::reverse_iterator it;
    688   for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
    689   {
    690     if ( (*it)->getFrameLevel() == m_frameLevel )
    691     {
    692       m_lastPicture = (*it);
    693       break;
    694     }
    695   }
    696 #endif
    697613}
    698614
     
    709625
    710626
    711 #if RATE_CONTROL_INTRA
    712627Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures, SliceType eSliceType)
    713 #else
    714 Double TEncRCPic::estimatePicLambda( list<TEncRCPic*>& listPreviousPictures )
    715 #endif
    716628{
    717629  Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    718630  Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    719631  Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
    720 #if RATE_CONTROL_INTRA
    721632  Double estLambda;
    722633  if (eSliceType == I_SLICE)
     
    728639    estLambda = alpha * pow( bpp, beta );
    729640  }
    730 #else
    731   Double estLambda = alpha * pow( bpp, beta );
    732 #endif 
    733641 
    734642  Double lastLevelLambda = -1.0;
     
    778686  m_estPicLambda = estLambda;
    779687
    780 #if M0036_RC_IMPROVEMENT
    781688  Double totalWeight = 0.0;
    782689  // initial BU bit allocation weight
    783690  for ( Int i=0; i<m_numberOfLCU; i++ )
    784691  {
    785 #if RC_FIX
    786692    Double alphaLCU, betaLCU;
    787693    if ( m_encRCSeq->getUseLCUSeparateModel() )
     
    795701      betaLCU  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    796702    }
    797 #else
    798     Double alphaLCU = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_alpha;
    799     Double betaLCU  = m_encRCSeq->getLCUPara( m_frameLevel, i ).m_beta;
    800 #endif
    801703
    802704    m_LCUs[i].m_bitWeight =  m_LCUs[i].m_numberOfPixel * pow( estLambda/alphaLCU, 1.0/betaLCU );
     
    813715    m_LCUs[i].m_bitWeight = BUTargetBits;
    814716  }
    815 #endif
    816717
    817718  return estLambda;
     
    856757}
    857758
    858 #if RATE_CONTROL_INTRA
    859759Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 
    860 #else
    861 Double TEncRCPic::getLCUTargetBpp()
    862 #endif
    863760{
    864761  Int   LCUIdx    = getLCUCoded();
    865762  Double bpp      = -1.0;
    866763  Int avgBits     = 0;
    867 #if !M0036_RC_IMPROVEMENT
    868   Double totalMAD = -1.0;
    869   Double MAD      = -1.0;
    870 #endif
    871 
    872 #if RATE_CONTROL_INTRA
    873   if (eSliceType == I_SLICE){
     764
     765  if (eSliceType == I_SLICE)
     766  {
    874767    Int noOfLCUsLeft = m_numberOfLCU - LCUIdx + 1;
    875768    Int bitrateWindow = min(4,noOfLCUsLeft);
     
    889782  else
    890783  {
    891 #endif
    892 #if M0036_RC_IMPROVEMENT
    893784  Double totalWeight = 0;
    894785  for ( Int i=LCUIdx; i<m_numberOfLCU; i++ )
     
    898789  Int realInfluenceLCU = min( g_RCLCUSmoothWindowSize, getLCULeft() );
    899790  avgBits = (Int)( m_LCUs[LCUIdx].m_bitWeight - ( totalWeight - m_bitsLeft ) / realInfluenceLCU + 0.5 );
    900 #else
    901   if ( m_lastPicture == NULL )
    902   {
    903     avgBits = Int( m_bitsLeft / m_LCULeft );
    904   }
    905   else
    906   {
    907     MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;
    908     totalMAD = m_lastPicture->getTotalMAD();
    909     for ( Int i=0; i<LCUIdx; i++ )
    910     {
    911       totalMAD -= m_lastPicture->getLCU(i).m_MAD;
    912     }
    913 
    914     if ( totalMAD > 0.1 )
    915     {
    916       avgBits = Int( m_bitsLeft * MAD / totalMAD );
    917     }
    918     else
    919     {
    920       avgBits = Int( m_bitsLeft / m_LCULeft );
    921     }
    922   }
    923 #endif
    924 #if RATE_CONTROL_INTRA
    925   }
    926 #endif
     791    }
    927792
    928793  if ( avgBits < 1 )
     
    1050915    beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
    1051916
    1052 #if M0036_RC_IMPROVEMENT
    1053917    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    1054918    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1055 #else
    1056     alpha = Clip3( 0.05, 20.0, alpha );
    1057     beta  = Clip3( -3.0, -0.1, beta  );
    1058 #endif
    1059919
    1060920    TRCParameter rcPara;
     
    1069929  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    1070930  double lnbpp = log( bpp );
    1071 #if M0036_RC_IMPROVEMENT
    1072931  lnbpp = Clip3( -5.0, -0.1, lnbpp );
    1073 #else
    1074   lnbpp = Clip3( -5.0, 1.0, lnbpp );
    1075 #endif
    1076932  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
    1077933
    1078 #if M0036_RC_IMPROVEMENT
    1079934  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    1080935  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1081 #else
    1082   alpha = Clip3( 0.05, 20.0, alpha );
    1083   beta  = Clip3( -3.0, -0.1, beta  );
    1084 #endif
    1085936  TRCParameter rcPara;
    1086937  rcPara.m_alpha = alpha;
     
    1090941}
    1091942
    1092 #if !M0036_RC_IMPROVEMENT
    1093 Double TEncRCPic::getEffectivePercentage()
    1094 {
    1095   Int effectivePiexels = 0;
    1096   Int totalPixels = 0;
    1097 
    1098   for ( Int i=0; i<m_numberOfLCU; i++ )
    1099   {
    1100     totalPixels += m_LCUs[i].m_numberOfPixel;
    1101     if ( m_LCUs[i].m_QP > 0 )
    1102     {
    1103       effectivePiexels += m_LCUs[i].m_numberOfPixel;
    1104     }
    1105   }
    1106 
    1107   Double effectivePixelPercentage = (Double)effectivePiexels/(Double)totalPixels;
    1108   return effectivePixelPercentage;
    1109 }
    1110 #endif
    1111 
    1112943Double TEncRCPic::calAverageQP()
    1113944{
     
    1164995}
    1165996
    1166 #if M0036_RC_IMPROVEMENT
    1167 #if RATE_CONTROL_INTRA
    1168997Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType)
    1169 #else
    1170 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda )
    1171 #endif
    1172 #else
    1173 Void TEncRCPic::updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage )
    1174 #endif
    1175998{
    1176999  m_picActualHeaderBits = actualHeaderBits;
     
    11851008  }
    11861009  m_picLambda           = averageLambda;
    1187 #if !M0036_RC_IMPROVEMENT
    1188   for ( Int i=0; i<m_numberOfLCU; i++ )
    1189   {
    1190     m_totalMAD += m_LCUs[i].m_MAD;
    1191   }
    1192 #endif
    11931010
    11941011  Double alpha = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
    11951012  Double beta  = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
    1196 #if RATE_CONTROL_INTRA
    11971013  if (eSliceType == I_SLICE)
    11981014  {
     
    12011017  else
    12021018  {
    1203 #endif
    12041019  // update parameters
    12051020  Double picActualBits = ( Double )m_picActualBits;
     
    12081023  Double inputLambda   = m_picLambda;
    12091024
    1210 #if M0036_RC_IMPROVEMENT
    12111025  if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 )
    1212 #else
    1213   if ( inputLambda < 0.01 || calLambda < 0.01 || picActualBpp < 0.0001 || effectivePercentage < 0.05 )
    1214 #endif
    12151026  {
    12161027    alpha *= ( 1.0 - m_encRCSeq->getAlphaUpdate() / 2.0 );
    12171028    beta  *= ( 1.0 - m_encRCSeq->getBetaUpdate() / 2.0 );
    12181029
    1219 #if M0036_RC_IMPROVEMENT
    12201030    alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    12211031    beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1222 #else
    1223     alpha = Clip3( 0.05, 20.0, alpha );
    1224     beta  = Clip3( -3.0, -0.1, beta  );
    1225 #endif
    12261032    TRCParameter rcPara;
    12271033    rcPara.m_alpha = alpha;
     
    12351041  alpha += m_encRCSeq->getAlphaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * alpha;
    12361042  double lnbpp = log( picActualBpp );
    1237 #if M0036_RC_IMPROVEMENT
    12381043  lnbpp = Clip3( -5.0, -0.1, lnbpp );
    1239 #else
    1240   lnbpp = Clip3( -5.0, 1.0, lnbpp );
    1241 #endif
    12421044  beta  += m_encRCSeq->getBetaUpdate() * ( log( inputLambda ) - log( calLambda ) ) * lnbpp;
    12431045
    1244 #if M0036_RC_IMPROVEMENT
    12451046  alpha = Clip3( g_RCAlphaMinValue, g_RCAlphaMaxValue, alpha );
    12461047  beta  = Clip3( g_RCBetaMinValue,  g_RCBetaMaxValue,  beta  );
    1247 #else
    1248   alpha = Clip3( 0.05, 20.0, alpha );
    1249   beta  = Clip3( -3.0, -0.1, beta  );
    1250 #endif
    1251 #if RATE_CONTROL_INTRA
    1252   }
    1253 #endif
     1048  }
    12541049
    12551050  TRCParameter rcPara;
     
    12591054  m_encRCSeq->setPicPara( m_frameLevel, rcPara );
    12601055
    1261 #if M0036_RC_IMPROVEMENT
    12621056  if ( m_frameLevel == 1 )
    12631057  {
     
    12661060    m_encRCSeq->setLastLambda( updateLastLambda );
    12671061  }
    1268 #endif
    1269 }
    1270 
    1271 #if RATE_CONTROL_INTRA
     1062}
     1063
    12721064Int TEncRCPic::getRefineBitsForIntra( Int orgBits )
    12731065{
     
    13581150  return estLambda;
    13591151}
    1360 #endif
    13611152
    13621153TEncRateCtrl::TEncRateCtrl()
     
    13921183}
    13931184
    1394 #if M0036_RC_IMPROVEMENT
    13951185Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
    1396 #else
    1397 Void TEncRateCtrl::init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry  GOPList[MAX_GOP] )
    1398 #endif
    13991186{
    14001187  destroy();
     
    14111198
    14121199  Int numberOfLevel = 1;
    1413 #if M0036_RC_IMPROVEMENT
    14141200  Int adaptiveBit = 0;
    14151201  if ( keepHierBits > 0 )
    1416 #else
    1417   if ( keepHierBits )
    1418 #endif
    14191202  {
    14201203    numberOfLevel = Int( log((Double)GOPSize)/log(2.0) + 0.5 ) + 1;
     
    14391222  }
    14401223
    1441 #if M0036_RC_IMPROVEMENT
    14421224  if ( keepHierBits > 0 )
    1443 #else
    1444   if ( keepHierBits )
    1445 #endif
    14461225  {
    14471226    Double bpp = (Double)( targetBitrate / (Double)( frameRate*picWidth*picHeight ) );
     
    14761255        bitsRatio[3] = 14;
    14771256      }
    1478 #if M0036_RC_IMPROVEMENT
    14791257      if ( keepHierBits == 2 )
    14801258      {
    14811259        adaptiveBit = 1;
    14821260      }
    1483 #endif
    14841261    }
    14851262    else if ( GOPSize == 8 && !isLowdelay )
     
    15291306        bitsRatio[7] = 1;
    15301307      }
    1531 #if M0036_RC_IMPROVEMENT
    15321308      if ( keepHierBits == 2 )
    15331309      {
    15341310        adaptiveBit = 2;
    15351311      }
    1536 #endif
    15371312    }
    15381313    else
    15391314    {
    1540 #if M0036_RC_IMPROVEMENT
    15411315      printf( "\n hierarchical bit allocation is not support for the specified coding structure currently.\n" );
    1542 #else
    1543       printf( "\n hierarchical bit allocation is not support for the specified coding structure currently." );
    1544 #endif
    15451316    }
    15461317  }
     
    15551326    }
    15561327  }
    1557 #if M0036_RC_IMPROVEMENT
    15581328  if ( keepHierBits > 0 )
    1559 #else
    1560   if ( keepHierBits )
    1561 #endif
    15621329  {
    15631330    if ( GOPSize == 4 && isLowdelay )
     
    15941361
    15951362  m_encRCSeq = new TEncRCSeq;
    1596 #if M0036_RC_IMPROVEMENT
    15971363  m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel, adaptiveBit );
    1598 #else
    1599   m_encRCSeq->create( totalFrames, targetBitrate, frameRate, GOPSize, picWidth, picHeight, LCUWidth, LCUHeight, numberOfLevel, useLCUSeparateModel );
    1600 #endif
    16011364  m_encRCSeq->initBitsRatio( bitsRatio );
    16021365  m_encRCSeq->initGOPID2Level( GOPID2Level );
     
    16291392}
    16301393
    1631 #else
    1632 
    1633 #define ADJUSTMENT_FACTOR       0.60
    1634 #define HIGH_QSTEP_THRESHOLD    9.5238
    1635 #define HIGH_QSTEP_ALPHA        4.9371
    1636 #define HIGH_QSTEP_BETA         0.0922
    1637 #define LOW_QSTEP_ALPHA         16.7429
    1638 #define LOW_QSTEP_BETA          -1.1494
    1639 
    1640 #define MAD_PRED_Y1             1.0
    1641 #define MAD_PRED_Y2             0.0
    1642 
    1643 enum MAD_HISOTRY {
    1644   MAD_PPPrevious = 0,
    1645   MAD_PPrevious  = 1,
    1646   MAD_Previous   = 2
    1647 };
    1648 
    1649 Void    MADLinearModel::initMADLinearModel()
    1650 {
    1651   m_activeOn = false;
    1652   m_paramY1  = 1.0;
    1653   m_paramY2  = 0.0;
    1654   m_costMADs[0] = m_costMADs[1] = m_costMADs[2] = 0.0;
    1655 }
    1656 
    1657 Double  MADLinearModel::getMAD()
    1658 {
    1659   Double costPredMAD = m_paramY1 * m_costMADs[MAD_Previous] + m_paramY2;
    1660 
    1661   if(costPredMAD < 0)
    1662   {
    1663     costPredMAD = m_costMADs[MAD_Previous];
    1664     m_paramY1   = MAD_PRED_Y1;
    1665     m_paramY2   = MAD_PRED_Y2;
    1666   }
    1667   return costPredMAD;
    1668 }
    1669 
    1670 Void    MADLinearModel::updateMADLiearModel()
    1671 {
    1672   Double dNewY1 = ((m_costMADs[MAD_Previous] - m_costMADs[MAD_PPrevious]) / (m_costMADs[MAD_PPrevious] - m_costMADs[MAD_PPPrevious]));
    1673   Double dNewY2 =  (m_costMADs[MAD_Previous] - (dNewY1*m_costMADs[MAD_PPrevious]));
    1674  
    1675   m_paramY1 = 0.70+0.20*m_paramY1+ 0.10*dNewY1;
    1676   m_paramY2 =      0.20*m_paramY2+ 0.10*dNewY2;
    1677 }
    1678 
    1679 Void    MADLinearModel::updateMADHistory(Double dMAD)
    1680 {
    1681   m_costMADs[MAD_PPPrevious] = m_costMADs[MAD_PPrevious];
    1682   m_costMADs[MAD_PPrevious ] = m_costMADs[MAD_Previous ];
    1683   m_costMADs[MAD_Previous  ] = dMAD;
    1684   m_activeOn = (m_costMADs[MAD_Previous  ] && m_costMADs[MAD_PPrevious ] && m_costMADs[MAD_PPPrevious]);
    1685 }
    1686 
    1687 
    1688 Void    PixelBaseURQQuadraticModel::initPixelBaseQuadraticModel()
    1689 {
    1690   m_paramHighX1 = HIGH_QSTEP_ALPHA;
    1691   m_paramHighX2 = HIGH_QSTEP_BETA;
    1692   m_paramLowX1  = LOW_QSTEP_ALPHA;
    1693   m_paramLowX2  = LOW_QSTEP_BETA;
    1694 }
    1695 
    1696 Int     PixelBaseURQQuadraticModel::getQP(Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD)
    1697 {
    1698   Double qStep;
    1699   Double bppPerMAD = (Double)(targetBits/(numberOfPixels*costPredMAD));
    1700  
    1701   if(xConvertQP2QStep(qp) >= HIGH_QSTEP_THRESHOLD)
    1702   {
    1703     qStep = 1/( sqrt((bppPerMAD/m_paramHighX1)+((m_paramHighX2*m_paramHighX2)/(4*m_paramHighX1*m_paramHighX1))) - (m_paramHighX2/(2*m_paramHighX1)));
    1704   }
    1705   else
    1706   {
    1707     qStep = 1/( sqrt((bppPerMAD/m_paramLowX1)+((m_paramLowX2*m_paramLowX2)/(4*m_paramLowX1*m_paramLowX1))) - (m_paramLowX2/(2*m_paramLowX1)));
    1708   }
    1709  
    1710   return xConvertQStep2QP(qStep);
    1711 }
    1712 
    1713 Void    PixelBaseURQQuadraticModel::updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD)
    1714 {
    1715   Double qStep     = xConvertQP2QStep(qp);
    1716   Double invqStep = (1/qStep);
    1717   Double paramNewX1, paramNewX2;
    1718  
    1719   if(qStep >= HIGH_QSTEP_THRESHOLD)
    1720   {
    1721     paramNewX2    = (((bits/(numberOfPixels*costMAD))-(23.3772*invqStep*invqStep))/((1-200*invqStep)*invqStep));
    1722     paramNewX1    = (23.3772-200*paramNewX2);
    1723     m_paramHighX1 = 0.70*HIGH_QSTEP_ALPHA + 0.20 * m_paramHighX1 + 0.10 * paramNewX1;
    1724     m_paramHighX2 = 0.70*HIGH_QSTEP_BETA  + 0.20 * m_paramHighX2 + 0.10 * paramNewX2;
    1725   }
    1726   else
    1727   {
    1728     paramNewX2   = (((bits/(numberOfPixels*costMAD))-(5.8091*invqStep*invqStep))/((1-9.5455*invqStep)*invqStep));
    1729     paramNewX1   = (5.8091-9.5455*paramNewX2);
    1730     m_paramLowX1 = 0.90*LOW_QSTEP_ALPHA + 0.09 * m_paramLowX1 + 0.01 * paramNewX1;
    1731     m_paramLowX2 = 0.90*LOW_QSTEP_BETA  + 0.09 * m_paramLowX2 + 0.01 * paramNewX2;
    1732   }
    1733 }
    1734 
    1735 Bool    PixelBaseURQQuadraticModel::checkUpdateAvailable(Int qpReference )
    1736 {
    1737   Double qStep = xConvertQP2QStep(qpReference);
    1738 
    1739   if (qStep > xConvertQP2QStep(MAX_QP)
    1740     ||qStep < xConvertQP2QStep(MIN_QP) )
    1741   {
    1742     return false;
    1743   }
    1744 
    1745   return true;
    1746 }
    1747 
    1748 Double  PixelBaseURQQuadraticModel::xConvertQP2QStep(Int qp )
    1749 {
    1750   Int i;
    1751   Double qStep;
    1752   static const Double mapQP2QSTEP[6] = { 0.625, 0.703, 0.797, 0.891, 1.000, 1.125 };
    1753 
    1754   qStep = mapQP2QSTEP[qp % 6];
    1755   for( i=0; i<(qp/6); i++)
    1756   {
    1757     qStep *= 2;
    1758   }
    1759 
    1760   return qStep;
    1761 }
    1762 
    1763 Int     PixelBaseURQQuadraticModel::xConvertQStep2QP(Double qStep )
    1764 {
    1765   Int per = 0, rem = 0;
    1766 
    1767   if( qStep < xConvertQP2QStep(MIN_QP))
    1768   {
    1769     return MIN_QP;
    1770   }
    1771   else if (qStep > xConvertQP2QStep(MAX_QP) )
    1772   {
    1773     return MAX_QP;
    1774   }
    1775 
    1776   while( qStep > xConvertQP2QStep(5) )
    1777   {
    1778     qStep /= 2.0;
    1779     per++;
    1780   }
    1781 
    1782   if (qStep <= 0.625)
    1783   {
    1784     rem = 0;
    1785   }
    1786   else if (qStep <= 0.703)
    1787   {
    1788     rem = 1;
    1789   }
    1790   else if (qStep <= 0.797)
    1791   {
    1792     rem = 2;
    1793   }
    1794   else if (qStep <= 0.891)
    1795   {
    1796     rem = 3;
    1797   }
    1798   else if (qStep <= 1.000)
    1799   {
    1800     rem = 4;
    1801   }
    1802   else
    1803   {
    1804     rem = 5;
    1805   }
    1806   return (per * 6 + rem);
    1807 }
    1808 
    1809 
    1810 Void  TEncRateCtrl::create(Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight)
    1811 {
    1812   Int leftInHeight, leftInWidth;
    1813 
    1814   m_sourceWidthInLCU         = (sourceWidth  / maxCUWidth  ) + (( sourceWidth  %  maxCUWidth ) ? 1 : 0);
    1815   m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0); 
    1816   m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
    1817   m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
    1818   m_currBitrate              = ( targetKbps << 10 );
    1819   m_frameRate                = frameRate;
    1820   m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
    1821   m_nonRefFrameNum           = sizeGOP-m_refFrameNum;
    1822   m_sizeGOP                  = sizeGOP;
    1823   m_numOfPixels              = ((sourceWidth*sourceHeight*3)>>1);
    1824   m_indexGOP                 = 0;
    1825   m_indexFrame               = 0;
    1826   m_indexLCU                 = 0;
    1827   m_indexUnit                = 0;
    1828   m_indexRefFrame            = 0;
    1829   m_indexNonRefFrame         = 0;
    1830   m_occupancyVB              = 0;
    1831   m_initialOVB               = 0;
    1832   m_targetBufLevel           = 0;
    1833   m_initialTBL               = 0;
    1834   m_occupancyVBInFrame       = 0;
    1835   m_remainingBitsInGOP       = (m_currBitrate*sizeGOP/m_frameRate);
    1836   m_remainingBitsInFrame     = 0;
    1837   m_numUnitInFrame           = m_sourceWidthInLCU*m_sourceHeightInLCU;
    1838   m_cMADLinearModel.        initMADLinearModel();
    1839   m_cPixelURQQuadraticModel.initPixelBaseQuadraticModel();
    1840 
    1841   m_costRefAvgWeighting      = 0.0;
    1842   m_costNonRefAvgWeighting   = 0.0;
    1843   m_costAvgbpp               = 0.0; 
    1844   m_activeUnitLevelOn        = false;
    1845 
    1846   m_pcFrameData              = new FrameData   [sizeGOP+1];         initFrameData(qp);
    1847   m_pcLCUData                = new LCUData     [m_numUnitInFrame];  initUnitData (qp);
    1848 
    1849   for(Int i = 0, addressUnit = 0; i < m_sourceHeightInLCU*maxCUHeight; i += maxCUHeight) 
    1850   {
    1851     leftInHeight = sourceHeight - i;
    1852     leftInHeight = min(leftInHeight, maxCUHeight);
    1853     for(Int j = 0; j < m_sourceWidthInLCU*maxCUWidth; j += maxCUWidth, addressUnit++)
    1854     {
    1855       leftInWidth = sourceWidth - j;
    1856       leftInWidth = min(leftInWidth, maxCUWidth);
    1857       m_pcLCUData[addressUnit].m_widthInPixel = leftInWidth;
    1858       m_pcLCUData[addressUnit].m_heightInPixel= leftInHeight;
    1859       m_pcLCUData[addressUnit].m_pixels       = ((leftInHeight*leftInWidth*3)>>1);
    1860     }
    1861   }
    1862 }
    1863 
    1864 Void  TEncRateCtrl::destroy()
    1865 {
    1866   if(m_pcFrameData)
    1867   {
    1868     delete [] m_pcFrameData;
    1869     m_pcFrameData = NULL;
    1870   }
    1871   if(m_pcLCUData)
    1872   {
    1873     delete [] m_pcLCUData;
    1874     m_pcLCUData = NULL;
    1875   }
    1876 }
    1877 
    1878 Void  TEncRateCtrl::initFrameData   (Int qp)
    1879 {
    1880   for(Int i = 0 ; i <= m_sizeGOP; i++)
    1881   {
    1882     m_pcFrameData[i].m_isReferenced = false;
    1883     m_pcFrameData[i].m_costMAD      = 0.0;
    1884     m_pcFrameData[i].m_bits         = 0;
    1885     m_pcFrameData[i].m_qp           = qp;
    1886   }
    1887 }
    1888 
    1889 Void  TEncRateCtrl::initUnitData    (Int qp)
    1890 {
    1891   for(Int i = 1 ; i < m_numUnitInFrame; i++)
    1892   {
    1893     m_pcLCUData[i].m_qp            = qp;
    1894     m_pcLCUData[i].m_bits          = 0;
    1895     m_pcLCUData[i].m_pixels        = 0;
    1896     m_pcLCUData[i].m_widthInPixel  = 0;
    1897     m_pcLCUData[i].m_heightInPixel = 0;
    1898     m_pcLCUData[i].m_costMAD       = 0.0;
    1899   }
    1900 }
    1901 
    1902 Int  TEncRateCtrl::getFrameQP(Bool isReferenced, Int POC)
    1903 {
    1904   Int numofReferenced = 0;
    1905   Int finalQP = 0;
    1906   FrameData* pcFrameData;
    1907 
    1908   m_indexPOCInGOP = (POC%m_sizeGOP) == 0 ? m_sizeGOP : (POC%m_sizeGOP);
    1909   pcFrameData     = &m_pcFrameData[m_indexPOCInGOP];
    1910    
    1911   if(m_indexFrame != 0)
    1912   {
    1913     if(isReferenced)
    1914     {
    1915       Double gamma = m_isLowdelay ? 0.5 : 0.25;
    1916       Double beta  = m_isLowdelay ? 0.9 : 0.6;
    1917       Int    numRemainingRefFrames  = m_refFrameNum    - m_indexRefFrame;
    1918       Int    numRemainingNRefFrames = m_nonRefFrameNum - m_indexNonRefFrame;
    1919      
    1920       Double targetBitsOccupancy  = (m_currBitrate/(Double)m_frameRate) + gamma*(m_targetBufLevel-m_occupancyVB - (m_initialOVB/(Double)m_frameRate));
    1921       Double targetBitsLeftBudget = ((m_costRefAvgWeighting*m_remainingBitsInGOP)/((m_costRefAvgWeighting*numRemainingRefFrames)+(m_costNonRefAvgWeighting*numRemainingNRefFrames)));
    1922 
    1923       m_targetBits = (Int)(beta * targetBitsLeftBudget + (1-beta) * targetBitsOccupancy);
    1924  
    1925       if(m_targetBits <= 0 || m_remainingBitsInGOP <= 0)
    1926       {
    1927         finalQP = m_pcFrameData[m_indexPrevPOCInGOP].m_qp + 2;
    1928       }
    1929       else
    1930       {
    1931         Double costPredMAD   = m_cMADLinearModel.getMAD();
    1932         Int    qpLowerBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp-2;
    1933         Int    qpUpperBound = m_pcFrameData[m_indexPrevPOCInGOP].m_qp+2;
    1934         finalQP = m_cPixelURQQuadraticModel.getQP(m_pcFrameData[m_indexPrevPOCInGOP].m_qp, m_targetBits, m_numOfPixels, costPredMAD);
    1935         finalQP = max(qpLowerBound, min(qpUpperBound, finalQP));
    1936         m_activeUnitLevelOn    = true;
    1937         m_remainingBitsInFrame = m_targetBits;
    1938         m_costAvgbpp           = (m_targetBits/(Double)m_numOfPixels);
    1939       }
    1940 
    1941       m_indexRefFrame++;
    1942     }
    1943     else
    1944     {
    1945       Int bwdQP = m_pcFrameData[m_indexPOCInGOP-1].m_qp;
    1946       Int fwdQP = m_pcFrameData[m_indexPOCInGOP+1].m_qp;
    1947        
    1948       if( (fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP-1].m_qp
    1949         ||(fwdQP+bwdQP) == m_pcFrameData[m_indexPOCInGOP+1].m_qp)
    1950       {
    1951         finalQP = (fwdQP+bwdQP);
    1952       }
    1953       else if(bwdQP != fwdQP)
    1954       {
    1955         finalQP = ((bwdQP+fwdQP+2)>>1);
    1956       }
    1957       else
    1958       {
    1959         finalQP = bwdQP+2;
    1960       }
    1961       m_indexNonRefFrame++;
    1962     }
    1963   }
    1964   else
    1965   {
    1966     Int lastQPminus2 = m_pcFrameData[0].m_qp - 2;
    1967     Int lastQPplus2  = m_pcFrameData[0].m_qp + 2;
    1968 
    1969     for(Int idx = 1; idx <= m_sizeGOP; idx++)
    1970     {
    1971       if(m_pcFrameData[idx].m_isReferenced)
    1972       {
    1973         finalQP += m_pcFrameData[idx].m_qp;
    1974         numofReferenced++;
    1975       }
    1976     }
    1977    
    1978     finalQP = (numofReferenced == 0) ? m_pcFrameData[0].m_qp : ((finalQP + (1<<(numofReferenced>>1)))/numofReferenced);
    1979     finalQP = max( lastQPminus2, min( lastQPplus2, finalQP));
    1980 
    1981     Double costAvgFrameBits = m_remainingBitsInGOP/(Double)m_sizeGOP;
    1982     Int    bufLevel  = m_occupancyVB + m_initialOVB;
    1983 
    1984     if(abs(bufLevel) > costAvgFrameBits)
    1985     {
    1986       if(bufLevel < 0)
    1987       {
    1988         finalQP -= 2;
    1989       }
    1990       else
    1991       {
    1992         finalQP += 2;
    1993       }
    1994     }
    1995     m_indexRefFrame++;
    1996   }
    1997   finalQP = max(MIN_QP, min(MAX_QP, finalQP));
    1998 
    1999   for(Int indexLCU = 0 ; indexLCU < m_numUnitInFrame; indexLCU++)
    2000   {
    2001     m_pcLCUData[indexLCU].m_qp = finalQP;
    2002   }
    2003 
    2004   pcFrameData->m_isReferenced = isReferenced;
    2005   pcFrameData->m_qp           = finalQP;
    2006 
    2007   return finalQP;
    2008 }
    2009 
    2010 Bool  TEncRateCtrl::calculateUnitQP ()
    2011 {
    2012   if(!m_activeUnitLevelOn || m_indexLCU == 0)
    2013   {
    2014     return false;
    2015   }
    2016   Int upperQPBound, lowerQPBound, finalQP;
    2017   Int    colQP        = m_pcLCUData[m_indexLCU].m_qp;
    2018   Double colMAD       = m_pcLCUData[m_indexLCU].m_costMAD;
    2019   Double budgetInUnit = m_pcLCUData[m_indexLCU].m_pixels*m_costAvgbpp;
    2020 
    2021 
    2022   Int targetBitsOccupancy = (Int)(budgetInUnit - (m_occupancyVBInFrame/(m_numUnitInFrame-m_indexUnit)));
    2023   Int targetBitsLeftBudget= (Int)((m_remainingBitsInFrame*m_pcLCUData[m_indexLCU].m_pixels)/(Double)(m_numOfPixels-m_codedPixels));
    2024   Int targetBits = (targetBitsLeftBudget>>1) + (targetBitsOccupancy>>1);
    2025  
    2026 
    2027   if( m_indexLCU >= m_sourceWidthInLCU)
    2028   {
    2029     upperQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) + MAX_DELTA_QP;
    2030     lowerQPBound = ( (m_pcLCUData[m_indexLCU-1].m_qp + m_pcLCUData[m_indexLCU - m_sourceWidthInLCU].m_qp)>>1) - MAX_DELTA_QP;
    2031   }
    2032   else
    2033   {
    2034     upperQPBound = m_pcLCUData[m_indexLCU-1].m_qp + MAX_DELTA_QP;
    2035     lowerQPBound = m_pcLCUData[m_indexLCU-1].m_qp - MAX_DELTA_QP;
    2036   }
    2037 
    2038   if(targetBits < 0)
    2039   {
    2040     finalQP = m_pcLCUData[m_indexLCU-1].m_qp + 1;
    2041   }
    2042   else
    2043   {
    2044     finalQP = m_cPixelURQQuadraticModel.getQP(colQP, targetBits, m_pcLCUData[m_indexLCU].m_pixels, colMAD);
    2045   }
    2046  
    2047   finalQP = max(lowerQPBound, min(upperQPBound, finalQP));
    2048   m_pcLCUData[m_indexLCU].m_qp = max(MIN_QP, min(MAX_QP, finalQP));
    2049  
    2050   return true;
    2051 }
    2052 
    2053 Void  TEncRateCtrl::updateRCGOPStatus()
    2054 {
    2055   m_remainingBitsInGOP = ((m_currBitrate/m_frameRate)*m_sizeGOP) - m_occupancyVB;
    2056  
    2057   FrameData cFrameData = m_pcFrameData[m_sizeGOP];
    2058   initFrameData();
    2059 
    2060   m_pcFrameData[0]   = cFrameData;
    2061   m_indexGOP++;
    2062   m_indexFrame       = 0;
    2063   m_indexRefFrame    = 0;
    2064   m_indexNonRefFrame = 0;
    2065 }
    2066 
    2067 Void  TEncRateCtrl::updataRCFrameStatus(Int frameBits, SliceType eSliceType)
    2068 {
    2069   FrameData* pcFrameData = &m_pcFrameData[m_indexPOCInGOP];
    2070   Int occupancyBits;
    2071   Double adjustmentBits;
    2072 
    2073   m_remainingBitsInGOP = m_remainingBitsInGOP + ( ((m_currBitrate-m_prevBitrate)/m_frameRate)*(m_sizeGOP-m_indexFrame) ) - frameBits;
    2074   occupancyBits        = (Int)((Double)frameBits - (m_currBitrate/(Double)m_frameRate));
    2075  
    2076   if( (occupancyBits < 0) && (m_initialOVB > 0) )
    2077   {
    2078     adjustmentBits = xAdjustmentBits(occupancyBits, m_initialOVB );
    2079 
    2080     if(m_initialOVB < 0)
    2081     {
    2082       adjustmentBits = m_initialOVB;
    2083       occupancyBits += (Int)adjustmentBits;
    2084       m_initialOVB   =  0;
    2085     }
    2086   }
    2087   else if( (occupancyBits > 0) && (m_initialOVB < 0) )
    2088   {
    2089     adjustmentBits = xAdjustmentBits(m_initialOVB, occupancyBits );
    2090    
    2091     if(occupancyBits < 0)
    2092     {
    2093       adjustmentBits = occupancyBits;
    2094       m_initialOVB  += (Int)adjustmentBits;
    2095       occupancyBits  =  0;
    2096     }
    2097   }
    2098 
    2099   if(m_indexGOP == 0)
    2100   {
    2101     m_initialOVB = occupancyBits;
    2102   }
    2103   else
    2104   {
    2105     m_occupancyVB= m_occupancyVB + occupancyBits;
    2106   }
    2107 
    2108   if(pcFrameData->m_isReferenced)
    2109   {
    2110     m_costRefAvgWeighting  = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costRefAvgWeighting)/8.0);
    2111 
    2112     if(m_indexFrame == 0)
    2113     {
    2114       m_initialTBL = m_targetBufLevel  = (frameBits - (m_currBitrate/m_frameRate));
    2115     }
    2116     else
    2117     {
    2118       Int distance = (m_costNonRefAvgWeighting == 0) ? 0 : 1;
    2119       m_targetBufLevel =  m_targetBufLevel
    2120                             - (m_initialTBL/(m_refFrameNum-1))
    2121                             + (Int)((m_costRefAvgWeighting*(distance+1)*m_currBitrate)/(m_frameRate*(m_costRefAvgWeighting+(m_costNonRefAvgWeighting*distance))))
    2122                             - (m_currBitrate/m_frameRate);
    2123     }
    2124 
    2125     if(m_cMADLinearModel.IsUpdateAvailable())
    2126     {
    2127       m_cMADLinearModel.updateMADLiearModel();
    2128     }
    2129 
    2130     if(eSliceType != I_SLICE &&
    2131        m_cPixelURQQuadraticModel.checkUpdateAvailable(pcFrameData->m_qp))
    2132     {
    2133       m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(pcFrameData->m_qp, pcFrameData->m_bits, m_numOfPixels, pcFrameData->m_costMAD);
    2134     }
    2135   }
    2136   else
    2137   {
    2138     m_costNonRefAvgWeighting = ((pcFrameData->m_bits*pcFrameData->m_qp)/8.0) + (7.0*(m_costNonRefAvgWeighting)/8.0);
    2139   }
    2140 
    2141   m_indexFrame++;
    2142   m_indexLCU             = 0;
    2143   m_indexUnit            = 0;
    2144   m_occupancyVBInFrame   = 0;
    2145   m_remainingBitsInFrame = 0;
    2146   m_codedPixels          = 0;
    2147   m_activeUnitLevelOn    = false;
    2148   m_costAvgbpp           = 0.0;
    2149 }
    2150 Void  TEncRateCtrl::updataRCUnitStatus ()
    2151 {
    2152   if(!m_activeUnitLevelOn || m_indexLCU == 0)
    2153   {
    2154     return;
    2155   }
    2156 
    2157   m_codedPixels  += m_pcLCUData[m_indexLCU-1].m_pixels;
    2158   m_remainingBitsInFrame = m_remainingBitsInFrame - m_pcLCUData[m_indexLCU-1].m_bits;
    2159   m_occupancyVBInFrame   = (Int)(m_occupancyVBInFrame + m_pcLCUData[m_indexLCU-1].m_bits - m_pcLCUData[m_indexLCU-1].m_pixels*m_costAvgbpp);
    2160 
    2161   if( m_cPixelURQQuadraticModel.checkUpdateAvailable(m_pcLCUData[m_indexLCU-1].m_qp) )
    2162   {
    2163     m_cPixelURQQuadraticModel.updatePixelBasedURQQuadraticModel(m_pcLCUData[m_indexLCU-1].m_qp, m_pcLCUData[m_indexLCU-1].m_bits, m_pcLCUData[m_indexLCU-1].m_pixels, m_pcLCUData[m_indexLCU-1].m_costMAD);
    2164   }
    2165 
    2166   m_indexUnit++;
    2167 }
    2168 
    2169 Void  TEncRateCtrl::updateFrameData(UInt64 actualFrameBits)
    2170 {
    2171   Double costMAD = 0.0;
    2172  
    2173   for(Int i = 0; i < m_numUnitInFrame; i++)
    2174   {
    2175     costMAD    += m_pcLCUData[i].m_costMAD;
    2176   }
    2177  
    2178   m_pcFrameData[m_indexPOCInGOP].m_costMAD = (costMAD/(Double)m_numUnitInFrame);
    2179   m_pcFrameData[m_indexPOCInGOP].m_bits    = (Int)actualFrameBits;
    2180  
    2181   if(m_pcFrameData[m_indexPOCInGOP].m_isReferenced)
    2182   {
    2183     m_indexPrevPOCInGOP = m_indexPOCInGOP;
    2184     m_cMADLinearModel.updateMADHistory(m_pcFrameData[m_indexPOCInGOP].m_costMAD);
    2185   }
    2186 }
    2187 
    2188 Void  TEncRateCtrl::updateLCUData(TComDataCU* pcCU, UInt64 actualLCUBits, Int qp)
    2189 {
    2190   Int     x, y;
    2191   Double  costMAD = 0.0;
    2192 
    2193   Pel*  pOrg   = pcCU->getPic()->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
    2194   Pel*  pRec   = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
    2195   Int   stride = pcCU->getPic()->getStride();
    2196 
    2197   Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
    2198   Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
    2199 
    2200   for( y = 0; y < height; y++ )
    2201   {
    2202     for( x = 0; x < width; x++ )
    2203     {
    2204       costMAD += abs( pOrg[x] - pRec[x] );
    2205     }
    2206     pOrg += stride;
    2207     pRec += stride;
    2208   }
    2209   m_pcLCUData[m_indexLCU  ].m_qp      = qp;
    2210   m_pcLCUData[m_indexLCU  ].m_costMAD = (costMAD /(Double)(width*height));
    2211   m_pcLCUData[m_indexLCU++].m_bits    = (Int)actualLCUBits;
    2212 }
    2213 
    2214 Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)
    2215 {
    2216   Double adjustment  = ADJUSTMENT_FACTOR*reductionBits;
    2217   reductionBits     -= (Int)adjustment;
    2218   compensationBits  += (Int)adjustment;
    2219 
    2220   return adjustment;
    2221 }
    2222 
    2223 #endif
    2224 
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.h

    r313 r540  
    5555//! \{
    5656
    57 #if RATE_CONTROL_LAMBDA_DOMAIN
    5857#include "../TLibEncoder/TEncCfg.h"
    5958#include <list>
     
    6564const Double g_RCWeightPicTargetBitInGOP    = 0.9;
    6665const Double g_RCWeightPicRargetBitInBuffer = 1.0 - g_RCWeightPicTargetBitInGOP;
    67 #if M0036_RC_IMPROVEMENT
    6866const Int g_RCIterationNum = 20;
    6967const Double g_RCWeightHistoryLambda = 0.5;
     
    7472const Double g_RCBetaMinValue  = -3.0;
    7573const Double g_RCBetaMaxValue  = -0.1;
    76 #endif
    77 
    78 #if RATE_CONTROL_INTRA
     74
    7975#define ALPHA     6.7542;
    8076#define BETA1     1.2517
    8177#define BETA2     1.7860
    82 #endif
    8378
    8479struct TRCLCU
     
    8883  Int m_targetBits;
    8984  Double m_lambda;
    90 #if M0036_RC_IMPROVEMENT
    9185  Double m_bitWeight;
    92 #else
    93   Double m_MAD;
    94 #endif
    9586  Int m_numberOfPixel;
    96 #if RATE_CONTROL_INTRA
    9787  Double m_costIntra;
    9888  Int m_targetBitsLeft;
    99 #endif
    10089};
    10190
     
    113102
    114103public:
    115 #if M0036_RC_IMPROVEMENT
    116104  Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit );
    117 #else
    118   Void create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel );
    119 #endif
    120105  Void destroy();
    121106  Void initBitsRatio( Int bitsRatio[] );
     
    124109  Void initLCUPara( TRCParameter** LCUPara = NULL );    // NULL to initial with default value
    125110  Void updateAfterPic ( Int bits );
    126 #if !RATE_CONTROL_INTRA
    127   Int  getRefineBitsForIntra( Int orgBits );
    128 #endif
    129 #if M0036_RC_IMPROVEMENT
    130111  Void setAllBitRatio( Double basicLambda, Double* equaCoeffA, Double* equaCoeffB );
    131 #endif
    132112
    133113public:
     
    167147  Double getBetaUpdate()                { return m_betaUpdate; }
    168148
    169 #if M0036_RC_IMPROVEMENT
    170149  Int    getAdaptiveBits()              { return m_adaptiveBit;  }
    171150  Double getLastLambda()                { return m_lastLambda;   }
    172151  Void   setLastLambda( Double lamdba ) { m_lastLambda = lamdba; }
    173 #endif
    174152
    175153private:
     
    200178  Bool m_useLCUSeparateModel;
    201179
    202 #if M0036_RC_IMPROVEMENT
    203180  Int m_adaptiveBit;
    204181  Double m_lastLambda;
    205 #endif
    206182};
    207183
     
    219195private:
    220196  Int  xEstGOPTargetBits( TEncRCSeq* encRCSeq, Int GOPSize );
    221 #if M0036_RC_IMPROVEMENT
    222197  Void   xCalEquaCoeff( TEncRCSeq* encRCSeq, Double* lambdaRatio, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
    223198  Double xSolveEqua( Double targetBpp, Double* equaCoeffA, Double* equaCoeffB, Int GOPSize );
    224 #endif
    225199
    226200public:
     
    251225  Void destroy();
    252226
    253 #if !RATE_CONTROL_INTRA
    254   Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );
    255 #endif
    256227  Int    estimatePicQP    ( Double lambda, list<TEncRCPic*>& listPreviousPictures );
    257 #if RATE_CONTROL_INTRA
    258228  Int    getRefineBitsForIntra(Int orgBits);
    259229  Double calculateLambdaIntra(double alpha, double beta, double MADPerPixel, double bitsPerPixel);
     
    264234  Double getLCUTargetBpp(SliceType eSliceType);
    265235  Double getLCUEstLambdaAndQP(Double bpp, Int clipPicQP, Int *estQP);
    266 #else
    267   Double getLCUTargetBpp();
    268 #endif
    269236  Double getLCUEstLambda( Double bpp );
    270237  Int    getLCUEstQP( Double lambda, Int clipPicQP );
    271238
    272239  Void updateAfterLCU( Int LCUIdx, Int bits, Int QP, Double lambda, Bool updateLCUParameter = true );
    273 #if M0036_RC_IMPROVEMENT
    274 #if RATE_CONTROL_INTRA
    275240  Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, SliceType eSliceType);
    276 #else
    277   Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda );
    278 #endif
    279 #else
    280   Void updateAfterPicture( Int actualHeaderBits, Int actualTotalBits, Double averageQP, Double averageLambda, Double effectivePercentage );
    281 #endif
    282241
    283242  Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures );
    284 #if !M0036_RC_IMPROVEMENT
    285   Double getEffectivePercentage();
    286 #endif
    287243  Double calAverageQP();
    288244  Double calAverageLambda();
     
    300256  Int  getNumberOfLCU()                                   { return m_numberOfLCU; }
    301257  Int  getTargetBits()                                    { return m_targetBits; }
    302 #if !RATE_CONTROL_INTRA
    303   Void setTargetBits( Int bits )                          { m_targetBits = bits; }
    304 #endif
    305258  Int  getEstHeaderBits()                                 { return m_estHeaderBits; }
    306259  Int  getLCULeft()                                       { return m_LCULeft; }
     
    312265  TRCLCU& getLCU( Int LCUIdx )                            { return m_LCUs[LCUIdx]; }
    313266  Int  getPicActualHeaderBits()                           { return m_picActualHeaderBits; }
    314 #if !M0036_RC_IMPROVEMENT
    315   Double getTotalMAD()                                    { return m_totalMAD; }
    316   Void   setTotalMAD( Double MAD )                        { m_totalMAD = MAD; }
    317 #endif
    318 #if RATE_CONTROL_INTRA
    319267  Void setTargetBits( Int bits )                          { m_targetBits = bits; m_bitsLeft = bits;}
    320268  Void setTotalIntraCost(Double cost)                     { m_totalCostIntra = cost; }
    321269  Void getLCUInitTargetBits();
    322 #endif
    323270
    324271  Int  getPicActualBits()                                 { return m_picActualBits; }
     
    348295  TRCLCU* m_LCUs;
    349296  Int m_picActualHeaderBits;    // only SH and potential APS
    350 #if !M0036_RC_IMPROVEMENT
    351   Double m_totalMAD;
    352 #endif
    353 #if RATE_CONTROL_INTRA
    354297  Double m_totalCostIntra;
    355298  Double m_remainingCostIntra;
    356 #endif
    357299  Int m_picActualBits;          // the whole picture, including header
    358300  Int m_picQP;                  // in integer form
    359301  Double m_picLambda;
    360 #if !M0036_RC_IMPROVEMENT
    361   TEncRCPic* m_lastPicture;
    362 #endif
    363302};
    364303
     
    370309
    371310public:
    372 #if M0036_RC_IMPROVEMENT
    373311  Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
    374 #else
    375   Void init( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Bool keepHierBits, Bool useLCUSeparateModel, GOPEntry GOPList[MAX_GOP] );
    376 #endif
    377312  Void destroy();
    378313  Void initRCPic( Int frameLevel );
     
    396331};
    397332
    398 #else
    399 
    400 // ====================================================================================================================
    401 // Class definition
    402 // ====================================================================================================================
    403 #define MAX_DELTA_QP    2
    404 #define MAX_CUDQP_DEPTH 0
    405 
    406 typedef struct FrameData
    407 {
    408   Bool       m_isReferenced;
    409   Int        m_qp;
    410   Int        m_bits;
    411   Double     m_costMAD;
    412 }FrameData;
    413 
    414 typedef struct LCUData
    415 {
    416   Int     m_qp;                ///<  coded QP
    417   Int     m_bits;              ///<  actually generated bits
    418   Int     m_pixels;            ///<  number of pixels for a unit
    419   Int     m_widthInPixel;      ///<  number of pixels for width
    420   Int     m_heightInPixel;     ///<  number of pixels for height
    421   Double  m_costMAD;           ///<  texture complexity for a unit
    422 }LCUData;
    423 
    424 class MADLinearModel
    425 {
    426 private:
    427   Bool   m_activeOn;
    428   Double m_paramY1;
    429   Double m_paramY2;
    430   Double m_costMADs[3];
    431 
    432 public:
    433   MADLinearModel ()   {};
    434   ~MADLinearModel()   {};
    435  
    436   Void    initMADLinearModel      ();
    437   Double  getMAD                  ();
    438   Void    updateMADLiearModel     ();
    439   Void    updateMADHistory        (Double costMAD);
    440   Bool    IsUpdateAvailable       ()              { return m_activeOn; }
    441 };
    442 
    443 class PixelBaseURQQuadraticModel
    444 {
    445 private:
    446   Double m_paramHighX1;
    447   Double m_paramHighX2;
    448   Double m_paramLowX1;
    449   Double m_paramLowX2;
    450 public:
    451   PixelBaseURQQuadraticModel () {};
    452   ~PixelBaseURQQuadraticModel() {};
    453 
    454   Void    initPixelBaseQuadraticModel       ();
    455   Int     getQP                             (Int qp, Int targetBits, Int numberOfPixels, Double costPredMAD);
    456   Void    updatePixelBasedURQQuadraticModel (Int qp, Int bits, Int numberOfPixels, Double costMAD);
    457   Bool    checkUpdateAvailable              (Int qpReference );
    458   Double  xConvertQP2QStep                  (Int qp );
    459   Int     xConvertQStep2QP                  (Double qStep );
    460 };
    461 
    462 class TEncRateCtrl
    463 {
    464 private:
    465   Bool            m_isLowdelay;
    466   Int             m_prevBitrate;
    467   Int             m_currBitrate;
    468   Int             m_frameRate;
    469   Int             m_refFrameNum;
    470   Int             m_nonRefFrameNum;
    471   Int             m_numOfPixels;
    472   Int             m_sourceWidthInLCU;
    473   Int             m_sourceHeightInLCU;     
    474   Int             m_sizeGOP;
    475   Int             m_indexGOP;
    476   Int             m_indexFrame;
    477   Int             m_indexLCU;
    478   Int             m_indexUnit;
    479   Int             m_indexRefFrame;
    480   Int             m_indexNonRefFrame;
    481   Int             m_indexPOCInGOP;
    482   Int             m_indexPrevPOCInGOP;
    483   Int             m_occupancyVB;
    484   Int             m_initialOVB;
    485   Int             m_targetBufLevel;
    486   Int             m_initialTBL;
    487   Int             m_remainingBitsInGOP;
    488   Int             m_remainingBitsInFrame;
    489   Int             m_occupancyVBInFrame;
    490   Int             m_targetBits;
    491   Int             m_numUnitInFrame;
    492   Int             m_codedPixels;
    493   Bool            m_activeUnitLevelOn;
    494   Double          m_costNonRefAvgWeighting;
    495   Double          m_costRefAvgWeighting;
    496   Double          m_costAvgbpp;         
    497  
    498   FrameData*      m_pcFrameData;
    499   LCUData*        m_pcLCUData;
    500 
    501   MADLinearModel              m_cMADLinearModel;
    502   PixelBaseURQQuadraticModel  m_cPixelURQQuadraticModel;
    503  
    504 public:
    505   TEncRateCtrl         () {};
    506   virtual ~TEncRateCtrl() {};
    507 
    508   Void          create                (Int sizeIntraPeriod, Int sizeGOP, Int frameRate, Int targetKbps, Int qp, Int numLCUInBasicUnit, Int sourceWidth, Int sourceHeight, Int maxCUWidth, Int maxCUHeight);
    509   Void          destroy               ();
    510 
    511   Void          initFrameData         (Int qp = 0);
    512   Void          initUnitData          (Int qp = 0);
    513   Int           getFrameQP            (Bool isReferenced, Int POC);
    514   Bool          calculateUnitQP       ();
    515   Int           getUnitQP             ()                                          { return m_pcLCUData[m_indexLCU].m_qp;  }
    516   Void          updateRCGOPStatus     ();
    517   Void          updataRCFrameStatus   (Int frameBits, SliceType eSliceType);
    518   Void          updataRCUnitStatus    ();
    519   Void          updateLCUData         (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp);
    520   Void          updateFrameData       (UInt64 actualFrameBits);
    521   Double        xAdjustmentBits       (Int& reductionBits, Int& compensationBits);
    522   Int           getGOPId              ()                                          { return m_indexFrame; }
    523 };
    524333#endif
    525334
    526 #endif
    527 
    528 
     335
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.cpp

    r494 r540  
    4545//! \{
    4646
     47
     48#if HM_CLEANUP_SAO
     49
     50/** rounding with IBDI
     51 * \param  x
     52 */
     53inline Double xRoundIbdi2(Int bitDepth, Double x)
     54{
     55  return ((x)>0) ? (Int)(((Int)(x)+(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))) : ((Int)(((Int)(x)-(1<<(bitDepth-8-1)))/(1<<(bitDepth-8))));
     56}
     57
     58inline Double xRoundIbdi(Int bitDepth, Double x)
     59{
     60  return (bitDepth > 8 ? xRoundIbdi2(bitDepth, (x)) : ((x)>=0 ? ((Int)((x)+0.5)) : ((Int)((x)-0.5)))) ;
     61}
     62
     63
     64TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
     65{
     66  m_pppcRDSbacCoder = NULL;           
     67  m_pcRDGoOnSbacCoder = NULL;
     68  m_pppcBinCoderCABAC = NULL;   
     69  m_statData = NULL;
     70#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     71  m_preDBFstatData = NULL;
     72#endif
     73}
     74
     75TEncSampleAdaptiveOffset::~TEncSampleAdaptiveOffset()
     76{
     77  destroyEncData();
     78}
     79
     80#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     81Void TEncSampleAdaptiveOffset::createEncData(Bool isPreDBFSamplesUsed)
     82#else
     83Void TEncSampleAdaptiveOffset::createEncData()
     84#endif
     85{
     86
     87  //cabac coder for RDO
     88  m_pppcRDSbacCoder = new TEncSbac* [NUM_SAO_CABACSTATE_LABELS];
     89  m_pppcBinCoderCABAC = new TEncBinCABACCounter* [NUM_SAO_CABACSTATE_LABELS];
     90
     91  for(Int cs=0; cs < NUM_SAO_CABACSTATE_LABELS; cs++)
     92  {
     93    m_pppcRDSbacCoder[cs] = new TEncSbac;
     94    m_pppcBinCoderCABAC[cs] = new TEncBinCABACCounter;
     95    m_pppcRDSbacCoder   [cs]->init( m_pppcBinCoderCABAC [cs] );
     96  }
     97
     98
     99  //statistics
     100  m_statData = new SAOStatData**[m_numCTUsPic];
     101  for(Int i=0; i< m_numCTUsPic; i++)
     102  {
     103    m_statData[i] = new SAOStatData*[NUM_SAO_COMPONENTS];
     104    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     105    {
     106      m_statData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES];
     107    }
     108  }
     109#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     110  if(isPreDBFSamplesUsed)
     111  {
     112    m_preDBFstatData = new SAOStatData**[m_numCTUsPic];
     113    for(Int i=0; i< m_numCTUsPic; i++)
     114    {
     115      m_preDBFstatData[i] = new SAOStatData*[NUM_SAO_COMPONENTS];
     116      for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     117      {
     118        m_preDBFstatData[i][compIdx] = new SAOStatData[NUM_SAO_NEW_TYPES];
     119      }
     120    }
     121
     122  }
     123#endif
     124
     125#if SAO_ENCODING_CHOICE
     126  ::memset(m_saoDisabledRate, 0, sizeof(m_saoDisabledRate));
     127#endif
     128
     129  for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++)
     130  {
     131    m_skipLinesR[SAO_Y ][typeIdc]= 5;
     132    m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     133
     134    m_skipLinesB[SAO_Y ][typeIdc]= 4;
     135    m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     136
     137#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     138    if(isPreDBFSamplesUsed)
     139    {
     140      switch(typeIdc)
     141      {
     142      case SAO_TYPE_EO_0:
     143        {
     144          m_skipLinesR[SAO_Y ][typeIdc]= 5;
     145          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     146
     147          m_skipLinesB[SAO_Y ][typeIdc]= 3;
     148          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;
     149        }
     150        break;
     151      case SAO_TYPE_EO_90:
     152        {
     153          m_skipLinesR[SAO_Y ][typeIdc]= 4;
     154          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;
     155
     156          m_skipLinesB[SAO_Y ][typeIdc]= 4;
     157          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     158        }
     159        break;
     160      case SAO_TYPE_EO_135:
     161      case SAO_TYPE_EO_45:
     162        {
     163          m_skipLinesR[SAO_Y ][typeIdc]= 5;
     164          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 3;
     165
     166          m_skipLinesB[SAO_Y ][typeIdc]= 4;
     167          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 2;
     168        }
     169        break;
     170      case SAO_TYPE_BO:
     171        {
     172          m_skipLinesR[SAO_Y ][typeIdc]= 4;
     173          m_skipLinesR[SAO_Cb][typeIdc]= m_skipLinesR[SAO_Cr][typeIdc]= 2;
     174
     175          m_skipLinesB[SAO_Y ][typeIdc]= 3;
     176          m_skipLinesB[SAO_Cb][typeIdc]= m_skipLinesB[SAO_Cr][typeIdc]= 1;
     177        }
     178        break;
     179      default:
     180        {
     181          printf("Not a supported type");
     182          assert(0);
     183          exit(-1);
     184        }
     185      }
     186    }
     187#endif   
     188  }
     189
     190}
     191
     192Void TEncSampleAdaptiveOffset::destroyEncData()
     193{
     194  if(m_pppcRDSbacCoder != NULL)
     195  {
     196    for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ )
     197    {
     198      delete m_pppcRDSbacCoder[cs];
     199    }
     200    delete[] m_pppcRDSbacCoder; m_pppcRDSbacCoder = NULL;
     201  }
     202
     203  if(m_pppcBinCoderCABAC != NULL)
     204  {
     205    for (Int cs = 0; cs < NUM_SAO_CABACSTATE_LABELS; cs ++ )
     206    {
     207      delete m_pppcBinCoderCABAC[cs];
     208    }
     209    delete[] m_pppcBinCoderCABAC; m_pppcBinCoderCABAC = NULL;
     210  }
     211
     212  if(m_statData != NULL)
     213  {
     214    for(Int i=0; i< m_numCTUsPic; i++)
     215    {
     216      for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     217      {
     218        delete[] m_statData[i][compIdx];
     219      }
     220      delete[] m_statData[i];
     221    }
     222    delete[] m_statData; m_statData = NULL;
     223  }
     224#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     225  if(m_preDBFstatData != NULL)
     226  {
     227    for(Int i=0; i< m_numCTUsPic; i++)
     228    {
     229      for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     230      {
     231        delete[] m_preDBFstatData[i][compIdx];
     232      }
     233      delete[] m_preDBFstatData[i];
     234    }
     235    delete[] m_preDBFstatData; m_preDBFstatData = NULL;
     236  }
     237
     238#endif
     239}
     240
     241Void TEncSampleAdaptiveOffset::initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice)
     242{
     243  m_pcRDGoOnSbacCoder = pcRDGoOnSbacCoder;
     244  m_pcRDGoOnSbacCoder->setSlice(pcSlice);
     245  m_pcRDGoOnSbacCoder->resetEntropy();
     246  m_pcRDGoOnSbacCoder->resetBits();
     247
     248  m_pcRDGoOnSbacCoder->store( m_pppcRDSbacCoder[SAO_CABACSTATE_PIC_INIT]);
     249}
     250
     251
     252
     253Void TEncSampleAdaptiveOffset::SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas
     254#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     255                                         , Bool isPreDBFSamplesUsed
     256#endif
     257                                          )
     258{
     259  TComPicYuv* orgYuv= pPic->getPicYuvOrg();
     260  TComPicYuv* resYuv= pPic->getPicYuvRec();
     261  m_labmda[SAO_Y]= lambdas[0]; m_labmda[SAO_Cb]= lambdas[1]; m_labmda[SAO_Cr]= lambdas[2];
     262  TComPicYuv* srcYuv = m_tempPicYuv;
     263  resYuv->copyToPic(srcYuv);
     264  srcYuv->setBorderExtension(false);
     265  srcYuv->extendPicBorder();
     266
     267  //collect statistics
     268  getStatistics(m_statData, orgYuv, srcYuv, pPic);
     269#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     270  if(isPreDBFSamplesUsed)
     271  {
     272    addPreDBFStatistics(m_statData);
     273  }
     274#endif
     275  //slice on/off
     276  decidePicParams(sliceEnabled, pPic->getSlice(0)->getDepth());
     277
     278  //block on/off
     279  SAOBlkParam* reconParams = new SAOBlkParam[m_numCTUsPic]; //temporary parameter buffer for storing reconstructed SAO parameters
     280  decideBlkParams(pPic, sliceEnabled, m_statData, srcYuv, resYuv, reconParams, pPic->getPicSym()->getSAOBlkParam());
     281  delete[] reconParams;
     282
     283}
     284
     285#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     286Void TEncSampleAdaptiveOffset::getPreDBFStatistics(TComPic* pPic)
     287{
     288  getStatistics(m_preDBFstatData, pPic->getPicYuvOrg(), pPic->getPicYuvRec(), pPic, true);
     289}
     290
     291Void TEncSampleAdaptiveOffset::addPreDBFStatistics(SAOStatData*** blkStats)
     292{
     293  for(Int n=0; n< m_numCTUsPic; n++)
     294  {
     295    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     296    {
     297      for(Int typeIdc=0; typeIdc < NUM_SAO_NEW_TYPES; typeIdc++)
     298      {
     299        blkStats[n][compIdx][typeIdc] += m_preDBFstatData[n][compIdx][typeIdc];
     300      }
     301    }
     302  }
     303}
     304
     305#endif
     306
     307Void TEncSampleAdaptiveOffset::getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv, TComPic* pPic
     308#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     309                          , Bool isCalculatePreDeblockSamples
     310#endif
     311                          )
     312{
     313  Bool isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail;
     314
     315  for(Int ctu= 0; ctu < m_numCTUsPic; ctu++)
     316  {
     317    Int yPos   = (ctu / m_numCTUInWidth)*m_maxCUHeight;
     318    Int xPos   = (ctu % m_numCTUInWidth)*m_maxCUWidth;
     319    Int height = (yPos + m_maxCUHeight > m_picHeight)?(m_picHeight- yPos):m_maxCUHeight;
     320    Int width  = (xPos + m_maxCUWidth  > m_picWidth )?(m_picWidth - xPos):m_maxCUWidth;
     321
     322    pPic->getPicSym()->deriveLoopFilterBoundaryAvailibility(ctu, isLeftAvail,isRightAvail,isAboveAvail,isBelowAvail,isAboveLeftAvail,isAboveRightAvail,isBelowLeftAvail,isBelowRightAvail);
     323
     324    //NOTE: The number of skipped lines during gathering CTU statistics depends on the slice boundary availabilities.
     325    //For simplicity, here only picture boundaries are considered.
     326
     327    isRightAvail      = (xPos + m_maxCUWidth  < m_picWidth );
     328    isBelowAvail      = (yPos + m_maxCUHeight < m_picHeight);
     329    isBelowRightAvail = (isRightAvail && isBelowAvail);
     330    isBelowLeftAvail  = ((xPos > 0) && (isBelowAvail));
     331    isAboveRightAvail = ((yPos > 0) && (isRightAvail));
     332
     333    for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     334    {
     335      Bool isLuma     = (compIdx == SAO_Y);
     336      Int  formatShift= isLuma?0:1;
     337
     338      Int  srcStride = isLuma?srcYuv->getStride():srcYuv->getCStride();
     339      Pel* srcBlk    = getPicBuf(srcYuv, compIdx)+ (yPos >> formatShift)*srcStride+ (xPos >> formatShift);
     340
     341      Int  orgStride  = isLuma?orgYuv->getStride():orgYuv->getCStride();
     342      Pel* orgBlk     = getPicBuf(orgYuv, compIdx)+ (yPos >> formatShift)*orgStride+ (xPos >> formatShift);
     343
     344      getBlkStats(compIdx, blkStats[ctu][compIdx] 
     345                , srcBlk, orgBlk, srcStride, orgStride, (width  >> formatShift), (height >> formatShift)
     346                , isLeftAvail,  isRightAvail, isAboveAvail, isBelowAvail, isAboveLeftAvail, isAboveRightAvail, isBelowLeftAvail, isBelowRightAvail
     347#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     348                , isCalculatePreDeblockSamples
     349#endif
     350                );
     351
     352    }
     353  }
     354}
     355
     356Void TEncSampleAdaptiveOffset::decidePicParams(Bool* sliceEnabled, Int picTempLayer)
     357{
     358  //decide sliceEnabled[compIdx]
     359  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     360  {
     361    // reset flags & counters
     362    sliceEnabled[compIdx] = true;
     363
     364#if SAO_ENCODING_CHOICE
     365#if SAO_ENCODING_CHOICE_CHROMA
     366    // decide slice-level on/off based on previous results
     367    if( (picTempLayer > 0)
     368      && (m_saoDisabledRate[compIdx][picTempLayer-1] > ((compIdx==SAO_Y) ? SAO_ENCODING_RATE : SAO_ENCODING_RATE_CHROMA)) )
     369    {
     370      sliceEnabled[compIdx] = false;
     371    }
     372#else
     373    // decide slice-level on/off based on previous results
     374    if( (picTempLayer > 0)
     375      && (m_saoDisabledRate[SAO_Y][0] > SAO_ENCODING_RATE) )
     376    {
     377      sliceEnabled[compIdx] = false;
     378    }
     379#endif
     380#endif
     381  }
     382}
     383
     384Int64 TEncSampleAdaptiveOffset::getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* invQuantOffset, SAOStatData& statData)
     385{
     386  Int64 dist=0;
     387  Int inputBitDepth    = (compIdx == SAO_Y) ? g_bitDepthY : g_bitDepthC ;
     388  Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(inputBitDepth-8);
     389
     390  switch(typeIdc)
     391  {
     392    case SAO_TYPE_EO_0:
     393    case SAO_TYPE_EO_90:
     394    case SAO_TYPE_EO_135:
     395    case SAO_TYPE_EO_45:
     396      {
     397        for (Int offsetIdx=0; offsetIdx<NUM_SAO_EO_CLASSES; offsetIdx++)
     398        {
     399          dist += estSaoDist( statData.count[offsetIdx], invQuantOffset[offsetIdx], statData.diff[offsetIdx], shift);
     400        }       
     401      }
     402      break;
     403    case SAO_TYPE_BO:
     404      {
     405        for (Int offsetIdx=typeAuxInfo; offsetIdx<typeAuxInfo+4; offsetIdx++)
     406        {
     407          Int bandIdx = offsetIdx % NUM_SAO_BO_CLASSES ;
     408          dist += estSaoDist( statData.count[bandIdx], invQuantOffset[bandIdx], statData.diff[bandIdx], shift);
     409        }
     410      }
     411      break;
     412    default:
     413      {
     414        printf("Not a supported type");
     415        assert(0);
     416        exit(-1);
     417      }
     418  }
     419
     420  return dist;
     421}
     422
     423inline Int64 TEncSampleAdaptiveOffset::estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift)
     424{
     425  return (( count*offset*offset-diffSum*offset*2 ) >> shift);
     426}
     427
     428
     429inline Int TEncSampleAdaptiveOffset::estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh )
     430{
     431  Int iterOffset, tempOffset;
     432  Int64 tempDist, tempRate;
     433  Double tempCost, tempMinCost;
     434  Int offsetOutput = 0;
     435  iterOffset = offsetInput;
     436  // Assuming sending quantized value 0 results in zero offset and sending the value zero needs 1 bit. entropy coder can be used to measure the exact rate here.
     437  tempMinCost = lambda;
     438  while (iterOffset != 0)
     439  {
     440    // Calculate the bits required for signaling the offset
     441    tempRate = (typeIdx == SAO_TYPE_BO) ? (abs((Int)iterOffset)+2) : (abs((Int)iterOffset)+1);
     442    if (abs((Int)iterOffset)==offsetTh) //inclusive
     443    { 
     444      tempRate --;
     445    }
     446    // Do the dequantization before distortion calculation
     447    tempOffset  = iterOffset << bitIncrease;
     448    tempDist    = estSaoDist( count, tempOffset, diffSum, shift);
     449    tempCost    = ((Double)tempDist + lambda * (Double) tempRate);
     450    if(tempCost < tempMinCost)
     451    {
     452      tempMinCost = tempCost;
     453      offsetOutput = iterOffset;
     454      bestDist = tempDist;
     455      bestCost = tempCost;
     456    }
     457    iterOffset = (iterOffset > 0) ? (iterOffset-1):(iterOffset+1);
     458  }
     459  return offsetOutput;
     460}
     461
     462
     463Void TEncSampleAdaptiveOffset::deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo)
     464{
     465  Int bitDepth = (compIdx== SAO_Y) ? g_bitDepthY : g_bitDepthC;
     466  Int shift = 2 * DISTORTION_PRECISION_ADJUSTMENT(bitDepth-8);
     467  Int offsetTh = g_saoMaxOffsetQVal[compIdx];  //inclusive
     468
     469  ::memset(quantOffsets, 0, sizeof(Int)*MAX_NUM_SAO_CLASSES);
     470
     471  //derive initial offsets
     472  Int numClasses = (typeIdc == SAO_TYPE_BO)?((Int)NUM_SAO_BO_CLASSES):((Int)NUM_SAO_EO_CLASSES);
     473  for(Int classIdx=0; classIdx< numClasses; classIdx++)
     474  {
     475    if( (typeIdc != SAO_TYPE_BO) && (classIdx==SAO_CLASS_EO_PLAIN)  )
     476    {
     477      continue; //offset will be zero
     478    }
     479
     480    if(statData.count[classIdx] == 0)
     481    {
     482      continue; //offset will be zero
     483    }
     484
     485    quantOffsets[classIdx] = (Int) xRoundIbdi(bitDepth, (Double)( statData.diff[classIdx]<<(bitDepth-8))
     486                                                                  /
     487                                                          (Double)( statData.count[classIdx]<< m_offsetStepLog2[compIdx])
     488                                               );
     489    quantOffsets[classIdx] = Clip3(-offsetTh, offsetTh, quantOffsets[classIdx]);
     490  }
     491
     492  // adjust offsets
     493  switch(typeIdc)
     494  {
     495    case SAO_TYPE_EO_0:
     496    case SAO_TYPE_EO_90:
     497    case SAO_TYPE_EO_135:
     498    case SAO_TYPE_EO_45:
     499      {
     500        Int64 classDist;
     501        Double classCost;
     502        for(Int classIdx=0; classIdx<NUM_SAO_EO_CLASSES; classIdx++) 
     503        {         
     504          if(classIdx==SAO_CLASS_EO_FULL_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0;
     505          if(classIdx==SAO_CLASS_EO_HALF_VALLEY && quantOffsets[classIdx] < 0) quantOffsets[classIdx] =0;
     506          if(classIdx==SAO_CLASS_EO_HALF_PEAK   && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0;
     507          if(classIdx==SAO_CLASS_EO_FULL_PEAK   && quantOffsets[classIdx] > 0) quantOffsets[classIdx] =0;
     508
     509          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
     510          {
     511            quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_labmda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], classDist , classCost , offsetTh );
     512          }
     513        }
     514     
     515        typeAuxInfo =0;
     516      }
     517      break;
     518    case SAO_TYPE_BO:
     519      {
     520        Int64  distBOClasses[NUM_SAO_BO_CLASSES];
     521        Double costBOClasses[NUM_SAO_BO_CLASSES];
     522        ::memset(distBOClasses, 0, sizeof(Int64)*NUM_SAO_BO_CLASSES);
     523        for(Int classIdx=0; classIdx< NUM_SAO_BO_CLASSES; classIdx++)
     524        {         
     525          costBOClasses[classIdx]= m_labmda[compIdx];
     526          if( quantOffsets[classIdx] != 0 ) //iterative adjustment only when derived offset is not zero
     527          {
     528            quantOffsets[classIdx] = estIterOffset( typeIdc, classIdx, m_labmda[compIdx], quantOffsets[classIdx], statData.count[classIdx], statData.diff[classIdx], shift, m_offsetStepLog2[compIdx], distBOClasses[classIdx], costBOClasses[classIdx], offsetTh );
     529          }
     530        }
     531
     532        //decide the starting band index
     533        Double minCost = MAX_DOUBLE, cost;
     534        for(Int band=0; band< NUM_SAO_BO_CLASSES- 4+ 1; band++)
     535        {
     536          cost  = costBOClasses[band  ];
     537          cost += costBOClasses[band+1];
     538          cost += costBOClasses[band+2];
     539          cost += costBOClasses[band+3];
     540
     541          if(cost < minCost)
     542          {
     543            minCost = cost;
     544            typeAuxInfo = band;
     545          }
     546        }
     547        //clear those unused classes
     548        Int clearQuantOffset[NUM_SAO_BO_CLASSES];
     549        ::memset(clearQuantOffset, 0, sizeof(Int)*NUM_SAO_BO_CLASSES);
     550        for(Int i=0; i< 4; i++)
     551        {
     552          Int band = (typeAuxInfo+i)%NUM_SAO_BO_CLASSES;
     553          clearQuantOffset[band] = quantOffsets[band];
     554        }
     555        ::memcpy(quantOffsets, clearQuantOffset, sizeof(Int)*NUM_SAO_BO_CLASSES);       
     556      }
     557      break;
     558    default:
     559      {
     560        printf("Not a supported type");
     561        assert(0);
     562        exit(-1);
     563      }
     564
     565  }
     566
     567
     568}
     569
     570
     571Void TEncSampleAdaptiveOffset::deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
     572{
     573  Double minCost, cost;
     574  Int rate, minRate;
     575  Int64 dist[NUM_SAO_COMPONENTS], modeDist[NUM_SAO_COMPONENTS];
     576  SAOOffset testOffset[NUM_SAO_COMPONENTS];
     577  Int compIdx;
     578  Int invQuantOffset[MAX_NUM_SAO_CLASSES];
     579
     580  modeDist[SAO_Y]= modeDist[SAO_Cb] = modeDist[SAO_Cr] = 0;
     581
     582  //pre-encode merge flags
     583  modeParam[SAO_Y ].modeIdc = SAO_MODE_OFF;
     584  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     585  m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), true);
     586  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     587
     588  //------ luma --------//
     589  compIdx = SAO_Y;
     590  //"off" case as initial cost
     591  modeParam[compIdx].modeIdc = SAO_MODE_OFF;
     592  m_pcRDGoOnSbacCoder->resetBits();
     593  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, modeParam[compIdx], sliceEnabled[compIdx]);
     594  minRate= m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     595  modeDist[compIdx] = 0;
     596  minCost= m_labmda[compIdx]*((Double)minRate);
     597  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     598  if(sliceEnabled[compIdx])
     599  {
     600    for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
     601    {
     602      testOffset[compIdx].modeIdc = SAO_MODE_NEW;
     603      testOffset[compIdx].typeIdc = typeIdc;
     604
     605      //derive coded offset
     606      deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
     607
     608      //inversed quantized offsets
     609      invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
     610
     611      //get distortion
     612      dist[compIdx] = getDistortion(ctu, compIdx, testOffset[compIdx].typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
     613
     614      //get rate
     615      m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     616      m_pcRDGoOnSbacCoder->resetBits();
     617      m_pcRDGoOnSbacCoder->codeSAOOffsetParam(compIdx, testOffset[compIdx], sliceEnabled[compIdx]);
     618      rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     619      cost = (Double)dist[compIdx] + m_labmda[compIdx]*((Double)rate);
     620      if(cost < minCost)
     621      {
     622        minCost = cost;
     623        minRate = rate;
     624        modeDist[compIdx] = dist[compIdx];
     625        modeParam[compIdx]= testOffset[compIdx];
     626        m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     627      }
     628    }
     629  }
     630  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     631  m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     632
     633  //------ chroma --------//
     634  assert(m_labmda[SAO_Cb] == m_labmda[SAO_Cr]);
     635  Double chromaLambda = m_labmda[SAO_Cb];
     636  //"off" case as initial cost
     637  m_pcRDGoOnSbacCoder->resetBits();
     638  modeParam[SAO_Cb].modeIdc = SAO_MODE_OFF;
     639  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cb, modeParam[SAO_Cb], sliceEnabled[SAO_Cb]);
     640  modeParam[SAO_Cr].modeIdc = SAO_MODE_OFF;
     641  m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cr, modeParam[SAO_Cr], sliceEnabled[SAO_Cr]);
     642  minRate= m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     643  modeDist[SAO_Cb] = modeDist[SAO_Cr]= 0;
     644  minCost= chromaLambda*((Double)minRate);
     645
     646  //doesn't need to store cabac status here since the whole CTU parameters will be re-encoded at the end of this function
     647
     648  for(Int typeIdc=0; typeIdc< NUM_SAO_NEW_TYPES; typeIdc++)
     649  {
     650    for(compIdx= SAO_Cb; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     651    {
     652      if(!sliceEnabled[compIdx])
     653      {
     654        testOffset[compIdx].modeIdc = SAO_MODE_OFF;
     655        dist[compIdx]= 0;
     656        continue;
     657      }
     658      testOffset[compIdx].modeIdc = SAO_MODE_NEW;
     659      testOffset[compIdx].typeIdc = typeIdc;
     660
     661      //derive offset & get distortion
     662      deriveOffsets(ctu, compIdx, typeIdc, blkStats[ctu][compIdx][typeIdc], testOffset[compIdx].offset, testOffset[compIdx].typeAuxInfo);
     663      invertQuantOffsets(compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, testOffset[compIdx].offset);
     664      dist[compIdx]= getDistortion(ctu, compIdx, typeIdc, testOffset[compIdx].typeAuxInfo, invQuantOffset, blkStats[ctu][compIdx][typeIdc]);
     665    }
     666
     667    //get rate
     668    m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_MID]);
     669    m_pcRDGoOnSbacCoder->resetBits();
     670    m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cb, testOffset[SAO_Cb], sliceEnabled[SAO_Cb]);
     671    m_pcRDGoOnSbacCoder->codeSAOOffsetParam(SAO_Cr, testOffset[SAO_Cr], sliceEnabled[SAO_Cr]);
     672    rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     673
     674    cost = (Double)(dist[SAO_Cb]+ dist[SAO_Cr]) + chromaLambda*((Double)rate);
     675    if(cost < minCost)
     676    {
     677      minCost = cost;
     678      minRate = rate;
     679      modeDist[SAO_Cb] = dist[SAO_Cb];
     680      modeDist[SAO_Cr] = dist[SAO_Cr];
     681      modeParam[SAO_Cb]= testOffset[SAO_Cb];
     682      modeParam[SAO_Cr]= testOffset[SAO_Cr];
     683    }
     684  }
     685
     686
     687  //----- re-gen rate & normalized cost----//
     688  modeNormCost  = (Double)modeDist[SAO_Y]/m_labmda[SAO_Y];
     689  modeNormCost += (Double)(modeDist[SAO_Cb]+ modeDist[SAO_Cr])/chromaLambda;
     690  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     691  m_pcRDGoOnSbacCoder->resetBits();
     692  m_pcRDGoOnSbacCoder->codeSAOBlkParam(modeParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
     693  modeNormCost += (Double)m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     694
     695}
     696
     697Void TEncSampleAdaptiveOffset::deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel)
     698{
     699  Int mergeListSize = (Int)mergeList.size();
     700  modeNormCost = MAX_DOUBLE;
     701
     702  Double cost;
     703  SAOBlkParam testBlkParam;
     704
     705  for(Int mergeType=0; mergeType< mergeListSize; mergeType++)
     706  {
     707    if(mergeList[mergeType] == NULL)
     708    {
     709      continue;
     710    }
     711
     712    testBlkParam = *(mergeList[mergeType]);
     713    //normalized distortion
     714    Double normDist=0;
     715    for(Int compIdx=0; compIdx< NUM_SAO_COMPONENTS; compIdx++)
     716    {
     717      testBlkParam[compIdx].modeIdc = SAO_MODE_MERGE;
     718      testBlkParam[compIdx].typeIdc = mergeType;
     719
     720      SAOOffset& mergedOffsetParam = (*(mergeList[mergeType]))[compIdx];
     721
     722      if( mergedOffsetParam.modeIdc != SAO_MODE_OFF)
     723      {
     724        //offsets have been reconstructed. Don't call inversed quantization function.
     725        normDist += (((Double)getDistortion(ctu, compIdx, mergedOffsetParam.typeIdc, mergedOffsetParam.typeAuxInfo, mergedOffsetParam.offset, blkStats[ctu][compIdx][mergedOffsetParam.typeIdc]))
     726                       /m_labmda[compIdx]
     727                    );
     728      }
     729
     730    }
     731
     732    //rate
     733    m_pcRDGoOnSbacCoder->load(cabacCoderRDO[inCabacLabel]);
     734    m_pcRDGoOnSbacCoder->resetBits();
     735    m_pcRDGoOnSbacCoder->codeSAOBlkParam(testBlkParam, sliceEnabled, (mergeList[SAO_MERGE_LEFT]!= NULL), (mergeList[SAO_MERGE_ABOVE]!= NULL), false);
     736    Int rate = m_pcRDGoOnSbacCoder->getNumberOfWrittenBits();
     737
     738    cost = normDist+(Double)rate;
     739
     740    if(cost < modeNormCost)
     741    {
     742      modeNormCost = cost;
     743      modeParam    = testBlkParam;
     744      m_pcRDGoOnSbacCoder->store(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     745    }
     746  }
     747
     748  m_pcRDGoOnSbacCoder->load(cabacCoderRDO[SAO_CABACSTATE_BLK_TEMP]);
     749
     750
     751}
     752
     753Void TEncSampleAdaptiveOffset::decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams)
     754{
     755  Bool isAllBlksDisabled = false;
     756  if(!sliceEnabled[SAO_Y] && !sliceEnabled[SAO_Cb] && !sliceEnabled[SAO_Cr])
     757  {
     758    isAllBlksDisabled = true;
     759  }
     760
     761  m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_PIC_INIT ]);
     762
     763  SAOBlkParam modeParam;
     764  Double minCost, modeCost;
     765
     766  for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
     767  {
     768    if(isAllBlksDisabled)
     769    {
     770      codedParams[ctu].reset();
     771      continue;
     772    }
     773
     774    m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_CUR ]);
     775
     776    //get merge list
     777    std::vector<SAOBlkParam*> mergeList;
     778    getMergeList(pic, ctu, reconParams, mergeList);
     779
     780    minCost = MAX_DOUBLE;
     781    for(Int mode=0; mode < NUM_SAO_MODES; mode++)
     782    {
     783      switch(mode)
     784      {
     785      case SAO_MODE_OFF:
     786        {
     787          continue; //not necessary, since all-off case will be tested in SAO_MODE_NEW case.
     788        }
     789        break;
     790      case SAO_MODE_NEW:
     791        {
     792          deriveModeNewRDO(ctu, mergeList, sliceEnabled, blkStats, modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
     793
     794        }
     795        break;
     796      case SAO_MODE_MERGE:
     797        {
     798          deriveModeMergeRDO(ctu, mergeList, sliceEnabled, blkStats , modeParam, modeCost, m_pppcRDSbacCoder, SAO_CABACSTATE_BLK_CUR);
     799        }
     800        break;
     801      default:
     802        {
     803          printf("Not a supported SAO mode\n");
     804          assert(0);
     805          exit(-1);
     806        }
     807      }
     808
     809      if(modeCost < minCost)
     810      {
     811        minCost = modeCost;
     812        codedParams[ctu] = modeParam;
     813        m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]);
     814
     815      }
     816    } //mode
     817    m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[ SAO_CABACSTATE_BLK_NEXT ]);
     818
     819    //apply reconstructed offsets
     820    reconParams[ctu] = codedParams[ctu];
     821    reconstructBlkSAOParam(reconParams[ctu], mergeList);
     822    offsetCTU(ctu, srcYuv, resYuv, reconParams[ctu], pic);
     823  } //ctu
     824
     825#if SAO_ENCODING_CHOICE
     826  Int picTempLayer = pic->getSlice(0)->getDepth();
     827  Int numLcusForSAOOff[NUM_SAO_COMPONENTS];
     828  numLcusForSAOOff[SAO_Y ] = numLcusForSAOOff[SAO_Cb]= numLcusForSAOOff[SAO_Cr]= 0;
     829
     830  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     831  {
     832    for(Int ctu=0; ctu< m_numCTUsPic; ctu++)
     833    {
     834      if( reconParams[ctu][compIdx].modeIdc == SAO_MODE_OFF)
     835      {
     836        numLcusForSAOOff[compIdx]++;
     837      }
     838    }
     839  }
     840#if SAO_ENCODING_CHOICE_CHROMA
     841  for (Int compIdx=0; compIdx<NUM_SAO_COMPONENTS; compIdx++)
     842  {
     843    m_saoDisabledRate[compIdx][picTempLayer] = (Double)numLcusForSAOOff[compIdx]/(Double)m_numCTUsPic;
     844  }
     845#else
     846  if (picTempLayer == 0)
     847  {
     848    m_saoDisabledRate[SAO_Y][0] = (Double)(numLcusForSAOOff[SAO_Y]+numLcusForSAOOff[SAO_Cb]+numLcusForSAOOff[SAO_Cr])/(Double)(m_numCTUsPic*3);
     849  }
     850#endif                                             
     851#endif
     852}
     853
     854
     855Void TEncSampleAdaptiveOffset::getBlkStats(Int compIdx, SAOStatData* statsDataTypes 
     856                        , Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height
     857                        , Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail
     858#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     859                        , Bool isCalculatePreDeblockSamples
     860#endif
     861                        )
     862{
     863  if(m_lineBufWidth != m_maxCUWidth)
     864  {
     865    m_lineBufWidth = m_maxCUWidth;
     866
     867    if (m_signLineBuf1) delete[] m_signLineBuf1; m_signLineBuf1 = NULL;
     868    m_signLineBuf1 = new Char[m_lineBufWidth+1];
     869
     870    if (m_signLineBuf2) delete[] m_signLineBuf2; m_signLineBuf2 = NULL;
     871    m_signLineBuf2 = new Char[m_lineBufWidth+1];
     872  }
     873
     874  Int x,y, startX, startY, endX, endY, edgeType, firstLineStartX, firstLineEndX;
     875  Char signLeft, signRight, signDown;
     876  Int64 *diff, *count;
     877  Pel *srcLine, *orgLine;
     878  Int* skipLinesR = m_skipLinesR[compIdx];
     879  Int* skipLinesB = m_skipLinesB[compIdx];
     880
     881  for(Int typeIdx=0; typeIdx< NUM_SAO_NEW_TYPES; typeIdx++)
     882  {
     883    SAOStatData& statsData= statsDataTypes[typeIdx];
     884    statsData.reset();
     885
     886    srcLine = srcBlk;
     887    orgLine = orgBlk;
     888    diff    = statsData.diff;
     889    count   = statsData.count;
     890    switch(typeIdx)
     891    {
     892    case SAO_TYPE_EO_0:
     893      {
     894        diff +=2;
     895        count+=2;
     896        endY   = (isBelowAvail) ? (height - skipLinesB[typeIdx]) : height;
     897#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     898        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     899                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     900                                                 ;
     901#else
     902        startX = isLeftAvail ? 0 : 1;
     903#endif
     904#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     905        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     906                                                 : (isRightAvail ? width : (width - 1))
     907                                                 ;
     908#else
     909        endX   = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1);
     910#endif
     911        for (y=0; y<endY; y++)
     912        {
     913          signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
     914          for (x=startX; x<endX; x++)
     915          {
     916            signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]];
     917            edgeType  =  signRight + signLeft;
     918            signLeft  = -signRight;
     919
     920            diff [edgeType] += (orgLine[x] - srcLine[x]);
     921            count[edgeType] ++;
     922          }
     923          srcLine  += srcStride;
     924          orgLine  += orgStride;
     925        }
     926#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     927        if(isCalculatePreDeblockSamples)
     928        {
     929          if(isBelowAvail)
     930          {
     931            startX = isLeftAvail  ? 0 : 1;
     932            endX   = isRightAvail ? width : (width -1);
     933
     934            for(y=0; y<skipLinesB[typeIdx]; y++)
     935            {
     936              signLeft = (Char)m_sign[srcLine[startX] - srcLine[startX-1]];
     937              for (x=startX; x<endX; x++)
     938              {
     939                signRight =  (Char)m_sign[srcLine[x] - srcLine[x+1]];
     940                edgeType  =  signRight + signLeft;
     941                signLeft  = -signRight;
     942
     943                diff [edgeType] += (orgLine[x] - srcLine[x]);
     944                count[edgeType] ++;
     945              }
     946              srcLine  += srcStride;
     947              orgLine  += orgStride;
     948            }
     949          }
     950        }
     951#endif
     952      }
     953      break;
     954    case SAO_TYPE_EO_90:
     955      {
     956        diff +=2;
     957        count+=2;
     958        Char *signUpLine = m_signLineBuf1;
     959
     960#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     961        startX = (!isCalculatePreDeblockSamples) ? 0
     962                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : width)
     963                                                 ;
     964#endif
     965        startY = isAboveAvail ? 0 : 1;
     966#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     967        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : width)
     968                                                 : width
     969                                                 ;
     970#else
     971        endX   = isRightAvail ? (width - skipLinesR[typeIdx]) : width ;
     972#endif
     973        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     974        if (!isAboveAvail)
     975        {
     976          srcLine += srcStride;
     977          orgLine += orgStride;
     978        }
     979
     980        Pel* srcLineAbove = srcLine - srcStride;
     981#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     982        for (x=startX; x<endX; x++)
     983#else
     984        for (x=0; x< endX; x++)
     985#endif
     986        {
     987          signUpLine[x] = (Char)m_sign[srcLine[x] - srcLineAbove[x]];
     988        }
     989
     990        Pel* srcLineBelow;
     991        for (y=startY; y<endY; y++)
     992        {
     993          srcLineBelow = srcLine + srcStride;
     994
     995#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     996          for (x=startX; x<endX; x++)
     997#else
     998          for (x=0; x<endX; x++)
     999#endif
     1000          {
     1001            signDown  = (Char)m_sign[srcLine[x] - srcLineBelow[x]];
     1002            edgeType  = signDown + signUpLine[x];
     1003            signUpLine[x]= -signDown;
     1004
     1005            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1006            count[edgeType] ++;
     1007          }
     1008          srcLine += srcStride;
     1009          orgLine += orgStride;
     1010        }
     1011#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1012        if(isCalculatePreDeblockSamples)
     1013        {
     1014          if(isBelowAvail)
     1015          {
     1016            startX = 0;
     1017            endX   = width;
     1018
     1019            for(y=0; y<skipLinesB[typeIdx]; y++)
     1020            {
     1021              srcLineBelow = srcLine + srcStride;
     1022              srcLineAbove = srcLine - srcStride;
     1023
     1024              for (x=startX; x<endX; x++)
     1025              {
     1026                edgeType = m_sign[srcLine[x] - srcLineBelow[x]] + m_sign[srcLine[x] - srcLineAbove[x]];
     1027                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1028                count[edgeType] ++;
     1029              }
     1030              srcLine  += srcStride;
     1031              orgLine  += orgStride;
     1032            }
     1033          }
     1034        }
     1035#endif
     1036
     1037      }
     1038      break;
     1039    case SAO_TYPE_EO_135:
     1040      {
     1041        diff +=2;
     1042        count+=2;
     1043        Char *signUpLine, *signDownLine, *signTmpLine;
     1044
     1045        signUpLine  = m_signLineBuf1;
     1046        signDownLine= m_signLineBuf2;
     1047
     1048#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1049        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     1050                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1051                                                 ;
     1052#else
     1053        startX = isLeftAvail ? 0 : 1 ;
     1054#endif
     1055
     1056#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1057        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1))
     1058                                                 : (isRightAvail ? width : (width - 1))
     1059                                                 ;
     1060#else
     1061        endX   = isRightAvail ? (width - skipLinesR[typeIdx]): (width - 1);
     1062#endif
     1063        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     1064
     1065        //prepare 2nd line's upper sign
     1066        Pel* srcLineBelow = srcLine + srcStride;
     1067        for (x=startX; x<endX+1; x++)
     1068        {
     1069          signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x-1]];
     1070        }
     1071
     1072        //1st line
     1073        Pel* srcLineAbove = srcLine - srcStride;
     1074#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1075        firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveLeftAvail ? 0    : 1) : startX;
     1076        firstLineEndX   = (!isCalculatePreDeblockSamples) ? (isAboveAvail     ? endX : 1) : endX;
     1077#else
     1078        firstLineStartX = isAboveLeftAvail ? 0    : 1;
     1079        firstLineEndX   = isAboveAvail     ? endX : 1;
     1080#endif
     1081        for(x=firstLineStartX; x<firstLineEndX; x++)
     1082        {
     1083          edgeType = m_sign[srcLine[x] - srcLineAbove[x-1]] - signUpLine[x+1];
     1084          diff [edgeType] += (orgLine[x] - srcLine[x]);
     1085          count[edgeType] ++;
     1086        }
     1087        srcLine  += srcStride;
     1088        orgLine  += orgStride;
     1089
     1090
     1091        //middle lines
     1092        for (y=1; y<endY; y++)
     1093        {
     1094          srcLineBelow = srcLine + srcStride;
     1095
     1096          for (x=startX; x<endX; x++)
     1097          {
     1098            signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x+1]] ;
     1099            edgeType = signDown + signUpLine[x];
     1100            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1101            count[edgeType] ++;
     1102
     1103            signDownLine[x+1] = -signDown;
     1104          }
     1105          signDownLine[startX] = (Char)m_sign[srcLineBelow[startX] - srcLine[startX-1]];
     1106
     1107          signTmpLine  = signUpLine;
     1108          signUpLine   = signDownLine;
     1109          signDownLine = signTmpLine;
     1110
     1111          srcLine += srcStride;
     1112          orgLine += orgStride;
     1113        }
     1114#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1115        if(isCalculatePreDeblockSamples)
     1116        {
     1117          if(isBelowAvail)
     1118          {
     1119            startX = isLeftAvail  ? 0     : 1 ;
     1120            endX   = isRightAvail ? width : (width -1);
     1121
     1122            for(y=0; y<skipLinesB[typeIdx]; y++)
     1123            {
     1124              srcLineBelow = srcLine + srcStride;
     1125              srcLineAbove = srcLine - srcStride;
     1126
     1127              for (x=startX; x< endX; x++)
     1128              {
     1129                edgeType = m_sign[srcLine[x] - srcLineBelow[x+1]] + m_sign[srcLine[x] - srcLineAbove[x-1]];
     1130                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1131                count[edgeType] ++;
     1132              }
     1133              srcLine  += srcStride;
     1134              orgLine  += orgStride;
     1135            }
     1136          }
     1137        }
     1138#endif
     1139      }
     1140      break;
     1141    case SAO_TYPE_EO_45:
     1142      {
     1143        diff +=2;
     1144        count+=2;
     1145        Char *signUpLine = m_signLineBuf1+1;
     1146
     1147#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1148        startX = (!isCalculatePreDeblockSamples) ? (isLeftAvail  ? 0 : 1)
     1149                                                 : (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1150                                                 ;
     1151#else
     1152        startX = isLeftAvail ? 0 : 1;
     1153#endif
     1154#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1155        endX   = (!isCalculatePreDeblockSamples) ? (isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1))
     1156                                                 : (isRightAvail ? width : (width - 1))
     1157                                                 ;
     1158#else
     1159        endX   = isRightAvail ? (width - skipLinesR[typeIdx]) : (width - 1);
     1160#endif
     1161        endY   = isBelowAvail ? (height - skipLinesB[typeIdx]) : (height - 1);
     1162
     1163        //prepare 2nd line upper sign
     1164        Pel* srcLineBelow = srcLine + srcStride;
     1165        for (x=startX-1; x<endX; x++)
     1166        {
     1167          signUpLine[x] = (Char)m_sign[srcLineBelow[x] - srcLine[x+1]];
     1168        }
     1169
     1170
     1171        //first line
     1172        Pel* srcLineAbove = srcLine - srcStride;
     1173#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1174        firstLineStartX = (!isCalculatePreDeblockSamples) ? (isAboveAvail ? startX : endX)
     1175                                                          : startX
     1176                                                          ;
     1177        firstLineEndX   = (!isCalculatePreDeblockSamples) ? ((!isRightAvail && isAboveRightAvail) ? width : endX)
     1178                                                          : endX
     1179                                                          ;
     1180#else
     1181        firstLineStartX = isAboveAvail ? startX : endX;
     1182        firstLineEndX   = (!isRightAvail && isAboveRightAvail) ? width : endX;
     1183#endif
     1184        for(x=firstLineStartX; x<firstLineEndX; x++)
     1185        {
     1186          edgeType = m_sign[srcLine[x] - srcLineAbove[x+1]] - signUpLine[x-1];
     1187          diff [edgeType] += (orgLine[x] - srcLine[x]);
     1188          count[edgeType] ++;
     1189        }
     1190
     1191        srcLine += srcStride;
     1192        orgLine += orgStride;
     1193
     1194        //middle lines
     1195        for (y=1; y<endY; y++)
     1196        {
     1197          srcLineBelow = srcLine + srcStride;
     1198
     1199          for(x=startX; x<endX; x++)
     1200          {
     1201            signDown = (Char)m_sign[srcLine[x] - srcLineBelow[x-1]] ;
     1202            edgeType = signDown + signUpLine[x];
     1203
     1204            diff [edgeType] += (orgLine[x] - srcLine[x]);
     1205            count[edgeType] ++;
     1206
     1207            signUpLine[x-1] = -signDown;
     1208          }
     1209          signUpLine[endX-1] = (Char)m_sign[srcLineBelow[endX-1] - srcLine[endX]];
     1210          srcLine  += srcStride;
     1211          orgLine  += orgStride;
     1212        }
     1213#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1214        if(isCalculatePreDeblockSamples)
     1215        {
     1216          if(isBelowAvail)
     1217          {
     1218            startX = isLeftAvail  ? 0     : 1 ;
     1219            endX   = isRightAvail ? width : (width -1);
     1220
     1221            for(y=0; y<skipLinesB[typeIdx]; y++)
     1222            {
     1223              srcLineBelow = srcLine + srcStride;
     1224              srcLineAbove = srcLine - srcStride;
     1225
     1226              for (x=startX; x<endX; x++)
     1227              {
     1228                edgeType = m_sign[srcLine[x] - srcLineBelow[x-1]] + m_sign[srcLine[x] - srcLineAbove[x+1]];
     1229                diff [edgeType] += (orgLine[x] - srcLine[x]);
     1230                count[edgeType] ++;
     1231              }
     1232              srcLine  += srcStride;
     1233              orgLine  += orgStride;
     1234            }
     1235          }
     1236        }
     1237#endif
     1238      }
     1239      break;
     1240    case SAO_TYPE_BO:
     1241      {
     1242#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1243        startX = (!isCalculatePreDeblockSamples)?0
     1244                                                :( isRightAvail?(width- skipLinesR[typeIdx]):width)
     1245                                                ;
     1246        endX   = (!isCalculatePreDeblockSamples)?(isRightAvail ? (width - skipLinesR[typeIdx]) : width )
     1247                                                :width
     1248                                                ;
     1249#else
     1250        endX = isRightAvail ? (width- skipLinesR[typeIdx]) : width;
     1251#endif
     1252        endY = isBelowAvail ? (height- skipLinesB[typeIdx]) : height;
     1253        Int shiftBits = ((compIdx == SAO_Y)?g_bitDepthY:g_bitDepthC)- NUM_SAO_BO_CLASSES_LOG2;
     1254        for (y=0; y< endY; y++)
     1255        {
     1256#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1257          for (x=startX; x< endX; x++)
     1258#else
     1259          for (x=0; x< endX; x++)
     1260#endif
     1261          {
     1262
     1263            Int bandIdx= srcLine[x] >> shiftBits;
     1264            diff [bandIdx] += (orgLine[x] - srcLine[x]);
     1265            count[bandIdx] ++;
     1266          }
     1267          srcLine += srcStride;
     1268          orgLine += orgStride;
     1269        }
     1270#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     1271        if(isCalculatePreDeblockSamples)
     1272        {
     1273          if(isBelowAvail)
     1274          {
     1275            startX = 0;
     1276            endX   = width;
     1277
     1278            for(y= 0; y< skipLinesB[typeIdx]; y++)
     1279            {
     1280              for (x=startX; x< endX; x++)
     1281              {
     1282                Int bandIdx= srcLine[x] >> shiftBits;
     1283                diff [bandIdx] += (orgLine[x] - srcLine[x]);
     1284                count[bandIdx] ++;
     1285              }
     1286              srcLine  += srcStride;
     1287              orgLine  += orgStride;
     1288
     1289            }
     1290
     1291          }
     1292        }
     1293#endif
     1294      }
     1295      break;
     1296    default:
     1297      {
     1298        printf("Not a supported SAO types\n");
     1299        assert(0);
     1300        exit(-1);
     1301      }
     1302    }
     1303  }
     1304}
     1305
     1306#else
     1307
     1308
     1309
    471310TEncSampleAdaptiveOffset::TEncSampleAdaptiveOffset()
    481311{
     
    16612924}
    16622925
    1663 #if SAO_CHROMA_LAMBDA
    16642926/** Sample adaptive offset process
    16652927 * \param pcSaoParam
     
    16712933#else
    16722934Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambdaLuma, Double dLambdaChroma)
    1673 #endif
    1674 #else
    1675 /** Sample adaptive offset process
    1676  * \param dLambda
    1677  */
    1678 Void TEncSampleAdaptiveOffset::SAOProcess(SAOParam *pcSaoParam, Double dLambda)
    16792935#endif
    16802936{
     
    25013757}
    25023758
     3759#endif
     3760
    25033761//! \}
  • trunk/source/Lib/TLibEncoder/TEncSampleAdaptiveOffset.h

    r313 r540  
    5353// Class definition
    5454// ====================================================================================================================
     55
     56#if HM_CLEANUP_SAO
     57enum SAOCabacStateLablesRDO //CABAC state labels
     58{
     59  SAO_CABACSTATE_PIC_INIT =0,
     60  SAO_CABACSTATE_BLK_CUR,
     61  SAO_CABACSTATE_BLK_NEXT,
     62  SAO_CABACSTATE_BLK_MID,
     63  SAO_CABACSTATE_BLK_TEMP,
     64  NUM_SAO_CABACSTATE_LABELS
     65};
     66
     67struct SAOStatData //data structure for SAO statistics
     68{
     69  Int64 diff[MAX_NUM_SAO_CLASSES];
     70  Int64 count[MAX_NUM_SAO_CLASSES];
     71
     72  SAOStatData(){}
     73  ~SAOStatData(){}
     74  Void reset()
     75  {
     76    ::memset(diff, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     77    ::memset(count, 0, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     78  }
     79  const SAOStatData& operator=(const SAOStatData& src)
     80  {
     81    ::memcpy(diff, src.diff, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     82    ::memcpy(count, src.count, sizeof(Int64)*MAX_NUM_SAO_CLASSES);
     83    return *this;
     84  }
     85#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     86  const SAOStatData& operator+= (const SAOStatData& src)
     87  {
     88    for(Int i=0; i< MAX_NUM_SAO_CLASSES; i++)
     89    {
     90      diff[i] += src.diff[i];
     91      count[i] += src.count[i];
     92    }
     93    return *this;
     94  }
     95#endif
     96};
     97
     98class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
     99{
     100public:
     101  TEncSampleAdaptiveOffset();
     102  virtual ~TEncSampleAdaptiveOffset();
     103
     104  //interface
     105#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     106  Void createEncData(Bool isPreDBFSamplesUsed);
     107#else
     108  Void createEncData();
     109#endif
     110  Void destroyEncData();
     111  Void initRDOCabacCoder(TEncSbac* pcRDGoOnSbacCoder, TComSlice* pcSlice) ;
     112  Void SAOProcess(TComPic* pPic, Bool* sliceEnabled, const Double *lambdas
     113#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     114                , Bool isPreDBFSamplesUsed
     115#endif
     116                );
     117public: //methods
     118#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     119  Void getPreDBFStatistics(TComPic* pPic);
     120#endif
     121private: //methods
     122  Void getStatistics(SAOStatData*** blkStats, TComPicYuv* orgYuv, TComPicYuv* srcYuv,TComPic* pPic
     123#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     124                   , Bool isCalculatePreDeblockSamples = false
     125#endif
     126                   );
     127  Void decidePicParams(Bool* sliceEnabled, Int picTempLayer);
     128  Void decideBlkParams(TComPic* pic, Bool* sliceEnabled, SAOStatData*** blkStats, TComPicYuv* srcYuv, TComPicYuv* resYuv, SAOBlkParam* reconParams, SAOBlkParam* codedParams);
     129  Void getBlkStats(Int compIdx, SAOStatData* statsDataTypes, Pel* srcBlk, Pel* orgBlk, Int srcStride, Int orgStride, Int width, Int height, Bool isLeftAvail,  Bool isRightAvail, Bool isAboveAvail, Bool isBelowAvail, Bool isAboveLeftAvail, Bool isAboveRightAvail, Bool isBelowLeftAvail, Bool isBelowRightAvail
     130#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     131                  , Bool isCalculatePreDeblockSamples
     132#endif
     133                  );
     134  Void deriveModeNewRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
     135  Void deriveModeMergeRDO(Int ctu, std::vector<SAOBlkParam*>& mergeList, Bool* sliceEnabled, SAOStatData*** blkStats, SAOBlkParam& modeParam, Double& modeNormCost, TEncSbac** cabacCoderRDO, Int inCabacLabel);
     136  Int64 getDistortion(Int ctu, Int compIdx, Int typeIdc, Int typeAuxInfo, Int* offsetVal, SAOStatData& statData);
     137  Void deriveOffsets(Int ctu, Int compIdx, Int typeIdc, SAOStatData& statData, Int* quantOffsets, Int& typeAuxInfo);
     138  inline Int64 estSaoDist(Int64 count, Int64 offset, Int64 diffSum, Int shift);
     139  inline Int estIterOffset(Int typeIdx, Int classIdx, Double lambda, Int offsetInput, Int64 count, Int64 diffSum, Int shift, Int bitIncrease, Int64& bestDist, Double& bestCost, Int offsetTh );
     140#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     141  Void addPreDBFStatistics(SAOStatData*** blkStats);
     142#endif
     143private: //members
     144  //for RDO
     145  TEncSbac**             m_pppcRDSbacCoder;           
     146  TEncSbac*              m_pcRDGoOnSbacCoder;
     147  TEncBinCABACCounter**  m_pppcBinCoderCABAC;   
     148  Double                 m_labmda[NUM_SAO_COMPONENTS];
     149
     150  //statistics
     151  SAOStatData***         m_statData; //[ctu][comp][classes]
     152#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     153  SAOStatData***         m_preDBFstatData;
     154#endif
     155#if SAO_ENCODING_CHOICE
     156  Double                 m_saoDisabledRate[NUM_SAO_COMPONENTS][MAX_TLAYER];
     157#endif
     158  Int                    m_skipLinesR[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
     159  Int                    m_skipLinesB[NUM_SAO_COMPONENTS][NUM_SAO_NEW_TYPES];
     160};
     161#else
     162
    55163
    56164class TEncSampleAdaptiveOffset : public TComSampleAdaptiveOffset
     
    95203  Void endSaoEnc();
    96204  Void resetStats();
    97 #if SAO_CHROMA_LAMBDA
    98205#if SAO_ENCODING_CHOICE
    99206  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma, Int depth);
    100207#else
    101208  Void SAOProcess(SAOParam *pcSaoParam, Double dLambda, Double dLambdaChroma);
    102 #endif
    103 #else
    104   Void SAOProcess(SAOParam *pcSaoParam, Double dLambda);
    105209#endif
    106210
     
    131235  Int  getMaxNumOffsetsPerPic() {return m_maxNumOffsetsPerPic; }
    132236};
    133 
     237#endif
    134238//! \}
    135239
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r494 r540  
    416416{
    417417  PartSize eSize         = pcCU->getPartitionSize( uiAbsPartIdx );
    418 
    419418  if ( pcCU->isIntra( uiAbsPartIdx ) )
    420419  {
     
    13941393  {
    13951394    m_pcBinIf->encodeBin( 1, m_cSaoTypeIdxSCModel.get( 0, 0, 0 ) );
     1395#if HM_CLEANUP_SAO
     1396    m_pcBinIf->encodeBinEP( uiCode == 1 ? 0 : 1 );
     1397#else
    13961398    m_pcBinIf->encodeBinEP( uiCode <= 4 ? 1 : 0 );
     1399#endif
    13971400  }
    13981401}
     
    15971600}
    15981601
     1602#if HM_CLEANUP_SAO
     1603Void TEncSbac::codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled)
     1604{
     1605  UInt uiSymbol;
     1606  if(!sliceEnabled)
     1607  {
     1608    assert(ctbParam.modeIdc == SAO_MODE_OFF);
     1609    return;
     1610  }
     1611
     1612  //type
     1613  if(compIdx == SAO_Y || compIdx == SAO_Cb)
     1614  {
     1615    //sao_type_idx_luma or sao_type_idx_chroma
     1616    if(ctbParam.modeIdc == SAO_MODE_OFF)
     1617    {
     1618      uiSymbol =0;
     1619    }
     1620    else if(ctbParam.typeIdc == SAO_TYPE_BO) //BO
     1621    {
     1622      uiSymbol = 1;
     1623    }
     1624    else
     1625    {
     1626      assert(ctbParam.typeIdc < SAO_TYPE_START_BO); //EO
     1627      uiSymbol = 2;
     1628    }
     1629    codeSaoTypeIdx(uiSymbol);
     1630  }
     1631
     1632  if(ctbParam.modeIdc == SAO_MODE_NEW)
     1633  {
     1634    Int numClasses = (ctbParam.typeIdc == SAO_TYPE_BO)?4:NUM_SAO_EO_CLASSES;
     1635    Int offset[4];
     1636    Int k=0;
     1637    for(Int i=0; i< numClasses; i++)
     1638    {
     1639      if(ctbParam.typeIdc != SAO_TYPE_BO && i == SAO_CLASS_EO_PLAIN)
     1640      {
     1641        continue;
     1642      }
     1643      Int classIdx = (ctbParam.typeIdc == SAO_TYPE_BO)?(  (ctbParam.typeAuxInfo+i)% NUM_SAO_BO_CLASSES   ):i;
     1644      offset[k] = ctbParam.offset[classIdx];
     1645      k++;
     1646    }
     1647
     1648    for(Int i=0; i< 4; i++)
     1649    {
     1650      codeSaoMaxUvlc((offset[i]<0)?(-offset[i]):(offset[i]),  g_saoMaxOffsetQVal[compIdx] ); //sao_offset_abs
     1651    }
     1652
     1653
     1654    if(ctbParam.typeIdc == SAO_TYPE_BO)
     1655    {
     1656      for(Int i=0; i< 4; i++)
     1657      {
     1658        if(offset[i] != 0)
     1659        {
     1660          codeSAOSign((offset[i]< 0)?1:0);
     1661        }
     1662      }
     1663
     1664      codeSaoUflc(NUM_SAO_BO_CLASSES_LOG2, ctbParam.typeAuxInfo ); //sao_band_position
     1665    }
     1666    else //EO
     1667    {
     1668      if(compIdx == SAO_Y || compIdx == SAO_Cb)
     1669      {
     1670        assert(ctbParam.typeIdc - SAO_TYPE_START_EO >=0);
     1671        codeSaoUflc(NUM_SAO_EO_TYPES_LOG2, ctbParam.typeIdc - SAO_TYPE_START_EO ); //sao_eo_class_luma or sao_eo_class_chroma
     1672      }
     1673    }
     1674
     1675  }
     1676}
     1677
     1678
     1679Void TEncSbac::codeSAOBlkParam(SAOBlkParam& saoBlkParam
     1680                              , Bool* sliceEnabled
     1681                              , Bool leftMergeAvail
     1682                              , Bool aboveMergeAvail
     1683                              , Bool onlyEstMergeInfo // = false
     1684                              )
     1685{
     1686
     1687  Bool isLeftMerge = false;
     1688  Bool isAboveMerge= false;
     1689
     1690  if(leftMergeAvail)
     1691  {
     1692    isLeftMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_LEFT));
     1693    codeSaoMerge( isLeftMerge?1:0  ); //sao_merge_left_flag
     1694  }
     1695
     1696  if( aboveMergeAvail && !isLeftMerge)
     1697  {
     1698    isAboveMerge = ((saoBlkParam[SAO_Y].modeIdc == SAO_MODE_MERGE) && (saoBlkParam[SAO_Y].typeIdc == SAO_MERGE_ABOVE));
     1699    codeSaoMerge( isAboveMerge?1:0  ); //sao_merge_left_flag
     1700  }
     1701
     1702  if(onlyEstMergeInfo)
     1703  {
     1704    return; //only for RDO
     1705  }
     1706
     1707  if(!isLeftMerge && !isAboveMerge) //not merge mode
     1708  {
     1709    for(Int compIdx=0; compIdx < NUM_SAO_COMPONENTS; compIdx++)
     1710    {
     1711      codeSAOOffsetParam(compIdx, saoBlkParam[compIdx], sliceEnabled[compIdx]);
     1712    }
     1713  }
     1714}
     1715#endif
     1716
    15991717//! \}
  • trunk/source/Lib/TLibEncoder/TEncSbac.h

    r345 r540  
    103103  Void  codeSAOSign       ( UInt  uiCode);  //<! code SAO offset sign
    104104  Void  codeScalingList      ( TComScalingList* /*scalingList*/     ){ assert (0);  return;};
     105
     106#if HM_CLEANUP_SAO
     107  Void codeSAOOffsetParam(Int compIdx, SAOOffset& ctbParam, Bool sliceEnabled);
     108  Void codeSAOBlkParam(SAOBlkParam& saoBlkParam
     109                    , Bool* sliceEnabled
     110                    , Bool leftMergeAvail
     111                    , Bool aboveMergeAvail
     112                    , Bool onlyEstMergeInfo = false
     113                    );
     114#endif
    105115
    106116private:
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r494 r540  
    720720  Pel*  piRefPos;
    721721  Int iRefStride = m_filteredBlock[0][0].getStride();
    722 #if NS_HAD
    723   m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    724 #else
    725722  m_pcRdCost->setDistParam( pcPatternKey, m_filteredBlock[0][0].getLumaAddr(), iRefStride, 1, m_cDistParam, m_pcEncCfg->getUseHADME() );
    726 #endif
    727723 
    728724  const TComMv* pcMvRefine = (iFrac == 2 ? s_acMvRefineH : s_acMvRefineQ);
     
    737733    piRefPos = m_filteredBlock[ verVal & 3 ][ horVal & 3 ].getLumaAddr();
    738734    if ( horVal == 2 && ( verVal & 1 ) == 0 )
     735    {
    739736      piRefPos += 1;
     737    }
    740738    if ( ( horVal & 1 ) == 0 && verVal == 2 )
     739    {
    741740      piRefPos += iRefStride;
     741    }
    742742    cMvTest = pcMvRefine[i];
    743743    cMvTest += rcMvFrac;
     
    774774  UInt  uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiFullDepth;
    775775
    776   {
    777     if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 )
    778     {
    779       assert( uiSubdiv );
    780     }
    781     else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
    782     {
    783       assert( uiSubdiv );
    784     }
    785     else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
    786     {
    787       assert( !uiSubdiv );
    788     }
    789     else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    790     {
    791       assert( !uiSubdiv );
    792     }
    793     else
    794     {
    795       assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
    796       if( bLuma )
    797       {
    798         m_pcEntropyCoder->encodeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
    799       }
     776  if( pcCU->getPredictionMode(0) == MODE_INTRA && pcCU->getPartitionSize(0) == SIZE_NxN && uiTrDepth == 0 )
     777  {
     778    assert( uiSubdiv );
     779  }
     780  else if( uiLog2TrafoSize > pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() )
     781  {
     782    assert( uiSubdiv );
     783  }
     784  else if( uiLog2TrafoSize == pcCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() )
     785  {
     786    assert( !uiSubdiv );
     787  }
     788  else if( uiLog2TrafoSize == pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     789  {
     790    assert( !uiSubdiv );
     791  }
     792  else
     793  {
     794    assert( uiLog2TrafoSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
     795    if( bLuma )
     796    {
     797      m_pcEntropyCoder->encodeTransformSubdivFlag( uiSubdiv, 5 - uiLog2TrafoSize );
    800798    }
    801799  }
     
    806804    {
    807805      if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth-1 ) )
     806      {
    808807        m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrDepth );
     808      }
    809809      if( uiTrDepth==0 || pcCU->getCbf( uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth-1 ) )
     810      {
    810811        m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrDepth );
     812      }
    811813    }
    812814  }
     
    822824  }
    823825 
    824   {
    825     //===== Cbfs =====
    826     if( bLuma )
    827     {
    828       m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    829     }
     826  //===== Cbfs =====
     827  if( bLuma )
     828  {
     829    m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    830830  }
    831831}
     
    944944    }
    945945  }
    946 
    947946  if( bChroma )
    948947  {
     
    13061305
    13071306#if RDOQ_CHROMA_LAMBDA
    1308     m_pcTrQuant->selectLambda      (TEXT_CHROMA); 
     1307    m_pcTrQuant->selectLambda(eText);
    13091308#endif
    13101309    m_pcTrQuant->transformNxN      ( pcCU, piResi, uiStride, pcCoeff,
     
    13581357 
    13591358  //===== update distortion =====
    1360 #if WEIGHTED_CHROMA_DISTORTION
    13611359  ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight, eText );
    1362 #else
    1363   ruiDist += m_pcRdCost->getDistPart(g_bitDepthC, piReco, uiStride, piOrg, uiStride, uiWidth, uiHeight );
    1364 #endif
    13651360}
    13661361
     
    25392534     
    25402535      for( Int j=0; j < numCand; j++)
    2541 
    25422536      {
    25432537        Bool mostProbableModeIncluded = false;
     
    30393033                            pcYuvOrg->getLumaAddr( uiAbsPartIdx ), pcYuvOrg->getStride(),
    30403034                            m_tmpYuvPred .getLumaAddr( uiAbsPartIdx ), m_tmpYuvPred .getStride(),
    3041 #if NS_HAD
    3042                             iWidth, iHeight, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    3043 #else
    30443035                            iWidth, iHeight, m_pcEncCfg->getUseHADME() );
    3045 #endif
    30463036  ruiErr = cDistParam.DistFunc( &cDistParam );
    30473037}
     
    32463236
    32473237    UInt          uiCostTempL0[MAX_NUM_REF];
    3248     for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++) uiCostTempL0[iNumRef] = MAX_UINT;
     3238    for (Int iNumRef=0; iNumRef < MAX_NUM_REF; iNumRef++)
     3239    {
     3240      uiCostTempL0[iNumRef] = MAX_UINT;
     3241    }
    32493242    UInt          uiBitsTempL0[MAX_NUM_REF];
    32503243
     
    37163709    {
    37173710      uiLastMode = 2;
    3718       {
    3719             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3720             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3721             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3722             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3723       }
    3724       {
    3725         TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]];
    3726             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    3727       }
    3728       {
    3729         TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]];
    3730             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    3731       }
     3711      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMvBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3712      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdxBi[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3713      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMvBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
     3714      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdxBi[1], ePartSize, uiPartAddr, 0, iPartIdx );
     3715     
     3716      TempMv = cMvBi[0] - cMvPredBi[0][iRefIdxBi[0]];
     3717      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
     3718     
     3719      TempMv = cMvBi[1] - cMvPredBi[1][iRefIdxBi[1]];
     3720      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    37323721     
    37333722      pcCU->setInterDirSubParts( 3, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
     
    37433732    {
    37443733      uiLastMode = 0;
    3745           pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3746           pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3747       {
    3748         TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
    3749             pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    3750       }
     3734      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3735      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3736      TempMv = cMv[0] - cMvPred[0][iRefIdx[0]];
     3737      pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    37513738      pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    37523739     
     
    37593746    {
    37603747      uiLastMode = 1;
    3761           pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3762           pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3763       {
    3764         TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
    3765             pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    3766       }
     3748      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
     3749      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
     3750      TempMv = cMv[1] - cMvPred[1][iRefIdx[1]];
     3751      pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TempMv,                 ePartSize, uiPartAddr, 0, iPartIdx );
    37673752      pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
    37683753     
     
    38163801        pcCU->setMergeIndexSubParts( uiMRGIndex,    uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    38173802        pcCU->setInterDirSubParts  ( uiMRGInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    3818         {
    3819           pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3820           pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3821         }
     3803        pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMRGMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3804        pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMRGMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    38223805
    38233806        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( cMvZero,            ePartSize, uiPartAddr, 0, iPartIdx );
     
    38343817        pcCU->setMergeFlagSubParts( false,        uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    38353818        pcCU->setInterDirSubParts ( uiMEInterDir, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
    3836         {
    3837           pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
    3838           pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    3839         }
     3819        pcCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMEMvField[0], ePartSize, uiPartAddr, 0, iPartIdx );
     3820        pcCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMEMvField[1], ePartSize, uiPartAddr, 0, iPartIdx );
    38403821      }
    38413822    }
     
    39443925 
    39453926  if (iNum == 1)
     3927  {
    39463928    return 0;
     3929  }
    39473930 
    39483931  UInt uiLength = 1;
     
    41234106                            pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(),
    41244107                            pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(),
    4125 #if NS_HAD
    4126                             iSizeX, iSizeY, m_pcEncCfg->getUseHADME(), m_pcEncCfg->getUseNSQT() );
    4127 #else
    41284108                            iSizeX, iSizeY, m_pcEncCfg->getUseHADME() );
    4129 #endif
    41304109  ruiDist = cDistParam.DistFunc( &cDistParam );
    41314110  uiCost = ruiDist + m_pcRdCost->getCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum] );
    41324111#else
    4133 #if WEIGHTED_CHROMA_DISTORTION
    41344112  uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, TEXT_LUMA, DF_SAD );
    4135 #else
    4136   uiCost = m_pcRdCost->getDistPart(g_bitDepthY, pcTemplateCand->getLumaAddr(uiPartAddr), pcTemplateCand->getStride(), pcOrgYuv->getLumaAddr(uiPartAddr), pcOrgYuv->getStride(), iSizeX, iSizeY, DF_SAD );
    4137 #endif
    41384113  uiCost = (UInt) m_pcRdCost->calcRdCost( m_auiMVPIdxCost[iMVPIdx][iMVPNum], uiCost, false, DF_SAD );
    41394114#endif
     
    42284203  m_pcRdCost->getMotionCost( 1, 0 );
    42294204  m_pcRdCost->setCostScale ( 1 );
    4230  
    4231   {
     4205
    42324206#if REF_IDX_ME_ZEROMV
    4233     if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId()))  //ILR reference pic
    4234     {
    4235       xPatternSearchFracDIFMv0( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
    4236     }
    4237     else    //non ILR reference pic
    4238     {
    4239       xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
    4240     }
     4207  if( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxPred )->isILR(pcCU->getLayerId()))  //ILR reference pic
     4208  {
     4209    xPatternSearchFracDIFMv0( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
     4210  }
     4211  else    //non ILR reference pic
     4212  {
     4213    xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost, bBi );
     4214  }
    42414215#else
    4242     xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost
    4243                           ,bBi
    4244                           );
    4245 #endif
    4246   }
    4247  
    4248  
    4249  
     4216  xPatternSearchFracDIF( pcCU, pcPatternKey, piRefY, iRefStride, &rcMv, cMvHalf, cMvQter, ruiCost,bBi );
     4217#endif
     4218
    42504219  m_pcRdCost->setCostScale( 0 );
    42514220  rcMv <<= 2;
     
    46014570    pcYuvPred->copyToPartYuv( rpcYuvRec, 0 );
    46024571   
    4603 #if WEIGHTED_CHROMA_DISTORTION
    46044572    uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    46054573    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U )
    46064574    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V );
    4607 #else
    4608     uiDistortion = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    4609     + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )
    4610     + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );
    4611 #endif
    46124575
    46134576    if( m_bUseSBACRD )
     4577    {
    46144578      m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_CURR_BEST]);
     4579    }
    46154580   
    46164581    m_pcEntropyCoder->resetBits();
     
    46284593   
    46294594    if( m_bUseSBACRD )
     4595    {
    46304596      m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[pcCU->getDepth(0)][CI_TEMP_BEST]);
     4597    }
    46314598   
    46324599    pcCU->setCbfSubParts( 0, 0, 0, 0, pcCU->getDepth( 0 ) );
     
    47994766 
    48004767  // update with clipped distortion and cost (qp estimation loop uses unclipped values)
    4801 #if WEIGHTED_CHROMA_DISTORTION
    48024768    uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    48034769    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_U )
    48044770    + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1, TEXT_CHROMA_V );
    4805 #else
    4806   uiDistortionBest = m_pcRdCost->getDistPart(g_bitDepthY, rpcYuvRec->getLumaAddr(), rpcYuvRec->getStride(),  pcYuvOrg->getLumaAddr(), pcYuvOrg->getStride(),  uiWidth,      uiHeight      )
    4807   + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCbAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCbAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 )
    4808   + m_pcRdCost->getDistPart(g_bitDepthC, rpcYuvRec->getCrAddr(),   rpcYuvRec->getCStride(), pcYuvOrg->getCrAddr(),   pcYuvOrg->getCStride(), uiWidth >> 1, uiHeight >> 1 );
    4809 #endif
    48104771  dCostBest = m_pcRdCost->calcRdCost( uiBitsBest, uiDistortionBest );
    48114772 
     
    48324793  Bool bCheckFull;
    48334794  if ( SplitFlag && uiDepth == pcCU->getDepth(uiAbsPartIdx) && ( uiLog2TrSize >  pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) ) )
     4795  {
    48344796     bCheckFull = false;
     4797  }
    48354798  else
     4799  {
    48364800     bCheckFull =  ( uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() );
     4801  }
    48374802
    48384803  const Bool bCheckSplit  = ( uiLog2TrSize >  pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) );
     
    49324897
    49334898#if RDOQ_CHROMA_LAMBDA
    4934       m_pcTrQuant->selectLambda(TEXT_CHROMA);
     4899      m_pcTrQuant->selectLambda(TEXT_CHROMA_U);
    49354900#endif
    49364901
     
    49434908      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    49444909      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
     4910     
     4911#if RDOQ_CHROMA_LAMBDA
     4912      m_pcTrQuant->selectLambda(TEXT_CHROMA_V);
     4913#endif
     4914
    49454915      m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV,
    49464916#if ADAPTIVE_QP_SELECTION
     
    49554925    m_pcEntropyCoder->resetBits();
    49564926   
    4957     {
    4958       m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    4959     }
    4960    
     4927    m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
     4928
    49614929    m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx,  trWidth,  trHeight,    uiDepth, TEXT_LUMA );
    49624930    const UInt uiSingleBitsY = m_pcEntropyCoder->getNumberOfWrittenBits();
     
    49664934    if( bCodeChroma )
    49674935    {
    4968       {
    4969         m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    4970       }
     4936      m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    49714937      m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrU, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_U );
    49724938      uiSingleBitsU = m_pcEntropyCoder->getNumberOfWrittenBits() - uiSingleBitsY;
    49734939     
    4974       {
    4975         m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    4976       }
     4940      m_pcEntropyCoder->encodeQtCbf   ( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    49774941      m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrV, uiAbsPartIdx, trWidthC, trHeightC, uiDepth, TEXT_CHROMA_V );
    49784942      uiSingleBitsV = m_pcEntropyCoder->getNumberOfWrittenBits() - ( uiSingleBitsY + uiSingleBitsU );
     
    50034967      assert(scalingListType < 6);     
    50044968      m_pcTrQuant->invtransformNxN( pcCU->getCUTransquantBypass(uiAbsPartIdx), TEXT_LUMA,REG_DCT, pcResiCurrY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),  pcCoeffCurrY, trWidth, trHeight, scalingListType );//this is for inter mode only
     4969     
    50054970      const UInt uiNonzeroDistY = m_pcRdCost->getDistPart(g_bitDepthY, m_pcQTTempTComYuv[uiQTTempAccessLayer].getLumaAddr( absTUPartIdx ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getStride(),
    50064971      pcResi->getLumaAddr( absTUPartIdx ), pcResi->getStride(), trWidth,trHeight );
     
    50595024    {
    50605025      uiDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCbAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    5061 #if WEIGHTED_CHROMA_DISTORTION
    50625026                                        , TEXT_CHROMA_U
    5063 #endif
    50645027                                        ); // initialized with zero residual destortion
    50655028      if ( puiZeroDist )
     
    50805043        const UInt uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    50815044                                                            pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    5082 #if WEIGHTED_CHROMA_DISTORTION
    50835045                                                            , TEXT_CHROMA_U
    5084 #endif
    50855046                                                            );
    50865047
     
    51185079      {
    51195080        m_pcEntropyCoder->resetBits();
    5120         m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrModeC );
     5081        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_U, uiTrMode );
    51215082        const UInt uiNullBitsU = m_pcEntropyCoder->getNumberOfWrittenBits();
    51225083        minCostU = m_pcRdCost->calcRdCost( uiNullBitsU, uiDistU );
     
    51345095     
    51355096      uiDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pTempPel, trWidthC, pcResi->getCrAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    5136 #if WEIGHTED_CHROMA_DISTORTION
    51375097                                        , TEXT_CHROMA_V
    5138 #endif
    51395098                                        ); // initialized with zero residual destortion
    51405099      if ( puiZeroDist )
     
    51545113        const UInt uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    51555114                                                            pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    5156 #if WEIGHTED_CHROMA_DISTORTION
    51575115                                                            , TEXT_CHROMA_V
    5158 #endif
    51595116                                                            );
    51605117        if (pcCU->isLosslessCoded(0))
     
    51915148      {
    51925149        m_pcEntropyCoder->resetBits();
    5193         m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrModeC );
     5150        m_pcEntropyCoder->encodeQtCbfZero( pcCU, TEXT_CHROMA_V, uiTrMode );
    51945151        const UInt uiNullBitsV = m_pcEntropyCoder->getNumberOfWrittenBits();
    51955152        minCostV = m_pcRdCost->calcRdCost( uiNullBitsV, uiDistV );
     
    53525309
    53535310#if RDOQ_CHROMA_LAMBDA
    5354       m_pcTrQuant->selectLambda(TEXT_CHROMA);
     5311      m_pcTrQuant->selectLambda(TEXT_CHROMA_U);
    53555312#endif
    53565313
     
    53625319      curChromaQpOffset = pcCU->getSlice()->getPPS()->getChromaCrQpOffset() + pcCU->getSlice()->getSliceQpDeltaCr();
    53635320      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_CHROMA, pcCU->getSlice()->getSPS()->getQpBDOffsetC(), curChromaQpOffset );
     5321#if RDOQ_CHROMA_LAMBDA
     5322      m_pcTrQuant->selectLambda(TEXT_CHROMA_V);
     5323#endif
    53645324      m_pcTrQuant->transformNxN( pcCU, pcResi->getCrAddr(absTUPartIdxC), pcResi->getCStride(), pcCoeffCurrV,
    53655325#if ADAPTIVE_QP_SELECTION
     
    53915351        uiNonzeroDistU = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCbAddr( absTUPartIdxC), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    53925352                                                 pcResi->getCbAddr( absTUPartIdxC), pcResi->getCStride(), trWidthC, trHeightC
    5393 #if WEIGHTED_CHROMA_DISTORTION
    53945353                                                 , TEXT_CHROMA_U
    5395 #endif
    53965354                                                 );
    53975355
     
    54355393        uiNonzeroDistV = m_pcRdCost->getDistPart(g_bitDepthC, m_pcQTTempTComYuv[uiQTTempAccessLayer].getCrAddr( absTUPartIdxC ), m_pcQTTempTComYuv[uiQTTempAccessLayer].getCStride(),
    54365394                                                 pcResi->getCrAddr( absTUPartIdxC ), pcResi->getCStride(), trWidthC, trHeightC
    5437 #if WEIGHTED_CHROMA_DISTORTION
    54385395                                                 , TEXT_CHROMA_V
    5439 #endif
    54405396                                                 );
    54415397
     
    54745430    m_pcEntropyCoder->resetBits();
    54755431
    5476     {
    5477       if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    5478       {
    5479         m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize );
    5480       }
    5481     }
    5482 
    5483     {
    5484       if( bCodeChroma )
    5485       {
    5486         m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
    5487         m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
    5488       }
    5489 
    5490       m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    5491     }
     5432    if( uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     5433    {
     5434      m_pcEntropyCoder->encodeTransformSubdivFlag( 0, 5 - uiLog2TrSize );
     5435    }
     5436
     5437    if( bCodeChroma )
     5438    {
     5439      m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_U, uiTrMode );
     5440      m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_CHROMA_V, uiTrMode );
     5441    }
     5442
     5443    m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    54925444
    54935445    m_pcEntropyCoder->encodeCoeffNxN( pcCU, pcCoeffCurrY, uiAbsPartIdx, trWidth, trHeight,    uiDepth, TEXT_LUMA );
     
    55465498    m_pcEntropyCoder->resetBits();
    55475499   
    5548     {
    5549       xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true,  TEXT_LUMA );
    5550       xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA );
    5551       xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U );
    5552       xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V );
    5553     }
    5554    
     5500    xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, true,  TEXT_LUMA );
     5501    xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_LUMA );
     5502    xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_U );
     5503    xEncodeResidualQT( pcCU, uiAbsPartIdx, uiDepth, false, TEXT_CHROMA_V );
     5504
    55555505    uiSubdivBits = m_pcEntropyCoder->getNumberOfWrittenBits();
    55565506    dSubdivCost  = m_pcRdCost->calcRdCost( uiSubdivBits, uiSubdivDist );
     
    56025552  const UInt uiLog2TrSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth() >> uiDepth]+2;
    56035553
    5604   {
    5605     if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
    5606     {
    5607       m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize );
    5608     }
    5609   }
    5610 
    5611   {
    5612     assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA );
     5554  if( bSubdivAndCbf && uiLog2TrSize <= pcCU->getSlice()->getSPS()->getQuadtreeTULog2MaxSize() && uiLog2TrSize > pcCU->getQuadtreeTULog2MinSizeInCU(uiAbsPartIdx) )
     5555  {
     5556    m_pcEntropyCoder->encodeTransformSubdivFlag( bSubdiv, 5 - uiLog2TrSize );
     5557  }
     5558
     5559  assert( pcCU->getPredictionMode(uiAbsPartIdx) != MODE_INTRA );
    56135560    if( bSubdivAndCbf )
    56145561    {
     
    56315578      }
    56325579    }
    5633   }
    56345580 
    56355581  if( !bSubdiv )
     
    56555601    if( bSubdivAndCbf )
    56565602    {
    5657       {
    5658         m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    5659       }
     5603      m_pcEntropyCoder->encodeQtCbf( pcCU, uiAbsPartIdx, TEXT_LUMA,     uiTrMode );
    56605604    }
    56615605    else
     
    57255669      if( bCodeChroma )
    57265670      {
    5727         {
    5728           m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC );
    5729         }
     5671        m_pcQTTempTComYuv[uiQTTempAccessLayer].copyPartToPartChroma( pcResi, uiAbsPartIdx, 1 << uiLog2TrSizeC, 1 << uiLog2TrSizeC );
    57305672      }
    57315673    }
     
    58475789    m_pcEntropyCoder->encodePartSize( pcCU, 0, pcCU->getDepth(0), true );
    58485790    m_pcEntropyCoder->encodePredInfo( pcCU, 0, true );
    5849 
    58505791    Bool bDummy = false;
    58515792    m_pcEntropyCoder->encodeCoeff   ( pcCU, 0, pcCU->getDepth(0), pcCU->getWidth(0), pcCU->getHeight(0), bDummy );
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r494 r540  
    194194                                  UInt        uiPreCalcDistC );
    195195 
     196 
    196197  /// encoder estimation - inter prediction (non-skip)
    197198  Void predInterSearch          ( TComDataCU* pcCU,
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r494 r540  
    295295    dQP += pdQPs[ rpcSlice->getPOC() ];
    296296  }
    297 #if !RATE_CONTROL_LAMBDA_DOMAIN
    298   if ( m_pcCfg->getUseRateCtrl())
    299   {
    300     dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());
    301   }
    302 #endif
    303297  // ------------------------------------------------------------------------------------------------------------------
    304298  // Lambda computation
     
    386380  // store lambda
    387381  m_pcRdCost ->setLambda( dLambda );
    388 #if WEIGHTED_CHROMA_DISTORTION
    389382// for RDO
    390383  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    391   Double weight = 1.0;
     384  Double weight[2] = { 1.0, 1.0 };
    392385  Int qpc;
    393386  Int chromaQPOffset;
     
    395388  chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb();
    396389  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    397   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    398   m_pcRdCost->setCbDistortionWeight(weight);
     390  weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     391  m_pcRdCost->setCbDistortionWeight(weight[0]);
    399392
    400393  chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr();
    401394  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    402   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     395  weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     396  m_pcRdCost->setCrDistortionWeight(weight[1]);
     397
    403398#if JCTVC_M0259_LAMBDAREFINEMENT
    404399  if( rpcSlice->getLayerId() > 0 && m_ppcTEncTop[layerId]->getNumActiveRefLayers() && m_pcCfg->getGOPSize() >= 8 && rpcSlice->isIntra() == false && depth == 0 )
    405400  {
    406401    dLambda *= 1.1;
    407     weight *= 1.15;
    408   }
    409 #endif
    410   m_pcRdCost->setCrDistortionWeight(weight);
    411 #endif
    412 
     402    weight[1] *= 1.15;
     403    weight[0] *= 1.15;
     404
     405    m_pcRdCost ->setLambda( dLambda );
     406    m_pcRdCost->setCbDistortionWeight(weight[0]);
     407    m_pcRdCost->setCrDistortionWeight(weight[1]);
     408  }
     409#endif
     410
     411  const Double lambdaArray[3] = {dLambda, (dLambda / weight[0]), (dLambda / weight[1])};
     412 
    413413#if RDOQ_CHROMA_LAMBDA
    414414// for RDOQ
    415   m_pcTrQuant->setLambda( dLambda, dLambda / weight );
     415  m_pcTrQuant->setLambdas( lambdaArray );
    416416#else
    417417  m_pcTrQuant->setLambda( dLambda );
    418418#endif
    419419
    420 #if SAO_CHROMA_LAMBDA
    421420// For SAO
    422   rpcSlice   ->setLambda( dLambda, dLambda / weight );
    423 #else
    424   rpcSlice   ->setLambda( dLambda );
    425 #endif
     421  rpcSlice->setLambdas( lambdaArray );
    426422
    427423#if HB_LAMBDA_FOR_LDC
     
    430426
    431427#if SVC_EXTENSION
    432   if(m_pcCfg->getLayerId() > 0)
     428  if( m_pcCfg->getLayerId() > 0 && m_pcCfg->getNumActiveRefLayers() > 0 )
    433429  {
    434430    eSliceType=B_SLICE;
     
    500496
    501497  pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
    502 
    503498  if(eSliceType==I_SLICE)
    504499  {
     
    517512  rpcSlice->setSliceSegmentArgument ( m_pcCfg->getSliceSegmentArgument() );
    518513  rpcSlice->setMaxNumMergeCand        ( m_pcCfg->getMaxNumMergeCand()        );
     514#if HIGHER_LAYER_IRAP_SKIP_FLAG
     515  if (m_pcCfg->getSkipPictureAtArcSwitch() && m_pcCfg->getAdaptiveResolutionChange() > 0 && rpcSlice->getLayerId() == 1 && rpcSlice->getPOC() == m_pcCfg->getAdaptiveResolutionChange())
     516  {
     517    rpcSlice->setMaxNumMergeCand        ( 1 );
     518  }
     519#endif
    519520  xStoreWPparam( pPPS->getUseWP(), pPPS->getWPBiPred() );
    520521
     
    546547}
    547548
    548 #if RATE_CONTROL_LAMBDA_DOMAIN
    549549Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda )
    550550{
     
    555555  slice->setSliceQpBase ( sliceQP );
    556556  m_pcRdCost ->setLambda( lambda );
    557 #if WEIGHTED_CHROMA_DISTORTION
    558557  // for RDO
    559558  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    560   Double weight;
     559  Double weight[2] = { 1.0, 1.0 };
    561560  Int qpc;
    562561  Int chromaQPOffset;
     
    564563  chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb();
    565564  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
    566   weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    567   m_pcRdCost->setCbDistortionWeight(weight);
     565  weight[0] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     566  m_pcRdCost->setCbDistortionWeight(weight[0]);
    568567
    569568  chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr();
    570569  qpc = Clip3( 0, 57, sliceQP + chromaQPOffset);
    571   weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    572   m_pcRdCost->setCrDistortionWeight(weight);
    573 #endif
     570  weight[1] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     571  m_pcRdCost->setCrDistortionWeight(weight[1]);
     572
     573  const Double lambdaArray[3] = {lambda, (lambda / weight[0]), (lambda / weight[1])};
    574574
    575575#if RDOQ_CHROMA_LAMBDA
    576576  // for RDOQ
    577   m_pcTrQuant->setLambda( lambda, lambda / weight );
     577  m_pcTrQuant->setLambdas( lambdaArray );
    578578#else
    579579  m_pcTrQuant->setLambda( lambda );
    580580#endif
    581581
    582 #if SAO_CHROMA_LAMBDA
    583582  // For SAO
    584   slice   ->setLambda( lambda, lambda / weight );
    585 #else
    586   slice   ->setLambda( lambda );
    587 #endif
     583  slice->setLambdas( lambdaArray );
    588584}
    589 #else
    590 /**
    591  - lambda re-computation based on rate control QP
    592  */
    593 Void TEncSlice::xLamdaRecalculation(Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice)
    594 {
    595   Int qp;
    596   Double recalQP= (Double)changeQP;
    597   Double origQP = (Double)recalQP;
    598   Double lambda;
    599 
    600   // pre-compute lambda and QP values for all possible QP candidates
    601   for ( Int deltqQpIdx = 0; deltqQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; deltqQpIdx++ )
    602   {
    603     // compute QP value
    604     recalQP = origQP + ((deltqQpIdx+1)>>1)*(deltqQpIdx%2 ? -1 : 1);
    605 
    606     // compute lambda value
    607     Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    608     Int    SHIFT_QP = 12;
    609     Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
    610 #if FULL_NBIT
    611     Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
    612 #else
    613     Int    bitdepth_luma_qp_scale = 0;
    614 #endif
    615     Double qp_temp = (Double) recalQP + bitdepth_luma_qp_scale - SHIFT_QP;
    616 #if FULL_NBIT
    617     Double qp_temp_orig = (Double) recalQP - SHIFT_QP;
    618 #endif
    619     // Case #1: I or P-slices (key-frame)
    620     Double dQPFactor = m_pcCfg->getGOPEntry(idGOP).m_QPFactor;
    621     if ( eSliceType==I_SLICE )
    622     {
    623       dQPFactor=0.57*dLambda_scale;
    624     }
    625     lambda = dQPFactor*pow( 2.0, qp_temp/3.0 );
    626 
    627     if ( depth>0 )
    628     {
    629 #if FULL_NBIT
    630       lambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    631 #else
    632       lambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )
    633 #endif
    634     }
    635 
    636     // if hadamard is used in ME process
    637     if ( !m_pcCfg->getUseHADME() )
    638     {
    639       lambda *= 0.95;
    640     }
    641 
    642 #if REPN_FORMAT_IN_VPS
    643     qp = max( -pcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
    644 #else
    645     qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
    646 #endif
    647 
    648     m_pdRdPicLambda[deltqQpIdx] = lambda;
    649     m_pdRdPicQp    [deltqQpIdx] = recalQP;
    650     m_piRdPicQp    [deltqQpIdx] = qp;
    651   }
    652 
    653   // obtain dQP = 0 case
    654   lambda  = m_pdRdPicLambda[0];
    655   recalQP = m_pdRdPicQp    [0];
    656   qp      = m_piRdPicQp    [0];
    657 
    658   if( pcSlice->getSliceType( ) != I_SLICE )
    659   {
    660     lambda *= m_pcCfg->getLambdaModifier( depth );
    661   }
    662 
    663   // store lambda
    664   m_pcRdCost ->setLambda( lambda );
    665 #if WEIGHTED_CHROMA_DISTORTION
    666   // for RDO
    667   // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    668   Double weight = 1.0;
    669   Int qpc;
    670   Int chromaQPOffset;
    671 
    672   chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    673   qpc = Clip3( 0, 57, qp + chromaQPOffset);
    674   weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    675   m_pcRdCost->setCbDistortionWeight(weight);
    676 
    677   chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    678   qpc = Clip3( 0, 57, qp + chromaQPOffset);
    679   weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    680   m_pcRdCost->setCrDistortionWeight(weight);
    681 #endif
    682 
    683 #if RDOQ_CHROMA_LAMBDA
    684   // for RDOQ
    685   m_pcTrQuant->setLambda( lambda, lambda / weight );
    686 #else
    687   m_pcTrQuant->setLambda( lambda );
    688 #endif
    689 
    690 #if SAO_CHROMA_LAMBDA
    691   // For SAO
    692   pcSlice   ->setLambda( lambda, lambda / weight );
    693 #else
    694   pcSlice   ->setLambda( lambda );
    695 #endif
    696 }
    697 #endif
    698585// ====================================================================================================================
    699586// Public member functions
     
    735622  }
    736623
    737 #if RATE_CONTROL_LAMBDA_DOMAIN
    738624  if ( m_pcCfg->getUseRateCtrl() )
    739625  {
     
    741627    assert(0);
    742628  }
    743 #endif
    744629
    745630  TComSlice* pcSlice        = rpcPic->getSlice(getSliceIdx());
     
    773658#endif
    774659    m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    775 #if WEIGHTED_CHROMA_DISTORTION
    776660    // for RDO
    777661    // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    778662    Int iQP = m_piRdPicQp    [uiQpIdx];
    779     Double weight = 1.0;
     663    Double weight[2] = { 1.0, 1.0 };
    780664    Int qpc;
    781665    Int chromaQPOffset;
     
    783667    chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    784668    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    785     weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    786     m_pcRdCost->setCbDistortionWeight(weight);
     669    weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     670    m_pcRdCost->setCbDistortionWeight(weight[0]);
    787671
    788672    chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    789673    qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    790     weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    791     m_pcRdCost->setCrDistortionWeight(weight);
    792 #endif
    793 
     674    weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     675    m_pcRdCost->setCrDistortionWeight(weight[1]);
     676
     677    const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdx], (m_pdRdPicLambda[uiQpIdx] / weight[0]), (m_pdRdPicLambda[uiQpIdx] / weight[1])};
    794678#if RDOQ_CHROMA_LAMBDA
    795679    // for RDOQ
    796     m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
     680    m_pcTrQuant->setLambdas( lambdaArray );
    797681#else
    798682    m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    799683#endif
    800 #if SAO_CHROMA_LAMBDA
    801684    // For SAO
    802     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight );
    803 #else
    804     pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdx] );
    805 #endif
     685    pcSlice->setLambdas( lambdaArray );
    806686
    807687    // try compress
     
    830710#endif
    831711  m_pcRdCost    ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    832 #if WEIGHTED_CHROMA_DISTORTION
    833712  // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.
    834713  Int iQP = m_piRdPicQp    [uiQpIdxBest];
    835   Double weight = 1.0;
     714  Double weight[2] = { 1.0, 1.0 };
    836715  Int qpc;
    837716  Int chromaQPOffset;
     
    839718  chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();
    840719  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    841   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    842   m_pcRdCost->setCbDistortionWeight(weight);
     720  weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     721  m_pcRdCost->setCbDistortionWeight(weight[0]);
    843722
    844723  chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();
    845724  qpc = Clip3( 0, 57, iQP + chromaQPOffset);
    846   weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
    847   m_pcRdCost->setCrDistortionWeight(weight);
    848 #endif
    849 
     725  weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 );  // takes into account of the chroma qp mapping and chroma qp Offset
     726  m_pcRdCost->setCrDistortionWeight(weight[1]);
     727
     728  const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdxBest], (m_pdRdPicLambda[uiQpIdxBest] / weight[0]), (m_pdRdPicLambda[uiQpIdxBest] / weight[1])};
    850729#if RDOQ_CHROMA_LAMBDA
    851730  // for RDOQ
    852   m_pcTrQuant   ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
     731  m_pcTrQuant->setLambdas( lambdaArray );
    853732#else
    854733  m_pcTrQuant   ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    855734#endif
    856 #if SAO_CHROMA_LAMBDA
    857735  // For SAO
    858   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );
    859 #else
    860   pcSlice       ->setLambda              ( m_pdRdPicLambda[uiQpIdxBest] );
    861 #endif
     736  pcSlice->setLambdas( lambdaArray );
    862737}
    863738
    864739/** \param rpcPic   picture class
    865740 */
    866 #if RATE_CONTROL_INTRA
    867741Void TEncSlice::calCostSliceI(TComPic*& rpcPic)
    868742{
     
    903777  m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice);
    904778}
    905 #endif
    906779
    907780Void TEncSlice::compressSlice( TComPic*& rpcPic )
     
    1031904  UInt uiTileStartLCU = 0;
    1032905  UInt uiTileLCUX     = 0;
    1033 
    1034906  Bool depSliceSegmentsEnabled = pcSlice->getPPS()->getDependentSliceSegmentsEnabledFlag();
    1035907  uiCUAddr = rpcPic->getPicSym()->getCUOrderMap( uiStartCUAddr /rpcPic->getNumPartInCU());
     
    1080952    pcCU->initCU( rpcPic, uiCUAddr );
    1081953
    1082 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1083     if(m_pcCfg->getUseRateCtrl())
    1084     {
    1085       if(m_pcRateCtrl->calculateUnitQP())
    1086       {
    1087         xLamdaRecalculation(m_pcRateCtrl->getUnitQP(), m_pcRateCtrl->getGOPId(), pcSlice->getDepth(), pcSlice->getSliceType(), pcSlice->getSPS(), pcSlice );
    1088       }
    1089     }
    1090 #endif
    1091954    // inherit from TR if necessary, select substream to use.
    1092955    if( m_pcCfg->getUseSBACRD() )
     
    11631026      ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true);
    11641027
    1165 #if RATE_CONTROL_LAMBDA_DOMAIN
    11661028      Double oldLambda = m_pcRdCost->getLambda();
    11671029      if ( m_pcCfg->getUseRateCtrl() )
     
    11711033        Double bpp       = -1.0;
    11721034
    1173 #if M0036_RC_IMPROVEMENT
    11741035        if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() )
    1175 #else
    1176         if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )
    1177 #endif
    11781036        {
    11791037          estQP = pcSlice->getSliceQp();
     
    11811039        else
    11821040        {
    1183 #if RATE_CONTROL_INTRA
    11841041          bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
    11851042          if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE)
     
    11921049            estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    11931050          }
    1194 #else
    1195           bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();
    1196           estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
    1197           estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    1198 #endif
    11991051
    12001052#if REPN_FORMAT_IN_VPS
     
    12051057
    12061058          m_pcRdCost->setLambda(estLambda);
    1207 #if M0036_RC_IMPROVEMENT
    12081059#if RDOQ_CHROMA_LAMBDA
    12091060          // set lambda for RDOQ
    12101061          Double weight=m_pcRdCost->getChromaWeight();
    1211           m_pcTrQuant->setLambda( estLambda, estLambda / weight );
     1062          const Double lambdaArray[3] = { estLambda, (estLambda / weight), (estLambda / weight) };
     1063          m_pcTrQuant->setLambdas( lambdaArray );
    12121064#else
    12131065          m_pcTrQuant->setLambda( estLambda );
    1214 #endif
    12151066#endif
    12161067        }
     
    12191070        pcCU->getSlice()->setSliceQpBase( estQP );
    12201071      }
    1221 #endif
    12221072
    12231073      // run CU encoder
    12241074      m_pcCuEncoder->compressCU( pcCU );
    1225 
    1226 #if !TICKET_1090_FIX
    1227 #if RATE_CONTROL_LAMBDA_DOMAIN
    1228       if ( m_pcCfg->getUseRateCtrl() )
    1229       {
    1230 #if !M0036_RC_IMPROVEMENT
    1231         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    1232 #if REPN_FORMAT_IN_VPS
    1233         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1234         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->>getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1235 #else
    1236         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1237         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1238 #endif
    1239         Double MAD = (Double)SAD / (Double)(height * width);
    1240         MAD = MAD * MAD;
    1241         ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
    1242 #endif
    1243 
    1244         Int actualQP        = g_RCInvalidQPValue;
    1245         Double actualLambda = m_pcRdCost->getLambda();
    1246         Int actualBits      = pcCU->getTotalBits();
    1247         Int numberOfEffectivePixels    = 0;
    1248         for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )
    1249         {
    1250           if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )
    1251           {
    1252             numberOfEffectivePixels = numberOfEffectivePixels + 16;
    1253             break;
    1254           }
    1255         }
    1256 
    1257         if ( numberOfEffectivePixels == 0 )
    1258         {
    1259           actualQP = g_RCInvalidQPValue;
    1260         }
    1261         else
    1262         {
    1263           actualQP = pcCU->getQP( 0 );
    1264         }
    1265         m_pcRdCost->setLambda(oldLambda);
    1266 #if RATE_CONTROL_INTRA
    1267         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    1268           pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1269 #else
    1270         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1271 #endif
    1272       }
    1273 #endif
    1274 #endif
    12751075
    12761076      // restore entropy coder to an initial stage
     
    13061106      }
    13071107
    1308 #if TICKET_1090_FIX
    1309 #if RATE_CONTROL_LAMBDA_DOMAIN
    13101108      if ( m_pcCfg->getUseRateCtrl() )
    13111109      {
    1312 #if !M0036_RC_IMPROVEMENT
    1313         UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    1314 #if REPN_FORMAT_IN_VPS
    1315         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1316         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1317 #else
    1318         Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    1319         Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
    1320 #endif
    1321         Double MAD = (Double)SAD / (Double)(height * width);
    1322         MAD = MAD * MAD;
    1323         ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;
    1324 #endif
    13251110
    13261111        Int actualQP        = g_RCInvalidQPValue;
     
    13471132        m_pcRdCost->setLambda(oldLambda);
    13481133
    1349 #if RATE_CONTROL_INTRA
    13501134        m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,
    13511135          pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );
    1352 #else
    1353         m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );
    1354 #endif
    1355       }
    1356 #endif
    1357 #endif
     1136      }
    13581137    }
    13591138    // other case: encodeCU is not called
     
    13771156    m_dPicRdCost     += pcCU->getTotalCost();
    13781157    m_uiPicDist      += pcCU->getTotalDistortion();
    1379 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1380     if(m_pcCfg->getUseRateCtrl())
    1381     {
    1382       m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));
    1383       m_pcRateCtrl->updataRCUnitStatus();
    1384     }
    1385 #endif
    13861158  }
    13871159  if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled)
     
    13981170  }
    13991171  xRestoreWPparam( pcSlice );
    1400 #if !RATE_CONTROL_LAMBDA_DOMAIN
    1401   if(m_pcCfg->getUseRateCtrl())
    1402   {
    1403     m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);
    1404   }
    1405 #endif
    14061172}
    14071173
     
    16031369
    16041370    TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     1371#if HM_CLEANUP_SAO
     1372    if ( pcSlice->getSPS()->getUseSAO() )
     1373    {
     1374      if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma())
     1375      {
     1376        SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[uiCUAddr];
     1377        Bool sliceEnabled[NUM_SAO_COMPONENTS];
     1378        sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag();
     1379        sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma();
     1380
     1381        Bool leftMergeAvail = false;
     1382        Bool aboveMergeAvail= false;
     1383        //merge left condition
     1384        Int rx = (uiCUAddr % uiWidthInLCUs);
     1385        if(rx > 0)
     1386        {
     1387          leftMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-1);
     1388        }
     1389
     1390        //merge up condition
     1391        Int ry = (uiCUAddr / uiWidthInLCUs);
     1392        if(ry > 0)
     1393        {
     1394          aboveMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-uiWidthInLCUs);
     1395        }
     1396
     1397        m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail);
     1398      }
     1399    }
     1400#else
    16051401    if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) )
    16061402    {
     
    16851481      }
    16861482    }
     1483#endif
     1484
    16871485#if ENC_DEC_TRACE
    16881486    g_bJustDoIt = g_bEncDecTraceEnable;
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r494 r540  
    131131#endif
    132132
    133 #if RATE_CONTROL_LAMBDA_DOMAIN
    134133  Void    resetQP             ( TComPic* pic, Int sliceQP, Double lambda );
    135 #else
    136   Void    xLamdaRecalculation ( Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice);
    137 #endif
    138134  // compress and encode slice
    139135  Void    precompressSlice    ( TComPic*& rpcPic                                );      ///< precompress slice for multi-loop opt.
    140136  Void    compressSlice       ( TComPic*& rpcPic                                );      ///< analysis stage of slice
    141 #if RATE_CONTROL_INTRA
    142137  Void    calCostSliceI       ( TComPic*& rpcPic );
    143 #endif
    144138  Void    encodeSlice         ( TComPic*& rpcPic, TComOutputBitstream* pcSubstreams  );
    145139 
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r494 r540  
    9292  m_pocAdjustmentValue     = 0;
    9393#endif
     94#if NO_CLRAS_OUTPUT_FLAG
     95  m_noClrasOutputFlag          = false;
     96  m_layerInitializedFlag       = false;
     97  m_firstPicInLayerDecodedFlag = false;
     98  m_noOutputOfPriorPicsFlags   = false;
     99#endif
    94100#endif //SVC_EXTENSION
    95101}
     
    123129  if (m_bUseSAO)
    124130  {
     131#if HM_CLEANUP_SAO
     132#if AUXILIARY_PICTURES
     133    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     134#else
     135    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     136#endif
     137#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
     138    m_cEncSAO.createEncData(getSaoLcuBoundary());
     139#else
     140    m_cEncSAO.createEncData();
     141#endif
     142#else
    125143    m_cEncSAO.setSaoLcuBoundary(getSaoLcuBoundary());
    126144    m_cEncSAO.setSaoLcuBasedOptimization(getSaoLcuBasedOptimization());
     
    128146    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
    129147    m_cEncSAO.createEncBuffer();
     148#endif
    130149  }
    131150#if ADAPTIVE_QP_SELECTION
     
    137156  m_cLoopFilter.        create( g_uiMaxCUDepth );
    138157 
    139 #if RATE_CONTROL_LAMBDA_DOMAIN
    140158  if ( m_RCEnableRateControl )
    141159  {
     
    143161                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
    144162  }
    145 #else
    146   m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
    147 #endif
    148163  // if SBAC-based RD optimization is used
    149164  if( m_bUseSBACRD )
     
    244259  if (m_cSPS.getUseSAO())
    245260  {
     261#if HM_CLEANUP_SAO
     262    m_cEncSAO.destroyEncData();
     263    m_cEncSAO.destroy();
     264#else
    246265    m_cEncSAO.destroy();
    247266    m_cEncSAO.destroyEncBuffer();
     267#endif
    248268  }
    249269  m_cLoopFilter.        destroy();
     
    395415{
    396416  // compress GOP
    397 #if RATE_CONTROL_LAMBDA_DOMAIN
    398417#if !RC_SHVC_HARMONIZATION
    399418  if ( m_RCEnableRateControl )
     
    402421  }
    403422#endif
    404 #endif
    405423
    406424  // compress GOP
    407425  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    408426
    409 #if RATE_CONTROL_LAMBDA_DOMAIN
    410427#if !RC_SHVC_HARMONIZATION
    411428  if ( m_RCEnableRateControl )
     
    413430    m_cRateCtrl.destroyRCGOP();
    414431  }
    415 #endif
    416432#endif
    417433 
     
    457473  }
    458474 
    459 #if RATE_CONTROL_LAMBDA_DOMAIN
    460475  if ( m_RCEnableRateControl )
    461476  {
    462477    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
    463478  }
    464 #endif
    465479
    466480  // compress GOP
     
    468482  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    469483
    470 #if RATE_CONTROL_LAMBDA_DOMAIN
    471484  if ( m_RCEnableRateControl )
    472485  {
    473486    m_cRateCtrl.destroyRCGOP();
    474487  }
    475 #endif
    476488 
    477489  iNumEncoded         = m_iNumPicRcvd;
     
    513525    TComPic *pcTopField;
    514526    xGetNewPicBuffer( pcTopField );
     527#if !HM_CLEANUP_SAO
    515528    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     529#endif
    516530    pcTopField->setReconMark (false);
    517531   
     
    534548    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
    535549    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
    536    
     550
    537551    // compute image characteristics
    538552    if ( getUseAdaptiveQP() )
    539553    {
    540554      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
    541     }
    542    
     555    }   
     556
    543557    /* -- Defield -- */
    544558   
     
    554568    TComPic* pcBottomField;
    555569    xGetNewPicBuffer( pcBottomField );
     570#if !HM_CLEANUP_SAO
    556571    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     572#endif
    557573    pcBottomField->setReconMark (false);
    558574   
     
    575591    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
    576592    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
    577    
    578     // Compute image characteristics
     593
     594    // compute image characteristics
    579595    if ( getUseAdaptiveQP() )
    580596    {
    581597      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
    582     }
    583    
     598    }       
     599
    584600    /* -- Defield -- */
    585601   
     
    636652    TComPic *pcTopField;
    637653    xGetNewPicBuffer( pcTopField );
     654#if !HM_CLEANUP_SAO
    638655    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     656#endif
    639657    pcTopField->setReconMark (false);
    640658   
     
    688706    TComPic* pcBottomField;
    689707    xGetNewPicBuffer( pcBottomField );
     708#if !HM_CLEANUP_SAO
    690709    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     710#endif
    691711    pcBottomField->setReconMark (false);
    692712   
    693     TComPicYuv* rpcPicYuvRec = new TComPicYuv;
     713    TComPicYuv* rpcPicYuvRec;
    694714    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
    695715    {
     
    698718    else
    699719    {
     720      rpcPicYuvRec = new TComPicYuv;
    700721      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
    701722    }
     
    791812        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
    792813        {
     814#if O0098_SCALED_REF_LAYER_ID
     815          const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     816#else
    793817          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
     818#endif
    794819          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
    795820
     
    842867        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
    843868        {
     869#if O0098_SCALED_REF_LAYER_ID
     870          const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
     871#else
    844872          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
     873#endif
    845874          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
    846875
     
    883912#endif
    884913    }
    885 
     914#if !HM_CLEANUP_SAO
    886915    if (getUseSAO())
    887916    {
    888917      rpcPic->getPicSym()->allocSaoParam(&m_cEncSAO);
    889918    }
     919#endif
    890920    m_cListPic.pushBack( rpcPic );
    891921  }
     
    912942  for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
    913943  {
     944#if O0098_SCALED_REF_LAYER_ID
     945    m_cSPS.setScaledRefLayerId(i, m_scaledRefLayerId[i]);
     946#endif
    914947    m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
    915948  }
     
    10631096Void TEncTop::xInitPPS()
    10641097{
    1065 #if IL_SL_SIGNALLING_N0371
    1066   m_cPPS.setLayerId(m_layerId);
     1098#if SCALINGLIST_INFERRING
     1099  m_cPPS.setLayerId( m_layerId );
    10671100#endif
    10681101
     
    10721105#if REPN_FORMAT_IN_VPS
    10731106  Int lowestQP;
     1107#if O0096_REP_FORMAT_INDEX
     1108  if( m_layerId == 0 )
     1109  {
     1110    lowestQP = - m_cSPS.getQpBDOffsetY();
     1111  }
     1112  else
     1113  {
     1114    lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
     1115  }
     1116#else
    10741117  if( m_layerId == 0 || m_cSPS.getUpdateRepFormatFlag() )
    10751118  {
     
    10801123    lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
    10811124  }
     1125#endif
    10821126#else
    10831127  Int lowestQP = - m_cSPS.getQpBDOffsetY();
     
    11191163  }
    11201164
    1121 #if RATE_CONTROL_LAMBDA_DOMAIN
    11221165  if ( m_RCEnableRateControl )
    11231166  {
     
    11261169    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
    11271170  }
    1128 #endif
    11291171
    11301172  m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset );
     
    12091251#if POC_RESET_FLAG
    12101252  m_cPPS.setNumExtraSliceHeaderBits( 2 );
     1253#endif
     1254#if O0149_CROSS_LAYER_BLA_FLAG
     1255  if (m_crossLayerBLAFlag)
     1256  {
     1257    m_cPPS.setNumExtraSliceHeaderBits( 3 );
     1258  }
    12111259#endif
    12121260}
     
    16071655Void TEncTop::xInitILRP()
    16081656{
     1657#if O0096_REP_FORMAT_INDEX
     1658  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_layerId ) );
     1659#else
    16091660  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) );
     1661#endif
    16101662  Int bitDepthY,bitDepthC,picWidth,picHeight;
    16111663
     1664#if O0096_REP_FORMAT_INDEX
     1665  bitDepthY   = repFormat->getBitDepthVpsLuma();
     1666  bitDepthC   = repFormat->getBitDepthVpsChroma();
     1667  picWidth    = repFormat->getPicWidthVpsInLumaSamples();
     1668  picHeight   = repFormat->getPicHeightVpsInLumaSamples();
     1669#else
    16121670  if( m_cSPS.getUpdateRepFormatFlag() )
    16131671  {
     
    16241682    picHeight   = repFormat->getPicHeightVpsInLumaSamples();
    16251683  }
     1684#endif
    16261685 
    16271686  if(m_layerId > 0)
     
    16611720}
    16621721#endif
     1722
     1723#if O0098_SCALED_REF_LAYER_ID
     1724Window& TEncTop::getScaledRefLayerWindowForLayer(Int layerId)
     1725{
     1726  static Window win;
     1727
     1728  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
     1729  {
     1730    if (layerId == m_scaledRefLayerId[i])
     1731    {
     1732      return m_scaledRefLayerWindow[i];
     1733    }
     1734  }
     1735
     1736  win.resetWindow();  // scaled reference layer offsets are inferred to be zero when not present
     1737  return win;
     1738}
     1739#endif
     1740
    16631741#endif //SVC_EXTENSION
    16641742//! \}
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r494 r540  
    8383  // encoder search
    8484  TEncSearch              m_cSearch;                      ///< encoder search class
    85   TEncEntropy*            m_pcEntropyCoder;                     ///< entropy encoder
     85  //TEncEntropy*            m_pcEntropyCoder;                     ///< entropy encoder
    8686  TEncCavlc*              m_pcCavlcCoder;                       ///< CAVLC encoder 
    8787  // coding tool
     
    141141#endif
    142142  UInt                    m_numScaledRefLayerOffsets;
     143#if O0098_SCALED_REF_LAYER_ID
     144  UInt                    m_scaledRefLayerId[MAX_LAYERS];
     145#endif
    143146  Window                  m_scaledRefLayerWindow[MAX_LAYERS];
    144147#if POC_RESET_FLAG
    145148  Int                     m_pocAdjustmentValue;
     149#endif
     150#if NO_CLRAS_OUTPUT_FLAG
     151  Bool                    m_noClrasOutputFlag;
     152  Bool                    m_layerInitializedFlag;
     153  Bool                    m_firstPicInLayerDecodedFlag;
     154  Bool                    m_noOutputOfPriorPicsFlags;
    146155#endif
    147156#endif //SVC_EXTENSION
     
    209218  Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
    210219  UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
     220#if O0098_SCALED_REF_LAYER_ID
     221  Void                    setScaledRefLayerId(Int x, UInt id) { m_scaledRefLayerId[x] = id;   }
     222  UInt                    getScaledRefLayerId(Int x)          { return m_scaledRefLayerId[x]; }
     223  Window&  getScaledRefLayerWindowForLayer(Int layerId);
     224#endif
    211225  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
    212226#endif //SVC_EXTENSION
     
    242256  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
    243257#endif
     258#if NO_CLRAS_OUTPUT_FLAG
     259  Int  getNoClrasOutputFlag()                { return m_noClrasOutputFlag;}
     260  Void setNoClrasOutputFlag(Bool x)          { m_noClrasOutputFlag = x;   }
     261  Int  getLayerInitializedFlag()             { return m_layerInitializedFlag;}
     262  Void setLayerInitializedFlag(Bool x)       { m_layerInitializedFlag = x;   }
     263  Int  getFirstPicInLayerDecodedFlag()       { return m_firstPicInLayerDecodedFlag;}
     264  Void setFirstPicInLayerDecodedFlag(Bool x) { m_firstPicInLayerDecodedFlag = x;   }
     265  Int  getNoOutputOfPriorPicsFlags()         { return m_noOutputOfPriorPicsFlags;}
     266  Void setNoOutputOfPriorPicsFlags(Bool x)   { m_noOutputOfPriorPicsFlags = x;   }
     267#endif
    244268#else //SVC_EXTENSION
    245269  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
Note: See TracChangeset for help on using the changeset viewer.