Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc

Issue 2697453002: [DesktopCapturer] FallbackDesktopCapturerWrapper and its tests (Closed)
Patch Set: Resolve review comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc
diff --git a/webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc b/webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6797300a61f9f352540e64fb7c81a265b5ab9e55
--- /dev/null
+++ b/webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.cc
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/desktop_capture/fallback_desktop_capturer_wrapper.h"
+
+#include <utility>
+
+#include "webrtc/base/checks.h"
+
+namespace webrtc {
+
+FallbackDesktopCapturerWrapper::FallbackDesktopCapturerWrapper(
+ std::unique_ptr<DesktopCapturer> main_capturer,
+ std::unique_ptr<DesktopCapturer> secondary_capturer)
+ : main_capturer_(std::move(main_capturer)),
+ secondary_capturer_(std::move(secondary_capturer)) {
+ RTC_DCHECK(main_capturer_);
+ RTC_DCHECK(secondary_capturer_);
+}
+
+FallbackDesktopCapturerWrapper::~FallbackDesktopCapturerWrapper() = default;
+
+void FallbackDesktopCapturerWrapper::Start(
+ DesktopCapturer::Callback* callback) {
+ main_capturer_->Start(this);
+ secondary_capturer_->Start(callback);
+ callback_ = callback;
+}
+
+void FallbackDesktopCapturerWrapper::SetSharedMemoryFactory(
+ std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {
+ if (shared_memory_factory) {
+ shared_memory_factory_.reset(new SharedMemoryFactoryWrapper(
+ std::move(shared_memory_factory)));
+ main_capturer_->SetSharedMemoryFactory(shared_memory_factory_->Wrap());
+ secondary_capturer_->SetSharedMemoryFactory(shared_memory_factory_->Wrap());
Sergey Ulanov 2017/02/15 23:08:43 There is a potential threading issue that comes wi
Hzj_jie 2017/02/16 01:57:07 Done.
+ } else {
+ shared_memory_factory_.reset();
+ main_capturer_->SetSharedMemoryFactory(
+ std::unique_ptr<SharedMemoryFactory>());
+ secondary_capturer_->SetSharedMemoryFactory(
+ std::unique_ptr<SharedMemoryFactory>());
+ }
+}
+
+void FallbackDesktopCapturerWrapper::CaptureFrame() {
+ RTC_DCHECK(callback_);
+ if (main_capturer_permanent_error_) {
+ secondary_capturer_->CaptureFrame();
+ } else {
+ main_capturer_->CaptureFrame();
+ }
+}
+
+void FallbackDesktopCapturerWrapper::SetExcludedWindow(WindowId window) {
+ main_capturer_->SetExcludedWindow(window);
+ secondary_capturer_->SetExcludedWindow(window);
+}
+
+bool FallbackDesktopCapturerWrapper::GetSourceList(SourceList* sources) {
+ if (main_capturer_permanent_error_) {
+ return secondary_capturer_->GetSourceList(sources);
+ } else {
Sergey Ulanov 2017/02/15 23:08:43 no else after return please.
Hzj_jie 2017/02/16 01:57:07 Done.
+ return main_capturer_->GetSourceList(sources);
+ }
+}
+
+bool FallbackDesktopCapturerWrapper::SelectSource(SourceId id) {
+ if (main_capturer_permanent_error_) {
+ return secondary_capturer_->SelectSource(id);
+ }
+ return main_capturer_->SelectSource(id) &&
+ secondary_capturer_->SelectSource(id);
+}
+
+bool FallbackDesktopCapturerWrapper::FocusOnSelectedSource() {
+ if (main_capturer_permanent_error_) {
+ return secondary_capturer_->FocusOnSelectedSource();
+ }
+ return main_capturer_->FocusOnSelectedSource() &&
+ secondary_capturer_->FocusOnSelectedSource();
Sergey Ulanov 2017/02/15 23:08:43 Do we need to call both capturers here?
Hzj_jie 2017/02/16 01:57:07 I think it should be simpler to always forward the
Sergey Ulanov 2017/02/16 19:14:17 This makes sense fro SelectSource(), but not for F
Hzj_jie 2017/02/16 21:31:28 Oh, got you. I almost forgot the functionality of
Sergey Ulanov 2017/02/17 20:16:23 I don't think it needs to be const. E.g. an X11 ca
Hzj_jie 2017/02/17 21:55:17 Done.
+}
+
+void FallbackDesktopCapturerWrapper::OnCaptureResult(
+ Result result,
+ std::unique_ptr<DesktopFrame> frame) {
+ RTC_DCHECK(callback_);
+ if (result == Result::SUCCESS) {
+ callback_->OnCaptureResult(result, std::move(frame));
+ return;
+ }
+
+ if (result == Result::ERROR_PERMANENT) {
Sergey Ulanov 2017/02/15 23:08:43 it's possible that OnCaptureResult() was called by
Hzj_jie 2017/02/16 01:57:07 No, this class does not handle the OnCaptureResult
+ main_capturer_permanent_error_ = true;
+ }
+ secondary_capturer_->CaptureFrame();
Sergey Ulanov 2017/02/15 23:08:43 this may loop indefinitely if secondary_capturer_
Hzj_jie 2017/02/16 01:57:07 Same as the reason above.
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698