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

Commit 6013357

Browse files
authored
Add super resolution support for renderer. (#518)
1 parent 4d82cc0 commit 6013357

File tree

6 files changed

+187
-1
lines changed

6 files changed

+187
-1
lines changed

talk/owt/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ static_library("owt_sdk_base") {
202202
"sdk/base/win/msdkvideoencoderfactory.h",
203203
"sdk/base/win/sysmem_allocator.cc",
204204
"sdk/base/win/sysmem_allocator.h",
205+
"sdk/base/win/vpedefs.h",
205206
]
206207
}
207208

talk/owt/sdk/base/globalconfiguration.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ IcePortRanges GlobalConfiguration::ice_port_ranges_ = {
2828
{0, 0}};
2929
bool GlobalConfiguration::pre_decode_dump_enabled_ = false;
3030
bool GlobalConfiguration::post_encode_dump_enabled_ = false;
31+
bool GlobalConfiguration::video_super_resolution_enabled_ = false;
3132
} // namespace base
3233
}

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

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <system_error>
1010
#include "talk/owt/sdk/base/nativehandlebuffer.h"
1111
#include "talk/owt/sdk/base/win/d3dnativeframe.h"
12+
#include "talk/owt/sdk/include/cpp/owt/base/globalconfiguration.h"
1213
#include "talk/owt/sdk/include/cpp/owt/base/videorendererinterface.h"
1314
#include "third_party/libyuv/include/libyuv/convert.h"
1415
#include "webrtc/api/video/i420_buffer.h"
@@ -19,9 +20,23 @@ using namespace rtc;
1920
namespace owt {
2021
namespace base {
2122

23+
// Driver specific VPE interface for SR/FRC.
24+
static const GUID GUID_VPE_INTERFACE = {
25+
0xedd1d4b9,
26+
0x8659,
27+
0x4cbc,
28+
{0xa4, 0xd6, 0x98, 0x31, 0xa2, 0x16, 0x3a, 0xc3}};
29+
30+
#define VPE_FN_SCALING_MODE_PARAM 0x37
31+
#define VPE_FN_MODE_PARAM 0x20
32+
#define VPE_FN_SET_VERSION_PARAM 0x01
33+
#define VPE_FN_SR_SET_PARAM 0x401
34+
#define VPE_FN_SET_CPU_GPU_COPY_PARAM 0x2B
35+
2236
WebrtcVideoRendererD3D11Impl::WebrtcVideoRendererD3D11Impl(HWND wnd)
2337
: wnd_(wnd), clock_(Clock::GetRealTimeClock()) {
2438
CreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)(&dxgi_factory_));
39+
sr_enabled_ = SupportSuperResolution();
2540
}
2641

