diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index a9309805..1a7dfef4 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -33,6 +33,9 @@ on: - .github/workflows/** workflow_dispatch: +permissions: + contents: read + env: CARGO_TERM_COLOR: always # vcpkg binary caching for Windows @@ -252,7 +255,7 @@ jobs: ./build.sh clean-all || true fi - docker-build: + docker-build-x64: name: Build (docker-linux-x64) runs-on: ubuntu-latest @@ -267,9 +270,115 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Build Docker image - run: docker build -t livekit-cpp-sdk:${{ github.sha }} . -f docker/Dockerfile + run: | + docker buildx build \ + --platform linux/amd64 \ + --load \ + -t livekit-cpp-sdk-x64:${{ github.sha }} \ + . \ + -f docker/Dockerfile + + - name: Verify installed SDK inside image + run: | + docker run --rm livekit-cpp-sdk-x64:${{ github.sha }} bash -c \ + 'test -f /opt/livekit-sdk/lib/cmake/LiveKit/LiveKitConfig.cmake' - - name: Build SDK inside Docker + - name: Save Docker image artifact + run: | + docker save livekit-cpp-sdk-x64:${{ github.sha }} | gzip > livekit-cpp-sdk-x64-docker.tar.gz + + - name: Upload Docker image artifact + uses: actions/upload-artifact@v4 + with: + name: livekit-cpp-sdk-docker-x64 + path: livekit-cpp-sdk-x64-docker.tar.gz + retention-days: 7 + + docker-build-linux-arm64: + name: Build (docker-linux-arm64) + runs-on: ubuntu-24.04-arm + + steps: + - name: Checkout (with submodules) + uses: actions/checkout@v4 + with: + submodules: recursive + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + run: | + docker buildx build \ + --platform linux/arm64 \ + --load \ + -t livekit-cpp-sdk:${{ github.sha }} \ + . \ + -f docker/Dockerfile + + - name: Verify installed SDK inside image run: | docker run --rm livekit-cpp-sdk:${{ github.sha }} bash -c \ - 'cd /client-sdk-cpp && chmod +x build.sh && ./build.sh release-examples' + 'test -f /opt/livekit-sdk/lib/cmake/LiveKit/LiveKitConfig.cmake' + + - name: Save Docker image artifact + run: | + docker save livekit-cpp-sdk:${{ github.sha }} | gzip > livekit-cpp-sdk-arm64-docker.tar.gz + + - name: Upload Docker image artifact + uses: actions/upload-artifact@v4 + with: + name: livekit-cpp-sdk-docker-arm64 + path: livekit-cpp-sdk-arm64-docker.tar.gz + retention-days: 7 + + build-collections-linux-arm64: + name: Build (cpp-example-collection-linux-arm64) + runs-on: ubuntu-24.04-arm + needs: docker-build-linux-arm64 + + steps: + - name: Download Docker image artifact + uses: actions/download-artifact@v4 + with: + name: livekit-cpp-sdk-docker-arm64 + + - name: Load Docker image + run: gzip -dc livekit-cpp-sdk-arm64-docker.tar.gz | docker load + + - name: Build cpp-example-collection against installed SDK + run: | + docker run --rm livekit-cpp-sdk:${{ github.sha }} bash -lc ' + set -euxo pipefail + git clone https://github.com/livekit-examples/cpp-example-collection.git /tmp/cpp-example-collection + cd /tmp/cpp-example-collection + git checkout sderosa/examples-migration + cmake -S . -B build -DLIVEKIT_LOCAL_SDK_DIR=/opt/livekit-sdk + cmake --build build --parallel + ' + + build-collections-x64: + name: Build (cpp-example-collection-x64) + runs-on: ubuntu-latest + needs: docker-build-x64 + + steps: + - name: Download Docker image artifact + uses: actions/download-artifact@v4 + with: + name: livekit-cpp-sdk-docker-x64 + + - name: Load Docker image + run: gzip -dc livekit-cpp-sdk-x64-docker.tar.gz | docker load + + - name: Build cpp-example-collection against installed SDK + run: | + docker run --rm livekit-cpp-sdk-x64:${{ github.sha }} bash -lc ' + set -euxo pipefail + git clone https://github.com/livekit-examples/cpp-example-collection.git /tmp/cpp-example-collection + cd /tmp/cpp-example-collection + git checkout sderosa/examples-migration + cmake -S . -B build -DLIVEKIT_LOCAL_SDK_DIR=/opt/livekit-sdk + cmake --build build --parallel + ' diff --git a/CMakeLists.txt b/CMakeLists.txt index 3af32d2c..2ea1a353 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -378,9 +378,8 @@ target_include_directories(livekit ) target_link_libraries(livekit - PUBLIC - $ PRIVATE + spdlog::spdlog livekit_ffi ${LIVEKIT_PROTOBUF_TARGET} ) diff --git a/bridge/CMakeLists.txt b/bridge/CMakeLists.txt index 369c98df..549e86cb 100644 --- a/bridge/CMakeLists.txt +++ b/bridge/CMakeLists.txt @@ -32,13 +32,6 @@ target_include_directories(livekit_bridge target_link_libraries(livekit_bridge PUBLIC livekit - PRIVATE - spdlog::spdlog -) - -target_compile_definitions(livekit_bridge - PRIVATE - SPDLOG_ACTIVE_LEVEL=${_SPDLOG_ACTIVE_LEVEL} ) if(MSVC) diff --git a/bridge/include/livekit_bridge/livekit_bridge.h b/bridge/include/livekit_bridge/livekit_bridge.h index 47f13d46..1f2d44a6 100644 --- a/bridge/include/livekit_bridge/livekit_bridge.h +++ b/bridge/include/livekit_bridge/livekit_bridge.h @@ -23,7 +23,6 @@ #include "livekit_bridge/bridge_video_track.h" #include "livekit_bridge/rpc_constants.h" -#include "livekit/lk_log.h" #include "livekit/local_participant.h" #include "livekit/room.h" #include "livekit/rpc_error.h" diff --git a/bridge/src/bridge_audio_track.cpp b/bridge/src/bridge_audio_track.cpp index 1fa58cd2..5816cfce 100644 --- a/bridge/src/bridge_audio_track.cpp +++ b/bridge/src/bridge_audio_track.cpp @@ -24,10 +24,9 @@ #include "livekit/local_audio_track.h" #include "livekit/local_participant.h" +#include #include -#include "livekit/lk_log.h" - namespace livekit_bridge { BridgeAudioTrack::BridgeAudioTrack( @@ -56,7 +55,7 @@ bool BridgeAudioTrack::pushFrame(const std::vector &data, try { source_->captureFrame(frame, timeout_ms); } catch (const std::exception &e) { - LK_LOG_ERROR("BridgeAudioTrack captureFrame error: {}", e.what()); + std::cerr << "[error] BridgeAudioTrack captureFrame error: " << e.what() << "\n"; return false; } return true; @@ -77,7 +76,7 @@ bool BridgeAudioTrack::pushFrame(const std::int16_t *data, try { source_->captureFrame(frame, timeout_ms); } catch (const std::exception &e) { - LK_LOG_ERROR("BridgeAudioTrack captureFrame error: {}", e.what()); + std::cerr << "[error] BridgeAudioTrack captureFrame error: " << e.what() << "\n"; return false; } return true; @@ -115,8 +114,8 @@ void BridgeAudioTrack::release() { participant_->unpublishTrack(track_->publication()->sid()); } catch (...) { // Best-effort cleanup; ignore errors during teardown - LK_LOG_WARN("BridgeAudioTrack unpublishTrack error, continuing with " - "cleanup"); + std::cerr << "[warn] BridgeAudioTrack unpublishTrack error, continuing " + "with cleanup\n"; } } diff --git a/bridge/src/bridge_video_track.cpp b/bridge/src/bridge_video_track.cpp index 7b8a6cc8..7a66155f 100644 --- a/bridge/src/bridge_video_track.cpp +++ b/bridge/src/bridge_video_track.cpp @@ -24,10 +24,9 @@ #include "livekit/video_frame.h" #include "livekit/video_source.h" +#include #include -#include "livekit/lk_log.h" - namespace livekit_bridge { BridgeVideoTrack::BridgeVideoTrack( @@ -56,7 +55,7 @@ bool BridgeVideoTrack::pushFrame(const std::vector &rgba, try { source_->captureFrame(frame, timestamp_us); } catch (const std::exception &e) { - LK_LOG_ERROR("BridgeVideoTrack captureFrame error: {}", e.what()); + std::cerr << "[error] BridgeVideoTrack captureFrame error: " << e.what() << "\n"; return false; } return true; @@ -76,7 +75,7 @@ bool BridgeVideoTrack::pushFrame(const std::uint8_t *rgba, try { source_->captureFrame(frame, timestamp_us); } catch (const std::exception &e) { - LK_LOG_ERROR("BridgeVideoTrack captureFrame error: {}", e.what()); + std::cerr << "[error] BridgeVideoTrack captureFrame error: " << e.what() << "\n"; return false; } return true; @@ -114,8 +113,8 @@ void BridgeVideoTrack::release() { participant_->unpublishTrack(track_->publication()->sid()); } catch (...) { // Best-effort cleanup; ignore errors during teardown - LK_LOG_WARN("BridgeVideoTrack unpublishTrack error, continuing with " - "cleanup"); + std::cerr << "[warn] BridgeVideoTrack unpublishTrack error, continuing " + "with cleanup\n"; } } diff --git a/bridge/src/livekit_bridge.cpp b/bridge/src/livekit_bridge.cpp index 9f782904..b15587ec 100644 --- a/bridge/src/livekit_bridge.cpp +++ b/bridge/src/livekit_bridge.cpp @@ -34,6 +34,7 @@ #include "livekit/video_source.h" #include +#include #include namespace livekit_bridge { @@ -122,8 +123,8 @@ void LiveKitBridge::disconnect() { std::lock_guard lock(mutex_); if (!connected_) { - LK_LOG_WARN("Attempting to disconnect an already disconnected bridge. " - "Things may not disconnect properly."); + std::cerr << "[warn] Attempting to disconnect an already disconnected " + "bridge. Things may not disconnect properly.\n"; } connected_ = false; @@ -241,7 +242,8 @@ void LiveKitBridge::setOnAudioFrameCallback( AudioFrameCallback callback) { std::lock_guard lock(mutex_); if (!room_) { - LK_LOG_WARN("setOnAudioFrameCallback called before connect(); ignored"); + std::cerr << "[warn] setOnAudioFrameCallback called before connect(); " + "ignored\n"; return; } room_->setOnAudioFrameCallback(participant_identity, source, @@ -253,7 +255,8 @@ void LiveKitBridge::setOnVideoFrameCallback( VideoFrameCallback callback) { std::lock_guard lock(mutex_); if (!room_) { - LK_LOG_WARN("setOnVideoFrameCallback called before connect(); ignored"); + std::cerr << "[warn] setOnVideoFrameCallback called before connect(); " + "ignored\n"; return; } room_->setOnVideoFrameCallback(participant_identity, source, diff --git a/cmake/LiveKitConfig.cmake.in b/cmake/LiveKitConfig.cmake.in index 90b1a7e1..b5805e4d 100644 --- a/cmake/LiveKitConfig.cmake.in +++ b/cmake/LiveKitConfig.cmake.in @@ -1,7 +1,4 @@ @PACKAGE_INIT@ -include(CMakeFindDependencyMacro) -find_dependency(spdlog) - include("${CMAKE_CURRENT_LIST_DIR}/LiveKitTargets.cmake") diff --git a/docker/Dockerfile b/docker/Dockerfile index 0f42ff0b..ccdc1c7d 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -22,6 +22,7 @@ FROM ubuntu:22.04 ENV DEBIAN_FRONTEND=noninteractive ENV HOME=/root +ENV SDK_INSTALL_PREFIX=/opt/livekit-sdk # Install make, pkg-config, and base build deps (pkg-config + libglib2.0-dev for Rust glib-sys, libasound2-dev for alsa-sys) RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -29,18 +30,25 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ git \ libasound2-dev \ + libabsl-dev \ libclang-dev \ libdrm-dev \ libglib2.0-dev \ + libprotobuf-dev \ + libdecor-0-dev \ libspdlog-dev \ libssl-dev \ libunwind-dev \ libusb-1.0-0-dev \ libva-dev \ + libwayland-dev \ make \ ninja-build \ pkg-config \ + protobuf-compiler \ wget \ + llvm-dev \ + clang \ xz-utils \ && rm -rf /var/lib/apt/lists/* @@ -122,3 +130,13 @@ RUN mkdir -p /client-sdk-cpp/client-sdk-rust/.cargo \ && printf '%s\n' '[target.x86_64-unknown-linux-gnu]' 'linker = "/root/gcc-14/bin/g++"' \ '[target.aarch64-unknown-linux-gnu]' 'linker = "/root/gcc-14/bin/g++"' > /client-sdk-cpp/client-sdk-rust/.cargo/config.toml +# Build and install the SDK into a fixed prefix so downstream projects can +# consume the image as a prebuilt LiveKit SDK environment. +RUN LLVM_VERSION="$(llvm-config --version | cut -d. -f1)" \ + && export LIBCLANG_PATH="/usr/lib/llvm-${LLVM_VERSION}/lib" \ + && export CXXFLAGS="-Wno-deprecated-declarations" \ + && export CFLAGS="-Wno-deprecated-declarations" \ + && chmod +x /client-sdk-cpp/build.sh \ + && cd /client-sdk-cpp \ + && ./build.sh release --bundle --prefix "${SDK_INSTALL_PREFIX}" \ + && test -f "${SDK_INSTALL_PREFIX}/lib/cmake/LiveKit/LiveKitConfig.cmake" diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6d7ab0a5..5398e26d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -30,9 +30,6 @@ set(EXAMPLES_PRIVATE_INCLUDE_DIRS ${LIVEKIT_BINARY_DIR}/generated ) -# Propagate the compile-time log level to all example targets. -add_compile_definitions(SPDLOG_ACTIVE_LEVEL=${_SPDLOG_ACTIVE_LEVEL}) - # Shared example code (SDL media, wav source, etc.) set(EXAMPLES_COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common) @@ -97,7 +94,6 @@ target_include_directories(SimpleRoom PRIVATE target_link_libraries(SimpleRoom PRIVATE livekit - spdlog::spdlog SDL3::SDL3 ) @@ -152,7 +148,6 @@ target_link_libraries(SimpleRpc PRIVATE nlohmann_json::nlohmann_json livekit - spdlog::spdlog ) # --- SimpleJoystick example (sender + receiver executables with shared json_utils) --- @@ -183,7 +178,6 @@ target_link_libraries(SimpleJoystickReceiver PRIVATE simple_joystick_json_utils livekit - spdlog::spdlog ) add_executable(SimpleJoystickSender @@ -196,7 +190,6 @@ target_link_libraries(SimpleJoystickSender PRIVATE simple_joystick_json_utils livekit - spdlog::spdlog ) # --- LoggingLevelsBasicUsage example --- @@ -207,11 +200,17 @@ add_executable(LoggingLevelsBasicUsage target_include_directories(LoggingLevelsBasicUsage PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS}) +# Internal LK_LOG_* macros + lk_log.h require spdlog and the same compile-time +# log level as the main SDK (SPDLOG_ACTIVE_LEVEL). target_link_libraries(LoggingLevelsBasicUsage PRIVATE livekit spdlog::spdlog ) +target_compile_definitions(LoggingLevelsBasicUsage + PRIVATE + SPDLOG_ACTIVE_LEVEL=${_SPDLOG_ACTIVE_LEVEL} +) # --- LoggingLevelsCustomSinks example --- @@ -235,7 +234,6 @@ target_include_directories(SimpleDataStream PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_D target_link_libraries(SimpleDataStream PRIVATE livekit - spdlog::spdlog ) add_custom_command( @@ -275,7 +273,6 @@ target_link_libraries(PingPongPing PRIVATE ping_pong_support livekit - spdlog::spdlog ) add_executable(PingPongPong @@ -288,7 +285,6 @@ target_link_libraries(PingPongPong PRIVATE ping_pong_support livekit - spdlog::spdlog ) # --- hello_livekit (minimal synthetic video + data publish / subscribe) --- @@ -302,7 +298,6 @@ target_include_directories(HelloLivekitSender PRIVATE ${EXAMPLES_PRIVATE_INCLUDE target_link_libraries(HelloLivekitSender PRIVATE livekit - spdlog::spdlog ) add_executable(HelloLivekitReceiver @@ -314,7 +309,6 @@ target_include_directories(HelloLivekitReceiver PRIVATE ${EXAMPLES_PRIVATE_INCLU target_link_libraries(HelloLivekitReceiver PRIVATE livekit - spdlog::spdlog ) # --- bridge_human_robot examples (robot + human; use livekit_bridge and SDL3) --- @@ -328,7 +322,7 @@ target_include_directories(BridgeRobot PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS} ${EXAMPLES_COMMON_DIR} ) -target_link_libraries(BridgeRobot PRIVATE livekit_bridge spdlog::spdlog SDL3::SDL3) +target_link_libraries(BridgeRobot PRIVATE livekit_bridge SDL3::SDL3) add_executable(BridgeHuman bridge_human_robot/human.cpp @@ -339,7 +333,7 @@ target_include_directories(BridgeHuman PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS} ${EXAMPLES_COMMON_DIR} ) -target_link_libraries(BridgeHuman PRIVATE livekit spdlog::spdlog SDL3::SDL3) +target_link_libraries(BridgeHuman PRIVATE livekit SDL3::SDL3) # --- bridge_rpc examples (headless custom RPC caller + receiver) --- @@ -364,7 +358,7 @@ target_include_directories(BridgeMuteCaller PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS} ${EXAMPLES_COMMON_DIR} ) -target_link_libraries(BridgeMuteCaller PRIVATE livekit_bridge spdlog::spdlog SDL3::SDL3) +target_link_libraries(BridgeMuteCaller PRIVATE livekit_bridge SDL3::SDL3) add_executable(BridgeMuteReceiver bridge_mute_unmute/receiver.cpp @@ -375,7 +369,7 @@ target_include_directories(BridgeMuteReceiver PRIVATE ${EXAMPLES_PRIVATE_INCLUDE_DIRS} ${EXAMPLES_COMMON_DIR} ) -target_link_libraries(BridgeMuteReceiver PRIVATE livekit_bridge spdlog::spdlog SDL3::SDL3) +target_link_libraries(BridgeMuteReceiver PRIVATE livekit_bridge SDL3::SDL3) # Copy SDL3 shared library to bridge example output directories if(UNIX AND NOT APPLE) diff --git a/examples/bridge_human_robot/human.cpp b/examples/bridge_human_robot/human.cpp index 3e8c553d..714a77ae 100644 --- a/examples/bridge_human_robot/human.cpp +++ b/examples/bridge_human_robot/human.cpp @@ -162,7 +162,7 @@ int main(int argc, char *argv[]) { // ----- Initialize SDL3 ----- if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) { - LK_LOG_ERROR("[human] SDL_Init failed: {}", SDL_GetError()); + std::cerr << "[human] SDL_Init failed: " << SDL_GetError() << "\n"; return 1; } @@ -173,14 +173,15 @@ int main(int argc, char *argv[]) { SDL_Window *window = SDL_CreateWindow("Human - Robot Camera Feed", kWindowWidth, kWindowHeight, 0); if (!window) { - LK_LOG_ERROR("[human] SDL_CreateWindow failed: {}", SDL_GetError()); + std::cerr << "[human] SDL_CreateWindow failed: " << SDL_GetError() << "\n"; SDL_Quit(); return 1; } SDL_Renderer *renderer = SDL_CreateRenderer(window, nullptr); if (!renderer) { - LK_LOG_ERROR("[human] SDL_CreateRenderer failed: {}", SDL_GetError()); + std::cerr << "[human] SDL_CreateRenderer failed: " << SDL_GetError() + << "\n"; SDL_DestroyWindow(window); SDL_Quit(); return 1; @@ -202,7 +203,7 @@ int main(int argc, char *argv[]) { livekit::RoomOptions options; options.auto_subscribe = true; if (!room->Connect(url, token, options)) { - LK_LOG_ERROR("[human] Failed to connect."); + std::cerr << "[human] Failed to connect.\n"; livekit::shutdown(); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); @@ -224,7 +225,7 @@ int main(int argc, char *argv[]) { speaker = std::make_unique(frame.sample_rate(), frame.num_channels()); if (!speaker->init()) { - LK_LOG_ERROR("[human] Failed to init SDL speaker."); + std::cerr << "[human] Failed to init SDL speaker.\n"; speaker.reset(); return; } @@ -342,7 +343,8 @@ int main(int argc, char *argv[]) { texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STREAMING, fw, fh); if (!texture) { - LK_LOG_ERROR("[human] SDL_CreateTexture failed: {}", SDL_GetError()); + std::cerr << "[human] SDL_CreateTexture failed: " << SDL_GetError() + << "\n"; } tex_width = fw; tex_height = fh; diff --git a/examples/bridge_human_robot/robot.cpp b/examples/bridge_human_robot/robot.cpp index 041580ef..f3e2f021 100644 --- a/examples/bridge_human_robot/robot.cpp +++ b/examples/bridge_human_robot/robot.cpp @@ -351,21 +351,21 @@ int main(int argc, char *argv[]) { if (use_mic) sdl_flags |= SDL_INIT_AUDIO; if (!SDL_Init(sdl_flags)) { - LK_LOG_ERROR("[robot] SDL_Init failed: {}", SDL_GetError()); + std::cerr << "[robot] SDL_Init failed: " << SDL_GetError() << "\n"; return 1; } // ----- Connect to LiveKit ----- livekit_bridge::LiveKitBridge bridge; - LK_LOG_INFO("[robot] Connecting to {} ...", url); + std::cout << "[robot] Connecting to " << url << " ...\n"; livekit::RoomOptions options; options.auto_subscribe = true; if (!bridge.connect(url, token, options)) { - LK_LOG_ERROR("[robot] Failed to connect."); + std::cerr << "[robot] Failed to connect.\n"; SDL_Quit(); return 1; } - LK_LOG_INFO("[robot] Connected."); + std::cout << "[robot] Connected.\n"; // ----- Create outgoing tracks ----- constexpr int kSampleRate = 48000; @@ -389,10 +389,10 @@ int main(int argc, char *argv[]) { auto sim_cam = bridge.createVideoTrack("robot-sim-frame", kSimWidth, kSimHeight, livekit::TrackSource::SOURCE_SCREENSHARE); - LK_LOG_INFO("[robot] Publishing {} sim audio ({} Hz, {} ch), cam + sim frame " - "({}x{} / {}x{}).", - use_mic ? "mic + " : "(no mic) ", kSampleRate, kChannels, kWidth, - kHeight, kSimWidth, kSimHeight); + std::cout << "[robot] Publishing " << (use_mic ? "mic + " : "(no mic) ") + << "sim audio (" << kSampleRate << " Hz, " << kChannels + << " ch), cam + sim frame (" << kWidth << "x" << kHeight << " / " + << kSimWidth << "x" << kSimHeight << ").\n"; // ----- SDL Mic capture (only when use_mic) ----- // SDLMicSource pulls 10ms frames from the default recording device and @@ -415,13 +415,13 @@ int main(int argc, char *argv[]) { [&mic](const int16_t *samples, int num_samples_per_channel, int /*sample_rate*/, int /*num_channels*/) { if (mic && !mic->pushFrame(samples, num_samples_per_channel)) { - LK_LOG_WARN("[robot] Mic track released."); + std::cerr << "[robot] Mic track released.\n"; } }); if (sdl_mic->init()) { mic_using_sdl = true; - LK_LOG_INFO("[robot] Using SDL microphone."); + std::cout << "[robot] Using SDL microphone.\n"; mic_thread = std::thread([&]() { while (mic_running.load()) { sdl_mic->pump(); @@ -429,13 +429,13 @@ int main(int argc, char *argv[]) { } }); } else { - LK_LOG_ERROR("[robot] SDL mic init failed."); + std::cerr << "[robot] SDL mic init failed.\n"; sdl_mic.reset(); } } if (!mic_using_sdl) { - LK_LOG_INFO("[robot] No microphone found; sending silence."); + std::cout << "[robot] No microphone found; sending silence.\n"; mic_thread = std::thread([&]() { const int kSamplesPerFrame = kSampleRate / 100; std::vector silence(kSamplesPerFrame * kChannels, 0); @@ -479,13 +479,13 @@ int main(int argc, char *argv[]) { if (!cam->pushFrame( buf.data(), buf.size(), static_cast(timestampNS / 1000))) { - LK_LOG_WARN("[robot] Cam track released."); + std::cerr << "[robot] Cam track released.\n"; } }); if (sdl_cam->init()) { cam_using_sdl = true; - LK_LOG_INFO("[robot] Using SDL camera."); + std::cout << "[robot] Using SDL camera.\n"; cam_thread = std::thread([&]() { while (cam_running.load()) { sdl_cam->pump(); @@ -493,13 +493,13 @@ int main(int argc, char *argv[]) { } }); } else { - LK_LOG_ERROR("[robot] SDL camera init failed."); + std::cerr << "[robot] SDL camera init failed.\n"; sdl_cam.reset(); } } if (!cam_using_sdl) { - LK_LOG_INFO("[robot] No camera found; sending solid green frames."); + std::cout << "[robot] No camera found; sending solid green frames.\n"; cam_thread = std::thread([&]() { std::vector green(kWidth * kHeight * 4); for (int i = 0; i < kWidth * kHeight; ++i) { @@ -575,7 +575,7 @@ int main(int argc, char *argv[]) { std::this_thread::sleep_for(std::chrono::milliseconds(33)); } }); - LK_LOG_INFO("[robot] Sim frame track started."); + std::cout << "[robot] Sim frame track started.\n"; // ----- Sim audio track (siren: sine sweep 600-1200 Hz, 1s period) ----- std::atomic sim_audio_running{true}; @@ -616,10 +616,10 @@ int main(int argc, char *argv[]) { std::this_thread::sleep_until(next); } }); - LK_LOG_INFO("[robot] Sim audio (siren) track started."); + std::cout << "[robot] Sim audio (siren) track started.\n"; // ----- Main loop: keep alive + pump SDL events ----- - LK_LOG_INFO("[robot] Streaming... press Ctrl-C to stop."); + std::cout << "[robot] Streaming... press Ctrl-C to stop.\n"; while (g_running.load()) { SDL_Event e; @@ -632,7 +632,7 @@ int main(int argc, char *argv[]) { } // ----- Cleanup ----- - LK_LOG_INFO("[robot] Shutting down..."); + std::cout << "[robot] Shutting down...\n"; mic_running.store(false); cam_running.store(false); @@ -656,6 +656,6 @@ int main(int argc, char *argv[]) { bridge.disconnect(); SDL_Quit(); - LK_LOG_INFO("[robot] Done."); + std::cout << "[robot] Done.\n"; return 0; } diff --git a/examples/common/sdl_media.cpp b/examples/common/sdl_media.cpp index d4a44e63..4961f513 100644 --- a/examples/common/sdl_media.cpp +++ b/examples/common/sdl_media.cpp @@ -16,7 +16,7 @@ #include "sdl_media.h" -#include "livekit/lk_log.h" +#include // ---------------------- SDLMicSource ----------------------------- @@ -48,12 +48,13 @@ bool SDLMicSource::init() { nullptr); if (!stream_) { - LK_LOG_ERROR("Failed to open recording stream: {}", SDL_GetError()); + std::cerr << "Failed to open recording stream: " << SDL_GetError() << "\n"; return false; } if (!SDL_ResumeAudioStreamDevice(stream_)) { // unpause device - LK_LOG_ERROR("Failed to resume recording device: {}", SDL_GetError()); + std::cerr << "Failed to resume recording device: " << SDL_GetError() + << "\n"; return false; } @@ -124,12 +125,12 @@ bool DDLSpeakerSink::init() { nullptr); if (!stream_) { - LK_LOG_ERROR("Failed to open playback stream: {}", SDL_GetError()); + std::cerr << "Failed to open playback stream: " << SDL_GetError() << "\n"; return false; } if (!SDL_ResumeAudioStreamDevice(stream_)) { - LK_LOG_ERROR("Failed to resume playback device: {}", SDL_GetError()); + std::cerr << "Failed to resume playback device: " << SDL_GetError() << "\n"; return false; } @@ -146,7 +147,7 @@ void DDLSpeakerSink::enqueue(const int16_t *samples, // SDL will resample / convert as needed on SDL_GetAudioStreamData() side. if (!SDL_PutAudioStreamData(stream_, samples, bytes)) { - LK_LOG_ERROR("SDL_PutAudioStreamData failed: {}", SDL_GetError()); + std::cerr << "SDL_PutAudioStreamData failed: " << SDL_GetError() << "\n"; } } @@ -181,7 +182,7 @@ bool SDLCamSource::init() { int count = 0; SDL_CameraID *cams = SDL_GetCameras(&count); // if (!cams || count == 0) { - LK_LOG_ERROR("No cameras available: {}", SDL_GetError()); + std::cerr << "No cameras available: " << SDL_GetError() << "\n"; if (cams) SDL_free(cams); return false; @@ -200,7 +201,7 @@ bool SDLCamSource::init() { camera_ = SDL_OpenCamera(camId, &spec_); if (!camera_) { - LK_LOG_ERROR("Failed to open camera: {}", SDL_GetError()); + std::cerr << "Failed to open camera: " << SDL_GetError() << "\n"; return false; } diff --git a/examples/common/sdl_media_manager.cpp b/examples/common/sdl_media_manager.cpp index f44c60ae..380334f2 100644 --- a/examples/common/sdl_media_manager.cpp +++ b/examples/common/sdl_media_manager.cpp @@ -18,10 +18,10 @@ #include "fallback_capture.h" #include "livekit/livekit.h" -#include "livekit/lk_log.h" #include "sdl_media.h" #include "sdl_video_renderer.h" #include +#include #include using namespace livekit; @@ -39,8 +39,8 @@ bool SDLMediaManager::ensureSDLInit(Uint32 flags) { return true; // already init } if (!SDL_InitSubSystem(flags)) { - LK_LOG_ERROR("SDL_InitSubSystem failed (flags={}): {}", flags, - SDL_GetError()); + std::cerr << "SDL_InitSubSystem failed (flags=" << flags + << "): " << SDL_GetError() << "\n"; return false; } return true; @@ -53,7 +53,7 @@ bool SDLMediaManager::startMic( stopMic(); if (!audio_source) { - LK_LOG_ERROR("startMic: audioSource is null"); + std::cerr << "startMic: audioSource is null\n"; return false; } @@ -62,7 +62,7 @@ bool SDLMediaManager::startMic( // Try SDL path if (!ensureSDLInit(SDL_INIT_AUDIO)) { - LK_LOG_WARN("No SDL audio, falling back to noise loop."); + std::cerr << "No SDL audio, falling back to noise loop.\n"; mic_using_sdl_ = false; mic_thread_ = std::thread(runNoiseCaptureLoop, mic_source_, std::ref(mic_running_)); @@ -72,7 +72,7 @@ bool SDLMediaManager::startMic( int recCount = 0; SDL_AudioDeviceID *recDevs = SDL_GetAudioRecordingDevices(&recCount); if (!recDevs || recCount == 0) { - LK_LOG_WARN("No microphone devices found, falling back to noise loop."); + std::cerr << "No microphone devices found, falling back to noise loop.\n"; if (recDevs) SDL_free(recDevs); mic_using_sdl_ = false; @@ -97,12 +97,12 @@ bool SDLMediaManager::startMic( try { src->captureFrame(frame); } catch (const std::exception &e) { - LK_LOG_ERROR("Error in captureFrame (SDL mic): {}", e.what()); + std::cerr << "Error in captureFrame (SDL mic): " << e.what() << "\n"; } }); if (!mic_sdl_->init()) { - LK_LOG_WARN("Failed to init SDL mic, falling back to noise loop."); + std::cerr << "Failed to init SDL mic, falling back to noise loop.\n"; mic_using_sdl_ = false; mic_sdl_.reset(); mic_thread_ = @@ -137,7 +137,7 @@ bool SDLMediaManager::startCamera( stopCamera(); if (!video_source) { - LK_LOG_ERROR("startCamera: videoSource is null"); + std::cerr << "startCamera: videoSource is null\n"; return false; } @@ -146,7 +146,7 @@ bool SDLMediaManager::startCamera( // Try SDL if (!ensureSDLInit(SDL_INIT_CAMERA)) { - LK_LOG_WARN("No SDL camera subsystem, using fake video loop."); + std::cerr << "No SDL camera subsystem, using fake video loop.\n"; cam_using_sdl_ = false; cam_thread_ = std::thread(runFakeVideoCaptureLoop, cam_source_, std::ref(cam_running_)); @@ -156,7 +156,7 @@ bool SDLMediaManager::startCamera( int camCount = 0; SDL_CameraID *cams = SDL_GetCameras(&camCount); if (!cams || camCount == 0) { - LK_LOG_WARN("No camera devices found, using fake video loop."); + std::cerr << "No camera devices found, using fake video loop.\n"; if (cams) SDL_free(cams); cam_using_sdl_ = false; @@ -186,12 +186,12 @@ bool SDLMediaManager::startCamera( src->captureFrame(frame, timestampNS / 1000, VideoRotation::VIDEO_ROTATION_0); } catch (const std::exception &e) { - LK_LOG_ERROR("Error in captureFrame (SDL cam): {}", e.what()); + std::cerr << "Error in captureFrame (SDL cam): " << e.what() << "\n"; } }); if (!can_sdl_->init()) { - LK_LOG_WARN("Failed to init SDL camera, using fake video loop."); + std::cerr << "Failed to init SDL camera, using fake video loop.\n"; cam_using_sdl_ = false; can_sdl_.reset(); cam_thread_ = std::thread(runFakeVideoCaptureLoop, cam_source_, @@ -226,12 +226,12 @@ bool SDLMediaManager::startSpeaker( stopSpeaker(); if (!audio_stream) { - LK_LOG_ERROR("startSpeaker: audioStream is null"); + std::cerr << "startSpeaker: audioStream is null\n"; return false; } if (!ensureSDLInit(SDL_INIT_AUDIO)) { - LK_LOG_ERROR("startSpeaker: SDL_INIT_AUDIO failed"); + std::cerr << "startSpeaker: SDL_INIT_AUDIO failed\n"; return false; } @@ -244,7 +244,8 @@ bool SDLMediaManager::startSpeaker( try { speaker_thread_ = std::thread(&SDLMediaManager::speakerLoopSDL, this); } catch (const std::exception &e) { - LK_LOG_ERROR("startSpeaker: failed to start speaker thread: {}", e.what()); + std::cerr << "startSpeaker: failed to start speaker thread: " << e.what() + << "\n"; speaker_running_.store(false, std::memory_order_relaxed); speaker_stream_.reset(); return false; @@ -288,8 +289,8 @@ void SDLMediaManager::speakerLoopSDL() { /*userdata=*/nullptr); if (!localStream) { - LK_LOG_ERROR("speakerLoopSDL: SDL_OpenAudioDeviceStream failed: {}", - SDL_GetError()); + std::cerr << "speakerLoopSDL: SDL_OpenAudioDeviceStream failed: " + << SDL_GetError() << "\n"; break; } @@ -297,14 +298,14 @@ void SDLMediaManager::speakerLoopSDL() { dev = SDL_GetAudioStreamDevice(localStream); if (dev == 0) { - LK_LOG_ERROR("speakerLoopSDL: SDL_GetAudioStreamDevice failed: {}", - SDL_GetError()); + std::cerr << "speakerLoopSDL: SDL_GetAudioStreamDevice failed: " + << SDL_GetError() << "\n"; break; } if (!SDL_ResumeAudioDevice(dev)) { - LK_LOG_ERROR("speakerLoopSDL: SDL_ResumeAudioDevice failed: {}", - SDL_GetError()); + std::cerr << "speakerLoopSDL: SDL_ResumeAudioDevice failed: " + << SDL_GetError() << "\n"; break; } } @@ -314,8 +315,8 @@ void SDLMediaManager::speakerLoopSDL() { const int numBytes = static_cast(data.size() * sizeof(std::int16_t)); if (!SDL_PutAudioStreamData(localStream, data.data(), numBytes)) { - LK_LOG_ERROR("speakerLoopSDL: SDL_PutAudioStreamData failed: {}", - SDL_GetError()); + std::cerr << "speakerLoopSDL: SDL_PutAudioStreamData failed: " + << SDL_GetError() << "\n"; break; } @@ -349,12 +350,12 @@ void SDLMediaManager::stopSpeaker() { bool SDLMediaManager::initRenderer( const std::shared_ptr &video_stream) { if (!video_stream) { - LK_LOG_ERROR("startRenderer: videoStream is null"); + std::cerr << "startRenderer: videoStream is null\n"; return false; } // Ensure SDL video subsystem is initialized if (!ensureSDLInit(SDL_INIT_VIDEO)) { - LK_LOG_ERROR("startRenderer: SDL_INIT_VIDEO failed"); + std::cerr << "startRenderer: SDL_INIT_VIDEO failed\n"; return false; } renderer_stream_ = video_stream; @@ -365,7 +366,7 @@ bool SDLMediaManager::initRenderer( sdl_renderer_ = std::make_unique(); // You can tune these dimensions or even make them options if (!sdl_renderer_->init("LiveKit Remote Video", 1280, 720)) { - LK_LOG_ERROR("startRenderer: SDLVideoRenderer::init failed"); + std::cerr << "startRenderer: SDLVideoRenderer::init failed\n"; sdl_renderer_.reset(); renderer_stream_.reset(); renderer_running_.store(false, std::memory_order_relaxed); diff --git a/examples/common/sdl_video_renderer.cpp b/examples/common/sdl_video_renderer.cpp index 5ba2cd72..7ba3a783 100644 --- a/examples/common/sdl_video_renderer.cpp +++ b/examples/common/sdl_video_renderer.cpp @@ -17,8 +17,8 @@ #include "sdl_video_renderer.h" #include "livekit/livekit.h" -#include "livekit/lk_log.h" #include +#include using namespace livekit; @@ -35,13 +35,13 @@ bool SDLVideoRenderer::init(const char *title, int width, int height) { // Assume SDL_Init(SDL_INIT_VIDEO) already called in main() window_ = SDL_CreateWindow(title, width_, height_, 0); if (!window_) { - LK_LOG_ERROR("SDL_CreateWindow failed: {}", SDL_GetError()); + std::cerr << "SDL_CreateWindow failed: " << SDL_GetError() << "\n"; return false; } renderer_ = SDL_CreateRenderer(window_, nullptr); if (!renderer_) { - LK_LOG_ERROR("SDL_CreateRenderer failed: {}", SDL_GetError()); + std::cerr << "SDL_CreateRenderer failed: " << SDL_GetError() << "\n"; return false; } @@ -50,7 +50,7 @@ bool SDLVideoRenderer::init(const char *title, int width, int height) { texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, width_, height_); if (!texture_) { - LK_LOG_ERROR("SDL_CreateTexture failed: {}", SDL_GetError()); + std::cerr << "SDL_CreateTexture failed: " << SDL_GetError() << "\n"; return false; } @@ -123,7 +123,8 @@ void SDLVideoRenderer::render() { try { frame = frame.convert(livekit::VideoBufferType::RGBA, false); } catch (const std::exception &ex) { - LK_LOG_ERROR("SDLVideoRenderer: convert to RGBA failed: {}", ex.what()); + std::cerr << "SDLVideoRenderer: convert to RGBA failed: " << ex.what() + << "\n"; return; } } @@ -143,8 +144,8 @@ void SDLVideoRenderer::render() { // compatible with Livekit RGBA format. SDL_TEXTUREACCESS_STREAMING, width_, height_); if (!texture_) { - LK_LOG_ERROR("SDLVideoRenderer: SDL_CreateTexture failed: {}", - SDL_GetError()); + std::cerr << "SDLVideoRenderer: SDL_CreateTexture failed: " + << SDL_GetError() << "\n"; return; } } @@ -153,8 +154,8 @@ void SDLVideoRenderer::render() { void *pixels = nullptr; int pitch = 0; if (!SDL_LockTexture(texture_, nullptr, &pixels, &pitch)) { - LK_LOG_ERROR("SDLVideoRenderer: SDL_LockTexture failed: {}", - SDL_GetError()); + std::cerr << "SDLVideoRenderer: SDL_LockTexture failed: " << SDL_GetError() + << "\n"; return; } diff --git a/examples/hello_livekit/receiver.cpp b/examples/hello_livekit/receiver.cpp index bc05e5f2..cc913879 100644 --- a/examples/hello_livekit/receiver.cpp +++ b/examples/hello_livekit/receiver.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include using namespace livekit; @@ -58,10 +59,10 @@ int main(int argc, char *argv[]) { } if (url.empty() || receiver_token.empty() || sender_identity.empty()) { - LK_LOG_ERROR("Usage: HelloLivekitReceiver " + std::cerr << "Usage: HelloLivekitReceiver " "\n" " or set LIVEKIT_URL, LIVEKIT_RECEIVER_TOKEN, " - "LIVEKIT_SENDER_IDENTITY"); + "LIVEKIT_SENDER_IDENTITY\n"; return 1; } @@ -78,7 +79,7 @@ int main(int argc, char *argv[]) { options.dynacast = false; if (!room->Connect(url, receiver_token, options)) { - LK_LOG_ERROR("[receiver] Failed to connect"); + std::cerr << "[receiver] Failed to connect\n"; livekit::shutdown(); return 1; } @@ -86,9 +87,10 @@ int main(int argc, char *argv[]) { LocalParticipant *lp = room->localParticipant(); assert(lp); - LK_LOG_INFO("[receiver] Connected as identity='{}' room='{}'; subscribing " - "to sender identity='{}'", - lp->identity(), room->room_info().name, sender_identity); + std::cout << "[receiver] Connected as identity='" << lp->identity() + << "' room='" << room->room_info().name + << "'; subscribing to sender identity='" << sender_identity + << "'\n"; int video_frame_count = 0; room->setOnVideoFrameCallback( @@ -98,8 +100,8 @@ int main(int argc, char *argv[]) { std::chrono::duration(timestamp_us).count(); const int n = video_frame_count++; if (n % 10 == 0) { - LK_LOG_INFO("[receiver] Video frame #{} {}x{} ts_ms={}", n, - frame.width(), frame.height(), ts_ms); + std::cout << "[receiver] Video frame #" << n << " " << frame.width() + << "x" << frame.height() << " ts_ms=" << ts_ms << "\n"; } }); @@ -110,19 +112,18 @@ int main(int argc, char *argv[]) { std::optional user_ts) { const int n = data_frame_count++; if (n % 10 == 0) { - LK_LOG_INFO("[receiver] Data frame #{}", n); + std::cout << "[receiver] Data frame #" << n << "\n"; } }); - LK_LOG_INFO("[receiver] Listening for video track '{}' + data track '{}'; " - "Ctrl-C to exit", - kVideoTrackName, kDataTrackName); + std::cout << "[receiver] Listening for video track '" << kVideoTrackName + << "' + data track '" << kDataTrackName << "'; Ctrl-C to exit\n"; while (g_running.load()) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); } - LK_LOG_INFO("[receiver] Shutting down"); + std::cout << "[receiver] Shutting down\n"; room.reset(); livekit::shutdown(); diff --git a/examples/hello_livekit/sender.cpp b/examples/hello_livekit/sender.cpp index 253091fd..c58dcd34 100644 --- a/examples/hello_livekit/sender.cpp +++ b/examples/hello_livekit/sender.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -59,8 +60,8 @@ int main(int argc, char *argv[]) { } if (url.empty() || sender_token.empty()) { - LK_LOG_ERROR("Usage: HelloLivekitSender \n" - " or set LIVEKIT_URL, LIVEKIT_SENDER_TOKEN"); + std::cerr << "Usage: HelloLivekitSender \n" + " or set LIVEKIT_URL, LIVEKIT_SENDER_TOKEN\n"; return 1; } @@ -77,7 +78,7 @@ int main(int argc, char *argv[]) { options.dynacast = false; if (!room->Connect(url, sender_token, options)) { - LK_LOG_ERROR("[sender] Failed to connect"); + std::cerr << "[sender] Failed to connect\n"; livekit::shutdown(); return 1; } @@ -85,9 +86,9 @@ int main(int argc, char *argv[]) { LocalParticipant *lp = room->localParticipant(); assert(lp); - LK_LOG_INFO("[sender] Connected as identity='{}' room='{}' — pass this " - "identity to HelloLivekitReceiver", - lp->identity(), room->room_info().name); + std::cout << "[sender] Connected as identity='" << lp->identity() + << "' room='" << room->room_info().name + << "' — pass this identity to HelloLivekitReceiver\n"; auto video_source = std::make_shared(kWidth, kHeight); @@ -97,8 +98,9 @@ int main(int argc, char *argv[]) { auto publish_result = lp->publishDataTrack(kDataTrackName); if (!publish_result) { const auto &error = publish_result.error(); - LK_LOG_ERROR("Failed to publish data track: code={} message={}", - static_cast(error.code), error.message); + std::cerr << "Failed to publish data track: code=" + << static_cast(error.code) + << " message=" << error.message << "\n"; room.reset(); livekit::shutdown(); return 1; @@ -108,9 +110,8 @@ int main(int argc, char *argv[]) { const auto t0 = std::chrono::steady_clock::now(); std::uint64_t count = 0; - LK_LOG_INFO( - "[sender] Publishing synthetic video + data on '{}'; Ctrl-C to exit", - kDataTrackName); + std::cout << "[sender] Publishing synthetic video + data on '" << kDataTrackName + << "'; Ctrl-C to exit\n"; while (g_running.load()) { VideoFrame vf = VideoFrame::create(kWidth, kHeight, VideoBufferType::RGBA); @@ -126,15 +127,16 @@ int main(int argc, char *argv[]) { data_track->tryPush(std::vector(msg.begin(), msg.end())); if (!push_result) { const auto &error = push_result.error(); - LK_LOG_WARN("Failed to push data frame: code={} message={}", - static_cast(error.code), error.message); + std::cerr << "Failed to push data frame: code=" + << static_cast(error.code) + << " message=" << error.message << "\n"; } ++count; std::this_thread::sleep_for(std::chrono::milliseconds(100)); } - LK_LOG_INFO("[sender] Disconnecting"); + std::cout << "[sender] Disconnecting\n"; room.reset(); livekit::shutdown(); diff --git a/examples/logging_levels/README.md b/examples/logging_levels/README.md index 546318b5..080ec9bc 100644 --- a/examples/logging_levels/README.md +++ b/examples/logging_levels/README.md @@ -61,6 +61,11 @@ Valid values: `TRACE`, `DEBUG`, `INFO`, `WARN`, `ERROR`, `CRITICAL`, `OFF`. Under the hood this sets `SPDLOG_ACTIVE_LEVEL`, which the `LK_LOG_*` macros check with a preprocessor guard before emitting any code. +`LoggingLevelsBasicUsage` links **spdlog** and includes the internal `lk_log.h` +header so it can call `LK_LOG_*` (same path as the SDK implementation). Other +examples use only the public `livekit::logging.h` API and normal application +logging (`std::cerr`, etc.). + ### 2. Runtime (`setLogLevel`) Among the levels that survived compilation, `setLogLevel()` controls which diff --git a/examples/logging_levels/basic_usage.cpp b/examples/logging_levels/basic_usage.cpp index 8c0b0314..02cdb474 100644 --- a/examples/logging_levels/basic_usage.cpp +++ b/examples/logging_levels/basic_usage.cpp @@ -35,12 +35,11 @@ /// see which messages are filtered at each setting. #include "livekit/livekit.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include #include #include -#include namespace { diff --git a/examples/ping_pong/ping.cpp b/examples/ping_pong/ping.cpp index c46f941c..a0a26b3b 100644 --- a/examples/ping_pong/ping.cpp +++ b/examples/ping_pong/ping.cpp @@ -21,7 +21,6 @@ #include "constants.h" #include "json_converters.h" #include "livekit/livekit.h" -#include "livekit/lk_log.h" #include "messages.h" #include "utils.h" @@ -29,6 +28,8 @@ #include #include #include +#include +#include #include #include #include @@ -82,8 +83,8 @@ int main(int argc, char *argv[]) { } if (url.empty() || token.empty()) { - LK_LOG_ERROR("LIVEKIT_URL and LIVEKIT_TOKEN (or ) are " - "required"); + std::cerr << "LIVEKIT_URL and LIVEKIT_TOKEN (or ) are " + "required\n"; return 1; } @@ -100,7 +101,7 @@ int main(int argc, char *argv[]) { options.dynacast = false; if (!room->Connect(url, token, options)) { - LK_LOG_ERROR("Failed to connect to room"); + std::cerr << "Failed to connect to room\n"; livekit::shutdown(); return 1; } @@ -108,15 +109,16 @@ int main(int argc, char *argv[]) { LocalParticipant *local_participant = room->localParticipant(); assert(local_participant); - LK_LOG_INFO("ping connected as identity='{}' room='{}'", - local_participant->identity(), room->room_info().name); + std::cout << "ping connected as identity='" << local_participant->identity() + << "' room='" << room->room_info().name << "'\n"; auto publish_result = local_participant->publishDataTrack(ping_pong::kPingTrackName); if (!publish_result) { const auto &error = publish_result.error(); - LK_LOG_ERROR("Failed to publish ping data track: code={} message={}", - static_cast(error.code), error.message); + std::cerr << "Failed to publish ping data track: code=" + << static_cast(error.code) + << " message=" << error.message << "\n"; room->setDelegate(nullptr); room.reset(); livekit::shutdown(); @@ -134,7 +136,6 @@ int main(int argc, char *argv[]) { std::optional /*user_timestamp*/) { try { if (payload.empty()) { - LK_LOG_DEBUG("Ignoring empty pong payload"); return; } @@ -147,8 +148,8 @@ int main(int argc, char *argv[]) { std::lock_guard lock(sent_messages_mutex); const auto it = sent_messages.find(pong_message.rec_id); if (it == sent_messages.end()) { - LK_LOG_WARN("Received pong for unknown id={}", - pong_message.rec_id); + std::cerr << "Received pong for unknown id=" << pong_message.rec_id + << "\n"; return; } ping_message = it->second; @@ -158,22 +159,21 @@ int main(int argc, char *argv[]) { const auto metrics = calculateLatencyMetrics( ping_message, pong_message, received_ts_ns); - LK_LOG_INFO("pong id={} rtt_ms={:.3f} " - "pong_to_ping_ms={:.3f} " - "ping_to_pong_and_processing_ms={:.3f} " - "estimated_one_way_latency_ms={:.3f}", - metrics.id, metrics.round_trip_time_ms, - metrics.pong_to_ping_time_ms, - metrics.ping_to_pong_and_processing_ms, - metrics.estimated_one_way_latency_ms); + std::cout << "pong id=" << metrics.id << " rtt_ms=" << std::fixed + << std::setprecision(3) << metrics.round_trip_time_ms + << " pong_to_ping_ms=" << metrics.pong_to_ping_time_ms + << " ping_to_pong_and_processing_ms=" + << metrics.ping_to_pong_and_processing_ms + << " estimated_one_way_latency_ms=" + << metrics.estimated_one_way_latency_ms << "\n"; } catch (const std::exception &e) { - LK_LOG_WARN("Failed to process pong payload: {}", e.what()); + std::cerr << "Failed to process pong payload: " << e.what() << "\n"; } }); - LK_LOG_INFO("published data track '{}' and listening for '{}' from '{}'", - ping_pong::kPingTrackName, ping_pong::kPongTrackName, - ping_pong::kPongParticipantIdentity); + std::cout << "published data track '" << ping_pong::kPingTrackName + << "' and listening for '" << ping_pong::kPongTrackName + << "' from '" << ping_pong::kPongParticipantIdentity << "'\n"; std::uint64_t next_id = 1; auto next_deadline = std::chrono::steady_clock::now(); @@ -187,22 +187,23 @@ int main(int argc, char *argv[]) { auto push_result = ping_track->tryPush(ping_pong::toPayload(json)); if (!push_result) { const auto &error = push_result.error(); - LK_LOG_WARN("Failed to push ping data frame: code={} message={}", - static_cast(error.code), error.message); + std::cerr << "Failed to push ping data frame: code=" + << static_cast(error.code) + << " message=" << error.message << "\n"; } else { { std::lock_guard lock(sent_messages_mutex); sent_messages.emplace(ping_message.id, ping_message); } - LK_LOG_INFO("sent ping id={} ts_ns={}", ping_message.id, - ping_message.ts_ns); + std::cout << "sent ping id=" << ping_message.id + << " ts_ns=" << ping_message.ts_ns << "\n"; } next_deadline += ping_pong::kPingPeriod; std::this_thread::sleep_until(next_deadline); } - LK_LOG_INFO("shutting down ping participant"); + std::cout << "shutting down ping participant\n"; room.reset(); livekit::shutdown(); return 0; diff --git a/examples/ping_pong/pong.cpp b/examples/ping_pong/pong.cpp index 34bdbd54..c7307978 100644 --- a/examples/ping_pong/pong.cpp +++ b/examples/ping_pong/pong.cpp @@ -20,7 +20,6 @@ #include "constants.h" #include "json_converters.h" #include "livekit/livekit.h" -#include "livekit/lk_log.h" #include "messages.h" #include "utils.h" @@ -28,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -54,8 +54,8 @@ int main(int argc, char *argv[]) { } if (url.empty() || token.empty()) { - LK_LOG_ERROR("LIVEKIT_URL and LIVEKIT_TOKEN (or ) are " - "required"); + std::cerr << "LIVEKIT_URL and LIVEKIT_TOKEN (or ) are " + "required\n"; return 1; } @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) { options.dynacast = false; if (!room->Connect(url, token, options)) { - LK_LOG_ERROR("Failed to connect to room"); + std::cerr << "Failed to connect to room\n"; livekit::shutdown(); return 1; } @@ -80,15 +80,16 @@ int main(int argc, char *argv[]) { LocalParticipant *local_participant = room->localParticipant(); assert(local_participant); - LK_LOG_INFO("pong connected as identity='{}' room='{}'", - local_participant->identity(), room->room_info().name); + std::cout << "pong connected as identity='" << local_participant->identity() + << "' room='" << room->room_info().name << "'\n"; auto publish_result = local_participant->publishDataTrack(ping_pong::kPongTrackName); if (!publish_result) { const auto &error = publish_result.error(); - LK_LOG_ERROR("Failed to publish pong data track: code={} message={}", - static_cast(error.code), error.message); + std::cerr << "Failed to publish pong data track: code=" + << static_cast(error.code) + << " message=" << error.message << "\n"; room->setDelegate(nullptr); room.reset(); livekit::shutdown(); @@ -103,7 +104,6 @@ int main(int argc, char *argv[]) { std::optional /*user_timestamp*/) { try { if (payload.empty()) { - LK_LOG_DEBUG("Ignoring empty ping payload"); return; } @@ -118,29 +118,30 @@ int main(int argc, char *argv[]) { auto push_result = pong_track->tryPush(ping_pong::toPayload(json)); if (!push_result) { const auto &error = push_result.error(); - LK_LOG_WARN("Failed to push pong data frame: code={} message={}", - static_cast(error.code), error.message); + std::cerr << "Failed to push pong data frame: code=" + << static_cast(error.code) + << " message=" << error.message << "\n"; return; } - LK_LOG_INFO("received ping id={} ts_ns={} and sent pong rec_id={} " - "ts_ns={}", - ping_message.id, ping_message.ts_ns, pong_message.rec_id, - pong_message.ts_ns); + std::cout << "received ping id=" << ping_message.id + << " ts_ns=" << ping_message.ts_ns << " and sent pong rec_id=" + << pong_message.rec_id << " ts_ns=" << pong_message.ts_ns + << "\n"; } catch (const std::exception &e) { - LK_LOG_WARN("Failed to process ping payload: {}", e.what()); + std::cerr << "Failed to process ping payload: " << e.what() << "\n"; } }); - LK_LOG_INFO("published data track '{}' and listening for '{}' from '{}'", - ping_pong::kPongTrackName, ping_pong::kPingTrackName, - ping_pong::kPingParticipantIdentity); + std::cout << "published data track '" << ping_pong::kPongTrackName + << "' and listening for '" << ping_pong::kPingTrackName + << "' from '" << ping_pong::kPingParticipantIdentity << "'\n"; while (g_running.load()) { std::this_thread::sleep_for(ping_pong::kPollPeriod); } - LK_LOG_INFO("shutting down pong participant"); + std::cout << "shutting down pong participant\n"; room.reset(); livekit::shutdown(); return 0; diff --git a/examples/simple_room/fallback_capture.cpp b/examples/simple_room/fallback_capture.cpp index 26269886..40f6194c 100644 --- a/examples/simple_room/fallback_capture.cpp +++ b/examples/simple_room/fallback_capture.cpp @@ -48,7 +48,7 @@ void runNoiseCaptureLoop(const std::shared_ptr &source, try { source->captureFrame(frame); } catch (const std::exception &e) { - LK_LOG_ERROR("Error in captureFrame (noise): {}", e.what()); + std::cerr << "Error in captureFrame (noise): " << e.what() << "\n"; break; } @@ -60,7 +60,7 @@ void runNoiseCaptureLoop(const std::shared_ptr &source, try { source->clearQueue(); } catch (...) { - LK_LOG_WARN("Error in clearQueue (noise)"); + std::cerr << "Error in clearQueue (noise)\n"; } } @@ -110,7 +110,7 @@ void runFakeVideoCaptureLoop(const std::shared_ptr &source, // If it expects I420, pass i420 instead. source->captureFrame(frame, 0, VideoRotation::VIDEO_ROTATION_0); } catch (const std::exception &e) { - LK_LOG_ERROR("Error in captureFrame (fake video): {}", e.what()); + std::cerr << "Error in captureFrame (fake video): " << e.what() << "\n"; break; } diff --git a/examples/simple_room/main.cpp b/examples/simple_room/main.cpp index bd7c6abc..717519a9 100644 --- a/examples/simple_room/main.cpp +++ b/examples/simple_room/main.cpp @@ -204,13 +204,14 @@ class SimpleRoomDelegate : public livekit::RoomDelegate { opts.format = livekit::VideoBufferType::RGBA; auto video_stream = VideoStream::fromTrack(ev.track, opts); if (!video_stream) { - LK_LOG_ERROR("Failed to create VideoStream for track {}", track_sid); + std::cerr << "Failed to create VideoStream for track " << track_sid + << "\n"; return; } MainThreadDispatcher::dispatch([this, video_stream] { if (!media_.initRenderer(video_stream)) { - LK_LOG_ERROR("SDLMediaManager::startRenderer failed for track"); + std::cerr << "SDLMediaManager::startRenderer failed for track\n"; } }); } else if (ev.track && ev.track->kind() == TrackKind::KIND_AUDIO) { @@ -218,7 +219,7 @@ class SimpleRoomDelegate : public livekit::RoomDelegate { auto audio_stream = AudioStream::fromTrack(ev.track, opts); MainThreadDispatcher::dispatch([this, audio_stream] { if (!media_.startSpeaker(audio_stream)) { - LK_LOG_ERROR("SDLMediaManager::startSpeaker failed for track"); + std::cerr << "SDLMediaManager::startSpeaker failed for track\n"; } }); } @@ -257,7 +258,7 @@ int main(int argc, char *argv[]) { } if (!SDL_Init(SDL_INIT_VIDEO)) { - LK_LOG_ERROR("SDL_Init(SDL_INIT_VIDEO) failed: {}", SDL_GetError()); + std::cerr << "SDL_Init(SDL_INIT_VIDEO) failed: " << SDL_GetError() << "\n"; // You can choose to exit, or run in "headless" mode without renderer. // return 1; } @@ -300,7 +301,7 @@ int main(int argc, char *argv[]) { bool res = room->Connect(url, token, options); std::cout << "Connect result is " << std::boolalpha << res << std::endl; if (!res) { - LK_LOG_ERROR("Failed to connect to room"); + std::cerr << "Failed to connect to room\n"; livekit::shutdown(); return 1; } @@ -345,7 +346,7 @@ int main(int argc, char *argv[]) { << "\n" << " Muted: " << std::boolalpha << audioPub->muted() << "\n"; } catch (const std::exception &e) { - LK_LOG_ERROR("Failed to publish track: {}", e.what()); + std::cerr << "Failed to publish track: " << e.what() << "\n"; } media.startMic(audioSource); @@ -374,7 +375,7 @@ int main(int argc, char *argv[]) { << "\n" << " Muted: " << std::boolalpha << videoPub->muted() << "\n"; } catch (const std::exception &e) { - LK_LOG_ERROR("Failed to publish track: {}", e.what()); + std::cerr << "Failed to publish track: " << e.what() << "\n"; } media.startCamera(videoSource); diff --git a/include/livekit/livekit.h b/include/livekit/livekit.h index 7d055725..d6f3ec01 100644 --- a/include/livekit/livekit.h +++ b/include/livekit/livekit.h @@ -22,7 +22,6 @@ #include "audio_stream.h" #include "build.h" #include "e2ee.h" -#include "lk_log.h" #include "local_audio_track.h" #include "local_participant.h" #include "local_track_publication.h" diff --git a/src/audio_source.cpp b/src/audio_source.cpp index bc648e50..4e1a48a1 100644 --- a/src/audio_source.cpp +++ b/src/audio_source.cpp @@ -24,7 +24,7 @@ #include "ffi.pb.h" #include "ffi_client.h" #include "livekit/audio_frame.h" -#include "livekit/lk_log.h" +#include "lk_log.h" namespace livekit { diff --git a/src/data_stream.cpp b/src/data_stream.cpp index 9841a902..4db13120 100644 --- a/src/data_stream.cpp +++ b/src/data_stream.cpp @@ -6,7 +6,7 @@ #include #include "ffi_client.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include "livekit/local_participant.h" #include "room.pb.h" diff --git a/src/data_track_stream.cpp b/src/data_track_stream.cpp index 7a0a6d30..4a23d74d 100644 --- a/src/data_track_stream.cpp +++ b/src/data_track_stream.cpp @@ -19,7 +19,7 @@ #include "data_track.pb.h" #include "ffi.pb.h" #include "ffi_client.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include diff --git a/src/ffi_client.cpp b/src/ffi_client.cpp index e431fa5d..9c206911 100644 --- a/src/ffi_client.cpp +++ b/src/ffi_client.cpp @@ -24,7 +24,7 @@ #include "livekit/data_track_error.h" #include "livekit/e2ee.h" #include "livekit/ffi_handle.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include "livekit/room.h" #include "livekit/rpc_error.h" #include "livekit/track.h" diff --git a/src/livekit.cpp b/src/livekit.cpp index 86b9ebd6..b9132efc 100644 --- a/src/livekit.cpp +++ b/src/livekit.cpp @@ -16,7 +16,7 @@ #include "livekit/livekit.h" #include "ffi_client.h" -#include "livekit/lk_log.h" +#include "lk_log.h" namespace livekit { diff --git a/include/livekit/lk_log.h b/src/lk_log.h similarity index 100% rename from include/livekit/lk_log.h rename to src/lk_log.h diff --git a/src/local_data_track.cpp b/src/local_data_track.cpp index 3d183699..d0cc8e42 100644 --- a/src/local_data_track.cpp +++ b/src/local_data_track.cpp @@ -17,7 +17,7 @@ #include "livekit/local_data_track.h" #include "livekit/data_track_error.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include "data_track.pb.h" #include "ffi.pb.h" diff --git a/src/room.cpp b/src/room.cpp index 0ee28ba7..919e126d 100644 --- a/src/room.cpp +++ b/src/room.cpp @@ -32,7 +32,7 @@ #include "data_track.pb.h" #include "ffi.pb.h" #include "ffi_client.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include "livekit_ffi.h" #include "room.pb.h" #include "room_proto_converter.h" diff --git a/src/subscription_thread_dispatcher.cpp b/src/subscription_thread_dispatcher.cpp index 1a32bc56..ee683650 100644 --- a/src/subscription_thread_dispatcher.cpp +++ b/src/subscription_thread_dispatcher.cpp @@ -18,7 +18,7 @@ #include "livekit/data_track_frame.h" #include "livekit/data_track_stream.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include "livekit/remote_data_track.h" #include "livekit/track.h" diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 1b9695eb..1ca804d3 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -41,6 +41,7 @@ if(INTEGRATION_TEST_SOURCES) target_link_libraries(livekit_integration_tests PRIVATE livekit + spdlog::spdlog GTest::gtest_main GTest::gmock ) diff --git a/src/tests/integration/test_logging.cpp b/src/tests/integration/test_logging.cpp index 5ccb0fa1..88e16166 100644 --- a/src/tests/integration/test_logging.cpp +++ b/src/tests/integration/test_logging.cpp @@ -17,7 +17,7 @@ #include #include -#include "livekit/lk_log.h" +#include "lk_log.h" #include #include diff --git a/src/video_frame.cpp b/src/video_frame.cpp index 271c5ce5..5fdc83e2 100644 --- a/src/video_frame.cpp +++ b/src/video_frame.cpp @@ -6,7 +6,7 @@ #include #include "livekit/ffi_handle.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include "video_utils.h" namespace livekit { diff --git a/src/video_stream.cpp b/src/video_stream.cpp index 657d4db1..ed65da9e 100644 --- a/src/video_stream.cpp +++ b/src/video_stream.cpp @@ -4,7 +4,7 @@ #include "ffi.pb.h" #include "ffi_client.h" -#include "livekit/lk_log.h" +#include "lk_log.h" #include "livekit/track.h" #include "video_frame.pb.h" #include "video_utils.h"