Qt 6.x
The Qt SDK
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 "qwindowdefs_win.h"
6#include <QDebug>
7#include <QMutex>
8
10
11namespace {
12struct Holder {
14 {
15 QMutexLocker locker(&mutex);
16 instance = nullptr;
17 }
18 bool loadFailed = false;
20 std::unique_ptr<QWindowsMediaFoundation> instance;
21} holder;
22
23}
24
26
27template<typename T> bool setProcAddress(QSystemLibrary &lib, T &f, std::string_view name)
28{
29 f = reinterpret_cast<T>(lib.resolve(name.data()));
30 return bool(f);
31}
32
34{
35 QMutexLocker locker(&holder.mutex);
36 if (holder.instance)
37 return holder.instance.get();
38
39 if (holder.loadFailed)
40 return nullptr;
41
42 std::unique_ptr<QWindowsMediaFoundation> wmf(new QWindowsMediaFoundation);
43 if (wmf->m_mfplat.load(false)) {
44 if (setProcAddress(wmf->m_mfplat, wmf->mfCreateMediaType, "MFCreateMediaType")
45 && setProcAddress(wmf->m_mfplat, wmf->mfCreateMemoryBuffer, "MFCreateMemoryBuffer")
46 && setProcAddress(wmf->m_mfplat, wmf->mfCreateSample, "MFCreateSample"))
47 {
48 holder.instance = std::move(wmf);
49 return holder.instance.get();
50 }
51 }
52
53 holder.loadFailed = true;
54 return nullptr;
55}
56
\inmodule QtCore
Definition qmutex.h:317
\inmodule QtCore
Definition qmutex.h:285
static QWindowsMediaFoundation * instance()
Combined button and popup list for selecting options.
GLfloat GLfloat f
GLuint name
bool setProcAddress(QSystemLibrary &lib, T &f, std::string_view name)
QMutex mutex
[2]
std::unique_ptr< QWindowsMediaFoundation > instance