Index: webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc |
diff --git a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc |
index bdada9e3982244261a4f659ca74b4b5abf2126f3..8a2e77c7563aff84f6411b81887ce2dc17603ca6 100644 |
--- a/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc |
+++ b/webrtc/modules/desktop_capture/win/screen_capturer_win_directx.cc |
@@ -413,27 +413,28 @@ |
_com_error error = g_container->output1->DuplicateOutput( |
static_cast<IUnknown*>(g_container->device), |
g_container->duplication.GetAddressOf()); |
- if (error.Error() != S_OK || !g_container->duplication) { |
+ if (error.Error() == S_OK && g_container->duplication) { |
+ memset(&g_container->duplication_desc, 0, sizeof(DXGI_OUTDUPL_DESC)); |
+ g_container->duplication->GetDesc(&g_container->duplication_desc); |
+ if (g_container->duplication_desc.ModeDesc.Format != |
+ DXGI_FORMAT_B8G8R8A8_UNORM) { |
+ g_container->duplication.Reset(); |
+ LOG(LS_ERROR) << "IDXGIDuplicateOutput does not use RGBA (8 bit) " |
+ "format, which is required by downstream components, " |
+ "format is " |
+ << g_container->duplication_desc.ModeDesc.Format; |
+ return false; |
+ } |
+ return true; |
+ } else { |
+ // Make sure we have correct signal and duplicate the output next time. |
g_container->duplication.Reset(); |
LOG(LS_WARNING) << "Failed to duplicate output from IDXGIOutput1, error " |
<< error.ErrorMessage() << ", with code " |
<< error.Error(); |
- return false; |
- } |
- |
- memset(&g_container->duplication_desc, 0, sizeof(DXGI_OUTDUPL_DESC)); |
- g_container->duplication->GetDesc(&g_container->duplication_desc); |
- if (g_container->duplication_desc.ModeDesc.Format != |
- DXGI_FORMAT_B8G8R8A8_UNORM) { |
- g_container->duplication.Reset(); |
- LOG(LS_ERROR) << "IDXGIDuplicateOutput does not use RGBA (8 bit) " |
- "format, which is required by downstream components, " |
- "format is " |
- << g_container->duplication_desc.ModeDesc.Format; |
- return false; |
- } |
- |
- return true; |
+ } |
+ |
+ return false; |
} |
bool ScreenCapturerWinDirectx::ForceDuplicateOutput() { |
@@ -457,8 +458,8 @@ |
// Texture instance won't change forever. |
while (!surfaces_.current_frame()) { |
- surfaces_.ReplaceCurrentFrame(std::unique_ptr<rtc::scoped_refptr<Texture>>( |
- new rtc::scoped_refptr<Texture>(new Texture()))); |
+ surfaces_.ReplaceCurrentFrame( |
+ new rtc::scoped_refptr<Texture>(new Texture())); |
surfaces_.MoveToNextFrame(); |
} |
} |
@@ -592,9 +593,9 @@ |
return std::unique_ptr<DesktopFrame>(); |
} |
frames_.ReplaceCurrentFrame( |
- SharedDesktopFrame::Wrap(std::move(new_frame))); |
- } |
- result = frames_.current_frame()->Share(); |
+ SharedDesktopFrame::Wrap(new_frame.release())); |
+ } |
+ result.reset(frames_.current_frame()->Share()); |
std::unique_ptr<DesktopFrame> frame( |
new DxgiDesktopFrame(*surfaces_.current_frame())); |
@@ -619,8 +620,9 @@ |
RTC_DCHECK(callback_); |
if (!g_container->duplication && !DuplicateOutput()) { |
- // Failed to initialize desktop duplication. |
- callback_->OnCaptureResult(Result::ERROR_PERMANENT, nullptr); |
+ // Receive a capture request when application is shutting down, or between |
+ // mode change. |
+ callback_->OnCaptureCompleted(nullptr); |
return; |
} |
@@ -654,7 +656,7 @@ |
if (ForceDuplicateOutput()) { |
EmitCurrentFrame(); |
} else { |
- callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
+ callback_->OnCaptureCompleted(nullptr); |
} |
return; |
} |
@@ -675,14 +677,14 @@ |
g_container->duplication->ReleaseFrame(); |
} |
if (!result) { |
- callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
+ callback_->OnCaptureCompleted(nullptr); |
return; |
} |
result->set_capture_time_ms( |
(rtc::TimeNanos() - capture_start_time_nanos) / |
rtc::kNumNanosecsPerMillisec); |
- callback_->OnCaptureResult(Result::SUCCESS, std::move(result)); |
+ callback_->OnCaptureCompleted(result.release()); |
} |
bool ScreenCapturerWinDirectx::GetScreenList(ScreenList* screens) { |
@@ -697,7 +699,7 @@ |
void ScreenCapturerWinDirectx::EmitCurrentFrame() { |
if (!surfaces_.current_frame()->get()->bits()) { |
// At the very begining, we have not captured any frames. |
- callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
+ callback_->OnCaptureCompleted(nullptr); |
return; |
} |
@@ -706,12 +708,12 @@ |
// queue. If there is not an existing frame (at the very begining), we can |
// only return a nullptr. |
if (frames_.current_frame()) { |
- std::unique_ptr<SharedDesktopFrame> frame = |
- frames_.current_frame()->Share(); |
+ std::unique_ptr<SharedDesktopFrame> frame( |
+ frames_.current_frame()->Share()); |
frame->mutable_updated_region()->Clear(); |
- callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); |
+ callback_->OnCaptureCompleted(frame.release()); |
} else { |
- callback_->OnCaptureResult(Result::ERROR_TEMPORARY, nullptr); |
+ callback_->OnCaptureCompleted(nullptr); |
} |
return; |
} |
@@ -720,7 +722,7 @@ |
// queue. |
std::unique_ptr<DesktopFrame> frame( |
new DxgiDesktopFrame(*surfaces_.current_frame())); |
- callback_->OnCaptureResult(Result::SUCCESS, std::move(frame)); |
+ callback_->OnCaptureCompleted(frame.release()); |
} |
} // namespace webrtc |