Skip to content

FreeBSD #195

@paigeadelethompson

Description

@paigeadelethompson

I was kinda playing around with this to see if I could get something closer to what I need (2.9) to build on FreeBSD, currently the best one I can get is like 1.5 from 2022 from ports, but it actually wasn't too much work. FreeBSD uses
onevpl before it was renamed I guess,

/usr/ports/multimedia/onevpl oneVPL-2022.1.5/
I need something a little bit newer for OBS (to build the qsv driver): I could potentially build an older version of obs but not really because old QT vs new QT problems before 30 and the latest is 32 so I figured what the hell, this could be interesting. I guess I'll see if it works but I thought I'd give you a heads up incase I never get that far. Lately they've been wanting to improve the FreeBSD landscape a bit and make it more suitable for laptops which if you ask me like if you don't have things which use the graphics pipeline it's a wonder how you're getting any life out of your battery. I don't think even Linux handles using the graphics piplines for encode/decode very well (most of the time I have to find and install something that isn't part of any normal user experience as you might expect.)

Anyway I will test this and mess with it some more when I get chance (it does at least build now)

[sq@msi ~/libvpl]$ cmake --build build
[ 10%] Built target VPL
[ 13%] Built target vpl-inspect
[ 16%] Built target system_analyzer
[ 62%] Built target sample_common
[ 66%] Built target sample_decode
[ 78%] Built target sample_vpp
[ 85%] Built target sample_encode
[ 92%] Built target sample_multi_transcode
[100%] Built target vpl_wayland
[sq@msi ~/libvpl]$ 

