Skip to content

Commit ba1f334

Browse files
committed
win-mf: Add Windows Media Foundation Capture Device
1 parent f60d6bc commit ba1f334

21 files changed

Lines changed: 4370 additions & 0 deletions

cmake/Modules/FindWIL.cmake

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#[=======================================================================[.rst
2+
FindWIL
3+
-------
4+
5+
FindModule for WIL and associated headers
6+
7+
Imported Targets
8+
^^^^^^^^^^^^^^^^
9+
10+
.. versionadded:: 3.0
11+
12+
This module defines the :prop_tgt:`IMPORTED` target ``WIL::WIL``.
13+
14+
Result Variables
15+
^^^^^^^^^^^^^^^^
16+
17+
This module sets the following variables:
18+
19+
``WIL_FOUND``
20+
True, if headers were found.
21+
``WIL_VERSION``
22+
Detected version of found WIL headers.
23+
24+
Cache variables
25+
^^^^^^^^^^^^^^^
26+
27+
The following cache variables may also be set:
28+
29+
``WIL_INCLUDE_DIR``
30+
Directory containing ``cppwinrt.h``.
31+
32+
#]=======================================================================]
33+
34+
# cmake-format: off
35+
# cmake-lint: disable=C0103
36+
# cmake-lint: disable=C0301
37+
# cmake-format: on
38+
39+
find_package(PkgConfig QUIET)
40+
if(PKG_CONFIG_FOUND)
41+
pkg_search_module(_WIL QUIET wil)
42+
endif()
43+
44+
find_path(
45+
WIL_INCLUDE_DIR
46+
NAMES wil/cppwinrt.h
47+
HINTS ${_WI_INCLUDE_DIRS} ${_WIL_INCLUDE_DIRS}
48+
PATHS /usr/include /usr/local/include /opt/local/include /sw/include
49+
DOC "WIL include directory")
50+
51+
include(FindPackageHandleStandardArgs)
52+
find_package_handle_standard_args(
53+
WIL
54+
REQUIRED_VARS WIL_INCLUDE_DIR
55+
VERSION_VAR WIL_VERSION REASON_FAILURE_MESSAGE "${WIL_ERROR_REASON}")
56+
mark_as_advanced(WIL_INCLUDE_DIR)
57+
unset(WIL_ERROR_REASON)
58+
59+
if(EXISTS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h")
60+
file(STRINGS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h" _version_string REGEX "^.*VERSION_(MAJOR|MINOR)[ \t]+[0-9]+[ \t]*$")
61+
62+
string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
63+
string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")
64+
65+
set(WIL_VERSION "${_version_major}.${_version_minor}")
66+
unset(_version_major)
67+
unset(_version_minor)
68+
else()
69+
if(NOT WIL_FIND_QUIETLY)
70+
message(AUTHOR_WARNING "Failed to find WIL version.")
71+
endif()
72+
set(WIL_VERSION 0.0.0)
73+
endif()
74+
75+
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
76+
set(WIL_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
77+
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
78+
set(WIL_ERROR_REASON "Ensure WIL headers are available in local library paths.")
79+
endif()
80+
81+
if(WIL_FOUND)
82+
set(WIL_INCLUDE_DIRS ${WIL_INCLUDE_DIR})
83+
84+
if(NOT TARGET WIL::WIL)
85+
add_library(WIL::WIL INTERFACE IMPORTED)
86+
set_target_properties(WIL::WIL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${WIL_INCLUDE_DIRS}")
87+
88+
endif()
89+
endif()
90+
91+
include(FeatureSummary)
92+
set_package_properties(
93+
WIL PROPERTIES
94+
URL "https://github.com/microsoft/wil.git"
95+
DESCRIPTION
96+
"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."
97+
)

cmake/finders/FindWIL.cmake

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#[=======================================================================[.rst
2+
FindWIL
3+
-------
4+
5+
FindModule for WIL and associated headers
6+
7+
Imported Targets
8+
^^^^^^^^^^^^^^^^
9+
10+
.. versionadded:: 3.0
11+
12+
This module defines the :prop_tgt:`IMPORTED` target ``WIL::WIL``.
13+
14+
Result Variables
15+
^^^^^^^^^^^^^^^^
16+
17+
This module sets the following variables:
18+
19+
``WIL_FOUND``
20+
True, if headers were found.
21+
``WIL_VERSION``
22+
Detected version of found WIL headers.
23+
24+
Cache variables
25+
^^^^^^^^^^^^^^^
26+
27+
The following cache variables may also be set:
28+
29+
``WIL_INCLUDE_DIR``
30+
Directory containing ``cppwinrt.h``.
31+
32+
#]=======================================================================]
33+
34+
# cmake-format: off
35+
# cmake-lint: disable=C0103
36+
# cmake-lint: disable=C0301
37+
# cmake-format: on
38+
39+
find_package(PkgConfig QUIET)
40+
if(PKG_CONFIG_FOUND)
41+
pkg_search_module(_WIL QUIET wil)
42+
endif()
43+
44+
find_path(
45+
WIL_INCLUDE_DIR
46+
NAMES wil/cppwinrt.h
47+
HINTS ${_WI_INCLUDE_DIRS} ${_WIL_INCLUDE_DIRS}
48+
PATHS /usr/include /usr/local/include /opt/local/include /sw/include
49+
DOC "WIL include directory")
50+
51+
include(FindPackageHandleStandardArgs)
52+
find_package_handle_standard_args(
53+
WIL
54+
REQUIRED_VARS WIL_INCLUDE_DIR
55+
VERSION_VAR WIL_VERSION REASON_FAILURE_MESSAGE "${WIL_ERROR_REASON}")
56+
mark_as_advanced(WIL_INCLUDE_DIR)
57+
unset(WIL_ERROR_REASON)
58+
59+
if(EXISTS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h")
60+
file(STRINGS "${WIL_INCLUDE_DIR}/wil/cppwinrt.h" _version_string REGEX "^.*VERSION_(MAJOR|MINOR)[ \t]+[0-9]+[ \t]*$")
61+
62+
string(REGEX REPLACE ".*VERSION_MAJOR[ \t]+([0-9]+).*" "\\1" _version_major "${_version_string}")
63+
string(REGEX REPLACE ".*VERSION_MINOR[ \t]+([0-9]+).*" "\\1" _version_minor "${_version_string}")
64+
65+
set(WIL_VERSION "${_version_major}.${_version_minor}")
66+
unset(_version_major)
67+
unset(_version_minor)
68+
else()
69+
if(NOT WIL_FIND_QUIETLY)
70+
message(AUTHOR_WARNING "Failed to find WIL version.")
71+
endif()
72+
set(WIL_VERSION 0.0.0)
73+
endif()
74+
75+
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin|Windows")
76+
set(WIL_ERROR_REASON "Ensure that obs-deps is provided as part of CMAKE_PREFIX_PATH.")
77+
elseif(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux|FreeBSD")
78+
set(WIL_ERROR_REASON "Ensure WIL headers are available in local library paths.")
79+
endif()
80+
81+
if(WIL_FOUND)
82+
set(WIL_INCLUDE_DIRS ${WIL_INCLUDE_DIR})
83+
84+
if(NOT TARGET WIL::WIL)
85+
add_library(WIL::WIL INTERFACE IMPORTED)
86+
set_target_properties(WIL::WIL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${WIL_INCLUDE_DIRS}")
87+
88+
endif()
89+
endif()
90+
91+
include(FeatureSummary)
92+
set_package_properties(
93+
WIL PROPERTIES
94+
URL "https://github.com/microsoft/wil.git"
95+
DESCRIPTION
96+
"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."
97+
)

plugins/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ if(OBS_CMAKE_VERSION VERSION_GREATER_EQUAL 3.0.0)
7272
add_obs_plugin(vlc-video WITH_MESSAGE)
7373
add_obs_plugin(win-capture PLATFORMS WINDOWS)
7474
add_obs_plugin(win-dshow PLATFORMS WINDOWS)
75+
add_obs_plugin(win-mf PLATFORMS WINDOWS)
7576
add_obs_plugin(win-wasapi PLATFORMS WINDOWS)
7677

7778
return()
@@ -94,6 +95,7 @@ endfunction()
9495
if(OS_WINDOWS)
9596
add_subdirectory(coreaudio-encoder)
9697
add_subdirectory(win-wasapi)
98+
add_subdirectory(win-mf)
9799
add_subdirectory(win-dshow)
98100
add_subdirectory(win-capture)
99101
add_subdirectory(decklink)

plugins/win-mf/CMakeLists.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.24...3.25)
2+
3+
legacy_check()
4+
5+
find_package(FFmpeg REQUIRED avcodec avutil)
6+
find_package(WIL REQUIRED)
7+
8+
add_library(win-mf MODULE)
9+
add_library(OBS::mf ALIAS win-mf)
10+
11+
target_sources(win-mf PUBLIC mf-plugin.cpp win-mf.cpp)
12+
13+
add_library(libmfcapture INTERFACE)
14+
add_library(OBS::libmfcapture ALIAS libmfcapture)
15+
16+
target_include_directories(libmfcapture INTERFACE libmfcapture libmfcapture/source)
17+
18+
target_sources(libmfcapture INTERFACE libmfcapture/source/DeviceControlChangeListener.cpp
19+
libmfcapture/source/mfcapture.cpp libmfcapture/source/PhysicalCamera.cpp)
20+
21+
configure_file(cmake/windows/obs-module.rc.in win-mf.rc)
22+
target_sources(win-mf PRIVATE win-mf.rc)
23+
24+
target_precompile_headers(win-mf PRIVATE <wil/cppwinrt.h> <wil/result.h> <wil/com.h>)
25+
26+
target_link_libraries(
27+
win-mf
28+
PRIVATE OBS::libobs
29+
OBS::w32-pthreads
30+
OBS::winrt-headers
31+
FFmpeg::avcodec
32+
FFmpeg::avutil
33+
strmiids
34+
winmm
35+
dxcore
36+
dxguid
37+
libmfcapture)
38+
39+
# cmake-format: off
40+
set_target_properties_obs(win-mf PROPERTIES FOLDER plugins/win-mf PREFIX "")
41+
# cmake-format: on

plugins/win-mf/cmake/legacy.cmake

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
project(win-mf)
2+
3+
find_package(FFmpeg REQUIRED COMPONENTS avcodec avutil)
4+
find_package(WIL REQUIRED)
5+
6+
add_library(win-mf MODULE)
7+
add_library(OBS::mf ALIAS win-mf)
8+
9+
target_sources(win-mf PRIVATE mf-plugin.cpp plugin-macros.generated.h win-mf.cpp)
10+
11+
add_library(libmfcapture INTERFACE)
12+
add_library(OBS::libmfcapture ALIAS libmfcapture)
13+
14+
target_sources(
15+
libmfcapture
16+
INTERFACE libmfcapture/mfcapture.hpp
17+
libmfcapture/source/DeviceControlChangeListener.cpp
18+
libmfcapture/source/DeviceControlChangeListener.hpp
19+
libmfcapture/source/mfcapture.cpp
20+
libmfcapture/source/framework.hpp
21+
libmfcapture/source/mfcapture.rc
22+
libmfcapture/source/PhysicalCamera.cpp
23+
libmfcapture/source/PhysicalCamera.hpp
24+
libmfcapture/source/resource.hpp)
25+
26+
target_include_directories(libmfcapture INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libmfcapture)
27+
28+
target_compile_definitions(libmfcapture INTERFACE _UP_WINDOWS=1)
29+
30+
set(MODULE_DESCRIPTION "OBS MediaFoundation module")
31+
32+
configure_file(${CMAKE_SOURCE_DIR}/cmake/bundle/windows/obs-module.rc.in win-mf.rc)
33+
34+
target_sources(win-mf PRIVATE win-mf.rc)
35+
36+
target_compile_definitions(win-mf PRIVATE UNICODE _UNICODE _CRT_SECURE_NO_WARNINGS _CRT_NONSTDC_NO_WARNINGS OBS_LEGACY)
37+
38+
target_link_libraries(
39+
win-mf
40+
PRIVATE OBS::libobs
41+
OBS::w32-pthreads
42+
setupapi
43+
strmiids
44+
ksuser
45+
winmm
46+
wmcodecdspuuid
47+
FFmpeg::avcodec
48+
FFmpeg::avutil
49+
dxcore
50+
dxguid
51+
libmfcapture)
52+
53+
source_group(
54+
"libmfcapture\\Source Files"
55+
FILES libmfcapture/source/DeviceControlChangeListener.cpp libmfcapture/source/mfcapture.cpp
56+
libmfcapture/source/mfcapture.rc libmfcapture/source/PhysicalCamera.cpp)
57+
source_group(
58+
"libmfcapture\\Header Files"
59+
FILES libmfcapture/source/DeviceControlChangeListener.hpp libmfcapture/source/framework.hpp
60+
libmfcapture/source/mfcapture.hpp libmfcapture/source/PhysicalCamera.hpp libmfcapture/source/resource.hpp)
61+
62+
set_target_properties(win-mf PROPERTIES FOLDER "plugins/win-mf")
63+
64+
setup_plugin_target(win-mf)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
1 VERSIONINFO
2+
FILEVERSION ${OBS_VERSION_MAJOR},${OBS_VERSION_MINOR},${OBS_VERSION_PATCH},0
3+
BEGIN
4+
BLOCK "StringFileInfo"
5+
BEGIN
6+
BLOCK "040904B0"
7+
BEGIN
8+
VALUE "CompanyName", "${OBS_COMPANY_NAME}"
9+
VALUE "FileDescription", "OBS Media Foundation module"
10+
VALUE "FileVersion", "${OBS_VERSION_CANONICAL}"
11+
VALUE "ProductName", "${OBS_PRODUCT_NAME}"
12+
VALUE "ProductVersion", "${OBS_VERSION_CANONICAL}"
13+
VALUE "Comments", "${OBS_COMMENTS}"
14+
VALUE "LegalCopyright", "${OBS_LEGAL_COPYRIGHT}"
15+
VALUE "InternalName", "win-mf"
16+
VALUE "OriginalFilename", "win-mf"
17+
END
18+
END
19+
20+
BLOCK "VarFileInfo"
21+
BEGIN
22+
VALUE "Translation", 0x0409, 0x04B0
23+
END
24+
END

0 commit comments

Comments
 (0)