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
qwindowsmediafoundation.cpp
Go to the documentation of this file.
1// Copyright (C) 2021 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 <QtCore/qdebug.h>
6
8
9namespace {
10
11Q_GLOBAL_STATIC(QWindowsMediaFoundation, s_wmf);
12
13template <typename T>
14bool setProcAddress(QSystemLibrary &lib, T &f, const char name[])
15{
16 f = reinterpret_cast<T>(lib.resolve(name));
17 return static_cast<bool>(f);
18}
19
20} // namespace
21
22QWindowsMediaFoundation *QWindowsMediaFoundation::instance()
23{
24 if (s_wmf->valid())
25 return s_wmf;
26
27 return nullptr;
28}
29
30QWindowsMediaFoundation::QWindowsMediaFoundation()
31{
32 if (!m_mfplat.load(false))
33 return;
34
35 if (!m_mf.load(false))
36 return;
37
38 if (!m_mfreadwrite.load(false))
39 return;
40
41 m_valid = setProcAddress(m_mfplat, mfStartup, "MFStartup")
42 && setProcAddress(m_mfplat, mfShutdown, "MFShutdown")
43 && setProcAddress(m_mfplat, mfCreateMediaType, "MFCreateMediaType")
44 && setProcAddress(m_mfplat, mfCreateMemoryBuffer, "MFCreateMemoryBuffer")
45 && setProcAddress(m_mfplat, mfCreateSample, "MFCreateSample")
46 && setProcAddress(m_mfplat, mfCreateAttributes, "MFCreateAttributes")
47 && setProcAddress(m_mf, mfEnumDeviceSources, "MFEnumDeviceSources")
48 && setProcAddress(m_mfreadwrite, mfCreateSourceReaderFromMediaSource,
49 "MFCreateSourceReaderFromMediaSource");
50
51 Q_ASSERT(m_valid); // If it is not valid at this point, we have a programming bug
52}
53
54QWindowsMediaFoundation::~QWindowsMediaFoundation() = default;
55
56bool QWindowsMediaFoundation::valid() const
57{
58 return m_valid;
59}
60
61QMFRuntimeInit::QMFRuntimeInit(QWindowsMediaFoundation *wmf)
62 : m_wmf{ wmf }, m_initResult{ wmf ? m_wmf->mfStartup(MF_VERSION, MFSTARTUP_FULL) : E_FAIL }
63{
64 if (m_initResult != S_OK)
65 qErrnoWarning(m_initResult, "Failed to initialize Windows Media Foundation");
66}
67
69{
70 // According to documentation MFShutdown should be called
71 // also when MFStartup failed. This is wrong.
72 if (FAILED(m_initResult))
73 return;
74
75 const HRESULT hr = m_wmf->mfShutdown();
76 if (hr != S_OK)
77 qErrnoWarning(hr, "Failed to shut down Windows Media Foundation");
78}
79
80QT_END_NAMESPACE
Q_GLOBAL_STATIC(QWindowsMediaFoundation, s_wmf)
bool setProcAddress(QSystemLibrary &lib, T &f, const char name[])