* (HEAD detached at v2023.2.0)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index b50a74a..1a51ad5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -231,7 +231,7 @@ message(
 message(STATUS "  BUILD_DEV                            : ${BUILD_DEV}")
 message(STATUS "  BUILD_DISPATCHER                     : ${BUILD_DISPATCHER}")
 message(STATUS "  BUILD_TOOLS                          : ${BUILD_TOOLS}")
-if(CMAKE_SYSTEM_NAME MATCHES Linux)
+if(CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD")
   message(STATUS "  ENABLE_VA                            : ${ENABLE_VA}")
   message(STATUS "  ENABLE_DRM                           : ${ENABLE_DRM}")
   message(STATUS "  ENABLE_WAYLAND                       : ${ENABLE_WAYLAND}")
diff --git a/api/vpl/mfxdefs.h b/api/vpl/mfxdefs.h
index 2e8ad55..cce2d04 100644
--- a/api/vpl/mfxdefs.h
+++ b/api/vpl/mfxdefs.h
@@ -64,7 +64,7 @@ extern "C"
     #define MFX_PACK_BEGIN_STRUCT_W_PTR()    MFX_PACK_BEGIN_X(8)
     #define MFX_PACK_BEGIN_STRUCT_W_L_TYPE() MFX_PACK_BEGIN_X(8)
 /* 32-bit ILP32 data model Windows* (Intel(r) architecture) */
-#elif defined(_WIN32) || defined(_M_IX86) && !defined(__linux__)
+#elif defined(_WIN32) || defined(_M_IX86) && !defined(__linux__) && !defined(__FreeBSD__)
     #define MFX_PACK_BEGIN_STRUCT_W_PTR()    MFX_PACK_BEGIN_X(4)
     #define MFX_PACK_BEGIN_STRUCT_W_L_TYPE() MFX_PACK_BEGIN_X(8)
 /* 32-bit ILP32 data model Linux* */
@@ -99,7 +99,7 @@ extern "C"
        #define MFX_DEPRECATED __declspec(deprecated)
        #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg
        #define MFX_DEPRECATED_ENUM_FIELD_OUTSIDE(arg) __pragma(deprecated(arg))
-     #elif defined(__linux__)
+     #elif defined(__linux__) || defined(__FreeBSD__)
        #define MFX_DEPRECATED __attribute__((deprecated))
        #if defined(__cplusplus)
          #define MFX_DEPRECATED_ENUM_FIELD_INSIDE(arg) arg __attribute__((deprecated))
diff --git a/dispatcher/vpl/mfx_dispatcher_vpl.h b/dispatcher/vpl/mfx_dispatcher_vpl.h
index 443bbe8..2ad1880 100644
--- a/dispatcher/vpl/mfx_dispatcher_vpl.h
+++ b/dispatcher/vpl/mfx_dispatcher_vpl.h
@@ -48,7 +48,7 @@ typedef char CHAR_TYPE;
         #define MSDK_LIB_NAME L"libmfxhw64."
     #endif
     #define ONEVPL_PRIORITY_PATH_VAR L"ONEVPL_PRIORITY_PATH"
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__FreeBSD__)
     // Linux x64
     #define MSDK_LIB_NAME            "libmfxhw64."
     #define ONEVPL_PRIORITY_PATH_VAR "ONEVPL_PRIORITY_PATH"
diff --git a/dispatcher/vpl/mfx_dispatcher_vpl_loader.cpp b/dispatcher/vpl/mfx_dispatcher_vpl_loader.cpp
index c9aff94..bba898b 100644
--- a/dispatcher/vpl/mfx_dispatcher_vpl_loader.cpp
+++ b/dispatcher/vpl/mfx_dispatcher_vpl_loader.cpp
@@ -413,7 +413,7 @@ mfxU32 LoaderCtxVPL::GetSearchPathsLegacy(std::list<STRING_TYPE> &searchDirs) {
 mfxU32 LoaderCtxVPL::GetSearchPathsSystemDefault(std::list<STRING_TYPE> &searchDirs) {
     searchDirs.clear();
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     // Add the standard path for libmfx1 install in Ubuntu
     searchDirs.push_back("/usr/lib/x86_64-linux-gnu");
 
@@ -422,6 +422,7 @@ mfxU32 LoaderCtxVPL::GetSearchPathsSystemDefault(std::list<STRING_TYPE> &searchD
     searchDirs.push_back("/usr/lib");
     searchDirs.push_back("/lib64");
     searchDirs.push_back("/usr/lib64");
+    searchDirs.push_back("/usr/local/lib");
 #endif
 
     return (mfxU32)searchDirs.size();
diff --git a/dispatcher/vpl/mfx_dispatcher_vpl_lowlatency.cpp b/dispatcher/vpl/mfx_dispatcher_vpl_lowlatency.cpp
index 4908b2e..6916b0e 100644
--- a/dispatcher/vpl/mfx_dispatcher_vpl_lowlatency.cpp
+++ b/dispatcher/vpl/mfx_dispatcher_vpl_lowlatency.cpp
@@ -18,7 +18,7 @@
         #define LIB_ONEVPL L"libmfx64-gen.dll"
         #define LIB_MSDK   L"libmfxhw64.dll"
     #endif
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__FreeBSD__)
     // Linux x64
     #define LIB_ONEVPL "libmfx-gen.so.1.2"
     #define LIB_MSDK   "libmfxhw64.so.1"
@@ -197,7 +197,7 @@ mfxStatus LoaderCtxVPL::LoadLibsFromSystemDir(LibType libType) {
 }
 
 mfxStatus LoaderCtxVPL::LoadLibsFromMultipleDirs(LibType libType) {
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     // clang-format off
 
     // standard paths for RT installation on Linux
diff --git a/dispatcher/vpl/mfx_dispatcher_vpl_msdk.cpp b/dispatcher/vpl/mfx_dispatcher_vpl_msdk.cpp
index a48bb39..92a6bf7 100644
--- a/dispatcher/vpl/mfx_dispatcher_vpl_msdk.cpp
+++ b/dispatcher/vpl/mfx_dispatcher_vpl_msdk.cpp
@@ -10,7 +10,7 @@
     #include "vpl/mfx_dispatcher_vpl_win.h"
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     #include <pthread.h>
     #define strncpy_s(dst, size, src, cnt) strncpy((dst), (src), (cnt)) // NOLINT
 #endif
@@ -142,7 +142,7 @@ mfxStatus LoaderCtxMSDK::OpenSession(mfxSession *session,
     mfxInitializationParam vplParam = {};
     vplParam.AccelerationMode       = accelMode;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     vplParam.ExtParam    = (mfxExtBuffer **)&extParams;
     vplParam.NumExtParam = 1;
 #else
@@ -183,7 +183,7 @@ mfxAccelerationMode LoaderCtxMSDK::CvtAccelType(mfxIMPL implType, mfxIMPL implMe
 }
 
 mfxStatus LoaderCtxMSDK::GetDefaultAccelType(mfxU32 adapterID, mfxIMPL *implDefault, mfxU64 *luid) {
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     // VAAPI only
     *implDefault = MFX_IMPL_VIA_VAAPI;
     *luid        = 0;
@@ -235,7 +235,7 @@ mfxStatus LoaderCtxMSDK::QueryAPIVersion(STRING_TYPE libNameFull, mfxVersion *ms
         vplParam.AccelerationMode =
             (mfxAccelerationMode)CvtAccelType(MFX_IMPL_HARDWARE, implDefault & 0xFF00);
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
         vplParam.ExtParam    = (mfxExtBuffer **)&extParams;
         vplParam.NumExtParam = 1;
 #else
@@ -279,7 +279,7 @@ mfxStatus LoaderCtxMSDK::QueryMSDKCaps(STRING_TYPE libNameFull,
     m_libNameFull = libNameFull;
     m_deviceID    = 0;
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     // require pthreads to be linked in for MSDK RT to load
     pthread_key_t pkey;
     if (pthread_key_create(&pkey, NULL) == 0) {
@@ -489,7 +489,7 @@ mfxStatus LoaderCtxMSDK::GetRenderNodeDescription(mfxU32 adapterID,
     vendorID = 0;
     deviceID = 0;
 
-#if defined(__linux__)
+#if defined(__linux__) || defined(__FreeBSD__)
     mfxU32 DRMRenderNodeNum = 128 + adapterID;
     std::string nodeStr     = std::to_string(DRMRenderNodeNum);
 
@@ -580,7 +580,7 @@ mfxStatus LoaderCtxMSDK::QueryExtDeviceID(mfxExtendedDeviceId *extDeviceID,
             luidArr >>= 8;
         }
     }
-#elif defined(__linux__)
+#elif defined(__linux__) || defined(__FreeBSD__)
     extDeviceID->DRMPrimaryNodeNum = adapterID;
     extDeviceID->DRMRenderNodeNum  = 128 + adapterID;
 #endif
diff --git a/examples/api1x_core/legacy-decode/src/util.hpp b/examples/api1x_core/legacy-decode/src/util.hpp
index 1d64b31..d35e0ef 100644
--- a/examples/api1x_core/legacy-decode/src/util.hpp
+++ b/examples/api1x_core/legacy-decode/src/util.hpp
@@ -30,7 +30,7 @@ enum {
     #include "vpl/mfxdispatcher.h"
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     #include <fcntl.h>
     #include <unistd.h>
 #endif
diff --git a/examples/api1x_core/legacy-encode/src/util.hpp b/examples/api1x_core/legacy-encode/src/util.hpp
index 1d64b31..d35e0ef 100644
--- a/examples/api1x_core/legacy-encode/src/util.hpp
+++ b/examples/api1x_core/legacy-encode/src/util.hpp
@@ -30,7 +30,7 @@ enum {
     #include "vpl/mfxdispatcher.h"
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     #include <fcntl.h>
     #include <unistd.h>
 #endif
diff --git a/examples/api1x_core/legacy-vpp/src/util.hpp b/examples/api1x_core/legacy-vpp/src/util.hpp
index 1d64b31..d35e0ef 100644
--- a/examples/api1x_core/legacy-vpp/src/util.hpp
+++ b/examples/api1x_core/legacy-vpp/src/util.hpp
@@ -30,7 +30,7 @@ enum {
     #include "vpl/mfxdispatcher.h"
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     #include <fcntl.h>
     #include <unistd.h>
 #endif
diff --git a/examples/api2x/hello-decode/src/util.hpp b/examples/api2x/hello-decode/src/util.hpp
index 1d64b31..d35e0ef 100644
--- a/examples/api2x/hello-decode/src/util.hpp
+++ b/examples/api2x/hello-decode/src/util.hpp
@@ -30,7 +30,7 @@ enum {
     #include "vpl/mfxdispatcher.h"
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     #include <fcntl.h>
     #include <unistd.h>
 #endif
diff --git a/examples/api2x/hello-decvpp/src/util.hpp b/examples/api2x/hello-decvpp/src/util.hpp
index 1d64b31..d35e0ef 100644
--- a/examples/api2x/hello-decvpp/src/util.hpp
+++ b/examples/api2x/hello-decvpp/src/util.hpp
@@ -30,7 +30,7 @@ enum {
     #include "vpl/mfxdispatcher.h"
 #endif
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     #include <fcntl.h>
     #include <unistd.h>
 #endif
diff --git a/tools/cli/system_analyzer/system_analyzer.cpp b/tools/cli/system_analyzer/system_analyzer.cpp
index 6b6f712..534baa5 100644
--- a/tools/cli/system_analyzer/system_analyzer.cpp
+++ b/tools/cli/system_analyzer/system_analyzer.cpp
@@ -14,11 +14,11 @@
 #include <vector>
 #include "vpl/mfx.h"
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
     #include <fcntl.h>
     #include <stdlib.h>
     #include <unistd.h>
-    #include "dlfcn.h"
+    #include <dlfcn.h>
     #include "va/va.h"
     #include "va/va_drm.h"
 #endif
diff --git a/tools/legacy/sample_common/CMakeLists.txt b/tools/legacy/sample_common/CMakeLists.txt
index df15a4f..86f214f 100644
--- a/tools/legacy/sample_common/CMakeLists.txt
+++ b/tools/legacy/sample_common/CMakeLists.txt
@@ -4,7 +4,7 @@
 # SPDX-License-Identifier: MIT
 # ##############################################################################
 set(TOOLS_DEFAULT ON)
-if(CMAKE_SYSTEM_NAME MATCHES Linux)
+if(CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD")
   # Check dependencies up-front so we can set option defaults
   find_package(PkgConfig REQUIRED)
   # note: pkg-config version for libva is *API* version
@@ -161,7 +161,7 @@ if(BUILD_TOOLS_ONEVPL_EXPERIMENTAL)
   target_compile_definitions(${TARGET} PUBLIC -DONEVPL_EXPERIMENTAL)
 endif()
 
-if(CMAKE_SYSTEM_NAME MATCHES Linux)
+if(CMAKE_SYSTEM_NAME MATCHES "Linux|FreeBSD")
   target_compile_definitions(${TARGET} PUBLIC LINUX64)
 
   if(NOT ENABLE_VA)
diff --git a/tools/legacy/sample_common/include/base_allocator.h b/tools/legacy/sample_common/include/base_allocator.h
index 693807b..c833e53 100644
--- a/tools/legacy/sample_common/include/base_allocator.h
+++ b/tools/legacy/sample_common/include/base_allocator.h
@@ -156,8 +156,7 @@ protected:
     std::list<mfxFrameAllocResponse> m_responses;
     std::list<UniqueResponse> m_ExtResponses;
 
-    struct IsSame
-            : public std::binary_function<mfxFrameAllocResponse, mfxFrameAllocResponse, bool> {
+    struct IsSame {
         bool operator()(const mfxFrameAllocResponse& l, const mfxFrameAllocResponse& r) const {
             return r.mids != 0 && l.mids != 0 && r.mids[0] == l.mids[0] &&
                    r.NumFrameActual == l.NumFrameActual;
diff --git a/tools/legacy/sample_common/src/base_allocator.cpp b/tools/legacy/sample_common/src/base_allocator.cpp
index fccb808..39fb255 100644
--- a/tools/legacy/sample_common/src/base_allocator.cpp
+++ b/tools/legacy/sample_common/src/base_allocator.cpp
@@ -162,9 +162,10 @@ mfxStatus BaseFrameAllocator::FreeFrames(mfxFrameAllocResponse* response) {
     mfxStatus sts = MFX_ERR_NONE;
 
     // check whether response is an external decoder response
-    std::list<UniqueResponse>::iterator i = std::find_if(m_ExtResponses.begin(),
-                                                         m_ExtResponses.end(),
-                                                         std::bind1st(IsSame(), *response));
+    std::list<UniqueResponse>::iterator i = std::find_if(
+        m_ExtResponses.begin(),
+        m_ExtResponses.end(),
+        [&](const UniqueResponse& res) { return IsSame()(*response, res); });
 
     if (i != m_ExtResponses.end()) {
         if ((--i->m_refCount) == 0) {
@@ -176,7 +177,9 @@ mfxStatus BaseFrameAllocator::FreeFrames(mfxFrameAllocResponse* response) {
 
     // if not found so far, then search in internal responses
     std::list<mfxFrameAllocResponse>::iterator i2 =
-        std::find_if(m_responses.begin(), m_responses.end(), std::bind1st(IsSame(), *response));
+        std::find_if(m_responses.begin(),
+                     m_responses.end(),
+                     [&](const mfxFrameAllocResponse& res) { return IsSame()(*response, res); });
 
     if (i2 != m_responses.end()) {
         sts = ReleaseResponse(response);
diff --git a/tools/legacy/sample_common/src/vm/thread_linux.cpp b/tools/legacy/sample_common/src/vm/thread_linux.cpp
index cf3fa9a..b220bd4 100644
--- a/tools/legacy/sample_common/src/vm/thread_linux.cpp
+++ b/tools/legacy/sample_common/src/vm/thread_linux.cpp
@@ -283,12 +283,16 @@ mfxStatus msdk_thread_get_schedtype(const msdk_char* str, mfxI32& type) {
     else if (!msdk_strcmp(str, MSDK_STRING("other"))) {
         type = SCHED_OTHER;
     }
+#ifdef SCHED_BATCH
     else if (!msdk_strcmp(str, MSDK_STRING("batch"))) {
         type = SCHED_BATCH;
     }
+#endif
+#ifdef SCHED_IDLE
     else if (!msdk_strcmp(str, MSDK_STRING("idle"))) {
         type = SCHED_IDLE;
     }
+#endif
     //    else if (!msdk_strcmp(str, MSDK_STRING("deadline"))) {
     //        type = SCHED_DEADLINE;
     //    }
diff --git a/tools/legacy/sample_common/src/vpl_implementation_loader.cpp b/tools/legacy/sample_common/src/vpl_implementation_loader.cpp
index e54b3fe..18d42f1 100644
--- a/tools/legacy/sample_common/src/vpl_implementation_loader.cpp
+++ b/tools/legacy/sample_common/src/vpl_implementation_loader.cpp
@@ -9,7 +9,7 @@
 #include "sample_utils.h"
 #include "vpl/mfxdispatcher.h"
 
-#if defined(LINUX32) || defined(LINUX64)
+#if defined(LINUX32) || defined(LINUX64) || defined(__linux__) || defined(__FreeBSD__)
     #include <link.h>
     #include <string.h>
 #else
@@ -587,7 +587,7 @@ mfxStatus MainVideoSession::PrintLibInfo(VPLImplementationLoader* Loader) {
     }
 
     // Module Name
-#if (defined(LINUX32) || defined(LINUX64))
+#if defined(LINUX32) || defined(LINUX64) || defined(__linux__) || defined(__FreeBSD__)
     #ifdef ONEVPL_EXPERIMENTAL
     msdk_printf(MSDK_STRING("    DRMRenderNodeNum: %d \n"), Loader->GetDRMRenderNodeNumUsed());
     #endif
diff --git a/tools/legacy/sample_misc/wayland/CMakeLists.txt b/tools/legacy/sample_misc/wayland/CMakeLists.txt
index 471bcd9..9d6da16 100644
--- a/tools/legacy/sample_misc/wayland/CMakeLists.txt
+++ b/tools/legacy/sample_misc/wayland/CMakeLists.txt
@@ -109,8 +109,12 @@ if(PKGConfig_LIBDRM_FOUND)
     )
   endif()
 
-  target_link_libraries(${TARGET} PRIVATE sample_common wayland-client va drm
-                                          drm_intel)
+  target_link_libraries(
+    ${TARGET}
+    PRIVATE sample_common
+            PkgConfig::PKG_WAYLAND_CLIENT
+            PkgConfig::PKG_LIBVA
+            PkgConfig::PKGConfig_LIBDRM)
 
   install(TARGETS ${TARGET}
           LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions