diff --git a/src/gallium/frontends/mediafoundation/context.h b/src/gallium/frontends/mediafoundation/context.h index 8fcaa3d2bdd..bd3012eebb2 100644 --- a/src/gallium/frontends/mediafoundation/context.h +++ b/src/gallium/frontends/mediafoundation/context.h @@ -33,7 +33,6 @@ typedef class DX12EncodeContext { public: - ComPtr 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 = {}; diff --git a/src/gallium/frontends/mediafoundation/encode.cpp b/src/gallium/frontends/mediafoundation/encode.cpp index 7ae24621d3a..6ccaea1c9e4 100644 --- a/src/gallium/frontends/mediafoundation/encode.cpp +++ b/src/gallium/frontends/mediafoundation/encode.cpp @@ -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 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 ) ) ) { diff --git a/src/gallium/frontends/mediafoundation/mftransform.cpp b/src/gallium/frontends/mediafoundation/mftransform.cpp index 0a3684d1abc..9ea2dcbf608 100644 --- a/src/gallium/frontends/mediafoundation/mftransform.cpp +++ b/src/gallium/frontends/mediafoundation/mftransform.cpp @@ -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 );