mediafoundation: propagate input timestamp / duration to output

Reviewed-by: Sil Vilerino <sivileri@microsoft.com>

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14261
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/38427>
This commit is contained in:
Pohsiang (John) Hsu 2025-11-12 15:13:07 -08:00 committed by Marge Bot
parent 294e72e2b5
commit e9757d25e0
3 changed files with 12 additions and 7 deletions

View file

@ -33,7 +33,6 @@
typedef class DX12EncodeContext
{
public:
ComPtr<IMFSample> spSample;
void *pAsyncCookie = nullptr;
reference_frames_tracker_dpb_async_token *pAsyncDPBToken = nullptr;
struct pipe_fence_handle *pAsyncFence = NULL;
@ -66,6 +65,9 @@ typedef class DX12EncodeContext
UINT textureWidth = 0; // width of input sample
UINT textureHeight = 0; // height of input sample
LONGLONG inputSampleTime = 0;
LONGLONG inputSampleDuration = 0;
BOOL bROI = FALSE;
ROI_AREA video_roi_area = {};

View file

@ -44,6 +44,8 @@ CDX12EncHMFT::PrepareForEncode( IMFSample *pSample, LPDX12EncodeContext *ppDX12E
UINT textureHeight = 0u;
bool bReceivedDirtyRectBlob = false;
uint32_t dirtyRectFrameNum = UINT32_MAX;
LONGLONG inputSampleTime = 0;
LONGLONG inputSampleDuration = 0;
ComPtr<IMFDXGIBuffer> spDXGIBuffer;
HANDLE hTexture = NULL;
@ -66,7 +68,10 @@ CDX12EncHMFT::PrepareForEncode( IMFSample *pSample, LPDX12EncodeContext *ppDX12E
CHECKNULL_GOTO( pDX12EncodeContext->pAsyncDPBToken = new reference_frames_tracker_dpb_async_token(), E_OUTOFMEMORY, done );
CHECKHR_GOTO( pSample->GetBufferByIndex( 0, &pDX12EncodeContext->spMediaBuffer ), done );
CHECKHR_GOTO( pSample->GetSampleTime( &inputSampleTime ), done );
CHECKHR_GOTO( pSample->GetSampleDuration( &inputSampleDuration ), done );
pDX12EncodeContext->inputSampleTime = inputSampleTime;
pDX12EncodeContext->inputSampleDuration = inputSampleDuration;
// If we can't get a DXGIBuffer out of this incoming buffer, then its a software-based buffer
if( FAILED( pDX12EncodeContext->spMediaBuffer.As( &spDXGIBuffer ) ) )
{

View file

@ -1075,7 +1075,6 @@ CDX12EncHMFT::ConfigureBitstreamOutputSampleAttributes( IMFSample *pSample,
HRESULT hr = S_OK;
UINT32 uiFrameRateNumerator = pDX12EncodeContext->GetFrameRateNumerator();
UINT32 uiFrameRateDenominator = pDX12EncodeContext->GetFrameRateDenominator();
UINT64 frameDuration = 0;
GUID guidMajorType = { 0 };
GUID guidSubType = { 0 };
DWORD naluInfo[MAX_NALU_LENGTH_INFO_ENTRIES] = {};
@ -1095,10 +1094,9 @@ CDX12EncHMFT::ConfigureBitstreamOutputSampleAttributes( IMFSample *pSample,
// Set frame rate and timing
CHECKHR_GOTO( MFSetAttributeRatio( pSample, MF_MT_FRAME_RATE, uiFrameRateNumerator, uiFrameRateDenominator ), done );
CHECKHR_GOTO( MFFrameRateToAverageTimePerFrame( uiFrameRateNumerator, uiFrameRateDenominator, &frameDuration ), done );
CHECKHR_GOTO( pSample->SetSampleTime( dwReceivedInput * frameDuration ), done );
CHECKHR_GOTO( pSample->SetSampleDuration( frameDuration ), done );
CHECKHR_GOTO( pSample->SetUINT64( MFSampleExtension_DecodeTimestamp, dwReceivedInput * frameDuration ), done );
CHECKHR_GOTO( pSample->SetSampleTime( pDX12EncodeContext->inputSampleTime ), done );
CHECKHR_GOTO( pSample->SetSampleDuration( pDX12EncodeContext->inputSampleDuration ), done );
CHECKHR_GOTO( pSample->SetUINT64( MFSampleExtension_DecodeTimestamp, pDX12EncodeContext->inputSampleTime ), done );
// Set picture type and clean point
CHECKHR_GOTO( pSample->SetUINT32( MFSampleExtension_VideoEncodePictureType, pDX12EncodeContext->GetPictureType() ), done );