sergeyu 3eba2d8273 Fix DesktopCapturer constructors to handle failures properly.
CreateRawScreenCapturer() and CreateRawWindowCapturer() in
DesktopCapturer are allowed to return nullptr when capturer cannot be
initialized for some reason. CreateWindowCapturer() and
CreateScreenCapturer() in DesktopCapturer were not handling this case
correctly, which may lead to crash.

BUG=chromium:702745

Review-Url: https://codereview.webrtc.org/2754403002
Cr-Commit-Position: refs/heads/master@{#17298}
2017-03-17 22:33:27 +00:00

60 lines
1.8 KiB
C++

/*
* 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/desktop_capturer.h"
#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
#include "webrtc/modules/desktop_capture/desktop_capturer_differ_wrapper.h"
namespace webrtc {
DesktopCapturer::~DesktopCapturer() = default;
void DesktopCapturer::SetSharedMemoryFactory(
std::unique_ptr<SharedMemoryFactory> shared_memory_factory) {}
void DesktopCapturer::SetExcludedWindow(WindowId window) {}
bool DesktopCapturer::GetSourceList(SourceList* sources) {
return true;
}
bool DesktopCapturer::SelectSource(SourceId id) {
return false;
}
bool DesktopCapturer::FocusOnSelectedSource() {
return false;
}
// static
std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateWindowCapturer(
const DesktopCaptureOptions& options) {
std::unique_ptr<DesktopCapturer> capturer = CreateRawWindowCapturer(options);
if (capturer && options.detect_updated_region()) {
capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer)));
}
return capturer;
}
// static
std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateScreenCapturer(
const DesktopCaptureOptions& options) {
std::unique_ptr<DesktopCapturer> capturer = CreateRawScreenCapturer(options);
if (capturer && options.detect_updated_region()) {
capturer.reset(new DesktopCapturerDifferWrapper(std::move(capturer)));
}
return capturer;
}
} // namespace webrtc