chromium/media/mojo/services/BUILD.gn

# Copyright 2014 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/cast.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//media/gpu/args.gni")
import("//media/media_options.gni")
import("//mojo/public/tools/fuzzers/mojolpm.gni")
import("//testing/test.gni")

enable_playback_events_recorder =
    enable_cast_receiver && (is_fuchsia || is_android)

component("services") {
  output_name = "media_mojo_services"
  sources = [
    "deferred_destroy_unique_receiver_set.h",
    "gpu_mojo_media_client.cc",
    "gpu_mojo_media_client.h",
    "interface_factory_impl.cc",
    "interface_factory_impl.h",
    "media_metrics_provider.cc",
    "media_metrics_provider.h",
    "media_mojo_export.h",
    "media_resource_shim.cc",
    "media_resource_shim.h",
    "media_service.cc",
    "media_service.h",
    "media_service_factory.cc",
    "media_service_factory.h",
    "mojo_audio_decoder_service.cc",
    "mojo_audio_decoder_service.h",
    "mojo_audio_encoder_service.cc",
    "mojo_audio_encoder_service.h",
    "mojo_audio_input_stream.cc",
    "mojo_audio_input_stream.h",
    "mojo_cdm_promise.cc",
    "mojo_cdm_promise.h",
    "mojo_cdm_service.cc",
    "mojo_cdm_service.h",
    "mojo_cdm_service_context.cc",
    "mojo_cdm_service_context.h",
    "mojo_decryptor_service.cc",
    "mojo_decryptor_service.h",
    "mojo_demuxer_stream_adapter.cc",
    "mojo_demuxer_stream_adapter.h",
    "mojo_media_client.cc",
    "mojo_media_client.h",
    "mojo_media_log.cc",
    "mojo_media_log.h",
    "mojo_provision_fetcher.cc",
    "mojo_provision_fetcher.h",
    "mojo_renderer_service.cc",
    "mojo_renderer_service.h",
    "mojo_video_decoder_service.cc",
    "mojo_video_decoder_service.h",
    "mojo_video_encode_accelerator_provider.cc",
    "mojo_video_encode_accelerator_provider.h",
    "mojo_video_encode_accelerator_service.cc",
    "mojo_video_encode_accelerator_service.h",
    "mojo_video_encoder_metrics_provider_service.cc",
    "mojo_video_encoder_metrics_provider_service.h",
    "test_mojo_media_client.cc",
    "test_mojo_media_client.h",
    "video_decode_perf_history.cc",
    "video_decode_perf_history.h",
    "video_decode_stats_recorder.cc",
    "video_decode_stats_recorder.h",
    "watch_time_recorder.cc",
    "watch_time_recorder.h",
    "webrtc_video_perf_history.cc",
    "webrtc_video_perf_history.h",
    "webrtc_video_perf_recorder.cc",
    "webrtc_video_perf_recorder.h",
  ]

  if (enable_playback_events_recorder) {
    sources += [
      "playback_events_recorder.cc",
      "playback_events_recorder.h",
    ]
  }

  defines = [ "IS_MEDIA_MOJO_IMPL" ]

  public_deps = [
    "//base",
    "//media",
    "//media/gpu",
    "//media/gpu/ipc/common",
    "//media/mojo:buildflags",
    "//media/mojo/mojom",
    "//mojo/public/cpp/bindings",
    "//mojo/public/cpp/system",
    "//services/service_manager/public/cpp",
    "//url",
  ]

  deps = [
    "//build:chromeos_buildflags",
    "//gpu/ipc/service",
    "//media",
    "//media:shared_memory_support",
    "//media/gpu",
    "//media/gpu:buildflags",
    "//media/gpu/ipc/service",
    "//media/learning/impl",
    "//media/learning/mojo:impl",
    "//media/mojo/common",
    "//services/metrics/public/cpp:metrics_cpp",
    "//services/metrics/public/cpp:ukm_builders",
    "//services/service_manager/public/mojom",
  ]

  if (is_android) {
    sources += [ "gpu_mojo_media_client_android.cc" ]
  } else if (is_apple) {
    sources += [ "gpu_mojo_media_client_mac.cc" ]
  } else if (is_win) {
    sources += [ "gpu_mojo_media_client_win.cc" ]
  } else if (use_vaapi || use_v4l2_codec) {
    if (is_linux) {
      sources += [ "gpu_mojo_media_client_linux.cc" ]
    } else {
      sources += [ "gpu_mojo_media_client_cros.cc" ]
    }
  } else {
    sources += [ "gpu_mojo_media_client_stubs.cc" ]
  }

  if (is_chromeos) {
    deps +=
        [ "//chromeos/components/cdm_factory_daemon:cdm_factory_daemon_gpu" ]
  }

  if (is_linux || is_chromeos) {
    sources += [
      "mojo_video_encode_accelerator_provider_factory.cc",
      "mojo_video_encode_accelerator_provider_factory.h",
    ]
  }

  if (is_android) {
    sources += [
      "android_mojo_media_client.cc",
      "android_mojo_media_client.h",
      "android_mojo_util.cc",
      "android_mojo_util.h",
      "mediadrm_support_service.cc",
      "mediadrm_support_service.h",
    ]
  }

  if (enable_media_drm_storage) {
    sources += [
      "mojo_media_drm_storage.cc",
      "mojo_media_drm_storage.h",
    ]
  }

  if (enable_library_cdms) {
    sources += [
      "cdm_service.cc",
      "cdm_service.h",
      "cdm_service_broker.cc",
      "cdm_service_broker.h",
    ]

    # TODO(xhwang): Ideally media should not worry about sandbox. Find a way to
    # remove this dependency.
    if (is_mac) {
      deps += [ "//sandbox" ]
    }
  }

  if (is_win || enable_library_cdms) {
    sources += [
      "mojo_cdm_allocator.cc",
      "mojo_cdm_allocator.h",
      "mojo_cdm_file_io.cc",
      "mojo_cdm_file_io.h",
      "mojo_cdm_helper.cc",
      "mojo_cdm_helper.h",
    ]
    deps += [ "//media/cdm:cdm_api" ]
  }

  if (is_win) {
    sources += [
      "media_foundation_gpu_info_monitor.cc",
      "media_foundation_gpu_info_monitor.h",
      "media_foundation_mojo_media_client.cc",
      "media_foundation_mojo_media_client.h",
      "media_foundation_preferences.cc",
      "media_foundation_preferences.h",
      "media_foundation_renderer_wrapper.cc",
      "media_foundation_renderer_wrapper.h",
      "media_foundation_service.cc",
      "media_foundation_service.h",
      "media_foundation_service_broker.cc",
      "media_foundation_service_broker.h",
    ]
    deps += [ "//ui/gfx/mojom:dxgi_info" ]
  }

  if ((is_chromeos_ash || is_linux) && (use_vaapi || use_v4l2_codec)) {
    sources += [
      "stable_video_decoder_factory_process_service.cc",
      "stable_video_decoder_factory_process_service.h",
      "stable_video_decoder_factory_service.cc",
      "stable_video_decoder_factory_service.h",
      "stable_video_decoder_service.cc",
      "stable_video_decoder_service.h",
    ]

    public_deps += [ "//media/mojo/mojom/stable:stable_video_decoder" ]

    deps += [
      "//components/viz/common",
      "//media/gpu/chromeos",
    ]
  }

  if (is_fuchsia) {
    sources += [
      "fuchsia_cdm_manager.cc",
      "fuchsia_cdm_manager.h",
      "fuchsia_cdm_provisioning_fetcher_impl.cc",
      "fuchsia_cdm_provisioning_fetcher_impl.h",
    ]

    public_deps += [ "//third_party/fuchsia-sdk/sdk/fidl/fuchsia.media.drm:fuchsia.media.drm_hlcpp" ]
    deps += [ "//third_party/fuchsia-sdk/sdk/pkg/fit-promise" ]
  }
}

