# Copyright (C) 2023-2023 Huawei Device Co., Ltd.
# 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.

import("//build/ohos.gni")

declare_args() {
  av_codec_support_capi = true
  av_codec_support_codec = true
  av_codec_client_support_codec = true
  av_codec_support_codeclist = true
  av_codec_support_hcodec = true
  av_codec_support_demuxer = true
  av_codec_support_source = true
  av_codec_support_muxer = true
  av_codec_support_test = true
  av_codec_support_xcollie = true
  av_codec_support_bitstream_dump = true
  av_codec_support_drm = false
  av_codec_enable_special_codec = false
  av_codec_support_video_processing_engine = false
  if (defined(global_parts_info) &&
      defined(global_parts_info.multimedia_video_processing_engine)) {
    av_codec_support_video_processing_engine = true
  }
  av_codec_support_libcurl = true
  if (defined(global_parts_info) && defined(global_parts_info.multimedia_histreamer_ext)) {
    av_codec_support_libcurl = false
  }
  av_codec_support_software_codec = true
  av_codec_support_fcodec = true
  av_codec_support_avc_encoder = true
  av_codec_support_hevc_decoder = true
  av_codec_support_av1_decoder = false
  av_codec_support_mp4v_decoder = true
  av_codec_support_vc1_decoder = false
  av_codec_enable_start_stop_on_demand = false
  av_codec_hcodec_enable_qos_the_whole_time = false
  av_codec_enable_codec_rm = true
  av_codec_enable_codec_rv = true
  av_codec_enable_codec_eac3 = false
  av_codec_enable_codec_truehd = true
  av_codec_enable_codec_dts = true
  av_codec_enable_codec_opus = false
  av_codec_enable_codec_amrnb = false
  av_codec_enable_demuxer_lrc = false
  av_codec_enable_demuxer_eac3 = false
  av_codec_enable_demuxer_sami = false
  av_codec_enable_demuxer_ass = false
  av_codec_enable_demuxer_dtshd = false
  av_codec_enable_demuxer_truehd = false
  av_codec_enable_memc = false
  av_codec_support_camera_post_processor = false
  if (defined(global_parts_info) &&
      defined(global_parts_info.hdf_drivers_interface_camera_ext)) {
    av_codec_support_camera_post_processor = true
  }
  av_codec_support_vp8_decoder = false
  av_codec_support_vp9_decoder = false
  av_codec_support_10bit_test = false
  av_codec_enable_player_startup_optimization = false
  av_codec_enable_only_for_flagship_chip = false
  av_codec_enable_api_metrics = true
  if (defined(global_parts_info) && !defined(global_parts_info.hiviewdfx_api_metrics)) {
      av_codec_enable_api_metrics = false
  }
  av_codec_enable_audio_convert = false
  av_codec_support_video_encoder_preprocessing = false
  if (defined(global_parts_info) && defined(global_parts_info.UtilityApplication_FAST)) {
    av_codec_support_video_encoder_preprocessing = true
  }
}
av_codec_sanitize = {
  boundary_sanitize = true
  cfi = true
  cfi_cross_dso = true
  integer_overflow = true
  ubsan = true
  debug = false
}
av_codec_test_sanitize = {
  debug = false
}
av_codec_root_dir = "//foundation/multimedia/av_codec"
media_foundation_root_dir = "//foundation/multimedia/media_foundation"
audio_framework_root_dir = "//foundation/multimedia/audio_framework"
graphic_2d_root_dir = "//foundation/graphic/graphic_2d"
graphic_suface_root_dir = "//foundation/graphic/graphic_surface"
c_utils_root_dir = "//commonlibrary/c_utils"
drm_framework_root_dir = "//foundation/multimedia/drm_framework"
video_processing_engine_root_dir =
    "//foundation/multimedia/video_processing_engine"

av_codec_defines = [
  "HST_ANY_WITH_NO_RTTI",
  "MEDIA_OHOS",
]

if (build_variant != "user") {
  av_codec_defines += [ "BUILD_ENG_VERSION" ]
}

if (av_codec_support_capi) {
  av_codec_defines += [ "SUPPORT_CAPI" ]
} else {
  av_codec_defines += [ "UNSUPPORT_CAPI" ]
}

if (av_codec_support_codec) {
  av_codec_defines += [ "SUPPORT_CODEC" ]
} else {
  av_codec_defines += [ "UNSUPPORT_CODEC" ]
}

if (av_codec_support_codeclist) {
  av_codec_defines += [ "SUPPORT_CODECLIST" ]
} else {
  av_codec_defines += [ "UNSUPPORT_CODECLIST" ]
}

if (av_codec_support_hcodec) {
  av_codec_defines += [ "SUPPORT_HCODEC" ]
} else {
  av_codec_defines += [ "UNSUPPORT_HCODEC" ]
}

