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


Ignore:
Timestamp:
21 Oct 2013, 13:41:29 (11 years ago)
Author:
seregin
Message:

reintegrate SHM-3.1-dev branch

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/source

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

    r313 r442  
    9595    fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n");
    9696    break;
     97#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     98  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
     99    fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n");
     100    break;
     101#endif
    97102  case SEI::SCALABLE_NESTING:
    98103    fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n");
     
    153158    xWriteSEISOPDescription(*static_cast<const SEISOPDescription*>(&sei));
    154159    break;
     160#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     161  case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS:
     162    xWriteSEIInterLayerConstrainedTileSets(*static_cast<const SEIInterLayerConstrainedTileSets*>(&sei));
     163    break;
     164#endif
    155165  case SEI::SCALABLE_NESTING:
    156166    xWriteSEIScalableNesting(bs, *static_cast<const SEIScalableNesting*>(&sei), sps);
     
    559569}
    560570
     571#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     572Void SEIWriter::xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei)
     573{
     574  WRITE_FLAG( sei.m_ilAllTilesExactSampleValueMatchFlag,  "il_all_tiles_exact_sample_value_match_flag"   );
     575  WRITE_FLAG( sei.m_ilOneTilePerTileSetFlag,              "il_one_tile_per_tile_set_flag"                );
     576  if( !sei.m_ilOneTilePerTileSetFlag )
     577  {
     578    WRITE_UVLC( sei.m_ilNumSetsInMessageMinus1,             "il_num_sets_in_message_minus1"                );
     579    if( sei.m_ilNumSetsInMessageMinus1 )
     580    {
     581      WRITE_FLAG( sei.m_skippedTileSetPresentFlag,            "skipped_tile_set_present_flag"                );
     582    }
     583    UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1;
     584    for( UInt i = 0; i < numSignificantSets; i++ )
     585    {
     586      WRITE_UVLC( sei.m_ilctsId[i],                           "ilcts_id"                                     );
     587      WRITE_UVLC( sei.m_ilNumTileRectsInSetMinus1[i],         "il_num_tile_rects_in_set_minus1"              );
     588      for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ )
     589      {
     590        WRITE_UVLC( sei.m_ilTopLeftTileIndex[i][j],             "il_top_left_tile_index"                       );
     591        WRITE_UVLC( sei.m_ilBottomRightTileIndex[i][j],         "il_bottom_right_tile_index"                   );
     592      }
     593      WRITE_CODE( sei.m_ilcIdc[i], 2,                         "ilc_idc"                                      );
     594      if( sei.m_ilAllTilesExactSampleValueMatchFlag )
     595      {
     596        WRITE_FLAG( sei.m_ilExactSampleValueMatchFlag[i],        "il_exact_sample_value_match_flag"            );
     597      }
     598    }
     599  }
     600  else
     601  {
     602    WRITE_CODE( sei.m_allTilesIlcIdc, 2,                    "all_tiles_ilc_idc"                          );
     603  }
     604
     605  xWriteByteAlign();
     606}
     607#endif
     608
    561609Void SEIWriter::xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps)
    562610{
  • trunk/source/Lib/TLibEncoder/SEIwrite.h

    r313 r442  
    6868#endif
    6969  Void xWriteSEISOPDescription(const SEISOPDescription& sei);
     70#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     71  Void xWriteSEIInterLayerConstrainedTileSets(const SEIInterLayerConstrainedTileSets& sei);
     72#endif
    7073  Void xWriteSEIScalableNesting(TComBitIf& bs, const SEIScalableNesting& sei, TComSPS *sps);
    7174  Void xWriteByteAlign();
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.cpp

    r313 r442  
    5757#endif
    5858
     59TEncAnalyze             m_gcAnalyzeAll_in;
    5960//! \}
  • trunk/source/Lib/TLibEncoder/TEncAnalyze.h

    r313 r442  
    131131    fclose(pFile);
    132132  }
     133
     134  Void    printOutInterlaced ( Char cDelim, Double bits )
     135  {
     136    Double dFps     =   m_dFrmRate; //--CFG_KDY
     137    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
     138   
     139    printf( "\tTotal Frames |  "   "Bitrate    "  "Y-PSNR    "  "U-PSNR    "  "V-PSNR \n" );
     140    //printf( "\t------------ "  " ----------"   " -------- "  " -------- "  " --------\n" );
     141    printf( "\t %8d    %c"          "%12.4lf  "    "%8.4lf  "   "%8.4lf  "    "%8.4lf\n",
     142           getNumPic(), cDelim,
     143           bits * dScale,
     144           getPsnrY() / (Double)getNumPic(),
     145           getPsnrU() / (Double)getNumPic(),
     146           getPsnrV() / (Double)getNumPic() );
     147  }
     148 
     149  Void    printSummaryOutInterlaced (Int bits)
     150  {
     151    FILE* pFile = fopen ("summaryTotal.txt", "at");
     152    Double dFps     =   m_dFrmRate; //--CFG_KDY
     153    Double dScale   = dFps / 1000 / (Double)m_uiNumPic;
     154   
     155    fprintf(pFile, "%f\t %f\t %f\t %f\n", bits * dScale,
     156            getPsnrY() / (Double)getNumPic(),
     157            getPsnrU() / (Double)getNumPic(),
     158            getPsnrV() / (Double)getNumPic() );
     159    fclose(pFile);
     160  }
    133161 
    134162  Void    printSummary(Char ch)
     
    178206#endif
    179207
     208extern TEncAnalyze             m_gcAnalyzeAll_in;
    180209//! \}
    181210
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r345 r442  
    221221  }
    222222  WRITE_FLAG( pcPPS->getScalingListPresentFlag() ? 1 : 0,                          "pps_scaling_list_data_present_flag" );
     223
     224#if IL_SL_SIGNALLING_N0371
     225  pcPPS->setPPS( pcPPS->getLayerId(), pcPPS ); 
     226#endif
     227
    223228  if( pcPPS->getScalingListPresentFlag() )
    224229  {
     
    226231    printf("PPS\n");
    227232#endif
     233
     234#if IL_SL_SIGNALLING_N0371
     235    m_pcSlice->getScalingList()->setLayerId( pcPPS->getLayerId() );
     236
     237    if( pcPPS->getLayerId() > 0 )
     238    {
     239      WRITE_FLAG( pcPPS->getPredScalingListFlag() ? 1 : 0,                          "pps_pred_scaling_list_flag" );
     240      m_pcSlice->getScalingList()->setPredScalingListFlag( pcPPS->getPredScalingListFlag() );
     241
     242      if( pcPPS->getPredScalingListFlag() )
     243      {
     244        // The value of pps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     245        assert( /*pcPPS->getScalingListRefLayerId() >= 0 &&*/ pcPPS->getScalingListRefLayerId() <= 62 );
     246
     247        // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of pps_scaling_list_ref_layer_id shall be greater than 0
     248        if( pcPPS->getSPS()->getVPS()->getAvcBaseLayerFlag() )
     249        {
     250          assert( pcPPS->getScalingListRefLayerId() > 0 );
     251        }
     252
     253        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
     254        // pps_infer_scaling_list_flag in the PPS is equal to 1, pps_infer_scaling_list_flag shall be equal to 0 for the PPS that is active for the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id
     255        assert( pcPPS->getPPS( pcPPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
     256
     257        // It is a requirement of bitstream conformance that, when a PPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
     258        // the layer with nuh_layer_id equal to pps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
     259        assert( pcPPS->getSPS()->getVPS()->getScalingListLayerDependency( pcPPS->getLayerId(), pcPPS->getScalingListRefLayerId() ) == true );
     260       
     261        WRITE_UVLC( pcPPS->getScalingListRefLayerId(),                            "scaling_list_pps_ref_layer_id" );
     262        m_pcSlice->getScalingList()->setScalingListRefLayerId( pcPPS->getScalingListRefLayerId() );
     263        codeScalingList( m_pcSlice->getScalingList() );
     264      }
     265      else
     266      {
     267        codeScalingList( m_pcSlice->getScalingList() );
     268      }
     269    }
     270    else
     271    {
     272      codeScalingList( m_pcSlice->getScalingList() );
     273    }
     274#else
    228275    codeScalingList( m_pcSlice->getScalingList() );
     276#endif
     277
    229278  }
    230279  WRITE_FLAG( pcPPS->getListsModificationPresentFlag(), "lists_modification_present_flag");
     
    414463  }
    415464#endif
     465#ifdef SPS_PTL_FIX
     466  if (pcSPS->getLayerId() == 0)
     467  {
     468    codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     469  }
     470#else
    416471  codePTL(pcSPS->getPTL(), 1, pcSPS->getMaxTLayers() - 1);
     472#endif
    417473  WRITE_UVLC( pcSPS->getSPSId (),                   "sps_seq_parameter_set_id" );
    418   WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
    419   assert(pcSPS->getChromaFormatIdc () == 1);
    420   // in the first version chroma_format_idc can only be equal to 1 (4:2:0)
    421   if( pcSPS->getChromaFormatIdc () == 3 )
    422   {
    423     WRITE_FLAG( 0,                                  "separate_colour_plane_flag");
    424   }
    425 
    426   WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
    427   WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
     474#if REPN_FORMAT_IN_VPS
     475  if( pcSPS->getLayerId() > 0 )
     476  {
     477    WRITE_FLAG( pcSPS->getUpdateRepFormatFlag(), "update_rep_format_flag" );
     478  }
     479  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     480  {
     481#endif
     482    WRITE_UVLC( pcSPS->getChromaFormatIdc (),         "chroma_format_idc" );
     483    assert(pcSPS->getChromaFormatIdc () == 1);
     484    // in the first version chroma_format_idc can only be equal to 1 (4:2:0)
     485    if( pcSPS->getChromaFormatIdc () == 3 )
     486    {
     487      WRITE_FLAG( 0,                                  "separate_colour_plane_flag");
     488    }
     489
     490    WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
     491    WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
     492#if REPN_FORMAT_IN_VPS
     493  }
     494#endif
    428495  Window conf = pcSPS->getConformanceWindow();
    429496
     
    437504  }
    438505
    439   WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
    440   WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
    441 
     506#if REPN_FORMAT_IN_VPS
     507  if( pcSPS->getLayerId() == 0 || pcSPS->getUpdateRepFormatFlag() )
     508  {
     509    assert( pcSPS->getBitDepthY() >= 8 );
     510    assert( pcSPS->getBitDepthC() >= 8 );
     511#endif
     512    WRITE_UVLC( pcSPS->getBitDepthY() - 8,             "bit_depth_luma_minus8" );
     513    WRITE_UVLC( pcSPS->getBitDepthC() - 8,             "bit_depth_chroma_minus8" );
     514#if REPN_FORMAT_IN_VPS
     515  }
     516#endif
    442517  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
    443518
     
    463538  WRITE_UVLC( pcSPS->getQuadtreeTUMaxDepthIntra() - 1,                               "max_transform_hierarchy_depth_intra" );
    464539  WRITE_FLAG( pcSPS->getScalingListFlag() ? 1 : 0,                                   "scaling_list_enabled_flag" );
     540
     541#if IL_SL_SIGNALLING_N0371
     542  pcSPS->setSPS( pcSPS->getLayerId(), pcSPS );
     543#endif
     544
    465545  if(pcSPS->getScalingListFlag())
    466546  {
     
    471551    printf("SPS\n");
    472552#endif
     553
     554#if IL_SL_SIGNALLING_N0371
     555    m_pcSlice->getScalingList()->setLayerId( pcSPS->getLayerId() );
     556
     557    if( pcSPS->getLayerId() > 0 )
     558    {
     559      WRITE_FLAG( pcSPS->getPredScalingListFlag() ? 1 : 0,                          "sps_pred_scaling_list_flag" );
     560      m_pcSlice->getScalingList()->setPredScalingListFlag( pcSPS->getPredScalingListFlag() );
     561
     562      if( pcSPS->getPredScalingListFlag() )
     563      {
     564
     565        // The value of sps_scaling_list_ref_layer_id shall be in the range of 0 to 62, inclusive
     566        assert( /*pcSPS->getScalingListRefLayerId() >= 0 &&*/ pcSPS->getScalingListRefLayerId() <= 62 );
     567       
     568        // When avc_base_layer_flag is equal to 1, it is a requirement of bitstream conformance that the value of sps_scaling_list_ref_layer_id shall be greater than 0
     569        if( pcSPS->getVPS()->getAvcBaseLayerFlag() )
     570        {
     571          assert( pcSPS->getScalingListRefLayerId() > 0 );
     572        }
     573
     574        // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB and
     575        // sps_infer_scaling_list_flag in the SPS is equal to 1, sps_infer_scaling_list_flag shall be equal to 0 for the SPS that is active for the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id
     576        assert( pcSPS->getSPS( pcSPS->getScalingListRefLayerId() )->getPredScalingListFlag() == false );
     577
     578        // It is a requirement of bitstream conformance that, when an SPS with nuh_layer_id equal to nuhLayerIdA is active for a layer with nuh_layer_id equal to nuhLayerIdB,
     579        // the layer with nuh_layer_id equal to sps_scaling_list_ref_layer_id shall be a direct or indirect reference layer of the layer with nuh_layer_id equal to nuhLayerIdB
     580        assert( pcSPS->getVPS()->getScalingListLayerDependency( pcSPS->getLayerId(), pcSPS->getScalingListRefLayerId() ) == true );
     581
     582        WRITE_UVLC( pcSPS->getScalingListRefLayerId(),                            "scaling_list_sps_ref_layer_id" );
     583        m_pcSlice->getScalingList()->setScalingListRefLayerId( pcSPS->getScalingListRefLayerId() );
     584        codeScalingList( m_pcSlice->getScalingList() );
     585      }
     586      else
     587      {
     588        codeScalingList( m_pcSlice->getScalingList() );
     589      }
     590    }
     591    else
     592    {
    473593      codeScalingList( m_pcSlice->getScalingList() );
     594    }
     595#else
     596      codeScalingList( m_pcSlice->getScalingList() );
     597#endif
     598
    474599    }
    475600  }
     
    491616  TComRPSList* rpsList = pcSPS->getRPSList();
    492617  TComReferencePictureSet*      rps;
    493 
     618 
    494619  WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" );
    495620  for(Int i=0; i < rpsList->getNumberOfReferencePictureSets(); i++)
     
    540665{
    541666  // more syntax elements to be written here
     667
     668#if VERT_MV_CONSTRAINT
     669  // Vertical MV component restriction is not used in SHVC CTC
     670  WRITE_FLAG( 0, "inter_view_mv_vert_constraint_flag" );
     671#endif
    542672#if SCALED_REF_LAYER_OFFSETS
    543 #if SCALED_REF_LAYER_OFFSET_FLAG
    544   WRITE_FLAG( pcSPS->getLayerId() > 0, "scaled_ref_layer_offset_present_flag" );
    545673  if( pcSPS->getLayerId() > 0 )
    546 #else
    547   if( pcSPS->getLayerId() > 0 )
    548 #endif
    549674  {
    550675    WRITE_UVLC( pcSPS->getNumScaledRefLayerOffsets(),      "num_scaled_ref_layer_offsets" );
     
    593718  WRITE_FLAG( pcVPS->getTemporalNestingFlag(),                "vps_temporal_id_nesting_flag" );
    594719  assert (pcVPS->getMaxTLayers()>1||pcVPS->getTemporalNestingFlag());
     720#if VPS_EXTN_OFFSET
     721  WRITE_CODE( pcVPS->getExtensionOffset(),         16,        "vps_extension_offset" );
     722#else
    595723  WRITE_CODE( 0xffff,                              16,        "vps_reserved_ffff_16bits" );
     724#endif
    596725  codePTL( pcVPS->getPTL(), true, pcVPS->getMaxTLayers() - 1 );
    597726  const Bool subLayerOrderingInfoPresentFlag = 1;
     
    676805#else
    677806  WRITE_FLAG( 1,                     "vps_extension_flag" );
    678   codeVPSExtension(pcVPS);
    679   WRITE_FLAG( 0,                     "vps_extension2_flag" );   // Flag value of 1 reserved
     807  if(1) // Should be conditioned on the value of vps_extension_flag
     808  {
     809    while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
     810    {
     811      WRITE_FLAG(1,                  "vps_extension_alignment_bit_equal_to_one");
     812    }
     813    codeVPSExtension(pcVPS);
     814    WRITE_FLAG( 0,                     "vps_extension2_flag" );   // Flag value of 1 reserved
     815  }
    680816#endif 
    681817  //future extensions here..
     
    737873  }
    738874#endif
     875#if VIEW_ID_RELATED_SIGNALING
     876  // if ( pcVPS->getNumViews() > 1 ) 
     877  //   However, this is a bug in the text since, view_id_len_minus1 is needed to parse view_id_val.
     878  {
     879    WRITE_CODE( vps->getViewIdLenMinus1( ), 4, "view_id_len_minus1" );
     880  }
     881
     882  for(  i = 0; i < vps->getNumViews(); i++ )
     883  {
     884    WRITE_CODE( vps->getViewIdVal( i ), vps->getViewIdLenMinus1( ) + 1, "view_id_val[i]" );
     885  }
     886#endif
    739887#if VPS_MOVE_DIR_DEPENDENCY_FLAG
    740888#if VPS_EXTN_DIRECT_REF_LAYERS
     
    750898#if JCTVC_M0203_INTERLAYER_PRED_IDC
    751899#if N0120_MAX_TID_REF_PRESENT_FLAG
    752    WRITE_FLAG( vps->getMaxTidIlRefPicsPlus1PresentFlag(), "max_tid_il_ref_pics_plus1_present_flag");
    753    if (vps->getMaxTidIlRefPicsPlus1PresentFlag())
     900   WRITE_FLAG( vps->getMaxTidRefPresentFlag(), "max_tid_ref_present_flag");
     901   if (vps->getMaxTidRefPresentFlag())
    754902   {
    755903     for( i = 0; i < vps->getMaxLayers() - 1; i++)
    756904     {
    757        WRITE_CODE(vps->getMaxSublayerForIlpPlus1(i), 3, "max_sublayer_for_ilp_plus1[i]" );
     905       WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" );
    758906     }
    759907   }
     
    761909  for( i = 0; i < vps->getMaxLayers() - 1; i++)
    762910  {
    763     WRITE_CODE(vps->getMaxSublayerForIlpPlus1(i), 3, "max_sublayer_for_ilp_plus1[i]" );
     911    WRITE_CODE(vps->getMaxTidIlRefPicsPlus1(i), 3, "max_tid_il_ref_pics_plus1[i]" );
    764912  }
    765913#endif
     
    849997#endif
    850998#endif
     999
     1000#if REPN_FORMAT_IN_VPS
     1001  WRITE_FLAG( vps->getRepFormatIdxPresentFlag(), "rep_format_idx_present_flag");
     1002
     1003  if( vps->getRepFormatIdxPresentFlag() )
     1004  {
     1005    WRITE_CODE( vps->getVpsNumRepFormats() - 1, 4, "vps_num_rep_formats_minus1" );
     1006  }
     1007  for(i = 0; i < vps->getVpsNumRepFormats(); i++)
     1008  {
     1009    // Read rep_format_structures
     1010    codeRepFormat( vps->getVpsRepFormat(i) );
     1011  }
     1012 
     1013  if( vps->getRepFormatIdxPresentFlag() )
     1014  {
     1015    for(i = 1; i < vps->getMaxLayers(); i++)
     1016    {
     1017      if( vps->getVpsNumRepFormats() > 1 )
     1018      {
     1019        WRITE_CODE( vps->getVpsRepFormatIdx(i), 4, "vps_rep_format_idx[i]" );
     1020      }
     1021    }
     1022  }
     1023#endif
     1024
    8511025#if JCTVC_M0458_INTERLAYER_RPS_SIG
    8521026      WRITE_FLAG(vps->getMaxOneActiveRefLayerFlag(), "max_one_active_ref_layer_flag");
     1027#endif
     1028#if N0147_IRAP_ALIGN_FLAG
     1029      WRITE_FLAG(vps->getCrossLayerIrapAlignFlag(), "cross_layer_irap_aligned_flag");
    8531030#endif
    8541031#if !VPS_MOVE_DIR_DEPENDENCY_FLAG
     
    8751052    }
    8761053  }
     1054
     1055#if IL_SL_SIGNALLING_N0371
     1056  for(i = 1; i < vps->getMaxLayers(); i++)
     1057  {
     1058    for(j = 0; j < i; j++)
     1059    {
     1060      vps->setScalingListLayerDependency( i, j, vps->checkLayerDependency( i,j ) );
     1061    }
     1062  }
     1063#endif
     1064
    8771065#endif
    8781066#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    8791067  WRITE_FLAG(vps->getSingleLayerForNonIrapFlag(), "single_layer_for_non_irap_flag" );
    8801068#endif
     1069
     1070#if !VPS_VUI
     1071  WRITE_FLAG( 0,                     "vps_vui_present_flag" );
     1072#else
     1073  WRITE_FLAG( 1,                     "vps_vui_present_flag" );
     1074  if(1)   // Should be conditioned on the value of vps_vui_present_flag
     1075  {
     1076    while ( m_pcBitIf->getNumberOfWrittenBits() % 8 != 0 )
     1077    {
     1078      WRITE_FLAG(1,                  "vps_vui_alignment_bit_equal_to_one");
     1079    }
     1080    codeVPSVUI(vps); 
     1081  }
     1082#endif
     1083}
     1084#endif
     1085#if REPN_FORMAT_IN_VPS
     1086Void  TEncCavlc::codeRepFormat      ( RepFormat *repFormat )
     1087{
     1088  WRITE_CODE( repFormat->getChromaFormatVpsIdc(), 2, "chroma_format_idc" );   
     1089 
     1090  if( repFormat->getChromaFormatVpsIdc() == 3 )
     1091  {
     1092    WRITE_FLAG( repFormat->getSeparateColourPlaneVpsFlag(), "separate_colour_plane_flag");     
     1093  }
     1094
     1095  WRITE_CODE ( repFormat->getPicWidthVpsInLumaSamples (), 16, "pic_width_in_luma_samples" );   
     1096  WRITE_CODE ( repFormat->getPicHeightVpsInLumaSamples(), 16, "pic_height_in_luma_samples" );   
     1097 
     1098  assert( repFormat->getBitDepthVpsLuma() >= 8 );
     1099  assert( repFormat->getBitDepthVpsChroma() >= 8 );
     1100  WRITE_CODE( repFormat->getBitDepthVpsLuma() - 8,   4, "bit_depth_luma_minus8" );           
     1101  WRITE_CODE( repFormat->getBitDepthVpsChroma() - 8, 4, "bit_depth_chroma_minus8" );         
     1102
     1103}
     1104#endif
     1105#if VPS_VUI
     1106Void TEncCavlc::codeVPSVUI (TComVPS *vps)
     1107{
     1108  Int i,j;
     1109#if VPS_VUI_BITRATE_PICRATE
     1110  WRITE_FLAG( vps->getBitRatePresentVpsFlag(),        "bit_rate_present_vps_flag" );
     1111  WRITE_FLAG( vps->getPicRatePresentVpsFlag(),        "pic_rate_present_vps_flag" );
     1112
     1113  if( vps->getBitRatePresentVpsFlag() || vps->getPicRatePresentVpsFlag() )
     1114  {
     1115    for( i = 0; i < vps->getNumLayerSets(); i++ )
     1116    {
     1117      for( j = 0; j < vps->getMaxTLayers(); j++ )
     1118      {
     1119        if( vps->getBitRatePresentVpsFlag() )
     1120        {
     1121          WRITE_FLAG( vps->getBitRatePresentFlag( i, j),        "bit_rate_present_vps_flag[i][j]" );
     1122        }
     1123        if( vps->getPicRatePresentVpsFlag() )
     1124        {
     1125          WRITE_FLAG( vps->getPicRatePresentFlag( i, j),        "pic_rate_present_vps_flag[i][j]" );
     1126        }
     1127        if( vps->getBitRatePresentFlag(i, j) )
     1128        {
     1129          WRITE_CODE( vps->getAvgBitRate( i, j ), 16, "avg_bit_rate[i][j]" );
     1130          WRITE_CODE( vps->getAvgBitRate( i, j ), 16, "max_bit_rate[i][j]" );
     1131        }
     1132        if( vps->getPicRatePresentFlag(i, j) )
     1133        {
     1134          WRITE_CODE( vps->getConstPicRateIdc( i, j), 2 , "constant_pic_rate_idc[i][j]" );
     1135          WRITE_CODE( vps->getConstPicRateIdc( i, j), 16, "avg_pic_rate[i][j]"          );
     1136        }
     1137      }
     1138    }
     1139  }
     1140#endif
     1141#if TILE_BOUNDARY_ALIGNED_FLAG
     1142  for(i = 1; i < vps->getMaxLayers(); i++)
     1143  {
     1144    for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
     1145    {
     1146      WRITE_FLAG( vps->getTileBoundariesAlignedFlag(i,j) ? 1 : 0 , "tile_boundaries_aligned_flag[i][j]" );
     1147    }
     1148  } 
     1149#endif
     1150#if N0160_VUI_EXT_ILP_REF
     1151  WRITE_FLAG( vps->getNumIlpRestrictedRefLayers() ? 1 : 0 , "num_ilp_restricted_ref_layers" );   
     1152  if( vps->getNumIlpRestrictedRefLayers())
     1153  {
     1154    for(i = 1; i < vps->getMaxLayers(); i++)
     1155    {
     1156      for(j = 0; j < vps->getNumDirectRefLayers(vps->getLayerIdInNuh(i)); j++)
     1157      {       
     1158        WRITE_UVLC(vps->getMinSpatialSegmentOffsetPlus1( i, j),    "min_spatial_segment_offset_plus1[i][j]");
     1159       
     1160        if( vps->getMinSpatialSegmentOffsetPlus1(i,j ) > 0 )
     1161        { 
     1162          WRITE_FLAG( vps->getCtuBasedOffsetEnabledFlag( i, j) ? 1 : 0 , "ctu_based_offset_enabled_flag[i][j]" );   
     1163         
     1164          if(vps->getCtuBasedOffsetEnabledFlag(i,j)) 
     1165          {
     1166            WRITE_UVLC(vps->getMinHorizontalCtuOffsetPlus1( i, j),    "min_horizontal_ctu_offset_plus1[i][j]");           
     1167          }
     1168        } 
     1169      } 
     1170    }
     1171  }
     1172#endif
    8811173}
    8821174#endif
     
    9271219  {
    9281220
     1221#if POC_RESET_FLAG
     1222    Int iBits = 0;
     1223    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits )
     1224    {
     1225      WRITE_FLAG( pcSlice->getPocResetFlag(), "poc_reset_flag" );
     1226      iBits++;
     1227    }
     1228    if( pcSlice->getPPS()->getNumExtraSliceHeaderBits() > iBits )
     1229    {
     1230      assert(!!"discardable_flag");
     1231      WRITE_FLAG(pcSlice->getDiscardableFlag(), "discardable_flag");
     1232      iBits++;
     1233    }
     1234    for ( ; iBits < pcSlice->getPPS()->getNumExtraSliceHeaderBits(); iBits++)
     1235    {
     1236      assert(!!"slice_reserved_undetermined_flag[]");
     1237      WRITE_FLAG(0, "slice_reserved_undetermined_flag[]");
     1238    }
     1239#else
    9291240#if SH_DISCARDABLE_FLAG
    9301241    if (pcSlice->getPPS()->getNumExtraSliceHeaderBits()>0)
     
    9451256    }
    9461257#endif
     1258#endif
    9471259
    9481260    WRITE_UVLC( pcSlice->getSliceType(),       "slice_type" );
     
    9531265    }
    9541266
     1267#if REPN_FORMAT_IN_VPS
     1268    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
     1269    assert( pcSlice->getChromaFormatIdc() == 1 );
     1270#else
    9551271    // in the first version chroma_format_idc is equal to one, thus colour_plane_id will not be present
    9561272    assert (pcSlice->getSPS()->getChromaFormatIdc() == 1 );
     1273#endif
    9571274    // if( separate_colour_plane_flag  ==  1 )
    9581275    //   colour_plane_id                                      u(2)
    9591276
     1277#if N0065_LAYER_POC_ALIGNMENT
     1278    if( pcSlice->getLayerId() > 0 || !pcSlice->getIdrPicFlag() )
     1279#else
    9601280    if( !pcSlice->getIdrPicFlag() )
    961     {
    962       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
     1281#endif
     1282    {
     1283#if POC_RESET_FLAG
     1284      Int picOrderCntLSB;
     1285      if( !pcSlice->getPocResetFlag() )
     1286      {
     1287        picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
     1288      }
     1289      else
     1290      {
     1291        picOrderCntLSB = (pcSlice->getPocValueBeforeReset()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
     1292      }
     1293#else
     1294      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
     1295#endif
    9631296      WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
     1297
     1298#if N0065_LAYER_POC_ALIGNMENT
     1299      if( !pcSlice->getIdrPicFlag() )
     1300      {
     1301#endif
    9641302      TComReferencePictureSet* rps = pcSlice->getRPS();
    9651303     
     
    10761414        WRITE_FLAG( pcSlice->getEnableTMVPFlag() ? 1 : 0, "slice_temporal_mvp_enable_flag" );
    10771415      }
     1416#if N0065_LAYER_POC_ALIGNMENT
     1417      }
     1418#endif
    10781419    }
    10791420
     
    12241565    if ( pcSlice->getEnableTMVPFlag() )
    12251566    {
    1226 #if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
     1567#if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
    12271568      if ( !pcSlice->getIdrPicFlag() && pcSlice->getLayerId() > 0 && pcSlice->getActiveNumILRRefIdx() > 0 && pcSlice->getNumMotionPredRefLayers() > 0 )
    12281569      {
     
    12471588        WRITE_UVLC( pcSlice->getColRefIdx(), "collocated_ref_idx" );
    12481589      }
    1249 #if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
     1590#if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
    12501591      }
    12511592#endif
     
    15541895  Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
    15551896
     1897#if REPN_FORMAT_IN_VPS
     1898  Int qpBdOffsetY =  pcCU->getSlice()->getQpBDOffsetY();
     1899#else
    15561900  Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
     1901#endif
    15571902  iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
    15581903
     
    16822027        startBit = m_pcBitIf->getNumberOfWrittenBits();
    16832028#endif
     2029
     2030#if IL_SL_SIGNALLING_N0371
     2031        if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
     2032        {
     2033          scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
     2034          WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
     2035          if(!scalingListPredModeFlag)// Copy Mode
     2036          {
     2037            WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
     2038          }
     2039          else// DPCM Mode
     2040          {
     2041            xCodeScalingList(scalingList, sizeId, listId);
     2042          }
     2043        }
     2044        else
     2045        {
     2046          scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
     2047          WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
     2048          if(!scalingListPredModeFlag)// Copy Mode
     2049          {
     2050            WRITE_UVLC( (Int)listId - (Int)scalingList->getRefMatrixId (sizeId,listId), "scaling_list_pred_matrix_id_delta");
     2051          }
     2052          else// DPCM Mode
     2053          {
     2054            xCodeScalingList(scalingList, sizeId, listId);
     2055          }
     2056        }
     2057#else
    16842058        scalingListPredModeFlag = scalingList->checkPredMode( sizeId, listId );
    16852059        WRITE_FLAG( scalingListPredModeFlag, "scaling_list_pred_mode_flag" );
     
    16922066          xCodeScalingList(scalingList, sizeId, listId);
    16932067        }
     2068#endif
     2069
    16942070#if SCALING_LIST_OUTPUT_RESULT
    16952071        printf("Matrix [%d][%d] Bit %d\n",sizeId,listId,m_pcBitIf->getNumberOfWrittenBits() - startBit);
    16962072#endif
     2073
    16972074      }
    16982075    }
     
    17142091  Int data;
    17152092  Int *src = scalingList->getScalingListAddress(sizeId, listId);
     2093
    17162094    if( sizeId > SCALING_LIST_8x8 )
    17172095    {
     2096#if IL_SL_SIGNALLING_N0371
     2097      if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
     2098      {
     2099        ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
     2100        scalingList->setScalingListDC(sizeId,listId,ref_scalingListDC[scalingList->getScalingListRefLayerId()][sizeId][listId]);
     2101      }
     2102      else
     2103      {
     2104        WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
     2105        nextCoef = scalingList->getScalingListDC(sizeId,listId);
     2106        ref_scalingListDC[scalingList->getLayerId()][sizeId][listId] = scalingList->getScalingListDC(sizeId,listId);
     2107      }
     2108#else
    17182109      WRITE_SVLC( scalingList->getScalingListDC(sizeId,listId) - 8, "scaling_list_dc_coef_minus8");
    17192110      nextCoef = scalingList->getScalingListDC(sizeId,listId);
     2111#endif
    17202112    }
    17212113    for(Int i=0;i<coefNum;i++)
    17222114    {
     2115#if IL_SL_SIGNALLING_N0371
     2116      if( scalingList->getLayerId() > 0 && scalingList->getPredScalingListFlag() )
     2117      {
     2118        ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = src[scan[i]];
     2119        src[scan[i]] = ref_scalingListCoef[scalingList->getScalingListRefLayerId()][sizeId][listId][i];
     2120      }
     2121      else
     2122      {
     2123        data = src[scan[i]] - nextCoef;
     2124        ref_scalingListCoef[scalingList->getLayerId()][sizeId][listId][i] = src[scan[i]];
     2125        nextCoef = src[scan[i]];
     2126        if(data > 127)
     2127        {
     2128          data = data - 256;
     2129        }
     2130        if(data < -128)
     2131        {
     2132          data = data + 256;
     2133        }
     2134
     2135        WRITE_SVLC( data,  "scaling_list_delta_coef");
     2136      }
     2137#else
    17232138      data = src[scan[i]] - nextCoef;
    17242139      nextCoef = src[scan[i]];
     
    17332148
    17342149      WRITE_SVLC( data,  "scaling_list_delta_coef");
     2150#endif
    17352151    }
    17362152}
     
    17382154{
    17392155  // Bool state = true, state2 = false;
    1740   Int lsb = ltrpPOC % (1<<pcSlice->getSPS()->getBitsForPOC());
     2156  Int lsb = ltrpPOC & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    17412157  for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++)
    17422158  {
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r345 r442  
    8787  Void  codeVPSExtension        ( TComVPS* pcVPS );
    8888#endif
     89
     90#if VPS_VUI
     91  Void codeVPSVUI               (TComVPS *vps);
     92#endif
     93#if REPN_FORMAT_IN_VPS
     94  Void  codeRepFormat           ( RepFormat *repFormat );
     95#endif
    8996  Void  codeVUI                 ( TComVUI *pcVUI, TComSPS* pcSPS );
    9097  Void  codeSPS                 ( TComSPS* pcSPS );
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r313 r442  
    6969  Int m_numRefIdc;
    7070  Int m_refIdc[MAX_NUM_REF_PICS+1];
     71#if EXTERNAL_USEDBYCURR_N0082
     72  Int m_UseExtusedByCurrPic;
     73  Int m_ExtusedByCurrPic[MAX_NUM_REF_PICS];
     74#endif
    7175  GOPEntry()
    7276  : m_POC(-1)
     
    8387  , m_deltaRPS(0)
    8488  , m_numRefIdc(0)
     89#if EXTERNAL_USEDBYCURR_N0082
     90  , m_UseExtusedByCurrPic(0)
     91#endif
    8592  {
    8693    ::memset( m_referencePics, 0, sizeof(m_referencePics) );
    8794    ::memset( m_usedByCurrPic, 0, sizeof(m_usedByCurrPic) );
    8895    ::memset( m_refIdc,        0, sizeof(m_refIdc) );
     96#if EXTERNAL_USEDBYCURR_N0082
     97    ::memset( m_usedByCurrPic, 0, sizeof(m_ExtusedByCurrPic) );
     98#endif
    8999  }
    90100};
    91101
    92102std::istringstream &operator>>(std::istringstream &in, GOPEntry &entry);     //input
     103
     104#if REPN_FORMAT_IN_VPS
     105struct RepFormatCfg
     106{
     107  Int   m_chromaFormatIdc;
     108  Bool  m_separateColourPlaneFlag;
     109  Int   m_picWidthInLumaSamples;
     110  Int   m_picHeightInLumaSamples;
     111  Int   m_bitDepthLuma;
     112  Int   m_bitDepthChroma;
     113  RepFormatCfg()
     114    : m_chromaFormatIdc         (CHROMA_420)
     115    , m_separateColourPlaneFlag (0)
     116    , m_picWidthInLumaSamples   (352)
     117    , m_picHeightInLumaSamples  (288)
     118    , m_bitDepthLuma            (8)
     119    , m_bitDepthChroma          (8)
     120  {}
     121};
     122std::istringstream &operator>>(std::istringstream &in, RepFormatCfg &repFormatCfg);
     123#endif
     124
    93125//! \ingroup TLibEncoder
    94126//! \{
     
    155187#endif
    156188#endif
     189#if N0120_MAX_TID_REF_CFG
     190  Int       m_maxTidIlRefPicsPlus1;
     191#endif
    157192  //======= Transform =============
    158193  UInt      m_uiQuadtreeTULog2MaxSize;
     
    283318  Int       m_SOPDescriptionSEIEnabled;
    284319  Int       m_scalableNestingSEIEnabled;
     320#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     321  Bool      m_interLayerConstrainedTileSetsSEIEnabled;
     322  UInt      m_ilNumSetsInMessage;
     323  Bool      m_skippedTileSetPresentFlag;
     324  UInt      m_topLeftTileIndex[1024];
     325  UInt      m_bottomRightTileIndex[1024];
     326  UInt      m_ilcIdc[1024];
     327#endif
    285328  //====== Weighted Prediction ========
    286329  Bool      m_useWeightedPred;       //< Use of Weighting Prediction (P_SLICE)
     
    353396  UInt      m_layerId;   
    354397  UInt      m_numLayer;
    355 #endif
    356 #if REF_IDX_FRAMEWORK
    357   Int      m_elRapSliceBEnabled;
    358 #endif
     398  Int       m_elRapSliceBEnabled;
    359399#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    360   Int      m_adaptiveResolutionChange;
     400  Int       m_adaptiveResolutionChange;
     401#endif
    361402#endif
    362403
     
    438479#endif
    439480#endif
     481#if N0120_MAX_TID_REF_CFG
     482  Int       getMaxTidIlRefPicsPlus1         ()                              { return m_maxTidIlRefPicsPlus1; }
     483  Void      setMaxTidIlRefPicsPlus1         (Int num)                       { m_maxTidIlRefPicsPlus1 = num;  }
     484#endif
    440485  //======== Transform =============
    441486  Void      setQuadtreeTULog2MaxSize        ( UInt  u )      { m_uiQuadtreeTULog2MaxSize = u; }
     
    720765  Void  setScalableNestingSEIEnabled(Int b)                { m_scalableNestingSEIEnabled = b; }
    721766  Int   getScalableNestingSEIEnabled()                     { return m_scalableNestingSEIEnabled; }
     767#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     768  Void  setInterLayerConstrainedTileSetsSEIEnabled(Bool b) { m_interLayerConstrainedTileSetsSEIEnabled = b; }
     769  Bool  getInterLayerConstrainedTileSetsSEIEnabled()       { return m_interLayerConstrainedTileSetsSEIEnabled; }
     770  Void  setIlNumSetsInMessage(UInt b)                      { m_ilNumSetsInMessage = b; }
     771  Int   getIlNumSetsInMessage()                            { return m_ilNumSetsInMessage; }
     772  Void  setSkippedTileSetPresentFlag(Bool b)               { m_skippedTileSetPresentFlag = b; }
     773  Bool  getSkippedTileSetPresentFlag()                     { return m_skippedTileSetPresentFlag; }
     774  Void  setTopLeftTileIndex(UInt *b)
     775  {
     776    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
     777    {
     778      m_topLeftTileIndex[i] = b[i];
     779    }
     780  }
     781  UInt  getTopLeftTileIndex(UInt b)                        { return m_topLeftTileIndex[b]; }
     782  Void  setBottomRightTileIndex(UInt *b)
     783  {
     784    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
     785    {
     786      m_bottomRightTileIndex[i] = b[i];
     787    }
     788  }
     789  UInt  getBottomRightTileIndex(UInt b)                    { return m_bottomRightTileIndex[b]; }
     790  Void  setIlcIdc(UInt *b)
     791  {
     792    for (UInt i = 0; i < m_ilNumSetsInMessage; i++)
     793    {
     794      m_ilcIdc[i] = b[i];
     795    }
     796  }
     797  UInt  getIlcIdc(UInt b)                                  { return m_ilcIdc[b]; }
     798#endif
    722799  Void      setUseWP               ( Bool b )    { m_useWeightedPred   = b;    }
    723800  Void      setWPBiPred            ( Bool b )    { m_useWeightedBiPred = b;    }
     
    858935  Void      setConformanceMode    (Int mode)     { m_conformanceMode = mode; }
    859936  Void      setConformanceWindow(Window& conformanceWindow ) { m_conformanceWindow = conformanceWindow; }
    860 #endif
    861 #if REF_IDX_FRAMEWORK
    862937  Void      setElRapSliceTypeB(Int bEnabled) {m_elRapSliceBEnabled = bEnabled;}
    863938  Int       getElRapSliceTypeB()              {return m_elRapSliceBEnabled;}
    864 #endif
    865939#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    866940  Void      setAdaptiveResolutionChange(Int x) { m_adaptiveResolutionChange = x;    }
    867941  Int       getAdaptiveResolutionChange()      { return m_adaptiveResolutionChange; }
    868942#endif
     943#endif
    869944};
    870945
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r345 r442  
    379379  m_ppcOrigYuv[uiDepth]->copyFromPicYuv( pcPic->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
    380380
    381   // variables for fast encoder decision
    382   Bool    bEarlySkip  = false;
    383   Bool    bTrySplit    = true;
    384   Double  fRD_Skip    = MAX_DOUBLE;
    385 
    386381  // variable for Early CU determination
    387382  Bool    bSubBranch = true;
     
    390385  Bool    doNotBlockPu = true;
    391386  Bool earlyDetectionSkipMode = false;
    392 
    393   Bool    bTrySplitDQP  = true;
    394 
    395   static  Double  afCost[ MAX_CU_DEPTH ];
    396   static  Int      aiNum [ MAX_CU_DEPTH ];
    397 
    398   if ( rpcBestCU->getAddr() == 0 )
    399   {
    400     ::memset( afCost, 0, sizeof( afCost ) );
    401     ::memset( aiNum,  0, sizeof( aiNum  ) );
    402   }
    403387
    404388  Bool bBoundary = false;
     
    412396  Int iMaxQP;
    413397  Bool isAddLowestQP = false;
     398#if REPN_FORMAT_IN_VPS
     399  Int lowestQP = -rpcTempCU->getSlice()->getQpBDOffsetY();
     400#else
    414401  Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();
     402#endif
    415403
    416404  if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
    417405  {
    418406    Int idQP = m_pcEncCfg->getMaxDeltaQP();
     407#if REPN_FORMAT_IN_VPS
    419408    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    420409    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
     410#else
     411    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
     412    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
     413#endif
    421414    if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
    422415    {
     
    450443  Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart();
    451444  Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart());
     445#if REPN_FORMAT_IN_VPS
     446  Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getPicWidthInLumaSamples()           ) && ( uiBPelY < rpcBestCU->getSlice()->getPicHeightInLumaSamples()           );
     447#else
    452448  Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() );
     449#endif
    453450  // We need to split, so don't try these modes.
    454451  if(!bSliceEnd && !bSliceStart && bInsidePicture )
     
    458455    if (rpcBestCU->getLayerId() > 0)
    459456    {
    460         if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx())
    461             testInter = false;
    462         if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx())
    463             testInter = false;
     457      if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx())
     458      {
     459        testInter = false;
     460      }
     461      if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx())
     462      {
     463        testInter = false;
     464      }
    464465#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
    465         if( pcSlice->getInterLayerSamplePredOnlyFlag() )
    466             testInter = false;
     466      if( pcSlice->getInterLayerSamplePredOnlyFlag() )
     467      {
     468        testInter = false;
     469      }
    467470#endif
    468471    }
     
    474477        iQP = lowestQP;
    475478      }
    476       // variables for fast encoder decision
    477       bEarlySkip  = false;
    478       bTrySplit    = true;
    479       fRD_Skip    = MAX_DOUBLE;
    480479
    481480      rpcTempCU->initEstData( uiDepth, iQP );
     
    496495        xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
    497496        rpcTempCU->initEstData( uiDepth, iQP );
    498 
    499         // fast encoder decision for early skip
    500         if ( m_pcEncCfg->getUseFastEnc() )
    501         {
    502           Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
    503           if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] )
    504           {
    505             bEarlySkip = true;
    506             bTrySplit  = false;
    507           }
    508         }
     497       
    509498#if (ENCODER_FAST_MODE == 2)
    510499        if (testInter)
    511500        {
    512501#endif
    513 
    514502        if(!m_pcEncCfg->getUseEarlySkipDetection())
    515503        {
    516504          // 2Nx2N, NxN
    517           if ( !bEarlySkip )
     505          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
     506          if(m_pcEncCfg->getUseCbfFastMode())
    518507          {
    519             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
    520             if(m_pcEncCfg->getUseCbfFastMode())
    521             {
    522               doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    523             }
     508            doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    524509          }
    525510        }
    526511#if (ENCODER_FAST_MODE == 2)
    527     }
    528 #endif
    529 
    530       }
    531 
    532       if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
    533       {
    534         if(iQP == iBaseQP)
    535         {
    536           bTrySplitDQP = bTrySplit;
    537         }
    538       }
    539       else
    540       {
    541         bTrySplitDQP = bTrySplit;
    542       }
     512        }
     513#endif
     514      }
     515
    543516      if (isAddLowestQP && (iQP == lowestQP))
    544517      {
     
    567540        // do inter modes, NxN, 2NxN, and Nx2N
    568541#if (ENCODER_FAST_MODE)
    569       if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
     542        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
    570543#else
    571544        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
     
    573546        {
    574547          // 2Nx2N, NxN
    575           if ( !bEarlySkip )
     548          if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
    576549          {
    577             if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
     550            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
    578551            {
    579               if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
    580               {
    581                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
    582                 rpcTempCU->initEstData( uiDepth, iQP );
    583               }
     552              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
     553              rpcTempCU->initEstData( uiDepth, iQP );
    584554            }
    585555          }
     
    721691
    722692        // do normal intra modes
    723         if ( !bEarlySkip )
    724         {
    725693          // speedup for inter frames
    726694#if (ENCODER_FAST_MODE)
     
    748716            }
    749717          }
    750         }
    751718
    752719        // test PCM
     
    790757    rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
    791758
    792     // accumulate statistics for early skip
    793     if ( m_pcEncCfg->getUseFastEnc() )
    794     {
    795       if ( rpcBestCU->isSkipped(0) )
    796       {
    797         Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
    798         afCost[ iIdx ] += rpcBestCU->getTotalCost();
    799         aiNum [ iIdx ] ++;
    800       }
    801     }
    802 
    803759    // Early CU determination
    804760    if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
     
    827783  {
    828784    Int idQP = m_pcEncCfg->getMaxDeltaQP();
     785#if REPN_FORMAT_IN_VPS
     786    iMinQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
     787    iMaxQP = Clip3( -rpcTempCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
     788#else
    829789    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    830790    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
     791#endif
    831792    if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
    832793    {
     
    878839
    879840    // further split
    880     if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
     841    if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
    881842    {
    882843      UChar       uhNextDepth         = uiDepth+1;
     
    890851
    891852        Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr();
     853#if REPN_FORMAT_IN_VPS
     854        if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getPicWidthInLumaSamples()           ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getPicHeightInLumaSamples()           ) )
     855#else
    892856        if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     857#endif
    893858        {
    894859          if( m_bUseSBACRD )
     
    10381003  UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
    10391004  UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1005#if REPN_FORMAT_IN_VPS
     1006  UInt uiWidth =  pcSlice->getPicWidthInLumaSamples();
     1007  UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
     1008#else
    10401009  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
    10411010  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     1011#endif
    10421012  while(uiPosX>=uiWidth||uiPosY>=uiHeight)
    10431013  {
     
    11361106    iQpOffset = Int(floor( dQpOffset + 0.49999 ));
    11371107  }
     1108#if REPN_FORMAT_IN_VPS
     1109  return Clip3(-pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
     1110#else
    11381111  return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
     1112#endif
    11391113}
    11401114
     
    11601134    pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) );
    11611135  // We need to split, so don't try these modes.
     1136#if REPN_FORMAT_IN_VPS
     1137  if(!bSliceStart&&( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()           ) )
     1138#else
    11621139  if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     1140#endif
    11631141  {
    11641142    m_pcEntropyCoder->encodeSplitFlag( pcCU, uiAbsPartIdx, uiDepth );
     
    11811159      uiTPelY   = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ];
    11821160      Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr();
     1161#if REPN_FORMAT_IN_VPS
     1162      if(bInSlice&&( uiLPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiTPelY < pcSlice->getPicHeightInLumaSamples()           ) )
     1163#else
    11831164      if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     1165#endif
    11841166      {
    11851167        xEncodeCU( pcCU, uiAbsPartIdx, uiDepth+1 );
     
    17061688  Bool bSliceEnd   = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx &&
    17071689    pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) );
     1690#if REPN_FORMAT_IN_VPS
     1691  if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiBPelY < pcSlice->getPicHeightInLumaSamples()           ) )
     1692#else
    17081693  if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     1694#endif
    17091695  {
    17101696    UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx];
     
    17271713      Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() &&
    17281714        rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr();
     1715#if REPN_FORMAT_IN_VPS
     1716      if(bInSlice&&( uiSubCULPelX < pcSlice->getPicWidthInLumaSamples()           ) && ( uiSubCUTPelY < pcSlice->getPicHeightInLumaSamples()           ) )
     1717#else
    17291718      if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) )
     1719#endif
    17301720      {
    17311721        xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY );   // Copy Yuv data to picture Yuv
  • trunk/source/Lib/TLibEncoder/TEncGOP.cpp

    r352 r442  
    307307}
    308308
     309#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     310SEIInterLayerConstrainedTileSets* TEncGOP::xCreateSEIInterLayerConstrainedTileSets()
     311{
     312  SEIInterLayerConstrainedTileSets *seiInterLayerConstrainedTileSets = new SEIInterLayerConstrainedTileSets();
     313  seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag = false;
     314  seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag = false;
     315  if (!seiInterLayerConstrainedTileSets->m_ilOneTilePerTileSetFlag)
     316  {
     317    seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 = m_pcCfg->getIlNumSetsInMessage() - 1;
     318    if (seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1)
     319    {
     320      seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = m_pcCfg->getSkippedTileSetPresentFlag();
     321    }
     322    else
     323    {
     324      seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag = false;
     325    }
     326    seiInterLayerConstrainedTileSets->m_ilNumSetsInMessageMinus1 += seiInterLayerConstrainedTileSets->m_skippedTileSetPresentFlag ? 1 : 0;
     327    for (UInt i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++)
     328    {
     329      seiInterLayerConstrainedTileSets->m_ilctsId[i] = i;
     330      seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i] = 0;
     331      for( UInt j = 0; j <= seiInterLayerConstrainedTileSets->m_ilNumTileRectsInSetMinus1[i]; j++)
     332      {
     333        seiInterLayerConstrainedTileSets->m_ilTopLeftTileIndex[i][j]     = m_pcCfg->getTopLeftTileIndex(i);
     334        seiInterLayerConstrainedTileSets->m_ilBottomRightTileIndex[i][j] = m_pcCfg->getBottomRightTileIndex(i);
     335      }
     336      seiInterLayerConstrainedTileSets->m_ilcIdc[i] = m_pcCfg->getIlcIdc(i);
     337      if (seiInterLayerConstrainedTileSets->m_ilAllTilesExactSampleValueMatchFlag)
     338      {
     339        seiInterLayerConstrainedTileSets->m_ilExactSampleValueMatchFlag[i] = false;
     340      }
     341    }
     342  }
     343
     344  return seiInterLayerConstrainedTileSets;
     345}
     346#endif
     347
    309348Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps)
    310349{
     
    369408    delete sei;
    370409  }
     410#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     411  if(m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled())
     412  {
     413    SEIInterLayerConstrainedTileSets *sei = xCreateSEIInterLayerConstrainedTileSets ();
     414
     415    nalu = NALUnit(NAL_UNIT_PREFIX_SEI, 0, m_pcCfg->getNumLayer()-1); // For highest layer
     416    m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream);
     417    m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps);
     418    writeRBSPTrailingBits(nalu.m_Bitstream);
     419    accessUnit.push_back(new NALUnitEBSP(nalu));
     420    delete sei;
     421  }
     422#endif
    371423}
    372424
     
    375427// ====================================================================================================================
    376428#if SVC_EXTENSION
    377 Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
    378 #else
    379 Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP)
     429Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff)
     430#else
     431Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff)
    380432#endif
    381433{
     
    390442  TComOutputBitstream* pcSubstreamsOut = NULL;
    391443
    392   xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
     444  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
    393445
    394446  m_iNumPicCoded = 0;
     
    463515
    464516    /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding
    465     Int pocCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC;
    466     Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
    467     if(iPOCLast == 0)
     517    Int iTimeOffset;
     518    Int pocCurr;
     519   
     520    if(iPOCLast == 0) //case first frame or first top field
    468521    {
    469522      pocCurr=0;
    470523      iTimeOffset = 1;
    471524    }
     525    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
     526    {
     527      pocCurr = 1;
     528      iTimeOffset = 1;
     529    }
     530    else
     531    {
     532      pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
     533      iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
     534    }
     535
    472536    if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
    473537    {
     
    490554    accessUnitsInGOP.push_back(AccessUnit());
    491555    AccessUnit& accessUnit = accessUnitsInGOP.back();
    492     xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr );
     556    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField );
    493557
    494558    //  Slice data initialization
     
    499563#if SVC_EXTENSION
    500564    pcPic->setLayerId( m_layerId );
    501     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS() );
    502 #else
    503     m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() );
    504 #endif
    505 
     565    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS(), isField );
     566#else
     567    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField );
     568#endif
     569
     570    //Set Frame/Field coding
     571    pcSlice->getPic()->setField(isField);
     572
     573#if POC_RESET_FLAG
     574    if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files.
     575    {
     576      // Subtract POC adjustment value until now.
     577      pcSlice->setPOC( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() );
     578    }
     579    else
     580    {
     581      // Check if this is the first slice in the picture
     582      // In the encoder, the POC values are copied along with copySliceInfo, so we only need
     583      // to do this for the first slice.
     584      Int pocAdjustValue = pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue();
     585      if( pcSlice->getSliceIdx() == 0 )
     586      {
     587        TComList<TComPic*>::iterator  iterPic = rcListPic.begin(); 
     588
     589        // Iterate through all picture in DPB
     590        while( iterPic != rcListPic.end() )
     591        {             
     592          TComPic *dpbPic = *iterPic;
     593          if( dpbPic->getPOC() == pocCurr )
     594          {
     595            if( dpbPic->getReconMark() )
     596            {
     597              assert( !( dpbPic->getSlice(0)->isReferenced() ) && !( dpbPic->getOutputMark() ) );
     598            }
     599          }
     600          // Check if the picture pointed to by iterPic is either used for reference or
     601          // needed for output, are in the same layer, and not the current picture.
     602          if( /* ( ( dpbPic->getSlice(0)->isReferenced() ) || ( dpbPic->getOutputMark() ) )
     603              && */ ( dpbPic->getLayerId() == pcSlice->getLayerId() )
     604              && ( dpbPic->getReconMark() )
     605            )
     606          {
     607            for(Int i = dpbPic->getNumAllocatedSlice()-1; i >= 0; i--)
     608            {
     609              TComSlice *slice = dpbPic->getSlice(i);
     610              TComReferencePictureSet *rps = slice->getRPS();
     611              slice->setPOC( dpbPic->getSlice(i)->getPOC() - pocAdjustValue );
     612
     613              // Also adjust the POC value stored in the RPS of each such slice
     614              for(Int j = rps->getNumberOfPictures(); j >= 0; j--)
     615              {
     616                rps->setPOC( j, rps->getPOC(j) - pocAdjustValue );
     617              }
     618              // Also adjust the value of refPOC
     619              for(Int k = 0; k < 2; k++)  // For List 0 and List 1
     620              {
     621                RefPicList list = (k == 1) ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
     622                for(Int j = 0; j < slice->getNumRefIdx(list); j++)
     623                {
     624                  slice->setRefPOC( slice->getRefPOC(list, j) - pocAdjustValue, list, j);
     625                }
     626              }
     627            }
     628          }
     629          iterPic++;
     630        }
     631        m_pcEncTop->setPocAdjustmentValue( m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue );
     632      }
     633      pcSlice->setPocValueBeforeReset( pcSlice->getPOC() - m_pcEncTop->getPocAdjustmentValue() + pocAdjustValue );
     634      pcSlice->setPOC( 0 );
     635    }
     636#endif
    506637#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    507638    if (m_pcEncTop->getAdaptiveResolutionChange() > 0 && m_layerId == 1 && pocCurr > m_pcEncTop->getAdaptiveResolutionChange())
     
    530661#endif
    531662
     663#if IL_SL_SIGNALLING_N0371
     664    m_pcEncTop->getScalingList()->setLayerId( m_layerId );
     665#endif
     666
    532667    pcSlice->setLastIDR(m_iLastIDR);
    533668    pcSlice->setSliceIdx(0);
     
    535670    pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
    536671    pcSlice->setScalingList ( m_pcEncTop->getScalingList()  );
    537     pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip());
    538672    if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
    539673    {
     674#if IL_SL_SIGNALLING_N0371
     675      m_pcEncTop->getTrQuant()->setFlatScalingList( m_layerId );
     676#else
    540677      m_pcEncTop->getTrQuant()->setFlatScalingList();
     678#endif
    541679      m_pcEncTop->getTrQuant()->setUseScalingList(false);
    542680      m_pcEncTop->getSPS()->setScalingListPresentFlag(false);
     
    545683    else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT)
    546684    {
     685#if IL_SL_SIGNALLING_N0371
     686      pcSlice->getScalingList()->setLayerId( m_layerId );
     687#endif
     688
     689#if IL_SL_SIGNALLING_N0371
     690      pcSlice->setDefaultScalingList ( m_layerId );
     691#else
    547692      pcSlice->setDefaultScalingList ();
     693#endif
     694
    548695      m_pcEncTop->getSPS()->setScalingListPresentFlag(false);
    549696      m_pcEncTop->getPPS()->setScalingListPresentFlag(false);
     
    553700    else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ)
    554701    {
     702#if IL_SL_SIGNALLING_N0371
     703      pcSlice->getScalingList()->setLayerId( m_layerId );
     704#endif
     705
    555706      if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile()))
    556707      {
     708#if IL_SL_SIGNALLING_N0371
     709        pcSlice->setDefaultScalingList ( m_layerId );
     710#else
    557711        pcSlice->setDefaultScalingList ();
    558       }
     712#endif
     713      }
     714#if IL_SL_SIGNALLING_N0371
     715      pcSlice->getScalingList()->checkDcOfMatrix( m_layerId );
     716#else
    559717      pcSlice->getScalingList()->checkDcOfMatrix();
     718#endif
    560719      m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList());
     720
     721#if IL_SL_SIGNALLING_N0371
     722      if( m_layerId > 0 )
     723      {
     724        m_pcEncTop->getSPS()->setPredScalingListFlag  (true);
     725        m_pcEncTop->getSPS()->setScalingListRefLayerId( 0 );
     726      }
     727#endif
     728
    561729      m_pcEncTop->getPPS()->setScalingListPresentFlag(false);
     730
     731#if IL_SL_SIGNALLING_N0371
     732      if( m_layerId > 0 )
     733      {
     734        m_pcEncTop->getPPS()->setPredScalingListFlag  (false);
     735        m_pcEncTop->getPPS()->setScalingListRefLayerId( 0   );
     736      }
     737#endif
     738
    562739      m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList());
    563740      m_pcEncTop->getTrQuant()->setUseScalingList(true);
     
    576753    pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR));
    577754#if SVC_EXTENSION
     755#if ILR_RESTR && ILR_RESTR_FIX
     756    Int interLayerPredLayerIdcTmp[MAX_VPS_LAYER_ID_PLUS1];
     757    Int activeNumILRRefIdxTmp = 0;
     758#endif
    578759    if (m_layerId > 0)
    579760    {
     
    588769        pcSlice->setBaseColPic( *cListPic, refLayerIdc );
    589770
    590 #if SIMPLIFIED_MV_POS_SCALING
     771#if ILR_RESTR && ILR_RESTR_FIX
     772        // Apply temporal layer restriction to inter-layer prediction
     773        Int maxTidIlRefPicsPlus1 = m_pcEncTop->getVPS()->getMaxTidIlRefPicsPlus1(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getLayerId());
     774        if( ((Int)(pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getTLayer())<=maxTidIlRefPicsPlus1-1) || (maxTidIlRefPicsPlus1==0 && pcSlice->getBaseColPic(refLayerIdc)->getSlice(0)->getRapPicFlag()) )
     775        {
     776          interLayerPredLayerIdcTmp[activeNumILRRefIdxTmp++] = refLayerIdc; // add picture to the list of valid inter-layer pictures
     777        }
     778        else
     779        {
     780          continue; // ILP is not valid due to temporal layer restriction
     781        }
     782#endif
     783
    591784#if SCALED_REF_LAYER_OFFSETS
    592785        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(refLayerIdc);
     
    612805        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
    613806        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
    614 #endif
    615807
    616808#if SVC_UPSAMPLING
    617809        if( pcPic->isSpatialEnhLayer(refLayerIdc))
    618         { 
     810        {
    619811#if SCALED_REF_LAYER_OFFSETS
    620812          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow(refLayerIdc) );
     
    630822#endif
    631823      }
    632     }
    633 #endif
    634 
    635 #if REF_IDX_FRAMEWORK
    636     if( m_layerId > 0 && (pocCurr % m_pcCfg->getIntraPeriod() == 0) )
    637     {
     824
     825#if ILR_RESTR && ILR_RESTR_FIX
     826      // Update the list of active inter-layer pictures
     827      for ( Int i = 0; i < activeNumILRRefIdxTmp; i++)
     828      {
     829        pcSlice->setInterLayerPredLayerIdc( interLayerPredLayerIdcTmp[i], i );
     830      }
     831      pcSlice->setActiveNumILRRefIdx( activeNumILRRefIdxTmp );
     832      if ( pcSlice->getActiveNumILRRefIdx() == 0 )
     833      {
     834        // No valid inter-layer pictures -> disable inter-layer prediction
     835        pcSlice->setInterLayerPredEnabledFlag(false);
     836      }
     837#endif
     838     
     839      if( pocCurr % m_pcCfg->getIntraPeriod() == 0 )
     840      {
     841#if N0147_IRAP_ALIGN_FLAG
     842        if(pcSlice->getVPS()->getCrossLayerIrapAlignFlag())
     843        {
     844          TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
     845          TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
     846          if(picLayer0)
     847          {
     848            pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
     849          }
     850          else
     851          {
     852            pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
     853          }
     854        }
     855        else
     856#endif
     857        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
     858
    638859#if IDR_ALIGNMENT
    639       TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
    640       TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
    641       if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
    642       {
    643         pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
    644       }
    645       else
    646 #endif
    647       pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
    648     }
    649 
    650     if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
    651     {
    652       pcSlice->setSliceType(I_SLICE);
    653     }
    654     else if( m_layerId > 0 && !m_pcEncTop->getElRapSliceTypeB() )
    655     {
    656       if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
    657           (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
     860        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
     861        TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
     862        if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
     863        {
     864          pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
     865        }
     866        else
     867        {
     868          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA);
     869        }
     870#endif
     871      }
     872     
     873      if( pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
     874      {
     875        pcSlice->setSliceType(I_SLICE);
     876      }
     877      else if( !m_pcEncTop->getElRapSliceTypeB() )
     878      {
     879        if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
     880           (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
    658881           pcSlice->getSliceType() == B_SLICE )
    659       {
    660         pcSlice->setSliceType(P_SLICE);
    661       }
    662     }
    663 #endif
     882        {
     883          pcSlice->setSliceType(P_SLICE);
     884        }
     885      }
     886    }
     887#endif //#if SVC_EXTENSION
    664888    if(pcSlice->getTemporalLayerNonReferenceFlag())
    665889    {
    666       if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
     890      if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
     891          !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
     892        // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker)
    667893      {
    668894        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
     
    700926      if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag())
    701927      {
     928#if ALIGN_TSA_STSA_PICS
     929        if( pcSlice->getLayerId() > 0 )
     930        {
     931          Bool oneRefLayerTSA = false, oneRefLayerNotTSA = false;
     932          for( Int i = 0; i < pcSlice->getLayerId(); i++)
     933          {
     934            TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic();
     935            TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC());
     936            if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) )
     937            {
     938              if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) ||
     939                  ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R )
     940                )
     941              {
     942                if(pcSlice->getTemporalLayerNonReferenceFlag() )
     943                {
     944                  pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N);
     945                }
     946                else
     947                {
     948                  pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R );
     949                }
     950                oneRefLayerTSA = true;
     951              }
     952              else
     953              {
     954                oneRefLayerNotTSA = true;
     955              }
     956            }
     957          }
     958          assert( !( oneRefLayerNotTSA && oneRefLayerTSA ) ); // Only one variable should be true - failure of this assert means
     959                                                                // that two independent reference layers that are not dependent on
     960                                                                // each other, but are reference for current layer have inconsistency
     961          if( oneRefLayerNotTSA /*&& !oneRefLayerTSA*/ )          // No reference layer is TSA - set current as TRAIL
     962          {
     963            if(pcSlice->getTemporalLayerNonReferenceFlag() )
     964            {
     965              pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N );
     966            }
     967            else
     968            {
     969              pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R );
     970            }
     971          }
     972          else  // This means there is no reference layer picture for current picture in this AU
     973          {
     974            if(pcSlice->getTemporalLayerNonReferenceFlag() )
     975            {
     976              pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N);
     977            }
     978            else
     979            {
     980              pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R );
     981            }
     982          }
     983        }
     984#else
    702985        if(pcSlice->getTemporalLayerNonReferenceFlag())
    703986        {
     
    708991          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
    709992        }
     993#endif
    710994      }
    711995      else if(pcSlice->isStepwiseTemporalLayerSwitchingPointCandidate(rcListPic))
     
    7411025        if(isSTSA==true)
    7421026        {   
     1027#if ALIGN_TSA_STSA_PICS
     1028          if( pcSlice->getLayerId() > 0 )
     1029          {
     1030            Bool oneRefLayerSTSA = false, oneRefLayerNotSTSA = false;
     1031            for( Int i = 0; i < pcSlice->getLayerId(); i++)
     1032            {
     1033              TComList<TComPic *> *cListPic = m_ppcTEncTop[i]->getListPic();
     1034              TComPic *lowerLayerPic = pcSlice->getRefPic(*cListPic, pcSlice->getPOC());
     1035              if( lowerLayerPic && pcSlice->getVPS()->getDirectDependencyFlag(pcSlice->getLayerId(), i) )
     1036              {
     1037                if( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_N ) ||
     1038                    ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_STSA_R )
     1039                  )
     1040                {
     1041                  if(pcSlice->getTemporalLayerNonReferenceFlag() )
     1042                  {
     1043                    pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
     1044                  }
     1045                  else
     1046                  {
     1047                    pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R );
     1048                  }
     1049                  oneRefLayerSTSA = true;
     1050                }
     1051                else
     1052                {
     1053                  oneRefLayerNotSTSA = true;
     1054                }
     1055              }
     1056            }
     1057            assert( !( oneRefLayerNotSTSA && oneRefLayerSTSA ) ); // Only one variable should be true - failure of this assert means
     1058                                                                  // that two independent reference layers that are not dependent on
     1059                                                                  // each other, but are reference for current layer have inconsistency
     1060            if( oneRefLayerNotSTSA /*&& !oneRefLayerSTSA*/ )          // No reference layer is STSA - set current as TRAIL
     1061            {
     1062              if(pcSlice->getTemporalLayerNonReferenceFlag() )
     1063              {
     1064                pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_N );
     1065              }
     1066              else
     1067              {
     1068                pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_TRAIL_R );
     1069              }
     1070            }
     1071            else  // This means there is no reference layer picture for current picture in this AU
     1072            {
     1073              if(pcSlice->getTemporalLayerNonReferenceFlag() )
     1074              {
     1075                pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N);
     1076              }
     1077              else
     1078              {
     1079                pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R );
     1080              }
     1081            }
     1082          }
     1083#else
    7431084          if(pcSlice->getTemporalLayerNonReferenceFlag())
    7441085          {
     
    7491090            pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R);
    7501091          }
     1092#endif
    7511093        }
    7521094      }
     
    7591101    pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures()));
    7601102
    761 #if REF_IDX_FRAMEWORK
     1103#if SVC_EXTENSION
    7621104    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
    7631105    {
    7641106#if RESTR_CHK
    765       if (pcSlice->getPOC()>0  && pcSlice->isRADL()&& pcPic->getSlice(0)->isRASL())
     1107#if POC_RESET_FLAG
     1108      if ( pocCurr > 0          && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
     1109#else
     1110      if (pcSlice->getPOC()>0  && pcSlice->isRADL() && pcPic->getSlice(0)->getBaseColPic(pcPic->getSlice(0)->getInterLayerPredLayerIdc(0))->getSlice(0)->isRASL())
     1111#endif
    7661112      {
    7671113#if JCTVC_M0458_INTERLAYER_RPS_SIG
     
    7971143#endif
    7981144    }
    799 #endif
     1145#endif //SVC_EXTENSION
    8001146
    8011147#if ADAPTIVE_QP_SELECTION
     
    8031149#endif     
    8041150
    805 #if REF_IDX_FRAMEWORK
     1151#if SVC_EXTENSION
    8061152#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
    8071153    if ( pcSlice->getSliceType() == B_SLICE && !(pcSlice->getActiveNumILRRefIdx() > 0 && m_pcEncTop->getNumMotionPredRefLayers() > 0) )
     
    8121158      pcSlice->setColFromL0Flag(1-uiColDir);
    8131159    }
    814 #endif
    8151160
    8161161    //  Set reference list
    817 #if REF_IDX_FRAMEWORK
    8181162    if(m_layerId ==  0 || ( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 ) )
    8191163    {
    8201164      pcSlice->setRefPicList( rcListPic);
    8211165    }
    822 #else
    823     pcSlice->setRefPicList ( rcListPic );
    824 #endif
    825 #if REF_IDX_FRAMEWORK
     1166
    8261167    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
    8271168    {
    8281169      m_pcEncTop->setILRPic(pcPic);
    829 
    8301170#if REF_IDX_MFM
    8311171#if M0457_COL_PICTURE_SIGNALING
     
    8401180#endif
    8411181      }
    842 #endif
     1182#else
     1183      //  Set reference list
     1184      pcSlice->setRefPicList ( rcListPic );
     1185#endif //SVC_EXTENSION
    8431186      pcSlice->setRefPicListModificationSvc();
    8441187      pcSlice->setRefPicList( rcListPic, false, m_pcEncTop->getIlpList());
     
    8901233#endif
    8911234    }
    892 #endif
     1235#else //SVC_EXTENSION
     1236    //  Set reference list
     1237    pcSlice->setRefPicList ( rcListPic );
     1238#endif //#if SVC_EXTENSION
    8931239
    8941240    //  Slice info. refinement
     
    9041250#endif
    9051251    {
    906 #if !REF_IDX_FRAMEWORK
     1252#if !SVC_EXTENSION
    9071253      pcSlice->setColFromL0Flag(1-uiColDir);
    9081254#endif
     
    10211367
    10221368      Int sliceQP = m_pcCfg->getInitialQP();
     1369#if POC_RESET_FLAG
     1370      if ( ( pocCurr == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
     1371#else
    10231372      if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified
     1373#endif
    10241374      {
    10251375        Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
     
    10711421      }
    10721422
     1423#if REPN_FORMAT_IN_VPS
     1424      sliceQP = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, sliceQP );
     1425#else
    10731426      sliceQP = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, sliceQP );
     1427#endif
    10741428      m_pcRateCtrl->getRCPic()->setPicEstQP( sliceQP );
    10751429
     
    10841438    UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
    10851439    UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1440#if REPN_FORMAT_IN_VPS
     1441    UInt uiWidth = pcSlice->getPicWidthInLumaSamples();
     1442    UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
     1443#else
    10861444    UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
    10871445    UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     1446#endif
    10881447    while(uiPosX>=uiWidth||uiPosY>=uiHeight)
    10891448    {
     
    11641523    //intialize each tile of the current picture
    11651524    pcPic->getPicSym()->xInitTiles();
     1525
     1526#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     1527    if (m_pcCfg->getInterLayerConstrainedTileSetsSEIEnabled())
     1528    {
     1529      xBuildTileSetsMap(pcPic->getPicSym());
     1530    }
     1531#endif
    11661532
    11671533    // Allocate some coders, now we know how many tiles there are.
     
    13101676    {
    13111677#if SVC_EXTENSION
     1678#if VPS_NUH_LAYER_ID
     1679      OutputNALUnit nalu(NAL_UNIT_VPS, 0, 0        ); // The value of nuh_layer_id of VPS NAL unit shall be equal to 0.
     1680#else
    13121681      OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId);
     1682#endif
    13131683#if AVC_BASE
    13141684      if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) )
     
    13331703#if SVC_EXTENSION
    13341704      nalu = NALUnit(NAL_UNIT_SPS, 0, m_layerId);
     1705#if IL_SL_SIGNALLING_N0371
     1706      pcSlice->getSPS()->setVPS( pcSlice->getVPS() );
     1707#endif
    13351708#else
    13361709      nalu = NALUnit(NAL_UNIT_SPS);
     
    14521825        }
    14531826      }
    1454       pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
     1827      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 .
     1828#if POC_RESET_FLAG
     1829      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded;
     1830#else
    14551831      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded;
     1832#endif
    14561833      Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2;
    14571834      pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay;
     
    15581935      SEIRecoveryPoint sei_recovery_point;
    15591936      sei_recovery_point.m_recoveryPocCnt    = 0;
     1937#if POC_RESET_FLAG
     1938      sei_recovery_point.m_exactMatchingFlag = ( pocCurr == 0 ) ? (true) : (false);
     1939#else
    15601940      sei_recovery_point.m_exactMatchingFlag = ( pcSlice->getPOC() == 0 ) ? (true) : (false);
     1941#endif
    15611942      sei_recovery_point.m_brokenLinkFlag    = false;
    15621943
     
    16192000            startCUAddrSliceSegmentIdx++;
    16202001          }
    1621 #if REF_IDX_FRAMEWORK && M0457_COL_PICTURE_SIGNALING
     2002#if SVC_EXTENSION && M0457_COL_PICTURE_SIGNALING
    16222003          pcSlice->setNumMotionPredRefLayers(m_pcEncTop->getNumMotionPredRefLayers());
    16232004#endif
     
    16322013          uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
    16332014          uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     2015
     2016#if REPN_FORMAT_IN_VPS
     2017          uiWidth = pcSlice->getPicWidthInLumaSamples();
     2018          uiHeight = pcSlice->getPicHeightInLumaSamples();
     2019#else
    16342020          uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
    16352021          uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     2022#endif
    16362023          while(uiPosX>=uiWidth||uiPosY>=uiHeight)
    16372024          {
     
    16882075          tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits();
    16892076#endif
     2077
    16902078          m_pcEntropyCoder->encodeSliceHeader(pcSlice);
     2079
    16912080#if RATE_CONTROL_LAMBDA_DOMAIN
    16922081          actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting );
     
    19752364      xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime );
    19762365
     2366      //In case of field coding, compute the interlaced PSNR for both fields
     2367      if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
     2368      {
     2369        //get complementary top field
     2370        TComPic* pcPicTop;
     2371        TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
     2372        while ((*iterPic)->getPOC() != pcPic->getPOC()-1)
     2373        {
     2374          iterPic ++;
     2375        }
     2376        pcPicTop = *(iterPic);
     2377        xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
     2378      }
     2379
    19772380      if (digestStr)
    19782381      {
     
    21072510            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    21082511          m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     2512          pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
    21092513          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
    21102514          writeRBSPTrailingBits(nalu.m_Bitstream);
     
    22252629
    22262630#if SVC_EXTENSION
    2227   assert ( m_iNumPicCoded <= 1 );
    2228 #else
    2229   assert ( m_iNumPicCoded == iNumPicRcvd );
     2631  assert ( m_iNumPicCoded <= 1 || (isField && iPOCLast == 1) );
     2632#else
     2633  assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) );
    22302634#endif
    22312635}
    22322636
    22332637#if !SVC_EXTENSION
    2234 Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
     2638Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, Bool isField)
    22352639{
    22362640  assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic());
     
    22382642   
    22392643  //--CFG_KDY
    2240   m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
    2241   m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
    2242   m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
    2243   m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
     2644  if(isField)
     2645  {
     2646    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2647    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2648    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2649    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2650  }
     2651   else
     2652  {
     2653    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
     2654    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
     2655    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
     2656    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
     2657  }
    22442658 
    22452659  //-- all
     
    22642678  m_gcAnalyzeB.printSummary('B');
    22652679#endif
     2680
     2681  if(isField)
     2682  {
     2683    //-- interlaced summary
     2684    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate());
     2685    printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
     2686    m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll.getBits());
     2687   
     2688#if _SUMMARY_OUT_
     2689    m_gcAnalyzeAll_in.printSummaryOutInterlaced();
     2690#endif
     2691  }
    22662692
    22672693  printf("\nRVM: %.3lf\n" , xCalculateRVM());
     
    23052731// ====================================================================================================================
    23062732
     2733
     2734Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField )
     2735{
     2736  assert( iNumPicRcvd > 0 );
     2737  //  Exception for the first frames
     2738  if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField  && (iPOCLast == 0))  )
     2739  {
     2740    m_iGopSize    = 1;
     2741  }
     2742  else
     2743  {
     2744    m_iGopSize    = m_pcCfg->getGOPSize();
     2745  }
     2746  assert (m_iGopSize > 0);
     2747 
     2748  return;
     2749}
     2750
    23072751Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut )
    23082752{
     
    23272771                         TComPic*&                 rpcPic,
    23282772                         TComPicYuv*&              rpcPicYuvRecOut,
    2329                          Int                       pocCurr )
     2773                         Int                       pocCurr,
     2774                         Bool                      isField)
    23302775{
    23312776  Int i;
    23322777  //  Rec. output
    23332778  TComList<TComPicYuv*>::iterator     iterPicYuvRec = rcListPicYuvRecOut.end();
    2334   for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ )
    2335   {
    2336     iterPicYuvRec--;
    2337   }
    2338  
     2779
     2780  if (isField)
     2781  {
     2782    for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ )
     2783    {
     2784      iterPicYuvRec--;
     2785    }
     2786  }
     2787  else
     2788  {
     2789    for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ )
     2790    {
     2791      iterPicYuvRec--;
     2792    }
     2793  }
     2794 
     2795  if (isField)
     2796  {
     2797    if(pocCurr == 1)
     2798    {
     2799      iterPicYuvRec++;
     2800    }
     2801  }
    23392802  rpcPicYuvRecOut = *(iterPicYuvRec);
    23402803 
     
    24212884  switch (type)
    24222885  {
    2423     case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
    2424     case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
     2886    case NAL_UNIT_CODED_SLICE_TRAIL_R:    return "TRAIL_R";
     2887    case NAL_UNIT_CODED_SLICE_TRAIL_N:    return "TRAIL_N";
    24252888    case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
    2426     case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
    2427     case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
    2428     case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N";
     2889    case NAL_UNIT_CODED_SLICE_TSA_N:      return "TSA_N";
     2890    case NAL_UNIT_CODED_SLICE_STSA_R:     return "STSA_R";
     2891    case NAL_UNIT_CODED_SLICE_STSA_N:     return "STSA_N";
    24292892    case NAL_UNIT_CODED_SLICE_BLA_W_LP:   return "BLA_W_LP";
    24302893    case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
    2431     case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP";
     2894    case NAL_UNIT_CODED_SLICE_BLA_N_LP:   return "BLA_N_LP";
    24322895    case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
    2433     case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP";
    2434     case NAL_UNIT_CODED_SLICE_CRA: return "CRA";
     2896    case NAL_UNIT_CODED_SLICE_IDR_N_LP:   return "IDR_N_LP";
     2897    case NAL_UNIT_CODED_SLICE_CRA:        return "CRA";
    24352898    case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
    24362899    case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
    2437     case NAL_UNIT_VPS: return "VPS";
    2438     case NAL_UNIT_SPS: return "SPS";
    2439     case NAL_UNIT_PPS: return "PPS";
    2440     case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD";
    2441     case NAL_UNIT_EOS: return "EOS";
    2442     case NAL_UNIT_EOB: return "EOB";
    2443     case NAL_UNIT_FILLER_DATA: return "FILLER";
     2900    case NAL_UNIT_VPS:                    return "VPS";
     2901    case NAL_UNIT_SPS:                    return "SPS";
     2902    case NAL_UNIT_PPS:                    return "PPS";
     2903    case NAL_UNIT_ACCESS_UNIT_DELIMITER:  return "AUD";
     2904    case NAL_UNIT_EOS:                    return "EOS";
     2905    case NAL_UNIT_EOB:                    return "EOB";
     2906    case NAL_UNIT_FILLER_DATA:            return "FILLER";
    24442907    case NAL_UNIT_PREFIX_SEI:             return "SEI";
    24452908    case NAL_UNIT_SUFFIX_SEI:             return "SEI";
    2446     default: return "UNK";
     2909    default:                              return "UNK";
    24472910  }
    24482911}
     
    26253088    for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++)
    26263089    {
    2627 #if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS
     3090#if SVC_EXTENSION
     3091#if VPS_EXTN_DIRECT_REF_LAYERS
    26283092      if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) )
    26293093      {
    2630         printf( "%d(%d) ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
     3094        printf( "%d(%d)", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() );
    26313095      }
    26323096      else
    2633 #endif
     3097      {
     3098        printf ("%d", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
     3099      }
     3100#endif
     3101      if( pcSlice->getEnableTMVPFlag() && iRefList == 1 - pcSlice->getColFromL0Flag() && iRefIndex == pcSlice->getColRefIdx() )
     3102      {
     3103        printf( "c" );
     3104      }
     3105
     3106      printf( " " );
     3107#else
    26343108      printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR());
     3109#endif
    26353110    }
    26363111    printf("]");
    26373112  }
     3113}
     3114
     3115
     3116Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, Bool isTff)
     3117{
     3118 
     3119  for (Int y = 0; y < height; y++)
     3120  {
     3121    for (Int x = 0; x < width; x++)
     3122    {
     3123      dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
     3124      dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     3125    }
     3126    top += stride;
     3127    bottom += stride;
     3128    dst += stride*2;
     3129  }
     3130}
     3131
     3132Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime )
     3133{
     3134  Int     x, y;
     3135 
     3136  UInt64 uiSSDY_in  = 0;
     3137  UInt64 uiSSDU_in  = 0;
     3138  UInt64 uiSSDV_in  = 0;
     3139 
     3140  Double  dYPSNR_in  = 0.0;
     3141  Double  dUPSNR_in  = 0.0;
     3142  Double  dVPSNR_in  = 0.0;
     3143 
     3144  /*------ INTERLACED PSNR -----------*/
     3145 
     3146  /* Luma */
     3147 
     3148  Pel*  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr();
     3149  Pel*  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr();
     3150  Pel*  pRecTop = pcPicRecTop->getLumaAddr();
     3151  Pel*  pRecBottom = pcPicRecBottom->getLumaAddr();
     3152 
     3153  Int   iWidth;
     3154  Int   iHeight;
     3155  Int iStride;
     3156 
     3157  iWidth  = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0);
     3158  iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1);
     3159  iStride = pcPicOrgTop->getPicYuvOrg()->getStride();
     3160  Int   iSize   = iWidth*iHeight;
     3161  bool isTff = pcPicOrgTop->isTopField();
     3162 
     3163  TComPicYuv* pcOrgInterlaced = new TComPicYuv;
     3164  pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     3165 
     3166  TComPicYuv* pcRecInterlaced = new TComPicYuv;
     3167  pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     3168 
     3169  Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr();
     3170  Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr();
     3171 
     3172  //=== Interlace fields ====
     3173  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3174  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3175 
     3176  //===== calculate PSNR =====
     3177  for( y = 0; y < iHeight << 1; y++ )
     3178  {
     3179    for( x = 0; x < iWidth; x++ )
     3180    {
     3181      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3182      uiSSDY_in   += iDiff * iDiff;
     3183    }
     3184    pOrgInterlaced += iStride;
     3185    pRecInterlaced += iStride;
     3186  }
     3187 
     3188  /*Chroma*/
     3189 
     3190  iHeight >>= 1;
     3191  iWidth  >>= 1;
     3192  iStride >>= 1;
     3193 
     3194  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr();
     3195  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr();
     3196  pRecTop = pcPicRecTop->getCbAddr();
     3197  pRecBottom = pcPicRecBottom->getCbAddr();
     3198  pOrgInterlaced = pcOrgInterlaced->getCbAddr();
     3199  pRecInterlaced = pcRecInterlaced->getCbAddr();
     3200 
     3201  //=== Interlace fields ====
     3202  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3203  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3204 
     3205  //===== calculate PSNR =====
     3206  for( y = 0; y < iHeight << 1; y++ )
     3207  {
     3208    for( x = 0; x < iWidth; x++ )
     3209    {
     3210      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3211      uiSSDU_in   += iDiff * iDiff;
     3212    }
     3213    pOrgInterlaced += iStride;
     3214    pRecInterlaced += iStride;
     3215  }
     3216 
     3217  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr();
     3218  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr();
     3219  pRecTop = pcPicRecTop->getCrAddr();
     3220  pRecBottom = pcPicRecBottom->getCrAddr();
     3221  pOrgInterlaced = pcOrgInterlaced->getCrAddr();
     3222  pRecInterlaced = pcRecInterlaced->getCrAddr();
     3223 
     3224  //=== Interlace fields ====
     3225  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3226  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3227 
     3228  //===== calculate PSNR =====
     3229  for( y = 0; y < iHeight << 1; y++ )
     3230  {
     3231    for( x = 0; x < iWidth; x++ )
     3232    {
     3233      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3234      uiSSDV_in   += iDiff * iDiff;
     3235    }
     3236    pOrgInterlaced += iStride;
     3237    pRecInterlaced += iStride;
     3238  }
     3239 
     3240  Int maxvalY = 255 << (g_bitDepthY-8);
     3241  Int maxvalC = 255 << (g_bitDepthC-8);
     3242  Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2;
     3243  Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0;
     3244  dYPSNR_in            = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 );
     3245  dUPSNR_in            = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 );
     3246  dVPSNR_in            = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 );
     3247 
     3248  /* calculate the size of the access unit, excluding:
     3249   *  - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
     3250   *  - SEI NAL units
     3251   */
     3252  UInt numRBSPBytes = 0;
     3253  for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
     3254  {
     3255    UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
     3256   
     3257    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
     3258      numRBSPBytes += numRBSPBytes_nal;
     3259  }
     3260 
     3261  UInt uibits = numRBSPBytes * 8 ;
     3262 
     3263  //===== add PSNR =====
     3264  m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits);
     3265 
     3266  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 );
     3267 
     3268  pcOrgInterlaced->destroy();
     3269  delete pcOrgInterlaced;
     3270  pcRecInterlaced->destroy();
     3271  delete pcRecInterlaced;
    26383272}
    26393273
     
    28723506  return seiStartPos;
    28733507}
     3508
     3509#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     3510Void TEncGOP::xBuildTileSetsMap(TComPicSym* picSym)
     3511{
     3512  Int numCUs = picSym->getFrameWidthInCU() * picSym->getFrameHeightInCU();
     3513
     3514  for (Int i = 0; i < numCUs; i++)
     3515  {
     3516    picSym->setTileSetIdxMap(i, -1, 0, false);
     3517  }
     3518
     3519  for (Int i = 0; i < m_pcCfg->getIlNumSetsInMessage(); i++)
     3520  {
     3521    TComTile* topLeftTile     = picSym->getTComTile(m_pcCfg->getTopLeftTileIndex(i));
     3522    TComTile* bottomRightTile = picSym->getTComTile(m_pcCfg->getBottomRightTileIndex(i));
     3523    Int tileSetLeftEdgePosInCU = topLeftTile->getRightEdgePosInCU() - topLeftTile->getTileWidth() + 1;
     3524    Int tileSetRightEdgePosInCU = bottomRightTile->getRightEdgePosInCU();
     3525    Int tileSetTopEdgePosInCU = topLeftTile->getBottomEdgePosInCU() - topLeftTile->getTileHeight() + 1;
     3526    Int tileSetBottomEdgePosInCU = bottomRightTile->getBottomEdgePosInCU();
     3527    assert(tileSetLeftEdgePosInCU < tileSetRightEdgePosInCU && tileSetTopEdgePosInCU < tileSetBottomEdgePosInCU);
     3528    for (Int j = tileSetTopEdgePosInCU; j <= tileSetBottomEdgePosInCU; j++)
     3529    {
     3530      for (Int k = tileSetLeftEdgePosInCU; k <= tileSetRightEdgePosInCU; k++)
     3531      {
     3532        picSym->setTileSetIdxMap(j * picSym->getFrameWidthInCU() + k, i, m_pcCfg->getIlcIdc(i), false);
     3533      }
     3534    }
     3535  }
     3536 
     3537  if (m_pcCfg->getSkippedTileSetPresentFlag())
     3538  {
     3539    Int skippedTileSetIdx = m_pcCfg->getIlNumSetsInMessage();
     3540    for (Int i = 0; i < numCUs; i++)
     3541    {
     3542      if (picSym->getTileSetIdxMap(i) < 0)
     3543      {
     3544        picSym->setTileSetIdxMap(i, skippedTileSetIdx, 0, true);
     3545      }
     3546    }
     3547  }
     3548}
     3549#endif
    28743550
    28753551Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices )
  • trunk/source/Lib/TLibEncoder/TEncGOP.h

    r345 r442  
    145145  Void  init        ( TEncTop* pcTEncTop );
    146146#if SVC_EXTENSION
    147   Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
     147  Void  compressGOP ( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
    148148#else
    149   Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP );
     149  Void  compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff );
    150150#endif
    151151  Void  xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect);
     
    156156  TComList<TComPic*>*   getListPic()      { return m_pcListPic; }
    157157 
    158   Void  printOutSummary      ( UInt uiNumAllPicCoded );
     158#if !SVC_EXTENSION
     159  Void  printOutSummary      ( UInt uiNumAllPicCoded, Bool isField);
     160#endif
    159161  Void  preLoopFilterPicAll  ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits );
    160162 
     
    166168
    167169protected:
     170 
     171  Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField );
    168172  Void  xInitGOP          ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut );
    169   Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr );
     173  Void  xGetBuffer        ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField );
    170174 
    171175  Void  xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime );
     176  Void  xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime );
    172177 
    173178  UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1);
     
    183188
    184189  SEIToneMappingInfo*     xCreateSEIToneMappingInfo();
     190
     191#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     192  SEIInterLayerConstrainedTileSets* xCreateSEIInterLayerConstrainedTileSets();
     193#endif
    185194
    186195  Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps);
     
    197206    m_nestedPictureTimingSEIPresentInAU      = false;
    198207  }
     208#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     209  Void xBuildTileSetsMap(TComPicSym* picSym);
     210#endif
    199211  Void dblMetric( TComPic* pcPic, UInt uiNumSlices );
    200212#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
  • trunk/source/Lib/TLibEncoder/TEncSbac.cpp

    r345 r442  
    804804  Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
    805805 
     806#if REPN_FORMAT_IN_VPS
     807  Int qpBdOffsetY =  pcCU->getSlice()->getQpBDOffsetY();
     808#else
    806809  Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
     810#endif
    807811  iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
    808812
  • trunk/source/Lib/TLibEncoder/TEncSearch.cpp

    r345 r442  
    11041104  pcCU       ->setTrIdxSubParts ( uiTrDepth, uiAbsPartIdx, uiFullDepth );
    11051105
     1106#if REPN_FORMAT_IN_VPS
     1107  m_pcTrQuant->setQPforQuant    ( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
     1108#else
    11061109  m_pcTrQuant->setQPforQuant    ( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
     1110#endif
    11071111
    11081112#if RDOQ_CHROMA_LAMBDA
     
    32173221  Int numValidMergeCand = 0 ;
    32183222
     3223#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     3224  Bool disableILP = false;
     3225  if (pcCU->getPic()->getLayerId() == (m_pcEncCfg->getNumLayer() - 1)  && m_pcEncCfg->getInterLayerConstrainedTileSetsSEIEnabled() && pcCU->getPic()->getPicSym()->getTileSetIdxMap(pcCU->getAddr()) >= 0)
     3226  {
     3227    if (pcCU->getPic()->getPicSym()->getTileSetType(pcCU->getAddr()) == 2)
     3228    {
     3229      disableILP = true;
     3230    }
     3231    if (pcCU->getPic()->getPicSym()->getTileSetType(pcCU->getAddr()) == 1)
     3232    {
     3233      Int currCUaddr = pcCU->getAddr();
     3234      Int frameWitdhInCU  = pcCU->getPic()->getPicSym()->getFrameWidthInCU();
     3235      Int frameHeightInCU = pcCU->getPic()->getPicSym()->getFrameHeightInCU();
     3236      Bool leftCUExists   = (currCUaddr % frameWitdhInCU) > 0;
     3237      Bool aboveCUExists  = (currCUaddr / frameWitdhInCU) > 0;
     3238      Bool rightCUExists  = (currCUaddr % frameWitdhInCU) < (frameWitdhInCU - 1);
     3239      Bool belowCUExists  = (currCUaddr / frameWitdhInCU) < (frameHeightInCU - 1);
     3240      Int currTileSetIdx  = pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr);
     3241      // Check if CU is at tile set boundary
     3242      if ( (leftCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-1) != currTileSetIdx) ||
     3243           (leftCUExists && aboveCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU-1) != currTileSetIdx) ||
     3244           (aboveCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU) != currTileSetIdx) ||
     3245           (aboveCUExists && rightCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr-frameWitdhInCU+1) != currTileSetIdx) ||
     3246           (rightCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+1) != currTileSetIdx) ||
     3247           (rightCUExists && belowCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU+1) != currTileSetIdx) ||
     3248           (belowCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU) != currTileSetIdx) ||
     3249           (belowCUExists && leftCUExists && pcCU->getPic()->getPicSym()->getTileIdxMap(currCUaddr+frameWitdhInCU-1) != currTileSetIdx) )
     3250      {
     3251        disableILP = true;  // Disable ILP in tile set boundary CU
     3252      }
     3253    }
     3254  }
     3255#endif
     3256
    32193257  for ( Int iPartIdx = 0; iPartIdx < iNumPart; iPartIdx++ )
    32203258  {
     
    32663304      for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
    32673305      {
     3306#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     3307        if (pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp )->isILR(pcCU->getLayerId()) && disableILP)
     3308        {
     3309          continue;
     3310        }
     3311#endif
    32683312#if (ENCODER_FAST_MODE)
    32693313        TComPic* pcPic    = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp );
     
    34843528          testIter = false;  //the fixed part is ILR, skip this iteration       
    34853529        }
     3530#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     3531        if (pcPic->isILR(pcCU->getLayerId()) && disableILP)
     3532        {
     3533          testIter = false;
     3534        }
     3535#endif
    34863536        if(testIter)
    34873537        {
     
    34993549            testRefIdx = false;  //the refined part is ILR, skip this reference pic           
    35003550          }
     3551#if N0383_IL_CONSTRAINED_TILE_SETS_SEI
     3552          if (pcPic->isILR(pcCU->getLayerId()) && disableILP)
     3553          {
     3554            testRefIdx = false;
     3555          }
     3556#endif
    35013557          if(testRefIdx)
    35023558          {
     
    46104666  while((uiWidth>>uiMaxTrMode) < (g_uiMaxCUWidth>>g_uiMaxCUDepth)) uiMaxTrMode--;
    46114667 
     4668#if REPN_FORMAT_IN_VPS
     4669  qpMin =  bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 );
     4670  qpMax =  bHighPass ? Clip3( -pcCU->getSlice()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) + m_iMaxDeltaQP ) : pcCU->getQP( 0 );
     4671#else
    46124672  qpMin =  bHighPass ? Clip3( -pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) - m_iMaxDeltaQP ) : pcCU->getQP( 0 );
    46134673  qpMax =  bHighPass ? Clip3( -pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, pcCU->getQP(0) + m_iMaxDeltaQP ) : pcCU->getQP( 0 );
     4674#endif
    46144675
    46154676  rpcYuvResi->subtract( pcYuvOrg, pcYuvPred, 0, uiWidth );
     
    48604921    }
    48614922
     4923#if REPN_FORMAT_IN_VPS
     4924    m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
     4925#else
    48624926    m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
     4927#endif
    48634928
    48644929#if RDOQ_CHROMA_LAMBDA
     
    49465011      Pel *pcResiCurrY = m_pcQTTempTComYuv[ uiQTTempAccessLayer ].getLumaAddr( absTUPartIdx );
    49475012
     5013#if REPN_FORMAT_IN_VPS
    49485014      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
     5015#else
     5016      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
     5017#endif
    49495018
    49505019      Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
     
    51955264      }
    51965265
     5266#if REPN_FORMAT_IN_VPS
     5267      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
     5268#else
    51975269      m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
     5270#endif
    51985271
    51995272#if RDOQ_CHROMA_LAMBDA
     
    52145287        const UInt uiTsSingleBitsY = m_pcEntropyCoder->getNumberOfWrittenBits();
    52155288
     5289#if REPN_FORMAT_IN_VPS
     5290        m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getQpBDOffsetY(), 0 );
     5291#else
    52165292        m_pcTrQuant->setQPforQuant( pcCU->getQP( 0 ), TEXT_LUMA, pcCU->getSlice()->getSPS()->getQpBDOffsetY(), 0 );
     5293#endif
    52175294
    52185295        Int scalingListType = 3 + g_eTTable[(Int)TEXT_LUMA];
  • trunk/source/Lib/TLibEncoder/TEncSlice.cpp

    r345 r442  
    180180#if SVC_EXTENSION
    181181//\param vps          VPS associated with the slice
    182 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps )
    183 #else
    184 Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS )
     182Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps, Bool isField )
     183#else
     184Void TEncSlice::initEncSlice( TComPic* pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd, Int iGOPid, TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, Bool isField )
    185185#endif
    186186{
     
    260260  if(eSliceType!=I_SLICE)
    261261  {
     262#if REPN_FORMAT_IN_VPS
     263    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
     264#else
    262265    if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getSPS()->getUseLossless())))
     266#endif
    263267    {
    264268      dQP += m_pcCfg->getGOPEntry(iGOPid).m_QPOffset;
     
    294298    Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    295299    Int    SHIFT_QP = 12;
    296     Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );
     300
     301    Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)(isField ? NumberBFrames/2 : NumberBFrames) );
     302
    297303#if FULL_NBIT
    298304    Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
     
    327333    }
    328334   
     335#if REPN_FORMAT_IN_VPS
     336    iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
     337#else
    329338    iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
     339#endif
    330340
    331341    m_pdRdPicLambda[iDQpIdx] = dLambda;
     
    400410  eSliceType = (pocLast == 0 || pocCurr % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;
    401411 
    402 #if REF_IDX_FRAMEWORK
     412#if SVC_EXTENSION
    403413  if(m_pcCfg->getLayerId() > 0)
    404414  {
     
    412422  {
    413423    dQP = xGetQPValueAccordingToLambda( dLambda );
     424#if REPN_FORMAT_IN_VPS
     425    iQP = max( -rpcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );   
     426#else
    414427    iQP = max( -pSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );   
     428#endif
    415429  }
    416430
     
    467481 
    468482  pcPic->setTLayer( m_pcCfg->getGOPEntry(iGOPid).m_temporalId );
     483#if TEMP_SCALABILITY_FIX
     484  if((eSliceType==I_SLICE) || (rpcSlice->getPOC() == 0))
     485#else
    469486  if(eSliceType==I_SLICE)
     487#endif
    470488  {
    471489    pcPic->setTLayer(0);
     
    485503  xStoreWPparam( pPPS->getUseWP(), pPPS->getWPBiPred() );
    486504
    487 #if SVC_EXTENSION && REF_IDX_FRAMEWORK
     505#if SVC_EXTENSION
    488506  if( layerId > 0 )
    489507  {
     
    606624    }
    607625
     626#if REPN_FORMAT_IN_VPS
     627    qp = max( -pcSlice->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
     628#else
    608629    qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );
     630#endif
    609631
    610632    m_pdRdPicLambda[deltqQpIdx] = lambda;
     
    849871    pcCU->initCU( rpcPic, uiCUAddr );
    850872
     873#if REPN_FORMAT_IN_VPS
     874    Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     875    Int width   = min( pcSlice->getSPS()->getMaxCUWidth(), pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     876#else
    851877    Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    852878    Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     879#endif
    853880
    854881    iSumHad = m_pcCuEncoder->updateLCUDataISlice(pcCU, uiCUAddr, width, height);
     
    11481175#endif
    11491176
     1177#if REPN_FORMAT_IN_VPS
     1178          estQP     = Clip3( -pcSlice->getQpBDOffsetY(), MAX_QP, estQP );
     1179#else
    11501180          estQP     = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, estQP );
     1181#endif
    11511182
    11521183          m_pcRdCost->setLambda(estLambda);
     
    11761207#if !M0036_RC_IMPROVEMENT
    11771208        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
     1209#if REPN_FORMAT_IN_VPS
     1210        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     1211        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->>getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     1212#else
    11781213        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    11791214        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     1215#endif
    11801216        Double MAD = (Double)SAD / (Double)(height * width);
    11811217        MAD = MAD * MAD;
     
    12531289#if !M0036_RC_IMPROVEMENT
    12541290        UInt SAD    = m_pcCuEncoder->getLCUPredictionSAD();
     1291#if REPN_FORMAT_IN_VPS
     1292        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
     1293        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     1294#else
    12551295        Int height  = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );
    12561296        Int width   = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );
     1297#endif
    12571298        Double MAD = (Double)SAD / (Double)(height * width);
    12581299        MAD = MAD * MAD;
     
    19191960  UInt uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
    19201961  UInt uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1962#if REPN_FORMAT_IN_VPS
     1963  UInt uiWidth = pcSlice->getPicWidthInLumaSamples();
     1964  UInt uiHeight = pcSlice->getPicHeightInLumaSamples();
     1965#else
    19211966  UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
    19221967  UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     1968#endif
    19231969  while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
    19241970  {
     
    19421988  uiPosX = ( uiExternalAddress % rpcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ];
    19431989  uiPosY = ( uiExternalAddress / rpcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ];
     1990#if REPN_FORMAT_IN_VPS
     1991  uiWidth = pcSlice->getPicWidthInLumaSamples();
     1992  uiHeight = pcSlice->getPicHeightInLumaSamples();
     1993#else
    19441994  uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples();
    19451995  uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples();
     1996#endif
    19461997  while((uiPosX>=uiWidth||uiPosY>=uiHeight)&&!(uiPosX>=uiWidth&&uiPosY>=uiHeight))
    19471998  {
  • trunk/source/Lib/TLibEncoder/TEncSlice.h

    r313 r442  
    118118#if SVC_EXTENSION
    119119  Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
    120                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps );
     120                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, TComVPS *vps, Bool isField );
    121121#else
    122122  Void    initEncSlice        ( TComPic*  pcPic, Int pocLast, Int pocCurr, Int iNumPicRcvd,
    123                                 Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS );
     123                                Int iGOPid,   TComSlice*& rpcSlice, TComSPS* pSPS, TComPPS *pPPS, Bool isField );
    124124#endif
    125125
  • trunk/source/Lib/TLibEncoder/TEncTop.cpp

    r345 r442  
    8383  m_pcBitCounters          = NULL;
    8484  m_pcRdCosts              = NULL;
    85 #if REF_IDX_FRAMEWORK
     85#if SVC_EXTENSION
    8686  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
    87 #endif
    8887#if REF_IDX_MFM
    8988  m_bMFMEnabledFlag = false;
     
    9190#if SCALED_REF_LAYER_OFFSETS
    9291  m_numScaledRefLayerOffsets = 0;
     92#endif
     93#endif
     94#if POC_RESET_FLAG
     95  m_pocAdjustmentValue     = 0;
    9396#endif
    9497}
     
    107110  initROM();
    108111#endif
    109  
     112
    110113  // create processing unit classes
    111114#if SVC_EXTENSION
     
    288291  delete[] m_pcRdCosts;
    289292 
    290 #if !SVC_EXTENSION
    291   // destroy ROM
    292   destroyROM();
    293 #endif
    294 #if REF_IDX_FRAMEWORK
     293#if SVC_EXTENSION
    295294  for(Int i=0; i<MAX_NUM_REF; i++)
    296295  {
     
    301300      m_cIlpPic[i] = NULL;
    302301    }
    303   }   
     302  }
     303#else
     304  // destroy ROM
     305  destroyROM();
    304306#endif
    305307  return;
    306308}
    307309
    308 Void TEncTop::init()
     310Void TEncTop::init(Bool isFieldCoding)
    309311{
    310312  // initialize SPS
     
    317319  m_cPPS.setSPS(&m_cSPS);
    318320  xInitPPS();
    319   xInitRPS();
     321  xInitRPS(isFieldCoding);
    320322
    321323  xInitPPSforTiles();
     
    346348  m_iSPSIdCnt ++;
    347349  m_iPPSIdCnt ++;
    348 #endif
    349 #if REF_IDX_FRAMEWORK
    350350  xInitILRP();
    351351#endif
     
    396396
    397397  // compress GOP
    398   m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
     398  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    399399
    400400#if RATE_CONTROL_LAMBDA_DOMAIN
     
    456456
    457457  // compress GOP
    458   m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut);
     458
     459  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
    459460
    460461#if RATE_CONTROL_LAMBDA_DOMAIN
     
    467468  iNumEncoded         = m_iNumPicRcvd;
    468469  m_iNumPicRcvd       = 0;
     470  m_uiNumAllPicCoded += iNumEncoded;
     471}
     472#endif
     473
     474/**------------------------------------------------
     475 Separate interlaced frame into two fields
     476 -------------------------------------------------**/
     477void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
     478{
     479  if (!isTop)
     480  {
     481    org += stride;
     482  }
     483  for (Int y = 0; y < height>>1; y++)
     484  {
     485    for (Int x = 0; x < width; x++)
     486    {
     487      dstField[x] = org[x];
     488    }
     489   
     490    dstField += stride;
     491    org += stride*2;
     492  }
     493 
     494}
     495
     496#if SVC_EXTENSION
     497Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff )
     498{
     499  if (pcPicYuvOrg)
     500  {
     501    /* -- TOP FIELD -- */
     502    /* -- Top field initialization -- */
     503   
     504    TComPic *pcTopField;
     505    xGetNewPicBuffer( pcTopField );
     506    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     507    pcTopField->setReconMark (false);
     508   
     509    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
     510    pcTopField->getPicYuvRec()->setBorderExtension(false);
     511    pcTopField->setTopField(isTff);
     512   
     513    Int nHeight = pcPicYuvOrg->getHeight();
     514    Int nWidth = pcPicYuvOrg->getWidth();
     515    Int nStride = pcPicYuvOrg->getStride();
     516    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
     517    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
     518   
     519    // Get pointers
     520    Pel * PicBufY = pcPicYuvOrg->getBufY();
     521    Pel * PicBufU = pcPicYuvOrg->getBufU();
     522    Pel * PicBufV = pcPicYuvOrg->getBufV();
     523   
     524    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
     525    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
     526    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
     527   
     528    // compute image characteristics
     529    if ( getUseAdaptiveQP() )
     530    {
     531      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
     532    }
     533   
     534    /* -- Defield -- */
     535   
     536    Bool isTop = isTff;
     537   
     538    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
     539    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     540    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     541
     542    /* -- BOTTOM FIELD -- */
     543    /* -- Bottom field initialization -- */
     544   
     545    TComPic* pcBottomField;
     546    xGetNewPicBuffer( pcBottomField );
     547    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     548    pcBottomField->setReconMark (false);
     549   
     550    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
     551    pcBottomField->getPicYuvRec()->setBorderExtension(false);
     552    pcBottomField->setTopField(!isTff);
     553   
     554    nHeight = pcPicYuvOrg->getHeight();
     555    nWidth = pcPicYuvOrg->getWidth();
     556    nStride = pcPicYuvOrg->getStride();
     557    nPadLuma = pcPicYuvOrg->getLumaMargin();
     558    nPadChroma = pcPicYuvOrg->getChromaMargin();
     559   
     560    // Get pointers
     561    PicBufY = pcPicYuvOrg->getBufY();
     562    PicBufU = pcPicYuvOrg->getBufU();
     563    PicBufV = pcPicYuvOrg->getBufV();
     564   
     565    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
     566    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
     567    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
     568   
     569    // Compute image characteristics
     570    if ( getUseAdaptiveQP() )
     571    {
     572      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
     573    }
     574   
     575    /* -- Defield -- */
     576   
     577    isTop = !isTff;
     578   
     579    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
     580    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     581    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     582   
     583  }
     584}
     585
     586Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff )
     587{
     588  // compress GOP
     589  if (m_iPOCLast == 0) // compress field 0
     590  {
     591    m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     592  }
     593
     594  if (pcPicYuvOrg)
     595  {
     596    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
     597    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
     598    {
     599      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
     600    }
     601    else
     602    {
     603      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     604    }
     605    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
     606  }
     607 
     608  // compress GOP
     609  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     610
     611  m_uiNumAllPicCoded ++;
     612}
     613#else
     614Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
     615{
     616  /* -- TOP FIELD -- */
     617 
     618  if (pcPicYuvOrg)
     619  {
     620   
     621    /* -- Top field initialization -- */
     622   
     623    TComPic *pcTopField;
     624    xGetNewPicBuffer( pcTopField );
     625    pcTopField->getPicSym()->allocSaoParam(&m_cEncSAO);
     626    pcTopField->setReconMark (false);
     627   
     628    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
     629    pcTopField->getPicYuvRec()->setBorderExtension(false);
     630    pcTopField->setTopField(isTff);
     631   
     632    Int nHeight = pcPicYuvOrg->getHeight();
     633    Int nWidth = pcPicYuvOrg->getWidth();
     634    Int nStride = pcPicYuvOrg->getStride();
     635    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
     636    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
     637   
     638    // Get pointers
     639    Pel * PicBufY = pcPicYuvOrg->getBufY();
     640    Pel * PicBufU = pcPicYuvOrg->getBufU();
     641    Pel * PicBufV = pcPicYuvOrg->getBufV();
     642   
     643    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
     644    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
     645    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
     646   
     647    // compute image characteristics
     648    if ( getUseAdaptiveQP() )
     649    {
     650      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
     651    }
     652   
     653    /* -- Defield -- */
     654   
     655    Bool isTop = isTff;
     656   
     657    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
     658    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     659    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     660   
     661  }
     662 
     663  if (m_iPOCLast == 0) // compress field 0
     664  {
     665    m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     666  }
     667 
     668  /* -- BOTTOM FIELD -- */
     669 
     670  if (pcPicYuvOrg)
     671  {
     672   
     673    /* -- Bottom field initialization -- */
     674   
     675    TComPic* pcBottomField;
     676    xGetNewPicBuffer( pcBottomField );
     677    pcBottomField->getPicSym()->allocSaoParam(&m_cEncSAO);
     678    pcBottomField->setReconMark (false);
     679   
     680    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
     681    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
     682    {
     683      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
     684    }
     685    else
     686    {
     687      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     688    }
     689    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
     690   
     691    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
     692    pcBottomField->getPicYuvRec()->setBorderExtension(false);
     693    pcBottomField->setTopField(!isTff);
     694   
     695    int nHeight = pcPicYuvOrg->getHeight();
     696    int nWidth = pcPicYuvOrg->getWidth();
     697    int nStride = pcPicYuvOrg->getStride();
     698    int nPadLuma = pcPicYuvOrg->getLumaMargin();
     699    int nPadChroma = pcPicYuvOrg->getChromaMargin();
     700   
     701    // Get pointers
     702    Pel * PicBufY = pcPicYuvOrg->getBufY();
     703    Pel * PicBufU = pcPicYuvOrg->getBufU();
     704    Pel * PicBufV = pcPicYuvOrg->getBufV();
     705   
     706    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
     707    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
     708    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
     709   
     710    // Compute image characteristics
     711    if ( getUseAdaptiveQP() )
     712    {
     713      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
     714    }
     715   
     716    /* -- Defield -- */
     717   
     718    Bool isTop = !isTff;
     719   
     720    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
     721    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     722    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
     723   
     724  }
     725 
     726  if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) )
     727  {
     728    iNumEncoded = 0;
     729    return;
     730  }
     731 
     732  // compress GOP
     733  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
     734 
     735  iNumEncoded = m_iNumPicRcvd;
     736  m_iNumPicRcvd = 0;
    469737  m_uiNumAllPicCoded += iNumEncoded;
    470738}
     
    523791
    524792            //only for scalable extension
     793#if SCALABILITY_MASK_E0104
     794            assert( m_cVPS.getScalabilityMask(2) == true );
     795#else
    525796            assert( m_cVPS.getScalabilityMask(1) == true );
     797#endif
    526798          }
    527799        }
     
    560832
    561833            //only for scalable extension
     834#if SCALABILITY_MASK_E0104
     835            assert( m_cVPS.getScalabilityMask(2) == true );
     836#else
    562837            assert( m_cVPS.getScalabilityMask(1) == true );
     838#endif
    563839          }
    564840        }
     
    682958  }
    683959
     960#if REPN_FORMAT_IN_VPS
     961  m_cSPS.setBitDepthY( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() );
     962  m_cSPS.setBitDepthC( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  );
     963
     964  m_cSPS.setQpBDOffsetY ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma()  - 8) );
     965  m_cSPS.setQpBDOffsetC ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  - 8) );
     966#else
    684967  m_cSPS.setBitDepthY( g_bitDepthY );
    685968  m_cSPS.setBitDepthC( g_bitDepthC );
     
    687970  m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) );
    688971  m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) );
     972#endif
    689973
    690974  m_cSPS.setUseSAO( m_bUseSAO );
     
    7451029Void TEncTop::xInitPPS()
    7461030{
     1031#if IL_SL_SIGNALLING_N0371
     1032  m_cPPS.setLayerId(m_layerId);
     1033#endif
     1034
    7471035  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
    7481036  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
    7491037
     1038#if REPN_FORMAT_IN_VPS
     1039  Int lowestQP;
     1040  if( m_layerId == 0 || m_cSPS.getUpdateRepFormatFlag() )
     1041  {
     1042    lowestQP = - m_cSPS.getQpBDOffsetY();
     1043  }
     1044  else
     1045  {
     1046    lowestQP = - (m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() - 8) * 6;
     1047  }
     1048#else
    7501049  Int lowestQP = - m_cSPS.getQpBDOffsetY();
     1050#endif
    7511051
    7521052  if(getUseLossless())
     
    8601160    }
    8611161  }
    862 #if REF_IDX_FRAMEWORK
     1162#if SVC_EXTENSION
    8631163  if (!m_layerId)
    8641164  {
     
    8691169    m_cPPS.setListsModificationPresentFlag(true);
    8701170  }
    871 #endif
    872 #if SVC_EXTENSION
     1171
    8731172  m_cPPS.setPPSId         ( m_iPPSIdCnt         );
    8741173  m_cPPS.setSPSId         ( m_iSPSIdCnt         );
    8751174#endif
     1175#if POC_RESET_FLAG
     1176  m_cPPS.setNumExtraSliceHeaderBits( 2 );
     1177#endif
    8761178}
    8771179
    8781180//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
    879 Void TEncTop::xInitRPS()
     1181Void TEncTop::xInitRPS(Bool isFieldCoding)
    8801182{
    8811183  TComReferencePictureSet*      rps;
    8821184 
    883   m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
     1185  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1);
    8841186  TComRPSList* rpsList = m_cSPS.getRPSList();
    8851187
     
    9821284        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
    9831285        rps->setNumberOfNegativePictures(numNeg);
    984         rps->setNumberOfPositivePictures(numNeg+numPos);
     1286        rps->setNumberOfPictures(numNeg+numPos);
    9851287      }
    9861288      if (numPos != rps->getNumberOfPositivePictures())
     
    9881290        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
    9891291        rps->setNumberOfPositivePictures(numPos);
    990         rps->setNumberOfPositivePictures(numNeg+numPos);
     1292        rps->setNumberOfPictures(numNeg+numPos);
    9911293      }
    9921294      RPSTemp.setNumberOfPictures(numNeg+numPos);
     
    10521354#endif //INTER_RPS_AUTO
    10531355  }
    1054  
     1356  //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.
     1357  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
     1358  if (isFieldCoding)
     1359  {
     1360    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
     1361    rps->setNumberOfPictures(1);
     1362    rps->setNumberOfNegativePictures(1);
     1363    rps->setNumberOfPositivePictures(0);
     1364    rps->setNumberOfLongtermPictures(0);
     1365    rps->setDeltaPOC(0,-1);
     1366    rps->setPOC(0,0);
     1367    rps->setUsed(0,true);
     1368    rps->setInterRPSPrediction(false);
     1369    rps->setDeltaRIdxMinus1(0);
     1370    rps->setDeltaRPS(0);
     1371    rps->setNumRefIdc(0);
     1372}
    10551373}
    10561374
     
    10611379{
    10621380  slice->setRPSidx(GOPid);
    1063 
    10641381  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
    10651382  {   
     
    10851402  }
    10861403
     1404  if(POCCurr == 1 && slice->getPic()->isField())
     1405  {
     1406    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
     1407  }
     1408
    10871409  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
    10881410  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
    1089 
    10901411}
    10911412
     
    12151536#endif
    12161537
    1217 #if REF_IDX_FRAMEWORK
     1538#if SVC_EXTENSION
     1539#if !REPN_FORMAT_IN_VPS
    12181540Void TEncTop::xInitILRP()
    12191541{
     
    12491571  }
    12501572}
    1251 
     1573#else
     1574Void TEncTop::xInitILRP()
     1575{
     1576  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) );
     1577  Int bitDepthY,bitDepthC,picWidth,picHeight;
     1578
     1579  if( m_cSPS.getUpdateRepFormatFlag() )
     1580  {
     1581    bitDepthY   = m_cSPS.getBitDepthY();
     1582    bitDepthC   = m_cSPS.getBitDepthC();
     1583    picWidth    = m_cSPS.getPicWidthInLumaSamples();
     1584    picHeight   = m_cSPS.getPicHeightInLumaSamples();
     1585  }
     1586  else
     1587  {
     1588    bitDepthY   = repFormat->getBitDepthVpsLuma();
     1589    bitDepthC   = repFormat->getBitDepthVpsChroma();
     1590    picWidth    = repFormat->getPicWidthVpsInLumaSamples();
     1591    picHeight   = repFormat->getPicHeightVpsInLumaSamples();
     1592  }
     1593 
     1594  if(m_layerId > 0)
     1595  {
     1596    g_bitDepthY     = bitDepthY;
     1597    g_bitDepthC     = bitDepthC;
     1598    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
     1599    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
     1600    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
     1601    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
     1602
     1603    Int  numReorderPics[MAX_TLAYER];
     1604    Window &conformanceWindow = m_cSPS.getConformanceWindow();
     1605    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
     1606
     1607    if (m_cIlpPic[0] == NULL)
     1608    {
     1609      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
     1610      {
     1611        m_cIlpPic[j] = new  TComPic;
     1612#if SVC_UPSAMPLING
     1613        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
     1614#else
     1615        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, true);
     1616#endif
     1617        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
     1618        {
     1619          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
     1620        }
     1621      }
     1622    }
     1623  }
     1624}
     1625#endif
    12521626Void TEncTop::setILRPic(TComPic *pcPic)
    12531627{
     
    12631637      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
    12641638      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
     1639      for (Int j=0; j<m_cIlpPic[refLayerIdc]->getPicSym()->getNumberOfCUsInFrame(); j++)    // set reference CU layerId
     1640      {
     1641        m_cIlpPic[refLayerIdc]->getPicSym()->getCU(j)->setLayerId(m_cIlpPic[refLayerIdc]->getLayerId());
     1642      }
    12651643    }
    12661644  }
  • trunk/source/Lib/TLibEncoder/TEncTop.h

    r313 r442  
    130130 
    131131#if SVC_EXTENSION
     132
    132133  TEncTop**               m_ppcTEncTop;
    133134  TEncTop*                getLayerEnc(UInt layer)   { return m_ppcTEncTop[layer]; }
    134 #endif
    135 #if REF_IDX_FRAMEWORK
    136135  TComPic*                m_cIlpPic[MAX_NUM_REF];                    ///<  Inter layer Prediction picture =  upsampled picture
    137 #endif
    138136#if REF_IDX_MFM
    139137  Bool                    m_bMFMEnabledFlag;
     
    145143  UInt                    m_numScaledRefLayerOffsets;
    146144  Window                  m_scaledRefLayerWindow[MAX_LAYERS];
     145#endif
     146#if POC_RESET_FLAG
     147  Int                     m_pocAdjustmentValue;
     148#endif
    147149#endif
    148150protected:
     
    152154 
    153155  Void  xInitPPSforTiles  ();
    154   Void  xInitRPS          ();                             ///< initialize PPS from encoder options
    155 #if REF_IDX_FRAMEWORK
     156  Void  xInitRPS          (Bool isFieldCoding);           ///< initialize PPS from encoder options
     157#if SVC_EXTENSION
    156158  Void xInitILRP();
    157159#endif
     
    162164  Void      create          ();
    163165  Void      destroy         ();
    164   Void      init            ();
     166  Void      init            (Bool isFieldCoding);
    165167  Void      deletePicBuffer ();
    166168
     
    207209  Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
    208210  Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
    209 #endif
    210211#if SCALED_REF_LAYER_OFFSETS
    211212  Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
     
    213214  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
    214215#endif
     216#endif
    215217
    216218  // -------------------------------------------------------------------------------------------------------------------
     
    220222  /// encode several number of pictures until end-of-sequence
    221223#if SVC_EXTENSION
    222 #if REF_IDX_FRAMEWORK
    223224  TComPic** getIlpList() { return m_cIlpPic; }
    224225  Void      setILRPic(TComPic *pcPic);
    225 #endif
    226226#if REF_IDX_MFM
    227227  Void      setMFMEnabledFlag       (Bool flag)   {m_bMFMEnabledFlag = flag;}
     
    236236  fstream*  getBLSyntaxFile() { return m_pBLSyntaxFile; }
    237237#endif
    238   Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP  );
     238  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP );
    239239  Void      encodePrep( TComPicYuv* pcPicYuvOrg );
     240  Void      encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff );
     241  Void      encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff );
    240242#if VPS_EXTN_DIRECT_REF_LAYERS
    241243  TEncTop*  getRefLayerEnc(UInt refLayerIdc);
    242244#endif
    243 #else
     245#if POC_RESET_FLAG
     246  Int  getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
     247  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
     248#endif
     249#else //SVC_EXTENSION
    244250  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
    245               std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded ); 
    246 #endif
    247 
    248   void printSummary() { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded); }
     251              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded );
     252
     253  /// encode several number of pictures until end-of-sequence
     254  Void encode( bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
     255              std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff);
     256
     257  Void printSummary(Bool isField) { m_cGOPEncoder.printOutSummary (m_uiNumAllPicCoded, isField); }
     258#endif //#if SVC_EXTENSION
    249259};
    250260
Note: See TracChangeset for help on using the changeset viewer.