Skip to content

Commit

Permalink
Lyra 抜きでビルドするオプションを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Aug 7, 2023
1 parent 2fb6db0 commit a2fcacc
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 58 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

## develop

- [ADD] Lyra 抜きでビルドする --no-lyra オプションを追加
- @melpon

## 2023.8.0 (2023-07-28)

- [UPDATE] WebRTC を m115.5790.7.0 に上げる
Expand Down
22 changes: 18 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(WEBRTC_LIBRARY_NAME "webrtc" CACHE STRING "WebRTC のライブラリ名")
set(USE_LIBCXX OFF CACHE BOOL "libstdc++ の代わりに libc++ を使うかどうか")
set(LIBCXX_INCLUDE_DIR "" CACHE PATH "libc++ を使う場合の libc++ のインクルードディレクトリ\n空文字だった場合はデフォルト検索パスの libc++ を利用する")
set(USE_NVCODEC_ENCODER OFF CACHE BOOL "NVIDIA Video Codec SDK によるハードウェアエンコーダを利用するかどうか")
set(USE_LYRA OFF CACHE BOOL "Lyra を利用するかどうか")

project(sora-cpp-sdk C CXX)

Expand Down Expand Up @@ -67,8 +68,10 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)

find_package(WebRTC REQUIRED)
find_package(Boost REQUIRED COMPONENTS json filesystem)
find_package(Lyra REQUIRED)
find_package(Threads REQUIRED)
if (USE_LYRA)
find_package(Lyra REQUIRED)
endif()

