chromium/media/base/android/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/android/config.gni")
import("//build/config/arm.gni")
import("//build/config/ui.gni")
import("//media/media_options.gni")

if (is_android) {
  import("//build/config/android/rules.gni")
  import("//third_party/jni_zero/jni_zero.gni")

  # This is bundled into //media, so all dependencies should be on //media.
  # APK targets that depend on this indirectly, should also
  # depend on :media_java to get the corresponding Java classes.
  source_set("android") {
    visibility = [
      "//media",
      "//media/filters",
    ]

    sources = [
      "android_cdm_factory.cc",
      "android_cdm_factory.h",
      "android_overlay.cc",
      "android_overlay.h",
      "android_util.cc",
      "android_util.h",
      "jni_hdr_metadata.cc",
      "jni_hdr_metadata.h",
      "media_codec_bridge.h",
      "media_codec_bridge_impl.cc",
      "media_codec_bridge_impl.h",
      "media_codec_direction.h",
      "media_codec_loop.cc",
      "media_codec_loop.h",
      "media_codec_util.cc",
      "media_codec_util.h",
      "media_crypto_context.h",
      "media_crypto_context_impl.cc",
      "media_crypto_context_impl.h",
      "media_drm_bridge.cc",
      "media_drm_bridge.h",
      "media_drm_bridge_client.cc",
      "media_drm_bridge_client.h",
      "media_drm_bridge_delegate.cc",
      "media_drm_bridge_delegate.h",
      "media_drm_bridge_factory.cc",
      "media_drm_bridge_factory.h",
      "media_drm_storage_bridge.cc",
      "media_drm_storage_bridge.h",
      "media_player_bridge.cc",
      "media_player_bridge.h",
      "media_player_listener.cc",
      "media_player_listener.h",
      "media_resource_getter.cc",
      "media_resource_getter.h",
      "media_server_crash_listener.cc",
      "media_server_crash_listener.h",
      "media_service_throttler.cc",
      "media_service_throttler.h",
      "media_url_interceptor.h",
      "stream_texture_wrapper.h",
    ]
    configs += [ "//media:subcomponent_config" ]
    public_deps = [ ":media_jni_headers" ]
    deps = [
      "//media/audio",
      "//media/base",
      "//media/cdm",
      "//media/formats",
      "//net",
      "//third_party/re2",
      "//third_party/widevine/cdm:headers",
      "//ui/gl",
      "//url",
    ]
    if (proprietary_codecs) {
      sources += [
        "extract_sps_and_pps.cc",
        "extract_sps_and_pps.h",
      ]
    }
  }

  source_set("unit_tests") {
    testonly = true
    sources = [
      "media_codec_bridge_impl_unittest.cc",
      "media_codec_loop_unittest.cc",
      "media_codec_util_unittest.cc",
      "media_drm_bridge_unittest.cc",
      "media_player_bridge_unittest.cc",
      "media_service_throttler_unittest.cc",
    ]

    deps = [
      "//base/test:test_support",
      "//media:test_support",
      "//net",
      "//testing/gmock",
      "//testing/gtest",
      "//third_party/libyuv",
      "//third_party/widevine/cdm:headers",
      "//ui/gfx:color_space",
    ]
    configs += [ "//media:media_config" ]
  }

  static_library("test_support") {
    testonly = true
    sources = [
      "mock_android_overlay.cc",
      "mock_android_overlay.h",
      "mock_media_codec_bridge.cc",
      "mock_media_codec_bridge.h",
      "mock_media_crypto_context.cc",
      "mock_media_crypto_context.h",
      "test_destruction_observable.cc",
      "test_destruction_observable.h",
    ]
    deps = [
      "//base/test:test_support",
      "//media/base:test_support",
      "//testing/gmock",
      "//testing/gtest",
    ]
  }

  generate_jni("media_jni_headers") {
    sources = [
      "java/src/org/chromium/media/AudioManagerAndroid.java",
      "java/src/org/chromium/media/AudioTrackOutputStream.java",
      "java/src/org/chromium/media/CodecProfileLevelList.java",
      "java/src/org/chromium/media/HdrMetadata.java",
      "java/src/org/chromium/media/MediaCodecBridge.java",
      "java/src/org/chromium/media/MediaCodecBridgeBuilder.java",
      "java/src/org/chromium/media/MediaCodecUtil.java",
      "java/src/org/chromium/media/MediaDrmBridge.java",
      "java/src/org/chromium/media/MediaDrmStorageBridge.java",
      "java/src/org/chromium/media/MediaPlayerBridge.java",
      "java/src/org/chromium/media/MediaPlayerListener.java",
      "java/src/org/chromium/media/MediaServerCrashListener.java",
      "java/src/org/chromium/media/VideoAcceleratorUtil.java",
    ]
  }

  java_cpp_enum("java_enums") {
    sources = [
      "media_codec_bridge.h",
      "media_codec_direction.h",
      "media_drm_bridge.h",
    ]
  }

  java_cpp_strings("java_switches") {
    sources = [ "//media/base/media_switches.cc" ]
    template = "//media/base/android/java_templates/MediaSwitches.java.tmpl"
  }

  java_cpp_features("java_features") {
    sources = [ "//media/base/media_switches.cc" ]
    template = "//media/base/android/java_templates/MediaFeatures.java.tmpl"
  }

  android_resources("media_java_resources") {
    sources = [ "java/res/raw/empty.wav" ]
  }

  android_library("media_java") {
    visibility = [ "//*" ]
    deps = [
      ":display_java",
      ":media_java_resources",
      "//base:base_java",
      "//build/android:build_java",
      "//third_party/androidx:androidx_annotation_annotation_java",
      "//third_party/jni_zero:jni_zero_java",
    ]

    srcjar_deps = [
      ":java_enums",
      ":java_features",
      ":java_switches",
      ":media_jni_headers",
      "//media/base:java_enums",
    ]
    resources_package = "org.chromium.media"
    sources = [
      "java/src/org/chromium/media/AudioDeviceListener.java",
      "java/src/org/chromium/media/AudioDeviceSelector.java",
      "java/src/org/chromium/media/AudioDeviceSelectorPostS.java",
      "java/src/org/chromium/media/AudioDeviceSelectorPreS.java",
      "java/src/org/chromium/media/AudioManagerAndroid.java",
      "java/src/org/chromium/media/AudioTrackOutputStream.java",
      "java/src/org/chromium/media/BitrateAdjuster.java",
      "java/src/org/chromium/media/CodecProfileLevelList.java",
      "java/src/org/chromium/media/HdrMetadata.java",
      "java/src/org/chromium/media/MaxAnticipatedResolutionEstimator.java",
      "java/src/org/chromium/media/MediaCodecBridge.java",
      "java/src/org/chromium/media/MediaCodecBridgeBuilder.java",
      "java/src/org/chromium/media/MediaCodecEncoder.java",
      "java/src/org/chromium/media/MediaCodecUtil.java",
      "java/src/org/chromium/media/MediaDrmBridge.java",
      "java/src/org/chromium/media/MediaDrmSessionManager.java",
      "java/src/org/chromium/media/MediaDrmStorageBridge.java",
      "java/src/org/chromium/media/MediaFormatBuilder.java",
      "java/src/org/chromium/media/MediaPlayerBridge.java",
      "java/src/org/chromium/media/MediaPlayerListener.java",
      "java/src/org/chromium/media/MediaServerCrashListener.java",
      "java/src/org/chromium/media/ScreenResolutionUtil.java",
      "java/src/org/chromium/media/VideoAcceleratorUtil.java",
    ]
  }

  # TODO (b/146418831): Replace with androidx version
  android_library("display_java") {
    sources = [ "java/src/org/chromium/media/DisplayCompat.java" ]

    deps = [ "//third_party/androidx:androidx_annotation_annotation_java" ]
  }

  robolectric_binary("media_base_junit_tests") {
    sources = [
      "java/src/test/org/chromium/media/AudioDeviceListenerTest.java",
      "java/src/test/org/chromium/media/AudioTrackOutputStreamTest.java",
      "java/src/test/org/chromium/media/BitrateAdjusterTest.java",
      "java/src/test/org/chromium/media/MediaFormatBuilderTest.java",
    ]
    deps = [
      ":media_java",
      "//base:base_java",
      "//base:base_java_test_support",
      "//base:base_junit_test_support",
      "//third_party/androidx:androidx_test_runner_java",
      "//third_party/junit",
    ]
  }
} else {
  source_set("android") {
  }
  source_set("test_support") {
    testonly = true
  }
}