chromium/media/capture/BUILD.gn

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

import("//build/config/chromeos/ui_mode.gni")
import("//build/config/features.gni")
import("//build/config/ui.gni")
import("//media/media_options.gni")
import("//services/video_effects/args.gni")
import("//testing/test.gni")
import("//third_party/webrtc/webrtc.gni")

group("capture") {
  public_deps = [
    ":capture_lib",
    "//media/capture/mojom:image_capture",
    "//media/capture/mojom:image_capture_types",
    "//media/capture/mojom:video_capture",
    "//services/service_manager/public/cpp",
  ]
}

component("capture_switches") {
  defines = [ "CAPTURE_IMPLEMENTATION" ]
  sources = [
    "capture_export.h",
    "capture_switches.cc",
    "capture_switches.h",
  ]
  deps = [
    "//base",
    "//third_party/webrtc_overrides:webrtc_component",
  ]
}

# Things needed by //media/capture/mojom/video_capture_types.mojom.
component("capture_base") {
  defines = [ "CAPTURE_IMPLEMENTATION" ]
  sources = [
    "capture_export.h",
    "video/video_capture_device_descriptor.cc",
    "video/video_capture_device_descriptor.h",
    "video/video_capture_device_info.cc",
    "video/video_capture_device_info.h",
    "video/video_capture_feedback.cc",
    "video/video_capture_feedback.h",
    "video_capture_types.cc",
    "video_capture_types.h",
  ]
  deps = [
    "//base",
    "//base:i18n",
    "//media:shared_memory_support",
    "//media/base:video_facing",
    "//ui/gfx",
  ]
}

# Target which allows breakout of Android BUILD.gn files.
source_set("capture_device_specific") {
  visibility = [
    ":capture_lib",
    "//media/capture/video/android",
    "//media/capture/video/win",
  ]
  defines = [ "CAPTURE_IMPLEMENTATION" ]
  sources = [
    "content/animated_content_sampler.cc",
    "content/animated_content_sampler.h",
    "content/capture_resolution_chooser.cc",
    "content/capture_resolution_chooser.h",
    "content/screen_enumerator.h",
    "content/smooth_event_sampler.cc",
    "content/smooth_event_sampler.h",
    "content/video_capture_oracle.cc",
    "content/video_capture_oracle.h",
    "video/blob_utils.cc",
    "video/blob_utils.h",
    "video/fake_video_capture_device.cc",
    "video/fake_video_capture_device.h",
    "video/fake_video_capture_device_factory.cc",
    "video/fake_video_capture_device_factory.h",
    "video/file_video_capture_device.cc",
    "video/file_video_capture_device.h",
    "video/file_video_capture_device_factory.cc",
    "video/file_video_capture_device_factory.h",
    "video/gpu_memory_buffer_utils.cc",
    "video/gpu_memory_buffer_utils.h",
    "video/video_capture_buffer_handle.cc",
    "video/video_capture_buffer_handle.h",
    "video/video_capture_buffer_tracker.cc",
    "video/video_capture_buffer_tracker.h",
    "video/video_capture_device.cc",
    "video/video_capture_device.h",
    "video/video_capture_device_factory.cc",
    "video/video_capture_device_factory.h",
    "video/video_capture_metrics.cc",
    "video/video_capture_metrics.h",
  ]

  public_deps = [ ":capture_base" ]
  deps = [
    "//base",
    "//base:i18n",
    "//build:chromeos_buildflags",
    "//gpu/command_buffer/client",
    "//gpu/ipc/common:common",
    "//media",
    "//media/capture:capture_switches",
    "//media/capture/mojom:image_capture",
    "//media/capture/mojom:image_capture_types",
    "//media/capture/mojom:video_capture",
    "//media/mojo/mojom",
    "//skia",
    "//third_party/libyuv",
    "//third_party/webrtc_overrides:webrtc_component",
    "//ui/gfx",
  ]
}

