From 41a0168ac983e537a72c583cbd1572b7d3ef16bb Mon Sep 17 00:00:00 2001 From: "Zhang, Furong" Date: Fri, 1 Nov 2024 02:43:14 +0000 Subject: [PATCH] [VP] Added time stamp for AI VFI --- .../include/mfx_vpp_ai_frame_interpolation.h | 7 +++ .../src/mfx_vpp_ai_frame_interpolation.cpp | 56 +++++++++++++------ 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/_studio/mfx_lib/vpp/include/mfx_vpp_ai_frame_interpolation.h b/_studio/mfx_lib/vpp/include/mfx_vpp_ai_frame_interpolation.h index 74bfb5de3..a55e01c2a 100644 --- a/_studio/mfx_lib/vpp/include/mfx_vpp_ai_frame_interpolation.h +++ b/_studio/mfx_lib/vpp/include/mfx_vpp_ai_frame_interpolation.h @@ -126,6 +126,13 @@ class MFXVideoFrameInterpolation // second timestamp using task = std::pair; std::queue m_taskQueue; + + // To calculate the time stamp in mfxFrameData + // The starting time of input frame n for frame [n, n+1] interpolation in units of 90KHz. Divide TimeStamp by 90,000 (90 KHz) to obtain the time in seconds + // The value of MFX_TIMESTAMP_UNKNOWN indicates that there is no time stamp + mfxU64 m_time_stamp_start; + // The time interval of two interpolated frames [n, n+1] in units of 90KHz. Divide TimeStamp by 90,000 (90 KHz) to obtain the time in seconds + mfxU64 m_time_stamp_interval; }; #endif diff --git a/_studio/mfx_lib/vpp/src/mfx_vpp_ai_frame_interpolation.cpp b/_studio/mfx_lib/vpp/src/mfx_vpp_ai_frame_interpolation.cpp index 35b0f5852..623ca88c4 100644 --- a/_studio/mfx_lib/vpp/src/mfx_vpp_ai_frame_interpolation.cpp +++ b/_studio/mfx_lib/vpp/src/mfx_vpp_ai_frame_interpolation.cpp @@ -49,7 +49,9 @@ MFXVideoFrameInterpolation::MFXVideoFrameInterpolation() : m_rgbSurfForFiIn(), m_rgbSurfArray(), m_outSurfForFi(), - m_fiOut() + m_fiOut(), + m_time_stamp_start(0), + m_time_stamp_interval(0) { } @@ -107,6 +109,16 @@ mfxStatus MFXVideoFrameInterpolation::ConfigureFrameRate( m_outStamp = 0; m_outTick = (mfxU16)m_ratio; + m_time_stamp_start = (mfxU64)MFX_TIMESTAMP_UNKNOWN; + // Default to 30fps + m_time_stamp_interval = (mfxU64)((mfxF64) MFX_TIME_STAMP_FREQUENCY / (mfxF64)30); + + if (m_frcRational[VPP_OUT].FrameRateExtN != 0) + { + // Specify the frame rate: FrameRateExtN / FrameRateExtD. + m_time_stamp_interval = (mfxU64)(MFX_TIME_STAMP_FREQUENCY * (((mfxF64)m_frcRational[VPP_OUT].FrameRateExtD / (mfxF64)m_frcRational[VPP_OUT].FrameRateExtN))); + } + return MFX_ERR_NONE; } @@ -369,6 +381,8 @@ mfxStatus MFXVideoFrameInterpolation::UpdateTsAndGetStatus( mfxFrameSurface1* output, mfxStatus* intSts) { + mfxStatus sts = MFX_ERR_NONE; + if (nullptr == input) { // nullptr == input means input sequence reaches its end @@ -376,26 +390,34 @@ mfxStatus MFXVideoFrameInterpolation::UpdateTsAndGetStatus( { return MFX_ERR_MORE_DATA; } - if (m_outStamp == (m_ratio - 1)) m_sequenceEnd = true; - return MFX_ERR_NONE; - } - mfxStatus sts = MFX_ERR_NONE; - - if (m_outStamp == 0) - { - m_inputBkwd.Info = output->Info; - } - else if (m_outStamp == 1) - { - m_inputFwd.Info = output->Info; - - *intSts = MFX_ERR_MORE_SURFACE; + else + { + if (m_outStamp == (m_ratio - 1)) m_sequenceEnd = true; + sts = MFX_ERR_NONE; + } } else { - *intSts = MFX_ERR_MORE_SURFACE; - } + if (m_outStamp == 0) + { + // record the time stamp of input frame [n, n+1] + m_time_stamp_start = input->Data.TimeStamp; + m_inputBkwd.Info = output->Info; + } + else if (m_outStamp == 1) + { + m_inputFwd.Info = output->Info; + *intSts = MFX_ERR_MORE_SURFACE; + } + else + { + *intSts = MFX_ERR_MORE_SURFACE; + } + } + + output->Data.TimeStamp = m_time_stamp_start + m_outStamp * m_time_stamp_interval; + MFX_RETURN(sts); }