if (av_codec_support_demuxer) {
  av_codec_defines += [ "SUPPORT_DEMUXER" ]
} else {
  av_codec_defines += [ "UNSUPPORT_DEMUXER" ]
}

if (av_codec_support_muxer) {
  av_codec_defines += [ "SUPPORT_MUXER" ]
} else {
  av_codec_defines += [ "UNSUPPORT_MUXER" ]
}

if (av_codec_support_source) {
  av_codec_defines += [ "SUPPORT_SOURCE" ]
} else {
  av_codec_defines += [ "UNSUPPORT_SOURCE" ]
}

if (av_codec_support_xcollie) {
  av_codec_defines += [ "HICOLLIE_ENABLE" ]
}

if (av_codec_support_bitstream_dump) {
  av_codec_defines += [ "BITSTREAM_DUMP_ENABLE" ]
}

if (defined(global_parts_info) &&
    defined(global_parts_info.multimedia_drm_framework)) {
  av_codec_support_drm = true
}

if (av_codec_support_drm) {
  av_codec_defines += [ "SUPPORT_DRM" ]
} else {
  av_codec_defines += [ "UNSUPPORT_DRM" ]
}

if (av_codec_support_mp4v_decoder) {
  av_codec_defines += ["SUPPORT_CODEC_MP4V_ES"]
}

if (av_codec_support_vc1_decoder) {
  av_codec_defines += ["SUPPORT_CODEC_VC1"]
}

if (!(defined(global_parts_info) && defined(global_parts_info.thirdparty_dav1d))) {
  av_codec_support_av1_decoder = false
}

if (!(defined(global_parts_info) && defined(global_parts_info.thirdparty_libvpx))) {
  av_codec_support_vp8_decoder = false
  av_codec_support_vp9_decoder = false
}

if (!av_codec_support_software_codec) {
  av_codec_support_fcodec = false
  av_codec_support_avc_encoder = false
  av_codec_support_hevc_decoder = false
  av_codec_support_vp8_decoder = false
  av_codec_support_vp9_decoder = false
  av_codec_support_av1_decoder = false
}

if (av_codec_support_vp8_decoder) {
  av_codec_defines += ["SUPPORT_CODEC_VP8"]
}

if (av_codec_support_vp9_decoder) {
  av_codec_defines += ["SUPPORT_CODEC_VP9"]
}

if (av_codec_support_av1_decoder) {
  av_codec_defines += ["SUPPORT_CODEC_AV1"]
}

if (av_codec_enable_codec_rm) {
  av_codec_defines += [ "SUPPORT_CODEC_RM" ]
}

if (av_codec_enable_codec_rv) {
  av_codec_defines += [ "SUPPORT_CODEC_RV" ]
}

if (av_codec_enable_codec_eac3) {
  av_codec_defines += [ "SUPPORT_CODEC_EAC3" ]
}

if (av_codec_enable_codec_truehd) {
  av_codec_defines += [ "SUPPORT_CODEC_TRUEHD" ]
}

if (av_codec_enable_codec_dts) {
  av_codec_defines += [ "SUPPORT_CODEC_DTS" ]
}

if (av_codec_enable_codec_opus) {
  av_codec_defines += [ "SUPPORT_CODEC_OPUS" ]
}

if (av_codec_enable_codec_amrnb) {
  av_codec_defines += [ "SUPPORT_CODEC_AMRNB" ]
}

if (av_codec_enable_demuxer_lrc) {
  av_codec_defines += [ "SUPPORT_DEMUXER_LRC" ]
}

if (av_codec_enable_demuxer_sami) {
  av_codec_defines += [ "SUPPORT_DEMUXER_SAMI" ]
}

if (av_codec_enable_demuxer_ass) {
  av_codec_defines += [ "SUPPORT_DEMUXER_ASS" ]
}

if (av_codec_enable_memc) {
  av_codec_defines += [ "SUPPORT_FPS_FOR_MEMC" ]
}

if (av_codec_enable_demuxer_eac3) {
  av_codec_defines += [ "SUPPORT_DEMUXER_EAC3" ]
}

if (av_codec_enable_demuxer_dtshd) {
  av_codec_defines += [ "SUPPORT_DEMUXER_DTSHD" ]
}

if (av_codec_enable_demuxer_truehd) {
  av_codec_defines += [ "SUPPORT_DEMUXER_TRUEHD" ]
}

if (av_codec_support_10bit_test) {
  av_codec_defines += ["SUPPORT_10BIT_TEST"]
}

if (av_codec_enable_audio_convert) {
  av_codec_defines += ["SUPPORT_AUDIO_CONVERT"]
}

if (av_codec_support_video_encoder_preprocessing) {
  av_codec_defines += ["SUPPORT_VIDEO_ENCODER_PREPROCESSING"]
}