component("capture_lib") {
  defines = [ "CAPTURE_IMPLEMENTATION" ]
  sources = [
    "video/create_video_capture_device_factory.cc",
    "video/create_video_capture_device_factory.h",
    "video/scoped_buffer_pool_reservation.h",
    "video/shared_memory_buffer_tracker.cc",
    "video/shared_memory_buffer_tracker.h",
    "video/video_capture_buffer_pool.h",
    "video/video_capture_buffer_pool_impl.cc",
    "video/video_capture_buffer_pool_impl.h",
    "video/video_capture_buffer_pool_util.cc",
    "video/video_capture_buffer_pool_util.h",
    "video/video_capture_buffer_tracker_factory.h",
    "video/video_capture_buffer_tracker_factory_impl.cc",
    "video/video_capture_buffer_tracker_factory_impl.h",
    "video/video_capture_device_client.cc",
    "video/video_capture_device_client.h",
    "video/video_capture_system.h",
    "video/video_capture_system_impl.cc",
    "video/video_capture_system_impl.h",
    "video/video_frame_receiver.cc",
    "video/video_frame_receiver.h",
    "video/video_frame_receiver_on_task_runner.cc",
    "video/video_frame_receiver_on_task_runner.h",
  ]

  public_deps = [
    ":capture_base",
    ":capture_device_specific",
    ":capture_gpu_channel",
    ":capture_switches",
  ]

  deps = [
    "//base",
    "//base:i18n",
    "//build:chromeos_buildflags",
    "//media",
    "//media/capture/mojom:image_capture",
    "//media/capture/mojom:image_capture_types",
    "//media/capture/mojom:video_capture",
    "//media/mojo/mojom",
    "//services/service_manager/public/cpp",
    "//services/video_capture/public/mojom",
    "//services/video_effects:buildflags",
    "//third_party/libyuv",
    "//ui/display",
    "//ui/gfx",
  ]

  if (enable_video_effects) {
    sources += [
      "video/video_capture_effects_processor.cc",
      "video/video_capture_effects_processor.h",
    ]
  }

  if (is_android) {
    public_deps += [ "video/android" ]
    deps += [ "video/android:capture_jni_headers" ]
  }

  if (is_apple) {
    sources += [
      "video/apple/gpu_memory_buffer_tracker_apple.cc",
      "video/apple/gpu_memory_buffer_tracker_apple.h",
      "video/apple/pixel_buffer_pool.h",
      "video/apple/pixel_buffer_pool.mm",
      "video/apple/pixel_buffer_transferer.cc",
      "video/apple/pixel_buffer_transferer.h",
      "video/apple/sample_buffer_transformer.cc",
      "video/apple/sample_buffer_transformer.h",
      "video/apple/video_capture_device_apple.h",
      "video/apple/video_capture_device_apple.mm",
      "video/apple/video_capture_device_avfoundation.h",
      "video/apple/video_capture_device_avfoundation.mm",
      "video/apple/video_capture_device_avfoundation_utils.h",
      "video/apple/video_capture_device_avfoundation_utils.mm",
      "video/apple/video_capture_device_factory_apple.h",
      "video/apple/video_capture_device_factory_apple.mm",
      "video/apple/video_capture_device_frame_receiver.h",
    ]
    deps += [ "//components/crash/core/common:crash_key" ]
    frameworks = [
      "AVFoundation.framework",
      "CoreFoundation.framework",
      "CoreGraphics.framework",
      "CoreMedia.framework",
      "CoreVideo.framework",
      "Foundation.framework",
      "IOSurface.framework",
      "VideoToolbox.framework",
    ]
  }

  if (is_mac) {
    sources += [
      "video/mac/uvc_control_mac.h",
      "video/mac/uvc_control_mac.mm",
      "video/mac/video_capture_device_decklink_mac.h",
      "video/mac/video_capture_device_decklink_mac.mm",
      "video/mac/video_capture_metrics_mac.h",
      "video/mac/video_capture_metrics_mac.mm",
    ]
    deps += [ "//third_party/decklink" ]
  }

  if (is_ios) {
    sources += [
      "video/ios/pixel_buffer_rotator.cc",
      "video/ios/pixel_buffer_rotator.h",
    ]
  }

  if (is_win) {
    public_deps += [ "video/win" ]
  }

  if (is_linux || is_chromeos) {
    sources += [
      "video/linux/scoped_v4l2_device_fd.cc",
      "video/linux/scoped_v4l2_device_fd.h",
      "video/linux/v4l2_capture_delegate.cc",
      "video/linux/v4l2_capture_delegate.h",
      "video/linux/v4l2_capture_device.h",
      "video/linux/v4l2_capture_device_impl.cc",
      "video/linux/v4l2_capture_device_impl.h",
      "video/linux/video_capture_device_factory_linux.cc",
      "video/linux/video_capture_device_factory_linux.h",
      "video/linux/video_capture_device_factory_v4l2.cc",
      "video/linux/video_capture_device_factory_v4l2.h",
      "video/linux/video_capture_device_linux.cc",
      "video/linux/video_capture_device_linux.h",
    ]
    if (rtc_use_pipewire) {
      sources += [
        "video/linux/video_capture_device_factory_webrtc.cc",
        "video/linux/video_capture_device_factory_webrtc.h",
        "video/linux/video_capture_device_webrtc.cc",
        "video/linux/video_capture_device_webrtc.h",
      ]
    }
    deps += [ "//gpu/command_buffer/client" ]
  }

  if (is_linux) {
    sources += [
      "video/linux/v4l2_capture_delegate_gpu_helper.cc",
      "video/linux/v4l2_capture_delegate_gpu_helper.h",
      "video/linux/v4l2_gpu_memory_buffer_tracker.cc",
      "video/linux/v4l2_gpu_memory_buffer_tracker.h",
    ]
  }

  if (is_chromeos_ash) {
    sources += [
      "video/chromeos/camera_3a_controller.cc",
      "video/chromeos/camera_3a_controller.h",
      "video/chromeos/camera_app_device_bridge_impl.cc",
      "video/chromeos/camera_app_device_bridge_impl.h",
      "video/chromeos/camera_app_device_impl.cc",
      "video/chromeos/camera_app_device_impl.h",
      "video/chromeos/camera_app_device_provider_impl.cc",
      "video/chromeos/camera_app_device_provider_impl.h",
      "video/chromeos/camera_auto_framing_state_observer.cc",
      "video/chromeos/camera_auto_framing_state_observer.h",
      "video/chromeos/camera_buffer_factory.cc",
      "video/chromeos/camera_buffer_factory.h",
      "video/chromeos/camera_device_context.cc",
      "video/chromeos/camera_device_context.h",
      "video/chromeos/camera_device_delegate.cc",
      "video/chromeos/camera_device_delegate.h",
      "video/chromeos/camera_effects_observer.cc",
      "video/chromeos/camera_effects_observer.h",
      "video/chromeos/camera_hal_delegate.cc",
      "video/chromeos/camera_hal_delegate.h",
      "video/chromeos/camera_hal_dispatcher_impl.cc",
      "video/chromeos/camera_hal_dispatcher_impl.h",
      "video/chromeos/camera_metadata_utils.cc",
      "video/chromeos/camera_metadata_utils.h",
      "video/chromeos/camera_sw_privacy_switch_state_observer.cc",
      "video/chromeos/camera_sw_privacy_switch_state_observer.h",
      "video/chromeos/camera_trace_utils.cc",
      "video/chromeos/camera_trace_utils.h",
      "video/chromeos/capture_metadata_dispatcher.h",
      "video/chromeos/display_rotation_observer.cc",
      "video/chromeos/display_rotation_observer.h",
      "video/chromeos/gpu_memory_buffer_tracker_cros.cc",
      "video/chromeos/gpu_memory_buffer_tracker_cros.h",
      "video/chromeos/jpeg_accelerator_provider.cc",
      "video/chromeos/jpeg_accelerator_provider.h",
      "video/chromeos/mojo_service_manager_observer.cc",
      "video/chromeos/mojo_service_manager_observer.h",
      "video/chromeos/pixel_format_utils.cc",
      "video/chromeos/pixel_format_utils.h",
      "video/chromeos/request_builder.cc",
      "video/chromeos/request_builder.h",
      "video/chromeos/request_manager.cc",
      "video/chromeos/request_manager.h",
      "video/chromeos/scoped_video_capture_jpeg_decoder.cc",
      "video/chromeos/scoped_video_capture_jpeg_decoder.h",
      "video/chromeos/stream_buffer_manager.cc",
      "video/chromeos/stream_buffer_manager.h",
      "video/chromeos/system_event_monitor_impl.cc",
      "video/chromeos/system_event_monitor_impl.h",
      "video/chromeos/token_manager.cc",
      "video/chromeos/token_manager.h",
      "video/chromeos/vendor_tag_ops_delegate.cc",
      "video/chromeos/vendor_tag_ops_delegate.h",
      "video/chromeos/video_capture_device_chromeos_delegate.cc",
      "video/chromeos/video_capture_device_chromeos_delegate.h",
      "video/chromeos/video_capture_device_chromeos_halv3.cc",
      "video/chromeos/video_capture_device_chromeos_halv3.h",
      "video/chromeos/video_capture_device_factory_chromeos.cc",
      "video/chromeos/video_capture_device_factory_chromeos.h",
      "video/chromeos/video_capture_features_chromeos.cc",
      "video/chromeos/video_capture_features_chromeos.h",
      "video/chromeos/video_capture_jpeg_decoder.h",
      "video/chromeos/video_capture_jpeg_decoder_impl.cc",
      "video/chromeos/video_capture_jpeg_decoder_impl.h",
    ]
    public_deps += [
      "//ash/webui/camera_app_ui:document_scanning",
      "//media/capture/video/chromeos/public",
    ]
    deps += [
      "//ash/constants",
      "//build/config/linux/libdrm",
      "//chromeos/ash/components/mojo_service_manager",
      "//chromeos/dbus/power",
      "//components/chromeos_camera:mojo_mjpeg_decode_accelerator",
      "//components/chromeos_camera/common",
      "//components/device_event_log",
      "//gpu/ipc/common:common",
      "//media/capture/video/chromeos/mojom:cros_camera",
      "//media/capture/video/chromeos/mojom:document_scanner",
      "//media/capture/video/chromeos/mojom:jpeg_accelerator",
      "//media/capture/video/chromeos/mojom:system_event_monitor",
      "//media/capture/video/chromeos/mojom:video_capture_device_info_monitor",
      "//third_party/libsync",
    ]
    data_deps = [
      ":camera_hal_dispatcher_mojo_policy",
      ":document_scanner_mojo_policy",
      ":jpeg_accelerator_mojo_policy",
      ":system_event_monitor_mojo_policy",
      ":video_capture_device_info_monitor_mojo_policy",
    ]
  }

  if (is_fuchsia) {
    sources += [
      "video/fuchsia/video_capture_device_factory_fuchsia.cc",
      "video/fuchsia/video_capture_device_factory_fuchsia.h",
      "video/fuchsia/video_capture_device_fuchsia.cc",
      "video/fuchsia/video_capture_device_fuchsia.h",
    ]
    deps += [
      "//media/fuchsia/common",
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.camera3:fuchsia.camera3_hlcpp",
      "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
      "//third_party/libyuv",
    ]
  }
}

