Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit c4e5103

Browse files
authored
Implement media foundation based video capturer. (#521)
* Implement media foundation based video capturer. * Address review comments
1 parent ab0d40b commit c4e5103

File tree

6 files changed

+1141
-1
lines changed

6 files changed

+1141
-1
lines changed

talk/owt/BUILD.gn

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static_library("owt_sdk_base") {
140140
"sdk/base/encodedvideoencoderfactory.h",
141141
"sdk/base/webrtcvideorendererimpl.cc",
142142
"sdk/base/webrtcvideorendererimpl.h",
143+
"sdk/base/windowcapturer.cc",
143144
"sdk/include/cpp/owt/base/videodecoderinterface.h",
144145
]
145146
}
@@ -242,7 +243,11 @@ static_library("owt_sdk_base") {
242243
"sdk/base/win/videorendererd3d11.h",
243244
"sdk/base/win/vp9ratecontrol.cc",
244245
"sdk/base/win/vp9ratecontrol.h",
245-
"sdk/base/windowcapturer.cc",
246+
"sdk/base/win/d3d11_manager.h",
247+
"sdk/base/win/device_info_mf.h",
248+
"sdk/base/win/device_info_mf.cc",
249+
"sdk/base/win/video_capture_mf.h",
250+
"sdk/base/win/video_capture_mf.cc",
246251
]
247252
public_deps += [ "//third_party/webrtc/modules/audio_device:audio_device_module_from_input_and_output" ]
248253
public_deps += [ "//third_party/libvpx" ]

talk/owt/sdk/base/win/d3d11_manager.h

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright (C) <2021> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#ifndef OWT_BASE_WIN_D3D11_MANAGER_H
6+
#define OWT_BASE_WIN_D3D11_MANAGER_H
7+
8+
#include <atlbase.h>
9+
#include <dxgi1_2.h>
10+
#include <d3d11_2.h>
11+
#include <mfobjects.h>
12+
#include <mfapi.h>
13+
#include "webrtc/rtc_base/logging.h"
14+
#include "webrtc/rtc_base/ref_count.h"
15+
16+
namespace owt {
17+
namespace base {
18+
19+
class D3D11Manager : public rtc::RefCountInterface {
20+
public:
21+
D3D11Manager()
22+
: manager_(nullptr),
23+
device_(nullptr),
24+
ctx_(nullptr),
25+
adapter_(nullptr),
26+
mt_(nullptr),
27+
reset_token_(0) {}
28+
29+
~D3D11Manager() = default;
30+
31+
bool Init() {
32+
HRESULT hr = MFCreateDXGIDeviceManager(&reset_token_, &manager_);
33+
if (FAILED(hr)) {
34+
RTC_LOG(LS_ERROR) << "MFCreateDxgiDeviceManager failed with error hr:"
35+
<< hr;
36+
return false;
37+
}
38+
39+
CComPtr<IDXGIFactory2> factory;
40+
hr = CreateDXGIFactory1(__uuidof(IDXGIFactory2), (void**)(&factory));
41+
if (FAILED(hr)) {
42+
RTC_LOG(LS_ERROR) << "CreateDxgiFactory failed with error hr:" << hr;
43+
return false;
44+
}
45+
46+
hr = factory->EnumAdapters(0, &adapter_);
47+
if (FAILED(hr)) {
48+
RTC_LOG(LS_ERROR) << "EnumAdapters failed with error hr:" << hr;
49+
return false;
50+
}
51+
52+
UINT creation_flags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT | D3D11_CREATE_DEVICE_BGRA_SUPPORT;
53+
54+
D3D_FEATURE_LEVEL feature_levels_in[] = {
55+
D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1,
56+
D3D_FEATURE_LEVEL_10_0};
57+
58+
D3D_FEATURE_LEVEL feature_levels_out;
59+
hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr,
60+
creation_flags, feature_levels_in,
61+
ARRAYSIZE(feature_levels_in), D3D11_SDK_VERSION,
62+
&device_, &feature_levels_out, &ctx_);
63+
if (FAILED(hr)) {
64+
RTC_LOG(LS_ERROR) << "D3D11 CreateDevice failed with error hr:" << hr;
65+
return false;
66+
}
67+
68+
hr = manager_->ResetDevice(device_, reset_token_);
69+
if (FAILED(hr)) {
70+
RTC_LOG(LS_ERROR) << "ResetDevice failed with error hr:" << hr;
71+
return false;
72+
}
73+
74+
hr = device_->QueryInterface(__uuidof(ID3D10Multithread), (void**)(&mt_));
75+
if (FAILED(hr)) {
76+
RTC_LOG(LS_ERROR) << "CreateDxgiFactory failed with error hr:" << hr;
77+
return false;
78+
}
79+
80+
hr = mt_->SetMultithreadProtected(true);
81+
if (FAILED(hr)) {
82+
RTC_LOG(LS_ERROR) << "SetMultithread Protection failed with error hr:"
83+
<< hr;
84+
return false;
85+
}
86+
87+
return true;
88+
}
89+
90+
CComPtr<IMFDXGIDeviceManager> GetManager() {
91+
return manager_;
92+
}
93+
94+
CComPtr<ID3D11Device> GetDevice() {
95+
return device_;
96+
}
97+
98+
CComPtr<ID3D11DeviceContext> GetDeviceContext() {
99+
return ctx_;
100+
}
101+
102+
CComPtr<ID3D10Multithread> GetMultiThread() {
103+
return mt_;
104+
}
105+
106+
private:
107+
CComPtr<IMFDXGIDeviceManager> manager_;
108+
CComPtr<ID3D11Device> device_;
109+
CComPtr<ID3D11DeviceContext> ctx_;
110+
CComQIPtr<IDXGIAdapter> adapter_;
111+
CComPtr<ID3D10Multithread> mt_;
112+
UINT reset_token_;
113+
};
114+
} // namespace base
115+
} // namespace owt
116+
#endif //OWT_BASE_WIN_D3D11_MANAGER_H

0 commit comments

Comments
 (0)