diff --git a/.github/workflows/build-debug.yml b/.github/workflows/build-debug.yml new file mode 100644 index 0000000..a1a5166 --- /dev/null +++ b/.github/workflows/build-debug.yml @@ -0,0 +1,251 @@ +name: build-debug + +on: + workflow_dispatch: + inputs: + loopCount: + required: true + type: number + defualt: 10 + +env: + TEST_SIGNALING_URLS: ${{ secrets.TEST_SIGNALING_URLS }} + TEST_CHANNEL_ID_PREFIX: ${{ secrets.TEST_CHANNEL_ID_PREFIX }} + TEST_SECRET_KEY: ${{ secrets.TEST_SECRET_KEY }} + TEST_API_URL: ${{ secrets.TEST_API_URL }} + +jobs: + build-linux: + strategy: + fail-fast: false + matrix: + platform: + - name: ubuntu-24.04_x86_64 + runs-on: ubuntu-24.04 + python: + - version: "3.10" + - version: "3.11" + - version: "3.12" + - version: "3.13" + runs-on: ${{ matrix.platform.runs-on }} + steps: + - name: Disk Cleanup + run: | + set -x + df -h + # sudo du -h -d1 /usr/local + # sudo du -h -d1 /usr/local/share + # sudo du -h -d1 /usr/local/lib + # sudo du -h -d1 /usr/share + RMI=`docker images -q -a` + if [ -n "$RMI" ]; then + docker rmi $RMI + fi + # 4.6G + sudo rm -rf /usr/local/.ghcup + # 1.7G + sudo rm -rf /usr/share/swift + # 1.4G + sudo rm -rf /usr/share/dotnet + # 13G + sudo rm -rf /usr/local/lib/android + df -h + - name: Get stats + run: | + set -x + cat /etc/lsb-release + uname -a + cat /proc/cpuinfo + cat /proc/meminfo + - name: Setup Git User + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + + - name: Setup common + run: | + # clang-18 + wget https://apt.llvm.org/llvm.sh + chmod a+x llvm.sh + sudo ./llvm.sh 18 + + - uses: actions/checkout@v4 + with: + path: sora-python-sdk + - name: Get versions + id: version + run: | + source sora-python-sdk/VERSION + echo "webrtc_build_version=${WEBRTC_BUILD_VERSION}" >> $GITHUB_OUTPUT + echo "sora_cpp_sdk_version=${SORA_CPP_SDK_VERSION}" >> $GITHUB_OUTPUT + echo "boost_version=${BOOST_VERSION}" >> $GITHUB_OUTPUT + + # libwebrtc + - uses: actions/cache@v4 + id: webrtc-build-cache + with: + path: webrtc-build/_package/${{ matrix.platform.name }}/webrtc + key: webrtc-build-${{ matrix.platform.name }}-${{ steps.version.outputs.webrtc_build_version }} + - uses: actions/checkout@v4 + if: steps.webrtc-build-cache.outputs.cache-hit != 'true' + with: + path: webrtc-build + repository: shiguredo-webrtc-build/webrtc-build + ref: ${{ steps.version.outputs.webrtc_build_version }} + - name: Setup libwebrtc + if: steps.webrtc-build-cache.outputs.cache-hit != 'true' + run: | + sudo bash -c ' + set -ex + apt-get -y install tzdata + echo "Asia/Tokyo" > /etc/timezone + dpkg-reconfigure -f noninteractive tzdata + export DEBIAN_FRONTEND=noninteractive + apt-get -y install \ + binutils \ + git \ + locales \ + lsb-release \ + ninja-build \ + pkg-config \ + python3 \ + python3-setuptools \ + rsync \ + sudo \ + unzip \ + vim \ + wget \ + xz-utils + ' + - name: Build libwebrtc + if: steps.webrtc-build-cache.outputs.cache-hit != 'true' + working-directory: webrtc-build + run: | + python3 run.py build --debug ${{ matrix.platform.name }} + python3 run.py package --debug ${{ matrix.platform.name }} + + # sora-cpp-sdk + - uses: actions/cache@v4 + id: sora-cpp-sdk-cache + with: + path: sora-cpp-sdk/_install/${{ matrix.platform.name }}/debug/sora + key: sora-cpp-sdk-${{ matrix.platform.name }}-${{ steps.version.outputs.sora_cpp_sdk_version }} + - uses: actions/cache@v4 + id: boost-cache + with: + path: sora-cpp-sdk/_install/${{ matrix.platform.name }}/debug/boost + key: boost-${{ matrix.platform.name }}-${{ steps.version.outputs.sora_cpp_sdk_version }} + - uses: actions/checkout@v4 + if: steps.sora-cpp-sdk-cache.outputs.cache-hit != 'true' + with: + path: sora-cpp-sdk + repository: shiguredo/sora-cpp-sdk + ref: ${{ steps.version.outputs.sora_cpp_sdk_version }} + # Ubuntu 24.04 だと libtinfo5 が見つからない問題があるので、その修正 + # ref: https://qiita.com/gengen16k/items/88cf3c18a40a94205fab + - name: Fix CUDA issues for Ubuntu 24.04 + if: steps.sora-cpp-sdk-cache.outputs.cache-hit != 'true' && matrix.platform.name == 'ubuntu-24.04_x86_64' + run: | + sudo tee /etc/apt/sources.list.d/jammy.list << EOF + deb http://archive.ubuntu.com/ubuntu/ jammy universe + EOF + + sudo tee /etc/apt/preferences.d/pin-jammy < sora-cpp-sdk/_install/${{ matrix.platform.name }}/debug/webrtc.version + - name: Build sora-cpp-sdk + if: steps.sora-cpp-sdk-cache.outputs.cache-hit != 'true' + working-directory: sora-cpp-sdk + run: python3 run.py --debug ${{ matrix.platform.name }} + + # sora-python-sdk + - name: Setup sora-python-sdk + run: | + sudo apt-get update + sudo apt-get -y install libva2 libdrm2 libva-dev libdrm-dev libx11-dev portaudio19-dev + + # Download OpneH264 + curl -LO http://ciscobinary.openh264.org/libopenh264-2.4.1-linux64.7.so.bz2 + bzip2 -d libopenh264-2.4.1-linux64.7.so.bz2 + mv libopenh264-2.4.1-linux64.7.so libopenh264.so + echo "OPENH264_PATH=`pwd`/libopenh264.so" >> $GITHUB_ENV + - name: Copy libwebrtc to sora-python-sdk + run: | + mkdir -p sora-python-sdk/_install/${{ matrix.platform.name }}/debug + cp -r webrtc-build/_package/${{ matrix.platform.name }}/webrtc sora-python-sdk/_install/${{ matrix.platform.name }}/webrtc + echo ${{ steps.version.outputs.webrtc_build_version }} > sora-python-sdk/_install/${{ matrix.platform.name }}/webrtc.version + - name: Copy sora-cpp-sdk to sora-python-sdk + run: | + mkdir -p sora-python-sdk/_install/${{ matrix.platform.name }}/debug + cp -r sora-cpp-sdk/_install/${{ matrix.platform.name }}/debug/sora sora-python-sdk/_install/${{ matrix.platform.name }}/sora + echo ${{ steps.version.outputs.sora_cpp_sdk_version }} > sora-python-sdk/_install/${{ matrix.platform.name }}/sora.version + - name: Copy boost to sora-python-sdk + run: | + mkdir -p sora-python-sdk/_install/${{ matrix.platform.name }}/debug + cp -r sora-cpp-sdk/_install/${{ matrix.platform.name }}/debug/boost sora-python-sdk/_install/${{ matrix.platform.name }}/boost + echo ${{ steps.version.outputs.boost_version }} > sora-python-sdk/_install/${{ matrix.platform.name }}/boost.version + - uses: actions/cache@v4 + id: llvm-cache + with: + path: sora-python-sdk/_install/${{ matrix.platform.name }}/llvm + key: llvm-${{ matrix.platform.name }}-${{ steps.version.outputs.sora_cpp_sdk }} + - uses: actions/cache@v4 + id: version-file-cache + with: + path: versions + key: versions-${{ matrix.platform.name }}-${{ steps.version.outputs.sora_cpp_sdk }} + - name: Copy version file + if: steps.version-file-cache.outputs.cache-hit == 'true' + run: cp versions/llvm.version sora-python-sdk/_install/${{ matrix.platform.name }}/ + - uses: astral-sh/setup-uv@v3 + - name: Build sora-python-sdk + working-directory: sora-python-sdk + run: | + set -x + uv python pin ${{ matrix.python.version }} + uv sync + uv run python run.py --debug ${{ matrix.platform.name }} + # cache + mkdir -p ../versions + cp _install/${{ matrix.platform.name }}/llvm.version ../versions + - name: E2E Test sora-python-sdk + working-directory: sora-python-sdk + run: | + for i in {1..${{ inputs.loopCount || 10 }}}; do + echo "---------------- $i 回目 ----------------" + sleep 10 + lldb-18 --batch -o 'command script import test_with_llvm.py' -o 'test' + done diff --git a/.github/workflows/build-relwithdebinfo.yml b/.github/workflows/build-relwithdebinfo.yml new file mode 100644 index 0000000..b5db9c3 --- /dev/null +++ b/.github/workflows/build-relwithdebinfo.yml @@ -0,0 +1,202 @@ +name: build-relwithdebinfo + +on: + workflow_dispatch: + inputs: + loopCount: + required: true + type: number + defualt: 10 + +env: + TEST_SIGNALING_URLS: ${{ secrets.TEST_SIGNALING_URLS }} + TEST_CHANNEL_ID_PREFIX: ${{ secrets.TEST_CHANNEL_ID_PREFIX }} + TEST_SECRET_KEY: ${{ secrets.TEST_SECRET_KEY }} + TEST_API_URL: ${{ secrets.TEST_API_URL }} + +jobs: + build-linux: + strategy: + fail-fast: false + matrix: + platform: + - name: ubuntu-24.04_x86_64 + runs-on: ubuntu-24.04 + python: + - version: "3.10" + - version: "3.11" + - version: "3.12" + - version: "3.13" + runs-on: ${{ matrix.platform.runs-on }} + steps: + - name: Disk Cleanup + run: | + set -x + df -h + # sudo du -h -d1 /usr/local + # sudo du -h -d1 /usr/local/share + # sudo du -h -d1 /usr/local/lib + # sudo du -h -d1 /usr/share + RMI=`docker images -q -a` + if [ -n "$RMI" ]; then + docker rmi $RMI + fi + # 4.6G + sudo rm -rf /usr/local/.ghcup + # 1.7G + sudo rm -rf /usr/share/swift + # 1.4G + sudo rm -rf /usr/share/dotnet + # 13G + sudo rm -rf /usr/local/lib/android + df -h + - name: Get stats + run: | + set -x + cat /etc/lsb-release + uname -a + cat /proc/cpuinfo + cat /proc/meminfo + - name: Setup Git User + run: | + git config --global user.name "${{ github.actor }}" + git config --global user.email "${{ github.actor }}@users.noreply.github.com" + + - name: Setup common + run: | + # clang-18 + wget https://apt.llvm.org/llvm.sh + chmod a+x llvm.sh + sudo ./llvm.sh 18 + + - uses: actions/checkout@v4 + with: + path: sora-python-sdk + - name: Get versions + id: version + run: | + source sora-python-sdk/VERSION + echo "webrtc_build_version=${WEBRTC_BUILD_VERSION}" >> $GITHUB_OUTPUT + echo "sora_cpp_sdk_version=${SORA_CPP_SDK_VERSION}" >> $GITHUB_OUTPUT + echo "boost_version=${BOOST_VERSION}" >> $GITHUB_OUTPUT + + # sora-cpp-sdk + - uses: actions/cache@v4 + id: sora-cpp-sdk-cache + with: + path: sora-cpp-sdk/_install/${{ matrix.platform.name }}/release/sora + key: sora-cpp-sdk-${{ matrix.platform.name }}-${{ steps.version.outputs.sora_cpp_sdk_version }}-relwithdebinfo + - uses: actions/cache@v4 + id: boost-cache + with: + path: sora-cpp-sdk/_install/${{ matrix.platform.name }}/release/boost + key: boost-${{ matrix.platform.name }}-${{ steps.version.outputs.sora_cpp_sdk_version }}-relwithdebinfo + - uses: actions/checkout@v4 + if: steps.sora-cpp-sdk-cache.outputs.cache-hit != 'true' + with: + path: sora-cpp-sdk + repository: shiguredo/sora-cpp-sdk + ref: ${{ steps.version.outputs.sora_cpp_sdk_version }} + # Ubuntu 24.04 だと libtinfo5 が見つからない問題があるので、その修正 + # ref: https://qiita.com/gengen16k/items/88cf3c18a40a94205fab + - name: Fix CUDA issues for Ubuntu 24.04 + if: steps.sora-cpp-sdk-cache.outputs.cache-hit != 'true' && matrix.platform.name == 'ubuntu-24.04_x86_64' + run: | + sudo tee /etc/apt/sources.list.d/jammy.list << EOF + deb http://archive.ubuntu.com/ubuntu/ jammy universe + EOF + + sudo tee /etc/apt/preferences.d/pin-jammy <> $GITHUB_ENV + - name: Copy sora-cpp-sdk to sora-python-sdk + run: | + mkdir -p sora-python-sdk/_install/${{ matrix.platform.name }}/release + cp -r sora-cpp-sdk/_install/${{ matrix.platform.name }}/release/sora sora-python-sdk/_install/${{ matrix.platform.name }}/sora + echo ${{ steps.version.outputs.sora_cpp_sdk_version }} > sora-python-sdk/_install/${{ matrix.platform.name }}/sora.version + - name: Copy boost to sora-python-sdk + run: | + mkdir -p sora-python-sdk/_install/${{ matrix.platform.name }}/release + cp -r sora-cpp-sdk/_install/${{ matrix.platform.name }}/release/boost sora-python-sdk/_install/${{ matrix.platform.name }}/boost + echo ${{ steps.version.outputs.boost_version }} > sora-python-sdk/_install/${{ matrix.platform.name }}/boost.version + - uses: actions/cache@v4 + id: llvm-cache + with: + path: sora-python-sdk/_install/${{ matrix.platform.name }}/llvm + key: llvm-${{ matrix.platform.name }}-${{ steps.version.outputs.sora_cpp_sdk }} + - uses: actions/cache@v4 + id: version-file-cache + with: + path: versions + key: versions-${{ matrix.platform.name }}-${{ steps.version.outputs.sora_cpp_sdk }} + - name: Copy version file + if: steps.version-file-cache.outputs.cache-hit == 'true' + run: cp versions/llvm.version sora-python-sdk/_install/${{ matrix.platform.name }}/ + - uses: astral-sh/setup-uv@v3 + - name: Build sora-python-sdk + working-directory: sora-python-sdk + run: | + set -x + uv python pin ${{ matrix.python.version }} + uv sync + uv run python run.py --relwithdebinfo ${{ matrix.platform.name }} + # cache + mkdir -p ../versions + cp _install/${{ matrix.platform.name }}/llvm.version ../versions + - name: E2E Test sora-python-sdk + working-directory: sora-python-sdk + run: | + for i in {1..${{ inputs.loopCount || 10 }}}; do + echo "---------------- $i 回目 ----------------" + sleep 10 + lldb-18 --batch -o 'command script import test_with_llvm.py' -o 'test' + done diff --git a/run.py b/run.py index e054a37..3bc6a79 100644 --- a/run.py +++ b/run.py @@ -226,7 +226,11 @@ def main(): args.local_sora_cpp_sdk_args, ) - configuration = "Debug" if args.debug else "Release" + configuration = "Release" + if args.debug: + configuration = "Debug" + if args.relwithdebinfo: + configuration = "RelWithDebInfo" webrtc_platform = get_webrtc_platform(platform) webrtc_info = get_webrtc_info( diff --git a/src/sora_sdk_ext.cpp b/src/sora_sdk_ext.cpp index 41237dc..b08b029 100644 --- a/src/sora_sdk_ext.cpp +++ b/src/sora_sdk_ext.cpp @@ -30,6 +30,10 @@ using namespace nb::literals; * やっておかないと終了時にリークエラーが発生する。 */ int audio_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) { + if (!nb::inst_ready(self)) { + return 0; + } + // インスタンスを取得する SoraAudioSinkImpl* audio_sink = nb::inst_ptr(self); @@ -51,6 +55,10 @@ int audio_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) { } int audio_sink_tp_clear(PyObject* self) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraAudioSinkImpl* audio_sink = nb::inst_ptr(self); audio_sink->on_format_ = nullptr; audio_sink->on_data_ = nullptr; @@ -67,6 +75,10 @@ PyType_Slot audio_sink_slots[] = { {0, nullptr}}; int audio_stream_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraAudioStreamSinkImpl* audio_sink = nb::inst_ptr(self); @@ -79,6 +91,10 @@ int audio_stream_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) { } int audio_stream_sink_tp_clear(PyObject* self) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraAudioStreamSinkImpl* audio_sink = nb::inst_ptr(self); audio_sink->on_frame_ = nullptr; @@ -91,6 +107,10 @@ PyType_Slot audio_stream_sink_slots[] = { {0, nullptr}}; int video_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraVideoSinkImpl* video_sink = nb::inst_ptr(self); if (video_sink->on_frame_) { @@ -102,6 +122,10 @@ int video_sink_tp_traverse(PyObject* self, visitproc visit, void* arg) { } int video_sink_tp_clear(PyObject* self) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraVideoSinkImpl* video_sink = nb::inst_ptr(self); video_sink->on_frame_ = nullptr; return 0; @@ -115,6 +139,10 @@ PyType_Slot video_sink_slots[] = { int audio_frame_transformer_tp_traverse(PyObject* self, visitproc visit, void* arg) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraAudioFrameTransformer* audio_frame_transformer = nb::inst_ptr(self); @@ -127,6 +155,10 @@ int audio_frame_transformer_tp_traverse(PyObject* self, } int audio_frame_transformer_tp_clear(PyObject* self) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraAudioFrameTransformer* audio_frame_transformer = nb::inst_ptr(self); audio_frame_transformer->on_transform_ = nullptr; @@ -141,6 +173,10 @@ PyType_Slot audio_frame_transformer_slots[] = { int video_frame_transformer_tp_traverse(PyObject* self, visitproc visit, void* arg) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraVideoFrameTransformer* video_frame_transformer = nb::inst_ptr(self); @@ -153,6 +189,10 @@ int video_frame_transformer_tp_traverse(PyObject* self, } int video_frame_transformer_tp_clear(PyObject* self) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraVideoFrameTransformer* video_frame_transformer = nb::inst_ptr(self); video_frame_transformer->on_transform_ = nullptr; @@ -165,6 +205,10 @@ PyType_Slot video_frame_transformer_slots[] = { {0, nullptr}}; int connection_tp_traverse(PyObject* self, visitproc visit, void* arg) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraConnection* conn = nb::inst_ptr(self); if (conn->on_set_offer_) { @@ -221,6 +265,10 @@ int connection_tp_traverse(PyObject* self, visitproc visit, void* arg) { } int connection_tp_clear(PyObject* self) { + if (!nb::inst_ready(self)) { + return 0; + } + SoraConnection* conn = nb::inst_ptr(self); conn->on_set_offer_ = nullptr; conn->on_ws_close_ = nullptr; diff --git a/test_with_llvm.py b/test_with_llvm.py new file mode 100644 index 0000000..77f28c6 --- /dev/null +++ b/test_with_llvm.py @@ -0,0 +1,39 @@ +import sys +import time + +import lldb + + +def test(debugger, command, result, internal_dict): + debugger.HandleCommand("settings set target.process.follow-fork-mode child") + + target = debugger.CreateTargetWithFileAndArch("uv", lldb.LLDB_ARCH_DEFAULT) + process = target.LaunchSimple(["run", "pytest", "tests", "-s"], None, None) + + if not process: + print("Error: could not launch process") + return + + while True: + time.sleep(1.0) + state = process.GetState() + + if state == lldb.eStateExited: + exit_status = process.GetExitStatus() + # debugger.HandleCommand(f"exit {exit_status}") + # sys.exit(exit_status) + debugger.HandleCommand("exit 0") + sys.exit(0) + elif state == lldb.eStateStopped: + thread = process.GetSelectedThread() + if thread.GetStopReason() == lldb.eStopReasonExec: + process.Continue() + continue + debugger.HandleCommand("bt all") + debugger.HandleCommand("exit 1") + sys.exit(1) + + +# LLDBにスクリプトを初期化してコマンドを追加 +def __lldb_init_module(debugger, internal_dict): + debugger.HandleCommand("command script add -f test_with_llvm.test test")