set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
Expand All @@ -88,9 +91,7 @@ target_include_directories(sora PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_sources(sora
PRIVATE
src/aligned_encoder_adapter.cpp
src/audio_decoder_lyra.cpp
src/audio_device_module.cpp
src/audio_encoder_lyra.cpp
src/camera_device_capturer.cpp
src/data_channel.cpp
src/default_video_formats.cpp
Expand All @@ -115,6 +116,13 @@ target_sources(sora
src/websocket.cpp
src/zlib_helper.cpp
)
if (USE_LYRA)
target_sources(sora
PRIVATE
src/audio_decoder_lyra.cpp
src/audio_encoder_lyra.cpp
)
endif()

target_compile_definitions(sora PRIVATE ${SORA_TARGET_DEF})

Expand All @@ -133,11 +141,16 @@ endif()

target_link_libraries(sora
PUBLIC
Lyra::lyra
WebRTC::webrtc
Boost::json
Boost::filesystem
)
if (USE_LYRA)
target_link_libraries(sora
PUBLIC
Lyra::lyra
)
endif()

if (USE_LIBCXX)
target_compile_options(sora
Expand All @@ -154,6 +167,7 @@ target_compile_definitions(sora
USE_NVCODEC_ENCODER=$<BOOL:${USE_NVCODEC_ENCODER}>
USE_JETSON_ENCODER=$<BOOL:${USE_JETSON_ENCODER}>
USE_VPL_ENCODER=$<BOOL:${USE_VPL_ENCODER}>
USE_LYRA=$<BOOL:${USE_LYRA}>
)

# 指定したライブラリを自身の静的ライブラリにバンドルする
Expand Down
116 changes: 65 additions & 51 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,7 @@ def __init__(self, target_os, target_osver, target_arch):


def install_deps(platform: Platform, source_dir, build_dir, install_dir, debug,
webrtcbuild: bool, webrtc_config: WebrtcConfig):
webrtcbuild: bool, webrtc_config: WebrtcConfig, no_lyra: bool):
with cd(BASE_DIR):
version = read_version_file('VERSION')

Expand Down Expand Up @@ -1387,21 +1387,22 @@ def install_deps(platform: Platform, source_dir, build_dir, install_dir, debug,
with open(os.path.join(install_dir, 'webrtc.ldflags'), 'w') as f:
f.write('\n'.join(ldflags))

# Lyra
install_lyra_args = {
'version': version['LYRA_VERSION'],
'version_file': os.path.join(install_dir, 'lyra.version'),
'install_dir': install_dir,
'base_dir': BASE_DIR,
'debug': debug,
'target': platform.target.package_name,
'webrtc_version': webrtc_version,
'webrtc_info': webrtc_info,
'api_level': version['ANDROID_NATIVE_API_LEVEL'],
# run.py の引数から拾ってくるのが面倒なので環境変数を使う
'temp_dir': os.environ.get('SORA_CPP_SDK_TEMP_DIR'),
}
install_lyra(**install_lyra_args)
if not no_lyra:
# Lyra
install_lyra_args = {
'version': version['LYRA_VERSION'],
'version_file': os.path.join(install_dir, 'lyra.version'),
'install_dir': install_dir,
'base_dir': BASE_DIR,
'debug': debug,
'target': platform.target.package_name,
'webrtc_version': webrtc_version,
'webrtc_info': webrtc_info,
'api_level': version['ANDROID_NATIVE_API_LEVEL'],
# run.py の引数から拾ってくるのが面倒なので環境変数を使う
'temp_dir': os.environ.get('SORA_CPP_SDK_TEMP_DIR'),
}
install_lyra(**install_lyra_args)


AVAILABLE_TARGETS = ['windows_x86_64', 'macos_x86_64', 'macos_arm64', 'ubuntu-20.04_x86_64',
Expand All @@ -1414,6 +1415,7 @@ def main():
parser.add_argument("target", choices=AVAILABLE_TARGETS)
parser.add_argument("--debug", action='store_true')
parser.add_argument("--relwithdebinfo", action='store_true')
parser.add_argument("--no-lyra", action='store_true')
parser.add_argument("--webrtcbuild", action='store_true')
parser.add_argument("--webrtcbuild-fetch", action='store_true')
parser.add_argument("--webrtcbuild-fetch-force", action='store_true')
Expand Down Expand Up @@ -1461,7 +1463,7 @@ def main():
mkdir_p(install_dir)

install_deps(platform, source_dir, build_dir, install_dir, args.debug,
webrtcbuild=args.webrtcbuild, webrtc_config=args)
webrtcbuild=args.webrtcbuild, webrtc_config=args, no_lyra=args.no_lyra)

configuration = 'Release'
if args.debug:
Expand All @@ -1476,7 +1478,9 @@ def main():
cmake_args.append(f'-DCMAKE_BUILD_TYPE={configuration}')
cmake_args.append(f"-DCMAKE_INSTALL_PREFIX={cmake_path(os.path.join(install_dir, 'sora'))}")
cmake_args.append(f"-DBOOST_ROOT={cmake_path(os.path.join(install_dir, 'boost'))}")
cmake_args.append(f"-DLYRA_DIR={cmake_path(os.path.join(install_dir, 'lyra'))}")
if not args.no_lyra:
cmake_args.append(f"-DLYRA_DIR={cmake_path(os.path.join(install_dir, 'lyra'))}")
cmake_args.append(f"-DUSE_LYRA={'ON' if not args.no_lyra else 'OFF'}")
webrtc_info = get_webrtc_info(args.webrtcbuild, source_dir, build_dir, install_dir)
webrtc_version = read_version_file(webrtc_info.version_file)
with cd(BASE_DIR):
Expand All @@ -1493,7 +1497,8 @@ def main():
cmake_args.append(f"-DWEBRTC_BUILD_VERSION={webrtc_version['WEBRTC_BUILD_VERSION']}")
cmake_args.append(f"-DWEBRTC_READABLE_VERSION={webrtc_version['WEBRTC_READABLE_VERSION']}")
cmake_args.append(f"-DWEBRTC_COMMIT={webrtc_version['WEBRTC_COMMIT']}")
cmake_args.append(f"-DLYRA_COMPATIBLE_VERSION={lyra_compatible_version}")
if not args.no_lyra:
cmake_args.append(f"-DLYRA_COMPATIBLE_VERSION={lyra_compatible_version}")
if platform.target.os == 'windows':
cmake_args.append(f'-DCMAKE_SYSTEM_VERSION={WINDOWS_SDK_VERSION}')
if platform.target.os == 'ubuntu':
Expand Down Expand Up @@ -1598,12 +1603,13 @@ def main():

if args.test:
if platform.target.os == 'ios':
# Lyra テストのディレクトリに
# Lyra のモデル係数ファイルをコピーする
model_src = os.path.join(install_dir, 'lyra', 'share', 'model_coeffs')
model_dst = os.path.join(BASE_DIR, 'test', 'ios', 'hello', 'model_coeffs')
rm_rf(model_dst)
shutil.copytree(model_src, model_dst)
if not args.no_lyra:
# Lyra テストのディレクトリに
# Lyra のモデル係数ファイルをコピーする
model_src = os.path.join(install_dir, 'lyra', 'share', 'model_coeffs')
model_dst = os.path.join(BASE_DIR, 'test', 'ios', 'hello', 'model_coeffs')
rm_rf(model_dst)
shutil.copytree(model_src, model_dst)

# iOS の場合は事前に用意したプロジェクトをビルドする
cmd(['xcodebuild', 'build',
Expand All @@ -1624,13 +1630,14 @@ def main():
with cd(os.path.join(BASE_DIR, 'test', 'android')):
cmd(['./gradlew', '--no-daemon', 'assemble'])

# Lyra テストのビルド先のディレクトリに
# Lyra のモデル係数ファイルをコピーする
model_src = os.path.join(install_dir, 'lyra', 'share', 'model_coeffs')
model_dst = os.path.join('app', 'src', 'main', 'assets')
rm_rf(model_dst)
mkdir_p(os.path.dirname(model_dst))
shutil.copytree(model_src, model_dst)
if not args.no_lyra:
# Lyra テストのビルド先のディレクトリに
# Lyra のモデル係数ファイルをコピーする
model_src = os.path.join(install_dir, 'lyra', 'share', 'model_coeffs')
model_dst = os.path.join('app', 'src', 'main', 'assets')
rm_rf(model_dst)
mkdir_p(os.path.dirname(model_dst))
shutil.copytree(model_src, model_dst)
else:
# 普通のプロジェクトは CMake でビルドする
test_build_dir = os.path.join(build_dir, 'test')
Expand All @@ -1642,7 +1649,9 @@ def main():
cmake_args.append(f"-DWEBRTC_INCLUDE_DIR={cmake_path(webrtc_info.webrtc_include_dir)}")
cmake_args.append(f"-DWEBRTC_LIBRARY_DIR={cmake_path(webrtc_info.webrtc_library_dir)}")
cmake_args.append(f"-DSORA_DIR={cmake_path(os.path.join(install_dir, 'sora'))}")
cmake_args.append(f"-DLYRA_DIR={cmake_path(os.path.join(install_dir, 'lyra'))}")
if not args.no_lyra:
cmake_args.append(f"-DLYRA_DIR={cmake_path(os.path.join(install_dir, 'lyra'))}")
cmake_args.append(f"-DUSE_LYRA={'ON' if not args.no_lyra else 'OFF'}")
if platform.target.os == 'macos':
sysroot = cmdcap(['xcrun', '--sdk', 'macosx', '--show-sdk-path'])
target = 'x86_64-apple-darwin' if platform.target.arch == 'x86_64' else 'aarch64-apple-darwin'
Expand Down Expand Up @@ -1692,21 +1701,23 @@ def main():
if platform.target.package_name in ('windows_x86_64', 'macos_x86_64', 'macos_arm64',
'ubuntu-20.04_x86_64', 'ubuntu-22.04_x86_64',
'ubuntu-20.04_armv8_jetson'):
cmake_args.append("-DTEST_LYRA=ON")
if not args.no_lyra:
cmake_args.append("-DTEST_LYRA=ON")

cmd(['cmake', os.path.join(BASE_DIR, 'test')] + cmake_args)
cmd(['cmake', '--build', '.', f'-j{multiprocessing.cpu_count()}', '--config', configuration])

# Lyra テストのビルド先のディレクトリに
# Lyra のモデル係数ファイルをコピーする
model_src = os.path.join(install_dir, 'lyra', 'share', 'model_coeffs')
if platform.target.os == 'windows':
model_dst = os.path.join(test_build_dir, configuration, 'model_coeffs')
else:
model_dst = os.path.join(test_build_dir, 'model_coeffs')
rm_rf(model_dst)
mkdir_p(os.path.dirname(model_dst))
shutil.copytree(model_src, model_dst)
if not args.no_lyra:
# Lyra テストのビルド先のディレクトリに
# Lyra のモデル係数ファイルをコピーする
model_src = os.path.join(install_dir, 'lyra', 'share', 'model_coeffs')
if platform.target.os == 'windows':
model_dst = os.path.join(test_build_dir, configuration, 'model_coeffs')
else:
model_dst = os.path.join(test_build_dir, 'model_coeffs')
rm_rf(model_dst)
mkdir_p(os.path.dirname(model_dst))
shutil.copytree(model_src, model_dst)

if args.run:
if platform.target.os == 'windows':
Expand Down Expand Up @@ -1750,19 +1761,22 @@ def archive(archive_path, files, is_windows):
boost_archive_path = os.path.join(package_dir, boost_archive_name)
archive(boost_archive_path, enum_all_files('boost', '.'), is_windows)

lyra_archive_name = \
f'lyra-{lyra_version}_sora-cpp-sdk-{sora_cpp_sdk_version}_{platform.target.package_name}.{ext}'
lyra_archive_path = os.path.join(package_dir, lyra_archive_name)
archive(lyra_archive_path, enum_all_files('lyra', '.'), is_windows)
if not args.no_lyra:
lyra_archive_name = \
f'lyra-{lyra_version}_sora-cpp-sdk-{sora_cpp_sdk_version}_{platform.target.package_name}.{ext}'
lyra_archive_path = os.path.join(package_dir, lyra_archive_name)
archive(lyra_archive_path, enum_all_files('lyra', '.'), is_windows)

with open(os.path.join(package_dir, 'sora.env'), 'w') as f:
f.write(f'CONTENT_TYPE={content_type}\n')
f.write(f'PACKAGE_NAME={archive_name}\n')
f.write(f'BOOST_PACKAGE_NAME={boost_archive_name}\n')
f.write(f'LYRA_PACKAGE_NAME={lyra_archive_name}\n')
if not args.no_lyra:
f.write(f'LYRA_PACKAGE_NAME={lyra_archive_name}\n')

with cd(os.path.join(BASE_DIR, 'third_party', 'lyra')):
cmd(['bazel', 'shutdown'])
if not args.no_lyra:
with cd(os.path.join(BASE_DIR, 'third_party', 'lyra')):
cmd(['bazel', 'shutdown'])


if __name__ == '__main__':
Expand Down
9 changes: 8 additions & 1 deletion src/sora_audio_decoder_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <api/audio_codecs/opus/audio_decoder_multi_channel_opus.h>
#include <api/audio_codecs/opus/audio_decoder_opus.h>

#if USE_LYRA
#include "sora/audio_decoder_lyra.h"
#endif

namespace sora {

Expand Down Expand Up @@ -43,7 +45,12 @@ CreateBuiltinAudioDecoderFactory() {
webrtc::AudioDecoderOpus,
NotAdvertised<webrtc::AudioDecoderMultiChannelOpus>,
webrtc::AudioDecoderG722, webrtc::AudioDecoderG711,
NotAdvertised<webrtc::AudioDecoderL16>, sora::AudioDecoderLyra>();
NotAdvertised<webrtc::AudioDecoderL16>
#if USE_LYRA
,
sora::AudioDecoderLyra
#endif
>();
}

} // namespace sora
9 changes: 8 additions & 1 deletion src/sora_audio_encoder_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
#include <api/audio_codecs/opus/audio_encoder_multi_channel_opus.h>
#include <api/audio_codecs/opus/audio_encoder_opus.h>

#if USE_LYRA
#include "sora/audio_encoder_lyra.h"
#endif

namespace sora {

Expand Down Expand Up @@ -49,7 +51,12 @@ CreateBuiltinAudioEncoderFactory() {
webrtc::AudioEncoderOpus,
NotAdvertised<webrtc::AudioEncoderMultiChannelOpus>,
webrtc::AudioEncoderG722, webrtc::AudioEncoderG711,
NotAdvertised<webrtc::AudioEncoderL16>, sora::AudioEncoderLyra>();
NotAdvertised<webrtc::AudioEncoderL16>
#if USE_LYRA
,
sora::AudioEncoderLyra
#endif
>();
}

} // namespace sora
5 changes: 4 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(WEBRTC_LIBRARY_DIR "" CACHE PATH "WebRTC のライブラリディレクト
set(WEBRTC_LIBRARY_NAME "webrtc" CACHE STRING "WebRTC のライブラリ名")
set(LIBCXX_INCLUDE_DIR "" CACHE PATH "libc++ を使う場合の libc++ のインクルードディレクトリ\n空文字だった場合はデフォルト検索パスの libc++ を利用する")
set(SORA_DIR "" CACHE PATH "Sora のルートディレクトリ")
set(USE_LYRA OFF CACHE BOOL "Lyra を利用するかどうか")

project(sora-test C CXX)

Expand All @@ -23,11 +24,13 @@ endif()

find_package(Boost REQUIRED COMPONENTS json filesystem)
find_package(WebRTC REQUIRED)
find_package(Lyra REQUIRED)
find_package(Sora REQUIRED)
find_package(Threads REQUIRED)
find_package(Libdrm)
find_package(Libva)
if (USE_LYRA)
find_package(Lyra REQUIRED)
endif()

function (init_target target)
set_target_properties(${target} PROPERTIES CXX_STANDARD 20 C_STANDARD 20)
Expand Down

0 comments on commit a2fcacc

Please sign in to comment.