source_set("capture_gpu_channel") {
  defines = [ "CAPTURE_IMPLEMENTATION" ]
  sources = []
  deps = []

  # Establish GPU Channel
  if (is_linux || is_win || is_chromeos_ash || is_mac) {
    sources += [
      "video/video_capture_gpu_channel_host.cc",
      "video/video_capture_gpu_channel_host.h",
    ]
    deps += [
      ":capture_base",
      "//gpu/command_buffer/client",
      "//gpu/ipc/client",
    ]
  }
}

source_set("test_support") {
  testonly = true

  sources = [
    "video/mock_device.cc",
    "video/mock_device.h",
    "video/mock_device_factory.cc",
    "video/mock_device_factory.h",
    "video/mock_gpu_memory_buffer_manager.cc",
    "video/mock_gpu_memory_buffer_manager.h",
    "video/mock_video_capture_device_client.cc",
    "video/mock_video_capture_device_client.h",
    "video/mock_video_frame_receiver.cc",
    "video/mock_video_frame_receiver.h",
  ]

  deps = [
    ":capture_lib",
    "//base/test:test_support",
    "//build:chromeos_buildflags",
    "//gpu/command_buffer/client",
    "//gpu/command_buffer/common:common",
    "//media:test_support",
    "//media/capture/mojom:image_capture",
    "//media/capture/mojom:image_capture_types",
    "//testing/gmock",
    "//ui/gfx:test_support",
  ]

  if (is_linux || is_chromeos_lacros) {
    sources += [
      "video/linux/fake_device_provider.cc",
      "video/linux/fake_device_provider.h",
      "video/linux/fake_v4l2_impl.cc",
      "video/linux/fake_v4l2_impl.h",
    ]
  }

  if (is_chromeos_ash) {
    sources += [
      "video/chromeos/mock_camera_module.cc",
      "video/chromeos/mock_camera_module.h",
      "video/chromeos/mock_vendor_tag_ops.cc",
      "video/chromeos/mock_vendor_tag_ops.h",
      "video/chromeos/mock_video_capture_client.cc",
      "video/chromeos/mock_video_capture_client.h",
    ]
    deps += [
      "//media/capture/video/chromeos/mojom:cros_camera",
      "//media/capture/video/chromeos/public",
    ]
  }

  testonly = true
}

