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 m_valid = setProcAddress(m_mfplat, mfStartup, "MFStartup")
36 && setProcAddress(m_mfplat, mfShutdown, "MFShutdown")
37 && setProcAddress(m_mfplat, mfCreateMediaType, "MFCreateMediaType")
38 && setProcAddress(m_mfplat, mfCreateMemoryBuffer, "MFCreateMemoryBuffer")
39 && setProcAddress(m_mfplat, mfCreateSample, "MFCreateSample");
40
41 Q_ASSERT(m_valid); // If it is not valid at this point, we have a programming bug
42}
43
44QWindowsMediaFoundation::~QWindowsMediaFoundation() = default;
45
46bool QWindowsMediaFoundation::valid() const
47{
48 return m_valid;
49}
50
51QMFRuntimeInit::QMFRuntimeInit(QWindowsMediaFoundation *wmf)
52 : m_wmf{ wmf }, m_initResult{ wmf ? m_wmf->mfStartup(MF_VERSION, MFSTARTUP_FULL) : E_FAIL }
53{
54 if (m_initResult != S_OK)
55 qErrnoWarning(m_initResult, "Failed to initialize Windows Media Foundation");
56}
57
59{
60 // According to documentation MFShutdown should be called
61 // also when MFStartup failed. This is wrong.
62 if (FAILED(m_initResult))
63 return;
64
65 const HRESULT hr = m_wmf->mfShutdown();
66 if (hr != S_OK)
67 qErrnoWarning(hr, "Failed to shut down Windows Media Foundation");
68}
69
70QT_END_NAMESPACE
Combined button and popup list for selecting options.
Q_GLOBAL_STATIC(QWindowsMediaFoundation, s_wmf)
bool setProcAddress(QSystemLibrary &lib, T &f, const char name[])