Changeset 431 in SHVCSoftware for branches


Ignore:
Timestamp:
11 Oct 2013, 05:54:02 (11 years ago)
Author:
seregin
Message:

initial porting of HM12

Location:
branches/SHM-3.1-dev/source
Files:
42 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-3.1-dev/source/App/TAppDecoder/TAppDecTop.cpp

    r389 r431  
    5656TAppDecTop::TAppDecTop()
    5757{
    58   ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
    5958  for(UInt layer=0; layer < MAX_LAYERS; layer++)
    6059  {
     
    6766: m_iPOCLastDisplay(-MAX_INT)
    6867{
    69   ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag));
    7068}
    7169#endif
     
    146144
    147145  // main decoder loop
    148   Bool recon_opened[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen)
     146  Bool openedReconFile[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen)
    149147  for(UInt layer=0; layer<=m_tgtLayerId; layer++)
    150148  {
    151     recon_opened[layer] = false;
     149    openedReconFile[layer] = false;
    152150    m_aiPOCLastDisplay[layer] += m_iSkipFrame;      // set the last displayed POC correctly for skip forward.
    153151  }
     
    235233    if( pcListPic )
    236234    {
    237       if ( m_pchReconFile[curLayerId] && !recon_opened[curLayerId] )
     235      if ( m_pchReconFile[curLayerId] && !openedReconFile[curLayerId] )
    238236      {
    239237        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }       
     
    242240        m_acTVideoIOYuvReconFile[curLayerId].open( m_pchReconFile[curLayerId], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
    243241
    244         recon_opened[curLayerId] = true;
     242        openedReconFile[curLayerId] = true;
    245243      }
    246244      if ( bNewPicture && bNewPOC &&
     
    278276  pcBLPic.destroy();
    279277
    280   for(UInt layer = 1; layer <= m_tgtLayerId; layer++)
     278  UInt layerIdmin = m_acTDecTop[0].getBLReconFile() == NULL ? 0 : 1;
     279
     280  for(UInt layer = layerIdmin; layer <= m_tgtLayerId; layer++)
    281281#else
    282282  for(UInt layer = 0; layer <= m_tgtLayerId; layer++)
     
    310310
    311311  // main decoder loop
    312   Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
     312  Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen)
    313313
    314314#if SYNTAX_OUTPUT
     
    341341    streampos location = bitstreamFile.tellg();
    342342    AnnexBStats stats = AnnexBStats();
    343     Bool bPreviousPictureDecoded = false;
    344343
    345344    vector<uint8_t> nalUnit;
     
    363362      if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu)  )
    364363      {
    365         if(bPreviousPictureDecoded)
    366         {
    367           bNewPicture = true;
    368           bPreviousPictureDecoded = false;
    369         }
    370         else
    371         {
    372364          bNewPicture = false;
    373365        }
    374       }
    375366      else
    376367      {
     
    386377          bytestream.reset();
    387378        }
    388         bPreviousPictureDecoded = true;
    389379      }
    390380    }
     
    396386    if( pcListPic )
    397387    {
    398       if ( m_pchReconFile && !recon_opened )
     388      if ( m_pchReconFile && !openedReconFile )
    399389      {
    400390        if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; }
     
    402392
    403393        m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode
    404         recon_opened = true;
     394        openedReconFile = true;
    405395      }
    406396      if ( bNewPicture &&
     
    508498
    509499/** \param pcListPic list of pictures to be written to file
    510     \todo            DYN_REF_FREE should be revised
    511  */
     500\todo            DYN_REF_FREE should be revised
     501*/
    512502#if SVC_EXTENSION
    513503Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId )
     
    517507{
    518508  TComList<TComPic*>::iterator iterPic   = pcListPic->begin();
    519   Int not_displayed = 0;
     509  Int numPicsNotYetDisplayed = 0;
    520510
    521511  while (iterPic != pcListPic->end())
     
    528518#endif
    529519    {
    530        not_displayed++;
     520      numPicsNotYetDisplayed++;
    531521    }
    532522    iterPic++;
    533523  }
    534524  iterPic   = pcListPic->begin();
    535  
    536   while (iterPic != pcListPic->end())
    537   {
    538     TComPic* pcPic = *(iterPic);
    539    
    540 #if SVC_EXTENSION
    541     if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]))
    542 #else
    543     if ( pcPic->getOutputMark() && (not_displayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
    544 #endif
    545     {
    546       // write to file
    547        not_displayed--;
    548 #if SVC_EXTENSION
    549       if ( m_pchReconFile[layerId] )
    550       {
    551         const Window &conf = pcPic->getConformanceWindow();
    552         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
     525  if (numPicsNotYetDisplayed>2)
     526  {
     527    iterPic++;
     528  }
     529
     530  TComPic* pcPic = *(iterPic);
     531  if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding
     532  {
     533    TComList<TComPic*>::iterator endPic   = pcListPic->end();
     534    endPic--;
     535    iterPic   = pcListPic->begin();
     536    while (iterPic != endPic)
     537    {
     538      TComPic* pcPicTop = *(iterPic);
     539      iterPic++;
     540      TComPic* pcPicBottom = *(iterPic);
     541
     542#if SVC_EXTENSION
     543      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
     544        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0)))
     545#else
     546      if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed >  pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1)
     547        && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed >  pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay<0)))
     548#endif
     549      {
     550        // write to file
     551        numPicsNotYetDisplayed = numPicsNotYetDisplayed-2;
     552#if SVC_EXTENSION
     553        if ( m_pchReconFile[layerId] )
     554        {
     555          const Window &conf = pcPicTop->getConformanceWindow();
     556          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
     557          const Bool isTff = pcPicTop->isTopField();
    553558#if REPN_FORMAT_IN_VPS
    554         UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
    555         Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
    556         m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
    557                                        conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
    558                                        conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
    559                                        conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
    560                                        conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
    561 
    562 #else
    563         m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
    564                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
    565                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
    566                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
    567                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
    568 #endif
    569       }
    570      
    571       // update POC of display order
    572       m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
    573 #else
    574       if ( m_pchReconFile )
    575       {
     559          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
     560          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
     561          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
     562            conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
     563            conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
     564            conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
     565            conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
     566
     567#else
     568          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
     569            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
     570            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
     571            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
     572            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
     573#endif
     574        }
     575
     576        // update POC of display order
     577        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
     578#else
     579        if ( m_pchReconFile )
     580        {
     581          const Window &conf = pcPicTop->getConformanceWindow();
     582          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
     583          const Bool isTff = pcPicTop->isTopField();
     584          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
     585            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
     586            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
     587            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
     588            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
     589        }
     590
     591        // update POC of display order
     592        m_iPOCLastDisplay = pcPicBottom->getPOC();
     593#endif
     594
     595        // erase non-referenced picture in the reference picture list after display
     596        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
     597        {
     598#if !DYN_REF_FREE
     599          pcPicTop->setReconMark(false);
     600
     601          // mark it should be extended later
     602          pcPicTop->getPicYuvRec()->setBorderExtension( false );
     603
     604#else
     605          pcPicTop->destroy();
     606          pcListPic->erase( iterPic );
     607          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
     608          continue;
     609#endif
     610        }
     611        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
     612        {
     613#if !DYN_REF_FREE
     614          pcPicBottom->setReconMark(false);
     615
     616          // mark it should be extended later
     617          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
     618
     619#else
     620          pcPicBottom->destroy();
     621          pcListPic->erase( iterPic );
     622          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
     623          continue;
     624#endif
     625        }
     626        pcPicTop->setOutputMark(false);
     627        pcPicBottom->setOutputMark(false);
     628      }
     629    }
     630  }
     631  else if (!pcPic->isField()) //Frame Decoding
     632  {
     633    iterPic = pcListPic->begin();
     634    while (iterPic != pcListPic->end())
     635    {
     636      pcPic = *(iterPic);
     637
     638#if SVC_EXTENSION
     639      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]))
     640#else
     641      if ( pcPic->getOutputMark() && (numPicsNotYetDisplayed >  pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay))
     642#endif
     643      {
     644        // write to file
     645        numPicsNotYetDisplayed--;
     646#if SVC_EXTENSION
     647        if ( m_pchReconFile[layerId] )
     648        {
     649          const Window &conf = pcPic->getConformanceWindow();
     650          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
     651#if REPN_FORMAT_IN_VPS
     652          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
     653          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
     654          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
     655            conf.getWindowLeftOffset()  * xScal + defDisp.getWindowLeftOffset(),
     656            conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(),
     657            conf.getWindowTopOffset()   * yScal + defDisp.getWindowTopOffset(),
     658            conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() );
     659
     660#else
     661          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
     662            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
     663            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
     664            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
     665            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
     666#endif
     667        }
     668
     669        // update POC of display order
     670        m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
     671#else
     672        if ( m_pchReconFile )
     673        {
    576674#if SYNTAX_OUTPUT
    577         const Window &conf = pcPic->getConformanceWindow();
    578         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
    579         m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
    580                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
    581                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
    582                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
    583                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
    584 #endif
    585       }
    586      
    587       // update POC of display order
    588       m_iPOCLastDisplay = pcPic->getPOC();
    589 #endif
    590      
    591       // erase non-referenced picture in the reference picture list after display
    592       if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
    593       {
     675          const Window &conf = pcPic->getConformanceWindow();
     676          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
     677          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
     678            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
     679            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
     680            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
     681            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
     682#endif
     683        }
     684
     685        // update POC of display order
     686        m_iPOCLastDisplay = pcPic->getPOC();
     687#endif
     688
     689        // erase non-referenced picture in the reference picture list after display
     690        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
     691        {
    594692#if !DYN_REF_FREE
    595         pcPic->setReconMark(false);
    596        
    597         // mark it should be extended later
    598         pcPic->getPicYuvRec()->setBorderExtension( false );
    599        
    600 #else
    601         pcPic->destroy();
    602         pcListPic->erase( iterPic );
    603         iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
    604         continue;
    605 #endif
    606       }
    607       pcPic->setOutputMark(false);
    608     }
    609    
    610     iterPic++;
     693          pcPic->setReconMark(false);
     694
     695          // mark it should be extended later
     696          pcPic->getPicYuvRec()->setBorderExtension( false );
     697
     698#else
     699          pcPic->destroy();
     700          pcListPic->erase( iterPic );
     701          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
     702          continue;
     703#endif
     704        }
     705        pcPic->setOutputMark(false);
     706      }
     707
     708      iterPic++;
     709    }
    611710  }
    612711}
     
    628727
    629728  iterPic   = pcListPic->begin();
    630  
    631   while (iterPic != pcListPic->end())
    632   {
    633     TComPic* pcPic = *(iterPic);
    634 
    635     if ( pcPic->getOutputMark() )
    636     {
    637       // write to file
    638 #if SVC_EXTENSION
    639       if ( m_pchReconFile[layerId] )
    640       {
    641         const Window &conf = pcPic->getConformanceWindow();
    642         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
     729  TComPic* pcPic = *(iterPic);
     730
     731  if (pcPic->isField()) //Field Decoding
     732  {
     733    TComList<TComPic*>::iterator endPic   = pcListPic->end();
     734    endPic--;
     735    TComPic *pcPicTop, *pcPicBottom = NULL;
     736    while (iterPic != endPic)
     737    {
     738      pcPicTop = *(iterPic);
     739      iterPic++;
     740      pcPicBottom = *(iterPic);
     741
     742      if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) )
     743      {
     744        // write to file
     745#if SVC_EXTENSION
     746        if ( m_pchReconFile[layerId] )
     747        {
     748          const Window &conf = pcPicTop->getConformanceWindow();
     749          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
     750          const Bool isTff = pcPicTop->isTopField();
    643751#if REPN_FORMAT_IN_VPS
    644         UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
    645         Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
    646         m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
    647                                        conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
    648                                        conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
    649                                        conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
    650                                        conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset() );
    651 
    652 #else
    653         m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
    654                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
    655                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
    656                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
    657                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
    658 #endif
    659       }
    660      
    661       // update POC of display order
    662       m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
    663 #else
    664       if ( m_pchReconFile )
    665       {
    666         const Window &conf = pcPic->getConformanceWindow();
    667         const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
    668         m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
    669                                        conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
    670                                        conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
    671                                        conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
    672                                        conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
    673       }
    674      
    675       // update POC of display order
    676       m_iPOCLastDisplay = pcPic->getPOC();
    677 #endif
    678      
    679       // erase non-referenced picture in the reference picture list after display
    680       if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
    681       {
     752          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
     753          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
     754          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
     755            conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
     756            conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
     757            conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
     758            conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset() );
     759
     760#else
     761          m_cTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
     762            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
     763            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
     764            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
     765            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
     766#endif
     767        }
     768
     769        // update POC of display order
     770        m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC();
     771#else
     772        if ( m_pchReconFile )
     773        {
     774          const Window &conf = pcPicTop->getConformanceWindow();
     775          const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window();
     776          const Bool isTff = pcPicTop->isTopField();
     777          m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(),
     778            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
     779            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
     780            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
     781            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff );
     782        }
     783
     784        // update POC of display order
     785        m_iPOCLastDisplay = pcPicBottom->getPOC();
     786#endif
     787
     788        // erase non-referenced picture in the reference picture list after display
     789        if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true )
     790        {
    682791#if !DYN_REF_FREE
    683         pcPic->setReconMark(false);
    684        
    685         // mark it should be extended later
    686         pcPic->getPicYuvRec()->setBorderExtension( false );
    687        
    688 #else
    689         pcPic->destroy();
    690         pcListPic->erase( iterPic );
    691         iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
    692         continue;
    693 #endif
    694       }
    695       pcPic->setOutputMark(false);
    696     }
     792          pcPicTop->setReconMark(false);
     793
     794          // mark it should be extended later
     795          pcPicTop->getPicYuvRec()->setBorderExtension( false );
     796
     797#else
     798          pcPicTop->destroy();
     799          pcListPic->erase( iterPic );
     800          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
     801          continue;
     802#endif
     803        }
     804        if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true )
     805        {
     806#if !DYN_REF_FREE
     807          pcPicBottom->setReconMark(false);
     808
     809          // mark it should be extended later
     810          pcPicBottom->getPicYuvRec()->setBorderExtension( false );
     811
     812#else
     813          pcPicBottom->destroy();
     814          pcListPic->erase( iterPic );
     815          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
     816          continue;
     817#endif
     818        }
     819        pcPicTop->setOutputMark(false);
     820        pcPicBottom->setOutputMark(false);
     821
     822#if !DYN_REF_FREE
     823        if(pcPicTop)
     824        {
     825          pcPicTop->destroy();
     826          delete pcPicTop;
     827          pcPicTop = NULL;
     828        }
     829#endif
     830      }
     831    }
     832    if(pcPicBottom)
     833    {
     834      pcPicBottom->destroy();
     835      delete pcPicBottom;
     836      pcPicBottom = NULL;
     837    }
     838  }
     839  else //Frame decoding
     840  {
     841    while (iterPic != pcListPic->end())
     842    {
     843      pcPic = *(iterPic);
     844
     845      if ( pcPic->getOutputMark() )
     846      {
     847        // write to file
     848#if SVC_EXTENSION
     849        if ( m_pchReconFile[layerId] )
     850        {
     851          const Window &conf = pcPic->getConformanceWindow();
     852          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
     853#if REPN_FORMAT_IN_VPS
     854          UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc();
     855          Int xScal =  TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc );
     856          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
     857            conf.getWindowLeftOffset()  *xScal + defDisp.getWindowLeftOffset(),
     858            conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(),
     859            conf.getWindowTopOffset()   *yScal + defDisp.getWindowTopOffset(),
     860            conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset() );
     861
     862#else
     863          m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(),
     864            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
     865            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
     866            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
     867            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
     868#endif
     869        }
     870
     871        // update POC of display order
     872        m_aiPOCLastDisplay[layerId] = pcPic->getPOC();
     873#else
     874        if ( m_pchReconFile )
     875        {
     876          const Window &conf = pcPic->getConformanceWindow();
     877          const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window();
     878          m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(),
     879            conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(),
     880            conf.getWindowRightOffset() + defDisp.getWindowRightOffset(),
     881            conf.getWindowTopOffset() + defDisp.getWindowTopOffset(),
     882            conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() );
     883        }
     884
     885        // update POC of display order
     886        m_iPOCLastDisplay = pcPic->getPOC();
     887#endif
     888
     889        // erase non-referenced picture in the reference picture list after display
     890        if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true )
     891        {
     892#if !DYN_REF_FREE
     893          pcPic->setReconMark(false);
     894
     895          // mark it should be extended later
     896          pcPic->getPicYuvRec()->setBorderExtension( false );
     897
     898#else
     899          pcPic->destroy();
     900          pcListPic->erase( iterPic );
     901          iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised!
     902          continue;
     903#endif
     904        }
     905        pcPic->setOutputMark(false);
     906      }
    697907#if !SVC_EXTENSION
    698908#if !DYN_REF_FREE
    699     if(pcPic)
    700     {
    701       pcPic->destroy();
    702       delete pcPic;
    703       pcPic = NULL;
    704     }
     909      if(pcPic)
     910      {
     911        pcPic->destroy();
     912        delete pcPic;
     913        pcPic = NULL;
     914      }
    705915#endif   
    706916#endif
    707     iterPic++;
     917      iterPic++;
     918    }
    708919  }
    709920#if SVC_EXTENSION
  • branches/SHM-3.1-dev/source/App/TAppDecoder/TAppDecTop.h

    r313 r431  
    7070#endif
    7171 
    72   // for output control
    73   Bool                            m_abDecFlag[ MAX_GOP ];         ///< decoded flag in one GOP
     72  // for output control 
    7473#if SVC_EXTENSION
    7574  Int                             m_aiPOCLastDisplay [MAX_LAYERS]; ///< last POC in display order
  • branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp

    r405 r431  
    348348 
    349349#if SVC_EXTENSION
    350   string  cfg_LayerCfgFile  [MAX_LAYERS];
     350  string  cfg_LayerCfgFile   [MAX_LAYERS];
    351351  string  cfg_BitstreamFile;
    352   string* cfg_InputFile     [MAX_LAYERS];
    353   string* cfg_ReconFile     [MAX_LAYERS];
    354   Double* cfg_fQP           [MAX_LAYERS];
     352  string* cfg_InputFile      [MAX_LAYERS];
     353  string* cfg_ReconFile      [MAX_LAYERS];
     354  Double* cfg_fQP            [MAX_LAYERS];
    355355
    356356#if REPN_FORMAT_IN_VPS
     
    565565  ("FrameRate,-fr",         m_iFrameRate,          0, "Frame rate")
    566566#endif
     567
     568  //Field coding parameters
     569  ("FieldCoding", m_isField, false, "Signals if it's a field based coding")
     570  ("TopFieldFirst, Tff", m_isTopFieldFirst, false, "In case of field based coding, signals whether if it's a top field first or not")
    567571  ("FrameSkip,-fs",         m_FrameSkip,          0u, "Number of frames to skip at start of input YUV")
    568572  ("FramesToBeEncoded,f",   m_framesToBeEncoded,   0, "Number of frames to be encoded (default=all)")
     
    862866  const list<const Char*>& argv_unhandled = po::scanArgv(opts, argc, (const Char**) argv);
    863867
     868  if(m_isField)
     869  {
     870#if SVC_EXTENSION
     871    for(Int layer = 0; layer < MAX_LAYERS; layer++)
     872    {
     873      //Frame height
     874      m_acLayerCfg[layer].m_iSourceHeightOrg = m_acLayerCfg[layer].m_iSourceHeight;
     875      //Field height
     876      m_acLayerCfg[layer].m_iSourceHeight = m_acLayerCfg[layer].m_iSourceHeight >> 1;
     877    }
     878#else
     879    //Frame height
     880    m_iSourceHeightOrg = m_iSourceHeight;
     881    //Field height
     882    m_iSourceHeight = m_iSourceHeight >> 1;
     883#endif
     884    //number of fields to encode
     885    m_framesToBeEncoded *= 2;
     886  }
     887 
    864888  for (list<const Char*>::const_iterator it = argv_unhandled.begin(); it != argv_unhandled.end(); it++)
    865889  {
     
    11931217        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
    11941218        m_iSourceHeight += m_confBottom;
     1219        if ( m_isField )
     1220        {
     1221          m_iSourceHeightOrg += m_confBottom << 1;
     1222          m_aiPad[1] = m_confBottom << 1;
     1223        }
    11951224      }
    11961225      if (m_aiPad[0] % TComSPS::getWinUnitX(CHROMA_420) != 0)
     
    15151544#if  EXTERNAL_USEDBYCURR_N0082|| !FINAL_RPL_CHANGE_N0082
    15161545  Int checkGOP=1;
    1517   Int numRefs = 1;
     1546  Int numRefs = m_isField ? 2 : 1;
    15181547#endif
    15191548  Int refList[MAX_NUM_REF_PICS+1];
    15201549  refList[0]=0;
     1550  if(m_isField)
     1551  {
     1552    refList[1] = 1;
     1553  }
    15211554  Bool isOK[MAX_GOP];
    15221555  for(Int i=0; i<MAX_GOP; i++)
     
    15461579  for(UInt layer=0; layer<m_numLayers; layer++)
    15471580  {
    1548     if(m_acLayerCfg[layer].xCheckParameter())
     1581    if(m_acLayerCfg[layer].xCheckParameter(m_isField))
    15491582    {
    15501583      printf("\nError: invalid configuration parameter found in layer %d \n", layer);
     
    21812214  printf("Internal Format              : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate );
    21822215#endif
    2183   printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
     2216  if (m_isField)
     2217  {
     2218    printf("Frame/Field          : Field based coding\n");
     2219    printf("Field index          : %u - %d (%d fields)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
     2220    if (m_isTopFieldFirst)
     2221    {
     2222      printf("Field Order            : Top field first\n");
     2223    }
     2224    else
     2225    {
     2226      printf("Field Order            : Bottom field first\n");
     2227    }
     2228  }
     2229  else
     2230  {
     2231    printf("Frame/Field                  : Frame based coding\n");
     2232    printf("Frame index                  : %u - %d (%d frames)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded );
     2233  }
    21842234  printf("CU size / depth              : %d / %d\n", m_uiMaxCUWidth, m_uiMaxCUDepth );
    21852235  printf("RQT trans. size (min / max)  : %d / %d\n", 1 << m_uiQuadtreeTULog2MinSize, 1 << m_uiQuadtreeTULog2MaxSize );
  • branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncCfg.h

    r402 r431  
    8888  UInt      m_FrameSkip;                                      ///< number of skipped frames from the beginning
    8989  Int       m_iSourceWidth;                                   ///< source width in pixel
    90   Int       m_iSourceHeight;                                  ///< source height in pixel
     90  Int       m_iSourceHeight;                                  ///< source height in pixel (when interlaced = field height)
     91 
     92  Int       m_iSourceHeightOrg;                               ///< original source height in pixel (when interlaced = frame height)
     93 
     94 
    9195  Int       m_conformanceMode;
    9296  Int       m_confLeft;
     
    97101  Int       m_aiPad[2];                                       ///< number of padded pixels for width and height
    98102#endif 
     103
     104  Bool      m_isField;                                        ///< enable field coding
     105  Bool      m_isTopFieldFirst;
    99106
    100107  // profile/level
  • branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.cpp

    r389 r431  
    161161Bool confirmPara(Bool bflag, const char* message);
    162162
    163 Bool TAppEncLayerCfg::xCheckParameter()
     163Bool TAppEncLayerCfg::xCheckParameter( Bool isField )
    164164{
    165165  switch (m_conformanceMode)
     
    185185        m_aiPad[1] = m_confBottom = ((m_iSourceHeight / minCuSize) + 1) * minCuSize - m_iSourceHeight;
    186186        m_iSourceHeight += m_confBottom;
     187        if ( isField )
     188        {
     189          m_iSourceHeightOrg += m_confBottom << 1;
     190          m_aiPad[1] = m_confBottom << 1;
     191        }
    187192      }
    188193      break;
  • branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.h

    r403 r431  
    3333  Int       m_iFrameRate;                                     ///< source frame-rates (Hz)
    3434  Int       m_iSourceWidth;                                   ///< source width in pixel
    35   Int       m_iSourceHeight;                                  ///< source height in pixel
     35  Int       m_iSourceHeight;                                  ///< source height in pixel (when interlaced = field height)
     36  Int       m_iSourceHeightOrg;                               ///< original source height in pixel (when interlaced = frame height)
    3637  Int       m_conformanceMode;
    3738  Int       m_confLeft;
     
    104105  Void  xPrintParameter();
    105106#endif
    106   Bool  xCheckParameter();
     107  Bool  xCheckParameter( Bool isField );
    107108
    108109  Void    setAppEncCfg(TAppEncCfg* p) {m_cAppEncCfg = p;          }
     
    113114  Int     getSourceWidth()            {return m_iSourceWidth;     }
    114115  Int     getSourceHeight()           {return m_iSourceHeight;    }
     116  Int     getSourceHeightOrg()        {return m_iSourceHeightOrg; }
    115117  Int     getConformanceMode()        { return m_conformanceMode; }
    116118  Int*    getPad()                    {return m_aiPad;            }
  • branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncTop.cpp

    r427 r431  
    888888}
    889889
    890 Void TAppEncTop::xInitLib()
     890Void TAppEncTop::xInitLib(Bool isFieldCoding)
    891891{
    892892#if SVC_EXTENSION
    893893  for(UInt layer=0; layer<m_numLayers; layer++)
    894894  {
    895     m_acTEncTop[layer].init();
     895    m_acTEncTop[layer].init(isFieldCoding);
    896896  }
    897897#if VPS_RENAME
     
    10911091  vps->setExtensionOffset( 0xffff );
    10921092#endif
    1093 #else
    1094   m_cTEncTop.init();
    1095 #endif
     1093#else //SVC_EXTENSION
     1094  m_cTEncTop.init(isFieldCoding);
     1095#endif //SVC_EXTENSION
    10961096}
    10971097
     
    11241124  xInitLibCfg();
    11251125  xCreateLib();
    1126   xInitLib();
     1126  xInitLib(m_isField);
    11271127
    11281128  // main encoder loop
     
    11361136    // allocate original YUV buffer
    11371137    pcPicYuvOrg[layer] = new TComPicYuv;
     1138    if( m_isField )
     1139    {
    11381140#if SVC_UPSAMPLING
    1139     pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
    1140 #else
    1141     pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
    1142 #endif
     1141      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
     1142#else
     1143      pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeightOrg(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
     1144#endif
     1145    }
     1146    else
     1147    {
     1148#if SVC_UPSAMPLING
     1149      pcPicYuvOrg[layer]->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth, NULL );
     1150#else
     1151      pcPicYuvOrg->create( m_acLayerCfg[layer].getSourceWidth(), m_acLayerCfg[layer].getSourceHeight(), m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
     1152#endif
     1153    }
    11431154  }
    11441155
     
    11821193          m_iFrameRcvd++;
    11831194          // check end of file
    1184           bEos = (m_iFrameRcvd == m_framesToBeEncoded);
     1195          bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
    11851196        }
    11861197
    1187         m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer] );
     1198        if ( m_isField )
     1199        {
     1200          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer], m_isTopFieldFirst );
     1201        }
     1202        else
     1203        {
     1204          m_acTEncTop[layer].encodePrep( pcPicYuvOrg[layer] );
     1205        }
    11881206      }
    11891207
     
    12321250      {
    12331251        // call encoding function for one frame
    1234         m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
     1252        if ( m_isField )
     1253        {
     1254          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP, m_isTopFieldFirst );
     1255        }
     1256        else
     1257        {
     1258          m_acTEncTop[layer].encode( flush ? 0 : pcPicYuvOrg[layer], m_acListPicYuvRec[layer], outputAccessUnits, iPicIdInGOP );
     1259        }
    12351260      }
    12361261    }
     
    12691294    if (bEos)
    12701295    {
    1271       printOutSummary();
     1296      printOutSummary(m_isTopFieldFirst);
    12721297    }
    12731298
     
    13011326}
    13021327
    1303 Void TAppEncTop::printOutSummary()
     1328Void TAppEncTop::printOutSummary(Bool isField)
    13041329{
    13051330  UInt layer;
     
    13081333  for(layer = 0; layer < m_numLayers; layer++)
    13091334  {
    1310     m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
    1311     m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
    1312     m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
    1313     m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
     1335    if(isField)
     1336    {
     1337      m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate());
     1338      m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
     1339      m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
     1340      m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() );
     1341    }
     1342    else
     1343    {
     1344      m_gcAnalyzeAll[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2);
     1345      m_gcAnalyzeI[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
     1346      m_gcAnalyzeP[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
     1347      m_gcAnalyzeB[layer].setFrmRate( m_acLayerCfg[layer].getFrameRate() * 2 );
     1348    }
    13141349  }
    13151350
     
    13421377    m_gcAnalyzeB[layer].printOut('b', layer);
    13431378  }
     1379
     1380  if(isField)
     1381  {
     1382    for(layer = 0; layer < m_numLayers; layer++)
     1383    {
     1384      //-- interlaced summary
     1385      m_gcAnalyzeAll_in.setFrmRate( m_acLayerCfg[layer].getFrameRate());
     1386      printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
     1387      m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll[layer].getBits());
     1388
     1389#if _SUMMARY_OUT_
     1390      m_gcAnalyzeAll_in.printSummaryOutInterlaced();
     1391#endif
     1392    }
     1393  }
    13441394}
    13451395
     
    13601410  xInitLibCfg();
    13611411  xCreateLib();
    1362   xInitLib();
     1412  xInitLib(m_isField);
    13631413
    13641414  // main encoder loop
     
    13691419
    13701420  // allocate original YUV buffer
    1371   pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
     1421  if( m_isField )
     1422  {
     1423    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeightOrg, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
     1424  }
     1425  else
     1426  {
     1427    pcPicYuvOrg->create( m_iSourceWidth, m_iSourceHeight, m_uiMaxCUWidth, m_uiMaxCUHeight, m_uiMaxCUDepth );
     1428  }
    13721429
    13731430  while ( !bEos )
     
    13821439    m_iFrameRcvd++;
    13831440
    1384     bEos = (m_iFrameRcvd == m_framesToBeEncoded);
    1385 
     1441    bEos = (m_isField && (m_iFrameRcvd == (m_framesToBeEncoded >> 1) )) || ( !m_isField && (m_iFrameRcvd == m_framesToBeEncoded) );
    13861442    Bool flush = 0;
    13871443    // if end of file (which is only detected on a read failure) flush the encoder of any queued pictures
     
    13951451
    13961452    // call encoding function for one frame
     1453    if ( m_isField )
     1454    {
     1455      m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded, m_isTopFieldFirst);
     1456    }
     1457    else
     1458    {
    13971459    m_cTEncTop.encode( bEos, flush ? 0 : pcPicYuvOrg, m_cListPicYuvRec, outputAccessUnits, iNumEncoded );
     1460    }
    13981461
    13991462    // write bistream to file if necessary
     
    14051468  }
    14061469
    1407   m_cTEncTop.printSummary();
     1470  m_cTEncTop.printSummary(m_isField);
    14081471
    14091472  // delete original YUV buffer
     
    14791542Void TAppEncTop::xWriteRecon(UInt layer, Int iNumEncoded)
    14801543{
    1481   Int i;
    1482 
    1483   TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
    1484 
    1485   for ( i = 0; i < iNumEncoded; i++ )
    1486   {
    1487     --iterPicYuvRec;
    1488   }
    1489 
    1490   for ( i = 0; i < iNumEncoded; i++ )
    1491   {
    1492     TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
     1544  if (m_isField)
     1545  {
     1546    //Reinterlace fields
     1547    Int i;
     1548    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
     1549
     1550    for ( i = 0; i < iNumEncoded; i++ )
     1551    {
     1552      --iterPicYuvRec;
     1553    }
     1554
     1555    for ( i = 0; i < iNumEncoded/2; i++ )
     1556    {
     1557      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
     1558      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
     1559
    14931560#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    1494     if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRec->isReconstructed())
    1495 #else
    1496     if (!m_acLayerCfg[layer].getReconFile().empty())
    1497 #endif
    1498     {
    1499       m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(),
    1500         m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
     1561      if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRecTop->isReconstructed() && pcPicYuvRecBottom->isReconstructed())
     1562#else
     1563      if (!m_acLayerCfg[layer].getReconFile().empty())
     1564#endif
     1565      {
     1566        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRecTop, pcPicYuvRecBottom, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(), m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom(), m_isTopFieldFirst );
     1567      }
     1568    }
     1569  }
     1570  else
     1571  {
     1572    Int i;
     1573
     1574    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_acListPicYuvRec[layer].end();
     1575
     1576    for ( i = 0; i < iNumEncoded; i++ )
     1577    {
     1578      --iterPicYuvRec;
     1579    }
     1580
     1581    for ( i = 0; i < iNumEncoded; i++ )
     1582    {
     1583      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
     1584#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     1585      if (!m_acLayerCfg[layer].getReconFile().empty() && pcPicYuvRec->isReconstructed())
     1586#else
     1587      if (!m_acLayerCfg[layer].getReconFile().empty())
     1588#endif
     1589      {
     1590        m_acTVideoIOYuvReconFile[layer].write( pcPicYuvRec, m_acLayerCfg[layer].getConfLeft(), m_acLayerCfg[layer].getConfRight(),
     1591          m_acLayerCfg[layer].getConfTop(), m_acLayerCfg[layer].getConfBottom() );
     1592      }
    15011593    }
    15021594  }
     
    15051597Void TAppEncTop::xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
    15061598{
    1507   Int i;
    1508 
    1509   list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
     1599  if (m_isField)
     1600  {
     1601    //Reinterlace fields
     1602    Int i;
     1603    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
    15101604
    15111605#if M0040_ADAPTIVE_RESOLUTION_CHANGE
    1512   for ( i = 0; i < iNumEncoded && iterBitstream != accessUnits.end(); i++ )
    1513 #else
    1514   for ( i = 0; i < iNumEncoded; i++ )
    1515 #endif
    1516   {
    1517     const AccessUnit& au = *(iterBitstream++);
    1518     const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
    1519     rateStatsAccum(au, stats);
     1606    for ( i = 0; i < iNumEncoded/2 && iterBitstream != accessUnits.end(); i++ )
     1607#else
     1608    for ( i = 0; i < iNumEncoded/2; i++ )
     1609#endif
     1610    {     
     1611      const AccessUnit& auTop = *(iterBitstream++);
     1612      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
     1613      rateStatsAccum(auTop, statsTop);
     1614
     1615      const AccessUnit& auBottom = *(iterBitstream++);
     1616      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
     1617      rateStatsAccum(auBottom, statsBottom);
     1618    }
     1619  }
     1620  else
     1621  {
     1622    Int i;
     1623
     1624    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
     1625
     1626#if M0040_ADAPTIVE_RESOLUTION_CHANGE
     1627    for ( i = 0; i < iNumEncoded && iterBitstream != accessUnits.end(); i++ )
     1628#else
     1629    for ( i = 0; i < iNumEncoded; i++ )
     1630#endif
     1631    {
     1632      const AccessUnit& au = *(iterBitstream++);
     1633      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
     1634      rateStatsAccum(au, stats);
     1635    }
    15201636  }
    15211637}
     
    15611677Void TAppEncTop::xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits)
    15621678{
    1563   Int i;
    1564 
    1565   TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
    1566   list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
    1567 
    1568   for ( i = 0; i < iNumEncoded; i++ )
    1569   {
    1570     --iterPicYuvRec;
    1571   }
    1572 
    1573   for ( i = 0; i < iNumEncoded; i++ )
    1574   {
    1575     TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
    1576     if (m_pchReconFile)
    1577     {
     1679  if (m_isField)
     1680  {
     1681    //Reinterlace fields
     1682    Int i;
     1683    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
     1684    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
     1685
     1686    for ( i = 0; i < iNumEncoded; i++ )
     1687    {
     1688      --iterPicYuvRec;
     1689    }
     1690
     1691    for ( i = 0; i < iNumEncoded/2; i++ )
     1692    {
     1693      TComPicYuv*  pcPicYuvRecTop  = *(iterPicYuvRec++);
     1694      TComPicYuv*  pcPicYuvRecBottom  = *(iterPicYuvRec++);
     1695
     1696      if (m_pchReconFile)
     1697      {
     1698        m_cTVideoIOYuvReconFile.write( pcPicYuvRecTop, pcPicYuvRecBottom, m_confLeft, m_confRight, m_confTop, m_confBottom, m_isTopFieldFirst );
     1699      }
     1700
     1701      const AccessUnit& auTop = *(iterBitstream++);
     1702      const vector<UInt>& statsTop = writeAnnexB(bitstreamFile, auTop);
     1703      rateStatsAccum(auTop, statsTop);
     1704
     1705      const AccessUnit& auBottom = *(iterBitstream++);
     1706      const vector<UInt>& statsBottom = writeAnnexB(bitstreamFile, auBottom);
     1707      rateStatsAccum(auBottom, statsBottom);
     1708    }
     1709  }
     1710  else
     1711  {
     1712    Int i;
     1713
     1714    TComList<TComPicYuv*>::iterator iterPicYuvRec = m_cListPicYuvRec.end();
     1715    list<AccessUnit>::const_iterator iterBitstream = accessUnits.begin();
     1716
     1717    for ( i = 0; i < iNumEncoded; i++ )
     1718    {
     1719      --iterPicYuvRec;
     1720    }
     1721
     1722    for ( i = 0; i < iNumEncoded; i++ )
     1723    {
     1724      TComPicYuv*  pcPicYuvRec  = *(iterPicYuvRec++);
     1725      if (m_pchReconFile)
     1726      {
    15781727#if SYNTAX_OUTPUT
    1579       m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
    1580 #endif
    1581     }
    1582 
    1583     const AccessUnit& au = *(iterBitstream++);
    1584     const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
    1585     rateStatsAccum(au, stats);
     1728        m_cTVideoIOYuvReconFile.write( pcPicYuvRec, m_confLeft, m_confRight, m_confTop, m_confBottom );
     1729#endif
     1730      }
     1731
     1732      const AccessUnit& au = *(iterBitstream++);
     1733      const vector<UInt>& stats = writeAnnexB(bitstreamFile, au);
     1734      rateStatsAccum(au, stats);
     1735    }
    15861736  }
    15871737}
     
    16021752    case NAL_UNIT_CODED_SLICE_TRAIL_R:
    16031753    case NAL_UNIT_CODED_SLICE_TRAIL_N:
    1604     case NAL_UNIT_CODED_SLICE_TSA_R:
     1754    case NAL_UNIT_CODED_SLICE_TLA_R:
    16051755    case NAL_UNIT_CODED_SLICE_TSA_N:
    16061756    case NAL_UNIT_CODED_SLICE_STSA_R:
  • branches/SHM-3.1-dev/source/App/TAppEncoder/TAppEncTop.h

    r313 r431  
    8282  Void  xCreateLib        ();                               ///< create files & encoder class
    8383  Void  xInitLibCfg       ();                               ///< initialize internal variables
    84   Void  xInitLib          ();                               ///< initialize encoder class
     84  Void  xInitLib          (Bool isFieldCoding);             ///< initialize encoder class
    8585  Void  xDestroyLib       ();                               ///< destroy encoder class
    8686 
     
    9999  Void xWriteRecon(UInt layer, Int iNumEncoded);
    100100  Void xWriteStream(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits);
    101   Void printOutSummary();
     101  Void printOutSummary(Bool isField);
    102102#else
    103103  Void xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits); ///< write bitstream to file
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/CommonDef.h

    r412 r431  
    5959#define NV_VERSION        "3.0.1"                 ///< Current software version
    6060#else
    61 #define NV_VERSION        "11.0"                ///< Current software version
     61#define NV_VERSION        "12.0"                ///< Current software version
    6262#endif
    6363
     
    200200 
    201201  NAL_UNIT_CODED_SLICE_TSA_N,     // 2
    202   NAL_UNIT_CODED_SLICE_TSA_R,       // 3
     202  NAL_UNIT_CODED_SLICE_TLA_R,       // 3
    203203 
    204204  NAL_UNIT_CODED_SLICE_STSA_N,    // 4
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/NAL.h

    r412 r431  
    7676    return m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_R
    7777        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TRAIL_N
    78         || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_R
     78        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TLA_R
    7979        || m_nalUnitType == NAL_UNIT_CODED_SLICE_TSA_N
    8080        || m_nalUnitType == NAL_UNIT_CODED_SLICE_STSA_R
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComMv.h

    r370 r431  
    4040
    4141#include "CommonDef.h"
     42#include <cstdlib>
    4243
    4344//! \ingroup TLibCommon
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPic.cpp

    r389 r431  
    5353, m_bUsedByCurr                           (false)
    5454, m_bIsLongTerm                           (false)
    55 , m_bIsUsedAsLongTerm                     (false)
    5655, m_apcPicSym                             (NULL)
    5756, m_pcPicYuvPred                          (NULL)
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPic.h

    r377 r431  
    6666  Bool                  m_bUsedByCurr;            //  Used by current picture
    6767  Bool                  m_bIsLongTerm;            //  IS long term picture
    68   Bool                  m_bIsUsedAsLongTerm;      //  long term picture is used as reference before
    6968  TComPicSym*           m_apcPicSym;              //  Symbol
    7069 
     
    8887  Window                m_defaultDisplayWindow;
    8988
     89  Bool                  m_isTop;
     90  Bool                  m_isField;
     91 
    9092  std::vector<std::vector<TComDataCU*> > m_vSliceCUDataLink;
    9193
     
    194196  std::vector<TComDataCU*>& getOneSliceCUDataForNDBFilter      (Int sliceID) { return m_vSliceCUDataLink[sliceID];}
    195197
     198  /* field coding parameters*/
     199
     200  Void              setTopField(bool b)                  {m_isTop = b;}
     201  Bool              isTopField()                         {return m_isTop;}
     202  Void              setField(bool b)                     {m_isField = b;}
     203  Bool              isField()                            {return m_isField;}
     204
    196205  /** transfer ownership of seis to this picture */
    197206  void setSEIs(SEIMessages& seis) { m_SEIs = seis; }
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPicSym.cpp

    r377 r431  
    6161,m_uiNumAllocatedSlice (0)
    6262,m_apcTComDataCU (NULL)
    63 ,m_iTileBoundaryIndependenceIdr (0)
    6463,m_iNumColumnsMinus1 (0)
    6564,m_iNumRowsMinus1(0)
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPicSym.h

    r313 r431  
    100100  TComDataCU**  m_apcTComDataCU;        ///< array of CU data
    101101 
    102   Int           m_iTileBoundaryIndependenceIdr;
    103102  Int           m_iNumColumnsMinus1;
    104103  Int           m_iNumRowsMinus1;
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComPrediction.cpp

    r345 r431  
    696696  Int k, l, bottomLeft, topRight;
    697697  Int horPred;
    698   Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
     698  Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
    699699  UInt blkSize = width;
    700700  UInt offset2D = width;
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComRdCost.h

    r313 r431  
    116116private:
    117117  // for distortion
    118   Int                     m_iBlkWidth;
    119   Int                     m_iBlkHeight;
    120118 
    121119#if AMP_SAD
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComRom.cpp

    r414 r431  
    5555  ::memset( g_aucConvertToBit,   -1, sizeof( g_aucConvertToBit ) );
    5656  c=0;
    57   for ( i=4; i<MAX_CU_SIZE; i*=2 )
     57  for ( i=4; i<=MAX_CU_SIZE; i*=2 )
    5858  {
    5959    g_aucConvertToBit[ i ] = c;
    6060    c++;
    6161  }
    62   g_aucConvertToBit[ i ] = c;
    6362 
    6463  c=2;
     
    278277
    279278#if FAST_UDI_USE_MPM
    280 const UChar g_aucIntraModeNumFast[7] =
     279const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] =
    281280{
    282281  3,  //   2x2
     
    285284  3,  //  16x16   
    286285  3,  //  32x32   
    287   3,  //  64x64   
    288   3   // 128x128 
     286  3   //  64x64   
    289287};
    290288#else // FAST_UDI_USE_MPM
    291 const UChar g_aucIntraModeNumFast[7] =
     289const UChar g_aucIntraModeNumFast[MAX_CU_DEPTH] =
    292290{
    293291  3,  //   2x2
     
    296294  4,  //  16x16   33
    297295  4,  //  32x32   33
    298   5,  //  64x64   33
    299   4   // 128x128  33
     296  5   //  64x64   33
    300297};
    301298#endif // FAST_UDI_USE_MPM
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComRom.h

    r414 r431  
    5151// ====================================================================================================================
    5252
    53 #define     MAX_CU_DEPTH            7                           // log2(LCUSize)
     53#define     MAX_CU_DEPTH            6                           // log2(LCUSize)
    5454#define     MAX_CU_SIZE             (1<<(MAX_CU_DEPTH))         // maximum allowable size of CU
    5555#define     MIN_PU_SIZE             4
     
    131131// ====================================================================================================================
    132132
    133 extern const UChar  g_aucIntraModeNumFast[7];
     133extern const UChar  g_aucIntraModeNumFast[ MAX_CU_DEPTH ];
    134134
    135135#if FAST_INTRA_SHVC
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.cpp

    r430 r431  
    186186  m_aiNumRefIdx[0]      = 0;
    187187  m_aiNumRefIdx[1]      = 0;
     188 
    188189  m_colFromL0Flag = 1;
    189190 
     
    292293  if (!pocHasMsb)
    293294  {
    294     poc = poc % pocCycle;
     295    poc = poc & (pocCycle - 1);
    295296  }
    296297 
     
    303304      if (!pocHasMsb)
    304305      {
    305         picPoc = picPoc % pocCycle;
     306        picPoc = picPoc & (pocCycle - 1);
    306307      }
    307308     
     
    966967}
    967968
    968 Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic)
     969Void TComSlice::checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic)
    969970{
    970971  for(Int i = 0; i < pReferencePictureSet->getNumberOfNegativePictures()+pReferencePictureSet->getNumberOfPositivePictures(); i++)
     
    992993  {
    993994    pocCRA = getPOC();
    994     prevRAPisBLA = false;
     995    associatedIRAPType = getNalUnitType();
    995996  }
    996997  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA ) // CRA picture found
    997998  {
    998999    pocCRA = getPOC();
    999     prevRAPisBLA = false;
     1000    associatedIRAPType = getNalUnitType();
    10001001  }
    10011002  else if ( getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP
     
    10041005  {
    10051006    pocCRA = getPOC();
    1006     prevRAPisBLA = true;
     1007    associatedIRAPType = getNalUnitType();
    10071008  }
    10081009}
     
    10291030{
    10301031  TComPic*                 rpcPic;
     1032  setAssociatedIRAPPOC(pocCRA);
    10311033  Int pocCurr = getPOC();
    10321034
     
    11951197}
    11961198
    1197 Int TComSlice::m_prevPOC = 0;
     1199Int TComSlice::m_prevTid0POC = 0;
    11981200
    11991201/** Function for setting the slice's temporal layer ID and corresponding temporal_layer_switching_point_flag.
     
    12501252}
    12511253
     1254
     1255Void TComSlice::checkLeadingPictureRestrictions(TComList<TComPic*>& rcListPic)
     1256{
     1257  TComPic* rpcPic;
     1258
     1259  Int nalUnitType = this->getNalUnitType();
     1260
     1261  // When a picture is a leading picture, it shall be a RADL or RASL picture.
     1262  if(this->getAssociatedIRAPPOC() > this->getPOC())
     1263  {
     1264    // Do not check IRAP pictures since they may get a POC lower than their associated IRAP
     1265    if(nalUnitType < NAL_UNIT_CODED_SLICE_BLA_W_LP ||
     1266       nalUnitType > NAL_UNIT_RESERVED_IRAP_VCL23)
     1267    {
     1268      assert(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     1269             nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
     1270             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     1271             nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R);
     1272    }
     1273  }
     1274
     1275  // When a picture is a trailing picture, it shall not be a RADL or RASL picture.
     1276  if(this->getAssociatedIRAPPOC() < this->getPOC())
     1277  {
     1278    assert(nalUnitType != NAL_UNIT_CODED_SLICE_RASL_N &&
     1279           nalUnitType != NAL_UNIT_CODED_SLICE_RASL_R &&
     1280           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_N &&
     1281           nalUnitType != NAL_UNIT_CODED_SLICE_RADL_R);
     1282  }
     1283
     1284  // No RASL pictures shall be present in the bitstream that are associated
     1285  // with a BLA picture having nal_unit_type equal to BLA_W_RADL or BLA_N_LP.
     1286  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     1287     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
     1288  {
     1289    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_W_RADL &&
     1290           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP);
     1291  }
     1292
     1293  // No RASL pictures shall be present in the bitstream that are associated with
     1294  // an IDR picture.
     1295  if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     1296     nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
     1297  {
     1298    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP   &&
     1299           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_W_RADL);
     1300  }
     1301
     1302  // No RADL pictures shall be present in the bitstream that are associated with
     1303  // a BLA picture having nal_unit_type equal to BLA_N_LP or that are associated
     1304  // with an IDR picture having nal_unit_type equal to IDR_N_LP.
     1305  if(nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     1306     nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
     1307  {
     1308    assert(this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_BLA_N_LP   &&
     1309           this->getAssociatedIRAPType() != NAL_UNIT_CODED_SLICE_IDR_N_LP);
     1310  }
     1311
     1312  // loop through all pictures in the reference picture buffer
     1313  TComList<TComPic*>::iterator iterPic = rcListPic.begin();
     1314  while ( iterPic != rcListPic.end())
     1315  {
     1316    rpcPic = *(iterPic++);
     1317    if (rpcPic->getPOC() == this->getPOC())
     1318    {
     1319      continue;
     1320    }
     1321
     1322    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
     1323    // in decoding order shall precede the IRAP picture in output order.
     1324    // (Note that any picture following in output order would be present in the DPB)
     1325    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
     1326    {
     1327      if(nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP    ||
     1328         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP    ||
     1329         nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL  ||
     1330         nalUnitType == NAL_UNIT_CODED_SLICE_CRA         ||
     1331         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP    ||
     1332         nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL)
     1333      {
     1334        assert(rpcPic->getPOC() < this->getPOC());
     1335      }
     1336    }
     1337
     1338    // Any picture that has PicOutputFlag equal to 1 that precedes an IRAP picture
     1339    // in decoding order shall precede any RADL picture associated with the IRAP
     1340    // picture in output order.
     1341    if(rpcPic->getSlice(0)->getPicOutputFlag() == 1)
     1342    {
     1343      if((nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     1344          nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R))
     1345      {
     1346        // rpcPic precedes the IRAP in decoding order
     1347        if(this->getAssociatedIRAPPOC() > rpcPic->getSlice(0)->getAssociatedIRAPPOC())
     1348        {
     1349          // rpcPic must not be the IRAP picture
     1350          if(this->getAssociatedIRAPPOC() != rpcPic->getPOC())
     1351          {
     1352            assert(rpcPic->getPOC() < this->getPOC());
     1353          }
     1354        }
     1355      }
     1356    }
     1357
     1358    // When a picture is a leading picture, it shall precede, in decoding order,
     1359    // all trailing pictures that are associated with the same IRAP picture.
     1360    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     1361       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R ||
     1362       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_N ||
     1363       nalUnitType == NAL_UNIT_CODED_SLICE_RADL_R)
     1364    {
     1365      if(rpcPic->getSlice(0)->getAssociatedIRAPPOC() == this->getAssociatedIRAPPOC())
     1366      {
     1367        // rpcPic is a picture that preceded the leading in decoding order since it exist in the DPB
     1368        // rpcPic would violate the constraint if it was a trailing picture
     1369        assert(rpcPic->getPOC() <= this->getAssociatedIRAPPOC());
     1370      }
     1371    }
     1372
     1373    // Any RASL picture associated with a CRA or BLA picture shall precede any
     1374    // RADL picture associated with the CRA or BLA picture in output order
     1375    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     1376       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
     1377    {
     1378      if((this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
     1379          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
     1380          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
     1381          this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)       &&
     1382          this->getAssociatedIRAPPOC() == rpcPic->getSlice(0)->getAssociatedIRAPPOC())
     1383      {
     1384        if(rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_N ||
     1385           rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_RADL_R)
     1386        {
     1387          assert(rpcPic->getPOC() > this->getPOC());
     1388        }
     1389      }
     1390    }
     1391
     1392    // Any RASL picture associated with a CRA picture shall follow, in output
     1393    // order, any IRAP picture that precedes the CRA picture in decoding order.
     1394    if(nalUnitType == NAL_UNIT_CODED_SLICE_RASL_N ||
     1395       nalUnitType == NAL_UNIT_CODED_SLICE_RASL_R)
     1396    {
     1397      if(this->getAssociatedIRAPType() == NAL_UNIT_CODED_SLICE_CRA)
     1398      {
     1399        if(rpcPic->getSlice(0)->getPOC() < this->getAssociatedIRAPPOC() &&
     1400           (rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_N_LP   ||
     1401            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_LP   ||
     1402            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_BLA_W_RADL ||
     1403            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP   ||
     1404            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL ||
     1405            rpcPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
     1406        {
     1407          assert(this->getPOC() > rpcPic->getSlice(0)->getPOC());
     1408        }
     1409      }
     1410    }
     1411  }
     1412}
     1413
    12521414/** Function for applying picture marking based on the Reference Picture Set in pReferencePictureSet.
    12531415*/
     
    12561418  TComPic* rpcPic;
    12571419  Int i, isReference;
     1420
     1421  checkLeadingPictureRestrictions(rcListPic);
    12581422
    12591423  // loop through all pictures in the reference picture buffer
     
    12921456      else
    12931457      {
    1294         if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()))
     1458        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
     1459        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
     1460        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
     1461        if(rpcPic->getIsLongTerm() && curPoc == refPoc)
    12951462        {
    12961463          isReference = 1;
     
    13111478    assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getUsedByCurr()==0||rpcPic->getTLayer()<=this->getTLayer());
    13121479    //check that pictures of higher or equal temporal layer are not in the RPS if the current picture is a TSA picture
    1313     if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
     1480    if(this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R || this->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N)
    13141481    {
    13151482      assert(rpcPic->getSlice( 0 )->isReferenced()==0||rpcPic->getTLayer()<this->getTLayer());
     
    13521519      else
    13531520      {
    1354         if(rpcPic->getIsLongTerm() && (rpcPic->getPicSym()->getSlice(0)->getPOC()%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC())) == pReferencePictureSet->getPOC(i)%(1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC()) && rpcPic->getSlice(0)->isReferenced())
     1521        Int pocCycle = 1<<rpcPic->getPicSym()->getSlice(0)->getSPS()->getBitsForPOC();
     1522        Int curPoc = rpcPic->getPicSym()->getSlice(0)->getPOC() & (pocCycle-1);
     1523        Int refPoc = pReferencePictureSet->getPOC(i) & (pocCycle-1);
     1524        if(rpcPic->getIsLongTerm() && curPoc == refPoc && rpcPic->getSlice(0)->isReferenced())
    13551525        {
    13561526          isAvailable = 1;
     
    13711541        if (!pReferencePictureSet->getCheckLTMSBPresent(i))
    13721542        {
    1373           curPoc = curPoc % pocCycle;
    1374           refPoc = refPoc % pocCycle;
     1543          curPoc = curPoc & (pocCycle - 1);
     1544          refPoc = refPoc & (pocCycle - 1);
    13751545        }
    13761546       
     
    21142284    }
    21152285
    2116   /*
     2286/*
    21172287     Note: only the case of "vps_max_temporal_layers_minus1 = 0" is supported.
    2118   */
     2288*/
    21192289    Int i, j;
    21202290    UInt birateValue, cpbSizeValue;
     
    24102580TComScalingList::TComScalingList()
    24112581{
    2412   m_useTransformSkip = false;
    24132582  init();
    24142583}
     2584
    24152585TComScalingList::~TComScalingList()
    24162586{
     
    24952665    {
    24962666      src = getScalingListAddress(sizeIdc, listIdc);
     2667
    24972668      fseek(fp,0,0);
    24982669      do
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComSlice.h

    r425 r431  
    166166#endif
    167167
    168   Bool     getUseTransformSkip    ()                                     { return m_useTransformSkip; }     
    169   Void     setUseTransformSkip    (Bool b)                               { m_useTransformSkip = b;    }
    170 
    171168  Int*     getScalingListAddress          (UInt sizeId, UInt listId)           { return m_scalingListCoef[sizeId][listId]; } //!< get matrix coefficient
    172 
    173169  Bool     checkPredMode                  (UInt sizeId, UInt listId);
    174 
    175170  Void     setRefMatrixId                 (UInt sizeId, UInt listId, UInt u)   { m_refMatrixId[sizeId][listId] = u;    }     //!< set reference matrix ID
    176171  UInt     getRefMatrixId                 (UInt sizeId, UInt listId)           { return m_refMatrixId[sizeId][listId]; }     //!< get reference matrix ID
     
    201196  Void     init                    ();
    202197  Void     destroy                 ();
    203 
    204198  Int      m_scalingListDC               [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< the DC value of the matrix coefficient for 16x16
    205199  Bool     m_useDefaultScalingMatrixFlag [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< UseDefaultScalingMatrixFlag
     
    213207
    214208  UInt     m_predMatrixId                [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< reference list index
    215 
    216   Int      *m_scalingListCoef            [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< quantization matrix
    217 
    218   Bool     m_useTransformSkip;                                                      //!< transform skipping flag for setting default scaling matrix for 4x4
     209  Int      *m_scalingListCoef            [SCALING_LIST_SIZE_NUM][SCALING_LIST_NUM]; //!< quantization matrix                                           
    219210};
    220211
     
    16271618  Int         m_iPOC;
    16281619  Int         m_iLastIDR;
    1629   static Int  m_prevPOC;
     1620  Int         m_iAssociatedIRAP;
     1621  NalUnitType m_iAssociatedIRAPType;
     1622  static Int  m_prevTid0POC;
    16301623  TComReferencePictureSet *m_pcRPS;
    16311624  TComReferencePictureSet m_LocalRPS;
     
    17881781  Void      setRPSidx          ( Int iBDidx ) { m_iBDidx = iBDidx; }
    17891782  Int       getRPSidx          () { return m_iBDidx; }
    1790   Int       getPrevPOC      ()                          { return  m_prevPOC;       }
     1783  Int       getPrevTid0POC      ()                        { return  m_prevTid0POC;       }
    17911784  TComRefPicListModification* getRefPicListModification() { return &m_RefPicListModification; }
    17921785  Void      setLastIDR(Int iIDRPOC)                       { m_iLastIDR = iIDRPOC; }
    17931786  Int       getLastIDR()                                  { return m_iLastIDR; }
     1787  Void      setAssociatedIRAPPOC(Int iAssociatedIRAPPOC)             { m_iAssociatedIRAP = iAssociatedIRAPPOC; }
     1788  Int       getAssociatedIRAPPOC()                        { return m_iAssociatedIRAP; }
     1789  Void      setAssociatedIRAPType(NalUnitType associatedIRAPType)    { m_iAssociatedIRAPType = associatedIRAPType; }
     1790  NalUnitType getAssociatedIRAPType()                        { return m_iAssociatedIRAPType; }
    17941791  SliceType getSliceType    ()                          { return  m_eSliceType;         }
    17951792  Int       getPOC          ()                          { return  m_iPOC;           }
     
    18171814  Void      checkColRefIdx      (UInt curSliceIdx, TComPic* pic);
    18181815  Bool      getIsUsedAsLongTerm (Int i, Int j)                  { return m_bIsUsedAsLongTerm[i][j]; }
     1816  Void      setIsUsedAsLongTerm (Int i, Int j, Bool value)      { m_bIsUsedAsLongTerm[i][j] = value; }
    18191817  Bool      getCheckLDC     ()                                  { return m_bCheckLDC; }
    18201818  Bool      getMvdL1ZeroFlag ()                                  { return m_bLMvdL1Zero;    }
     
    18261824  Void      setReferenced(Bool b)                               { m_bRefenced = b; }
    18271825  Bool      isReferenced()                                      { return m_bRefenced; }
    1828   Void      setPOC              ( Int i )                       { m_iPOC              = i; if(getTLayer()==0) m_prevPOC=i; }
     1826  Bool      isReferenceNalu()                                   { return ((getNalUnitType() <= NAL_UNIT_RESERVED_VCL_R15) && (getNalUnitType()%2 != 0)) || ((getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && (getNalUnitType() <= NAL_UNIT_RESERVED_IRAP_VCL23) ); }
     1827  Void      setPOC              ( Int i )                       { m_iPOC              = i; if ((getTLayer()==0) && (isReferenceNalu() && (getNalUnitType()!=NAL_UNIT_CODED_SLICE_RASL_R)&& (getNalUnitType()!=NAL_UNIT_CODED_SLICE_RADL_R))) {m_prevTid0POC=i;} }
    18291828  Void      setNalUnitType      ( NalUnitType e )               { m_eNalUnitType      = e;      }
    18301829  NalUnitType getNalUnitType    () const                        { return m_eNalUnitType;        }
     
    18481847#endif
    18491848
    1850   Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, Bool& prevRAPisBLA, TComList<TComPic *>& rcListPic);
     1849  Void      checkCRA(TComReferencePictureSet *pReferencePictureSet, Int& pocCRA, NalUnitType& associatedIRAPType, TComList<TComPic *>& rcListPic);
    18511850  Void      decodingRefreshMarking(Int& pocCRA, Bool& bRefreshPending, TComList<TComPic*>& rcListPic);
    18521851  Void      setSliceType        ( SliceType e )                 { m_eSliceType        = e;      }
     
    19171916  Void setTLayerInfo( UInt uiTLayer );
    19181917  Void decodingMarking( TComList<TComPic*>& rcListPic, Int iGOPSIze, Int& iMaxRefPicNum );
     1918  Void checkLeadingPictureRestrictions( TComList<TComPic*>& rcListPic );
    19191919  Void applyReferencePictureSet( TComList<TComPic*>& rcListPic, TComReferencePictureSet *RPSList);
    19201920  Bool isTemporalLayerSwitchingPoint( TComList<TComPic*>& rcListPic );
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TComWeightPrediction.h

    r313 r431  
    5353class TComWeightPrediction
    5454{
    55   wpScalingParam  m_wp0[3], m_wp1[3];
    56 
    5755public:
    5856  TComWeightPrediction();
  • branches/SHM-3.1-dev/source/Lib/TLibCommon/TypeDef.h

    r425 r431  
    4343#define SYNTAX_BYTES                     10      ///< number of bytes taken by syntaxes per 4x4 block [RefIdxL0(1byte), RefIdxL1(1byte), MVxL0(2bytes), MVyL0(2bytes), MVxL1(2bytes), MVyL1(2bytes)]
    4444
    45 #define HM12_RANDOM_ACCESS               1
    4645#define RANDOM_ACCESS_SEI_FIX            1
     46#if SVC_EXTENSION
    4747#define VPS_NUH_LAYER_ID                 1      ///< JCTVC-N0085: Assert that the nuh_layer_id of VPS NAL unit should be 0
    48 #if SVC_EXTENSION
    4948#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
    5049#define POC_RESET_FLAG                   1      ///< JCTVC-N0244: POC reset flag for  layer pictures.
     
    156155#define RC_SHVC_HARMONIZATION            1      ///< JCTVC-M0037: rate control for SHVC
    157156
     157#define VIEW_ID_RELATED_SIGNALING        1      ///< Introduce syntax elements view_id_len_minus1 and view_id_val
     158#define M0043_LAYERS_PRESENT_SEI         0      ///< JCTVC-M0043: add layers present SEI. Macro shall be equal to 0 according to the JCTVC-N0174 discussion. The code is to be removed.
    158159#else
    159160#define SYNTAX_OUTPUT                    0
     
    165166
    166167#define FIX1071 1 ///< fix for issue #1071
    167 #define VIEW_ID_RELATED_SIGNALING        1 ///< Introduce syntax elements view_id_len_minus1 and view_id_val
    168 #define M0043_LAYERS_PRESENT_SEI         0 ///< JCTVC-M0043: add layers present SEI. Macro shall be equal to 0 according to the JCTVC-N0174 discussion. The code is to be removed.
    169168
    170169#define MAX_NUM_PICS_IN_SOP           1024
  • branches/SHM-3.1-dev/source/Lib/TLibDecoder/NALread.cpp

    r412 r431  
    126126  else
    127127  {
    128     assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_R
     128    assert( nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TLA_R
    129129         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_TSA_N
    130130         && nalu.m_nalUnitType != NAL_UNIT_CODED_SLICE_STSA_R
  • branches/SHM-3.1-dev/source/Lib/TLibDecoder/SEIread.cpp

    r313 r431  
    349349
    350350  /* restore primary bitstream for sei_message */
     351  getBitstream()->deleteFifo();
    351352  delete getBitstream();
    352353  setBitstream(bs);
  • branches/SHM-3.1-dev/source/Lib/TLibDecoder/SyntaxElementParser.cpp

    r313 r431  
    5252  if (length < 10)
    5353  {
    54     fprintf( g_hTrace, "%-50s u(%d)  : %d\n", pSymbolName, length, rValue );
     54    fprintf( g_hTrace, "%-50s u(%d)  : %u\n", pSymbolName, length, rValue );
    5555  }
    5656  else
    5757  {
    58     fprintf( g_hTrace, "%-50s u(%d) : %d\n", pSymbolName, length, rValue );
     58    fprintf( g_hTrace, "%-50s u(%d) : %u\n", pSymbolName, length, rValue );
    5959  }
    6060  fflush ( g_hTrace );
     
    6565  xReadUvlc (rValue);
    6666  fprintf( g_hTrace, "%8lld  ", g_nSymbolCounter++ );
    67   fprintf( g_hTrace, "%-50s ue(v) : %d\n", pSymbolName, rValue );
     67  fprintf( g_hTrace, "%-50s ue(v) : %u\n", pSymbolName, rValue );
    6868  fflush ( g_hTrace );
    6969}
  • branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecCAVLC.cpp

    r427 r431  
    16141614      READ_CODE(sps->getBitsForPOC(), uiCode, "pic_order_cnt_lsb");
    16151615      Int iPOClsb = uiCode;
    1616       Int iPrevPOC = rpcSlice->getPrevPOC();
     1616      Int iPrevPOC = rpcSlice->getPrevTid0POC();
    16171617      Int iMaxPOClsb = 1<< sps->getBitsForPOC();
    1618       Int iPrevPOClsb = iPrevPOC%iMaxPOClsb;
     1618      Int iPrevPOClsb = iPrevPOC & (iMaxPOClsb - 1);
    16191619      Int iPrevPOCmsb = iPrevPOC-iPrevPOClsb;
    16201620      Int iPOCmsb;
     
    17381738            rps->setDeltaPOC(j, - rpcSlice->getPOC() + pocLsbLt);
    17391739            rps->setCheckLTMSBPresent(j,false);
     1740           
     1741            // reset deltaPocMSBCycleLT for first LTRP from slice header if MSB not present
     1742            if( j == offset+(numOfLtrp-numLtrpInSPS)-1 )
     1743            {
     1744              deltaPocMSBCycleLT = 0;
     1745            }
    17401746          }
    17411747          prevDeltaMSB = deltaPocMSBCycleLT;
  • branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecSlice.h

    r313 r431  
    6565  TDecEntropy*    m_pcEntropyDecoder;
    6666  TDecCu*         m_pcCuDecoder;
    67   UInt            m_uiCurrSliceIdx;
    6867
    6968  TDecSbac*       m_pcBufferSbacDecoders;   ///< line to store temporary contexts, one per column of tiles.
  • branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.cpp

    r424 r431  
    5757  g_nSymbolCounter = 0;
    5858#endif
     59  m_associatedIRAPType = NAL_UNIT_INVALID;
    5960  m_pocCRA = 0;
    60   m_prevRAPisBLA = false;
    6161  m_pocRandomAccess = MAX_INT;         
    6262#if !SVC_EXTENSION
     
    7777  m_pBLSyntaxFile = NULL;
    7878#endif
    79 #if HM12_RANDOM_ACCESS
    8079  m_prevSliceSkipped = false;
    8180  m_skippedPOC = 0;
    82 #endif
    8381}
    8482
     
    700698#endif
    701699
    702 #if HM12_RANDOM_ACCESS
    703700  // set POC for dependent slices in skipped pictures
    704701  if(m_apcSlicePilot->getDependentSliceSegmentFlag() && m_prevSliceSkipped)
     
    706703    m_apcSlicePilot->setPOC(m_skippedPOC);
    707704  }
    708 #endif
     705
     706  m_apcSlicePilot->setAssociatedIRAPPOC(m_pocCRA);
     707  m_apcSlicePilot->setAssociatedIRAPType(m_associatedIRAPType);
    709708
    710709  // Skip pictures due to random access
    711710  if (isRandomAccessSkipPicture(iSkipFrame, iPOCLastDisplay))
    712711  {
    713 #if HM12_RANDOM_ACCESS
    714712    m_prevSliceSkipped = true;
    715713    m_skippedPOC = m_apcSlicePilot->getPOC();
    716 #endif
    717714    return false;
    718715  }
     
    720717  if (isSkipPictureForBLA(iPOCLastDisplay))
    721718  {
    722 #if HM12_RANDOM_ACCESS
    723719    m_prevSliceSkipped = true;
    724720    m_skippedPOC = m_apcSlicePilot->getPOC();
    725 #endif
    726721    return false;
    727722  }
    728723
    729 #if HM12_RANDOM_ACCESS
    730724  // clear previous slice skipped flag
    731725  m_prevSliceSkipped = false;
    732 #endif
    733726
    734727  // exit when a new picture is found
     
    913906    xGetNewPicBuffer (m_apcSlicePilot, pcPic);
    914907
     908    Bool isField = false;
     909    Bool isTff = false;
     910   
     911    if(!m_SEIs.empty())
     912    {
     913      // Check if any new Picture Timing SEI has arrived
     914      SEIMessages pictureTimingSEIs = extractSeisByType (m_SEIs, SEI::PICTURE_TIMING);
     915      if (pictureTimingSEIs.size()>0)
     916      {
     917        SEIPictureTiming* pictureTiming = (SEIPictureTiming*) *(pictureTimingSEIs.begin());
     918        isField = (pictureTiming->m_picStruct == 1) || (pictureTiming->m_picStruct == 2);
     919        isTff =  (pictureTiming->m_picStruct == 1);
     920      }
     921    }
     922   
     923    //Set Field/Frame coding mode
     924    m_pcPic->setField(isField);
     925    m_pcPic->setTopField(isTff);
     926
    915927    // transfer any SEI messages that have been received to the picture
    916928    pcPic->setSEIs(m_SEIs);
     
    10521064  if (bNextSlice)
    10531065  {
    1054     pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_prevRAPisBLA, m_cListPic );
     1066    pcSlice->checkCRA(pcSlice->getRPS(), m_pocCRA, m_associatedIRAPType, m_cListPic );
    10551067    // Set reference list
    10561068#if SVC_EXTENSION
     
    12511263      pcSlice->setScalingList ( pcSlice->getPPS()->getScalingList()  );
    12521264    }
    1253     pcSlice->getScalingList()->setUseTransformSkip(pcSlice->getPPS()->getUseTransformSkip());
    12541265    if(!pcSlice->getPPS()->getScalingListPresentFlag() && !pcSlice->getSPS()->getScalingListPresentFlag())
    12551266    {
     
    14971508    case NAL_UNIT_CODED_SLICE_TRAIL_R:
    14981509    case NAL_UNIT_CODED_SLICE_TRAIL_N:
    1499     case NAL_UNIT_CODED_SLICE_TSA_R:
     1510    case NAL_UNIT_CODED_SLICE_TLA_R:
    15001511    case NAL_UNIT_CODED_SLICE_TSA_N:
    15011512    case NAL_UNIT_CODED_SLICE_STSA_R:
     
    15321543Bool TDecTop::isSkipPictureForBLA(Int& iPOCLastDisplay)
    15331544{
    1534   if (m_prevRAPisBLA && m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
     1545  if ((m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_N_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_LP || m_associatedIRAPType == NAL_UNIT_CODED_SLICE_BLA_W_RADL) &&
     1546       m_apcSlicePilot->getPOC() < m_pocCRA && (m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || m_apcSlicePilot->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N))
    15351547  {
    15361548    iPOCLastDisplay++;
  • branches/SHM-3.1-dev/source/Lib/TLibDecoder/TDecTop.h

    r414 r431  
    6767  Int                     m_iMaxRefPicNum;
    6868 
     69  NalUnitType             m_associatedIRAPType; ///< NAL unit type of the associated IRAP picture
    6970  Int                     m_pocCRA;            ///< POC number of the latest CRA picture
    70   Bool                    m_prevRAPisBLA;      ///< true if the previous RAP (CRA/CRANT/BLA/BLANT/IDR) picture is a BLA/BLANT picture
    7171  Int                     m_pocRandomAccess;   ///< POC number of the random access point (the first IDR or CRA picture)
    7272
     
    107107  Bool                    m_bFirstSliceInSequence;
    108108#endif
    109 #if HM12_RANDOM_ACCESS
    110109  Bool                    m_prevSliceSkipped;
    111110  Int                     m_skippedPOC;
    112 #endif
    113111
    114112#if SVC_EXTENSION
     
    122120  fstream*                m_pBLReconFile;
    123121  Int                     m_iBLSourceWidth;
    124   Int                     m_iBLSourceHeight;
     122  Int                     m_iBLSourceHeight; 
    125123#endif
    126124#if VPS_EXTN_DIRECT_REF_LAYERS && M0457_PREDICTION_INDICATIONS
     
    159157
    160158  Void executeLoopFilters(Int& poc, TComList<TComPic*>*& rpcListPic);
     159#if SVC_EXTENSION
    161160#if EARLY_REF_PIC_MARKING
    162161  Void earlyPicMarking(Int maxTemporalLayer, std::vector<Int>& targetDecLayerIdList);
    163162#endif
    164 
    165 #if SVC_EXTENSION
    166163  UInt      getLayerId            () { return m_layerId;              }
    167164  Void      setLayerId            (UInt layer) { m_layerId = layer; }
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncAnalyze.cpp

    r313 r431  
    5757#endif
    5858
     59TEncAnalyze             m_gcAnalyzeAll_in;
    5960//! \}
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncAnalyze.h

    r313 r431  
    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
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp

    r427 r431  
    12811281      if( !pcSlice->getPocResetFlag() )
    12821282      {
    1283         picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
     1283        picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    12841284      }
    12851285      else
    12861286      {
    1287         picOrderCntLSB = (pcSlice->getPocValueBeforeReset()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
    1288       }
    1289 #else
    1290       Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC()))%(1<<pcSlice->getSPS()->getBitsForPOC());
     1287        picOrderCntLSB = (pcSlice->getPocValueBeforeReset()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
     1288      }
     1289#else
     1290      Int picOrderCntLSB = (pcSlice->getPOC()-pcSlice->getLastIDR()+(1<<pcSlice->getSPS()->getBitsForPOC())) & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    12911291#endif
    12921292      WRITE_CODE( picOrderCntLSB, pcSlice->getSPS()->getBitsForPOC(), "pic_order_cnt_lsb");
     
    21422142{
    21432143  // Bool state = true, state2 = false;
    2144   Int lsb = ltrpPOC % (1<<pcSlice->getSPS()->getBitsForPOC());
     2144  Int lsb = ltrpPOC & ((1<<pcSlice->getSPS()->getBitsForPOC())-1);
    21452145  for (Int k = 0; k < pcSlice->getSPS()->getNumLongTermRefPicSPS(); k++)
    21462146  {
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncCu.cpp

    r389 r431  
    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;
     
    471455    if (rpcBestCU->getLayerId() > 0)
    472456    {
    473         if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx())
    474             testInter = false;
    475         if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx())
    476             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      }
    477465#if M0457_IL_SAMPLE_PRED_ONLY_FLAG
    478         if( pcSlice->getInterLayerSamplePredOnlyFlag() )
    479             testInter = false;
     466      if( pcSlice->getInterLayerSamplePredOnlyFlag() )
     467      {
     468        testInter = false;
     469      }
    480470#endif
    481471    }
     
    487477        iQP = lowestQP;
    488478      }
    489       // variables for fast encoder decision
    490       bEarlySkip  = false;
    491       bTrySplit    = true;
    492       fRD_Skip    = MAX_DOUBLE;
    493479
    494480      rpcTempCU->initEstData( uiDepth, iQP );
     
    509495        xCheckRDCostMerge2Nx2N( rpcBestCU, rpcTempCU, &earlyDetectionSkipMode );//by Merge for inter_2Nx2N
    510496        rpcTempCU->initEstData( uiDepth, iQP );
    511 
    512         // fast encoder decision for early skip
    513         if ( m_pcEncCfg->getUseFastEnc() )
    514         {
    515           Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
    516           if ( aiNum [ iIdx ] > 5 && fRD_Skip < EARLY_SKIP_THRES*afCost[ iIdx ]/aiNum[ iIdx ] )
    517           {
    518             bEarlySkip = true;
    519             bTrySplit  = false;
    520           }
    521         }
     497       
    522498#if (ENCODER_FAST_MODE == 2)
    523499        if (testInter)
    524500        {
    525501#endif
    526 
    527502        if(!m_pcEncCfg->getUseEarlySkipDetection())
    528503        {
    529504          // 2Nx2N, NxN
    530           if ( !bEarlySkip )
     505          xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
     506          if(m_pcEncCfg->getUseCbfFastMode())
    531507          {
    532             xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N );  rpcTempCU->initEstData( uiDepth, iQP );
    533             if(m_pcEncCfg->getUseCbfFastMode())
    534             {
    535               doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    536             }
     508            doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;
    537509          }
    538510        }
    539511#if (ENCODER_FAST_MODE == 2)
    540     }
    541 #endif
    542 
    543       }
    544 
    545       if( (g_uiMaxCUWidth>>uiDepth) >= rpcTempCU->getSlice()->getPPS()->getMinCuDQPSize() )
    546       {
    547         if(iQP == iBaseQP)
    548         {
    549           bTrySplitDQP = bTrySplit;
    550         }
    551       }
    552       else
    553       {
    554         bTrySplitDQP = bTrySplit;
    555       }
     512        }
     513#endif
     514      }
     515
    556516      if (isAddLowestQP && (iQP == lowestQP))
    557517      {
     
    580540        // do inter modes, NxN, 2NxN, and Nx2N
    581541#if (ENCODER_FAST_MODE)
    582       if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
     542        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter )
    583543#else
    584544        if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
     
    586546        {
    587547          // 2Nx2N, NxN
    588           if ( !bEarlySkip )
     548          if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
    589549          {
    590             if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) ))
     550            if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
    591551            {
    592               if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu)
    593               {
    594                 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
    595                 rpcTempCU->initEstData( uiDepth, iQP );
    596               }
     552              xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN   );
     553              rpcTempCU->initEstData( uiDepth, iQP );
    597554            }
    598555          }
     
    734691
    735692        // do normal intra modes
    736         if ( !bEarlySkip )
    737         {
    738693          // speedup for inter frames
    739694#if (ENCODER_FAST_MODE)
     
    761716            }
    762717          }
    763         }
    764718
    765719        // test PCM
     
    803757    rpcBestCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcBestCU->getTotalBits(), rpcBestCU->getTotalDistortion() );
    804758
    805     // accumulate statistics for early skip
    806     if ( m_pcEncCfg->getUseFastEnc() )
    807     {
    808       if ( rpcBestCU->isSkipped(0) )
    809       {
    810         Int iIdx = g_aucConvertToBit[ rpcBestCU->getWidth(0) ];
    811         afCost[ iIdx ] += rpcBestCU->getTotalCost();
    812         aiNum [ iIdx ] ++;
    813       }
    814     }
    815 
    816759    // Early CU determination
    817760    if( m_pcEncCfg->getUseEarlyCU() && rpcBestCU->isSkipped(0) )
     
    896839
    897840    // further split
    898     if( bSubBranch && bTrySplitDQP && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
     841    if( bSubBranch && uiDepth < g_uiMaxCUDepth - g_uiAddCUDepth )
    899842    {
    900843      UChar       uhNextDepth         = uiDepth+1;
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp

    r429 r431  
    375375// ====================================================================================================================
    376376#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)
     377Void TEncGOP::compressGOP( Int iPicIdInGOP, Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff)
     378#else
     379Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff)
    380380#endif
    381381{
     
    390390  TComOutputBitstream* pcSubstreamsOut = NULL;
    391391
    392   xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut );
     392  xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut, isField );
    393393
    394394  m_iNumPicCoded = 0;
     
    463463
    464464    /////////////////////////////////////////////////////////////////////////////////////////////////// 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)
     465    Int iTimeOffset;
     466    Int pocCurr;
     467   
     468    if(iPOCLast == 0) //case first frame or first top field
    468469    {
    469470      pocCurr=0;
    470471      iTimeOffset = 1;
    471472    }
     473    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
     474    {
     475      pocCurr = 1;
     476      iTimeOffset = 1;
     477    }
     478    else
     479    {
     480      pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField;
     481      iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC;
     482    }
     483
    472484    if(pocCurr>=m_pcCfg->getFramesToBeEncoded())
    473485    {
     
    490502    accessUnitsInGOP.push_back(AccessUnit());
    491503    AccessUnit& accessUnit = accessUnitsInGOP.back();
    492     xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr );
     504    xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr, isField );
    493505
    494506    //  Slice data initialization
     
    499511#if SVC_EXTENSION
    500512    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
     513    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS(), isField );
     514#else
     515    m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), isField );
     516#endif
     517
     518    //Set Frame/Field coding
     519    pcSlice->getPic()->setField(isField);
     520
    505521#if POC_RESET_FLAG
    506522    if( !pcSlice->getPocResetFlag() ) // For picture that are not reset, we should adjust the value of POC calculated from the configuration files.
     
    602618    pcSlice->setLFCrossSliceBoundaryFlag(  pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag()  );
    603619    pcSlice->setScalingList ( m_pcEncTop->getScalingList()  );
    604     pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip());
    605620    if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF)
    606621    {
     
    818833      }
    819834    }
    820 #endif //SVC_EXTENSION
     835#endif //#if SVC_EXTENSION
    821836    if(pcSlice->getTemporalLayerNonReferenceFlag())
    822837    {
    823       if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)
     838      if (pcSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_TRAIL_R &&
     839          !(m_iGopSize == 1 && pcSlice->getSliceType() == I_SLICE))
     840        // Add this condition to avoid POC issues with encoder_intra_main.cfg configuration (see #1127 in bug tracker)
    824841      {
    825842        pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N);
     
    863880        else
    864881        {
    865           pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_R);
     882          pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R);
    866883        }
    867884#if ALIGN_TSA_STSA_PICS
     
    875892            {
    876893              assert( ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_N ) ||
    877                       ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TSA_R ) );
     894                      ( lowerLayerPic->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_TLA_R ) );
    878895              // TSA pictures are aligned within an access unit.
    879896            }
     
    10191036      if( pcSlice->getMFMEnabledFlag() )
    10201037#else
    1021         if( pcSlice->getSPS()->getMFMEnabledFlag() )
    1022 #endif
    1023         {
    1024           pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic());
     1038      if( pcSlice->getSPS()->getMFMEnabledFlag() )
     1039#endif
     1040      {
     1041        pcSlice->setRefPOCListILP(m_pcEncTop->getIlpList(), pcSlice->getBaseColPic());
    10251042#if M0457_COL_PICTURE_SIGNALING && !REMOVE_COL_PICTURE_SIGNALING
    1026           pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
    1027 #endif
    1028         }
    1029 #else
    1030     //  Set reference list
    1031     pcSlice->setRefPicList ( rcListPic );
     1043        pcSlice->setMotionPredIlp(getMotionPredIlp(pcSlice));
     1044#endif
     1045      }
     1046#else
     1047      //  Set reference list
     1048      pcSlice->setRefPicList ( rcListPic );
    10321049#endif //SVC_EXTENSION
    10331050      pcSlice->setRefPicListModificationSvc();
     
    10801097#endif
    10811098    }
    1082 #endif
     1099#else //SVC_EXTENSION
     1100    //  Set reference list
     1101    pcSlice->setRefPicList ( rcListPic );
     1102#endif //#if SVC_EXTENSION
    10831103
    10841104    //  Slice info. refinement
     
    16621682        }
    16631683      }
    1664       pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the .
     1684      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 .
    16651685#if POC_RESET_FLAG
    16661686      pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pocCurr - m_totalCoded;
     
    22012221      xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime );
    22022222
     2223      //In case of field coding, compute the interlaced PSNR for both fields
     2224      if (isField && ((!pcPic->isTopField() && isTff) || (pcPic->isTopField() && !isTff)))
     2225      {
     2226        //get complementary top field
     2227        TComPic* pcPicTop;
     2228        TComList<TComPic*>::iterator   iterPic = rcListPic.begin();
     2229        while ((*iterPic)->getPOC() != pcPic->getPOC()-1)
     2230        {
     2231          iterPic ++;
     2232        }
     2233        pcPicTop = *(iterPic);
     2234        xCalculateInterlacedAddPSNR(pcPicTop, pcPic, pcPicTop->getPicYuvRec(), pcPic->getPicYuvRec(), accessUnit, dEncTime );
     2235      }
     2236
    22032237      if (digestStr)
    22042238      {
     
    23332367            OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer());
    23342368          m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice);
     2369          pictureTimingSEI.m_picStruct = (isField && pcSlice->getPic()->isTopField())? 1 : isField? 2 : 0;
    23352370          m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS());
    23362371          writeRBSPTrailingBits(nalu.m_Bitstream);
     
    24512486
    24522487#if SVC_EXTENSION
    2453   assert ( m_iNumPicCoded <= 1 );
    2454 #else
    2455   assert ( m_iNumPicCoded == iNumPicRcvd );
     2488  assert ( m_iNumPicCoded <= 1 || (isField && iPOCLast == 1) );
     2489#else
     2490  assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) );
    24562491#endif
    24572492}
    24582493
    24592494#if !SVC_EXTENSION
    2460 Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded)
     2495Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, Bool isField)
    24612496{
    24622497  assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic());
     
    24642499   
    24652500  //--CFG_KDY
    2466   m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
    2467   m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
    2468   m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
    2469   m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
     2501  if(isField)
     2502  {
     2503    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2504    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2505    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2506    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() * 2);
     2507  }
     2508   else
     2509  {
     2510    m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() );
     2511    m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() );
     2512    m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() );
     2513    m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() );
     2514  }
    24702515 
    24712516  //-- all
     
    24902535  m_gcAnalyzeB.printSummary('B');
    24912536#endif
     2537
     2538  if(isField)
     2539  {
     2540    //-- interlaced summary
     2541    m_gcAnalyzeAll_in.setFrmRate( m_pcCfg->getFrameRate());
     2542    printf( "\n\nSUMMARY INTERLACED ---------------------------------------------\n" );
     2543    m_gcAnalyzeAll_in.printOutInterlaced('a',  m_gcAnalyzeAll.getBits());
     2544   
     2545#if _SUMMARY_OUT_
     2546    m_gcAnalyzeAll_in.printSummaryOutInterlaced();
     2547#endif
     2548  }
    24922549
    24932550  printf("\nRVM: %.3lf\n" , xCalculateRVM());
     
    25312588// ====================================================================================================================
    25322589
     2590
     2591Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Bool isField )
     2592{
     2593  assert( iNumPicRcvd > 0 );
     2594  //  Exception for the first frames
     2595  if ( ( isField && (iPOCLast == 0 || iPOCLast == 1) ) || (!isField  && (iPOCLast == 0))  )
     2596  {
     2597    m_iGopSize    = 1;
     2598  }
     2599  else
     2600  {
     2601    m_iGopSize    = m_pcCfg->getGOPSize();
     2602  }
     2603  assert (m_iGopSize > 0);
     2604 
     2605  return;
     2606}
     2607
    25332608Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut )
    25342609{
     
    25532628                         TComPic*&                 rpcPic,
    25542629                         TComPicYuv*&              rpcPicYuvRecOut,
    2555                          Int                       pocCurr )
     2630                         Int                       pocCurr,
     2631                         Bool                      isField)
    25562632{
    25572633  Int i;
    25582634  //  Rec. output
    25592635  TComList<TComPicYuv*>::iterator     iterPicYuvRec = rcListPicYuvRecOut.end();
    2560   for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ )
    2561   {
    2562     iterPicYuvRec--;
    2563   }
    2564  
     2636
     2637  if (isField)
     2638  {
     2639    for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ )
     2640    {
     2641      iterPicYuvRec--;
     2642    }
     2643  }
     2644  else
     2645  {
     2646    for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ )
     2647    {
     2648      iterPicYuvRec--;
     2649    }
     2650  }
     2651 
     2652  if (isField)
     2653  {
     2654    if(pocCurr == 1)
     2655    {
     2656      iterPicYuvRec++;
     2657    }
     2658  }
    25652659  rpcPicYuvRecOut = *(iterPicYuvRec);
    25662660 
     
    26472741  switch (type)
    26482742  {
    2649     case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R";
    2650     case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N";
    2651     case NAL_UNIT_CODED_SLICE_TSA_R:      return "TSA_R";
    2652     case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N";
    2653     case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R";
    2654     case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N";
     2743    case NAL_UNIT_CODED_SLICE_TRAIL_R:    return "TRAIL_R";
     2744    case NAL_UNIT_CODED_SLICE_TRAIL_N:    return "TRAIL_N";
     2745    case NAL_UNIT_CODED_SLICE_TLA_R:      return "TLA_R";
     2746    case NAL_UNIT_CODED_SLICE_TSA_N:      return "TSA_N";
     2747    case NAL_UNIT_CODED_SLICE_STSA_R:     return "STSA_R";
     2748    case NAL_UNIT_CODED_SLICE_STSA_N:     return "STSA_N";
    26552749    case NAL_UNIT_CODED_SLICE_BLA_W_LP:   return "BLA_W_LP";
    26562750    case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL";
    2657     case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP";
     2751    case NAL_UNIT_CODED_SLICE_BLA_N_LP:   return "BLA_N_LP";
    26582752    case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL";
    2659     case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP";
    2660     case NAL_UNIT_CODED_SLICE_CRA: return "CRA";
     2753    case NAL_UNIT_CODED_SLICE_IDR_N_LP:   return "IDR_N_LP";
     2754    case NAL_UNIT_CODED_SLICE_CRA:        return "CRA";
    26612755    case NAL_UNIT_CODED_SLICE_RADL_R:     return "RADL_R";
    26622756    case NAL_UNIT_CODED_SLICE_RASL_R:     return "RASL_R";
    2663     case NAL_UNIT_VPS: return "VPS";
    2664     case NAL_UNIT_SPS: return "SPS";
    2665     case NAL_UNIT_PPS: return "PPS";
    2666     case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD";
    2667     case NAL_UNIT_EOS: return "EOS";
    2668     case NAL_UNIT_EOB: return "EOB";
    2669     case NAL_UNIT_FILLER_DATA: return "FILLER";
     2757    case NAL_UNIT_VPS:                    return "VPS";
     2758    case NAL_UNIT_SPS:                    return "SPS";
     2759    case NAL_UNIT_PPS:                    return "PPS";
     2760    case NAL_UNIT_ACCESS_UNIT_DELIMITER:  return "AUD";
     2761    case NAL_UNIT_EOS:                    return "EOS";
     2762    case NAL_UNIT_EOB:                    return "EOB";
     2763    case NAL_UNIT_FILLER_DATA:            return "FILLER";
    26702764    case NAL_UNIT_PREFIX_SEI:             return "SEI";
    26712765    case NAL_UNIT_SUFFIX_SEI:             return "SEI";
    2672     default: return "UNK";
     2766    default:                              return "UNK";
    26732767  }
    26742768}
     
    28742968    printf("]");
    28752969  }
     2970}
     2971
     2972
     2973Void reinterlace(Pel* top, Pel* bottom, Pel* dst, UInt stride, UInt width, UInt height, Bool isTff)
     2974{
     2975 
     2976  for (Int y = 0; y < height; y++)
     2977  {
     2978    for (Int x = 0; x < width; x++)
     2979    {
     2980      dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
     2981      dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     2982    }
     2983    top += stride;
     2984    bottom += stride;
     2985    dst += stride*2;
     2986  }
     2987}
     2988
     2989Void TEncGOP::xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime )
     2990{
     2991  Int     x, y;
     2992 
     2993  UInt64 uiSSDY_in  = 0;
     2994  UInt64 uiSSDU_in  = 0;
     2995  UInt64 uiSSDV_in  = 0;
     2996 
     2997  Double  dYPSNR_in  = 0.0;
     2998  Double  dUPSNR_in  = 0.0;
     2999  Double  dVPSNR_in  = 0.0;
     3000 
     3001  /*------ INTERLACED PSNR -----------*/
     3002 
     3003  /* Luma */
     3004 
     3005  Pel*  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getLumaAddr();
     3006  Pel*  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getLumaAddr();
     3007  Pel*  pRecTop = pcPicRecTop->getLumaAddr();
     3008  Pel*  pRecBottom = pcPicRecBottom->getLumaAddr();
     3009 
     3010  Int   iWidth;
     3011  Int   iHeight;
     3012  Int iStride;
     3013 
     3014  iWidth  = pcPicOrgTop->getPicYuvOrg()->getWidth () - m_pcEncTop->getPad(0);
     3015  iHeight = pcPicOrgTop->getPicYuvOrg()->getHeight() - m_pcEncTop->getPad(1);
     3016  iStride = pcPicOrgTop->getPicYuvOrg()->getStride();
     3017  Int   iSize   = iWidth*iHeight;
     3018  bool isTff = pcPicOrgTop->isTopField();
     3019 
     3020  TComPicYuv* pcOrgInterlaced = new TComPicYuv;
     3021  pcOrgInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     3022 
     3023  TComPicYuv* pcRecInterlaced = new TComPicYuv;
     3024  pcRecInterlaced->create( iWidth, iHeight << 1, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
     3025 
     3026  Pel* pOrgInterlaced = pcOrgInterlaced->getLumaAddr();
     3027  Pel* pRecInterlaced = pcRecInterlaced->getLumaAddr();
     3028 
     3029  //=== Interlace fields ====
     3030  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3031  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3032 
     3033  //===== calculate PSNR =====
     3034  for( y = 0; y < iHeight << 1; y++ )
     3035  {
     3036    for( x = 0; x < iWidth; x++ )
     3037    {
     3038      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3039      uiSSDY_in   += iDiff * iDiff;
     3040    }
     3041    pOrgInterlaced += iStride;
     3042    pRecInterlaced += iStride;
     3043  }
     3044 
     3045  /*Chroma*/
     3046 
     3047  iHeight >>= 1;
     3048  iWidth  >>= 1;
     3049  iStride >>= 1;
     3050 
     3051  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCbAddr();
     3052  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCbAddr();
     3053  pRecTop = pcPicRecTop->getCbAddr();
     3054  pRecBottom = pcPicRecBottom->getCbAddr();
     3055  pOrgInterlaced = pcOrgInterlaced->getCbAddr();
     3056  pRecInterlaced = pcRecInterlaced->getCbAddr();
     3057 
     3058  //=== Interlace fields ====
     3059  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3060  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3061 
     3062  //===== calculate PSNR =====
     3063  for( y = 0; y < iHeight << 1; y++ )
     3064  {
     3065    for( x = 0; x < iWidth; x++ )
     3066    {
     3067      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3068      uiSSDU_in   += iDiff * iDiff;
     3069    }
     3070    pOrgInterlaced += iStride;
     3071    pRecInterlaced += iStride;
     3072  }
     3073 
     3074  pOrgTop = pcPicOrgTop->getPicYuvOrg()->getCrAddr();
     3075  pOrgBottom = pcPicOrgBottom->getPicYuvOrg()->getCrAddr();
     3076  pRecTop = pcPicRecTop->getCrAddr();
     3077  pRecBottom = pcPicRecBottom->getCrAddr();
     3078  pOrgInterlaced = pcOrgInterlaced->getCrAddr();
     3079  pRecInterlaced = pcRecInterlaced->getCrAddr();
     3080 
     3081  //=== Interlace fields ====
     3082  reinterlace(pOrgTop, pOrgBottom, pOrgInterlaced, iStride, iWidth, iHeight, isTff);
     3083  reinterlace(pRecTop, pRecBottom, pRecInterlaced, iStride, iWidth, iHeight, isTff);
     3084 
     3085  //===== calculate PSNR =====
     3086  for( y = 0; y < iHeight << 1; y++ )
     3087  {
     3088    for( x = 0; x < iWidth; x++ )
     3089    {
     3090      Int iDiff = (Int)( pOrgInterlaced[x] - pRecInterlaced[x] );
     3091      uiSSDV_in   += iDiff * iDiff;
     3092    }
     3093    pOrgInterlaced += iStride;
     3094    pRecInterlaced += iStride;
     3095  }
     3096 
     3097  Int maxvalY = 255 << (g_bitDepthY-8);
     3098  Int maxvalC = 255 << (g_bitDepthC-8);
     3099  Double fRefValueY = (Double) maxvalY * maxvalY * iSize*2;
     3100  Double fRefValueC = (Double) maxvalC * maxvalC * iSize*2 / 4.0;
     3101  dYPSNR_in            = ( uiSSDY_in ? 10.0 * log10( fRefValueY / (Double)uiSSDY_in ) : 99.99 );
     3102  dUPSNR_in            = ( uiSSDU_in ? 10.0 * log10( fRefValueC / (Double)uiSSDU_in ) : 99.99 );
     3103  dVPSNR_in            = ( uiSSDV_in ? 10.0 * log10( fRefValueC / (Double)uiSSDV_in ) : 99.99 );
     3104 
     3105  /* calculate the size of the access unit, excluding:
     3106   *  - any AnnexB contributions (start_code_prefix, zero_byte, etc.,)
     3107   *  - SEI NAL units
     3108   */
     3109  UInt numRBSPBytes = 0;
     3110  for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++)
     3111  {
     3112    UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size());
     3113   
     3114    if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI)
     3115      numRBSPBytes += numRBSPBytes_nal;
     3116  }
     3117 
     3118  UInt uibits = numRBSPBytes * 8 ;
     3119 
     3120  //===== add PSNR =====
     3121  m_gcAnalyzeAll_in.addResult (dYPSNR_in, dUPSNR_in, dVPSNR_in, (Double)uibits);
     3122 
     3123  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 );
     3124 
     3125  pcOrgInterlaced->destroy();
     3126  delete pcOrgInterlaced;
     3127  pcRecInterlaced->destroy();
     3128  delete pcRecInterlaced;
    28763129}
    28773130
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncGOP.h

    r345 r431  
    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);
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp

    r401 r431  
    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{
     
    298298    Int    NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );
    299299    Int    SHIFT_QP = 12;
    300     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
    301303#if FULL_NBIT
    302304    Int    bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncSlice.h

    r313 r431  
    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
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.cpp

    r414 r431  
    308308}
    309309
    310 Void TEncTop::init()
     310Void TEncTop::init(Bool isFieldCoding)
    311311{
    312312  // initialize SPS
     
    319319  m_cPPS.setSPS(&m_cSPS);
    320320  xInitPPS();
    321   xInitRPS();
     321  xInitRPS(isFieldCoding);
    322322
    323323  xInitPPSforTiles();
     
    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}
     
    9111179
    9121180//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
    913 Void TEncTop::xInitRPS()
     1181Void TEncTop::xInitRPS(Bool isFieldCoding)
    9141182{
    9151183  TComReferencePictureSet*      rps;
    9161184 
    917   m_cSPS.createRPSList(getGOPSize()+m_extraRPSs);
     1185  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1);
    9181186  TComRPSList* rpsList = m_cSPS.getRPSList();
    9191187
     
    10161284        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
    10171285        rps->setNumberOfNegativePictures(numNeg);
    1018         rps->setNumberOfPositivePictures(numNeg+numPos);
     1286        rps->setNumberOfPictures(numNeg+numPos);
    10191287      }
    10201288      if (numPos != rps->getNumberOfPositivePictures())
     
    10221290        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
    10231291        rps->setNumberOfPositivePictures(numPos);
    1024         rps->setNumberOfPositivePictures(numNeg+numPos);
     1292        rps->setNumberOfPictures(numNeg+numPos);
    10251293      }
    10261294      RPSTemp.setNumberOfPictures(numNeg+numPos);
     
    10861354#endif //INTER_RPS_AUTO
    10871355  }
    1088  
     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}
    10891373}
    10901374
     
    10951379{
    10961380  slice->setRPSidx(GOPid);
    1097 
    10981381  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
    10991382  {   
     
    11191402  }
    11201403
     1404  if(POCCurr == 1 && slice->getPic()->isField())
     1405  {
     1406    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
     1407  }
     1408
    11211409  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
    11221410  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
    1123 
    11241411}
    11251412
  • branches/SHM-3.1-dev/source/Lib/TLibEncoder/TEncTop.h

    r414 r431  
    144144  Window                  m_scaledRefLayerWindow[MAX_LAYERS];
    145145#endif
    146 #endif
    147146#if POC_RESET_FLAG
    148147  Int                     m_pocAdjustmentValue;
     148#endif
    149149#endif
    150150protected:
     
    154154 
    155155  Void  xInitPPSforTiles  ();
    156   Void  xInitRPS          ();                             ///< initialize PPS from encoder options
     156  Void  xInitRPS          (Bool isFieldCoding);           ///< initialize PPS from encoder options
    157157#if SVC_EXTENSION
    158158  Void xInitILRP();
     
    164164  Void      create          ();
    165165  Void      destroy         ();
    166   Void      init            ();
     166  Void      init            (Bool isFieldCoding);
    167167  Void      deletePicBuffer ();
    168168
     
    209209  Int                     getNumPicRcvd         () { return m_iNumPicRcvd;            }
    210210  Void                    setNumPicRcvd         ( Int num ) { m_iNumPicRcvd = num;      }
    211 #endif
    212211#if SCALED_REF_LAYER_OFFSETS
    213212  Void                    setNumScaledRefLayerOffsets(Int x) { m_numScaledRefLayerOffsets = x; }
    214213  UInt                    getNumScaledRefLayerOffsets() { return m_numScaledRefLayerOffsets; }
    215214  Window&  getScaledRefLayerWindow(Int x)            { return m_scaledRefLayerWindow[x]; }
     215#endif
    216216#endif
    217217
     
    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
    244   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); }
    249245#if POC_RESET_FLAG
    250246  Int  getPocAdjustmentValue()      { return m_pocAdjustmentValue;}
    251247  Void setPocAdjustmentValue(Int x) { m_pocAdjustmentValue = x;   }
    252248#endif
     249#else //SVC_EXTENSION
     250  Void encode( Bool bEos, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut,
     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
    253259};
    254260
  • branches/SHM-3.1-dev/source/Lib/TLibVideoIO/TVideoIOYuv.cpp

    r313 r431  
    339339}
    340340
     341static Bool writeField(ostream& fd, Pel* top, Pel* bottom, Bool is16bit,
     342                       UInt stride,
     343                       UInt width, UInt height, bool isTff)
     344{
     345  Int write_len = width * (is16bit ? 2 : 1)*2;
     346  UChar *buf = new UChar[write_len];
     347  for (Int y = 0; y < height; y++)
     348  {
     349    if (!is16bit)
     350    {
     351      for (Int x = 0; x < width; x++)
     352      {
     353        buf[x] = isTff ? (UChar) top[x] : (UChar) bottom[x];
     354        buf[width+x] = isTff ? (UChar) bottom[x] : (UChar) top[x];
     355      }
     356    }
     357    else
     358    {
     359      for (Int x = 0; x < width; x++)
     360      {
     361        buf[2*x] = isTff ? top[x] & 0xff : bottom[x] & 0xff;
     362        buf[2*x+1] = isTff ? (top[x] >> 8) & 0xff : (bottom[x] >> 8) & 0xff;
     363       
     364        buf[width+2*x] = isTff ? bottom[x] & 0xff : top[x] & 0xff;
     365        buf[width+2*x+1] = isTff ? (bottom[x] >> 8) & 0xff : (top[x] >> 8) & 0xff;
     366      }
     367    }
     368   
     369    fd.write(reinterpret_cast<Char*>(buf), write_len);
     370    if (fd.eof() || fd.fail() )
     371    {
     372      delete[] buf;
     373      return false;
     374    }
     375    top += stride;
     376    bottom += stride;
     377  }
     378  delete[] buf;
     379  return true;
     380}
    341381/**
    342382 * Read one Y'CbCr frame, performing any required input scaling to change
     
    501541}
    502542
     543
     544/**
     545 * Write one Y'CbCr frame. No bit-depth conversion is performed, pcPicYuv is
     546 * assumed to be at TVideoIO::m_fileBitdepth depth.
     547 *
     548 * @param pPicTop     input top field YUV buffer class pointer
     549 * @param pPicBottom  input bottom field YUV buffer class pointer
     550 * @param aiPad       source padding size, aiPad[0] = horizontal, aiPad[1] = vertical
     551 * @return true for success, false in case of error
     552 */
     553Bool TVideoIOYuv::write( TComPicYuv* pPicTop, TComPicYuv* pPicBottom, Int cropLeft, Int cropRight, Int cropTop, Int cropBottom , bool isTff)
     554{
     555  // compute actual YUV frame size excluding padding size
     556  Int   iStride = pPicTop->getStride();
     557  UInt  width  = pPicTop->getWidth()  - cropLeft - cropRight;
     558  UInt  height = pPicTop->getHeight() - cropTop  - cropBottom;
     559  Bool is16bit = m_fileBitDepthY > 8 || m_fileBitDepthC > 8;
     560 
     561  TComPicYuv *dstPicTop = NULL;
     562  TComPicYuv *dstPicBottom = NULL;
     563 
     564  Bool retval = true;
     565 
     566  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
     567  {
     568    dstPicTop = new TComPicYuv;
     569    dstPicTop->create( pPicTop->getWidth(), pPicTop->getHeight(), 1, 1, 0 );
     570    pPicTop->copyToPic(dstPicTop);
     571   
     572    dstPicBottom = new TComPicYuv;
     573    dstPicBottom->create( pPicBottom->getWidth(), pPicBottom->getHeight(), 1, 1, 0 );
     574    pPicBottom->copyToPic(dstPicBottom);
     575   
     576    Pel minvalY = 0;
     577    Pel minvalC = 0;
     578    Pel maxvalY = (1 << m_fileBitDepthY) - 1;
     579    Pel maxvalC = (1 << m_fileBitDepthC) - 1;
     580#if CLIP_TO_709_RANGE
     581    if (-m_bitDepthShiftY < 0 && m_fileBitDepthY >= 8)
     582    {
     583      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
     584      minvalY = 1 << (m_fileBitDepthY - 8);
     585      maxvalY = (0xff << (m_fileBitDepthY - 8)) -1;
     586    }
     587    if (-m_bitDepthShiftC < 0 && m_fileBitDepthC >= 8)
     588    {
     589      /* ITU-R BT.709 compliant clipping for converting say 10b to 8b */
     590      minvalC = 1 << (m_fileBitDepthC - 8);
     591      maxvalC = (0xff << (m_fileBitDepthC - 8)) -1;
     592    }
     593#endif
     594    scalePlane(dstPicTop->getLumaAddr(), dstPicTop->getStride(), dstPicTop->getWidth(), dstPicTop->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
     595    scalePlane(dstPicTop->getCbAddr(), dstPicTop->getCStride(), dstPicTop->getWidth()>>1, dstPicTop->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     596    scalePlane(dstPicTop->getCrAddr(), dstPicTop->getCStride(), dstPicTop->getWidth()>>1, dstPicTop->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     597   
     598    scalePlane(dstPicBottom->getLumaAddr(), dstPicBottom->getStride(), dstPicBottom->getWidth(), dstPicBottom->getHeight(), -m_bitDepthShiftY, minvalY, maxvalY);
     599    scalePlane(dstPicBottom->getCbAddr(), dstPicBottom->getCStride(), dstPicBottom->getWidth()>>1, dstPicBottom->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     600    scalePlane(dstPicBottom->getCrAddr(), dstPicBottom->getCStride(), dstPicBottom->getWidth()>>1, dstPicBottom->getHeight()>>1, -m_bitDepthShiftC, minvalC, maxvalC);
     601  }
     602  else
     603  {
     604    dstPicTop = pPicTop;
     605    dstPicBottom = pPicBottom;
     606  }
     607  // location of upper left pel in a plane
     608  Int planeOffset = 0; //cropLeft + cropTop * iStride;
     609  //Write luma
     610  if (! writeField(m_cHandle, dstPicTop->getLumaAddr() + planeOffset,  dstPicBottom->getLumaAddr() + planeOffset, is16bit, iStride, width, height, isTff))
     611  {
     612    retval=false;
     613    goto exit;
     614  }
     615 
     616  width >>= 1;
     617  height >>= 1;
     618  iStride >>= 1;
     619  cropLeft >>= 1;
     620  cropRight >>= 1;
     621 
     622  planeOffset = 0; // cropLeft + cropTop * iStride;
     623 
     624  //Write chroma U
     625  if (! writeField(m_cHandle, dstPicTop->getCbAddr() + planeOffset, dstPicBottom->getCbAddr() + planeOffset, is16bit, iStride, width, height, isTff))
     626  {
     627    retval=false;
     628    goto exit;
     629  }
     630 
     631  //Write chroma V
     632  if (! writeField(m_cHandle, dstPicTop->getCrAddr() + planeOffset, dstPicBottom->getCrAddr() + planeOffset, is16bit, iStride, width, height, isTff))
     633   
     634  {
     635    retval=false;
     636    goto exit;
     637  }
     638 
     639exit:
     640  if (m_bitDepthShiftY != 0 || m_bitDepthShiftC != 0)
     641  {
     642    dstPicTop->destroy();
     643    delete dstPicTop;
     644    dstPicBottom->destroy();
     645    delete dstPicBottom;
     646  } 
     647  return retval;
     648}
  • branches/SHM-3.1-dev/source/Lib/TLibVideoIO/TVideoIOYuv.h

    r313 r431  
    7272  Bool  read  ( TComPicYuv*   pPicYuv, Int aiPad[2] );     ///< read  one YUV frame with padding parameter
    7373  Bool  write( TComPicYuv*    pPicYuv, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0 );
     74  Bool  write( TComPicYuv*    pPicYuv, TComPicYuv*    pPicYuv2, Int confLeft=0, Int confRight=0, Int confTop=0, Int confBottom=0  , bool isTff=false);
    7475 
    7576  Bool  isEof ();                                           ///< check for end-of-file
Note: See TracChangeset for help on using the changeset viewer.