# Copyright (c) 2024 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("//plugins/multimedia/media/media.gni")

template("plugin_multimedia_media_static") {
  forward_variables_from(invoker, "*")

  ohos_source_set(target_name) {
    defines += invoker.defines
    cflags_cc += invoker.cflags_cc

    defines += [
      "MEDIA_OHOS",
      "LOG_DOMAIN = 0xD0015B0",
      "SUPPORT_PLAYER_API9",
      "SUPPORT_VIDEO",
      "SUPPORT_METADATA",
      "SUPPORT_RECORDER_API9",
      "CROSS_PLATFORM",
    ]

    include_dirs = media_include
    include_dirs += utils_include

  third_party_skia_include_root = "//third_party/skia"
  if (ace_engine_feature_enable_upgrade_skia) {
    third_party_skia_include_root = "//third_party/skia/m133"
    defines += [ "USE_M133_SKIA" ]
  }
    include_dirs += [
      "//foundation/multimedia/player_framework/frameworks/js/avscreen_capture",
      "//foundation/multimedia/player_framework/frameworks/js/mediasource",
      "//foundation/graphic/graphic_2d/rosen/modules/platform/ipc_core",
      "//foundation/graphic/graphic_surface/interfaces/inner_api",
      "//foundation/multimedia/player_framework/frameworks/js/avtranscoder",
      "//foundation/multimedia/drm_framework/services/drm_service/ipc",
      "//foundation/multimedia/player_framework/frameworks/js/utils",
      "//foundation/multimedia/audio_framework/frameworks/native/audioutils/include",
      "${third_party_skia_include_root}",
    ]

    sources = media_source
    sources += utils_source

    deps = [
      "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_${platform}",
      "//foundation/appframework/ability/ability_runtime/cross_platform/frameworks/native/base/event_handler:cross_platform_event_handler",
      "//foundation/graphic/graphic_2d/rosen/modules/platform:utils",
      "//plugins/interfaces/native:ace_plugin_util_${platform}",
      "//plugins/interfaces/native:plugin_log",
      "//plugins/libs/napi:napi_${target_os}",
    ]

    if (platform == "android") {
      sources += [
        "//foundation/resourceschedule/qos_manager/qos/qos.cpp",
        "//foundation/resourceschedule/qos_manager/services/src/qos_interface.cpp",
      ]
      deps += [
        "android/java:media_android_jni",
        "//foundation/arkui/ace_engine/adapter/android/build:libarkui_android",
      ]
    } else if (platform == "ios") {
      sources += [
        "//plugins/multimedia/media/mock/qos.cpp",
        "//plugins/multimedia/media/mock/qos_interface.cpp",
      ]
      deps += [ "ios:media_ios" ]
      defines += [ "PLATFORM_IOS" ]
    }

    subsystem_name = "plugins"
    part_name = "multimedia"
  }
}

foreach(item, ace_platforms) {
  plugin_multimedia_media_static("multimedia_media_static_" + item.name) {
    platform = item.name

    defines = []
    cflags_cc = []
    config = {
    }

    if (defined(item.config)) {
      config = item.config
    }

    if (defined(config.defines)) {
      defines = config.defines
    }

    if (defined(config.cflags_cc)) {
      cflags_cc = config.cflags_cc
    }
  }
}