Index: source/App/TAppEncoder/TAppEncCfg.cpp =================================================================== --- source/App/TAppEncoder/TAppEncCfg.cpp (revision 2966) +++ source/App/TAppEncoder/TAppEncCfg.cpp (working copy) @@ -1422,16 +1422,9 @@ printf("Internal Format : %dx%d %dHz\n", m_iSourceWidth, m_iSourceHeight, m_iFrameRate ); if (m_isField) { - printf("Frame/Field : Field based coding\n"); - printf("Field index : %u - %d (%d fields)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded ); - if (m_isTopFieldFirst) - { - printf("Field Order : Top field first\n"); - } - else - { - printf("Field Order : Bottom field first\n"); - } + printf("Frame/Field : Field based coding\n"); + printf("Field index : %u - %d (%d fields)\n", m_FrameSkip, m_FrameSkip+m_framesToBeEncoded-1, m_framesToBeEncoded ); + printf("Field Order : %s field first\n", m_isTopFieldFirst?"Top":"Bottom"); } else { Index: source/App/TAppEncoder/TAppEncTop.cpp =================================================================== --- source/App/TAppEncoder/TAppEncTop.cpp (revision 2966) +++ source/App/TAppEncoder/TAppEncTop.cpp (working copy) @@ -480,7 +480,7 @@ assert( m_iGOPSize > 0 ); // org. buffer - if ( m_cListPicYuvRec.size() == (UInt)m_iGOPSize ) + if ( m_cListPicYuvRec.size() >= (UInt)m_iGOPSize ) // buffer will be 1 element longer when using field coding, to maintain first field whilst processing second. { rpcPicYuvRec = m_cListPicYuvRec.popFront(); Index: source/Lib/TLibEncoder/TEncGOP.cpp =================================================================== --- source/Lib/TLibEncoder/TEncGOP.cpp (revision 2966) +++ source/Lib/TLibEncoder/TEncGOP.cpp (working copy) @@ -160,7 +160,7 @@ seiFramePacking->m_spatialFlippingFlag = 0; seiFramePacking->m_frame0FlippedFlag = 0; seiFramePacking->m_fieldViewsFlag = (seiFramePacking->m_arrangementType == 2); - seiFramePacking->m_currentFrameIsFrame0Flag = ((seiFramePacking->m_arrangementType == 5) && m_iNumPicCoded&1); + seiFramePacking->m_currentFrameIsFrame0Flag = ((seiFramePacking->m_arrangementType == 5) && (m_iNumPicCoded&1)); seiFramePacking->m_frame0SelfContainedFlag = 0; seiFramePacking->m_frame1SelfContainedFlag = 0; seiFramePacking->m_frame0GridPositionX = 0; @@ -420,7 +420,7 @@ } else { - pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - isField; + pocCurr = iPOCLast - iNumPicRcvd + m_pcCfg->getGOPEntry(iGOPid).m_POC - ((isField && m_iGopSize>1) ? 1:0); iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC; } @@ -1888,7 +1888,7 @@ if( accumBitsDU != NULL) delete accumBitsDU; if( accumNalsDU != NULL) delete accumNalsDU; - assert ( (m_iNumPicCoded == iNumPicRcvd) || (isField && iPOCLast == 1) ); + assert ( (m_iNumPicCoded == iNumPicRcvd) ); } Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded, bool isField) @@ -2032,29 +2032,16 @@ // Rec. output TComList::iterator iterPicYuvRec = rcListPicYuvRecOut.end(); - if (isField) + if (isField && pocCurr > 2 && m_iGopSize!=1) { - for ( i = 0; i < ( (pocCurr == 0 ) || (pocCurr == 1 ) ? (iNumPicRcvd - iTimeOffset + 1) : (iNumPicRcvd - iTimeOffset + 2) ); i++ ) - { - iterPicYuvRec--; - } + iTimeOffset--; } - else + + for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ ) { - for ( i = 0; i < (iNumPicRcvd - iTimeOffset + 1); i++ ) - { - iterPicYuvRec--; - } - + iterPicYuvRec--; } - if (isField) - { - if(pocCurr == 1) - { - iterPicYuvRec++; - } - } rpcPicYuvRecOut = *(iterPicYuvRec); // Current pic. @@ -2318,8 +2305,8 @@ { for (Int x = 0; x < width; x++) { - dst[x] = isTff ? (UChar) top[x] : (UChar) bottom[x]; - dst[stride+x] = isTff ? (UChar) bottom[x] : (UChar) top[x]; + dst[x] = isTff ? top[x] : bottom[x]; + dst[stride+x] = isTff ? bottom[x] : top[x]; } top += stride; bottom += stride; Index: source/Lib/TLibEncoder/TEncTop.cpp =================================================================== --- source/Lib/TLibEncoder/TEncTop.cpp (revision 2966) +++ source/Lib/TLibEncoder/TEncTop.cpp (working copy) @@ -410,6 +410,8 @@ Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList& rcListPicYuvRecOut, std::list& accessUnitsOut, Int& iNumEncoded, bool isTff) { + iNumEncoded = 0; + /* -- TOP FIELD -- */ if (pcPicYuvOrg) @@ -446,7 +448,7 @@ { m_cPreanalyzer.xPreanalyze( dynamic_cast( pcTopField ) ); } - + /* -- Defield -- */ bool isTop = isTff; @@ -457,11 +459,16 @@ } - if (m_iPOCLast == 0) // compress field 0 + if ( m_iNumPicRcvd && ( (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) ) { + // compress GOP m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); + + iNumEncoded += m_iNumPicRcvd; + m_uiNumAllPicCoded += m_iNumPicRcvd; + m_iNumPicRcvd = 0; } - + /* -- BOTTOM FIELD -- */ if (pcPicYuvOrg) @@ -475,7 +482,7 @@ pcBottomField->setReconMark (false); TComPicYuv* rpcPicYuvRec = new TComPicYuv; - if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize ) + if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize. { rpcPicYuvRec = rcListPicYuvRecOut.popFront(); } @@ -509,7 +516,7 @@ { m_cPreanalyzer.xPreanalyze( dynamic_cast( pcBottomField ) ); } - + /* -- Defield -- */ bool isTop = !isTff; @@ -520,18 +527,15 @@ } - if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) ) + if ( m_iNumPicRcvd && (flush || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) ) { - iNumEncoded = 0; - return; + // compress GOP + m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); + + iNumEncoded += m_iNumPicRcvd; + m_uiNumAllPicCoded += m_iNumPicRcvd; + m_iNumPicRcvd = 0; } - - // compress GOP - m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff); - - iNumEncoded = m_iNumPicRcvd; - m_iNumPicRcvd = 0; - m_uiNumAllPicCoded += iNumEncoded; } // ====================================================================================================================