# Copyright (c) 2023-2026 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("http_source_plugin_config") {
  defines = [
    "HST_ANY_WITH_NO_RTTI",
    "MEDIA_OHOS",
  ]

  cflags = [
    "-Wno-sign-compare",
    "-fno-exceptions",
    "-fno-common",
    "-fstack-protector-all",
    "-Wshadow",
    "-FPIC",
    "-FS",
    "-O2",
    "-fvisibility=hidden",
    "-D_FORTIFY_SOURCE=2",
    "-Wformat=2",
    "-Wdate-time",
  ]

  cflags_cc = [
    "-std=c++17",
    "-fno-rtti",
  ]

  include_dirs = [
    "$av_codec_root_dir/interfaces",
    "$av_codec_root_dir/interfaces/inner_api/native",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/base64",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/xml",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/include",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/include/mpd_parser",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/utils",
  ]
}

ohos_shared_library("media_plugin_HttpSource") {
  branch_protector_ret = "pac_ret"
  install_enable = true
  sanitize = av_codec_sanitize

  configs = [
    ":http_source_plugin_config",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]

  deps = [
    ":media_plugin_HttpSource_static",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/network_client:http_curl_client",
  ]

  external_deps = [
    "c_utils:utils",
    "ffmpeg:libohosffmpeg",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "netmanager_base:net_conn_manager_if",
   ]

  relative_install_dir = "media/media_plugins"
  subsystem_name = "multimedia"
  part_name = "av_codec"
}

ohos_static_library("media_plugin_HttpSource_static") {
  branch_protector_ret = "pac_ret"
  sanitize = av_codec_sanitize

  configs = [
    ":http_source_plugin_config",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]

  sources = [
    "base64/base64_utils.cpp",
    "dash/dash_media_downloader.cpp",
    "dash/dash_mpd_downloader.cpp",
    "dash/dash_segment_downloader.cpp",
    "dash/mpd_parser/dash_adpt_set_manager.cpp",
    "dash/mpd_parser/dash_manager_util.cpp",
    "dash/mpd_parser/dash_mpd_manager.cpp",
    "dash/mpd_parser/dash_mpd_parser.cpp",
    "dash/mpd_parser/dash_mpd_util.cpp",
    "dash/mpd_parser/dash_period_manager.cpp",
    "dash/mpd_parser/dash_representation_manager.cpp",
    "dash/mpd_parser/dash_generic_node.cpp",
    "dash/mpd_parser/i_dash_mpd_node.cpp",
    "dash/mpd_parser/sidx_box_parser.cpp",
    "download/app_client.cpp",
    "download/downloader.cpp",
    "download/media_source_loading_request.cpp",
    "hls/hls_media_downloader.cpp",
    "hls/hls_playlist_downloader.cpp",
    "hls/hls_tags.cpp",
    "hls/m3u8.cpp",
    "hls/playlist_downloader.cpp",
    "hls/hls_segment_manager.cpp",
    "http/http_media_downloader.cpp",
    "http_source_plugin.cpp",
    "http_source_plugin_stream_protocol_sniffer.cpp",
    "http_source_plugin_stream_resource_parser.cpp",
    "utils/http_media_utils.cpp",
    "monitor/download_monitor.cpp",
    "utils/aes_decryptor.cpp",
    "utils/media_cached_buffer.cpp",
    "xml/xml_element.cpp",
    "xml/xml_parser.cpp",
    "utils/storage_usage_util.cpp",
    "utils/string_utils.cpp",
  ]

  deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]

  external_deps = [
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "samgr:samgr_proxy",
    "c_utils:utils",
    "ffmpeg:libohosffmpeg",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "netmanager_base:net_conn_manager_if",
  ]

  subsystem_name = "multimedia"
  part_name = "av_codec"
}