Changeset 655 in 3DVCSoftware for trunk/source/Lib/TLibEncoder


Ignore:
Timestamp:
23 Oct 2013, 23:01:30 (11 years ago)
Author:
tech
Message:

Merged 8.1-Cleanup@654

Location:
trunk/source/Lib/TLibEncoder
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp

    r608 r655  
    5252TEncAnalyze             m_gcAnalyzeP;
    5353TEncAnalyze             m_gcAnalyzeB;
     54
     55TEncAnalyze             m_gcAnalyzeAll_in;
    5456#endif
    5557
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.h

    r608 r655  
    116116  }
    117117 
     118  Void    printOutInterlaced ( Char cDelim, Double bits )
     119  {
     120    Double dFps     =   m_dFrmRate; //--CFG_KDY
     121    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
     122   
     123    printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
     124    //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
     125    printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
     126           getNumPic(), cDelim,
     127           bits * dScale,
     128           getPsnrY() / (Double)getNumPic(),
     129           getPsnrU() / (Double)getNumPic(),
     130           getPsnrV() / (Double)getNumPic() );
     131  }
     132 
     133  Void    printSummaryOutInterlaced (Int bits)
     134  {
     135    FILE* pFile = fopen ("summaryTotal.txt", "at");
     136    Double dFps     =   m_dFrmRate; //--CFG_KDY
     137    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
     138   
     139    fprintf(pFile, "%f\t %f\t %f\t %f\n", bits * dScale,
     140            getPsnrY() / (Double)getNumPic(),
     141            getPsnrU() / (Double)getNumPic(),
     142            getPsnrV() / (Double)getNumPic() );
     143    fclose(pFile);
     144  }
     145 
     146 
    118147  Void    printSummary(Char ch)
    119148  {
     
    155184extern TEncAnalyze             m_gcAnalyzeP;
    156185extern TEncAnalyze             m_gcAnalyzeB;
     186
     187extern TEncAnalyze             m_gcAnalyzeAll_in;
    157188#endif
    158189
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r622 r655  
    229229    }
    230230  }
    231 #if H_MV5
    232231#if H_MV
    233232  if ( pcPPS->getLayerId() > 0 )
     
    243242  { 
    244243#endif 
    245 #endif
    246244  WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" );
    247245  if( pcPPS->getScalingListPresentFlag() )
     
    252250    codeScalingList( m_pcSlice->getScalingList() );
    253251  }
    254 #if H_MV5
    255252#if H_MV
    256253  }
    257 #endif
    258254#endif
    259255  WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
     
    339335  {
    340336    WRITE_FLAG(pcVUI->getTilesFixedStructureFlag(),             "tiles_fixed_structure_flag");
    341 #if !H_MV5
    342 #if H_MV
    343     if ( pcSPS->getLayerId() > 0 )
    344     {
    345       WRITE_FLAG( pcVUI->getTileBoundariesAlignedFlag( ) ? 1 : 0 , "tile_boundaries_aligned_flag" );
    346     }
    347 #endif
    348 #endif
    349337    WRITE_FLAG(pcVUI->getMotionVectorsOverPicBoundariesFlag(),  "motion_vectors_over_pic_boundaries_flag");
    350338    WRITE_FLAG(pcVUI->getRestrictedRefPicListsFlag(),           "restricted_ref_pic_lists_flag");
     
    451439#endif
    452440  WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
    453 #if H_MV5
    454441#if H_MV
    455442  if ( pcSPS->getLayerId() > 0 )
     
    460447  if ( pcSPS->getUpdateRepFormatFlag() )
    461448  {
    462 #endif
    463449#endif
    464450  WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
     
    472458  WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
    473459  WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
    474 #if H_MV5
    475460#if H_MV
    476461  }
    477 #endif
    478462#endif
    479463  Window conf = pcSPS->getConformanceWindow();
     
    487471    WRITE_UVLC( conf.getWindowBottomOffset() / TComSPS::getWinUnitY(pcSPS->getChromaFormatIdc() ), "conf_win_bottom_offset" );
    488472  }
    489 #if H_MV5
    490473#if H_MV
    491474  if ( pcSPS->getUpdateRepFormatFlag() )
    492475  {
    493476#endif
    494 #endif
    495477  WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
    496478  WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
    497 #if H_MV5
    498479#if H_MV
    499480  }
    500 #endif
    501481#endif
    502482  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
     
    525505  if(pcSPS->getScalingListFlag())
    526506  {
    527 #if H_MV5
    528507#if H_MV
    529508    if ( pcSPS->getLayerId() > 0 )
     
    539518    {   
    540519#endif
    541 #endif
    542520    WRITE_FLAG( pcSPS->getScalingListPresentFlag() ? 1 : 0,                          "sps_scaling_list_data_present_flag" );
    543521    if(pcSPS->getScalingListPresentFlag())
     
    548526      codeScalingList( m_pcSlice->getScalingList() );
    549527    }
    550 #if H_MV5
    551528#if H_MV
    552529    }
    553 #endif
    554530#endif
    555531  }
     
    598574  }
    599575
    600 #if !H_MV5
    601 #if H_MV
    602   WRITE_FLAG( 1, "sps_extension_flag" );
    603   WRITE_FLAG( pcSPS->getInterViewMvVertConstraintFlag() ? 1 : 0, "inter_view_mv_vert_constraint_flag" );
    604   ////   sps_extension_vui_parameters( )
    605   if( pcSPS->getVuiParameters()->getBitstreamRestrictionFlag() )
    606   { 
    607     WRITE_UVLC( pcSPS->getNumIlpRestrictedRefLayers( ),           "num_ilp_restricted_ref_layers" );
    608     for( Int i = 0; i < pcSPS->getNumIlpRestrictedRefLayers( ); i++ )
    609     { 
    610       WRITE_UVLC( pcSPS->getMinSpatialSegmentOffsetPlus1( i ),    "min_spatial_segment_offset_plus1" );
    611       if( pcSPS->getMinSpatialSegmentOffsetPlus1( i ) > 0 )
    612       { 
    613         WRITE_FLAG( pcSPS->getCtuBasedOffsetEnabledFlag( i ),      "ctu_based_offset_enabled_flag[ i ]");
    614         if( pcSPS->getCtuBasedOffsetEnabledFlag( i ) ) 
    615         {
    616           WRITE_UVLC( pcSPS->getMinHorizontalCtuOffsetPlus1( i ), "min_horizontal_ctu_offset_plus1[ i ]");
    617         }
    618       } 
    619     } 
    620   }
    621 #if H_3D_QTLPC
    622   if( depthFlag )
    623   {
    624     WRITE_FLAG( pcSPS->getUseQTL() ? 1 : 0, "use_qtl_flag");
    625     WRITE_FLAG( pcSPS->getUsePC()  ? 1 : 0, "use_pc_flag");
    626   }
    627 #endif
    628   ////   sps_extension_vui_parameters( ) END
    629   WRITE_UVLC( 0, "sps_shvc_reserved_zero_idc" );
    630 #if !H_3D
    631   WRITE_FLAG( 0, "sps_extension2_flag" );
    632 #else
    633   WRITE_FLAG( 1, "sps_extension2_flag"  );
    634   if (!depthFlag )
    635   {
    636     WRITE_UVLC( pcSPS->getCamParPrecision(), "cp_precision" );
    637     WRITE_FLAG( pcSPS->hasCamParInSliceHeader() ? 1 : 0, "cp_in_slice_header_flag" );
    638     if( !pcSPS->hasCamParInSliceHeader() )
    639     {
    640       for( UInt uiIndex = 0; uiIndex < viewIndex; uiIndex++ )
    641       {
    642         WRITE_SVLC( pcSPS->getCodedScale    ()[ uiIndex ],                                      "cp_scale" );
    643         WRITE_SVLC( pcSPS->getCodedOffset   ()[ uiIndex ],                                      "cp_off" );
    644         WRITE_SVLC( pcSPS->getInvCodedScale ()[ uiIndex ] + pcSPS->getCodedScale ()[ uiIndex ], "cp_inv_scale_plus_scale" );
    645         WRITE_SVLC( pcSPS->getInvCodedOffset()[ uiIndex ] + pcSPS->getCodedOffset()[ uiIndex ], "cp_inv_off_plus_off" );
    646       }
    647     }
    648   }
    649 
    650   WRITE_FLAG( 0, "sps_extension3_flag" );
    651 #endif
    652 #else
    653   WRITE_FLAG( 0, "sps_extension_flag" );
    654 #endif
    655 }
    656 #else
    657576#if !H_MV
    658577  WRITE_FLAG( 0, "sps_extension_flag" );
     
    706625}
    707626#endif
    708 #endif
    709627
    710628Void TEncCavlc::codeVPS( TComVPS* pcVPS )
     
    713631  WRITE_CODE( 3,                                    2,        "vps_reserved_three_2bits" );
    714632#if H_MV
    715 #if H_MV5
    716633  WRITE_CODE( pcVPS->getMaxLayersMinus1(),       6,        "vps_max_layers_minus1" );
    717 #else
    718   WRITE_CODE( pcVPS->getMaxLayers() - 1,            6,        "vps_max_layers_minus1" );
    719 #endif
    720634#else
    721635  WRITE_CODE( 0,                                    6,        "vps_reserved_zero_6bits" );
     
    800714    }
    801715  }
    802 #if !H_MV5
    803 #if H_MV
    804   WRITE_FLAG( 1,                                             "vps_extension_flag" );
    805 
    806   m_pcBitIf->writeAlignOne();                       
    807 
    808   WRITE_FLAG( pcVPS->getAvcBaseLayerFlag() ? 1 : 0,          "avc_base_layer_flag" );
    809   WRITE_FLAG( pcVPS->getSplittingFlag() ? 1 : 0,             "splitting_flag" );
    810  
    811   for( Int type = 0; type < MAX_NUM_SCALABILITY_TYPES; type++ )
    812   {
    813     WRITE_FLAG( pcVPS->getScalabilityMask( type ) ? 1 : 0,   "scalability_mask[i]" );
    814   }
    815 
    816   for( Int sIdx = 0; sIdx < pcVPS->getNumScalabilityTypes( ) - ( pcVPS->getSplittingFlag() ? 1 : 0 ); sIdx++ )
    817   {
    818     WRITE_CODE( pcVPS->getDimensionIdLen( sIdx ) - 1 , 3,    "dimension_id_len_minus1[j]");   
    819   }
    820 
    821   if ( pcVPS->getSplittingFlag() )
    822   { // Ignore old dimension id length
    823     pcVPS->setDimensionIdLen( pcVPS->getNumScalabilityTypes( ) - 1 ,pcVPS->inferLastDimsionIdLenMinus1() + 1 );       
    824   }   
    825 
    826 
    827   WRITE_FLAG( pcVPS->getVpsNuhLayerIdPresentFlag() ? 1 : 0,  "vps_nuh_layer_id_present_flag");
    828 
    829   for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
    830   {
    831     if ( pcVPS->getVpsNuhLayerIdPresentFlag() && ( i > 0 ) )
    832     {     
    833       WRITE_CODE( pcVPS->getLayerIdInNuh( i ), 6,          "layer_id_in_nuh[i]");
    834   }
    835     else
    836     {
    837       assert( pcVPS->getLayerIdInNuh( i ) == i );
    838   }
    839 
    840     assert(  pcVPS->getLayerIdInVps( pcVPS->getLayerIdInNuh( i ) ) == i );
    841 
    842     for( Int j = 0; j < pcVPS->getNumScalabilityTypes() ; j++ )
    843   {
    844       if ( !pcVPS->getSplittingFlag() )
    845     {
    846         WRITE_CODE( pcVPS->getDimensionId( i, j ), pcVPS->getDimensionIdLen( j ), "dimension_id[i][j]");     
    847       }
    848       else
    849       {
    850         assert( pcVPS->getDimensionId( i, j ) ==  pcVPS->inferDimensionId( i, j )  );
    851       }
    852     }
    853   }
    854 
    855   for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
    856   {
    857     for( Int j = 0; j < i; j++ )
    858     {
    859       WRITE_FLAG( pcVPS->getDirectDependencyFlag( i, j ),    "direct_dependency_flag[i][j]" );
    860     }
    861   }
    862 
    863   for( Int i = 0; i < pcVPS->getMaxLayers() - 1; i++ )
    864   {
    865     WRITE_CODE( pcVPS->getMaxTidIlRefPicPlus1( i ), 3,       "max_tid_il_ref_pics_plus1[i]" );
    866   }
    867 
    868   WRITE_CODE( pcVPS->getVpsNumberLayerSetsMinus1( )    , 10,    "vps_number_layer_sets_minus1"      );
    869   WRITE_CODE( pcVPS->getVpsNumProfileTierLevelMinus1( ), 6,     "vps_num_profile_tier_level_minus1" );
    870 
    871   for( Int i = 1; i <= pcVPS->getVpsNumProfileTierLevelMinus1(); i++ )
    872   {
    873     WRITE_FLAG( pcVPS->getVpsProfilePresentFlag( i ) ? 1 : 0, "vps_profile_present_flag[i]" );
    874     if( !pcVPS->getVpsProfilePresentFlag( i ) )
    875     {   
    876       WRITE_CODE( pcVPS->getProfileRefMinus1( i ), 6, "profile_ref_minus1[i]" );
    877     }
    878     codePTL( pcVPS->getPTL( i ), pcVPS->getVpsProfilePresentFlag( i ), pcVPS->getMaxTLayers() - 1 );
    879   }
    880 
    881   Int numOutputLayerSets = pcVPS->getVpsNumberLayerSetsMinus1( ) + 1;
    882 
    883   WRITE_FLAG( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) ? 1 : 0, "more_output_layer_sets_than_default_flag" );
    884 
    885   if ( pcVPS->getMoreOutputLayerSetsThanDefaultFlag( ) )
    886   {
    887     WRITE_CODE( pcVPS->getNumAddOutputLayerSetsMinus1( )    , 10,    "num_add_output_layer_sets_minus1"      );
    888     numOutputLayerSets += ( pcVPS->getNumAddOutputLayerSetsMinus1( ) + 1 );
    889   }
    890 
    891   if( numOutputLayerSets > 1)
    892   {
    893     WRITE_FLAG( pcVPS->getDefaultOneTargetOutputLayerFlag( ) ? 1 : 0, "default_one_target_output_layer_flag" );
    894   } 
    895 
    896   for( Int i = 1; i < numOutputLayerSets; i++ )
    897   {
    898     if( i > pcVPS->getVpsNumberLayerSetsMinus1( ) )
    899     {     
    900       WRITE_UVLC( pcVPS->getOutputLayerSetIdxMinus1( i ),      "output_layer_set_idx_minus1[i]" );
    901       for( Int j = 0; j < pcVPS->getNumLayersInIdList( j ) - 1 ; j++ )
    902       {
    903         WRITE_FLAG( pcVPS->getOutputLayerFlag( i, j) ? 1 : 0, "output_layer_flag" );
    904       }     
    905     }
    906     if ( pcVPS->getProfileLevelTierIdxLen()  > 0 )
    907     {     
    908       WRITE_CODE( pcVPS->getProfileLevelTierIdx( i ), pcVPS->getProfileLevelTierIdxLen() ,"profile_level_tier_idx[ i ]" );   
    909     }
    910   }
    911 
    912   WRITE_FLAG( pcVPS->getMaxOneActiveRefLayerFlag( ) ? 1 : 0, "max_one_active_ref_layer_flag" );
    913   WRITE_UVLC( pcVPS->getDirectDepTypeLenMinus2 ( ),         "direct_dep_type_len_minus2");
    914 
    915     for( Int i = 1; i <= pcVPS->getMaxLayers() - 1; i++ )
    916     {
    917       for( Int j = 0; j < i; j++ )
    918       {
    919         if (pcVPS->getDirectDependencyFlag( i, j) )
    920         {       
    921           assert ( pcVPS->getDirectDependencyType( i, j ) != -1 );
    922           WRITE_CODE( pcVPS->getDirectDependencyType( i, j ),pcVPS->getDirectDepTypeLenMinus2( ) + 2,  "direct_dependency_type[i][j]" );
    923         }
    924       }
    925     }
    926 
    927     WRITE_FLAG ( 0,                    "vps_shvc_reserved_zero_flag" );
    928 
    929 #if H_3D
    930   WRITE_FLAG( 1,                                             "vps_extension2_flag" );
    931   m_pcBitIf->writeAlignOne();     
    932   for( Int i = 0; i <= pcVPS->getMaxLayers() - 1; i++ )
    933   {
    934     if (i!= 0)
    935     {
    936       if ( !( pcVPS->getDepthId( i ) == 1 ) )
    937       {
    938 #if H_3D_IV_MERGE
    939         WRITE_FLAG( pcVPS->getIvMvPredFlag         ( i ) ? 1 : 0 , "iv_mv_pred_flag[i]");
    940 #endif
    941 #if H_3D_ARP
    942         WRITE_FLAG( pcVPS->getUseAdvRP             ( i ) ? 1 : 0,  "iv_res_pred_flag[i]"  );
    943 #endif
    944 #if H_3D_NBDV_REF
    945         WRITE_FLAG( pcVPS->getDepthRefinementFlag  ( i ) ? 1 : 0 , "depth_refinement_flag[i]");
    946 #endif
    947 #if H_3D_VSP
    948         WRITE_FLAG( pcVPS->getViewSynthesisPredFlag( i ) ? 1 : 0 , "view_synthesis_pred_flag[i]");
    949 #endif
    950       }         
    951       else
    952       {
    953         WRITE_FLAG( pcVPS->getVpsDepthModesFlag( i ) ? 1 : 0 ,          "vps_depth_modes_flag[i]" );
    954         //WRITE_FLAG( pcVPS->getLimQtPredFlag    ( i ) ? 1 : 0 ,          "lim_qt_pred_flag[i]"     );
    955 #if H_3D_DIM_DLT
    956         if( pcVPS->getVpsDepthModesFlag( i ) )
    957         {
    958           WRITE_FLAG( pcVPS->getUseDLTFlag( i ) ? 1 : 0, "dlt_flag[i]" );
    959         }
    960         if( pcVPS->getUseDLTFlag( i ) )
    961         {
    962           // code mapping
    963           WRITE_UVLC(pcVPS->getNumDepthValues(i), "num_depth_values_in_dlt[i]");
    964           for(Int d=0; d<pcVPS->getNumDepthValues(i); d++)
    965           {
    966             WRITE_UVLC( pcVPS->idx2DepthValue(i, d), "dlt_depth_value[i][d]" );
    967           }
    968         }       
    969 #endif
    970 #if LGE_INTER_SDC_E0156
    971         WRITE_FLAG( pcVPS->getInterSDCFlag( i ) ? 1 : 0, "depth_inter_SDC_flag" );
    972 #endif
    973       }
    974     } 
    975   }
    976   WRITE_FLAG( pcVPS->getIvMvScalingFlag( ) ? 1 : 0 ,          "iv_mv_scaling_flag" );
    977 #else
    978   WRITE_FLAG( 0,                                             "vps_extension2_flag" );
    979 #endif
    980 #else
    981   WRITE_FLAG( 0,                     "vps_extension_flag" );
    982 #endif
    983  
    984   //future extensions here..
    985  
    986   return;
    987 }
    988 #else
    989716#if H_MV
    990717  WRITE_FLAG( 1,                     "vps_extension_flag" );
     
    1003730#endif
    1004731  //future extensions here..
    1005 }
    1006 
    1007 #endif
    1008 
    1009 
    1010 #if H_MV5
     732
     733  return;
     734}
     735
     736
     737
    1011738#if H_MV
    1012739Void TEncCavlc::codeVPSExtension( TComVPS *pcVPS )
     
    13091036        }       
    13101037#endif
    1311 #if LGE_INTER_SDC_E0156
     1038#if H_3D_INTER_SDC
    13121039        WRITE_FLAG( pcVPS->getInterSDCFlag( i ) ? 1 : 0, "depth_inter_SDC_flag" );
    13131040#endif
     
    13191046#endif
    13201047}
    1321 #endif
    13221048#endif
    13231049
     
    13701096  {
    13711097#if H_MV   
    1372 #if H_MV5
    13731098    Int esb = 0;  //Don't use i, otherwise will shadow something below
    13741099    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > esb )
     
    13851110
    13861111    for (; esb < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); esb++)   
    1387 #else
    1388     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
    1389     {
    1390       WRITE_FLAG( pcSlice->getDiscardableFlag( ) ? 1 : 0 , "discardable_flag" );
    1391     }
    1392 
    1393     for (Int i = 1; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)   
    1394 #endif
    13951112#else
    13961113    for (Int i = 0; i < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); i++)
     
    14151132    if( !pcSlice->getIdrPicFlag() )
    14161133    {
    1417       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
     1134      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    14181135      WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
    14191136      TComReferencePictureSet* rps = pcSlice->getRPS();
     
    15301247    }
    15311248#if H_MV
    1532 #if H_MV5
    15331249    Int layerId = pcSlice->getLayerId();
    15341250    if( pcSlice->getLayerId() > 0 && !vps->getAllRefLayersActiveFlag() && vps->getNumDirectRefLayers( layerId ) > 0 )
     
    15501266      } 
    15511267    }
    1552 #else
    1553     Int layerIdInVps       = pcSlice->getLayerIdInVps();
    1554     if( pcSlice->getLayerId() > 0 && vps->getNumDirectRefLayers( layerIdInVps ) > 0 )
    1555     {   
    1556       WRITE_FLAG( pcSlice->getInterLayerPredEnabledFlag( ) ? 1 : 0 , "inter_layer_pred_enabled_flag" );
    1557       if( pcSlice->getInterLayerPredEnabledFlag() && vps->getNumDirectRefLayers( layerIdInVps ) > 1 )
    1558       {           
    1559         if( !vps->getMaxOneActiveRefLayerFlag()) 
    1560         {
    1561           WRITE_CODE( pcSlice->getNumInterLayerRefPicsMinus1( ), pcSlice->getNumInterLayerRefPicsMinus1Len( ), "num_inter_layer_ref_pics_minus1" );
    1562         }
    1563         for( Int i = 0; i < pcSlice->getNumActiveRefLayerPics(); i++ )   
    1564         {
    1565           WRITE_CODE( pcSlice->getInterLayerPredLayerIdc( i ), pcSlice->getInterLayerPredLayerIdcLen( ), "inter_layer_pred_layer_idc" );
    1566         }
    1567       } 
    1568     }
    1569 
    1570     if( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0  &&  pcSlice->getNumActiveRefLayerPics() > 0 )
    1571     {
    1572       WRITE_FLAG( pcSlice->getInterLayerSamplePredOnlyFlag( ) ? 1 : 0 , "inter_layer_sample_pred_only_flag" );
    1573     }
    1574 
    1575 #endif
    15761268#endif
    15771269    if(pcSlice->getSPS()->getUseSAO())
     
    16781370    if ( pcSlice->getEnableTMVPFlag() )
    16791371    {
    1680 #if !H_MV5
    1681 #if H_MV
    1682       if( pcSlice->getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
    1683       {
    1684         WRITE_FLAG( pcSlice->getAltCollocatedIndicationFlag( ) ? 1 : 0 , "alt_collocated_indication_flag" );
    1685       }
    1686       if( pcSlice->getAltCollocatedIndicationFlag() && pcSlice->getNumActiveMotionPredRefLayers() > 1 )
    1687       {         
    1688         WRITE_UVLC( pcSlice->getCollocatedRefLayerIdx( ), "collocated_ref_layer_idx" );
    1689       }     
    1690       else
    1691       {
    1692 #endif
    1693 #endif
    16941372      if ( pcSlice->getSliceType() == B_SLICE )
    16951373      {
     
    17041382      }
    17051383    }
    1706 #if !H_MV5
    1707 #if H_MV
    1708     }
    1709 #endif
    1710 #endif
    17111384    if ( (pcSlice->getPPS()->getUseWP() && pcSlice->getSliceType()==P_SLICE) || (pcSlice->getPPS()->getWPBiPred() && pcSlice->getSliceType()==B_SLICE) )
    17121385    {
     
    22561929{
    22571930  // Bool state = true, state2 = false;
    2258   Int lsb = ltrpPOC % (1<<pcSlice->getSPS()->getBitsForPOC());
     1931  Int lsb = ltrpPOC & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    22591932  for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++)
    22601933  {
     
    22821955}
    22831956
    2284 #if LGE_INTER_SDC_E0156
     1957#if H_3D_INTER_SDC
    22851958Void TEncCavlc::codeInterSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx )
    22861959{
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r622 r655  
    8484  UInt  getCoeffCost          ()                { return  m_uiCoeffCost;  }
    8585  Void  codeVPS                 ( TComVPS* pcVPS );
    86 #if H_MV5
    8786#if H_MV
    8887  Void  codeVPSExtension       ( TComVPS *pcVPS );
     
    9089  Void  codeVPSVUI             ( TComVPS* pcVPS );
    9190#endif
    92 #endif
    9391  Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
    94 #if H_MV5
    9592#if H_MV
    9693  Void  codeSPSExtension        ( TComSPS* pcSPS );
    9794#endif
    98 #endif
    9995#if H_3D
    100 #if H_MV5
    10196  Void  codeVPSExtension2       ( TComVPS* pcVPS );
    10297  Void  codeSPSExtension2       ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag  );
    103 #endif
    10498  Void  codeSPS                 ( TComSPS* pcSPS, Int viewIndex, Bool depthFlag );
    10599#else
     
    133127  Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    134128#endif
    135 #if LGE_INTER_SDC_E0156
     129#if H_3D_INTER_SDC
    136130  Void codeInterSDCFlag          ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    137131  Void codeInterSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r622 r655  
    7777  Int m_interLayerPredLayerIdc [MAX_NUM_REF_PICS];
    7878  Int m_interViewRefPosL[2][MAX_NUM_REF_PICS]; 
    79 #if !H_MV5
    80   Int m_collocatedRefLayerIdx;
    81 #endif
    8279#endif
    8380  GOPEntry()
     
    9794#if H_MV
    9895  , m_numActiveRefLayerPics(0)
    99 #if !H_MV5
    100   , m_collocatedRefLayerIdx(-1)
    101 #endif
    10296#endif
    10397  {
     
    310304  Int       m_RCInitialQP;
    311305  Bool      m_RCForceIntraQP;
     306
     307#if KWU_RC_MADPRED_E0227
     308  UInt       m_depthMADPred;
     309#endif
     310#if KWU_RC_VIEWRC_E0227
     311  Bool      m_bViewWiseRateCtrl;
     312#endif
    312313#else
    313314  Bool      m_enableRateCtrl;                                ///< Flag for using rate control algorithm
    314315  Int       m_targetBitrate;                                 ///< target bitrate
    315316  Int       m_numLCUInUnit;                                  ///< Total number of LCUs in a frame should be divided by the NumLCUInUnit
     317
     318#if KWU_RC_MADPRED_E0227
     319  UInt       m_depthMADPred;
     320#endif
     321#if KWU_RC_VIEWRC_E0227
     322  Bool      m_bViewWiseRateCtrl;
     323#endif
    316324#endif
    317325  Bool      m_TransquantBypassEnableFlag;                     ///< transquant_bypass_enable_flag setting in PPS.
     
    361369  Int       m_layerIdInVps;
    362370  Int       m_viewId;
    363 #if H_MV5
    364371  Int       m_viewIndex;
    365 #endif
    366372#endif
    367373
    368374#if H_3D
    369 #if !H_MV5
    370   Int       m_viewIndex;
    371 #endif
    372375  Bool      m_isDepth;
    373376
     
    403406  Bool      m_bUseIC;
    404407#endif
    405 #if LGE_INTER_SDC_E0156
     408#if H_3D_INTER_SDC
    406409  bool      m_bInterSDC;
    407410#endif
     
    426429  , m_layerIdInVps(-1)
    427430  , m_viewId(-1)
    428 #if H_MV5
    429431  , m_viewIndex(-1)
    430 #endif
    431432#if H_3D
    432 #if !H_MV5
    433   , m_viewIndex(-1)
    434 #endif
    435433  , m_isDepth(false)
    436434  , m_bUseVSO(false)
     
    465463  Void      setViewId                        ( Int viewId  )      { m_viewId  = viewId;  }
    466464  Int       getViewId                        ()                   { return m_viewId;    }
    467 #if H_MV5
    468465  Void      setViewIndex                     ( Int viewIndex  )   { m_viewIndex  = viewIndex;  }
    469466  Int       getViewIndex                     ()                   { return m_viewIndex;    }
    470 #endif
    471467#if H_3D
    472 #if !H_MV5
    473   Void      setViewIndex                     ( Int viewIndex  )   { m_viewIndex  = viewIndex;  }
    474   Int       getViewIndex                     ()                   { return m_viewIndex;    }
    475 #endif
    476468  Void      setIsDepth                       ( Bool isDepth )   { m_isDepth = isDepth; }
    477469  Bool      getIsDepth                       ()                 { return m_isDepth; }
     
    514506  Bool       getUseIC                       ()               { return m_bUseIC; }
    515507#endif
    516 #if LGE_INTER_SDC_E0156
     508#if H_3D_INTER_SDC
    517509  Void       setInterSDCEnable              ( Bool bVal )    { m_bInterSDC = bVal; }
    518510  Bool       getInterSDCEnable              ()               { return m_bInterSDC; }
     
    826818  Bool      getForceIntraQP        ()              { return m_RCForceIntraQP;        }
    827819  Void      setForceIntraQP        ( Bool b )      { m_RCForceIntraQP = b;           }
     820
     821#if KWU_RC_MADPRED_E0227
     822  UInt      getUseDepthMADPred    ()                { return m_depthMADPred;        }
     823  Void      setUseDepthMADPred    (UInt b)          { m_depthMADPred    = b;        }
     824#endif
     825#if KWU_RC_VIEWRC_E0227
     826  Bool      getUseViewWiseRateCtrl    ()                { return m_bViewWiseRateCtrl;        }
     827  Void      setUseViewWiseRateCtrl    (Bool b)          { m_bViewWiseRateCtrl    = b;        }
     828#endif
    828829#else
    829830  Bool      getUseRateCtrl    ()                { return m_enableRateCtrl;    }
     
    833834  Int       getNumLCUInUnit   ()                { return m_numLCUInUnit;      }
    834835  Void      setNumLCUInUnit   (Int numLCUs)     { m_numLCUInUnit   = numLCUs; }
     836
     837#if KWU_RC_MADPRED_E0227
     838  UInt      getUseDepthMADPred    ()                { return m_depthMADPred;        }
     839  Void      setUseDepthMADPred    (UInt b)          { m_depthMADPred    = b;        }
     840#endif
     841#if KWU_RC_VIEWRC_E0227
     842  Bool      getUseViewWiseRateCtrl    ()                { return m_bViewWiseRateCtrl;        }
     843  Void      setUseViewWiseRateCtrl    (Bool b)          { m_bViewWiseRateCtrl    = b;        }
     844#endif
    835845#endif
    836846  Bool      getTransquantBypassEnableFlag()           { return m_TransquantBypassEnableFlag; }
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r622 r655  
    103103 
    104104  m_bEncodeDQP = false;
    105 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     105#if RATE_CONTROL_LAMBDA_DOMAIN
     106#if !M0036_RC_IMPROVEMENT
    106107  m_LCUPredictionSAD = 0;
    107108  m_addSADDepth      = 0;
    108109  m_temporalSAD      = 0;
     110#endif
     111#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     112  m_LCUPredictionSAD = 0;
     113  m_addSADDepth      = 0;
     114  m_temporalSAD      = 0;
     115  m_spatialSAD       = 0;
     116#endif
     117#endif
     118#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
     119  m_LCUPredictionSAD = 0;
     120  m_addSADDepth      = 0;
     121  m_temporalSAD      = 0;
     122  m_spatialSAD       = 0;
    109123#endif
    110124
     
    256270  m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() );
    257271
    258 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     272#if RATE_CONTROL_LAMBDA_DOMAIN
     273#if !M0036_RC_IMPROVEMENT
    259274  m_addSADDepth      = 0;
    260275  m_LCUPredictionSAD = 0;
    261276  m_temporalSAD      = 0;
     277#endif
     278#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     279  m_LCUPredictionSAD = 0;
     280  m_addSADDepth      = 0;
     281  m_temporalSAD      = 0;
     282  m_spatialSAD       = 0;
     283#endif
     284#endif
     285#if KWU_RC_MADPRED_E0227
     286  m_LCUPredictionSAD = 0;
     287  m_addSADDepth      = 0;
     288  m_temporalSAD      = 0;
     289  m_spatialSAD       = 0;
    262290#endif
    263291
     
    404432
    405433  // variables for fast encoder decision
    406   Bool    bEarlySkip  = false;
    407   Bool    bTrySplit    = true;
    408   Double  fRD_Skip    = MAX_DOUBLE;
     434#if H_3D_QTLPC 
     435  Bool    bTrySplit     = true;
     436  Bool    bTrySplitDQP  = true;
     437#endif
    409438
    410439  // variable for Early CU determination
     
    415444  Bool earlyDetectionSkipMode = false;
    416445
    417   Bool    bTrySplitDQP  = true;
    418446#if H_3D_VSP
    419447  DisInfo DvInfo;
     
    425453#endif
    426454#endif
    427   static  Double  afCost[ MAX_CU_DEPTH ];
    428   static  Int      aiNum [ MAX_CU_DEPTH ];
    429 
    430   if ( rpcBestCU->getAddr() == 0 )
    431   {
    432     ::memset( afCost, 0, sizeof( afCost ) );
    433     ::memset( aiNum,  0, sizeof( aiNum  ) );
    434   }
    435 
    436455  Bool bBoundary = false;
    437456  UInt uiLPelX   = rpcBestCU->getCUPelX();
     
    489508  if(!bSliceEnd && !bSliceStart && bInsidePicture )
    490509  {
    491 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     510#if  H_3D_FAST_TEXTURE_ENCODING
    492511    Bool bIVFMerge = false;
    493512    Int  iIVFMaxD = 0;
     
    501520      }
    502521      // variables for fast encoder decision
    503       bEarlySkip  = false;
     522#if H_3D_QTLPC
    504523      bTrySplit    = true;
    505       fRD_Skip    = MAX_DOUBLE;
     524#endif
    506525
    507526      rpcTempCU->initEstData( uiDepth, iQP );
     
    560579        }
    561580      }
    562 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     581#if  H_3D_FAST_TEXTURE_ENCODING
    563582      if(rpcTempCU->getSlice()->getViewIndex() && !rpcTempCU->getSlice()->getIsDepth())
    564583      {
     
    584603          rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    585604#endif
    586 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     605#if  H_3D_FAST_TEXTURE_ENCODING
    587606          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP );//by Competition for inter_2Nx2N
    588607#else
     
    598617#endif
    599618        xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
    600 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     619#if  H_3D_FAST_TEXTURE_ENCODING
    601620        bFMD = bIVFMerge && rpcBestCU->isSkipped(0);
    602621#endif
     
    605624        rpcTempCU->setDvInfoSubParts(DvInfo, 0, uiDepth);
    606625#endif
    607         // fast encoder decision for early skip
    608         if ( m_pcEncCfg->getUseFastEnc() )
    609         {
    610           Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
    611           if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] )
    612           {
    613             bEarlySkip = true;
    614             bTrySplit  = false;
    615           }
    616         }
    617626
    618627        if(!m_pcEncCfg->getUseEarlySkipDetection())
    619628        {
    620629          // 2Nx2N, NxN
    621           if ( !bEarlySkip )
    622           {
    623630#if H_3D_IC
    624631            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    625632#endif
    626 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     633#if  H_3D_FAST_TEXTURE_ENCODING
    627634            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N, bFMD );  rpcTempCU->initEstData( uiDepth, iQP );
    628635#else
     
    636643              doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    637644            }
    638           }
    639645        }
    640646#if H_3D_IC
     
    643649      }
    644650
    645 #if H_3D_QTLPC
     651#if H_3D_QTLPC     
    646652      if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTL())
    647653      {
    648654        bTrySplitDQP = bTrySplit;
    649655      }
    650       else
    651       {
    652 #endif
    653         if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
    654         {
    655           if(iQP == iBaseQP)
    656           {
    657             bTrySplitDQP = bTrySplit;
    658           }
    659         }
    660         else
    661         {
    662           bTrySplitDQP = bTrySplit;
    663         }
    664 #if H_3D_QTLPC
    665       }
    666656#endif
    667657      if (isAddLowestQP && (iQP == lowestQP))
     
    678668    }
    679669#endif
     670#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     671    if ( uiDepth <= m_addSADDepth )
     672    {
     673      m_LCUPredictionSAD += m_temporalSAD;
     674      m_addSADDepth = uiDepth;
     675    }
     676#endif
     677#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
     678if ( uiDepth <= m_addSADDepth )
     679{
     680  m_LCUPredictionSAD += m_temporalSAD;
     681  m_addSADDepth = uiDepth;
     682}
     683#endif
     684#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
     685    if(m_pcEncCfg->getUseRateCtrl())
     686    {
     687      Int qp = m_pcRateCtrl->getUnitQP();
     688      iMinQP  = Clip3( MIN_QP, MAX_QP, qp);
     689      iMaxQP  = Clip3( MIN_QP, MAX_QP, qp);
     690    }
     691#endif
    680692
    681693#if H_3D_DIM_ENC
     
    700712        {
    701713          // 2Nx2N, NxN
    702           if ( !bEarlySkip )
    703           {
    704714            if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
    705715            {
     
    710720                )
    711721              {
    712 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     722#if  H_3D_FAST_TEXTURE_ENCODING
    713723                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN, bFMD  );
    714724#else
     
    721731              }
    722732            }
    723           }
    724733
    725734          // 2NxN, Nx2N
     
    730739            )
    731740          {
    732 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     741#if  H_3D_FAST_TEXTURE_ENCODING
    733742            xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_Nx2N, bFMD  );
    734743#else
     
    750759            )
    751760          {
    752 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     761#if  H_3D_FAST_TEXTURE_ENCODING
    753762            xCheckRDCostInter      ( rpcBestCU, rpcTempCU, SIZE_2NxN, bFMD  );
    754763#else
     
    789798                )
    790799              {
    791 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     800#if  H_3D_FAST_TEXTURE_ENCODING
    792801                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD );
    793802#else
     
    809818                )
    810819              {
    811 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     820#if  H_3D_FAST_TEXTURE_ENCODING
    812821                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD );
    813822#else
     
    833842                )
    834843              {
    835 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     844#if  H_3D_FAST_TEXTURE_ENCODING
    836845                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, bFMD, true );
    837846#else
     
    853862                )
    854863              {
    855 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     864#if  H_3D_FAST_TEXTURE_ENCODING
    856865                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, bFMD, true );
    857866#else
     
    879888                )
    880889              {
    881 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     890#if  H_3D_FAST_TEXTURE_ENCODING
    882891                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD );
    883892#else
     
    899908                )
    900909              {
    901 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     910#if  H_3D_FAST_TEXTURE_ENCODING
    902911                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD );
    903912#else
     
    919928                )
    920929              {
    921 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     930#if  H_3D_FAST_TEXTURE_ENCODING
    922931                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, bFMD, true );
    923932#else
     
    939948                )
    940949              {
    941 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     950#if  H_3D_FAST_TEXTURE_ENCODING
    942951                xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, bFMD, true );
    943952#else
     
    990999#endif
    9911000        }
    992 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     1001#if  H_3D_FAST_TEXTURE_ENCODING
    9931002        if(!bFMD)
    9941003        {
    9951004#endif
    9961005        // do normal intra modes
    997 #if H_3D_DIM_ENC
    998         if ( !bEarlySkip || ( rpcBestCU->getSlice()->getIsDepth() && rpcBestCU->getSlice()->isIRAP() ) )
    999 #else
    1000         if ( !bEarlySkip )
    1001 #endif
    1002         {
     1006       
    10031007          // speedup for inter frames
    10041008          if( rpcBestCU->getSlice()->getSliceType() == I_SLICE ||
     
    10121016          {
    10131017            xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N );
     1018
     1019#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     1020            if ( uiDepth <= m_addSADDepth )
     1021            {
     1022              m_LCUPredictionSAD += m_spatialSAD;
     1023              m_addSADDepth = uiDepth;
     1024            }
     1025#endif
     1026#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     1027            if ( uiDepth <= m_addSADDepth )
     1028            {
     1029              m_LCUPredictionSAD += m_spatialSAD;
     1030              m_addSADDepth = uiDepth;
     1031            }
     1032#endif
     1033
     1034#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
     1035            if ( uiDepth <= m_addSADDepth )
     1036            {
     1037              m_LCUPredictionSAD += m_spatialSAD;
     1038              m_addSADDepth = uiDepth;
     1039            }
     1040#endif
    10141041            rpcTempCU->initEstData( uiDepth, iQP );
    10151042            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth )
     
    10291056            }
    10301057          }
    1031         }
    1032 
    10331058        // test PCM
    10341059        if(pcPic->getSlice(0)->getSPS()->getUsePCM()
     
    10491074          }
    10501075        }
    1051 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     1076#if  H_3D_FAST_TEXTURE_ENCODING
    10521077        }
    10531078#endif
     
    10741099    rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
    10751100
    1076     // accumulate statistics for early skip
    1077     if ( m_pcEncCfg->getUseFastEnc() )
    1078     {
    1079       if ( rpcBestCU->isSkipped(0) )
    1080       {
    1081         Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
    1082         afCost[ iIdx ] += rpcBestCU->getTotalCost();
    1083         aiNum [ iIdx ] ++;
    1084       }
    1085     }
    1086 
    10871101    // Early CU determination
    10881102    if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
     
    10941108      bSubBranch = true;
    10951109    }
    1096 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     1110#if  H_3D_FAST_TEXTURE_ENCODING
    10971111    if(rpcBestCU->getSlice()->getViewIndex() && !rpcBestCU->getSlice()->getIsDepth() && (uiDepth >=iIVFMaxD) && rpcBestCU->isSkipped(0))
    10981112    {
     
    11681182
    11691183    // further split
     1184#if H_3D_QTLPC
    11701185    if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
     1186#else
     1187    if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
     1188#endif
    11711189    {
    11721190#if H_3D_VSO // M9
     
    15801598  m_pcEntropyCoder->encodeARPW( pcCU , uiAbsPartIdx );
    15811599#endif
    1582 #if LGE_INTER_SDC_E0156
     1600#if H_3D_INTER_SDC
    15831601  m_pcEntropyCoder->encodeInterSDCFlag( pcCU, uiAbsPartIdx, false );
    15841602#endif
     
    18751893
    18761894          rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth );
    1877 #if LGE_INTER_SDC_E0156
     1895#if H_3D_INTER_SDC
    18781896          TComDataCU *rpcTempCUPre = rpcTempCU;
    18791897#endif
     
    18811899          xCheckDQP( rpcTempCU );
    18821900          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    1883 #if LGE_INTER_SDC_E0156
     1901#if H_3D_INTER_SDC
    18841902          if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() && !uiNoResidual )
    18851903          {
     
    19171935      if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
    19181936      {
    1919 #if LGE_INTER_SDC_E0156
     1937#if H_3D_INTER_SDC
    19201938        if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) )
    19211939        {
     
    19261944#endif
    19271945        bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
    1928 #if LGE_INTER_SDC_E0156
     1946#if H_3D_INTER_SDC
    19291947        }
    19301948#endif
     
    19711989
    19721990#if AMP_MRG
    1973 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     1991#if  H_3D_FAST_TEXTURE_ENCODING
    19741992Void TEncCu::xCheckRDCostInter( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize, Bool bFMD, Bool bUseMRG)
    19751993#else
     
    19801998#endif
    19811999{
    1982 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     2000#if  H_3D_FAST_TEXTURE_ENCODING
    19832001  if(!(bFMD && (ePartSize == SIZE_2Nx2N)))  //have  motion estimation or merge check
    19842002  {
     
    20572075#if AMP_MRG
    20582076  rpcTempCU->setMergeAMP (true);
    2059 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     2077#if  H_3D_FAST_TEXTURE_ENCODING
    20602078  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bFMD, false, bUseMRG );
    20612079#else
     
    21022120#endif
    21032121
    2104 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     2122#if RATE_CONTROL_LAMBDA_DOMAIN  && (!M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227)
    21052123  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
    21062124  {
     
    21112129  }
    21122130#endif
     2131#if !RATE_CONTROL_LAMBDA_DOMAIN  && KWU_RC_MADPRED_E0227
     2132  if ( m_pcEncCfg->getUseRateCtrl() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
     2133  {
     2134    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
     2135      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
     2136      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
     2137    m_temporalSAD = (Int)SAD;
     2138  }
     2139#endif
    21132140
    21142141  m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
     
    21212148#endif
    21222149  rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    2123 #if LGE_INTER_SDC_E0156
     2150#if H_3D_INTER_SDC
    21242151  TComDataCU *rpcTempCUPre = rpcTempCU;
    21252152#endif
    21262153  xCheckDQP( rpcTempCU );
    21272154  xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    2128 #if LGE_INTER_SDC_E0156
     2155#if H_3D_INTER_SDC
    21292156  if( rpcTempCU->getSlice()->getVPS()->getInterSDCFlag( rpcTempCU->getSlice()->getLayerIdInVps() ) && rpcTempCU->getSlice()->getIsDepth() )
    21302157  {
     
    21632190  }
    21642191#endif
    2165 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     2192#if  H_3D_FAST_TEXTURE_ENCODING
    21662193  }
    21672194#endif
     
    22352262  rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
    22362263 
     2264#if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     2265  UChar uhDepth = rpcTempCU->getDepth( 0 );
     2266  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
     2267  {
     2268    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
     2269      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
     2270      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
     2271    m_spatialSAD = (Int)SAD;
     2272  }
     2273#endif
     2274#if RATE_CONTROL_LAMBDA_DOMAIN && M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     2275  UChar uhDepth = rpcTempCU->getDepth( 0 );
     2276  if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
     2277  {
     2278    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
     2279      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
     2280      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
     2281    m_spatialSAD = (Int)SAD;
     2282  }
     2283#endif
     2284#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
     2285  UChar uhDepth = rpcTempCU->getDepth( 0 );
     2286  if ( m_pcEncCfg->getUseRateCtrl() && eSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth )
     2287  {
     2288    UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(),
     2289      m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(),
     2290      rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) );
     2291    m_spatialSAD = (Int)SAD;
     2292  }
     2293#endif
    22372294  xCheckDQP( rpcTempCU );
    22382295  xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth);
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r608 r655  
    102102  Bool                    m_bUseSBACRD;
    103103  TEncRateCtrl*           m_pcRateCtrl;
    104 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     104#if RATE_CONTROL_LAMBDA_DOMAIN
     105#if !M0036_RC_IMPROVEMENT
    105106  UInt                    m_LCUPredictionSAD;
    106107  Int                     m_addSADDepth;
    107108  Int                     m_temporalSAD;
    108109#endif
     110#if M0036_RC_IMPROVEMENT && KWU_RC_MADPRED_E0227
     111  UInt                    m_LCUPredictionSAD;
     112  Int                     m_addSADDepth;
     113  Int                     m_temporalSAD;
     114  Int                     m_spatialSAD;
     115#endif
     116#endif
     117#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_RC_MADPRED_E0227
     118  UInt                    m_LCUPredictionSAD;
     119  Int                     m_addSADDepth;
     120  Int                     m_temporalSAD;
     121  Int                     m_spatialSAD;
     122#endif
     123
    109124public:
    110125  /// copy parameters from encoder class
     
    124139 
    125140  Void setBitCounter        ( TComBitCounter* pcBitCounter ) { m_pcBitCounter = pcBitCounter; }
    126 #if RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT
     141#if (RATE_CONTROL_LAMBDA_DOMAIN && !M0036_RC_IMPROVEMENT) || KWU_RC_MADPRED_E0227
    127142  UInt getLCUPredictionSAD() { return m_LCUPredictionSAD; }
    128143#endif
     
    145160
    146161#if AMP_MRG
    147 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     162#if  H_3D_FAST_TEXTURE_ENCODING
    148163  Void  xCheckRDCostInter   ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize ePartSize,  Bool bFMD, Bool bUseMRG = false  ) ;
    149164#else
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r608 r655  
    662662#endif
    663663
    664 #if LGE_INTER_SDC_E0156
     664#if H_3D_INTER_SDC
    665665  if( pcCU->getInterSDCFlag( uiAbsPartIdx ) )
    666666  {
     
    824824}
    825825
    826 #if LGE_INTER_SDC_E0156
     826#if H_3D_INTER_SDC
    827827Void TEncEntropy::encodeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    828828{
  • trunk/source/Lib/TLibEncoder/TEncEntropy.h

    r608 r655  
    9494  virtual Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
    9595#endif
    96 #if LGE_INTER_SDC_E0156
     96#if H_3D_INTER_SDC
    9797  virtual Void codeInterSDCFlag  ( TComDataCU* pcCU, UInt uiAbsPartIdx ) = 0;
    9898  virtual Void codeInterSDCResidualData ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment ) = 0;
     
    185185  Void encodeICFlag       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
    186186#endif
    187 #if LGE_INTER_SDC_E0156
     187#if H_3D_INTER_SDC
    188188  Void encodeInterSDCFlag ( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD = false );
    189189  Void encodeInterSDCResidualData( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD );
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r622 r655  
    153153#endif
    154154#endif
     155
     156#if KWU_FIX_URQ
     157  m_pcRateCtrl           = pcTEncTop->getRateCtrl();
     158#endif
    155159}
    156160
     
    351355#endif
    352356#if H_MV
    353 Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid)
    354 #else
    355 Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
     357Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid, bool isField, bool isTff)
     358#else
     359Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, bool isField, bool isTff)
    356360#endif
    357361{
     
    367371
    368372#if !H_MV
    369   xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
     373  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
     374
    370375 
    371376  m_iNumPicCoded = 0;
     
    439444
    440445    /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding
    441     Int pocCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC;
    442     Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
    443     if(iPOCLast == 0)
     446    Int iTimeOffset;
     447    Int pocCurr;
     448   
     449    if(iPOCLast == 0) //case first frame or first top field
    444450    {
    445451      pocCurr=0;
    446452      iTimeOffset = 1;
     453    }
     454    else if(iPOCLast == 1 && isField) //case first bottom field, just like the first frame, the poc computation is not right anymore, we set the right value
     455    {
     456      pocCurr = 1;
     457      iTimeOffset = 1;
     458    }
     459    else
     460    {
     461      pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
     462      iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
    447463    }
    448464    if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
     
    463479    accessUnitsInGOP.push_back(AccessUnit());
    464480    AccessUnit& accessUnit = accessUnitsInGOP.back();
    465     xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr );
     481    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField);
    466482
    467483    //  Slice data initialization
     
    472488
    473489
    474 #if H_MV5
    475490#if H_MV
    476     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
    477 #else
    478     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
    479 #endif
    480 #else
    481 #if H_3D
    482     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId() );     
    483 #else
    484     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
    485 #endif
    486 #endif
     491    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getVPS(), m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), getLayerId(), isField  );     
     492#else
     493    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField  );
     494#endif
     495   
     496    //Set Frame/Field coding
     497    pcSlice->getPic()->setField(isField);
     498
    487499    pcSlice->setLastIDR(m_iLastIDR);
    488500    pcSlice->setSliceIdx(0);
    489501#if H_MV
    490 #if H_MV5
    491502    pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer0, &m_refPicSetInterLayer1 );
    492 #else
    493     pcSlice->setRefPicSetInterLayer ( &m_refPicSetInterLayer );
    494 #endif
    495503    pcPic  ->setLayerId     ( getLayerId()   );
    496504    pcPic  ->setViewId      ( getViewId()    );   
     
    508516    pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
    509517    pcSlice->setScalingList ( m_pcEncTop->getScalingList()  );
    510     pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip());
    511518    if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
    512519    {
     
    562569    if(pcSlice->getTemporalLayerNonReferenceFlag())
    563570    {
    564       if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
     571      if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
     572          !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
     573        // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker)
    565574      {
    566575        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
     
    655664    refPicListModification->setRefPicListModificationFlagL1(0);
    656665#if H_MV
    657 #if H_MV5
    658666    if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 1 )
    659667    {
     
    699707    xSetRefPicListModificationsMv( tempRefPicLists, pcSlice, iGOPid );   
    700708#else
    701     if ( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > 0 )
    702     {
    703       pcSlice->setDiscardableFlag           ( false );     
    704     }   
    705 
    706     TComVPS*           vps = pcSlice->getVPS();
    707     Int       layerIdInVps = vps    ->getLayerIdInVps( getLayerId());
    708     Int numDirectRefLayers = vps    ->getNumDirectRefLayers( layerIdInVps );
    709     GOPEntry gopEntry      = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid );     
    710    
    711     if ( getLayerId() > 0 && numDirectRefLayers > 0 )
    712     {         
    713       pcSlice->setInterLayerPredEnabledFlag ( gopEntry.m_numActiveRefLayerPics > 0 );     
    714       if ( pcSlice->getInterLayerPredEnabledFlag() && numDirectRefLayers > 1 )
    715       {
    716         if ( !vps->getMaxOneActiveRefLayerFlag() )
    717         {   
    718           pcSlice->setNumInterLayerRefPicsMinus1( gopEntry.m_numActiveRefLayerPics - 1 );
    719         }
    720         for (Int i = 0; i < gopEntry.m_numActiveRefLayerPics; i++ )
    721         {
    722           pcSlice->setInterLayerPredLayerIdc( i, gopEntry.m_interLayerPredLayerIdc[ i ] );
    723         }
    724       }
    725     }
    726     assert( pcSlice->getNumActiveRefLayerPics() == gopEntry.m_numActiveRefLayerPics );
    727    
    728     if ( vps->getNumSamplePredRefLayers( layerIdInVps ) > 0 && pcSlice->getNumActiveRefLayerPics() > 0)
    729     {
    730       pcSlice->setInterLayerSamplePredOnlyFlag( gopEntry.m_numRefPics == 0 );
    731     }   
    732 
    733     pcSlice->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer );
    734     pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
    735     pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(gopEntry.m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) );
    736 
    737     xSetRefPicListModificationsMv( pcSlice, iGOPid );   
    738 
    739     pcSlice->setActiveMotionPredRefLayers( );
    740 
    741     if ( getLayerId() > 0 && pcSlice->getNumActiveMotionPredRefLayers() > 0 && pcSlice->getEnableTMVPFlag() &&
    742         ( pcSlice->getSliceType() == B_SLICE || pcSlice->getSliceType() == P_SLICE ))
    743     {
    744       pcSlice->setAltCollocatedIndicationFlag( gopEntry.m_collocatedRefLayerIdx >= 0 );
    745       if ( pcSlice->getNumActiveRefLayerPics() && pcSlice->getNumActiveMotionPredRefLayers() > 0 )
    746       {
    747         pcSlice->setCollocatedRefLayerIdx( gopEntry.m_collocatedRefLayerIdx );
    748       }
    749     }
    750 
    751 #endif
    752 #else
    753709    pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
    754710    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
     
    760716
    761717    //  Set reference list
    762 #if H_MV5
    763718#if H_MV   
    764719    pcSlice->setRefPicList( tempRefPicLists, usedAsLongTerm, numPocTotalCurr );
     
    782737      }
    783738    }
    784 #endif
    785 #else
    786 #if H_MV   
    787     pcSlice->setRefPicList( rcListPic, m_refPicSetInterLayer );
    788 #if H_3D_ARP
    789     pcSlice->setARPStepNum();
    790     if(pcSlice->getARPStepNum() > 1)
    791     {
    792       for(Int iLayerId = 0; iLayerId < getLayerId(); iLayerId ++ )
    793       {
    794         Int  iViewIdx =   pcSlice->getVPS()->getViewIndex(iLayerId);
    795         Bool bIsDepth = ( pcSlice->getVPS()->getDepthId  ( iLayerId ) == 1 );
    796         if( iViewIdx<getViewIndex() && !bIsDepth )
    797         {
    798           pcSlice->setBaseViewRefPicList( m_ivPicLists->getPicList( iLayerId ), iViewIdx );
    799         }
    800       }
    801     }
    802 #endif
    803 #else
    804     pcSlice->setRefPicList ( rcListPic );
    805 #endif
    806739#endif
    807740#if H_3D
     
    913846
    914847    // SAIT_VSO_EST_A0033
     848#if H_3D_FCO
     849    Bool flagRec;
     850    flagRec =  ((m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), true) == NULL) ? false: true);
     851    pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false, pcSlice->getPOC(), flagRec ) );
     852    pcRdCost->setDepthPicYuv   ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true, pcSlice->getPOC(), false ) );
     853#else
    915854    pcRdCost->setVideoRecPicYuv( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), false , pcSlice->getPOC(), true ) );
    916855    pcRdCost->setDepthPicYuv   ( m_pcEncTop->getIvPicLists()->getPicYuv( pcSlice->getViewIndex(), true  , pcSlice->getPOC(), false ) );
     856#endif
    917857
    918858    // LGE_WVSO_A0119
     
    970910      }
    971911      m_pcRateCtrl->initRCPic( frameLevel );
     912
     913#if KWU_RC_MADPRED_E0227
     914      if(m_pcCfg->getLayerId() != 0)
     915      {
     916        m_pcRateCtrl->getRCPic()->setIVPic( m_pcEncTop->getEncTop()->getTEncTop(0)->getRateCtrl()->getRCPic() );
     917      }
     918#endif
     919
    972920      estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits();
    973921
     
    1014962      else    // normal case
    1015963      {
     964#if KWU_RC_MADPRED_E0227
     965        if(m_pcRateCtrl->getLayerID() != 0)
     966        {
     967          list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
     968          lambda  = m_pcRateCtrl->getRCPic()->estimatePicLambdaIV( listPreviousPicture, pcSlice->getPOC() );
     969          sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
     970        }
     971        else
     972        {
     973#endif
    1016974        list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList();
    1017975#if RATE_CONTROL_INTRA
     
    1021979#endif
    1022980        sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture );
     981#if KWU_RC_MADPRED_E0227
     982        }
     983#endif
    1023984      }
    1024985
     
    11551116        pcPic->setNumDdvCandPics(pcPic->getDisCandRefPictures(iColPoc));
    11561117      }
     1118#endif
    11571119#if H_3D
    11581120      pcSlice->setDepthToDisparityLUTs();
    11591121
    11601122#endif
    1161 #endif
    1162 #if MTK_NBDV_TN_FIX_E0172
     1123
     1124#if H_3D_NBDV
    11631125      if(pcSlice->getViewIndex() && !pcSlice->getIsDepth() && !pcSlice->isIntra()) //Notes from QC: this condition shall be changed once the configuration is completed, e.g. in pcSlice->getSPS()->getMultiviewMvPredMode() || ARP in prev. HTM. Remove this comment once it is done.
    11641126      {
    11651127        pcPic->checkTemporalIVRef();
    11661128      }
    1167 #endif
    1168 #if MTK_TEXTURE_MRGCAND_BUGFIX_E0182
     1129
    11691130      if(pcSlice->getIsDepth())
    11701131      {
     
    14121373        }
    14131374      }
    1414       pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
     1375      pictureTimingSEI.m_auCpbRemovalDelay = std::min<Int>(std::max<Int>(1, m_totalCoded - m_lastBPSEI), static_cast<Int>(pow(2, static_cast<double>(pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getCpbRemovalDelayLengthMinus1()+1)))); // Syntax element signalled as minus, hence the .
    14151376      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
    14161377      Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
     
    18621823        pcPic->destroyNonDBFilterInfo();
    18631824      }
    1864 #if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
     1825#if H_3D
    18651826      pcPic->compressMotion(2);
    18661827#endif
     
    18981859          digestStr = digestToString(sei_recon_picture_digest.digest, 4);
    18991860        }
    1900 #if H_MV_FIX_LID_PIC_HASH_SEI_T40
     1861#if H_MV
    19011862        OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), getLayerId() );
    19021863#else
     
    19401901      xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime );
    19411902
     1903    //In case of field coding, compute the interlaced PSNR for both fields
     1904    if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
     1905    {
     1906      //get complementary top field
     1907      TComPic* pcPicTop;
     1908      TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
     1909      while ((*iterPic)->getPOC() != pcPic->getPOC()-1)
     1910      {
     1911        iterPic ++;
     1912      }
     1913      pcPicTop = *(iterPic);
     1914      xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
     1915    }
     1916   
    19421917      if (digestStr)
    19431918      {
     
    20722047            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    20732048          m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     2049          pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
    20742050          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
    20752051          writeRBSPTrailingBits(nalu.m_Bitstream);
     
    21662142      pcPic->setReconMark   ( true );
    21672143#if H_MV
    2168 #if H_MV5
    21692144      TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer0, m_refPicSetInterLayer1 ); 
    2170 #else
    2171       TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); 
    2172 #endif
    21732145      std::vector<Int> temp;
    21742146      TComSlice::markCurrPic( pcPic );
     
    21842156      delete[] pcSubstreamsOut;
    21852157  }
    2186 #if !RATE_CONTROL_LAMBDA_DOMAIN
     2158#if !KWU_FIX_URQ && !RATE_CONTROL_LAMBDA_DOMAIN
    21872159  if(m_pcCfg->getUseRateCtrl())
    21882160  {
     
    21962168
    21972169#if !H_MV
    2198   assert ( m_iNumPicCoded == iNumPicRcvd );
     2170  assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) );
    21992171#endif
    22002172}
    22012173
    22022174#if !H_MV
    2203 Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
     2175Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, bool isField)
    22042176{
    22052177  assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic());
     
    22072179   
    22082180  //--CFG_KDY
     2181  if(isField)
     2182  {
     2183    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2184    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2185    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2186    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2187  }
     2188  else
     2189  {
    22092190  m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
    22102191  m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
    22112192  m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
    22122193  m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
     2194  }
    22132195 
    22142196  //-- all
     
    22332215  m_gcAnalyzeB.printSummary('B');
    22342216#endif
     2217
     2218  if(isField)
     2219  {
     2220    //-- interlaced summary
     2221    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate());
     2222    printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
     2223    m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll.getBits());
     2224   
     2225#if _SUMMARY_OUT_
     2226    m_gcAnalyzeAll_in.printSummaryOutInterlaced();
     2227#endif
     2228  }
    22352229
    22362230  printf("\nRVM: %.3lf\n" , xCalculateRVM());
     
    22762270// Protected member functions
    22772271// ====================================================================================================================
     2272
     2273
     2274Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField )
     2275{
     2276  assert( iNumPicRcvd > 0 );
     2277  //  Exception for the first frames
     2278  if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField  && (iPOCLast == 0))  )
     2279  {
     2280    m_iGopSize    = 1;
     2281  }
     2282  else
     2283  {
     2284    m_iGopSize    = m_pcCfg->getGOPSize();
     2285  }
     2286  assert (m_iGopSize > 0);
     2287 
     2288  return;
     2289}
    22782290
    22792291Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut )
     
    22992311                         TComPic*&                 rpcPic,
    23002312                         TComPicYuv*&              rpcPicYuvRecOut,
    2301                          Int                       pocCurr )
     2313                         Int                       pocCurr,
     2314                         bool                      isField)
    23022315{
    23032316  Int i;
    23042317  //  Rec. output
    23052318  TComList<TComPicYuv*>::iterator     iterPicYuvRec = rcListPicYuvRecOut.end();
    2306   for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ )
     2319 
     2320  if (isField)
     2321  {
     2322    for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ )
     2323    {
     2324      iterPicYuvRec--;
     2325    }
     2326  }
     2327  else
     2328  {
     2329    for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ )
    23072330  {
    23082331    iterPicYuvRec--;
    23092332  }
    23102333 
     2334  }
     2335 
     2336  if (isField)
     2337  {
     2338    if(pocCurr == 1)
     2339    {
     2340      iterPicYuvRec++;
     2341    }
     2342  }
    23112343  rpcPicYuvRecOut = *(iterPicYuvRec);
    23122344 
     
    23232355    iterPic++;
    23242356  }
    2325  
     2357
     2358#if !H_MV
     2359  assert( rpcPic != NULL );
     2360#endif
    23262361  assert (rpcPic->getPOC() == pocCurr);
    23272362 
     
    26422677}
    26432678
     2679
     2680Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, bool isTff)
     2681{
     2682 
     2683  for (Int y = 0; y < height; y++)
     2684  {
     2685    for (Int x = 0; x < width; x++)
     2686    {
     2687      dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
     2688      dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     2689    }
     2690    top += stride;
     2691    bottom += stride;
     2692    dst += stride*2;
     2693  }
     2694}
     2695
     2696
     2697Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime )
     2698{
     2699#if  H_MV
     2700  assert( 0 ); // Field coding and MV need to be aligned.
     2701#else
     2702  Int     x, y;
     2703 
     2704  UInt64 uiSSDY_in  = 0;
     2705  UInt64 uiSSDU_in  = 0;
     2706  UInt64 uiSSDV_in  = 0;
     2707 
     2708  Double  dYPSNR_in  = 0.0;
     2709  Double  dUPSNR_in  = 0.0;
     2710  Double  dVPSNR_in  = 0.0;
     2711 
     2712  /*------ INTERLACED PSNR -----------*/
     2713 
     2714  /* Luma */
     2715 
     2716  Pel*  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr();
     2717  Pel*  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr();
     2718  Pel*  pRecTop = pcPicRecTop->getLumaAddr();
     2719  Pel*  pRecBottom = pcPicRecBottom->getLumaAddr();
     2720 
     2721  Int   iWidth;
     2722  Int   iHeight;
     2723  Int iStride;
     2724 
     2725  iWidth  = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0);
     2726  iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1);
     2727  iStride = pcPicOrgTop->getPicYuvOrg()->getStride();
     2728  Int   iSize   = iWidth*iHeight;
     2729  bool isTff = pcPicOrgTop->isTopField();
     2730 
     2731  TComPicYuv* pcOrgInterlaced = new TComPicYuv;
     2732  pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     2733 
     2734  TComPicYuv* pcRecInterlaced = new TComPicYuv;
     2735  pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     2736 
     2737  Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr();
     2738  Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr();
     2739 
     2740  //=== Interlace fields ====
     2741  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     2742  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     2743 
     2744  //===== calculate PSNR =====
     2745  for( y = 0; y < iHeight << 1; y++ )
     2746  {
     2747    for( x = 0; x < iWidth; x++ )
     2748    {
     2749      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     2750      uiSSDY_in   += iDiff * iDiff;
     2751    }
     2752    pOrgInterlaced += iStride;
     2753    pRecInterlaced += iStride;
     2754  }
     2755 
     2756  /*Chroma*/
     2757 
     2758  iHeight >>= 1;
     2759  iWidth  >>= 1;
     2760  iStride >>= 1;
     2761 
     2762  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr();
     2763  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr();
     2764  pRecTop = pcPicRecTop->getCbAddr();
     2765  pRecBottom = pcPicRecBottom->getCbAddr();
     2766  pOrgInterlaced = pcOrgInterlaced->getCbAddr();
     2767  pRecInterlaced = pcRecInterlaced->getCbAddr();
     2768 
     2769  //=== Interlace fields ====
     2770  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     2771  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     2772 
     2773  //===== calculate PSNR =====
     2774  for( y = 0; y < iHeight << 1; y++ )
     2775  {
     2776    for( x = 0; x < iWidth; x++ )
     2777    {
     2778      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     2779      uiSSDU_in   += iDiff * iDiff;
     2780    }
     2781    pOrgInterlaced += iStride;
     2782    pRecInterlaced += iStride;
     2783  }
     2784 
     2785  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr();
     2786  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr();
     2787  pRecTop = pcPicRecTop->getCrAddr();
     2788  pRecBottom = pcPicRecBottom->getCrAddr();
     2789  pOrgInterlaced = pcOrgInterlaced->getCrAddr();
     2790  pRecInterlaced = pcRecInterlaced->getCrAddr();
     2791 
     2792  //=== Interlace fields ====
     2793  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     2794  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     2795 
     2796  //===== calculate PSNR =====
     2797  for( y = 0; y < iHeight << 1; y++ )
     2798  {
     2799    for( x = 0; x < iWidth; x++ )
     2800    {
     2801      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     2802      uiSSDV_in   += iDiff * iDiff;
     2803    }
     2804    pOrgInterlaced += iStride;
     2805    pRecInterlaced += iStride;
     2806  }
     2807 
     2808  Int maxvalY = 255 << (g_bitDepthY-8);
     2809  Int maxvalC = 255 << (g_bitDepthC-8);
     2810  Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2;
     2811  Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0;
     2812  dYPSNR_in            = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 );
     2813  dUPSNR_in            = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 );
     2814  dVPSNR_in            = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 );
     2815 
     2816  /* calculate the size of the access unit, excluding:
     2817   *  - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
     2818   *  - SEI NAL units
     2819   */
     2820  UInt numRBSPBytes = 0;
     2821  for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
     2822  {
     2823    UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
     2824   
     2825    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
     2826      numRBSPBytes += numRBSPBytes_nal;
     2827  }
     2828 
     2829  UInt uibits = numRBSPBytes * 8 ;
     2830 
     2831  //===== add PSNR =====
     2832  m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits);
     2833 
     2834  printf("\n                                      Interlaced frame %d: [Y %6.4lf dB    U %6.4lf dB    V %6.4lf dB]", pcPicOrgBottom->getPOC()/2 , dYPSNR_in, dUPSNR_in, dVPSNR_in );
     2835 
     2836  pcOrgInterlaced->destroy();
     2837  delete pcOrgInterlaced;
     2838  pcRecInterlaced->destroy();
     2839  delete pcRecInterlaced;
     2840#endif
     2841}
    26442842/** Function for deciding the nal_unit_type.
    26452843 * \param pocCurr POC of the current picture
     
    30023200
    30033201#if H_MV
    3004 #if H_MV5
    30053202Void TEncGOP::xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid )
    30063203{
     
    30863283  }
    30873284}
    3088 #else
    3089 Void TEncGOP::xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid )
    3090 {
    3091   Int layer    = pcSlice->getLayerIdInVps( );
    3092  
    3093   if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || pcSlice->getNumActiveRefLayerPics() == 0 )
    3094   {
    3095     return;
    3096   }
    3097 
    3098   // analyze inter-view modifications
    3099   GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( layer > 0) ) ? MAX_GOP : iGOPid );
    3100   assert( ge.m_numActiveRefLayerPics == pcSlice->getNumActiveRefLayerPics() );
    3101  
    3102   Int maxRefListSize  = pcSlice->getNumRpsCurrTempList();
    3103   Int numTemporalRefs = maxRefListSize - pcSlice->getNumActiveRefLayerPics();
    3104 
    3105   for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1
    3106   {
    3107     // set inter-view modifications   
    3108     Int tempList[16];
    3109     for( Int k = 0; k < 16; k++ )
    3110     {
    3111       tempList[ k ] = -1;
    3112     }
    3113 
    3114     Bool isModified = false;
    3115     if ( maxRefListSize > 1 )
    3116     {
    3117       for( Int k = 0, orgIdx = numTemporalRefs; k < ge.m_numActiveRefLayerPics; k++, orgIdx++ )
    3118       {
    3119           Int targetIdx = ge.m_interViewRefPosL[ li ][ k ];
    3120 
    3121         isModified = ( targetIdx != orgIdx ) && ( targetIdx >= 0  );
    3122         if ( isModified )
    3123             {
    3124           assert( tempList[ targetIdx ] == -1 ); // Assert when two inter layer reference pictures are sorted to the same position
    3125               tempList[ targetIdx ] = orgIdx;             
    3126         }
    3127       }
    3128     }
    3129 
    3130     TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
    3131     refPicListModification->setRefPicListModificationFlagL( li, isModified ); 
    3132 
    3133       if( isModified )
    3134       {
    3135         Int temporalRefIdx = 0;
    3136         for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ )
    3137         {
    3138           if( tempList[i] >= 0 )
    3139           {
    3140             refPicListModification->setRefPicSetIdxL( li, i, tempList[i] );
    3141           }
    3142           else
    3143           {
    3144             refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx );
    3145             temporalRefIdx++;
    3146           }
    3147         }
    3148       }
    3149   }
    3150 }
    3151 #endif
    31523285#endif
    31533286//! \}
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r622 r655  
    5757#include "TEncAnalyze.h"
    5858#include "TEncRateCtrl.h"
     59#if KWU_RC_MADPRED_E0227
     60#include "../App/TAppEncoder/TAppEncTop.h"
     61#endif
    5962#include <vector>
    6063
     
    99102#if H_MV
    100103  TComPicLists*           m_ivPicLists;
    101 #if H_MV5
    102104  std::vector<TComPic*>   m_refPicSetInterLayer0;
    103105  std::vector<TComPic*>   m_refPicSetInterLayer1;
    104 #else
    105   std::vector<TComPic*>   m_refPicSetInterLayer;
    106 #endif
    107106
    108107  Int                     m_pocLastCoded;
     
    148147#if H_MV
    149148  Void  initGOP     ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP);
    150   Void  compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid );
     149  Void  compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid, Bool isField, Bool isTff );
    151150#else
    152   Void  compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
     151  Void  compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
    153152#endif
    154153  Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
     
    169168
    170169#if !H_MV
    171   Void  printOutSummary      ( UInt uiNumAllPicCoded );
     170  Void  printOutSummary      ( UInt uiNumAllPicCoded , bool isField);
    172171#endif
    173172#if H_3D_VSO
     
    176175  Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
    177176#endif
    178  
     177
     178#if KWU_RC_MADPRED_E0227
     179  TEncTop* getEncTop() { return m_pcEncTop; }
     180#endif
     181
    179182  TEncSlice*  getSliceEncoder()   { return m_pcSliceEncoder; }
    180183  NalUnitType getNalUnitType( Int pocCurr, Int lastIdr );
     
    184187
    185188protected:
     189  Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField );
     190
    186191  Void  xInitGOP          ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut );
    187   Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr );
     192  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, bool isField );
    188193 
    189194  Void  xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime );
     195  Void  xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime );
     196
    190197#if H_3D_VSO
    191198  Dist64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1);
     
    216223  }
    217224#if H_MV
    218 #if H_MV5
    219225   Void  xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid );
    220 #else
    221    Void  xSetRefPicListModificationsMv( TComSlice* pcSlice, UInt iGOPid );
    222 #endif
    223226#endif
    224227  Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.cpp

    r608 r655  
    537537  m_lastPicture  = NULL;
    538538#endif
     539
     540#if KWU_RC_MADPRED_E0227
     541  m_lastIVPicture = NULL;
     542#endif
     543
    539544  m_picActualHeaderBits = 0;
    540545#if !M0036_RC_IMPROVEMENT
     
    544549  m_picQP               = 0;
    545550  m_picLambda           = 0.0;
     551
     552#if KWU_RC_MADPRED_E0227
     553  m_IVtotalMAD            = 0.0;
     554#endif
    546555}
    547556
     
    621630}
    622631
     632#if KWU_RC_MADPRED_E0227
     633Void TEncRCPic::addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures )
     634{
     635  m_lastIVPicture = NULL;
     636  m_lastIVPicture = this;
     637}
     638
     639Void TEncRCPic::setIVPic( TEncRCPic* BaseRCPic )
     640{
     641  m_lastIVPicture = BaseRCPic;
     642}
     643#endif
     644
     645#if KWU_RC_MADPRED_E0227
     646Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int layerID )
     647#else
    623648Void TEncRCPic::create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures )
     649#endif
    624650{
    625651  destroy();
     
    673699      Int currHeight = ( (j == picHeightInLCU-1) ? picHeight - LCUHeight*(picHeightInLCU-1) : LCUHeight );
    674700      m_LCUs[LCUIdx].m_numberOfPixel = currWidth * currHeight;
     701
     702#if KWU_RC_MADPRED_E0227
     703      m_LCUs[LCUIdx].m_CUWidth = currWidth;
     704      m_LCUs[LCUIdx].m_CUHeight = currHeight;
     705      m_LCUs[LCUIdx].m_IVMAD = -1.0;
     706#endif
    675707    }
    676708  }
     
    683715  m_picLambda           = 0.0;
    684716
     717
     718#if KWU_RC_MADPRED_E0227
     719  m_LayerID = layerID;
     720  m_lastIVPicture = NULL;
     721  m_IVtotalMAD            = 0.0;
     722#endif
     723
     724
    685725#if !M0036_RC_IMPROVEMENT
    686726  m_lastPicture = NULL;
    687727  list<TEncRCPic*>::reverse_iterator it;
     728  for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
     729  {
     730    if ( (*it)->getFrameLevel() == m_frameLevel )
     731    {
     732      m_lastPicture = (*it);
     733      break;
     734    }
     735  }
     736#endif
     737
     738#if KWU_RC_MADPRED_E0227
     739  list<TEncRCPic*>::reverse_iterator it;
     740  if( m_LayerID != 0)
     741  {
     742    m_lastIVPicture = NULL;
     743    for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
     744    {
     745      if ( (*it)->getLayerID() == 0 )
     746      {
     747        m_lastIVPicture = (*it);
     748        break;
     749      }
     750    }
     751  }
     752
     753  m_lastPicture = NULL;
    688754  for ( it = listPreviousPictures.rbegin(); it != listPreviousPictures.rend(); it++ )
    689755  {
     
    856922}
    857923
     924
     925#if KWU_RC_MADPRED_E0227
     926Double TEncRCPic::estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int CurPOC )
     927{
     928  Double alpha         = m_encRCSeq->getPicPara( m_frameLevel ).m_alpha;
     929  Double beta          = m_encRCSeq->getPicPara( m_frameLevel ).m_beta;
     930  Double bpp       = (Double)m_targetBits/(Double)m_numberOfPixel;
     931  Double estLambda = alpha * pow( bpp, beta );
     932  Double lastLevelLambda = -1.0;
     933  Double lastPicLambda   = -1.0;
     934  Double lastValidLambda = -1.0;
     935  list<TEncRCPic*>::iterator it;
     936
     937  if(listPreviousPictures.size() == 0 || CurPOC%8 == 0)
     938  {
     939    lastLevelLambda = m_lastIVPicture->getPicActualLambda();
     940    lastPicLambda     = m_lastIVPicture->getPicActualLambda();
     941  }
     942  else
     943  {
     944    for ( it = listPreviousPictures.begin(); it != listPreviousPictures.end(); it++ )
     945    {
     946      if ( (*it)->getFrameLevel() == m_frameLevel )
     947      {
     948        lastLevelLambda = (*it)->getPicActualLambda();
     949      }
     950      lastPicLambda     = (*it)->getPicActualLambda();
     951
     952      if ( lastPicLambda > 0.0 )
     953      {
     954        lastValidLambda = lastPicLambda;
     955      }
     956    }
     957  }
     958
     959  if ( lastLevelLambda > 0.0 )
     960  {
     961    lastLevelLambda = Clip3( 0.1, 10000.0, lastLevelLambda );
     962    estLambda = Clip3( lastLevelLambda * pow( 2.0, -3.0/3.0 ), lastLevelLambda * pow( 2.0, 3.0/3.0 ), estLambda );
     963  }
     964
     965  if ( lastPicLambda > 0.0 )
     966  {
     967    lastPicLambda = Clip3( 0.1, 2000.0, lastPicLambda );
     968    estLambda = Clip3( lastPicLambda * pow( 2.0, -10.0/3.0 ), lastPicLambda * pow( 2.0, 10.0/3.0 ), estLambda );
     969  }
     970  else if ( lastValidLambda > 0.0 )
     971  {
     972    lastValidLambda = Clip3( 0.1, 2000.0, lastValidLambda );
     973    estLambda = Clip3( lastValidLambda * pow(2.0, -10.0/3.0), lastValidLambda * pow(2.0, 10.0/3.0), estLambda );
     974  }
     975  else
     976  {
     977    estLambda = Clip3( 0.1, 10000.0, estLambda );
     978  }
     979
     980  if ( estLambda < 0.1 )
     981  {
     982    estLambda = 0.1;
     983  }
     984
     985  m_estPicLambda = estLambda;
     986  return estLambda;
     987}
     988#endif
     989
     990
    858991#if RATE_CONTROL_INTRA
    859992Double TEncRCPic::getLCUTargetBpp(SliceType eSliceType) 
     
    9371070}
    9381071
     1072
     1073#if KWU_RC_MADPRED_E0227
     1074Double TEncRCPic::getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity )
     1075{
     1076  Int   LCUIdx    = getLCUCoded();
     1077  Double bpp      = -1.0;
     1078  Int avgBits     = 0;
     1079#if !M0036_RC_IMPROVEMENT
     1080  Double totalMAD = -1.0;
     1081  Double MAD      = -1.0;
     1082#endif
     1083
     1084  Double totalMAD = -1.0;
     1085  Double MAD      = -1.0;
     1086
     1087  Double IVMAD      = -1.0;
     1088  Double SAD = 0.0;
     1089  Int     x, y;
     1090  Int Sum = 0;
     1091
     1092  {
     1093    Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     1094    Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
     1095    Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     1096    Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
     1097
     1098    Int   width  = m_LCUs[ LCUIdx ].m_CUWidth;
     1099    Int   height = m_LCUs[ LCUIdx ].m_CUHeight;
     1100
     1101    for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
     1102    {
     1103      for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
     1104      {
     1105        Sum += pDep[x];
     1106      }
     1107      pDep += iStride;
     1108    }
     1109
     1110    Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
     1111
     1112    Double fL = focalLen * abs( basePos - curPos );
     1113    Double z  = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);
     1114    *disparity = (Int)(direction*fL * z);
     1115    Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
     1116
     1117    Int disp = *disparity;
     1118    Int posX, posY;
     1119    pcCU->getPosInPic(0, posX, posY);
     1120    if((posX + *disparity) < 0 || (posX + *disparity + width) >= pcCU->getSlice()->getSPS()->getMaxCUWidth())
     1121    {
     1122      disp = 0;
     1123    }
     1124
     1125    for( y = 0; y < height; y++ )
     1126    {
     1127      for( x = 0; x < width; x++ )
     1128      {
     1129        SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]
     1130                  - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;
     1131      }
     1132      pOrg += iStride;
     1133      pRec += iStride;
     1134    }
     1135    IVMAD = SAD / (Double)(height * width);
     1136    IVMAD = IVMAD * IVMAD;
     1137
     1138    m_LCUs[ LCUIdx ].m_IVMAD = IVMAD;
     1139    if(m_lastPicture)
     1140    {
     1141      m_LCUs[ LCUIdx ].m_MAD = m_lastPicture->getLCU(LCUIdx).m_MAD;
     1142    }
     1143
     1144    MAD = m_LCUs[ LCUIdx ].m_IVMAD;
     1145
     1146    if(m_lastPicture)
     1147    {
     1148      totalMAD = m_lastPicture->getTotalMAD();      // get total MAD of temporal frame
     1149      for ( Int i=0; i<LCUIdx; i++ )
     1150      {
     1151        totalMAD -= m_lastPicture->getLCU(i).m_MAD;
     1152      }
     1153    }
     1154    else
     1155    {
     1156      totalMAD = m_lastIVPicture->getTotalMAD();      // get total MAD of inter-view frame
     1157      for ( Int i=0; i<LCUIdx; i++ )
     1158      {
     1159        totalMAD -= m_lastIVPicture->getLCU(i).m_MAD;
     1160      }
     1161    }
     1162
     1163
     1164    if ( totalMAD > 0.1 )
     1165    {
     1166      avgBits = Int( (m_bitsLeft * MAD) / totalMAD );
     1167    }
     1168    else
     1169    {
     1170      avgBits = Int( (m_bitsLeft) / m_LCULeft );
     1171    }
     1172  }
     1173
     1174  if ( avgBits < 5 )
     1175  {
     1176    avgBits = 5;
     1177  }
     1178
     1179  bpp = ( Double )avgBits/( Double )m_LCUs[ LCUIdx ].m_numberOfPixel;
     1180  m_LCUs[ LCUIdx ].m_targetBits = avgBits;
     1181
     1182  return bpp;
     1183}
     1184#endif
     1185
     1186
     1187
     1188
    9391189Double TEncRCPic::getLCUEstLambda( Double bpp )
    9401190{
     
    11851435  }
    11861436  m_picLambda           = averageLambda;
    1187 #if !M0036_RC_IMPROVEMENT
     1437#if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
     1438#if KWU_RC_MADPRED_E0227
     1439  m_totalMAD = 0;
     1440#endif
    11881441  for ( Int i=0; i<m_numberOfLCU; i++ )
    11891442  {
     
    13931646
    13941647#if M0036_RC_IMPROVEMENT
     1648#if KWU_RC_MADPRED_E0227
     1649Void 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], Int layerID )
     1650#else
    13951651Void 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] )
     1652#endif
    13961653#else
    13971654Void 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] )
     
    16071864  }
    16081865
     1866#if KWU_RC_MADPRED_E0227
     1867  setLayerID(layerID);
     1868#endif
     1869
    16091870  delete[] bitsRatio;
    16101871  delete[] GOPID2Level;
     
    16141875{
    16151876  m_encRCPic = new TEncRCPic;
     1877#if KWU_RC_MADPRED_E0227
     1878  m_encRCPic->create( m_encRCSeq, m_encRCGOP, frameLevel, m_listRCPictures, m_LayerID );
     1879#else
    16161880  m_encRCPic->create( m_encRCSeq, m_encRCGOP, frameLevel, m_listRCPictures );
     1881#endif
    16171882}
    16181883
     
    18152080  m_sourceHeightInLCU        = (sourceHeight / maxCUHeight) + (( sourceHeight %  maxCUHeight) ? 1 : 0); 
    18162081  m_isLowdelay               = (sizeIntraPeriod == -1) ? true : false;
     2082
    18172083  m_prevBitrate              = ( targetKbps << 10 );  // in units of 1,024 bps
    18182084  m_currBitrate              = ( targetKbps << 10 );
     2085
    18192086  m_frameRate                = frameRate;
    18202087  m_refFrameNum              = m_isLowdelay ? (sizeGOP) : (sizeGOP>>1);
     
    22122479}
    22132480
     2481
     2482#if KWU_RC_MADPRED_E0227
     2483Void  TEncRateCtrl::updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction)
     2484{
     2485  Int     x, y;
     2486  Double dMAD = 0.0;
     2487  Int Sum = 0;
     2488  Double SAD = 0.0;
     2489
     2490  Pel*  pOrg    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     2491  Pel*  pRec    = pcCU->getSlice()->getIvPic(false, 0)->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), 0);
     2492  Pel*  pDep    = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getLumaAddr(pcCU->getAddr(), 0);
     2493  Int   iStride = pcCU->getSlice()->getIvPic(true, pcCU->getSlice()->getViewIndex())->getPicYuvOrg()->getStride();
     2494
     2495  Int   width  = m_pcLCUData[m_indexLCU].m_widthInPixel;
     2496  Int   height = m_pcLCUData[m_indexLCU].m_heightInPixel;
     2497
     2498  for( y = 0 ; y < pcCU->getSlice()->getSPS()->getMaxCUHeight() ; y+=8)
     2499  {
     2500    for( x = 0 ; x < pcCU->getSlice()->getSPS()->getMaxCUWidth() ; x+=8)
     2501    {
     2502      Sum += pDep[x];
     2503    }
     2504    pDep += iStride;
     2505  }
     2506
     2507  Double AvgDepth = (Double)Sum/((pcCU->getSlice()->getSPS()->getMaxCUHeight()/8)*(pcCU->getSlice()->getSPS()->getMaxCUWidth()/8));
     2508  Double fL = focalLen * abs( basePos - curPos );
     2509  Double z  = abs( 1.0 / znear - 1.0 / zfar ) * ((Double)(AvgDepth) / (( 1 << g_bitDepthY ) - 1) ) + abs(1.0 / zfar);
     2510  Int   disparity = (Int)(direction*fL * z);
     2511  Int shift = DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8);
     2512  Int disp = disparity;
     2513
     2514  for( y = 0; y < height; y++ )
     2515  {
     2516    for( x = 0; x < width; x++ )
     2517    {
     2518      SAD += abs( pOrg[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)]
     2519      - pRec[Clip3(0, (Int)(pcCU->getPic()->getPicYuvOrg()->getWidth() - pcCU->getSlice()->getSPS()->getMaxCUWidth()), x + disp)] )>>shift;
     2520    }
     2521    pOrg += iStride;
     2522    pRec += iStride;
     2523  }
     2524  m_pcLCUData[m_indexLCU].m_qp   = qp;
     2525  m_pcLCUData[m_indexLCU].m_costMAD  = (SAD /(Double)(width*height));
     2526  m_pcLCUData[m_indexLCU].m_bits = (Int)uiBits;
     2527}
     2528#endif
     2529
     2530
    22142531Double TEncRateCtrl::xAdjustmentBits(Int& reductionBits, Int& compensationBits)
    22152532{
  • trunk/source/Lib/TLibEncoder/TEncRateCtrl.h

    r608 r655  
    9898  Int m_targetBitsLeft;
    9999#endif
     100
     101#if KWU_RC_MADPRED_E0227
     102  Double m_MAD;
     103
     104  Int m_CUWidth;
     105  Int m_CUHeight;
     106  Double m_IVMAD;
     107#endif
    100108};
    101109
     
    248256
    249257public:
     258#if KWU_RC_MADPRED_E0227
     259  Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures, Int layerID );
     260#else
    250261  Void create( TEncRCSeq* encRCSeq, TEncRCGOP* encRCGOP, Int frameLevel, list<TEncRCPic*>& listPreviousPictures );
     262#endif
    251263  Void destroy();
    252264
     265#if KWU_RC_MADPRED_E0227
     266  Double estimatePicLambdaIV( list<TEncRCPic*>& listPreviousPictures, Int curPOC );
     267#endif
    253268#if !RATE_CONTROL_INTRA
    254269  Double estimatePicLambda( list<TEncRCPic*>& listPreviousPictures );
     
    267282  Double getLCUTargetBpp();
    268283#endif
     284
     285#if KWU_RC_MADPRED_E0227
     286  Double getLCUTargetBppforInterView( list<TEncRCPic*>& listPreviousPictures, TComDataCU* pcCU, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction, Int* disparity );
     287#endif
     288
    269289  Double getLCUEstLambda( Double bpp );
    270290  Int    getLCUEstQP( Double lambda, Int clipPicQP );
     
    282302
    283303  Void addToPictureLsit( list<TEncRCPic*>& listPreviousPictures );
     304
     305#if KWU_RC_MADPRED_E0227
     306  Void addToPictureLsitIV( list<TEncRCPic*>& listPreviousPictures );
     307  Void setIVPic( TEncRCPic* baseRCPic );
     308#endif
     309
    284310#if !M0036_RC_IMPROVEMENT
    285311  Double getEffectivePercentage();
     
    322348#endif
    323349
     350#if KWU_RC_MADPRED_E0227
     351  Double getTotalMAD()                                    { return m_totalMAD; }
     352  Void   setTotalMAD( Double MAD )                        { m_totalMAD = MAD; }
     353
     354  Double getIVTotalMAD()                                    { return m_IVtotalMAD; }
     355  Void   setIVTotalMAD( Double MAD )                        { m_IVtotalMAD = MAD; }
     356#endif
     357
    324358  Int  getPicActualBits()                                 { return m_picActualBits; }
    325359  Int  getPicActualQP()                                   { return m_picQP; }
     
    330364  Void setPicEstLambda( Double lambda )                   { m_picLambda = lambda; }
    331365
     366#if KWU_RC_MADPRED_E0227
     367  Int getLayerID()                                         { return m_LayerID; }
     368  Void setLayerID(Int layerid)                              { m_LayerID = layerid; }
     369#endif
     370
    332371private:
    333372  TEncRCSeq* m_encRCSeq;
     
    361400  TEncRCPic* m_lastPicture;
    362401#endif
     402
     403#if KWU_RC_MADPRED_E0227
     404  Double m_totalMAD;
     405  TEncRCPic* m_lastPicture;
     406  Int m_LayerID;
     407  TEncRCPic* m_lastIVPicture;
     408  Double m_IVtotalMAD;
     409#endif
    363410};
    364411
     
    371418public:
    372419#if M0036_RC_IMPROVEMENT
     420#if KWU_RC_MADPRED_E0227
     421  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], Int layerID );
     422#else
    373423  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] );
     424#endif
    374425#else
    375426  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] );
     
    388439  list<TEncRCPic*>& getPicList() { return m_listRCPictures; }
    389440
     441#if KWU_RC_MADPRED_E0227
     442  Int getLayerID()                { return m_LayerID; }
     443  Void setLayerID(Int layerid)     { m_LayerID = layerid; }
     444#endif
     445
    390446private:
    391447  TEncRCSeq* m_encRCSeq;
     
    394450  list<TEncRCPic*> m_listRCPictures;
    395451  Int        m_RCQP;
     452
     453#if KWU_RC_MADPRED_E0227
     454  Int m_LayerID;
     455#endif
    396456};
    397457
     
    518578  Void          updataRCUnitStatus    ();
    519579  Void          updateLCUData         (TComDataCU* pcCU, UInt64 actualLCUBits, Int qp);
     580#if KWU_RC_MADPRED_E0227
     581  Void          updateLCUDataEnhancedView(TComDataCU* pcCU, UInt64 uiBits, Int qp, Double basePos, Double curPos, Double focalLen, Double znear, Double zfar, Int direction);
     582#endif
    520583  Void          updateFrameData       (UInt64 actualFrameBits);
    521584  Double        xAdjustmentBits       (Int& reductionBits, Int& compensationBits);
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r622 r655  
    9595#if H_3D_DIM_DMM
    9696, m_cDmm1DataSCModel          ( 1,             1,               NUM_DMM1_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    97 #if !SEC_DMM2_E0146_HHIFIX
    98 , m_cDmm2DataSCModel          ( 1,             1,               NUM_DMM2_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    99 #endif
    10097, m_cDmm3DataSCModel          ( 1,             1,               NUM_DMM3_DATA_CTX             , m_contextModels + m_numContextModels, m_numContextModels)
    10198#endif
     
    108105#endif
    109106#endif
    110 #if LGE_INTER_SDC_E0156
     107#if H_3D_INTER_SDC
    111108, m_cInterSDCFlagSCModel             ( 1,             1,  NUM_INTER_SDC_FLAG_CTX           , m_contextModels + m_numContextModels, m_numContextModels)
    112109, m_cInterSDCResidualSCModel         ( 1,             1,  NUM_INTER_SDC_RESIDUAL_CTX       , m_contextModels + m_numContextModels, m_numContextModels)
     
    177174#if H_3D_DIM_DMM
    178175  m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
    179 #if !SEC_DMM2_E0146_HHIFIX
    180   m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
    181 #endif
    182176  m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
    183177#endif
     
    190184#endif
    191185#endif
    192 #if LGE_INTER_SDC_E0156
     186#if H_3D_INTER_SDC
    193187  m_cInterSDCFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_FLAG );
    194188  m_cInterSDCResidualSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_RESIDUAL );
     
    232226      curCost += m_cCUICFlagSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_IC_FLAG );
    233227#endif
    234 #if LGE_INTER_SDC_E0156
     228#if H_3D_INTER_SDC
    235229      curCost += m_cInterSDCFlagSCModel.calcCost      ( curSliceType, qp, (UChar*)INIT_INTER_SDC_FLAG );
    236230      curCost += m_cInterSDCResidualSCModel.calcCost  ( curSliceType, qp, (UChar*)INIT_INTER_SDC_RESIDUAL );
     
    268262#if H_3D_DIM_DMM
    269263      curCost += m_cDmm1DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM1_DATA );
    270 #if !SEC_DMM2_E0146_HHIFIX
    271       curCost += m_cDmm2DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM2_DATA );
    272 #endif
    273264      curCost += m_cDmm3DataSCModel.calcCost          ( curSliceType, qp, (UChar*)INIT_DMM3_DATA );
    274265#endif
     
    340331#if H_3D_DIM_DMM
    341332  m_cDmm1DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM1_DATA );
    342 #if !SEC_DMM2_E0146_HHIFIX
    343   m_cDmm2DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM2_DATA );
    344 #endif
    345333  m_cDmm3DataSCModel.initBuffer          ( eSliceType, iQp, (UChar*)INIT_DMM3_DATA );
    346334#endif
     
    353341#endif
    354342#endif
    355 #if LGE_INTER_SDC_E0156
     343#if H_3D_INTER_SDC
    356344  m_cInterSDCFlagSCModel.initBuffer         ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_FLAG );
    357345  m_cInterSDCResidualSCModel.initBuffer     ( eSliceType, iQp, (UChar*)INIT_INTER_SDC_RESIDUAL );
     
    548536  }
    549537}
    550 
    551 #if !SEC_DMM2_E0146_HHIFIX
    552 Void TEncSbac::xCodeDmm2Offset( Int iOffset )
    553 {
    554   if( DMM2_DELTAEND_MAX > 0 )
    555   {
    556     m_pcBinIf->encodeBin( (iOffset != 0) , m_cDmm2DataSCModel.get(0, 0, 0) );
    557     if( iOffset != 0 )
    558     {
    559       UInt uiAbsValMinus1 = abs(iOffset)-1;
    560       m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x01),      m_cDmm2DataSCModel.get(0, 0, 0) );
    561       m_pcBinIf->encodeBin( (uiAbsValMinus1 & 0x02) >> 1, m_cDmm2DataSCModel.get(0, 0, 0) );
    562 
    563       UInt uiSign = (iOffset > 0) ? 0 : 1;
    564       m_pcBinIf->encodeBinEP( uiSign );
    565     }
    566   }
    567 }
    568 #endif
    569538
    570539Void TEncSbac::xCodeDmm3WedgeIdx( UInt uiIntraIdx, Int iNumBit )
     
    12401209      xCodeDmm1WedgeIdx( pcCU->getDmmWedgeTabIdx( dimType, absPartIdx ), g_dmm1TabIdxBits[pcCU->getIntraSizeIdx(absPartIdx)] );
    12411210    } break;
    1242 #if !SEC_DMM2_E0146_HHIFIX
    1243   case( DMM2_IDX ):
    1244     {
    1245       xCodeDmm2Offset( pcCU->getDmm2DeltaEnd( absPartIdx ) );
    1246     } break;
    1247 #endif
    12481211  case( DMM3_IDX ):
    12491212    {
     
    12941257Void TEncSbac::codeIntraDepthMode( TComDataCU* pcCU, UInt absPartIdx )
    12951258{
    1296 #if ZJU_DEPTH_INTRA_MODE_E0204
    12971259    UInt codeWordTable[3][7] =    {{0, 0, 0, 2, 0,6, 7},{0, 0, 2, 7, 3, 6, 2},{0, 1, 0, 0, 0, 0, 0}};
    12981260    UInt codeWordLenTable[3][7] = {{0, 1, 0, 2, 0,3, 3},{1, 1, 2, 3, 2, 3, 2},{1, 1, 0, 0, 0, 0, 0}};
    1299 #else
    1300 #if LGE_SDC_REMOVE_DC_E0158
    1301 #if SEC_DMM2_E0146_HHIFIX
    1302   UInt codeWordTable[3][7] =    {{0, 0, 0, 2, 0,6, 7},{0, 2, 3, 4, 5, 6, 7},{0, 1, 0, 0, 0, 0, 0}};
    1303   UInt codeWordLenTable[3][7] = {{0, 1, 0, 2, 0,3, 3},{2, 3, 3, 3, 3, 3, 3},{1, 1, 0, 0, 0, 0, 0}};
    1304 #else
    1305   UInt codeWordTable[3][8] =    { { 0, 0, 0, 2, 0, 6, 0, 7 }, { 0, 2, 3, 4, 5, 6, 15, 14 }, { 0, 1, 0, 0, 0, 0, 0, 0 } };
    1306   UInt codeWordLenTable[3][8] = { { 0, 1, 0, 2, 0, 3, 0, 3 }, { 2, 3, 3, 3, 3, 3,  4,  4 }, { 1, 1, 0, 0, 0, 0, 0, 0 } };
    1307 #endif
    1308 #else
    1309 #if SEC_DMM2_E0146_HHIFIX
    1310   UInt codeWordTable[3][8] =    {{0, 0, 0, 2, 0,6, 0, 7},{0, 2, 3, 4, 5, 6, 14, 15},{0, 2, 0, 0, 0, 0, 3, 0}};
    1311   UInt codeWordLenTable[3][8] = {{0, 1, 0, 2, 0,3, 0, 3},{2, 3, 3, 3, 3, 3,  4,  4},{1, 2, 0, 0, 0, 0, 2, 0}};
    1312 #else
    1313   UInt codeWordTable[3][9] =    {{0, 0, 0, 2, 0,6, 0, 0, 7},{0, 2, 3, 4, 5, 6, 14, 31, 30},{0, 2, 0, 0, 0, 0, 3, 0, 0}};
    1314   UInt codeWordLenTable[3][9] = {{0, 1, 0, 2, 0,3, 0, 0, 3},{2, 3, 3, 3, 3, 3,  4,  5,  5},{1, 2, 0, 0, 0, 0, 2, 0, 0}};
    1315 #endif
    1316 #endif
    1317 #endif
    13181261  UInt dir = pcCU->getLumaIntraDir( absPartIdx );
    13191262  UInt puIdx = (pcCU->getWidth(absPartIdx) == 64) ? 2 : ( (pcCU->getPartitionSize(absPartIdx) == SIZE_NxN && pcCU->getWidth(absPartIdx) == 8) ? 0 : 1 );
     
    13311274    case DMM4_IDX: codeIdx = 4; break;
    13321275    case DMM3_IDX: codeIdx = 5; break;
    1333 #if LGE_SDC_REMOVE_DC_E0158
    1334 #if SEC_DMM2_E0146_HHIFIX
    13351276    case  RBC_IDX: codeIdx = 6; break;
    1336 #else
    1337     case DMM2_IDX: codeIdx = 6; break;
    1338     case  RBC_IDX: codeIdx = 7; break;
    1339 #endif
    1340 #else
    1341 #if SEC_DMM2_E0146_HHIFIX
    1342     case  RBC_IDX: codeIdx = 7; break;
    1343 #else
    1344     case DMM2_IDX: codeIdx = 7; break;
    1345     case  RBC_IDX: codeIdx = 8; break;
    1346 #endif
    1347 #endif
    13481277    default:                    break;
    13491278    }
     
    13561285    {
    13571286      case PLANAR_IDX:  codeIdx = 0; break;
    1358 #if !LGE_SDC_REMOVE_DC_E0158
    1359       case DC_IDX:      codeIdx = 6; break;
    1360 #endif
    13611287      default:          codeIdx = 2; break;
    13621288    }
    13631289  }
    13641290#endif
    1365 #if ZJU_DEPTH_INTRA_MODE_E0204
    13661291  if( puIdx==1 )
    13671292  {
     
    13751300      }
    13761301  }
    1377 #endif
    13781302  //mode coding
    13791303  for( UInt i = 0; i < codeWordLenTable[puIdx][codeIdx]; i++ )
     
    23042228}
    23052229
    2306 #if LGE_INTER_SDC_E0156
     2230#if H_3D_INTER_SDC
    23072231Void TEncSbac::codeInterSDCFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
    23082232{
  • trunk/source/Lib/TLibEncoder/TEncSbac.h

    r622 r655  
    121121#if H_3D_DIM_DMM
    122122  Void  xCodeDmm1WedgeIdx    ( UInt uiTabIdx, Int iNumBit );
    123 #if !SEC_DMM2_E0146_HHIFIX
    124   Void  xCodeDmm2Offset      ( Int iOffset );
    125 #endif
    126123  Void  xCodeDmm3WedgeIdx    ( UInt uiIntraIdx, Int iNumBit );
    127124#endif
     
    160157  Void codeICFlag        ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    161158#endif
    162 #if LGE_INTER_SDC_E0156
     159#if H_3D_INTER_SDC
    163160  Void codeInterSDCFlag  ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    164161  Void codeInterSDCResidualData  ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiSegment );
     
    256253#if H_3D_DIM_DMM
    257254  ContextModel3DBuffer m_cDmm1DataSCModel;
    258 #if !SEC_DMM2_E0146_HHIFIX
    259   ContextModel3DBuffer m_cDmm2DataSCModel;
    260 #endif
    261255  ContextModel3DBuffer m_cDmm3DataSCModel;
    262256#endif
     
    269263#endif
    270264#endif
    271 #if LGE_INTER_SDC_E0156
     265#if H_3D_INTER_SDC
    272266  ContextModel3DBuffer m_cInterSDCFlagSCModel;
    273267  ContextModel3DBuffer m_cInterSDCResidualSCModel;
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r622 r655  
    4141#include "TEncSearch.h"
    4242#include <math.h>
    43 #if LGE_INTER_SDC_E0156
     43#if H_3D_INTER_SDC
    4444#include <memory.h>
    4545#endif
     
    323323  m_cDistParam.bUseIC = pcPatternKey->getICFlag();
    324324#endif
    325 #if LGE_INTER_SDC_E0156
     325#if H_3D_INTER_SDC
    326326  m_cDistParam.bUseSDCMRSAD = pcPatternKey->getSDCMRSADFlag();
    327327#endif
     
    755755    m_cDistParam.bUseIC = pcPatternKey->getICFlag();
    756756#endif
    757 #if LGE_INTER_SDC_E0156
     757#if H_3D_INTER_SDC
    758758    m_cDistParam.bUseSDCMRSAD = pcPatternKey->getSDCMRSADFlag();
    759759#endif
     
    19001900  // get DC prediction for each segment
    19011901  Pel apDCPredValues[2];
    1902 #if KWU_SDC_SIMPLE_DC_E0117
    19031902  analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode );
    1904 #else
    1905   analyzeSegmentsSDC(piPred, uiStride, uiWidth, apDCPredValues, uiNumSegments, pbMask, uiMaskStride );
    1906 #endif
    19071903 
    19081904  // get original DC for each segment
    19091905  Pel apDCOrigValues[2];
    1910 #if KWU_SDC_SIMPLE_DC_E0117
    19111906  analyzeSegmentsSDC(piOrg, uiStride, uiWidth, apDCOrigValues, uiNumSegments, pbMask, uiMaskStride, uiLumaPredMode, true );
    1912 #else
    1913   analyzeSegmentsSDC(piOrg, uiStride, uiWidth, apDCOrigValues, uiNumSegments, pbMask, uiMaskStride );
    1914 #endif
    19151907 
    19161908  for( UInt uiSegment = 0; uiSegment < uiNumSegments; uiSegment++ )
     
    28512843    {
    28522844
    2853 #if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
     2845#if H_3D_FAST_DEPTH_INTRA
    28542846      Int  threshold    = max(((pcCU->getQP(0))>>3)-1,3);
    28552847      Int  varThreshold = (Int)( threshold * threshold - 8 );
     
    28592851#if H_3D_DIM_DMM
    28602852      if( m_pcEncCfg->getUseDMM()
    2861 #if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
     2853#if H_3D_FAST_DEPTH_INTRA
    28622854         && (uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold)
    28632855#endif
     
    28662858        for( UInt dmmType = 0; dmmType < DMM_NUM_TYPE; dmmType++ )
    28672859        {
     2860#if H_3D_FCO
     2861            TComPic* picTexture  = pcCU->getSlice()->getIvPic(false, pcCU->getSlice()->getViewIndex() );
     2862            if ( !picTexture->getReconMark() && (DMM3_IDX == dmmType || DMM4_IDX == dmmType ) )
     2863            {
     2864                continue;
     2865            }
     2866#endif
    28682867          UInt uiTabIdx = 0;
    28692868          TComWedgelet* biSegmentation = NULL;
     
    28772876              biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
    28782877            } break;
    2879 #if !SEC_DMM2_E0146_HHIFIX
    2880           case( DMM2_IDX ):
    2881             {
    2882               if( uiWidth > 4 )
    2883               {
    2884                 Int dmm2DeltaEnd = 0;
    2885                 xSearchDmm2Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, dmm2DeltaEnd );
    2886                 pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth );
    2887                 pcCU->setDmm2DeltaEndSubParts( dmm2DeltaEnd, uiPartOffset, uiDepth + uiInitTrDepth );
    2888                 biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
    2889               }
    2890             } break;
    2891 #endif
    28922878          case( DMM3_IDX ):
    28932879            {
    2894 #if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
     2880
    28952881              TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
    28962882              TComDataCU* pcColTexCU = pcPicTex->getCU( pcCU->getAddr() );
     
    29002886              if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 )
    29012887              {
    2902 #endif
    2903               UInt uiIntraTabIdx = 0;
    2904 #if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
     2888             UInt uiIntraTabIdx = 0;
    29052889              xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx, uiColTexIntraDir );
    2906 #else
    2907               xSearchDmm3Wedge( pcCU, uiPartOffset, piOrg, uiStride, uiWidth, uiHeight, uiTabIdx, uiIntraTabIdx );
    2908 #endif
    29092890              pcCU->setDmmWedgeTabIdxSubParts( uiTabIdx, dmmType, uiPartOffset, uiDepth + uiInitTrDepth );
    29102891              pcCU->setDmm3IntraTabIdxSubParts( uiIntraTabIdx, uiPartOffset, uiDepth + uiInitTrDepth );
    29112892              biSegmentation = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiTabIdx]);
    2912 #if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
    29132893              }
    2914 #endif
    29152894            } break;
    29162895          case( DMM4_IDX ):
     
    29412920#if H_3D_DIM_RBC
    29422921      if( m_pcEncCfg->getUseRBC()
    2943 #if SCU_HS_FAST_DEPTH_INTRA_E0238_HHIFIX
     2922#if H_3D_FAST_DEPTH_INTRA
    29442923          && (uiRdModeList[0] != PLANAR_IDX || varCU >= varThreshold)
    29452924#endif
     
    35813560  cDistParam.bUseIC = false;
    35823561#endif
    3583 #if LGE_INTER_SDC_E0156
     3562#if H_3D_INTER_SDC
    35843563  cDistParam.bUseSDCMRSAD = false;
    35853564#endif
     
    37243703 */
    37253704#if AMP_MRG
    3726 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     3705#if  H_3D_FAST_TEXTURE_ENCODING
    37273706Void TEncSearch::predInterSearch( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, Bool bFMD, Bool bUseRes, Bool bUseMRG )
    37283707#else
     
    38363815#if AMP_MRG
    38373816    Bool bTestNormalMC = true;
    3838 #if  MTK_FAST_TEXTURE_ENCODING_E0173
     3817#if  H_3D_FAST_TEXTURE_ENCODING
    38393818    if (bFMD||( bUseMRG && pcCU->getWidth( 0 ) > 8 && iNumPart == 2 ))
    38403819#else           
     
    47064685  pcPatternKey->setICFlag( bICFlag );
    47074686#endif
    4708 #if LGE_INTER_SDC_E0156
     4687#if H_3D_INTER_SDC
    47094688  if ( pcCU->getSlice()->getIsDepth() && pcCU->getSlice()->getVPS()->getInterSDCFlag( pcCU->getSlice()->getLayerIdInVps() ) )
    47104689  {
     
    48624841      m_cDistParam.bUseIC = pcPatternKey->getICFlag();
    48634842#endif
    4864 #if LGE_INTER_SDC_E0156
     4843#if H_3D_INTER_SDC
    48654844      m_cDistParam.bUseSDCMRSAD = pcPatternKey->getSDCMRSADFlag();
    48664845#endif
     
    54715450}
    54725451
    5473 #if LGE_INTER_SDC_E0156
     5452#if H_3D_INTER_SDC
    54745453Void TEncSearch::encodeResAndCalcRdInterSDCCU( TComDataCU* pcCU, TComYuv* pcOrg, TComYuv* pcPred, TComYuv* pcResi, TComYuv* pcRec, const UInt uiDepth )
    54755454{
     
    67946773    m_pcEntropyCoder->encodeARPW( pcCU , 0 );
    67956774#endif
    6796 #if LGE_INTER_SDC_E0156
     6775#if H_3D_INTER_SDC
    67976776    m_pcEntropyCoder->encodeInterSDCFlag( pcCU, 0, true );
    67986777#endif
     
    70457024}
    70467025
     7026#if H_3D_DIM
    70477027  // -------------------------------------------------------------------------------------------------------------------
    70487028  // Depth intra search
    70497029  // -------------------------------------------------------------------------------------------------------------------
    7050 #if H_3D_DIM
    70517030Void TEncSearch::xCalcBiSegDCs( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 )
    70527031{
     
    73217300}
    73227301
    7323 #if !SEC_DMM2_E0146_HHIFIX
    7324 Void TEncSearch::xSearchDmm2Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd )
    7325 {
    7326   ruiTabIdx       = 0;
    7327   riWedgeDeltaEnd = 0;
    7328 
    7329   // local pred buffer
    7330   TComYuv cPredYuv;
    7331   cPredYuv.create( uiWidth, uiHeight );
    7332   cPredYuv.clear();
    7333 
    7334   UInt uiPredStride = cPredYuv.getStride();
    7335   Pel* piPred       = cPredYuv.getLumaAddr();
    7336 
    7337 
    7338   // regular wedge search
    7339   Dist uiBestDist    = RDO_DIST_MAX;
    7340   UInt uiBestTabIdx  = 0;
    7341   Int  iBestDeltaEnd = 0;
    7342 
    7343   UInt uiIdx = 0;
    7344   Pel refDC1 = 0; Pel refDC2 = 0;
    7345   for( Int iTestDeltaEnd = -DMM2_DELTAEND_MAX; iTestDeltaEnd <= DMM2_DELTAEND_MAX; iTestDeltaEnd++ )
    7346   {
    7347     uiIdx = xPredWedgeFromIntra( pcCU, uiAbsPtIdx, uiWidth, uiHeight, iTestDeltaEnd );
    7348     TComWedgelet* pcWedgelet = &(g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])][uiIdx]);
    7349     xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
    7350     xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
    7351 
    7352     Dist uiActDist = RDO_DIST_MAX;
    7353 #if H_3D_VSO
    7354     if( m_pcRdCost->getUseVSO() )
    7355     {
    7356       if( m_pcRdCost->getUseEstimatedVSD() )
    7357       {
    7358         uiActDist = m_pcRdCost->getDistPartVSD( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
    7359       }
    7360       else
    7361       {
    7362         uiActDist = m_pcRdCost->getDistPartVSO( pcCU, uiAbsPtIdx, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, false );
    7363       }
    7364     }
    7365     else
    7366 #endif
    7367     {
    7368       uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
    7369     }
    7370 
    7371     if( uiActDist < uiBestDist || uiBestDist == RDO_DIST_MAX )
    7372     {
    7373       uiBestDist    = uiActDist;
    7374       uiBestTabIdx  = uiIdx;
    7375       iBestDeltaEnd = iTestDeltaEnd;
    7376     }
    7377     else if( uiIdx == uiBestTabIdx && abs(iTestDeltaEnd) < abs(iBestDeltaEnd) )
    7378     {
    7379       iBestDeltaEnd = iTestDeltaEnd;
    7380     }
    7381   }
    7382 
    7383   ruiTabIdx       = uiBestTabIdx;
    7384   riWedgeDeltaEnd = iBestDeltaEnd;
    7385 
    7386   cPredYuv.destroy();
    7387   return;
    7388 }
    7389 #endif
    7390 
    7391 #if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
    73927302Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx, UInt colTexIntraDir )
    73937303{
     
    74267336  cPredYuv.destroy();
    74277337}
    7428 #else
    7429 Void TEncSearch::xSearchDmm3Wedge( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx )
    7430 {
    7431   ruiTabIdx       = 0;
    7432   ruiIntraTabIdx  = 0;
    7433 
    7434   // local pred buffer
    7435   TComYuv cPredYuv;
    7436   cPredYuv.create( uiWidth, uiHeight );
    7437   cPredYuv.clear();
    7438   Pel* piPred = cPredYuv.getLumaAddr();
    7439   UInt uiPredStride = cPredYuv.getStride();
    7440 
    7441   // wedge search
    7442   UInt uiBestDist = MAX_UINT;
    7443   WedgeList* pacWedgeList = &g_dmmWedgeLists[(g_aucConvertToBit[uiWidth])];
    7444   Pel refDC1 = 0; Pel refDC2 = 0;
    7445 
    7446   TComPic*      pcPicTex = pcCU->getSlice()->getTexturePic();
    7447   assert( pcPicTex != NULL );
    7448   TComDataCU* pcColTexCU = pcPicTex->getCU(pcCU->getAddr());
    7449   UInt      uiTexPartIdx = pcCU->getZorderIdxInCU() + uiAbsPtIdx;
    7450   Int   uiColTexIntraDir = pcColTexCU->isIntra( uiTexPartIdx ) ? pcColTexCU->getLumaIntraDir( uiTexPartIdx ) : 255;
    7451 
    7452   std::vector< std::vector<UInt> > pauiWdgLstSz = g_aauiWdgLstM3[g_aucConvertToBit[uiWidth]];
    7453   if( uiColTexIntraDir > DC_IDX && uiColTexIntraDir < 35 )
    7454   {
    7455     std::vector<UInt>* pauiWdgLst = &pauiWdgLstSz[uiColTexIntraDir-2];
    7456     for( UInt uiIdxW = 0; uiIdxW < pauiWdgLst->size(); uiIdxW++ )
    7457     {
    7458       UInt uiIdx     =   pauiWdgLst->at(uiIdxW);
    7459       TComWedgelet* pcWedgelet = &(pacWedgeList->at(uiIdx));
    7460       xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
    7461       xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
    7462 
    7463       UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
    7464       if( uiActDist < uiBestDist || uiBestDist == MAX_UINT )
    7465       {
    7466         uiBestDist     = uiActDist;
    7467         ruiTabIdx      = uiIdx;
    7468         ruiIntraTabIdx = uiIdxW;
    7469       }
    7470     }
    7471   }
    7472   else
    7473   {
    7474     WedgeNodeList* pacWedgeNodeList = &g_dmmWedgeNodeLists[(g_aucConvertToBit[uiWidth])];
    7475     UInt uiBestNodeDist = MAX_UINT;
    7476     UInt uiBestNodeId   = 0;
    7477     for( UInt uiNodeId = 0; uiNodeId < pacWedgeNodeList->size(); uiNodeId++ )
    7478     {
    7479       TComWedgelet* pcWedgelet = &(pacWedgeList->at(pacWedgeNodeList->at(uiNodeId).getPatternIdx()));
    7480       xCalcBiSegDCs  ( piRef,  uiRefStride,  pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
    7481       xAssignBiSegDCs( piPred, uiPredStride, pcWedgelet->getPattern(), pcWedgelet->getStride(), refDC1, refDC2 );
    7482 
    7483       UInt uiActDist = m_pcRdCost->getDistPart( g_bitDepthY, piPred, uiPredStride, piRef, uiRefStride, uiWidth, uiHeight, TEXT_LUMA, DF_SAD );
    7484       if( uiActDist < uiBestNodeDist || uiBestNodeDist == MAX_UINT )
    7485       {
    7486         uiBestNodeDist = uiActDist;
    7487         uiBestNodeId   = uiNodeId;
    7488         ruiIntraTabIdx = uiNodeId;
    7489       }
    7490     }
    7491     ruiTabIdx = pacWedgeNodeList->at(uiBestNodeId).getPatternIdx();
    7492   }
    7493 
    7494   cPredYuv.destroy();
    7495 }
    7496 #endif
     7338
    74977339#endif
    74987340#if H_3D_DIM_RBC
  • trunk/source/Lib/TLibEncoder/TEncSearch.h

    r622 r655  
    196196                                  TComYuv*&   rpcResiYuv,
    197197                                  TComYuv*&   rpcRecoYuv,
    198 #if MTK_FAST_TEXTURE_ENCODING_E0173
     198#if H_3D_FAST_TEXTURE_ENCODING
    199199                                  Bool        bFMD,
    200200#endif
     
    213213                                  TComYuv*&   rpcYuvRec,
    214214                                  Bool        bSkipRes );
    215 #if LGE_INTER_SDC_E0156
     215#if H_3D_INTER_SDC
    216216  Void encodeResAndCalcRdInterSDCCU( TComDataCU* pcCU,
    217217    TComYuv* pcOrg,
     
    343343                                    UInt         stateU0V1Both2 );
    344344
    345 
     345#if H_3D_DIM
    346346  // -------------------------------------------------------------------------------------------------------------------
    347347  // Depth intra search
    348348  // -------------------------------------------------------------------------------------------------------------------
    349 #if H_3D_DIM
    350349  Void xCalcBiSegDCs              ( Pel* ptrSrc, UInt srcStride, Bool* biSegPattern, Int patternStride, Pel& valDC1, Pel& valDC2 );
    351350#if H_3D_DIM_DMM
    352351  Void xSearchDmmDeltaDCs         ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piOrig, Pel* piPredic, UInt uiStride, Bool* biSegPattern, Int patternStride, UInt uiWidth, UInt uiHeight, Pel& rDeltaDC1, Pel& rDeltaDC2 );
    353352  Void xSearchDmm1Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx );
    354 #if !SEC_DMM2_E0146_HHIFIX
    355   Void xSearchDmm2Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, Int& riWedgeDeltaEnd );
    356 #endif
    357 #if LGE_PKU_DMM3_OVERLAP_E0159_HHIFIX
    358353  Void xSearchDmm3Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx, UInt colTexIntraDir );
    359 #else
    360   Void xSearchDmm3Wedge           ( TComDataCU* pcCU, UInt uiAbsPtIdx, Pel* piRef, UInt uiRefStride, UInt uiWidth, UInt uiHeight, UInt& ruiTabIdx, UInt& ruiIntraTabIdx );
    361 #endif
    362354#endif
    363355#if H_3D_DIM_RBC
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r622 r655  
    157157  m_pdRdPicQp         = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
    158158  m_piRdPicQp         = (Int*   )xMalloc( Int,    m_pcCfg->getDeltaQpRD() * 2 + 1 );
     159#if KWU_RC_MADPRED_E0227
     160  if(m_pcCfg->getUseRateCtrl())
     161  {
     162    m_pcRateCtrl        = pcEncTop->getRateCtrl();
     163  }
     164  else
     165  {
     166    m_pcRateCtrl        = NULL;
     167  }
     168#else
    159169  m_pcRateCtrl        = pcEncTop->getRateCtrl();
     170#endif
    160171}
    161172
     
    176187 \param pPPS          PPS associated with the slice
    177188 */
    178 #if H_MV5
    179189#if H_MV
    180 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId )
    181 #else
    182 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
    183 #endif
    184 #else
    185 #if H_3D
    186 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId )
    187 #else
    188 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
    189 #endif
     190Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId, bool isField )
     191#else
     192Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, bool isField )
    190193#endif
    191194{
     
    195198  rpcSlice = pcPic->getSlice(0);
    196199
    197 #if H_MV5
     200#if H_MV
    198201  rpcSlice->setVPS( pVPS );
    199202
     
    203206#if H_3D
    204207  rpcSlice->setIsDepth     ( pVPS->getDepthId     ( layerId ) != 0 );   
    205 #endif
    206 #else
    207 #if H_3D
    208   // GT: Should also be activated for MV-HEVC at some stage
    209   rpcSlice->setVPS( pVPS );
    210   Int vpsLayerId = pVPS->getLayerIdInNuh( layerId );
    211 
    212   rpcSlice->setLayerId     ( layerId );
    213   rpcSlice->setViewId      ( pVPS->getViewId      ( vpsLayerId ) );   
    214   rpcSlice->setViewIndex   ( pVPS->getViewIndex   ( vpsLayerId ) );
    215   rpcSlice->setIsDepth     ( pVPS->getDepthId     ( vpsLayerId ) != 0 );   
    216208#endif
    217209#endif
     
    342334    Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    343335    Int    SHIFT_QP = 12;
    344     Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
     336    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
    345337#if FULL_NBIT
    346338    Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
     
    11251117    if(m_pcCfg->getUseRateCtrl())
    11261118    {
     1119#if KWU_RC_MADPRED_E0227
     1120      if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
     1121      {
     1122        Double zn, zf, focallength, position, camshift;
     1123        Double basepos;
     1124        Bool bInterpolated;
     1125        Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
     1126
     1127        pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);
     1128        pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basepos, camshift, bInterpolated);
     1129        pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camshift, bInterpolated);
     1130
     1131        m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), basepos, position, focallength, zn, zf, (direction > 0 ? 1 : -1));
     1132      }
     1133#endif
    11271134      if(m_pcRateCtrl->calculateUnitQP())
    11281135      {
     
    12231230        else
    12241231        {
     1232#if KWU_RC_MADPRED_E0227
     1233          if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())
     1234          {
     1235            Double zn, zf, focallength, position, camShift;
     1236            Double basePos;
     1237            Bool bInterpolated;
     1238            Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();
     1239            Int disparity;
     1240
     1241            pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);
     1242            pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basePos, camShift, bInterpolated);
     1243            pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camShift, bInterpolated);
     1244            bpp       = m_pcRateCtrl->getRCPic()->getLCUTargetBppforInterView( m_pcRateCtrl->getPicList(), pcCU,
     1245              basePos, position, focallength, zn, zf, (direction > 0 ? 1 : -1), &disparity );
     1246          }
     1247          else
     1248          {
     1249#endif
    12251250#if RATE_CONTROL_INTRA
    12261251          bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType());
     
    12391264          estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
    12401265#endif
    1241 
     1266#if KWU_RC_MADPRED_E0227
     1267          }
     1268#endif
     1269#if KWU_RC_MADPRED_E0227
     1270          estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );
     1271          estQP     = m_pcRateCtrl->getRCPic()->getLCUEstQP    ( estLambda, pcSlice->getSliceQp() );
     1272#endif
    12421273          estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
    12431274
     
    13431374      if ( m_pcCfg->getUseRateCtrl() )
    13441375      {
    1345 #if !M0036_RC_IMPROVEMENT
     1376#if !M0036_RC_IMPROVEMENT || KWU_RC_MADPRED_E0227
    13461377        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
    13471378        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r622 r655  
    116116 
    117117  /// preparation of slice encoding (reference marking, QP and lambda)
    118 #if H_MV5
    119118#if H_MV
    120119  Void    initEncSlice        ( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
    121                                 Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId );
     120                                Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId, bool isField );
    122121#else
    123122  Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
    124                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
    125 #endif
    126 #else
    127 #if H_3D
    128   Void    initEncSlice        ( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
    129                                 Int iGOPid, TComSlice*& rpcSlice, TComVPS* pVPS, TComSPS* pSPS, TComPPS *pPPS, Int layerId );
    130 #else
    131   Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
    132                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
    133 #endif
     123                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, bool isField  );
    134124#endif
    135125#if RATE_CONTROL_LAMBDA_DOMAIN
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r622 r655  
    123123  if ( m_RCEnableRateControl )
    124124  {
     125#if KWU_RC_MADPRED_E0227
     126    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
     127      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList, getLayerId() );
     128#else
    125129    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
    126130                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
     131#endif
    127132  }
    128133#else
    129   m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
     134#if KWU_FIX_URQ
     135  if(m_enableRateCtrl)
     136#endif
     137    m_cRateCtrl.create(getIntraPeriod(), getGOPSize(), getFrameRate(), getTargetBitrate(), getQP(), getNumLCUInUnit(), getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight);
    130138#endif
    131139  // if SBAC-based RD optimization is used
     
    284292}
    285293
    286 Void TEncTop::init()
     294#if KWU_RC_MADPRED_E0227
     295Void TEncTop::init(TAppEncTop* pcTAppEncTop, Bool isFieldCoding)
     296#else
     297Void TEncTop::init(Bool isFieldCoding)
     298#endif
    287299{
    288300  // initialize SPS
     
    301313  m_cPPS.setSPS(&m_cSPS);
    302314  xInitPPS();
    303   xInitRPS();
     315  xInitRPS(isFieldCoding);
    304316
    305317  xInitPPSforTiles();
     
    310322  m_cCuEncoder.   init( this );
    311323 
     324#if KWU_RC_MADPRED_E0227
     325  m_pcTAppEncTop = pcTAppEncTop;
     326#endif
    312327  // initialize transform & quantization class
    313328  m_pcCavlcCoder = getCavlcCoder();
     
    392407  if( picLastCoded )
    393408  {
    394 #if MTK_SONY_PROGRESSIVE_MV_COMPRESSION_E0170
    395409    picLastCoded->compressMotion(1);
    396 #else
    397     picLastCoded->compressMotion();
    398 #endif
    399410  }
    400411#endif
     
    433444#if H_MV
    434445  }
    435   m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId );
     446  m_cGOPEncoder.compressPicInGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, gopId, false, false );
    436447
    437448  if( gopId + 1 == m_cGOPEncoder.getGOPSize() )
     
    439450#else
    440451  // compress GOP
    441   m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
     452  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    442453#endif
    443454
     
    456467#endif
    457468}
     469/**------------------------------------------------
     470 Separate interlaced frame into two fields
     471 -------------------------------------------------**/
     472void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, bool isTop)
     473{
     474  if (!isTop)
     475  {
     476    org += stride;
     477  }
     478  for (Int y = 0; y < height>>1; y++)
     479  {
     480    for (Int x = 0; x < width; x++)
     481    {
     482      dstField[x] = org[x];
     483    }
     484   
     485    dstField += stride;
     486    org += stride*2;
     487  }
     488 
     489}
     490
     491#if H_MV
     492Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff, Int gopId )
     493{
     494  assert( 0 ); // Field coding and multiview need to be furhter harmonized.
     495}
     496#else
     497Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff)
     498{
     499  /* -- TOP FIELD -- */
     500 
     501  if (pcPicYuvOrg)
     502  {
     503   
     504    /* -- Top field initialization -- */
     505   
     506    TComPic *pcTopField;
     507    xGetNewPicBuffer( pcTopField );
     508    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     509    pcTopField->setReconMark (false);
     510   
     511    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
     512    pcTopField->getPicYuvRec()->setBorderExtension(false);
     513    pcTopField->setTopField(isTff);
     514   
     515    int nHeight = pcPicYuvOrg->getHeight();
     516    int nWidth = pcPicYuvOrg->getWidth();
     517    int nStride = pcPicYuvOrg->getStride();
     518    int nPadLuma = pcPicYuvOrg->getLumaMargin();
     519    int nPadChroma = pcPicYuvOrg->getChromaMargin();
     520   
     521    // Get pointers
     522    Pel * PicBufY = pcPicYuvOrg->getBufY();
     523    Pel * PicBufU = pcPicYuvOrg->getBufU();
     524    Pel * PicBufV = pcPicYuvOrg->getBufV();
     525   
     526    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
     527    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
     528    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
     529   
     530    // compute image characteristics
     531    if ( getUseAdaptiveQP() )
     532    {
     533      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
     534    }
     535   
     536    /* -- Defield -- */
     537   
     538    bool isTop = isTff;
     539   
     540    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
     541    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     542    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     543   
     544  }
     545 
     546  if (m_iPOCLast == 0) // compress field 0
     547  {
     548    m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     549  }
     550 
     551  /* -- BOTTOM FIELD -- */
     552 
     553  if (pcPicYuvOrg)
     554  {
     555   
     556    /* -- Bottom field initialization -- */
     557   
     558    TComPic* pcBottomField;
     559    xGetNewPicBuffer( pcBottomField );
     560    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     561    pcBottomField->setReconMark (false);
     562   
     563    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
     564    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
     565    {
     566      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
     567    }
     568    else
     569    {
     570      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     571    }
     572    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
     573   
     574    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
     575    pcBottomField->getPicYuvRec()->setBorderExtension(false);
     576    pcBottomField->setTopField(!isTff);
     577   
     578    int nHeight = pcPicYuvOrg->getHeight();
     579    int nWidth = pcPicYuvOrg->getWidth();
     580    int nStride = pcPicYuvOrg->getStride();
     581    int nPadLuma = pcPicYuvOrg->getLumaMargin();
     582    int nPadChroma = pcPicYuvOrg->getChromaMargin();
     583   
     584    // Get pointers
     585    Pel * PicBufY = pcPicYuvOrg->getBufY();
     586    Pel * PicBufU = pcPicYuvOrg->getBufU();
     587    Pel * PicBufV = pcPicYuvOrg->getBufV();
     588   
     589    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
     590    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
     591    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
     592   
     593    // Compute image characteristics
     594    if ( getUseAdaptiveQP() )
     595    {
     596      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
     597    }
     598   
     599    /* -- Defield -- */
     600   
     601    bool isTop = !isTff;
     602   
     603    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
     604    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     605    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     606   
     607  }
     608 
     609  if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) )
     610  {
     611    iNumEncoded = 0;
     612    return;
     613  }
     614 
     615  // compress GOP
     616  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     617 
     618  iNumEncoded = m_iNumPicRcvd;
     619  m_iNumPicRcvd = 0;
     620  m_uiNumAllPicCoded += iNumEncoded;
     621}
     622#endif
     623
     624
    458625
    459626// ====================================================================================================================
     
    551718   * that chooses the actual compatibility based upon options */
    552719
    553 #if H_MV5
    554720#if H_MV 
    555721  m_cSPS.setUpdateRepFormatFlag           ( m_layerId == 0 );   
    556722  m_cSPS.setSpsInferScalingListFlag       ( m_layerId > 0 && m_cVPS->getInDirectDependencyFlag( getLayerIdInVps(), 0 ) );
    557723  m_cSPS.setSpsScalingListRefLayerId      ( 0              );
    558 #endif
    559724#endif
    560725  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
     
    680845{
    681846#if H_MV
    682 #if H_MV5
    683847  m_cPPS.setLayerId( getLayerId() );
    684848  if( getVPS()->getNumDirectRefLayers( getLayerId() ) > 0 )
    685 #else
    686   if( getVPS()->getNumDirectRefLayers( getLayerIdInVps() ) > 0 )
    687 #endif
    688849  {
    689850    m_cPPS.setListsModificationPresentFlag( true );
     
    734895#if RATE_CONTROL_LAMBDA_DOMAIN
    735896  if ( m_RCEnableRateControl )
     897  {
     898    m_cPPS.setUseDQP(true);
     899    m_cPPS.setMaxCuDQPDepth( 0 );
     900    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
     901  }
     902#endif
     903#if !RATE_CONTROL_LAMBDA_DOMAIN && KWU_FIX_URQ
     904  if ( m_enableRateCtrl )
    736905  {
    737906    m_cPPS.setUseDQP(true);
     
    751920  m_cPPS.setOutputFlagPresentFlag( false );
    752921#if H_MV
    753 #if H_MV5
    754922  m_cPPS.setNumExtraSliceHeaderBits( 2 );
    755 #else
    756   m_cPPS.setNumExtraSliceHeaderBits( 1 );
    757 #endif
    758923#endif
    759924  m_cPPS.setSignHideFlag(getSignHideFlag());
    760   m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
     925  if ( getDeblockingFilterMetric() )
     926  {
     927    m_cPPS.setDeblockingFilterControlPresentFlag (true);
     928    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
     929    m_cPPS.setPicDisableDeblockingFilterFlag(false);
     930    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
     931    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
     932  }
     933  else
     934  {
     935    m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
     936  }
    761937  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
    762938  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
     
    812988
    813989//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
    814 Void TEncTop::xInitRPS()
     990Void TEncTop::xInitRPS(Bool isFieldCoding)
    815991{
    816992  TComReferencePictureSet*      rps;
    817993 
    818   m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
     994  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1);
    819995  TComRPSList* rpsList = m_cSPS.getRPSList();
    820996
     
    9131089        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
    9141090        rps->setNumberOfNegativePictures(numNeg);
    915         rps->setNumberOfPositivePictures(numNeg+numPos);
     1091        rps->setNumberOfPictures(numNeg+numPos);
    9161092      }
    9171093      if (numPos != rps->getNumberOfPositivePictures())
     
    9191095        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
    9201096        rps->setNumberOfPositivePictures(numPos);
    921         rps->setNumberOfPositivePictures(numNeg+numPos);
     1097        rps->setNumberOfPictures(numNeg+numPos);
    9221098      }
    9231099      RPSTemp.setNumberOfPictures(numNeg+numPos);
     
    9831159#endif //INTER_RPS_AUTO
    9841160  }
    985  
     1161  //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file.
     1162  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
     1163  if (isFieldCoding)
     1164  {
     1165    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
     1166    rps->setNumberOfPictures(1);
     1167    rps->setNumberOfNegativePictures(1);
     1168    rps->setNumberOfPositivePictures(0);
     1169    rps->setNumberOfLongtermPictures(0);
     1170    rps->setDeltaPOC(0,-1);
     1171    rps->setPOC(0,0);
     1172    rps->setUsed(0,true);
     1173    rps->setInterRPSPrediction(false);
     1174    rps->setDeltaRIdxMinus1(0);
     1175    rps->setDeltaRPS(0);
     1176    rps->setNumRefIdc(0);
     1177}
    9861178}
    9871179
     
    10281220    }
    10291221  }
     1222  if(POCCurr == 1 && slice->getPic()->isField())
     1223  {
     1224    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
     1225  }
    10301226
    10311227  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
     
    11471343}
    11481344#if H_MV
    1149 Void TEncTop::printSummary( Int numAllPicCoded )
    1150 {
     1345Void TEncTop::printSummary( Int numAllPicCoded, Bool isField )
     1346{
     1347  assert ( !isField ); // Multiview and field coding need to be further unified
    11511348  assert (numAllPicCoded == m_cAnalyzeAll.getNumPic());
    11521349
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r608 r655  
    6464// ====================================================================================================================
    6565
     66#if KWU_RC_MADPRED_E0227
     67class TAppEncTop;
     68#endif
    6669/// encoder class
    6770class TEncTop : public TEncCfg
     
    124127  TComScalingList         m_scalingList;                 ///< quantization matrix information
    125128  TEncRateCtrl            m_cRateCtrl;                    ///< Rate control class
     129
     130#if KWU_RC_MADPRED_E0227
     131  TAppEncTop*             m_pcTAppEncTop;
     132  TAppComCamPara*         m_cCamParam;
     133#endif
    126134 
    127135#if H_MV
     
    137145 
    138146  Void  xInitPPSforTiles  ();
    139   Void  xInitRPS          ();                             ///< initialize PPS from encoder options
     147  Void  xInitRPS          (Bool isFieldCoding);           ///< initialize PPS from encoder options
    140148
    141149public:
     
    145153  Void      create          ();
    146154  Void      destroy         ();
    147   Void      init            ();
     155#if KWU_RC_MADPRED_E0227
     156  Void      init            ( TAppEncTop* pcTAppEncTop, Bool isFieldCoding );
     157#else
     158  Void      init            (Bool isFieldCoding);
     159#endif
     160
    148161#if H_MV 
    149162  TComPicLists* getIvPicLists() { return m_ivPicLists; }
     
    185198  TEncSbac*               getRDGoOnSbacCoders   () { return  m_pcRDGoOnSbacCoders;   }
    186199  TEncRateCtrl*           getRateCtrl           () { return &m_cRateCtrl;             }
     200#if KWU_RC_MADPRED_E0227
     201  TAppEncTop*             getEncTop             () { return m_pcTAppEncTop; }
     202  TAppComCamPara*         getCamParam()                 { return m_cCamParam;}
     203  Void                    setCamParam(TAppComCamPara * pCamparam)                 { m_cCamParam = pCamparam;}
     204#endif
    187205  TComSPS*                getSPS                () { return  &m_cSPS;                 }
    188206  TComPPS*                getPPS                () { return  &m_cPPS;                 }
     
    210228#if H_MV
    211229  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded  , Int gopId  ); 
     230
     231   /// encode several number of pictures until end-of-sequence
     232  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
     233              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff  , Int gopId );
     234
    212235#else
    213236  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
    214               std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); 
    215 #endif
    216 
    217 #if H_MV
    218   Void printSummary      ( Int numAllPicCoded );
    219 #else
    220   void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); }
     237              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );
     238   /// encode several number of pictures until end-of-sequence
     239  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
     240              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, bool isTff);
     241
     242#endif
     243
     244#if H_MV
     245  Void printSummary      ( Int numAllPicCoded, bool isField );
     246#else
     247  Void printSummary(bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField); }
    221248#endif
    222249
Note: See TracChangeset for help on using the changeset viewer.