# Copyright (c) 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")
import("//foundation/multimedia/av_codec/config.gni")

config("hcodec_public_cfg") {
  include_dirs = [
    "$av_codec_root_dir/services/engine/codec/video/hcodec/include",
    "$av_codec_root_dir/services/engine/base/include/",
    "$av_codec_root_dir/interfaces/inner_api/native/",
    "$av_codec_root_dir/services/utils/include/",
  ]
}

config("hcodec_cfg") {
  cflags_cc = [ "-fexceptions" ]
}

ohos_shared_library("hcodec") {
  branch_protector_ret = "pac_ret"
  install_enable = true
  subsystem_name = "multimedia"
  part_name = "av_codec"

  sanitize = av_codec_sanitize

  sources = [
    "hcodec.cpp",
    "hcodec_api.cpp",
    "hcodec_bg.cpp",
    "hcodec_dfx.cpp",
    "hcodec_list.cpp",
    "hcodec_state.cpp",
    "hcodec_utils.cpp",
    "hdecoder.cpp",
    "hencoder.cpp",
    "msg_handle_loop.cpp",
    "state_machine.cpp",
    "type_converter.cpp",
  ]

  public_configs = [ ":hcodec_public_cfg" ]
  configs = [ ":hcodec_cfg" ]
  defines = []

  if (defined(av_codec_support_video_processing_engine) &&
      av_codec_support_video_processing_engine) {
    defines += [ "USE_VIDEO_PROCESSING_ENGINE" ]
  }

  include_dirs = [
    "$av_codec_root_dir/interfaces/inner_api/native",
    "$av_codec_root_dir/services/services/common/event_manager",
  ]

  deps = [
    "$av_codec_root_dir/services/engine/base:av_codec_codec_base",
    "$av_codec_root_dir/services/utils:av_codec_service_utils",
  ]

  external_deps = [
    "c_utils:utils",
    "drivers_interface_codec:libcodec_proxy_4.0",
    "drivers_interface_display:libdisplay_commontype_proxy_1.0",
    "drivers_interface_display:libdisplay_commontype_proxy_2.2",
    "graphic_surface:surface",
    "graphic_surface:sync_fence",
    "hdf_core:libhdf_utils",
    "hdf_core:libhdi",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "hitrace:hitrace_meter",
    "hiview:xperfservice_client",
    "init:libbegetutil",
    "ipc:ipc_single",
    "media_foundation:media_foundation",
    "memory_utils:libdmabufheap",
    "openmax:libopenmax_static",
    "qos_manager:qos",
    "resource_schedule_service:ressched_client",
    "samgr:samgr_proxy",
  ]

  if (defined(av_codec_support_video_processing_engine) &&
      av_codec_support_video_processing_engine) {
    external_deps += [ "video_processing_engine:videoprocessingengine" ]
  }

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

  if (av_codec_hcodec_enable_qos_the_whole_time) {
    defines += [ "AV_CODEC_HCODEC_ENABLE_QOS_THE_WHOLE_TIME" ]
  }
}

group("hcodec_group") {
  deps = [ ":hcodec" ]
  if (build_variant != "user") {
    deps += [ "$av_codec_root_dir/test/unittest/hcodec_test/demo:hcodec_demo" ]
  }
}