@@ -137,6 +137,12 @@ bool WebrtcVideoRendererD3D11Impl::InitSwapChain(int width,
137
137
window_width = rect.right - rect.left ;
138
138
window_height = rect.bottom - rect.top ;
139
139
140
+ if (window_width % 2 ) {
141
+ window_width += 1 ;
142
+ }
143
+ if (window_height % 2 ) {
144
+ window_height += 1 ;
145
+ }
140
146
rtc::CritScope lock (&d3d11_texture_lock_);
141
147
if (swap_chain_for_hwnd_) {
142
148
DXGI_SWAP_CHAIN_DESC desc;
@@ -151,6 +157,7 @@ bool WebrtcVideoRendererD3D11Impl::InitSwapChain(int width,
151
157
desc.BufferDesc .Height != (unsigned int )window_height) {
152
158
d3d11_device_context_->ClearState ();
153
159
d3d11_device_context_->Flush ();
160
+
154
161
hr = swap_chain_for_hwnd_->ResizeBuffers (0 , window_width, window_height,
155
162
DXGI_FORMAT_UNKNOWN, desc.Flags );
156
163
if (FAILED (hr)) {
@@ -256,6 +263,12 @@ void WebrtcVideoRendererD3D11Impl::RenderNV12DXGIMPO(int width, int height) {
256
263
window_width = rect.right - rect.left ;
257
264
window_height = rect.bottom - rect.top ;
258
265
266
+ if (window_width % 2 ) {
267
+ window_width += 1 ;
268
+ }
269
+ if (window_height % 2 ) {
270
+ window_height += 1 ;
271
+ }
259
272
if (!d3d11_video_device_) {
260
273
hr = d3d11_device_->QueryInterface (__uuidof (ID3D11VideoDevice),
261
274
(void **)&d3d11_video_device_);
@@ -363,8 +376,14 @@ bool WebrtcVideoRendererD3D11Impl::InitMPO(int width, int height) {
363
376
window_width = rect_width;
364
377
window_height = rect_height;
365
378
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;
368
387
swapChainDesc.Format = DXGI_FORMAT_NV12;
369
388
swapChainDesc.Stereo = false ;
370
389
swapChainDesc.SampleDesc .Count = 1 ; // Don't use multi-sampling.
@@ -460,14 +479,20 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
460
479
rtc::CritScope lock (&d3d11_texture_lock_);
461
480
HRESULT hr = S_OK;
462
481
463
- if (swap_chain_for_hwnd_ == nullptr )
482
+ if (swap_chain_for_hwnd_ == nullptr ) {
483
+ RTC_LOG (LS_ERROR) << " Invalid swap chain." ;
464
484
return ;
485
+ }
465
486
466
487
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;
470
494
return ;
495
+ }
471
496
472
497
D3D11_TEXTURE2D_DESC back_buffer_desc;
473
498
dxgi_back_buffer->GetDesc (&back_buffer_desc);
@@ -480,8 +505,10 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
480
505
hr = d3d11_video_device_->CreateVideoProcessorOutputView (
481
506
dxgi_back_buffer.Get (), video_processor_enum_, &output_view_desc,
482
507
&output_view);
483
- if (FAILED (hr))
508
+ if (FAILED (hr)) {
509
+ RTC_LOG (LS_ERROR) << " Failed to create output view." ;
484
510
return ;
511
+ }
485
512
486
513
D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC input_view_desc;
487
514
ZeroMemory (&input_view_desc, sizeof (input_view_desc));
@@ -492,8 +519,10 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
492
519
Microsoft::WRL::ComPtr<ID3D11VideoProcessorInputView> input_view;
493
520
hr = d3d11_video_device_->CreateVideoProcessorInputView (
494
521
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." ;
496
524
return ;
525
+ }
497
526
498
527
D3D11_VIDEO_PROCESSOR_STREAM stream_data;
499
528
ZeroMemory (&stream_data, sizeof (stream_data));
@@ -518,8 +547,10 @@ void WebrtcVideoRendererD3D11Impl::RenderD3D11Texture(int width, int height) {
518
547
video_processor_, 0 , D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE);
519
548
hr = d3d11_video_context_->VideoProcessorBlt (
520
549
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." ;
522
552
return ;
553
+ }
523
554
524
555
hr = swap_chain_for_hwnd_->Present (1 , 0 );
525
556
if (FAILED (hr)) {
0 commit comments