// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Headers module is in frameworks/av/Android.bp because modules are not allowed
// to refer to headers in parent directories and the headers live in
// frameworks/av/include.

package {
    default_applicable_licenses: ["frameworks_av_media_ndk_license"],
}

// Added automatically by a large-scale-change that took the approach of
// 'apply every license found to every target'. While this makes sure we respect
// every license restriction, it may not be entirely correct.
//
// e.g. GPL in an MIT project might only apply to the contrib/ directory.
//
// Please consider splitting the single license below into multiple licenses,
// taking care not to lose any license_kind information, and overriding the
// default license using the 'licenses: [...]' property on targets as needed.
//
// For unused files, consider creating a 'fileGroup' with "//visibility:private"
// to attach the license to, and including a comment whether the files may be
// used in the current project.
// See: http://go/android-license-faq
license {
    name: "frameworks_av_media_ndk_license",
    visibility: [":__subpackages__"],
    license_kinds: [
        "SPDX-license-identifier-Apache-2.0",
        "SPDX-license-identifier-MIT",
        "SPDX-license-identifier-Unicode-DFS",
    ],
    license_text: [
        "NOTICE",
    ],
}

ndk_library {
    name: "libmediandk",
    symbol_file: "libmediandk.map.txt",
    first_version: "21",
    unversioned_until: "current",
}

ndk_headers {
    name: "libmediandk_headers",
    from: "include/media",
    to: "media",
    srcs: ["include/media/**/*.h"],
    license: "NOTICE",
}

// for use with header_libs
// supports use as <media/NdkMediaExtractor.h> not <NdkMediaExtractor.h>
cc_library_headers {
    name: "media_ndk_headers",
    vendor_available: true,
    // TODO(b/153609531): remove when no longer needed.
    native_bridge_supported: true,
    apex_available: [
        "//apex_available:platform",
        "com.android.media",
        "com.android.media.swcodec",
    ],
    min_sdk_version: "29",
    export_include_dirs: ["include"],
    host_supported: true,
    target: {
        darwin: {
            enabled: false,
        },
    },
}

cc_library_shared {
    name: "libmediandk",
    llndk: {
        symbol_file: "libmediandk.map.txt",
    },

    srcs: [
        "NdkJavaVMHelper.cpp",
        "NdkMediaCodec.cpp",
        "NdkMediaCrypto.cpp",
        "NdkMediaDataSource.cpp",
        "NdkMediaExtractor.cpp",
        "NdkMediaFormat.cpp",
        "NdkMediaMuxer.cpp",
        "NdkMediaDrm.cpp",
        "NdkImage.cpp",
        "NdkImageReader.cpp",
    ],

    include_dirs: [
        "system/media/camera/include",
    ],

    cflags: [
        "-DEXPORT=__attribute__((visibility(\"default\")))",
        "-Werror",
        "-Wall",
    ],

    static_libs: [
        "libgrallocusage",
        "libnativehelper_lazy",
    ],

    header_libs: [
        "jni_headers",
        "libmediadrm_headers",
        "libmediametrics_headers",
    ],

    shared_libs: [
        "android.hardware.graphics.bufferqueue@1.0",
        "android.hidl.token@1.0-utils",
        "libandroid_runtime_lazy",
        "libbase",
        "libdatasource",
        "libmedia",
        "libmediadrm",
        "libmedia_omx",
        "libmedia_jni_utils",
        "libstagefright",
        "libstagefright_foundation",
        "liblog",
        "libutils",
        "libcutils",
        "libnativewindow",
        "libhidlbase",
        "libgui",
        "libui",
        "libmediandk_utils",
        "android.hardware.drm-V1-ndk",
    ],

    export_header_lib_headers: ["jni_headers"],

    export_include_dirs: [
        "include",
        "include_platform",
    ],

    export_shared_lib_headers: [
        "libgui",
    ],

    version_script: "libmediandk.map.txt",
    stubs: {
        symbol_file: "libmediandk.map.txt",
        versions: ["29"],
    },
}

cc_library {
    name: "libmediandk_utils",

    srcs: [
        "NdkMediaDataSourceCallbacks.cpp",
    ],

    local_include_dirs: [
        "include",
    ],

    export_include_dirs: [
        "include",
    ],

    cflags: [
        "-Werror",
        "-Wno-error=deprecated-declarations",
        "-Wall",
    ],

    header_libs: [
        "libstagefright_headers",
        "libmedia_headers",
    ],

    shared_libs: [
    ],

    sanitize: {
        misc_undefined: [
            "unsigned-integer-overflow",
            "signed-integer-overflow",
        ],
        cfi: true,
    },
}

cc_test {
    name: "AImageReaderWindowTest",
    test_suites: ["device-tests"],
    srcs: ["tests/AImageReaderWindowTest.cpp"],
    shared_libs: [
        "libbinder",
        "libmediandk",
        "libmediautils",
        "libnativewindow",
        "libgui",
        "libhidlbase",
        "libutils",
        "libui",
        "libcutils",
        "android.hardware.graphics.bufferqueue@1.0",
        "android.hidl.token@1.0",
    ],

    header_libs: [
        "libstagefright_foundation_headers",
    ],

    cflags: [
        "-D__ANDROID_VNDK__",
    ],
}

cc_library_static {
    name: "libmediandk_format",

    host_supported: true,

    srcs: [
        "NdkMediaFormat.cpp",
    ],

    header_libs: [
        "libstagefright_foundation_headers",
    ],

    cflags: [
        "-DEXPORT=__attribute__((visibility(\"default\")))",
        "-Werror",
        "-Wall",
    ],

    export_include_dirs: ["include"],

    sanitize: {
        misc_undefined: [
            "unsigned-integer-overflow",
            "signed-integer-overflow",
        ],
        cfi: true,
    },

    target: {
        darwin: {
            enabled: false,
        },
    },

    apex_available: [
        "//apex_available:platform",
        "com.android.media",
        "com.android.media.swcodec",
    ],
}