test("capture_unittests") {
  use_xvfb = use_xvfb_in_this_config

  sources = [
    "content/animated_content_sampler_unittest.cc",
    "content/capture_resolution_chooser_unittest.cc",
    "content/smooth_event_sampler_unittest.cc",
    "content/video_capture_oracle_unittest.cc",
    "run_all_unittests.cc",
    "video/fake_video_capture_device_unittest.cc",
    "video/file_video_capture_device_unittest.cc",
    "video/video_capture_device_client_unittest.cc",
    "video/video_capture_device_unittest.cc",
    "video/video_capture_metrics_unittest.cc",
    "video_capture_types_unittest.cc",
  ]

  if (enable_video_effects) {
    sources += [ "video/video_capture_effects_processor_unittest.cc" ]
  }

  data = [ "//media/test/data/bear.mjpeg" ]

  deps = [
    ":capture",
    ":test_support",
    "//base/test:test_support",
    "//build:chromeos_buildflags",
    "//gpu:test_support",
    "//gpu/command_buffer/client",
    "//media:test_support",
    "//media/capture/mojom:image_capture",
    "//media/capture/mojom:image_capture_types",
    "//mojo/core/embedder",
    "//services/video_capture/public/mojom",
    "//services/video_effects/test:test_support",
    "//testing/gmock",
    "//testing/gtest",
    "//third_party/libyuv:libyuv",
    "//ui/gfx:test_support",
  ]

  if (enable_video_effects) {
    deps += [ "//components/viz/test:test_support" ]
  }

  if (is_linux || is_chromeos_lacros) {
    sources += [
      "video/linux/v4l2_capture_delegate_unittest.cc",
      "video/linux/video_capture_device_factory_v4l2_unittest.cc",
    ]
  }

  if (is_linux) {
    sources += [
      "video/linux/v4l2_capture_delegate_gpu_helper_unittest.cc",
      "video/linux/v4l2_gpu_memory_buffer_tracker_unittest.cc",
    ]
    data += [ "//media/test/data/one_frame_1280x720.mjpeg" ]
  }

  if (is_android) {
    deps += [
      "//media/capture/video/android",
      "//media/capture/video/android:capture_java",
    ]
  }

  if (is_fuchsia) {
    deps += [
      "//media/fuchsia/camera:test_support",
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.camera3:fuchsia.camera3_hlcpp",
      "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.sysmem:fuchsia.sysmem_hlcpp",
      "//third_party/fuchsia-sdk/sdk/pkg/sys_cpp",
    ]
    sources += [
      "video/fuchsia/video_capture_device_factory_fuchsia_test.cc",
      "video/fuchsia/video_capture_device_fuchsia_test.cc",
    ]
    additional_manifest_fragments =
        [ "//build/config/fuchsia/test/sysmem.shard.test-cml" ]
  }

  if (is_apple) {
    sources += [
      "video/apple/pixel_buffer_pool_unittest.mm",
      "video/apple/pixel_buffer_transferer_unittest.mm",
      "video/apple/sample_buffer_transformer_unittest.mm",
      "video/apple/test/fake_av_capture_device_format.h",
      "video/apple/test/fake_av_capture_device_format.mm",
      "video/apple/test/mock_video_capture_device_avfoundation_frame_receiver.h",
      "video/apple/test/mock_video_capture_device_avfoundation_frame_receiver.mm",
      "video/apple/test/pixel_buffer_test_utils.cc",
      "video/apple/test/pixel_buffer_test_utils.h",
      "video/apple/test/video_capture_test_utils.h",
      "video/apple/test/video_capture_test_utils.mm",
      "video/apple/video_capture_device_apple_unittest.mm",
      "video/apple/video_capture_device_avfoundation_unittest.mm",
      "video/apple/video_capture_device_factory_unittest.mm",
    ]
    frameworks = [
      "IOSurface.framework",
      "AVFoundation.framework",
      "CoreMedia.framework",
      "CoreVideo.framework",
    ]
  }

  if (is_mac) {
    sources += [ "video/mac/video_capture_metrics_mac_unittest.mm" ]
    deps += [ "//third_party/ocmock" ]
  }

  if (is_ios) {
    deps += [ "//media:unit_tests_bundle_data" ]
  }

  if (is_win) {
    deps += [ "video/win:win_unittests" ]
  }

  if (is_chromeos) {
    deps += [ "//chromeos/dbus/power" ]
  }

  # TODO(crbug.com/40115082): use is_linux.
  if (is_chromeos_ash) {
    deps += [ "//media/gpu/test:local_gpu_memory_buffer_manager" ]
  }

  if (is_chromeos_ash) {
    sources += [
      "video/chromeos/camera_3a_controller_unittest.cc",
      "video/chromeos/camera_device_delegate_unittest.cc",
      "video/chromeos/camera_hal_delegate_unittest.cc",
      "video/chromeos/camera_hal_dispatcher_impl_unittest.cc",
      "video/chromeos/request_manager_unittest.cc",
      "video/chromeos/token_manager_unittest.cc",
    ]
    deps += [
      "//build/config/linux/libdrm",
      "//chromeos/ash/components/mojo_service_manager",
      "//media/capture/video/chromeos/mojom:cros_camera",
      "//media/capture/video/chromeos/public",
      "//mojo/core/embedder",
      "//third_party/libsync",
      "//third_party/minigbm",
    ]
  }
}