source_set("test_support") {
  visibility = [ "//media:test_support" ]
  testonly = true
  sources = [
    "gpu_mojo_media_client_test_util.cc",
    "gpu_mojo_media_client_test_util.h",
  ]
  configs += [
    "//build/config/compiler:wexit_time_destructors",
    "//media:media_config",
  ]
  public_deps = [
    "//base",
    "//gpu/config",
  ]
  deps = [
    ":services",
    "//media",
  ]
}

source_set("unit_tests") {
  testonly = true

  sources = [
    "deferred_destroy_unique_receiver_set_unittest.cc",
    "media_metrics_provider_unittest.cc",
    "media_service_unittest.cc",
    "mojo_audio_input_stream_unittest.cc",
    "mojo_demuxer_stream_adapter_unittest.cc",
    "mojo_video_encode_accelerator_service_unittest.cc",
    "mojo_video_encoder_metrics_provider_service_unittest.cc",
    "test_helpers.cc",
    "test_helpers.h",
    "video_decode_perf_history_unittest.cc",
    "video_decode_stats_recorder_unittest.cc",
    "watch_time_recorder_unittest.cc",
    "webrtc_video_perf_history_unittest.cc",
    "webrtc_video_perf_recorder_unittest.cc",
  ]

  if (enable_playback_events_recorder) {
    sources += [ "playback_events_recorder_test.cc" ]
  }

  deps = [
    ":services",
    "//base",
    "//base/test:test_support",
    "//components/ukm:test_support",
    "//media:test_support",
    "//media/learning/common",
    "//media/mojo:test_support",
    "//media/mojo/clients",
    "//media/mojo/common",
    "//media/mojo/mojom",
    "//mojo/core/embedder",
    "//mojo/public/interfaces/bindings/tests:test_interfaces",
    "//services/metrics/public/cpp:ukm_builders",
    "//services/service_manager/public/cpp",
    "//services/service_manager/public/cpp/test:test_support",
    "//testing/gmock",
    "//testing/gtest",
  ]

  if (enable_library_cdms) {
    sources += [
      "cdm_service_broker_unittest.cc",
      "cdm_service_unittest.cc",
      "mojo_cdm_allocator_unittest.cc",
      "mojo_cdm_file_io_unittest.cc",
      "mojo_cdm_helper_unittest.cc",
    ]

    deps += [
      "//media/cdm:cdm_api",
      "//media/cdm:cdm_paths",
    ]
  }

  if (is_android) {
    sources += [ "mediadrm_support_service_unittest.cc" ]
    deps += [ "//third_party/widevine/cdm:headers" ]
  }

  if (is_chromeos_ash) {
    deps += [
      "//components/chromeos_camera:mjpeg_decode_accelerator_service_unittest",
    ]
  }

  if ((is_chromeos_ash || is_linux) && (use_vaapi || use_v4l2_codec)) {
    sources += [ "stable_video_decoder_service_unittest.cc" ]
  }

  if (is_fuchsia) {
    sources += [
      "fuchsia_cdm_manager_unittest.cc",
      "fuchsia_cdm_provisioning_fetcher_impl_unittest.cc",
    ]

    deps += [ "//third_party/fuchsia-sdk/sdk/pkg/fit-promise" ]
  }
}

mojolpm_fuzzer_test("webrtc_video_perf_mojolpm_fuzzer") {
  sources = [ "webrtc_video_perf_mojolpm_fuzzer.cc" ]

  proto_source = "webrtc_video_perf_mojolpm_fuzzer.proto"
  testcase_proto_kind = "media.fuzzing.webrtc_video_perf.proto.Testcase"

  seed_corpus_sources = [
    "webrtc_video_perf_fuzzer_seed_corpus/update_record_and_get_perf.textproto",
  ]

  proto_deps = [ "//third_party/blink/public/mojom:mojom_platform_mojolpm" ]

  deps = [
    ":services",
    "//base",
    "//base/test:test_support",
    "//components/leveldb_proto:test_support",
    "//media",
    "//media/capabilities:webrtc_video_stats_proto",
    "//third_party/blink/public:blink",
    "//third_party/blink/public/common",
    "//third_party/libprotobuf-mutator",
  ]
}