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

Commit cb71e52

Browse files
committed
Handle odd window size for swapchain creation.
1 parent ab671b8 commit cb71e52

File tree

1 file changed

+40
-9
lines changed

1 file changed

+40
-9
lines changed

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

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ bool WebrtcVideoRendererD3D11Impl::InitSwapChain(int width,
137137
window_width = rect.right - rect.left;
138138
window_height = rect.bottom - rect.top;
139139

140+
if (window_width % 2) {
141+
window_width += 1;
142+
}
143+
if (window_height % 2) {
144+
window_height += 1;
145+
}
140146
rtc::CritScope lock(&d3d11_texture_lock_);
141147
if (swap_chain_for_hwnd_) {
142148
DXGI_SWAP_CHAIN_DESC desc;
@@ -151,6 +157,7 @@ bool WebrtcVideoRendererD3D11Impl::InitSwapChain(int width,
151157
desc.BufferDesc.Height != (unsigned int)window_height) {
152158
d3d11_device_context_->ClearState();
153159
d3d11_device_context_->Flush();
160+
154161
hr = swap_chain_for_hwnd_->ResizeBuffers(0, window_width, window_height,
155162
DXGI_FORMAT_UNKNOWN, desc.Flags);
156163
if (FAILED(hr)) {
@@ -256,6 +263,12 @@ void WebrtcVideoRendererD3D11Impl::RenderNV12DXGIMPO(int width, int height) {
256263
window_width = rect.right - rect.left;
257264
window_height = rect.bottom - rect.top;
258265

266+
if (window_width % 2) {
267+
window_width += 1;
268+
}
269+
if (window_height % 2) {
270+
window_height += 1;
271+
}
259272
if (!d3d11_video_device_) {
260273
hr = d3d11_device_->QueryInterface(__uuidof(ID3D11VideoDevice),
261274
(void**)&d3d11_video_device_);
@@ -363,8 +376,14 @@ bool WebrtcVideoRendererD3D11Impl::InitMPO(int width, int height) {
363376
window_width = rect_width;
364377
window_height = rect_height;
365378

366-
swapChainDesc.Width = (rect_width%2) ? (rect_width + 1) : rect_width;
367-
swapChainDesc.Height = (rect_height%2) ? (rect_height + 1) : rect_height;
379+
if (window_width % 2) {
380+
window_width += 1;
381+
}
382+
if (window_height % 2) {
383+
window_height += 1;
384+
}
385+
swapChainDesc.Width = (rect_width % 2 != 0) ? (rect_width + 1) : rect_width;
386+
swapChainDesc.Height = (rect_height % 2 != 0) ? (rect_height + 1) : rect_height;
368387
swapChainDesc.Format = DXGI_FORMAT_NV12;
369388
swapChainDesc.Stereo = false;
370389
swapChainDesc.SampleDesc.Count = 1; // Don't use multi-sampling.
@@ -460,14 +479,20 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
460479
rtc::CritScope lock(&d3d11_texture_lock_);
461480
HRESULT hr = S_OK;
462481

463-
if (swap_chain_for_hwnd_ == nullptr)
482+
if (swap_chain_for_hwnd_ == nullptr) {
483+
RTC_LOG(LS_ERROR) << "Invalid swap chain.";
464484
return;
485+
}
465486

466487
Microsoft::WRL::ComPtr<ID3D11Texture2D> dxgi_back_buffer;
467-
hr = swap_chain_for_hwnd_->GetBuffer(0, __uuidof(ID3D11Texture2D),
468-
(void**)&dxgi_back_buffer);
469-
if (FAILED(hr))
488+
//hr = swap_chain_for_hwnd_->GetBuffer(0, __uuidof(ID3D11Texture2D),
489+
// (void**)&dxgi_back_buffer);
490+
hr = swap_chain_for_hwnd_->GetBuffer(0, IID_PPV_ARGS(&dxgi_back_buffer));
491+
if (FAILED(hr)) {
492+
std::string message = std::system_category().message(hr);
493+
RTC_LOG(LS_ERROR) << "Failed to get back buffer:" << message;
470494
return;
495+
}
471496

472497
D3D11_TEXTURE2D_DESC back_buffer_desc;
473498
dxgi_back_buffer->GetDesc(&back_buffer_desc);
@@ -480,8 +505,10 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
480505
hr = d3d11_video_device_->CreateVideoProcessorOutputView(
481506
dxgi_back_buffer.Get(), video_processor_enum_, &output_view_desc,
482507
&output_view);
483-
if (FAILED(hr))
508+
if (FAILED(hr)) {
509+
RTC_LOG(LS_ERROR) << "Failed to create output view.";
484510
return;
511+
}
485512

486513
D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC input_view_desc;
487514
ZeroMemory(&input_view_desc, sizeof(input_view_desc));
@@ -492,8 +519,10 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
492519
Microsoft::WRL::ComPtr<ID3D11VideoProcessorInputView> input_view;
493520
hr = d3d11_video_device_->CreateVideoProcessorInputView(
494521
d3d11_texture_, video_processor_enum_, &input_view_desc, &input_view);
495-
if (FAILED(hr))
522+
if (FAILED(hr)) {
523+
RTC_LOG(LS_ERROR) << "Failed to create input view.";
496524
return;
525+
}
497526

498527
D3D11_VIDEO_PROCESSOR_STREAM stream_data;
499528
ZeroMemory(&stream_data, sizeof(stream_data));
@@ -518,8 +547,10 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
518547
video_processor_, 0, D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE);
519548
hr = d3d11_video_context_->VideoProcessorBlt(
520549
video_processor_, output_view.Get(), 0, 1, &stream_data);
521-
if (FAILED(hr))
550+
if (FAILED(hr)) {
551+
RTC_LOG(LS_ERROR) << "Failed to blit.";
522552
return;
553+
}
523554

524555
hr = swap_chain_for_hwnd_->Present(1, 0);
525556
if (FAILED(hr)) {

0 commit comments

Comments
 (0)