2742
// The swapchain needs to use window height/width of even number.
@@ -35,7 +50,7 @@ bool WebrtcVideoRendererD3D11Impl::GetWindowSizeForSwapChain(int& width, int& he
3550
height = rect.bottom - rect.top;
3651

3752
if (width % 2) {
38-
window_width_ += 1;
53+
width += 1;
3954
}
4055
if (height % 2) {
4156
height += 1;
@@ -556,6 +571,61 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
556571
true, &rect);
557572
d3d11_video_context_->VideoProcessorSetStreamFrameFormat(
558573
video_processor_, 0, D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE);
574+
575+
// Setup VPE for SR.
576+
if (sr_enabled_) {
577+
VPE_FUNCTION function_params;
578+
VPE_VERSION vpe_version = {};
579+
VPE_MODE vpe_mode = {};
580+
SR_SCALING_MODE sr_scaling_params = {};
581+
VPE_SR_PARAMS sr_params = {};
582+
void* p_ext_data = nullptr;
583+
UINT data_size = 0;
584+
const GUID* p_ext_guid = nullptr;
585+
586+
// Set VPE version
587+
ZeroMemory(&function_params, sizeof(function_params));
588+
vpe_version.Version = (UINT)VPE_VERSION_3_0;
589+
function_params.Function = VPE_FN_SET_VERSION_PARAM;
590+
function_params.pVPEVersion = &vpe_version;
591+
p_ext_data = &function_params;
592+
data_size = sizeof(function_params);
593+
p_ext_guid = &GUID_VPE_INTERFACE;
594+
595+
hr = d3d11_video_context_->VideoProcessorSetOutputExtension(
596+
video_processor_, p_ext_guid, data_size, p_ext_data);
597+
if (FAILED(hr))
598+
goto sr_fail;
599+
600+
// Clear mode
601+
ZeroMemory(&function_params, sizeof(function_params));
602+
vpe_mode.Mode = VPE_MODE_NONE;
603+
function_params.Function = VPE_FN_MODE_PARAM;
604+
function_params.pVPEMode = &vpe_mode;
605+
p_ext_data = &function_params;
606+
data_size = sizeof(function_params);
607+
p_ext_guid = &GUID_VPE_INTERFACE;
608+
hr = d3d11_video_context_->VideoProcessorSetOutputExtension(
609+
video_processor_, p_ext_guid, data_size, p_ext_data);
610+
if (FAILED(hr))
611+
goto sr_fail;
612+
613+
// Set SR parameters
614+
ZeroMemory(&function_params, sizeof(function_params));
615+
sr_params.bEnable = true;
616+
sr_params.SRMode = DEFAULT_SCENARIO_MODE;
617+
function_params.Function = VPE_FN_SR_SET_PARAM;
618+
function_params.pSRParams = &sr_params;
619+
p_ext_data = &function_params;
620+
data_size = sizeof(function_params);
621+
p_ext_guid = &GUID_VPE_INTERFACE;
622+
hr = d3d11_video_context_->VideoProcessorSetOutputExtension(
623+
video_processor_, p_ext_guid, data_size, p_ext_data);
624+
if (FAILED(hr))
625+
goto sr_fail;
626+
}
627+
628+
sr_fail:
559629
hr = d3d11_video_context_->VideoProcessorBlt(
560630
video_processor_, output_view.Get(), 0, 1, &stream_data);
561631
if (FAILED(hr)) {
@@ -695,5 +765,10 @@ bool WebrtcVideoRendererD3D11Impl::CreateStagingTexture(int width, int height) {
695765
return true;
696766
}
697767

768+
// Checks support for super resolution.
769+
bool WebrtcVideoRendererD3D11Impl::SupportSuperResolution() {
770+
return GlobalConfiguration::GetVideoSuperResolutionEnabled();
771+
}
772+
698773
} // namespace base
699774
} // namespace owt

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <wrl.h>
2727
#include <vector>
2828

29+
#include "talk/owt/sdk/base/win/vpedefs.h"
2930
#include "webrtc/api/video/video_frame.h"
3031
#include "webrtc/api/video/video_sink_interface.h"
3132
#include "webrtc/rtc_base/thread.h"
@@ -53,6 +54,7 @@ class WebrtcVideoRendererD3D11Impl
5354
bool InitSwapChain(int widht, int height, bool reset);
5455
bool CreateStagingTexture(int width, int height);
5556
bool GetWindowSizeForSwapChain(int& width, int& height);
57+
bool SupportSuperResolution();
5658

