From 7d35bc514df86e661e3b8db26ca449c8e32b41bc Mon Sep 17 00:00:00 2001 From: hongbolv Date: Mon, 10 Dec 2018 22:07:07 +0800 Subject: [PATCH] Reorder the time stamp when the input frame is in encoded order. (cherry picked from commit dca3b5aec66ce4a05cd9f836822d669911693b25) --- .../h264/include/mfx_h264_encode_hw_utils.h | 3 ++- .../encode_hw/h264/src/mfx_h264_encode_hw.cpp | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/_studio/mfx_lib/encode_hw/h264/include/mfx_h264_encode_hw_utils.h b/_studio/mfx_lib/encode_hw/h264/include/mfx_h264_encode_hw_utils.h index c705fbf10a..30784969e2 100644 --- a/_studio/mfx_lib/encode_hw/h264/include/mfx_h264_encode_hw_utils.h +++ b/_studio/mfx_lib/encode_hw/h264/include/mfx_h264_encode_hw_utils.h @@ -1957,7 +1957,8 @@ namespace MfxHwH264Encode DdiTask & newTask); void AssignDecodeTimeStamp( DdiTask & task); - + void PreserveTimeStamp( + mfxU64 timeStamp); mfxStatus UpdateBitstream( DdiTask & task, mfxU32 fid); // 0 - top/progressive, 1 - bottom diff --git a/_studio/mfx_lib/encode_hw/h264/src/mfx_h264_encode_hw.cpp b/_studio/mfx_lib/encode_hw/h264/src/mfx_h264_encode_hw.cpp index e6c1c71ac6..f0cc64f716 100644 --- a/_studio/mfx_lib/encode_hw/h264/src/mfx_h264_encode_hw.cpp +++ b/_studio/mfx_lib/encode_hw/h264/src/mfx_h264_encode_hw.cpp @@ -2198,6 +2198,26 @@ mfxU32 GetMaxFrameSize(DdiTask const & task, MfxVideoParam const &video, Hrd con std::min(maxFrameSize_hrd,maxFrameSize): std::max(maxFrameSize_hrd,maxFrameSize); } + +void ImplementationAvc::PreserveTimeStamp(mfxU64 timeStamp) +{ + // insert the unknown time stamp in the list end. + if (timeStamp == static_cast(MFX_TIMESTAMP_UNKNOWN)) + { + m_timeStamps.push_back(timeStamp); + return; + } + // insert the valid time stamp in the increasing order. + auto it = std::find_if(std::begin(m_timeStamps), std::end(m_timeStamps), + [timeStamp](mfxU64 currTimeStamp) + { + return (currTimeStamp != static_cast(MFX_TIMESTAMP_UNKNOWN)) + && (static_cast(currTimeStamp) > static_cast(timeStamp)); + }); + + m_timeStamps.insert(it, timeStamp); +} + void ImplementationAvc::AssignDecodeTimeStamp(DdiTask & task) { mfxU8 numReorderFrames = GetNumReorderFrames(m_video); @@ -2254,7 +2274,6 @@ mfxStatus ImplementationAvc::AsyncRoutine(mfxBitstream * bs) { MFX_AUTO_LTRACE(MFX_TRACE_LEVEL_HOTSPOTS, "Avc::STG_BIT_ACCEPT_FRAME"); DdiTask & newTask = m_incoming.front(); - m_timeStamps.push_back(newTask.m_timeStamp); if (m_video.mfx.RateControlMethod == MFX_RATECONTROL_LA_EXT) { @@ -2291,6 +2310,7 @@ mfxStatus ImplementationAvc::AsyncRoutine(mfxBitstream * bs) AssignFrameTypes(newTask); } + m_timeStamps.push_back(newTask.m_timeStamp); m_frameOrder++; } else @@ -2302,6 +2322,8 @@ mfxStatus ImplementationAvc::AsyncRoutine(mfxBitstream * bs) if (newTask.m_picStruct[ENC] == MFX_PICSTRUCT_FIELD_BFF) std::swap(newTask.m_type.top, newTask.m_type.bot); + + PreserveTimeStamp(newTask.m_timeStamp); } // move task to reordering queue