Skip to content

Commit

Permalink
fix: Dynamic library loading mode is optimized 1st
Browse files Browse the repository at this point in the history
  Dynamic library loading mode is optimized 1st

Log: Dynamic library loading mode is optimized 1st
  • Loading branch information
starhcq committed Jul 5, 2024
1 parent dca43ab commit b08b2c1
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/backends/mpv/mpv_glwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,9 @@ namespace dmr {
void MpvGLWidget::initMpvFuns()
{
qInfo() << "MpvGLWidget开始initMpvFuns";
QLibrary mpvLibrary(CompositingManager::libPath("libmpv.so.1"));
QString libPath = CompositingManager::libPath("libmpv.so.");
QLibrary mpvLibrary(libPath);

m_callback = reinterpret_cast<mpv_render_contextSet_update_callback>(mpvLibrary.resolve("mpv_render_context_set_update_callback"));
m_context_report = reinterpret_cast<mpv_render_contextReport_swap>(mpvLibrary.resolve("mpv_render_context_report_swap"));
m_renderContex = reinterpret_cast<mpv_renderContext_free>(mpvLibrary.resolve("mpv_render_context_free"));
Expand Down
8 changes: 7 additions & 1 deletion src/backends/mpv/mpv_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ void MpvProxy::setDecodeModel(const QVariant &value)

void MpvProxy::initMpvFuns()
{
QLibrary mpvLibrary(CompositingManager::libPath("libmpv.so.1"));
QString libPath = CompositingManager::libPath("libmpv.so.");
QLibrary mpvLibrary(libPath);

m_waitEvent = reinterpret_cast<mpv_waitEvent>(mpvLibrary.resolve("mpv_wait_event"));
m_setOptionString = reinterpret_cast<mpv_set_optionString>(mpvLibrary.resolve("mpv_set_option_string"));
Expand All @@ -160,10 +161,15 @@ void MpvProxy::initMpvFuns()
void MpvProxy::initGpuInfoFuns()
{
QString path = CompositingManager::libPath("libgpuinfo.so");
#ifdef LINGLONG_BUILD
if (!isLibExist(path))
return;
#else
if(!QFileInfo(path).exists()) {
m_gpuInfo = NULL;
return;
}
#endif
QLibrary mpvLibrary(CompositingManager::libPath("libgpuinfo.so"));
m_gpuInfo = reinterpret_cast<void *>(mpvLibrary.resolve("vdp_Iter_decoderInfo"));
}
Expand Down
2 changes: 1 addition & 1 deletion src/backends/mpv/mpv_proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class MpvHandle
explicit container(mpv_handle *pHandle) : m_pHandle(pHandle) {}
~container()
{
mpv_terminateDestroy func = (mpv_terminateDestroy)QLibrary::resolve(libPath("libmpv.so.1"), "mpv_terminate_destroy");
mpv_terminateDestroy func = (mpv_terminateDestroy)QLibrary::resolve(libPath("libmpv.so."), "mpv_terminate_destroy");
func(m_pHandle);
}
mpv_handle *m_pHandle;
Expand Down
32 changes: 26 additions & 6 deletions src/libdmr/compositing_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ using namespace std;

static CompositingManager *_compManager = nullptr;
bool CompositingManager::m_bCanHwdec = true;
QMap<QString, bool> m_mapSo2Exist = QMap<QString, bool>();

#define C2Q(cs) (QString::fromUtf8((cs).c_str()))

Expand Down Expand Up @@ -349,7 +350,14 @@ QString CompositingManager::libPath(const QString &strlib)
else
libName = strlib;

qDebug() << "libName:" << libName;
bool bExist = false;
if (m_mapSo2Exist.find(libName) == m_mapSo2Exist.end() && !libName.isEmpty()) {
QLibrary lib(libName);
bExist = lib.load();
m_mapSo2Exist[libName] = bExist;
}

qDebug() << QString("libName: $1 exist: %2").arg(libName).arg(bExist);

return libName;
#else
Expand All @@ -370,21 +378,33 @@ QString CompositingManager::libPath(const QString &strlib)
#endif
}

#ifdef LINGLONG_BUILD
bool CompositingManager::isLibExist(const QString &libName)
{
if (!libName.isEmpty())
return m_mapSo2Exist[libName];

return false;
}
#endif

void CompositingManager::setCanHwdec(bool bCanHwdec)
{
m_bCanHwdec = bCanHwdec;
}

bool CompositingManager::isMpvExists()
{
QDir dir;
QString path = QLibraryInfo::location(QLibraryInfo::LibrariesPath);
dir.setPath(path);
static QStringList list = dir.entryList(QStringList() << (QString("libmpv.so.1") + "*"), QDir::NoDotAndDotDot | QDir::Files);
if (list.contains("libmpv.so.1")) {
QString path = libPath("libmpv.so.");
#ifdef LINGLONG_BUILD
return isLibExist(path);
#else
if (path.contains("libmpv.so.")) {
qInfo() << "curreng load mpv is :" << path;
return true;
}
return false;
#endif
}

bool CompositingManager::isZXIntgraphics() const
Expand Down
6 changes: 6 additions & 0 deletions src/libdmr/compositing_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ class CompositingManager: public QObject
static bool isCanHwdec();
static void setCanHwdec(bool bCanHwdec);
static QString libPath(const QString &strlib);
#ifdef LINGLONG_BUILD
static bool isLibExist(const QString &libName);
#endif
/**
* @brief 判断是否可以使用mpv
*/
Expand Down Expand Up @@ -119,6 +122,9 @@ class CompositingManager: public QObject
static bool is_device_viable(int id);
static bool is_card_exists(int id, const std::vector<std::string> &drivers);

#ifdef LINGLONG_BUILD
static QMap<QString, bool> m_mapSo2Exist;
#endif
bool _composited {false};
Platform _platform {Platform::Unknown};
bool _isCoreFlag {false};
Expand Down
3 changes: 2 additions & 1 deletion src/libdmr/eventlogutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QJsonDocument>

#include "eventlogutils.h"
#include "compositing_manager.h"

EventLogUtils *EventLogUtils::m_instance(nullptr);

Expand All @@ -20,7 +21,7 @@ EventLogUtils &EventLogUtils::get()

EventLogUtils::EventLogUtils()
{
QLibrary library("libdeepin-event-log.so");
QLibrary library(dmr::CompositingManager::libPath("libdeepin-event-log.so"));

init =reinterpret_cast<bool (*)(const std::string &, bool)>(library.resolve("Initialize"));
writeEventLog = reinterpret_cast<void (*)(const std::string &)>(library.resolve("WriteEventLog"));
Expand Down
3 changes: 2 additions & 1 deletion src/libdmr/filefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ FileFilter::FileFilter()
m_pLoop = nullptr;
m_miType = MediaType::Other;

QLibrary avformatLibrary(CompositingManager::libPath("libavformat.so"));
QString libPath = CompositingManager::libPath("libavformat.so");
QLibrary avformatLibrary(libPath);

g_mvideo_avformat_open_input = (mvideo_avformat_open_input) avformatLibrary.resolve("avformat_open_input");
g_mvideo_avformat_find_stream_info = (mvideo_avformat_find_stream_info) avformatLibrary.resolve("avformat_find_stream_info");
Expand Down

0 comments on commit b08b2c1

Please sign in to comment.