4#ifndef EVRD3DPRESENTENGINE_H
5#define EVRD3DPRESENTENGINE_H
20#include <QVideoFrameFormat>
21#include <QtCore/private/qcomptr_p.h>
27struct IDirect3DDevice9Ex;
28struct IDirect3DDeviceManager9;
29struct IDirect3DSurface9;
30struct IDirect3DTexture9;
40static const GUID MFSamplePresenter_SampleCounter =
41{ 0xb0bb83cc, 0xf10f, 0x4e2e, { 0xaa, 0x2b, 0x29, 0xea, 0x5e, 0x92, 0xef, 0x85 } };
55 Q_DISABLE_COPY(EGLWrapper)
59 __eglMustCastToProperFunctionPointerType getProcAddress(
const char *procname);
60 EGLSurface createPbufferSurface(EGLDisplay dpy, EGLConfig config,
const EGLint *attrib_list);
61 EGLBoolean destroySurface(EGLDisplay dpy, EGLSurface surface);
62 EGLBoolean bindTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
63 EGLBoolean releaseTexImage(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
66 typedef __eglMustCastToProperFunctionPointerType (EGLAPIENTRYP EglGetProcAddress)(
const char *procname);
67 typedef EGLSurface (EGLAPIENTRYP EglCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config,
const EGLint *attrib_list);
68 typedef EGLBoolean (EGLAPIENTRYP EglDestroySurface)(EGLDisplay dpy, EGLSurface surface);
69 typedef EGLBoolean (EGLAPIENTRYP EglBindTexImage)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
70 typedef EGLBoolean (EGLAPIENTRYP EglReleaseTexImage)(EGLDisplay dpy, EGLSurface surface, EGLint buffer);
72 EglGetProcAddress m_eglGetProcAddress;
73 EglCreatePbufferSurface m_eglCreatePbufferSurface;
74 EglDestroySurface m_eglDestroySurface;
75 EglBindTexImage m_eglBindTexImage;
76 EglReleaseTexImage m_eglReleaseTexImage;
83struct WglNvDxInterop {
84 HANDLE (WINAPI* wglDXOpenDeviceNV) (
void* dxDevice);
85 BOOL (WINAPI* wglDXCloseDeviceNV) (HANDLE hDevice);
86 HANDLE (WINAPI* wglDXRegisterObjectNV) (HANDLE hDevice,
void *dxObject, GLuint name, GLenum type, GLenum access);
87 BOOL (WINAPI* wglDXSetResourceShareHandleNV) (
void *dxResource, HANDLE shareHandle);
88 BOOL (WINAPI* wglDXLockObjectsNV) (HANDLE hDevice, GLint count, HANDLE *hObjects);
89 BOOL (WINAPI* wglDXUnlockObjectsNV) (HANDLE hDevice, GLint count, HANDLE *hObjects);
90 BOOL (WINAPI* wglDXUnregisterObjectNV) (HANDLE hDevice, HANDLE hObject);
92 static const int WGL_ACCESS_READ_ONLY_NV = 0;
99 Q_DISABLE_COPY(D3DPresentEngine)
101 D3DPresentEngine(QVideoSink *sink);
102 virtual ~D3DPresentEngine();
104 bool isValid()
const;
106 HRESULT getService(REFGUID guidService, REFIID riid,
void** ppv);
107 HRESULT checkFormat(D3DFORMAT format);
108 UINT refreshRate()
const {
return m_displayMode.RefreshRate; }
110 HRESULT createVideoSamples(IMFMediaType *format, QList<ComPtr<IMFSample>> &videoSampleQueue,
112 QVideoFrameFormat videoSurfaceFormat()
const {
return m_surfaceFormat; }
113 QVideoFrame makeVideoFrame(
const ComPtr<IMFSample> &sample, QtVideo::Rotation rotation);
115 void releaseResources();
116 void setSink(QVideoSink *sink);
119 static const int PRESENTER_BUFFER_COUNT = 3;
121 HRESULT initializeD3D();
122 HRESULT createD3DDevice();
124 std::pair<IMFSample *, HANDLE> m_sampleTextureHandle[PRESENTER_BUFFER_COUNT] = {};
126 UINT m_deviceResetToken;
127 D3DDISPLAYMODE m_displayMode;
129 ComPtr<IDirect3D9Ex> m_D3D9;
130 ComPtr<IDirect3DDevice9Ex> m_device;
131 ComPtr<IDirect3DDeviceManager9> m_devices;
133 QVideoFrameFormat m_surfaceFormat;
135 QPointer<QVideoSink> m_sink;
136 bool m_useTextureRendering =
false;
138 WglNvDxInterop m_wglNvDxInterop;
142 unsigned int updateTexture(IDirect3DSurface9 *src);
144 OpenGLResources *m_glResources;
145 IDirect3DTexture9 *m_texture;
148 friend class IMFSampleVideoBuffer;
STDMETHODIMP_(ULONG) AddRef() override
AsyncCallback(T *parent, InvokeFn fn)
STDMETHODIMP QueryInterface(REFIID iid, void **ppv) override
STDMETHODIMP GetDeviceID(IID *deviceID) override
STDMETHODIMP GetSlowestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate) override
STDMETHODIMP OnClockStop(MFTIME systemTime) override
STDMETHODIMP ReleaseServicePointers() override
STDMETHODIMP QueryInterface(REFIID riid, void **ppv) override
STDMETHODIMP OnClockRestart(MFTIME systemTime) override
STDMETHODIMP InitServicePointers(IMFTopologyServiceLookup *lookup) override
STDMETHODIMP GetService(REFGUID guidService, REFIID riid, LPVOID *ppvObject) override
void supportedFormatsChanged()
void setCropRect(QRect cropRect)
STDMETHODIMP_(ULONG) AddRef() override
STDMETHODIMP IsRateSupported(BOOL thin, float rate, float *nearestSupportedRate) override
STDMETHODIMP OnClockSetRate(MFTIME systemTime, float rate) override
STDMETHODIMP GetCurrentMediaType(IMFVideoMediaType **mediaType) override
void setSink(QVideoSink *sink)
STDMETHODIMP GetFastestRate(MFRATE_DIRECTION direction, BOOL thin, float *rate) override
void presentSample(const ComPtr< IMFSample > &sample)
STDMETHODIMP OnClockStart(MFTIME systemTime, LONGLONG clockStartOffset) override
STDMETHODIMP OnClockPause(MFTIME systemTime) override
STDMETHODIMP ProcessMessage(MFVP_MESSAGE_TYPE message, ULONG_PTR param) override
~EVRCustomPresenter() override
EVRCustomPresenter(QVideoSink *sink=0)
ComPtr< IMFSample > sample() const
PresentSampleEvent(const ComPtr< IMFSample > &sample)
ComPtr< IMFSample > takeSample()
void returnSample(const ComPtr< IMFSample > &sample)
HRESULT initialize(QList< ComPtr< IMFSample > > &&samples)
Scheduler(EVRCustomPresenter *presenter)
HRESULT startScheduler(ComPtr< IMFClock > clock)
void setFrameRate(const MFRatio &fps)
void setClockRate(float rate)
HRESULT processSamplesInQueue(LONG *nextSleep)
bool areSamplesScheduled()
HRESULT scheduleSample(const ComPtr< IMFSample > &sample, bool presentNow)
static LONG MFTimeToMsec(const LONGLONG &time)
static QVideoFrameFormat::PixelFormat pixelFormatFromMediaType(IMFMediaType *type)
static HRESULT setMixerSourceRect(IMFTransform *mixer, const MFVideoNormalizedRect &nrcSource)
#define QMM_PRESENTATION_CURRENT_POSITION
static const DWORD SCHEDULER_TIMEOUT
bool qt_evr_setCustomPresenter(IUnknown *evr, EVRCustomPresenter *presenter)
static const LONG ONE_MSEC
static const MFTIME ONE_SECOND
static const MFRatio g_DefaultFrameRate
D3DFORMAT qt_evr_D3DFormatFromPixelFormat(QVideoFrameFormat::PixelFormat format)
bool qt_evr_areMediaTypesEqual(IMFMediaType *type1, IMFMediaType *type2)
QVideoFrameFormat::PixelFormat qt_evr_pixelFormatFromD3DFormat(DWORD format)
bool qt_evr_isSampleTimePassed(IMFClock *clock, IMFSample *sample)
HRESULT qt_evr_validateVideoArea(const MFVideoArea &area, UINT32 width, UINT32 height)
MFOffset qt_evr_makeMFOffset(float v)
HRESULT qt_evr_getFrameRate(IMFMediaType *pType, MFRatio *pRatio)
MFVideoArea qt_evr_makeMFArea(float x, float y, DWORD width, DWORD height)
float qt_evr_MFOffsetToFloat(const MFOffset &offset)
#define qCWarning(category,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)