Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

win-mf: Add Windows Media Foundation Capture Device and Intel NPU AI features #10471

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions cmake/Modules/FindWIL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#[=======================================================================[.rst
FindWIL
-------

FindModule for WIL and associated headers

Imported Targets
^^^^^^^^^^^^^^^^

.. versionadded:: 3.0

This module defines the :prop_tgt:`IMPORTED` target ``WIL::WIL``.

Result Variables
^^^^^^^^^^^^^^^^

This module sets the following variables:

``WIL_FOUND``
True, if headers were found.
``WIL_VERSION``
Detected version of found WIL headers.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``WIL_INCLUDE_DIR``
Directory containing ``cppwinrt.h``.

#]=======================================================================]

# cmake-format: off
# cmake-lint: disable=C0103
# cmake-lint: disable=C0301
# cmake-format: on

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_search_module(_WIL QUIET wil)
endif()

find_path(
WIL_INCLUDE_DIR
NAMES wil/cppwinrt.h
HINTS ${_WI_INCLUDE_DIRS} ${_WIL_INCLUDE_DIRS}
PATHS /usr/include /usr/local/include /opt/local/include /sw/include
DOC "WIL include directory")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
WIL
REQUIRED_VARS WIL_INCLUDE_DIR
VERSION_VAR WIL_VERSION REASON_FAILURE_MESSAGE "${WIL_ERROR_REASON}")
mark_as_advanced(WIL_INCLUDE_DIR)
unset(WIL_ERROR_REASON)

