Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
mfvideorenderercontrol.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include "mfactivate_p.h"
6
8
9#include <private/qplatformvideosink_p.h>
10
12
14{
15public:
16 EVRCustomPresenterActivate(QVideoSink *sink);
17
18 STDMETHODIMP ActivateObject(REFIID riid, void **ppv) override;
21
22 void setSink(QVideoSink *sink);
23 void setCropRect(QRect cropRect);
24
25private:
26 // Destructor is not public. Caller should call Release.
28
29 ComPtr<EVRCustomPresenter> m_presenter;
30 QVideoSink *m_videoSink;
31 QRect m_cropRect;
32 QMutex m_mutex;
33};
34
35
40
45
47{
48 if (m_sink)
49 m_sink->platformVideoSink()->setVideoFrame(QVideoFrame());
50
51 if (m_presenterActivate) {
52 m_presenterActivate->ShutdownObject();
53 m_presenterActivate.Reset();
54 }
55
56 if (m_currentActivate) {
57 m_currentActivate->ShutdownObject();
58 m_currentActivate.Reset();
59 }
60}
61
62void MFVideoRendererControl::setSink(QVideoSink *sink)
63{
64 m_sink = sink;
65
66 if (m_presenterActivate)
67 m_presenterActivate->setSink(m_sink);
68}
69
70void MFVideoRendererControl::setCropRect(const QRect &cropRect)
71{
72 if (m_presenterActivate)
73 m_presenterActivate->setCropRect(cropRect);
74}
75
77{
79
80 if (m_sink) {
81 // Create the EVR media sink, but replace the presenter with our own
82 if (SUCCEEDED(MFCreateVideoRendererActivate(::GetShellWindow(), &m_currentActivate))) {
83 m_presenterActivate = makeComObject<EVRCustomPresenterActivate>(m_sink);
84 m_currentActivate->SetUnknown(MF_ACTIVATE_CUSTOM_VIDEO_PRESENTER_ACTIVATE,
85 m_presenterActivate.Get());
86 }
87 }
88
89 return m_currentActivate.Get();
90}
91
93 : MFAbstractActivate(), m_videoSink(sink)
94{ }
95
97{
98 if (!ppv)
99 return E_INVALIDARG;
100 QMutexLocker locker(&m_mutex);
101 if (!m_presenter) {
102 m_presenter = makeComObject<EVRCustomPresenter>(m_videoSink);
103 m_presenter->setCropRect(m_cropRect);
104 }
105 return m_presenter->QueryInterface(riid, ppv);
106}
107
109{
110 // The presenter does not implement IMFShutdown so
111 // this function is the same as DetachObject()
112 return DetachObject();
113}
114
116{
117 QMutexLocker locker(&m_mutex);
118 if (m_presenter) {
119 m_presenter.Reset();
120 }
121 return S_OK;
122}
123
124void EVRCustomPresenterActivate::setSink(QVideoSink *sink)
125{
126 QMutexLocker locker(&m_mutex);
127 if (m_videoSink == sink)
128 return;
129
130 m_videoSink = sink;
131
132 if (m_presenter)
133 m_presenter->setSink(sink);
134}
135
137{
138 QMutexLocker locker(&m_mutex);
139 if (m_cropRect == cropRect)
140 return;
141
142 m_cropRect = cropRect;
143
144 if (m_presenter)
145 m_presenter->setCropRect(cropRect);
146}
147
148QT_END_NAMESPACE
STDMETHODIMP ActivateObject(REFIID riid, void **ppv) override
STDMETHODIMP ShutdownObject() override
STDMETHODIMP DetachObject() override
void setCropRect(const QRect &cropRect)
void setSink(QVideoSink *surface)
MFVideoRendererControl(QObject *parent=0)
\inmodule QtCore
Definition qmutex.h:346