#include "content/browser/media/capture/desktop_capture_device.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <algorithm>
#include <memory>
#include <utility>
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/message_loop/message_pump_type.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/synchronization/lock.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/tick_clock.h"
#include "base/timer/timer.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/media/capture/desktop_capture_device_uma_types.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_capture.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/device_service.h"
#include "content/public/common/content_switches.h"
#include "media/base/video_util.h"
#include "media/capture/content/capture_resolution_chooser.h"
#include "media/webrtc/webrtc_features.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/device/public/mojom/wake_lock.mojom.h"
#include "services/device/public/mojom/wake_lock_provider.mojom.h"
#include "third_party/libyuv/include/libyuv/scale_argb.h"
#include "third_party/webrtc/modules/desktop_capture/cropped_desktop_frame.h"
#include "third_party/webrtc/modules/desktop_capture/cropping_window_capturer.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_and_cursor_composer.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capture_options.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capture_types.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
#include "third_party/webrtc/modules/desktop_capture/fake_desktop_capturer.h"
#include "third_party/webrtc/modules/desktop_capture/mouse_cursor_monitor.h"
#include "ui/gfx/icc_profile.h"
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "content/browser/media/capture/desktop_capturer_lacros.h"
#endif
namespace content {
namespace {
const int kDefaultMaximumCpuConsumptionPercentage = …;
constexpr float kAlpha = …;
const char* DesktopMediaTypeToString(DesktopMediaID::Type type) { … }
webrtc::DesktopRect ComputeLetterboxRect(
const webrtc::DesktopSize& max_size,
const webrtc::DesktopSize& source_size) { … }
bool IsFrameUnpackedOrInverted(webrtc::DesktopFrame* frame) { … }
void BindWakeLockProvider(
mojo::PendingReceiver<device::mojom::WakeLockProvider> receiver) { … }
void LogDesktopCaptureZeroHzIsActive(DesktopMediaID::Type capturer_type,
bool zero_hz_is_active) { … }
void LogDesktopCaptureFrameIsRefresh(DesktopMediaID::Type capturer_type,
bool is_refresh_frame) { … }
void LogDesktopCaptureFrameRate(DesktopMediaID::Type capturer_type,
int frame_rate_fps) { … }
void LogDesktopCaptureRequestRefreshRate(DesktopMediaID::Type capturer_type,
int rrf_rate_fps) { … }
class ScopedHighResolutionTimer { … };
}
class DesktopCaptureDevice::Core : public webrtc::DesktopCapturer::Callback { … };
DesktopCaptureDevice::Core::Core(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
std::unique_ptr<webrtc::DesktopCapturer> capturer,
DesktopMediaID::Type type,
bool zero_hertz_is_supported)
: … { … }
DesktopCaptureDevice::Core::~Core() { … }
void DesktopCaptureDevice::Core::AllocateAndStart(
const media::VideoCaptureParams& params,
std::unique_ptr<Client> client) { … }
void DesktopCaptureDevice::Core::RequestRefreshFrame() { … }
void DesktopCaptureDevice::Core::SetNotificationWindowId(
gfx::NativeViewId window_id) { … }
void DesktopCaptureDevice::Core::SetMockTimeForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const base::TickClock* tick_clock) { … }
void DesktopCaptureDevice::Core::OnCaptureResult(
webrtc::DesktopCapturer::Result result,
std::unique_ptr<webrtc::DesktopFrame> frame) { … }
void DesktopCaptureDevice::Core::OnCaptureTimer() { … }
void DesktopCaptureDevice::Core::CaptureFrame(bool is_refresh_frame) { … }
void DesktopCaptureDevice::Core::ScheduleNextCaptureFrame() { … }
void DesktopCaptureDevice::Core::RequestWakeLock() { … }
base::TimeTicks DesktopCaptureDevice::Core::NowTicks() const { … }
std::unique_ptr<media::VideoCaptureDevice> DesktopCaptureDevice::Create(
const DesktopMediaID& source) { … }
DesktopCaptureDevice::~DesktopCaptureDevice() { … }
void DesktopCaptureDevice::AllocateAndStart(
const media::VideoCaptureParams& params,
std::unique_ptr<Client> client) { … }
void DesktopCaptureDevice::StopAndDeAllocate() { … }
void DesktopCaptureDevice::RequestRefreshFrame() { … }
void DesktopCaptureDevice::SetNotificationWindowId(
gfx::NativeViewId window_id) { … }
DesktopCaptureDevice::DesktopCaptureDevice(
std::unique_ptr<webrtc::DesktopCapturer> capturer,
DesktopMediaID::Type type)
: … { … }
void DesktopCaptureDevice::SetMockTimeForTesting(
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
const base::TickClock* tick_clock) { … }
}