chromium/content/browser/renderer_host/media/in_process_video_capture_device_launcher.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/renderer_host/media/in_process_video_capture_device_launcher.h"

#include <utility>
#include <vector>

#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/bind_post_task.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "content/browser/media/capture/native_screen_capture_picker.h"
#include "content/browser/renderer_host/media/in_process_launched_video_capture_device.h"
#include "content/browser/renderer_host/media/video_capture_controller.h"
#include "content/common/buildflags.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/desktop_media_id.h"
#include "content/public/common/content_features.h"
#include "media/base/media_switches.h"
#include "media/capture/video/fake_video_capture_device.h"
#include "media/capture/video/fake_video_capture_device_factory.h"
#include "media/capture/video/video_capture_buffer_pool_impl.h"
#include "media/capture/video/video_capture_buffer_pool_util.h"
#include "media/capture/video/video_capture_buffer_tracker_factory_impl.h"
#include "media/capture/video/video_capture_device_client.h"
#include "media/capture/video/video_frame_receiver.h"
#include "media/capture/video/video_frame_receiver_on_task_runner.h"
#include "services/video_effects/public/mojom/video_effects_processor.mojom-forward.h"
#include "third_party/blink/public/common/mediastream/media_stream_request.h"

#if BUILDFLAG(ENABLE_SCREEN_CAPTURE)
#include "content/browser/media/capture/desktop_capture_device_uma_types.h"
#include "content/browser/media/capture/web_contents_video_capture_device.h"
#if !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
#if defined(USE_AURA)
#include "content/browser/media/capture/aura_window_video_capture_device.h"
#endif  // defined(USE_AURA)
#include "content/browser/media/capture/desktop_capture_device.h"
#endif  // !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
#if BUILDFLAG(IS_MAC)
#include "content/browser/media/capture/desktop_capture_device_mac.h"
#include "content/browser/media/capture/screen_capture_kit_device_utils_mac.h"
#include "content/browser/media/capture/views_widget_video_capture_device_mac.h"
#endif
#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "content/browser/media/capture/video_capture_device_proxy_lacros.h"
#endif
#endif  // BUILDFLAG(ENABLE_SCREEN_CAPTURE)

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "content/browser/gpu/chromeos/video_capture_dependencies.h"
#include "media/capture/video/chromeos/scoped_video_capture_jpeg_decoder.h"
#include "media/capture/video/chromeos/video_capture_jpeg_decoder_impl.h"
#elif BUILDFLAG(IS_WIN)
#include "media/capture/video/win/video_capture_device_factory_win.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace content {

