diff options
Diffstat (limited to 'src/plugins/common/evr/evrcustompresenter.cpp')
-rw-r--r-- | src/plugins/common/evr/evrcustompresenter.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/plugins/common/evr/evrcustompresenter.cpp b/src/plugins/common/evr/evrcustompresenter.cpp index 3de8d3ac3..b2dd0426c 100644 --- a/src/plugins/common/evr/evrcustompresenter.cpp +++ b/src/plugins/common/evr/evrcustompresenter.cpp @@ -50,6 +50,9 @@ #include <qcoreapplication.h> #include <qmath.h> #include <QtCore/qdebug.h> + +#include <mutex> + #include <float.h> #include <evcode.h> @@ -542,7 +545,6 @@ EVRCustomPresenter::EVRCustomPresenter(QAbstractVideoSurface *surface) , m_sampleFreeCB(this, &EVRCustomPresenter::onSampleFree) , m_refCount(1) , m_renderState(RenderShutdown) - , m_mutex(QMutex::Recursive) , m_scheduler(this) , m_tokenCounter(0) , m_sampleNotify(false) @@ -557,6 +559,7 @@ EVRCustomPresenter::EVRCustomPresenter(QAbstractVideoSurface *surface) , m_mediaType(0) , m_surface(0) , m_canRenderToSurface(false) + , m_positionOffset(0) { // Initial source rectangle = (0,0,1,1) m_sourceRect.top = 0; @@ -658,7 +661,7 @@ HRESULT EVRCustomPresenter::InitServicePointers(IMFTopologyServiceLookup *lookup HRESULT hr = S_OK; DWORD objectCount = 0; - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); // Do not allow initializing when playing or paused. if (isActive()) @@ -738,7 +741,7 @@ HRESULT EVRCustomPresenter::ProcessMessage(MFVP_MESSAGE_TYPE message, ULONG_PTR { HRESULT hr = S_OK; - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); hr = checkShutdown(); if (FAILED(hr)) @@ -805,7 +808,7 @@ HRESULT EVRCustomPresenter::GetCurrentMediaType(IMFVideoMediaType **mediaType) *mediaType = NULL; - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); hr = checkShutdown(); if (FAILED(hr)) @@ -819,7 +822,7 @@ HRESULT EVRCustomPresenter::GetCurrentMediaType(IMFVideoMediaType **mediaType) HRESULT EVRCustomPresenter::OnClockStart(MFTIME, LONGLONG clockStartOffset) { - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); // We cannot start after shutdown. HRESULT hr = checkShutdown(); @@ -854,7 +857,7 @@ HRESULT EVRCustomPresenter::OnClockStart(MFTIME, LONGLONG clockStartOffset) HRESULT EVRCustomPresenter::OnClockRestart(MFTIME) { - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); HRESULT hr = checkShutdown(); if (FAILED(hr)) @@ -878,7 +881,7 @@ HRESULT EVRCustomPresenter::OnClockRestart(MFTIME) HRESULT EVRCustomPresenter::OnClockStop(MFTIME) { - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); HRESULT hr = checkShutdown(); if (FAILED(hr)) @@ -898,7 +901,7 @@ HRESULT EVRCustomPresenter::OnClockStop(MFTIME) HRESULT EVRCustomPresenter::OnClockPause(MFTIME) { - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); // We cannot pause the clock after shutdown. HRESULT hr = checkShutdown(); @@ -915,7 +918,7 @@ HRESULT EVRCustomPresenter::OnClockSetRate(MFTIME, float rate) // The presenter reports its maximum rate through the IMFRateSupport interface. // Here, we assume that the EVR honors the maximum rate. - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); HRESULT hr = checkShutdown(); if (FAILED(hr)) @@ -943,7 +946,7 @@ HRESULT EVRCustomPresenter::GetSlowestRate(MFRATE_DIRECTION, BOOL, float *rate) if (!rate) return E_POINTER; - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); HRESULT hr = checkShutdown(); @@ -960,7 +963,7 @@ HRESULT EVRCustomPresenter::GetFastestRate(MFRATE_DIRECTION direction, BOOL thin if (!rate) return E_POINTER; - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); float maxRate = 0.0f; @@ -982,7 +985,7 @@ HRESULT EVRCustomPresenter::GetFastestRate(MFRATE_DIRECTION direction, BOOL thin HRESULT EVRCustomPresenter::IsRateSupported(BOOL thin, float rate, float *nearestSupportedRate) { - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); float maxRate = 0.0f; float nearestRate = rate; // If we support rate, that is the nearest. @@ -1016,7 +1019,7 @@ HRESULT EVRCustomPresenter::IsRateSupported(BOOL thin, float rate, float *neares void EVRCustomPresenter::supportedFormatsChanged() { - QMutexLocker locker(&m_mutex); + const std::lock_guard<QRecursiveMutex> locker(m_mutex); m_canRenderToSurface = false; m_presentEngine->setHint(D3DPresentEngine::RenderToTexture, false); @@ -1143,7 +1146,7 @@ HRESULT EVRCustomPresenter::flush() sample->Release(); m_frameStep.samples.clear(); - if (m_renderState == RenderStopped && m_surface->isActive()) { + if (m_renderState == RenderStopped && m_surface && m_surface->isActive()) { // Repaint with black. presentSample(NULL); } @@ -1932,6 +1935,15 @@ void EVRCustomPresenter::presentSample(IMFSample *sample) QVideoFrame frame = m_presentEngine->makeVideoFrame(sample); + // Since start/end times are related to a position when the clock is started, + // to have times from the beginning, need to adjust it by adding seeked position. + if (m_positionOffset) { + if (frame.startTime()) + frame.setStartTime(frame.startTime() + m_positionOffset); + if (frame.endTime()) + frame.setEndTime(frame.endTime() + m_positionOffset); + } + if (!m_surface->isActive() || m_surface->surfaceFormat() != m_presentEngine->videoSurfaceFormat()) { m_surface->stop(); if (!m_surface->start(m_presentEngine->videoSurfaceFormat())) @@ -1941,6 +1953,11 @@ void EVRCustomPresenter::presentSample(IMFSample *sample) m_surface->present(frame); } +void EVRCustomPresenter::positionChanged(qint64 position) +{ + m_positionOffset = position * 1000; +} + HRESULT setDesiredSampleTime(IMFSample *sample, const LONGLONG &sampleTime, const LONGLONG &duration) { if (!sample) |