diff --git a/submodules/TelegramUI/BUCK b/submodules/TelegramUI/BUCK index 0037548b08..68c2344e36 100644 --- a/submodules/TelegramUI/BUCK +++ b/submodules/TelegramUI/BUCK @@ -35,6 +35,7 @@ framework( "//submodules/AccountContext:AccountContext", "//submodules/LegacyComponents:LegacyComponents", "//submodules/TgVoip:TgVoip", + "//submodules/TgVoipWebrtc:TgVoipWebrtc", "//submodules/lottie-ios:Lottie", "//submodules/FFMpegBinding:FFMpegBinding", "//submodules/WebPBinding:WebPBinding", diff --git a/submodules/TelegramVoip/BUCK b/submodules/TelegramVoip/BUCK index 6d74bfe5bb..9868b8dfa1 100644 --- a/submodules/TelegramVoip/BUCK +++ b/submodules/TelegramVoip/BUCK @@ -12,6 +12,7 @@ static_library( "//submodules/Postbox:Postbox#shared", "//submodules/TelegramUIPreferences:TelegramUIPreferences", "//submodules/TgVoip:TgVoip", + "//submodules/TgVoipWebrtc:TgVoipWebrtc", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", diff --git a/submodules/TgVoip/BUCK b/submodules/TgVoip/BUCK index e8d8d2596e..4b42a4b211 100644 --- a/submodules/TgVoip/BUCK +++ b/submodules/TgVoip/BUCK @@ -1,5 +1,36 @@ load("//Config:buck_rule_macros.bzl", "static_library", "glob_map", "glob_sub_map", "merge_maps") +replace_symbols = [ + "WebRtcAgc_Process", + "rtc_FatalMessage", + "WebRtcAgc_UpdateAgcThresholds", + "WebRtcAgc_Init", + "WebRtcAgc_GetAddFarendError", + "WebRtcAgc_ZeroCtrl", + "WebRtcAgc_SaturationCtrl", + "WebRtcAgc_SpeakerInactiveCtrl", + "WebRtcAgc_ProcessAnalog", + "WebRtcAgc_set_config", + "WebRtcAgc_get_config", + "WebRtcAgc_ExpCurve", + "WebRtcAgc_Create", + "WebRtcAgc_Free", + "WebRtcAgc_AddFarend", + "WebRtcAgc_VirtualMic", + "WebRtcAgc_AddMic", + "WebRtcAgc_InitDigital", + "WebRtcAgc_AddFarendToDigital", + "WebRtcAgc_CalculateGainTable", + "WebRtcAgc_InitVad", + "WebRtcAgc_ProcessVad", + "rtc", + "webrtc", +] + +shared_compiler_flags = [ + "-DTGVOIP_INCLUDE_OPUS_PACKAGE", +] + ["-D{symbol}={symbol}1".format(symbol=symbol) for symbol in replace_symbols] + static_library( name = "TgVoip", srcs = glob([ @@ -49,7 +80,7 @@ static_library( '-DWEBRTC_NS_FLOAT', '-DWEBRTC_IOS', '-DWEBRTC_HAS_NEON', - ]), + ] + shared_compiler_flags), ('.*', [ '-DTGVOIP_USE_CUSTOM_CRYPTO', '-DTGVOIP_USE_INSTALLED_OPUS', @@ -58,7 +89,7 @@ static_library( '-DTGVOIP_HAVE_TGLOG', '-DWEBRTC_NS_FLOAT', '-DWEBRTC_IOS', - ]), + ] + shared_compiler_flags), ], deps = [ "//submodules/MtProtoKit:MtProtoKit#shared", diff --git a/submodules/TgVoip/libtgvoip b/submodules/TgVoip/libtgvoip index a045c9eea4..dc4e9ec482 160000 --- a/submodules/TgVoip/libtgvoip +++ b/submodules/TgVoip/libtgvoip @@ -1 +1 @@ -Subproject commit a045c9eea47b371c0c514c72c76172a211c894cb +Subproject commit dc4e9ec48207388e41db1c2ef1cccf9899d9765f diff --git a/submodules/TgVoipWebrtc/BUCK b/submodules/TgVoipWebrtc/BUCK index ff3c426073..2d095f05d1 100644 --- a/submodules/TgVoipWebrtc/BUCK +++ b/submodules/TgVoipWebrtc/BUCK @@ -5,64 +5,33 @@ static_library( srcs = glob([ "Sources/**/*.m", "Sources/**/*.mm", - "Sources/**/*.h", - "libtgvoip/*.m", - "libtgvoip/*.mm", - "libtgvoip/*.cpp", - "libtgvoip/audio/*.cpp", - "libtgvoip/video/*.cpp", - "libtgvoip/os/darwin/*.m", - "libtgvoip/os/darwin/*.mm", - "libtgvoip/os/darwin/*.cpp", - "libtgvoip/os/posix/*.cpp", - "libtgvoip/webrtc_dsp/**/*.c", - "libtgvoip/webrtc_dsp/**/*.cc", - "libtgvoip/webrtc_dsp/**/*.cpp", - ], exclude = ["libtgvoip/os/darwin/*OSX*"]), + "Impl/*.cpp", + ]), has_cpp = True, headers = merge_maps([ - glob_sub_map("libtgvoip/", [ - "libtgvoip/*.h", - "libtgvoip/*.hpp", - "libtgvoip/audio/*.h", - "libtgvoip/audio/*.hpp", - "libtgvoip/video/*.h", - "libtgvoip/video/*.hpp", + glob_sub_map("PublicHeaders/", [ + "PublicHeaders/**/*.h", ]), - glob_sub_map("libtgvoip/", [ - "libtgvoip/os/darwin/*.h", - ], exclude = ["libtgvoip/os/darwin/*OSX*"]), - glob_sub_map("libtgvoip/webrtc_dsp/", [ - "libtgvoip/webrtc_dsp/**/*.h", + glob_sub_map("Impl/", [ + "Impl/*.h", ]), ]), exported_headers = glob([ "PublicHeaders/**/*.h", ]), - platform_compiler_flags = [ - ('arm.*', [ - '-DTGVOIP_USE_CUSTOM_CRYPTO', - '-DTGVOIP_USE_INSTALLED_OPUS', - '-DWEBRTC_APM_DEBUG_DUMP=0', - '-DWEBRTC_POSIX', - '-DTGVOIP_HAVE_TGLOG', - '-DWEBRTC_NS_FLOAT', - '-DWEBRTC_IOS', - '-DWEBRTC_HAS_NEON', - ]), - ('.*', [ - '-DTGVOIP_USE_CUSTOM_CRYPTO', - '-DTGVOIP_USE_INSTALLED_OPUS', - '-DWEBRTC_APM_DEBUG_DUMP=0', - '-DWEBRTC_POSIX', - '-DTGVOIP_HAVE_TGLOG', - '-DWEBRTC_NS_FLOAT', - '-DWEBRTC_IOS', - ]), + compiler_flags = [ + "-Ithird-party/webrtc/webrtc-ios/src", + "-Ithird-party/webrtc/webrtc-ios/src/third_party/abseil-cpp", + "-Ithird-party/submodules/TgVoipWebrtc/PublicHeaders", + "-DWEBRTC_IOS", + "-DWEBRTC_MAC", + "-DWEBRTC_POSIX", ], deps = [ "//submodules/MtProtoKit:MtProtoKit#shared", "//submodules/Opus:opus", + "//submodules/openssl:openssl", + "//third-party/webrtc:webrtc_lib", ], frameworks = [ "$SDKROOT/System/Library/Frameworks/Foundation.framework", @@ -73,4 +42,4 @@ static_library( "$SDKROOT/System/Library/Frameworks/CoreMedia.framework", "$SDKROOT/System/Library/Frameworks/AVFoundation.framework", ], -) \ No newline at end of file +) diff --git a/submodules/TgVoipWebrtc/BUILD b/submodules/TgVoipWebrtc/BUILD index b7da3e0490..eba68a38e4 100644 --- a/submodules/TgVoipWebrtc/BUILD +++ b/submodules/TgVoipWebrtc/BUILD @@ -20,8 +20,8 @@ objc_library( ]), copts = [ "-I{}/Impl".format(package_name()), - "-Ithird-party/webrtc/webrtc-ios/src".format(package_name()), - "-Ithird-party/webrtc/webrtc-ios/src/third_party/abseil-cpp".format(package_name()), + "-Ithird-party/webrtc/webrtc-ios/src", + "-Ithird-party/webrtc/webrtc-ios/src/third_party/abseil-cpp", "-DWEBRTC_IOS", "-DWEBRTC_MAC", "-DWEBRTC_POSIX", diff --git a/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm b/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm index fb7571841b..85ab31235d 100644 --- a/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm +++ b/submodules/TgVoipWebrtc/Sources/OngoingCallThreadLocalContext.mm @@ -1,4 +1,4 @@ -#import "TgVoip/OngoingCallThreadLocalContext.h" +#import #import "TgVoip.h" diff --git a/submodules/openssl/BUCK b/submodules/openssl/BUCK index dc53d924ab..5d87cd095d 100644 --- a/submodules/openssl/BUCK +++ b/submodules/openssl/BUCK @@ -132,13 +132,28 @@ genrule( srcs = [ "pack-openssl.sh", ], - bash = "sh $SRCDIR/pack-openssl.sh $OUT $(location :openssl_build_arm64)/out/include " + " ".join(["$(location :openssl_build_" + arch + ")/out/lib/libcrypto.a" for arch in archs]), + bash = "sh $SRCDIR/pack-openssl.sh $OUT $(location :openssl_build_arm64)/out/include " + + " ".join(["$(location :openssl_build_" + arch + ")/out/lib/libcrypto.a" for arch in archs]), out = "openssl", visibility = [ "PUBLIC", ] ) +genrule( + name = "openssl_libssl_merged", + srcs = [ + "pack-libssl.sh", + ], + bash = "sh $SRCDIR/pack-libssl.sh $OUT $(location :openssl_build_arm64)/out/include " + + " ".join(["$(location :openssl_build_" + arch + ")/out/lib/libssl.a" for arch in archs]), + out = "libssl", + visibility = [ + "PUBLIC", + ] +) + + openssl_header_targets = gen_header_targets(openssl_header_paths, "openssl_header_", "", "openssl_build_arm64", "out/include") apple_library( @@ -150,11 +165,15 @@ apple_library( exported_headers = openssl_header_targets, linker_flags = [ "-L$(location :openssl_build_merged)/lib", + "-L$(location :openssl_libssl_merged)/lib", "-lcrypto", + "-lssl", ], exported_linker_flags = [ "-L$(location :openssl_build_merged)/lib", + "-L$(location :openssl_libssl_merged)/lib", "-lcrypto", + "-lssl", ], deps = [":openssl_build_" + arch for arch in ["arm64"]], ) diff --git a/submodules/openssl/pack-libssl.sh b/submodules/openssl/pack-libssl.sh new file mode 100644 index 0000000000..9e00937932 --- /dev/null +++ b/submodules/openssl/pack-libssl.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +set -e +set -x + +OUT_DIR="$1" +INCLUDE_DIR="$2" +shift +shift +LIBS="$@" + +mkdir -p "$OUT_DIR/lib" + +/usr/bin/lipo $LIBS -output "$OUT_DIR/lib/libssl.a" -create + diff --git a/third-party/BUCK b/third-party/BUCK index e69de29bb2..c2e30f374b 100644 --- a/third-party/BUCK +++ b/third-party/BUCK @@ -0,0 +1,8 @@ + +filegroup( + name = "depot_tools_sources", + srcs = glob([ + "depot_tools/**/*" + ]), + visibility = ["PUBLIC"], +) diff --git a/third-party/webrtc/BUCK b/third-party/webrtc/BUCK new file mode 100644 index 0000000000..4d62e6de3d --- /dev/null +++ b/third-party/webrtc/BUCK @@ -0,0 +1,65 @@ +load("//Config:buck_rule_macros.bzl", "static_library") + +webrtc_lib_flags = [ + "-lwebrtc" +] + +genrule( + name = "webrtc_build", + srcs = [ + "build-webrtc-buck.sh", + "webrtc-ios", + "patch.sh", + ], + bash = +""" + set -x + echo "SRCDIR=$SRCDIR" + + OUT_DIR="ios" + + BUILD_ARCH=arm64 + + BUILD_DIR="$SRCDIR/$BUILD_ARCH" + rm -rf "$BUILD_DIR" + mkdir -p "$BUILD_DIR" + + mkdir -p "$BUILD_DIR/webrtc-ios" + cp -R "$SRCDIR/webrtc-ios/.git" "$BUILD_DIR/webrtc-ios/.git" + cp -R "$SRCDIR/webrtc-ios/src" "$BUILD_DIR/webrtc-ios/src" + + DEPOT_TOOLS_PATH="$(location //third-party:depot_tools_sources)" + + rm -rf "$BUILD_DIR/depot_tools" + cp -R "$DEPOT_TOOLS_PATH" "$BUILD_DIR/" + + cp "$SRCDIR/patch.sh" "$BUILD_DIR/" + + rm -rf "$BUILD_DIR/openssl" + cp -R "$(location //submodules/openssl:openssl_build_merged)" "$BUILD_DIR/openssl/" + cp -R "$(location //submodules/openssl:openssl_libssl_merged)" "$BUILD_DIR/libssl/" + + sh $SRCDIR/build-webrtc-buck.sh "$BUILD_DIR" $BUILD_ARCH + + mkdir -p "$OUT" + cp "$BUILD_DIR/webrtc-ios/src/out/$OUT_DIR/obj/libwebrtc.a" "$OUT/" +""", + out = "libwebrtc", + visibility = ["PUBLIC"] +) + +apple_library( + name = "webrtc_lib", + visibility = [ + "PUBLIC", + ], + linker_flags = [ + "-L$(location :webrtc_build)", + ] + webrtc_lib_flags, + exported_linker_flags = [ + "-L$(location :webrtc_build)", + ] + webrtc_lib_flags, + deps = [ + ":webrtc_build" + ], +) diff --git a/third-party/webrtc/build-webrtc-buck.sh b/third-party/webrtc/build-webrtc-buck.sh new file mode 100755 index 0000000000..4bbd9cd716 --- /dev/null +++ b/third-party/webrtc/build-webrtc-buck.sh @@ -0,0 +1,33 @@ +#/bin/sh + +set -x +set -e + +BUILD_DIR="$1" +ARCH="$2" + +echo "BUILD_DIR=$BUILD_DIR" +echo "ARCH=$ARCH" + +export PATH="$PATH:$BUILD_DIR/depot_tools_sources/depot_tools" + +rm -rf "$BUILD_DIR/webrtc-ios/src/openssl" +cp -R "$BUILD_DIR/openssl" "$BUILD_DIR/webrtc-ios/src/" +cp -R "$BUILD_DIR/libssl" "$BUILD_DIR/webrtc-ios/src/" + +pushd "$BUILD_DIR/webrtc-ios/src" + +mv openssl/lib/libcrypto.a openssl/ +mv libssl/lib/libssl.a openssl/ + +sh "../../patch.sh" || true + +OUT_DIR="ios" +if [ "$ARCH" == "x64" ]; then + OUT_DIR="ios_sim" +fi + +gn gen out/$OUT_DIR --args="use_xcode_clang=true "" target_cpu=\"$ARCH\""' target_os="ios" is_debug=false is_component_build=false rtc_include_tests=false use_rtti=true rtc_use_x11=false use_custom_libcxx=false use_custom_libcxx_for_host=false rtc_include_builtin_video_codecs=false rtc_build_ssl=false rtc_build_examples=false rtc_build_tools=false ios_deployment_target="9.0" ios_enable_code_signing=false is_unsafe_developer_build=false rtc_enable_protobuf=false rtc_include_builtin_video_codecs=false rtc_use_gtk=false rtc_use_metal_rendering=false rtc_ssl_root="//openssl"' +ninja -C out/$OUT_DIR webrtc + +popd diff --git a/third-party/webrtc/webrtc-ios b/third-party/webrtc/webrtc-ios index 6774acc02f..8f607fdd69 160000 --- a/third-party/webrtc/webrtc-ios +++ b/third-party/webrtc/webrtc-ios @@ -1 +1 @@ -Subproject commit 6774acc02feb905ee8209a2e187c8cc464c87289 +Subproject commit 8f607fdd6930223d8db1c8f0496c4cd3ab83be9a