namespace {

#if BUILDFLAG(IS_CHROMEOS_ASH)
std::unique_ptr<media::VideoCaptureJpegDecoder> CreateGpuJpegDecoder(
    media::VideoCaptureJpegDecoder::DecodeDoneCB decode_done_cb,
    base::RepeatingCallback<void(const std::string&)> send_log_message_cb) {
  auto io_task_runner = GetIOThreadTaskRunner({});
  return std::make_unique<media::ScopedVideoCaptureJpegDecoder>(
      std::make_unique<media::VideoCaptureJpegDecoderImpl>(
          base::BindRepeating(
              &VideoCaptureDependencies::CreateJpegDecodeAccelerator),
          io_task_runner, std::move(decode_done_cb),
          std::move(send_log_message_cb)),
      io_task_runner);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

#if BUILDFLAG(ENABLE_SCREEN_CAPTURE)

// The maximum number of video frame buffers in-flight at any one time. This
// value should be based on the logical capacity of the capture pipeline, and
// not on hardware performance.
const int kMaxNumberOfBuffers =;

#if BUILDFLAG(IS_MAC)
BASE_FEATURE(kScreenCaptureKitMac,
             "ScreenCaptureKitMac",
             base::FEATURE_DISABLED_BY_DEFAULT);

// If this feature is enabled, ScreenCaptureKit will be used for window
// capturing even if kScreenCaptureKitMac is disabled. Please note that this
// feature has no effect if kScreenCaptureKitMac is enabled.
BASE_FEATURE(kScreenCaptureKitMacWindow,
             "ScreenCaptureKitMacWindow",
             base::FEATURE_ENABLED_BY_DEFAULT);

// If this feature is enabled, ScreenCaptureKit will be used for screen
// capturing even if kScreenCaptureKitMac is disabled. Please note that this
// feature has no effect if kScreenCaptureKitMac is enabled.
BASE_FEATURE(kScreenCaptureKitMacScreen,
             "ScreenCaptureKitMacScreen",
             base::FEATURE_DISABLED_BY_DEFAULT);
#endif

void IncrementDesktopCaptureCounters(const DesktopMediaID& device_id) {}

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum DesktopCaptureImplementation {};

// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum DesktopCaptureImplementationAndType {};

void ReportDesktopCaptureImplementationAndType(
    DesktopCaptureImplementation implementation,
    DesktopMediaID::Type type) {}

DesktopCaptureImplementation CreatePlatformDependentVideoCaptureDevice(
    NativeScreenCapturePicker* picker,
    const DesktopMediaID& desktop_id,
    std::unique_ptr<media::VideoCaptureDevice>& device_out) {}
#endif  // BUILDFLAG(ENABLE_SCREEN_CAPTURE)
}  // anonymous namespace

InProcessVideoCaptureDeviceLauncher::InProcessVideoCaptureDeviceLauncher(
    scoped_refptr<base::SingleThreadTaskRunner> device_task_runner,
    NativeScreenCapturePicker* picker)
    :{}

InProcessVideoCaptureDeviceLauncher::~InProcessVideoCaptureDeviceLauncher() {}

void InProcessVideoCaptureDeviceLauncher::LaunchDeviceAsync(
    const std::string& device_id,
    blink::mojom::MediaStreamType stream_type,
    const media::VideoCaptureParams& params,
    base::WeakPtr<media::VideoFrameReceiver> receiver_on_io_thread,
    base::OnceClosure /* connection_lost_cb */,
    Callbacks* callbacks,
    base::OnceClosure done_cb,
    mojo::PendingRemote<video_effects::mojom::VideoEffectsProcessor>
        video_effects_processor) {}

void InProcessVideoCaptureDeviceLauncher::AbortLaunch() {}

std::unique_ptr<media::VideoCaptureDeviceClient>
InProcessVideoCaptureDeviceLauncher::CreateDeviceClient(
    media::VideoCaptureBufferType requested_buffer_type,
    int buffer_pool_max_buffer_count,
    std::unique_ptr<media::VideoFrameReceiver> receiver,
    base::WeakPtr<media::VideoFrameReceiver> receiver_on_io_thread) {}

void InProcessVideoCaptureDeviceLauncher::OnDeviceStarted(
    Callbacks* callbacks,
    base::OnceClosure done_cb,
    std::unique_ptr<media::VideoCaptureDevice> device) {}

#if BUILDFLAG(ENABLE_SCREEN_CAPTURE)

void InProcessVideoCaptureDeviceLauncher::DoStartTabCaptureOnDeviceThread(
    const std::string& device_id,
    const media::VideoCaptureParams& params,
    std::unique_ptr<media::VideoFrameReceiver> receiver,
    ReceiveDeviceCallback result_callback) {}

#if defined(USE_AURA) || BUILDFLAG(IS_MAC)
void InProcessVideoCaptureDeviceLauncher::
    DoStartVizFrameSinkWindowCaptureOnDeviceThread(
        const DesktopMediaID& device_id,
        const media::VideoCaptureParams& params,
        std::unique_ptr<media::VideoFrameReceiver> receiver,
        ReceiveDeviceCallback result_callback) {}
#endif  // defined(USE_AURA) || BUILDFLAG(IS_MAC)

void InProcessVideoCaptureDeviceLauncher::DoStartDesktopCaptureOnDeviceThread(
    const DesktopMediaID& desktop_id,
    const media::VideoCaptureParams& params,
    std::unique_ptr<media::VideoCaptureDeviceClient> device_client,
    ReceiveDeviceCallback result_callback) {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
void InProcessVideoCaptureDeviceLauncher::
    DoStartDesktopCaptureWithReceiverOnDeviceThread(
        const DesktopMediaID& device_id,
        const media::VideoCaptureParams& params,
        std::unique_ptr<media::VideoFrameReceiver> receiver,
        ReceiveDeviceCallback result_callback) {
  DCHECK(device_task_runner_->BelongsToCurrentThread());

  std::unique_ptr<VideoCaptureDeviceProxyLacros> video_capture_device =
      std::make_unique<VideoCaptureDeviceProxyLacros>(device_id);
  video_capture_device->AllocateAndStartWithReceiver(params,
                                                     std::move(receiver));
  IncrementDesktopCaptureCounters(device_id);
  std::move(result_callback).Run(std::move(video_capture_device));
}
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)
#endif  // BUILDFLAG(ENABLE_SCREEN_CAPTURE)

void InProcessVideoCaptureDeviceLauncher::
    DoStartFakeDisplayCaptureOnDeviceThread(
        const DesktopMediaID& desktop_id,
        const media::VideoCaptureParams& params,
        std::unique_ptr<media::VideoCaptureDeviceClient> device_client,
        ReceiveDeviceCallback result_callback) {}

void InProcessVideoCaptureDeviceLauncher::OnFakeDevicesEnumerated(
    const media::VideoCaptureParams& params,
    std::unique_ptr<media::VideoCaptureDeviceClient> device_client,
    ReceiveDeviceCallback result_callback,
    std::vector<media::VideoCaptureDeviceInfo> devices_info) {}

}  // namespace content