package {
    default_applicable_licenses: ["frameworks_av_media_codecs_mp3dec_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_codecs_mp3dec_license",
    visibility: [":__subpackages__"],
    license_kinds: [
        "SPDX-license-identifier-Apache-2.0",
        "SPDX-license-identifier-BSD",
    ],
    license_text: [
        "NOTICE",
    ],
}

cc_library_headers {
    name: "libstagefright_mp3dec_headers",
    vendor_available: true,
    min_sdk_version: "29",
    host_supported:true,
    export_include_dirs: [
        "include",
        "src",
    ],
    apex_available: [
        "//apex_available:platform",
        "com.android.media.swcodec",
    ],
}

cc_library_static {
    name: "libstagefright_mp3dec",
    vendor_available: true,
    min_sdk_version: "29",
    apex_available: [
        "//apex_available:platform",
        "com.android.media.swcodec",
    ],

    host_supported:true,
    srcs: [
        "src/pvmp3_normalize.cpp",
        "src/pvmp3_alias_reduction.cpp",
        "src/pvmp3_crc.cpp",
        "src/pvmp3_decode_header.cpp",
        "src/pvmp3_decode_huff_cw.cpp",
        "src/pvmp3_getbits.cpp",
        "src/pvmp3_dequantize_sample.cpp",
        "src/pvmp3_framedecoder.cpp",
        "src/pvmp3_get_main_data_size.cpp",
        "src/pvmp3_get_side_info.cpp",
        "src/pvmp3_get_scale_factors.cpp",
        "src/pvmp3_mpeg2_get_scale_data.cpp",
        "src/pvmp3_mpeg2_get_scale_factors.cpp",
        "src/pvmp3_mpeg2_stereo_proc.cpp",
        "src/pvmp3_huffman_decoding.cpp",
        "src/pvmp3_huffman_parsing.cpp",
        "src/pvmp3_tables.cpp",
        "src/pvmp3_imdct_synth.cpp",
        "src/pvmp3_mdct_6.cpp",
        "src/pvmp3_dct_6.cpp",
        "src/pvmp3_poly_phase_synthesis.cpp",
        "src/pvmp3_equalizer.cpp",
        "src/pvmp3_seek_synch.cpp",
        "src/pvmp3_stereo_proc.cpp",
        "src/pvmp3_reorder.cpp",

        "src/pvmp3_polyphase_filter_window.cpp",
        "src/pvmp3_mdct_18.cpp",
        "src/pvmp3_dct_9.cpp",
        "src/pvmp3_dct_16.cpp",
    ],

    arch: {
        arm: {
            exclude_srcs: [
                "src/pvmp3_polyphase_filter_window.cpp",
                "src/pvmp3_mdct_18.cpp",
                "src/pvmp3_dct_9.cpp",
                "src/pvmp3_dct_16.cpp",
            ],
            srcs: [
                "src/asm/pvmp3_polyphase_filter_window_gcc.s",
                "src/asm/pvmp3_mdct_18_gcc.s",
                "src/asm/pvmp3_dct_9_gcc.s",
                "src/asm/pvmp3_dct_16_gcc.s",
            ],

            instruction_set: "arm",
        },
    },

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

    header_libs: ["libstagefright_mp3dec_headers"],
    export_header_lib_headers: ["libstagefright_mp3dec_headers"],

    cflags: [
        "-DOSCL_UNUSED_ARG(x)=(void)(x)",
        "-Werror",
    ],

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

//###############################################################################
cc_test {
    name: "libstagefright_mp3dec_test",
    gtest: false,

    srcs: [
        "test/mp3dec_test.cpp",
        "test/mp3reader.cpp",
    ],

    cflags: ["-Wall", "-Werror"],

    local_include_dirs: [
        "src",
        "include",
    ],

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

    static_libs: [
        "libstagefright_mp3dec",
        "libsndfile",
    ],

    shared_libs: ["libaudioutils"],
}