5759
// Render window objects
5860
HWND wnd_ = nullptr;
@@ -91,6 +93,8 @@ class WebrtcVideoRendererD3D11Impl
9193
bool d3d11_raw_inited_ = false;
9294
// Remote view is using MPO swapchain.
9395
bool d3d11_mpo_inited_ = false;
96+
// Support super resolution
97+
bool sr_enabled_ = false;
9498
webrtc::Clock* clock_;
9599
};
96100

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

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (C) <2021> Intel Corporation
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#ifndef OWT_BASE_WIN_VPEDEFS_H
6+
#define OWT_BASE_WIN_VPEDEFS_H
7+
8+
enum ScalingMode : int {
9+
SCALING_MODE_DEFAULT = 0, // Default
10+
SCALING_MODE_QUALITY, // LowerPower
11+
SCALING_MODE_SUPERRESOLUTION // SuperREsolution
12+
};
13+
14+
enum VPEMode : int {
15+
VPE_MODE_NONE = 0x0,
16+
VPE_MODE_PREPROC = 0x1,
17+
VPE_MODE_CPU_GPU_COPY = 0x3,
18+
};
19+
20+
enum VPE_VERSION_ENUM : int {
21+
VPE_VERSION_1_0 = 0x0001,
22+
VPE_VERSION_2_0 = 0x0002,
23+
VPE_VERSION_3_0 = 0x0003,
24+
VPE_VERSION_UNKNOWN = 0xffff,
25+
};
26+
27+
enum VPE_SUPER_RESOLUTION_MODE : int {
28+
DEFAULT_SCENARIO_MODE = 0,
29+
CAMERA_SCENARIO_MODE = 1,
30+
};
31+
32+
enum VPE_CPU_GPU_COPY_DIRECTION : int {
33+
VPE_CPU_GPU_COPY_DIRECTION_CPU_TO_GPU,
34+
VPE_CPU_GPU_COPY_DIRECTION_GPU_TO_CPU,
35+
VPE_CPU_GPU_COPY_DIRECTION_MMC_IN,
36+
VPE_CPU_GPU_COPY_DIRECTION_NOW_MMC_IN,
37+
VPE_CPU_GPU_COPY_DIRECTION_MMC_OUT,
38+
VPE_CPU_GPU_COPY_DIRECTION_NOW_MMC_OUT,
39+
};
40+
41+
typedef struct _SR_SCALING_MODE {
42+
UINT Fastscaling;
43+
}SR_SCALING_MODE, *PSR_SCALING_MODE;
44+
45+
typedef struct _VPE_VERSION {
46+
UINT Version;
47+
}VPE_VERSION, *PVPE_VERSION;
48+
49+
typedef struct _VPE_MODE {
50+
UINT Mode;
51+
}VPE_MODE, *PVPE_MODE;
52+
53+
typedef struct _VPE_FUNCTION {
54+
UINT Function;
55+
union {
56+
void* pSrCalingmode;
57+
void* pVPEMode;
58+
void* pVPEVersion;
59+
void* pSRParams;
60+
void* pCpuGpuCopyParam;
61+
};
62+
} VPE_FUNCTION, *PVPE_FUNCTION;
63+
64+
typedef struct _VPE_SR_PARAMS {
65+
UINT bEnable : 1; // [in], Enable SR
66+
UINT ReservedBits : 31;
67+
VPE_SUPER_RESOLUTION_MODE SRMode;
68+
UINT Reserved[4];
69+
}VPE_SR_PARAMS, *PVPE_SR_PARAMS;
70+
71+
typedef struct _VPE_CPU_GPU_COPY_PARAM {
72+
VPE_CPU_GPU_COPY_DIRECTION Direction;
73+
UINT MemSize;
74+
void* pSystemMem;
75+
}VPE_CPU_GPU_COPY_PARAM, *PVPE_CPU_GPU_COPY_PARAM;
76+
77+
#endif

talk/owt/sdk/include/cpp/owt/base/globalconfiguration.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ class GlobalConfiguration {
8888
hardware_acceleration_enabled_ = enabled;
8989
}
9090
#endif
91+
92+
#if defined(WEBRTC_WIN)
93+
/**
94+
@brief Enable driver-based super resolution(SR) for video rendering if underlying
95+
platform supports it. This can only be enabled on Windows platform and is by default
96+
turned off. Requires 11th Generation Intel(R) Core(TM) processors or above, or
97+
Intel(R) discrete graphics for SR to function properly.
98+
Be noted turning this on does not neccessarily enable SR on all hardwares.
99+
If SR is not supported by driver, render will silently fall back to normal scaling mode
100+
and no error will be prompted. It is expected when SR is effectively on, 3D
101+
usage will increase, so application needs to balance accordingly.
102+
@param enabled If true, D3D11 video processor in the SDK will turn on SR when approriate.
103+
*/
104+
static void SetVideoSuperResolutionEnabled(bool enabled) {
105+
video_super_resolution_enabled_ = enabled;
106+
}
107+
108+
/**
109+
@brief Get SDK setting on whether super resolution is allowed. This does not
110+
neccessarily indicate if super resolution is effective on or not in render pipeline.
111+
@return True if SDK allows turnning on super resolution when appropriate. False otherwise.
112+
*/
113+
static bool GetVideoSuperResolutionEnabled() {
114+
return video_super_resolution_enabled_;
115+
}
116+
#endif
91117
/** @cond */
92118
/**
93119
@brief This function sets the capturing frame type to be encoded video frame.
@@ -339,6 +365,8 @@ class GlobalConfiguration {
339365
static std::unique_ptr<VideoDecoderInterface> video_decoder_;
340366

341367
static AudioProcessingSettings audio_processing_settings_;
368+
369+
static bool video_super_resolution_enabled_;
342370
};
343371
}
344372
}

0 commit comments

Comments
 (0)