| 533 | } |
| 534 | |
| 535 | const NDIlib_v6 *load_ndilib() |
| 536 | { |
| 537 | auto locations = QStringList(); |
| 538 | auto temp_path = QString(qgetenv(NDILIB_REDIST_FOLDER)); |
| 539 | if (!temp_path.isEmpty()) { |
| 540 | locations << temp_path; |
| 541 | } |
| 542 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACOS) |
| 543 | // Linux, MacOS |
| 544 | // https://github.com/DistroAV/DistroAV/blob/master/lib/ndi/NDI%20SDK%20Documentation.pdf |
| 545 | // "6.1 LOCATING THE LIBRARY |
| 546 | // ... the redistributable on MacOS is installed within `/usr/local/lib` ..." |
| 547 | // Flatpak install will look for the NDI lib in /app/plugins/DistroAV/extra/lib |
| 548 | locations << "/usr/lib"; |
| 549 | locations << "/usr/lib64"; |
| 550 | locations << "/usr/local/lib"; |
| 551 | #if defined(Q_OS_LINUX) |
| 552 | locations << "/app/plugins/DistroAV/extra/lib"; |
| 553 | #endif |
| 554 | #endif |
| 555 | auto lib_path = QString(); |
| 556 | #if defined(Q_OS_LINUX) |
| 557 | // Linux |
| 558 | auto regex = QRegularExpression("libndi\\.so\\.(\\d+)"); |
| 559 | int max_version = 0; |
| 560 | #endif |
| 561 | for (const auto &location : locations) { |
| 562 | auto dir = QDir(location); |
| 563 | #if defined(Q_OS_LINUX) |
| 564 | // Linux |
| 565 | auto filters = QStringList("libndi.so.*"); |
| 566 | dir.setNameFilters(filters); |
| 567 | auto file_names = dir.entryList(QDir::Files); |
| 568 | for (const auto &file_name : file_names) { |
| 569 | auto match = regex.match(file_name); |
| 570 | if (match.hasMatch()) { |
| 571 | int version = match.captured(1).toInt(); |
| 572 | if (version > max_version) { |
| 573 | max_version = version; |
| 574 | lib_path = dir.absoluteFilePath(file_name); |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | #else |
| 579 | // MacOS, Windows |
| 580 | temp_path = QDir::cleanPath(dir.absoluteFilePath(NDILIB_LIBRARY_NAME)); |
| 581 | obs_log(LOG_DEBUG, "load_ndilib: Trying '%s'", QT_TO_UTF8(QDir::toNativeSeparators(temp_path))); |
| 582 | auto file_info = QFileInfo(temp_path); |
| 583 | if (file_info.exists() && file_info.isFile()) { |
| 584 | lib_path = temp_path; |
| 585 | break; |
| 586 | } |
| 587 | #endif |
| 588 | } |
| 589 | if (!lib_path.isEmpty()) { |
| 590 | obs_log(LOG_DEBUG, "load_ndilib: Found '%s'; attempting to load NDI library...", |
| 591 | QT_TO_UTF8(QDir::toNativeSeparators(lib_path))); |
| 592 | loaded_lib = new QLibrary(lib_path, nullptr); |