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

Commit d979822

Browse files
taste1981jianjunz
andauthored
Cg client build support (#705)
* Add support for both CG server and client build. Update scripts and GN files to support CG client build on Windows. Macro OWT_CLOUD_GAMING will be removed soon, please move to OWT_CG_SERVER. * Build client without MSDK support. This allows building the dxva based decoder without dependency to MSDK. --------- Co-authored-by: Jianjun Zhu <[email protected]>
1 parent 204db47 commit d979822

File tree

14 files changed

+129
-132
lines changed

14 files changed

+129
-132
lines changed

DEPS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ deps = {
9898
Var('chromium_git') + '/chromium/src/third_party' + '@' + 'cd30703e732f3436f72f63c13f16ebb19803ddd6',
9999
# WebRTC-only dependencies (not present in Chromium).
100100
'src/third_party/webrtc':
101-
Var('deps_owt_git') + '/owt-deps-webrtc' + '@' + '15bb85d7886c653bba004f2b2826bc471d07fd96',
101+
Var('deps_owt_git') + '/owt-deps-webrtc' + '@' + 'c34716479181dfaac4635098422ed3914d9555c3',
102102
# Gradle 4.3-rc4. Used for testing Android Studio project generation for WebRTC.
103103
'src/third_party/webrtc/examples/androidtests/third_party/gradle': {
104104
'url': Var('chromium_git') + '/external/github.com/gradle/gradle.git' + '@' +

build_overrides/build.gni

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ declare_args() {
6969
# Enable HEVC for WebRTC.
7070
rtc_use_h265 = false
7171

72-
# Build OWT for cloud gaming. It enables low latency features, and disables audio processing. It may break normal WebRTC features, is not intended for general use.
73-
owt_cloud_gaming = false
72+
# Build OWT for cloud gaming. It enables low latency features, and disables audio processing for server side. It may break normal WebRTC features, is not intended for general use.
73+
owt_cg_server = false
74+
owt_cg_client = false
7475
}

scripts/build-win.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
]
3434

3535

36-
def gngen(arch, sio_root, ffmpeg_root, ssl_root, msdk_root, quic_root, scheme, tests, runtime, cloud_gaming):
36+
def gngen(arch, sio_root, ffmpeg_root, ssl_root, msdk_root, quic_root, scheme, tests, runtime, cg_server, cg_client):
3737
gn_args = list(GN_ARGS)
3838
gn_args.append('target_cpu="%s"' % arch)
3939
using_llvm = False
@@ -80,21 +80,24 @@ def gngen(arch, sio_root, ffmpeg_root, ssl_root, msdk_root, quic_root, scheme, t
8080
else:
8181
gn_args.append('rtc_include_tests=false')
8282
gn_args.append('owt_include_tests=false')
83-
if cloud_gaming:
83+
if cg_server:
8484
gn_args.append('rtc_enable_protobuf=false')
8585
gn_args.append('rtc_enable_win_wgc=false')
86-
gn_args.append('owt_cloud_gaming=true')
86+
gn_args.append('owt_cg_server=true')
8787
gn_args.append('enable_libaom=false')
8888
else:
8989
gn_args.append('enable_libaom=true')
90+
if cg_client:
91+
gn_args.append('owt_cg_client=true')
92+
gn_args.append('rtc_enable_protobuf=false')
9093
if sio_root:
9194
# If sio_root is not specified, conference SDK is not able to build.
9295
gn_args.append('owt_sio_header_root="%s"' % (sio_root + r'\include'))
9396
if ffmpeg_root:
9497
gn_args.append('owt_ffmpeg_header_root="%s"'%(ffmpeg_root+r'\include'))
95-
if ffmpeg_root or msdk_root or cloud_gaming:
98+
if ffmpeg_root or msdk_root or cg_server:
9699
gn_args.append('rtc_use_h264=true')
97-
if msdk_root or cloud_gaming:
100+
if msdk_root or cg_server:
98101
gn_args.append('rtc_use_h265=true')
99102
flattened_args = ' '.join(gn_args)
100103
ret = subprocess.call(['gn.bat', 'gen', getoutputpath(arch, scheme), '--args=%s' % flattened_args],
@@ -139,7 +142,6 @@ def runtest(arch, scheme):
139142

140143

141144
def gendocs():
142-
print('start ninja file generatio!')
143145
cmd_path = os.path.join(HOME_PATH, r'talk\owt\docs\cpp')
144146
doc_path = os.path.join(cmd_path, r'html')
145147
if os.path.exists(doc_path):
@@ -192,10 +194,19 @@ def main():
192194
parser.add_argument('--docs', default=False, action='store_true',
193195
help='To generate the API document.')
194196
parser.add_argument('--output_path', help='Path to copy sdk.')
197+
parser.add_argument('--cg_server', default=False,
198+
help='Build for cloud gaming server. This option is not intended to be used in general purpose. Setting to true may result unexpected behaviors. Default to false.', action='store_true')
195199
parser.add_argument('--cloud_gaming', default=False,
196-
help='Build for cloud gaming. This option is not intended to be used in general purpose. Setting to true may result unexpected behaviors. Default to false.', action='store_true')
200+
help='Deprecated. Please use cg_server instead.', action='store_true')
201+
parser.add_argument('--cg_client', default=False,
202+
help='Build for cloud gaming client. This option is not intended to be used in general purpose. Setting to true may result unexpected behaviors. Default to false.', action='store_true')
197203
opts = parser.parse_args()
198-
if not opts.sio_root and not opts.cloud_gaming:
204+
if opts.cg_server and opts.cg_client:
205+
print('Cannot build for both cloud gaming server and client.')
206+
return 1
207+
if opts.cloud_gaming:
208+
opts.cg_server = True
209+
if not opts.sio_root and not opts.cg_server and not opts.cg_client:
199210
print("sio_root is missing.")
200211
return 1
201212
if opts.ssl_root and not os.path.exists(os.path.expanduser(opts.ssl_root)):
@@ -211,7 +222,7 @@ def main():
211222
return 1
212223
if opts.gn_gen:
213224
if not gngen(opts.arch, opts.sio_root, opts.ffmpeg_root, opts.ssl_root, opts.msdk_root, opts.quic_root,
214-
opts.scheme, opts.tests, opts.runtime, opts.cloud_gaming):
225+
opts.scheme, opts.tests, opts.runtime, opts.cg_server, opts.cg_client):
215226
return 1
216227
if opts.sdk:
217228
if not ninjabuild(opts.arch, opts.scheme):

scripts/build_linux.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def gen_lib_path(scheme):
3939
out_lib = OUT_LIB % {'scheme': scheme}
4040
return os.path.join(HOME_PATH + r'/out', out_lib)
4141

42-
def gngen(arch, sio_root, ffmpeg_root, ssl_root, msdk_root, quic_root, scheme, tests, use_gcc, fake_audio, shared, cloud_gaming):
42+
def gngen(arch, sio_root, ffmpeg_root, ssl_root, msdk_root, quic_root, scheme, tests, use_gcc, fake_audio, shared, cg_server):
4343
gn_args = list(GN_ARGS)
4444
gn_args.append('target_cpu="%s"' % arch)
4545
if scheme == 'release':
@@ -89,15 +89,15 @@ def gngen(arch, sio_root, ffmpeg_root, ssl_root, msdk_root, quic_root, scheme, t
8989
gn_args.extend(['rtc_enable_protobuf=false', 'is_component_build=true'])
9090
else:
9191
gn_args.extend(['is_component_build=false'])
92-
if cloud_gaming:
93-
gn_args.extend(['owt_cloud_gaming=true', 'enable_libaom=false'])
92+
if cg_server:
93+
gn_args.extend(['owt_cg_server=true', 'enable_libaom=false'])
9494
else:
9595
gn_args.extend(['enable_libaom=true'])
9696
if ffmpeg_root:
9797
gn_args.append('owt_ffmpeg_header_root="%s"'%(ffmpeg_root+'/include'))
98-
if ffmpeg_root or msdk_root or cloud_gaming:
98+
if ffmpeg_root or msdk_root or cg_server:
9999
gn_args.append('rtc_use_h264=true')
100-
if msdk_root or cloud_gaming:
100+
if msdk_root or cg_server:
101101
gn_args.append('rtc_use_h265=true')
102102

103103
flattened_args = ' '.join(gn_args)
@@ -200,13 +200,18 @@ def main():
200200
parser.add_argument('--output_path', help='Path to copy sdk.')
201201
parser.add_argument('--use_gcc', help='Compile with GCC and libstdc++. Default is clang and libc++.', action='store_true')
202202
parser.add_argument('--shared', default=False, help='Build shared libraries. Default to static.', action='store_true')
203-
parser.add_argument('--cloud_gaming', default=False, help='Build for cloud gaming. This option is not intended to be used in general purpose. Setting to true may result unexpected behaviors. Default to false.', action='store_true')
203+
parser.add_argument('--cg_server', default=False,
204+
help='Build for cloud gaming server. This option is not intended to be used in general purpose. Setting to true may result unexpected behaviors. Default to false.', action='store_true')
205+
parser.add_argument('--cloud_gaming', default=False,
206+
help='Deprecated. Please use cg_server instead.', action='store_true')
204207
opts = parser.parse_args()
205-
if not opts.sio_root and not opts.cloud_gaming:
208+
if opts.cloud_gaming:
209+
opts.cg_server = True
210+
if not opts.sio_root and not opts.cg_server:
206211
print("sio_root is missing.")
207212
return 1
208213
if opts.gn_gen:
209-
if not gngen(opts.arch, opts.sio_root, opts.ffmpeg_root, opts.ssl_root, opts.msdk_root, opts.quic_root, opts.scheme, opts.tests, opts.use_gcc, opts.fake_audio, opts.shared, opts.cloud_gaming):
214+
if not gngen(opts.arch, opts.sio_root, opts.ffmpeg_root, opts.ssl_root, opts.msdk_root, opts.quic_root, opts.scheme, opts.tests, opts.use_gcc, opts.fake_audio, opts.shared, opts.cg_server):
210215
return 1
211216
if opts.sdk:
212217
if not ninjabuild(opts.arch, opts.scheme, opts.shared):

talk/owt/BUILD.gn

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static_library("owt_deps") {
9292
if (!is_ios) {
9393
if (is_component_build) {
9494
# Component build is only supported by cloud gaming mode on Linux.
95-
assert(owt_cloud_gaming)
95+
assert(owt_cg_server)
9696
shared_library("owt") {
9797
visibility = [ "*" ]
9898
deps = [
@@ -113,7 +113,7 @@ if (!is_ios) {
113113
"//third_party/webrtc:webrtc",
114114
"//third_party/webrtc/api:libjingle_peerconnection_api",
115115
]
116-
if (!owt_cloud_gaming) {
116+
if (!owt_cg_server && !owt_cg_client) {
117117
deps += [ ":owt_sdk_conf" ]
118118
}
119119
complete_static_lib = true
@@ -414,8 +414,8 @@ static_library("owt_sdk_p2p") {
414414
configs -= [ "//build/config/clang:find_bad_constructs" ]
415415
}
416416
configs += [ ":owt_common" ]
417-
if (owt_cloud_gaming) {
418-
defines = [ "OWT_CLOUD_GAMING" ]
417+
if (owt_cg_server) {
418+
defines = [ "OWT_CG_SERVER" ]
419419
}
420420
}
421421
static_library("owt_sdk_conf") {

talk/owt/sdk/base/win/d3d11device.cc

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
#include "talk/owt/sdk/base/win/d3d11device.h"
88
#include "rtc_base/logging.h"
99

10-
#define MSDK_D3D11_CHECK(result) \
11-
{ \
12-
if (FAILED(result)) { \
10+
#define MSDK_D3D11_CHECK(result) \
11+
{ \
12+
if (FAILED(result)) { \
1313
RTC_LOG(LS_ERROR) << "Failed with result:" << result; \
14-
return MFX_ERR_DEVICE_FAILED; \
15-
} \
14+
return false; \
15+
} \
1616
}
1717

1818
namespace owt {
@@ -25,8 +25,9 @@ RTCD3D11Device::~RTCD3D11Device() {
2525
Close();
2626
}
2727

28-
mfxStatus RTCD3D11Device::Init(mfxHDL window,
29-
mfxU32 adapter_num, ID3D11Device* device) {
28+
bool RTCD3D11Device::Init(mfxHDL window,
29+
int adapter_num,
30+
ID3D11Device* device) {
3031
window_handle_ = static_cast<HWND>(window);
3132
HRESULT hr;
3233

@@ -36,26 +37,26 @@ mfxStatus RTCD3D11Device::Init(mfxHDL window,
3637
// First get the immediate device context;
3738
device->GetImmediateContext(&external_d3d11_device_context_);
3839
if (external_d3d11_device_context_ == nullptr)
39-
return MFX_ERR_DEVICE_FAILED;
40+
return false;
4041

4142
// Get the ID3D11VideoDevice handle as well.
4243
hr = device->QueryInterface(__uuidof(ID3D11VideoDevice),
4344
(void**)&external_d3d11_video_device_);
4445
if (FAILED(hr))
45-
return MFX_ERR_DEVICE_FAILED;
46+
return false;
4647

4748
hr = external_d3d11_device_context_->QueryInterface(__uuidof(ID3D11VideoContext),
4849
(void**)&external_d3d11_video_context_);
4950
if (FAILED(hr))
50-
return MFX_ERR_DEVICE_FAILED;
51+
return false;
5152

5253
CComQIPtr<ID3D10Multithread> p_mt(external_d3d11_video_context_);
5354
if (p_mt) {
5455
p_mt->SetMultithreadProtected(true);
5556
} else {
56-
return MFX_ERR_DEVICE_FAILED;
57+
return false;
5758
}
58-
return MFX_ERR_NONE;
59+
return true;
5960
}
6061

6162
RTC_LOG(LS_ERROR) << "In d3d11device: Before create the dxgi factory.";
@@ -74,18 +75,18 @@ mfxStatus RTCD3D11Device::Init(mfxHDL window,
7475
MSDK_D3D11_CHECK(dxgi_factory_->EnumAdapters(adapter_num, &dxgi_adapter_));
7576

7677
RTC_LOG(LS_ERROR) << "In d3d11device: Before D3D11CreateDevice.";
77-
MSDK_D3D11_CHECK(D3D11CreateDevice(dxgi_adapter_, D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0,
78-
feature_levels, MSDK_ARRAY_LEN(feature_levels),
79-
D3D11_SDK_VERSION, &d3d11_device_,
80-
&feature_levels_out, &d3d11_device_context_));
78+
MSDK_D3D11_CHECK(D3D11CreateDevice(
79+
dxgi_adapter_, D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, feature_levels,
80+
sizeof(feature_levels), D3D11_SDK_VERSION, &d3d11_device_,
81+
&feature_levels_out, &d3d11_device_context_));
8182

8283
dxgi_device_ = d3d11_device_;
8384
d3d11_video_device_ = d3d11_device_;
8485
d3d11_video_context_ = d3d11_device_context_;
8586

8687
if (!dxgi_device_.p || !d3d11_video_device_.p || !d3d11_video_context_.p) {
8788
RTC_LOG(LS_ERROR) << "d3d11 device or context nullptr";
88-
return MFX_ERR_NULL_PTR;
89+
return false;
8990
}
9091

9192
// Turn on multi-threading for the context
@@ -94,32 +95,32 @@ mfxStatus RTCD3D11Device::Init(mfxHDL window,
9495
p_mt->SetMultithreadProtected(true);
9596
} else {
9697
RTC_LOG(LS_ERROR) << "Failed to turn on multi-threading for the context.";
97-
return MFX_ERR_DEVICE_FAILED;
98+
return false;
9899
}
99100

100-
return MFX_ERR_NONE;
101+
return true;
101102
}
102103

103-
mfxStatus RTCD3D11Device::Reset() {
104+
bool RTCD3D11Device::Reset() {
104105
// Currently do nothing.
105-
return MFX_ERR_NONE;
106+
return true;
106107
}
107108

108-
mfxStatus RTCD3D11Device::SetHandle(mfxHandleType handle_type, mfxHDL handle) {
109+
bool RTCD3D11Device::SetHandle(mfxHandleType handle_type, mfxHDL handle) {
109110
if (handle != nullptr) {
110111
window_handle_ = static_cast<HWND>(handle);
111-
return MFX_ERR_NONE;
112+
return true;
112113
}
113-
return MFX_ERR_UNSUPPORTED;
114+
return false;
114115
}
115116

116-
mfxStatus RTCD3D11Device::GetHandle(mfxHandleType handle_type, mfxHDL* handle) {
117+
bool RTCD3D11Device::GetHandle(mfxHandleType handle_type, mfxHDL* handle) {
117118
if (MFX_HANDLE_D3D11_DEVICE == handle_type) {
118119
*handle = external_d3d11_device_ != nullptr ? external_d3d11_device_
119120
: d3d11_device_.p;
120-
return MFX_ERR_NONE;
121+
return true;
121122
}
122-
return MFX_ERR_UNSUPPORTED;
123+
return false;
123124
}
124125

125126
void RTCD3D11Device::Close() {

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,37 @@
88
#include <d3d11.h>
99
#include <dxgi1_2.h>
1010
#include <windows.h>
11-
11+
#ifdef OWT_USE_MSDK
1212
#include "talk/owt/sdk/base/win/msdkvideobase.h"
13+
#endif
1314

1415
namespace owt {
1516
namespace base {
1617

18+
#ifndef OWT_USE_MSDK
19+
typedef enum {
20+
MFX_HANDLE_DIRECT3D_DEVICE_MANAGER9 = 1, /* IDirect3DDeviceManager9 */
21+
MFX_HANDLE_D3D9_DEVICE_MANAGER = MFX_HANDLE_DIRECT3D_DEVICE_MANAGER9,
22+
MFX_HANDLE_RESERVED1 = 2,
23+
MFX_HANDLE_D3D11_DEVICE = 3,
24+
MFX_HANDLE_VA_DISPLAY = 4,
25+
MFX_HANDLE_RESERVED3 = 5,
26+
} mfxHandleType;
27+
28+
typedef void* mfxHDL;
29+
typedef unsigned int mfxU32;
30+
typedef unsigned char mfxU8;
31+
#endif
32+
1733
class RTCD3D11Device {
1834
public:
1935
RTCD3D11Device();
2036
virtual ~RTCD3D11Device();
2137

22-
mfxStatus Init(mfxHDL window, mfxU32 adapter_idx, ID3D11Device* device);
23-
mfxStatus Reset();
24-
mfxStatus SetHandle(mfxHandleType handle_type, mfxHDL handle);
25-
mfxStatus GetHandle(mfxHandleType handle_type, mfxHDL* handle);
38+
bool Init(mfxHDL window, int adapter_idx, ID3D11Device* device);
39+
bool Reset();
40+
bool SetHandle(mfxHandleType handle_type, mfxHDL handle);
41+
bool GetHandle(mfxHandleType handle_type, mfxHDL* handle);
2642
void Close();
2743

2844
ID3D11Device* GetD3D11Device() const {

0 commit comments

Comments
 (0)