if(EXISTS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h")
file(STRINGS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h" _version_string REGEX "^.*VERSION_(MAJOR|MINOR)[ \t]+[0-9]+[ \t]*$")

string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")

set(WIL_VERSION "${_version_major}.${_version_minor}")
unset(_version_major)
unset(_version_minor)
else()
if(NOT WIL_FIND_QUIETLY)
message(AUTHOR_WARNING "Failed to find WIL version.")
endif()
set(WIL_VERSION 0.0.0)
endif()

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
set(WIL_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
set(WIL_ERROR_REASON "Ensure WIL headers are available in local library paths.")
endif()

if(WIL_FOUND)
set(WIL_INCLUDE_DIRS ${WIL_INCLUDE_DIR})

if(NOT TARGET WIL::WIL)
add_library(WIL::WIL INTERFACE IMPORTED)
set_target_properties(WIL::WIL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${WIL_INCLUDE_DIRS}")

endif()
endif()

include(FeatureSummary)
set_package_properties(
WIL PROPERTIES
URL "https://github.com/microsoft/wil.git"
DESCRIPTION
"The Windows Implementation Libraries (WIL) is a header-only C++ library created to make life easier for developers on Windows through readable type-safe C++ interfaces for common Windows coding patterns."
)
100 changes: 100 additions & 0 deletions cmake/finders/FindWIL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#[=======================================================================[.rst
FindWIL
-------

FindModule for WIL and associated headers

Imported Targets
^^^^^^^^^^^^^^^^

.. versionadded:: 3.0

This module defines the :prop_tgt:`IMPORTED` target ``WIL::WIL``.

Result Variables
^^^^^^^^^^^^^^^^

This module sets the following variables:

``WIL_FOUND``
True, if headers were found.
``WIL_VERSION``
Detected version of found WIL headers.

Cache variables
^^^^^^^^^^^^^^^

The following cache variables may also be set:

``WIL_INCLUDE_DIR``
Directory containing ``cppwinrt.h``.

#]=======================================================================]

# cmake-format: off
# cmake-lint: disable=C0103
# cmake-lint: disable=C0301
# cmake-format: on

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_search_module(_WIL QUIET wil)
endif()

find_path(
WIL_INCLUDE_DIR
NAMES wil/cppwinrt.h
HINTS ${_WI_INCLUDE_DIRS} ${_WIL_INCLUDE_DIRS}
PATHS /usr/include /usr/local/include /opt/local/include /sw/include
DOC "WIL include directory"
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
WIL
REQUIRED_VARS WIL_INCLUDE_DIR
VERSION_VAR WIL_VERSION
REASON_FAILURE_MESSAGE "${WIL_ERROR_REASON}"
)
mark_as_advanced(WIL_INCLUDE_DIR)
unset(WIL_ERROR_REASON)

if(EXISTS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h")
file(STRINGS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h" _version_string REGEX "^.*VERSION_(MAJOR|MINOR)[ \t]+[0-9]+[ \t]*$")

string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")

set(WIL_VERSION "${_version_major}.${_version_minor}")
unset(_version_major)
unset(_version_minor)
else()
if(NOT WIL_FIND_QUIETLY)
message(AUTHOR_WARNING "Failed to find WIL version.")
endif()
set(WIL_VERSION 0.0.0)
endif()

if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
set(WIL_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
set(WIL_ERROR_REASON "Ensure WIL headers are available in local library paths.")
endif()

if(WIL_FOUND)
set(WIL_INCLUDE_DIRS ${WIL_INCLUDE_DIR})

if(NOT TARGET WIL::WIL)
add_library(WIL::WIL INTERFACE IMPORTED)
set_target_properties(WIL::WIL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${WIL_INCLUDE_DIRS}")
endif()
endif()

include(FeatureSummary)
set_package_properties(
WIL
PROPERTIES
URL "https://github.com/microsoft/wil.git"
DESCRIPTION
"The Windows Implementation Libraries (WIL) is a header-only C++ library created to make life easier for developers on Windows through readable type-safe C++ interfaces for common Windows coding patterns."
)
1 change: 1 addition & 0 deletions plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,5 @@ add_obs_plugin(text-freetype2)
add_obs_plugin(vlc-video WITH_MESSAGE)
add_obs_plugin(win-capture PLATFORMS WINDOWS)
add_obs_plugin(win-dshow PLATFORMS WINDOWS)
add_obs_plugin(win-mf PLATFORMS WINDOWS)
add_obs_plugin(win-wasapi PLATFORMS WINDOWS)
48 changes: 48 additions & 0 deletions plugins/win-mf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
cmake_minimum_required(VERSION 3.24...3.25)

legacy_check()

find_package(FFmpeg REQUIRED avcodec avutil)
find_package(WIL REQUIRED)

add_library(win-mf MODULE)
add_library(OBS::mf ALIAS win-mf)

target_sources(win-mf PUBLIC mf-plugin.cpp win-mf.cpp)

add_library(libmfcapture INTERFACE)
add_library(OBS::libmfcapture ALIAS libmfcapture)

target_include_directories(libmfcapture INTERFACE libmfcapture libmfcapture/source)

target_sources(
libmfcapture
INTERFACE
libmfcapture/source/DeviceControlChangeListener.cpp
libmfcapture/source/mfcapture.cpp
libmfcapture/source/PhysicalCamera.cpp
)

configure_file(cmake/windows/obs-module.rc.in win-mf.rc)
target_sources(win-mf PRIVATE win-mf.rc)

target_precompile_headers(win-mf PRIVATE <wil/cppwinrt.h> <wil/result.h> <wil/com.h>)

target_link_libraries(
win-mf
PRIVATE
OBS::libobs
OBS::w32-pthreads
OBS::winrt-headers
FFmpeg::avcodec
FFmpeg::avutil
strmiids
winmm
dxcore
dxguid
libmfcapture
)

# cmake-format: off
set_target_properties_obs(win-mf PROPERTIES FOLDER plugins/win-mf PREFIX "")
# cmake-format: on
64 changes: 64 additions & 0 deletions plugins/win-mf/cmake/legacy.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
project(win-mf)

find_package(FFmpeg REQUIRED COMPONENTS avcodec avutil)
find_package(WIL REQUIRED)

add_library(win-mf MODULE)
add_library(OBS::mf ALIAS win-mf)

target_sources(win-mf PRIVATE mf-plugin.cpp plugin-macros.generated.h win-mf.cpp)

add_library(libmfcapture INTERFACE)
add_library(OBS::libmfcapture ALIAS libmfcapture)

target_sources(
libmfcapture
INTERFACE libmfcapture/mfcapture.hpp
libmfcapture/source/DeviceControlChangeListener.cpp
libmfcapture/source/DeviceControlChangeListener.hpp
libmfcapture/source/mfcapture.cpp
libmfcapture/source/framework.hpp
libmfcapture/source/mfcapture.rc
libmfcapture/source/PhysicalCamera.cpp
libmfcapture/source/PhysicalCamera.hpp
libmfcapture/source/resource.hpp)

target_include_directories(libmfcapture INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libmfcapture)

target_compile_definitions(libmfcapture INTERFACE _UP_WINDOWS=1)

set(MODULE_DESCRIPTION "OBS MediaFoundation module")

configure_file(${CMAKE_SOURCE_DIR}/cmake/bundle/windows/obs-module.rc.in win-mf.rc)

target_sources(win-mf PRIVATE win-mf.rc)

target_compile_definitions(win-mf PRIVATE UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS OBS_LEGACY)

target_link_libraries(
win-mf
PRIVATE OBS::libobs
OBS::w32-pthreads
setupapi
strmiids
ksuser
winmm
wmcodecdspuuid
FFmpeg::avcodec
FFmpeg::avutil
dxcore
dxguid
libmfcapture)

source_group(
"libmfcapture\\Source Files"
FILES libmfcapture/source/DeviceControlChangeListener.cpp libmfcapture/source/mfcapture.cpp
libmfcapture/source/mfcapture.rc libmfcapture/source/PhysicalCamera.cpp)
source_group(
"libmfcapture\\Header Files"
FILES libmfcapture/source/DeviceControlChangeListener.hpp libmfcapture/source/framework.hpp
libmfcapture/source/mfcapture.hpp libmfcapture/source/PhysicalCamera.hpp libmfcapture/source/resource.hpp)

set_target_properties(win-mf PROPERTIES FOLDER "plugins/win-mf")

setup_plugin_target(win-mf)
24 changes: 24 additions & 0 deletions plugins/win-mf/cmake/windows/obs-module.rc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
1 VERSIONINFO
FILEVERSION ${OBS_VERSION_MAJOR},${OBS_VERSION_MINOR},${OBS_VERSION_PATCH},0
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "${OBS_COMPANY_NAME}"
VALUE "FileDescription", "OBS Media Foundation module"
VALUE "FileVersion", "${OBS_VERSION_CANONICAL}"
VALUE "ProductName", "${OBS_PRODUCT_NAME}"
VALUE "ProductVersion", "${OBS_VERSION_CANONICAL}"
VALUE "Comments", "${OBS_COMMENTS}"
VALUE "LegalCopyright", "${OBS_LEGAL_COPYRIGHT}"
VALUE "InternalName", "win-mf"
VALUE "OriginalFilename", "win-mf"
END
END

BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 0x04B0
END
END
Loading
Loading