Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qffmpegsymbolsresolveutils.cpp
Go to the documentation of this file.
1// Copyright (C) 2023 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
6#include <qdebug.h>
7#include <algorithm>
8#include <qloggingcategory.h>
9
11
12static Q_LOGGING_CATEGORY(qLcLibSymbolsRelolver, "qt.multimedia.ffmpeg.libsymbolsresolver");
13
15 LibsLoader libsLoader)
16 : m_libName(libName), m_libsLoader(libsLoader)
17{
18 Q_ASSERT(m_libName);
19 Q_ASSERT(m_libsLoader);
20 m_symbols.reserve(symbolsCount);
21}
22
24{
25 if (m_state.testAndSetRelaxed(Initial, Requested)
26 || !m_state.testAndSetAcquire(Ready, Finished))
27 return false;
28
29 qCDebug(qLcLibSymbolsRelolver)
30 << "Start" << m_libName << "symbols resolving:" << m_symbols.size() << "symbols";
31
32 Q_ASSERT(m_symbols.size() == m_symbols.capacity());
33
34 auto cleanup = qScopeGuard([this]() { m_symbols = {}; });
35
36 auto libs = m_libsLoader();
37 if (libs.empty()) {
38 qCWarning(qLcLibSymbolsRelolver) << "Couldn't load" << m_libName << "library";
39 return false;
40 }
41
42 std::vector<QFunctionPointer> functions(m_symbols.size());
43
44 auto resolveElement = [&libs](const SymbolElement &element) {
45 return resolve(libs, element.name);
46 };
47
48 std::transform(m_symbols.begin(), m_symbols.end(), functions.begin(), resolveElement);
49
50 if (std::find(functions.begin(), functions.end(), nullptr) != functions.end()) {
51 unload(libs);
52 qCWarning(qLcLibSymbolsRelolver) << "Couldn't resolve" << m_libName << "symbols";
53 return false;
54 }
55
56 for (size_t i = 0; i < functions.size(); ++i)
57 m_symbols[i].setter(functions[i]);
58
59 qCDebug(qLcLibSymbolsRelolver) << m_libName << "symbols resolved";
60 return true;
61}
62
64{
65 Q_ASSERT(setter);
66 Q_ASSERT(m_symbols.size() < m_symbols.capacity());
67
68 m_symbols.push_back({ name, setter });
69
70 // handle the corner case: a user has initialized QtMM with global vars construction
71 // and it happened before the symbols initializing
72 if (m_symbols.size() == m_symbols.capacity() && !m_state.testAndSetRelease(Initial, Ready)
73 && m_state.testAndSetRelease(Requested, Ready))
74 resolve();
75}
76
78{
79 for (auto &lib : libs)
80 lib->unload();
81}
82
84{
85 auto load = [](auto &lib) { return lib->load(); };
86 if (std::all_of(libs.begin(), libs.end(), load))
87 return true;
88
89 unload(libs);
90 return false;
91}
92
93QFunctionPointer LibSymbolsResolver::resolve(const Libs &libs, const char *symbolName)
94{
95 for (auto &lib : libs)
96 if (auto pointer = lib->resolve(symbolName))
98
99 qWarning() << "Cannot resolve symbol" << symbolName;
100 return nullptr;
101}
102
LibSymbolsResolver(const char *libName, size_t symbolsCount, LibsLoader libsLoader)
void(*)(QFunctionPointer) FunctionSetter
static void unload(const Libs &libs)
static bool tryLoad(const Libs &libs)
void registerSymbol(const char *name, FunctionSetter setter)
bool testAndSetRelaxed(T expectedValue, T newValue) noexcept
bool testAndSetAcquire(T expectedValue, T newValue) noexcept
bool testAndSetRelease(T expectedValue, T newValue) noexcept
p1 load("image.bmp")
Combined button and popup list for selecting options.
std::vector< std::unique_ptr< QLibrary > > Libs
constexpr size_t symbolsCount
#define qWarning
Definition qlogging.h:166
#define Q_LOGGING_CATEGORY(name,...)
#define qCWarning(category,...)
#define qCDebug(category,...)
GLuint name
GLsizei const void * pointer
Definition qopenglext.h:384
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
Definition qscopeguard.h:60
if(qFloatDistance(a, b)<(1<< 7))
[0]