# TODO(crbug.com/40932597): Move platform-specific files/targets into subdirectories.
copy("camera_hal_dispatcher_mojo_policy") {
  sources = [ "video/chromeos/camera_hal_dispatcher_mojo_policy.jsonc" ]
  outputs = [ "$root_out_dir/mojo_service_manager/{{source_file_part}}" ]
}

copy("jpeg_accelerator_mojo_policy") {
  sources = [ "video/chromeos/jpeg_accelerator_mojo_policy.jsonc" ]
  outputs = [ "$root_out_dir/mojo_service_manager/{{source_file_part}}" ]
}

copy("system_event_monitor_mojo_policy") {
  sources = [ "video/chromeos/system_event_monitor.jsonc" ]
  outputs = [ "$root_out_dir/mojo_service_manager/{{source_file_part}}" ]
}

copy("video_capture_device_info_monitor_mojo_policy") {
  sources = [ "video/chromeos/video_capture_device_info_monitor.jsonc" ]
  outputs = [ "$root_out_dir/mojo_service_manager/{{source_file_part}}" ]
}

copy("document_scanner_mojo_policy") {
  sources = [ "video/chromeos/document_scanner_mojo_policy.jsonc" ]
  outputs = [ "$root_out_dir/mojo_service_manager/{{source_file_part}}" ]
}