diff --git a/include/livekit/room.h b/include/livekit/room.h index faffa715..382006bb 100644 --- a/include/livekit/room.h +++ b/include/livekit/room.h @@ -22,12 +22,14 @@ #include #include +#include "livekit/audio_stream.h" #include "livekit/data_stream.h" #include "livekit/e2ee.h" #include "livekit/ffi_handle.h" +#include "livekit/room_callbacks.h" #include "livekit/room_event_types.h" #include "livekit/stats.h" -#include "livekit/subscription_thread_dispatcher.h" +#include "livekit/video_stream.h" #include "livekit/visibility.h" namespace livekit { @@ -42,6 +44,7 @@ struct E2EEOptions; class E2EEManager; class LocalParticipant; class RemoteParticipant; +class SubscriptionThreadDispatcher; /// Represents a single ICE server configuration. struct IceServer { diff --git a/include/livekit/room_callbacks.h b/include/livekit/room_callbacks.h new file mode 100644 index 00000000..cca435f7 --- /dev/null +++ b/include/livekit/room_callbacks.h @@ -0,0 +1,46 @@ +/* + * Copyright 2026 LiveKit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include +#include + +namespace livekit { + +class AudioFrame; +class VideoFrame; +struct VideoFrameEvent; + +/// @brief Callback for incoming audio frames on a subscription reader thread. +using AudioFrameCallback = std::function; + +/// @brief Callback for incoming video frames on a subscription reader thread. +using VideoFrameCallback = std::function; + +/// @brief Callback for incoming video frame events on a subscription reader thread. +using VideoFrameEventCallback = std::function; + +/// @brief Callback for incoming data frames on a subscription reader thread. +using DataFrameCallback = + std::function& payload, std::optional user_timestamp)>; + +/// @brief Identifier for a data frame callback registration. +using DataFrameCallbackId = std::uint64_t; + +} // namespace livekit diff --git a/src/room.cpp b/src/room.cpp index 8277cf36..f37c5642 100644 --- a/src/room.cpp +++ b/src/room.cpp @@ -32,6 +32,7 @@ #include "lk_log.h" #include "room.pb.h" #include "room_proto_converter.h" +#include "subscription_thread_dispatcher.h" #include "trace/trace_event.h" #include "track.pb.h" #include "track_proto_converter.h" diff --git a/src/subscription_thread_dispatcher.cpp b/src/subscription_thread_dispatcher.cpp index ed77d0be..654bea45 100644 --- a/src/subscription_thread_dispatcher.cpp +++ b/src/subscription_thread_dispatcher.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "livekit/subscription_thread_dispatcher.h" +#include "subscription_thread_dispatcher.h" #include #include diff --git a/include/livekit/subscription_thread_dispatcher.h b/src/subscription_thread_dispatcher.h similarity index 92% rename from include/livekit/subscription_thread_dispatcher.h rename to src/subscription_thread_dispatcher.h index 73c86684..10df2fe3 100644 --- a/include/livekit/subscription_thread_dispatcher.h +++ b/src/subscription_thread_dispatcher.h @@ -27,6 +27,7 @@ #include #include "livekit/audio_stream.h" +#include "livekit/room_callbacks.h" #include "livekit/video_stream.h" #include "livekit/visibility.h" @@ -38,29 +39,6 @@ class RemoteDataTrack; class Track; class VideoFrame; -/// Callback type for incoming audio frames. -/// Invoked on a dedicated reader thread per (participant, track_name) pair. -using AudioFrameCallback = std::function; - -/// Callback type for incoming video frames. -/// Invoked on a dedicated reader thread per (participant, track_name) pair. -using VideoFrameCallback = std::function; - -/// Callback type for incoming video frame events. -/// Invoked on a dedicated reader thread per (participant, track_name) pair. -using VideoFrameEventCallback = std::function; - -/// Callback type for incoming data track frames. -/// Invoked on a dedicated reader thread per subscription. -/// @param payload Raw binary data received. -/// @param user_timestamp Optional application-defined timestamp from sender. -using DataFrameCallback = - std::function& payload, std::optional user_timestamp)>; - -/// Opaque identifier returned by addOnDataFrameCallback, used to remove an -/// individual subscription via removeOnDataFrameCallback. -using DataFrameCallbackId = std::uint64_t; - /// Owns subscription callback registration and per-subscription reader threads. /// /// `SubscriptionThreadDispatcher` is the low-level companion to @ref Room's @@ -81,7 +59,7 @@ using DataFrameCallbackId = std::uint64_t; /// The design keeps track-type-specific startup isolated so additional track /// kinds can be added later without pushing more thread state back into /// @ref Room. -class LIVEKIT_API SubscriptionThreadDispatcher { +class LIVEKIT_INTERNAL_API SubscriptionThreadDispatcher { public: /// Constructs an empty dispatcher with no registered callbacks or readers. SubscriptionThreadDispatcher(); diff --git a/src/tests/unit/test_subscription_thread_dispatcher.cpp b/src/tests/unit/test_subscription_thread_dispatcher.cpp index 80b52120..32cdf26a 100644 --- a/src/tests/unit/test_subscription_thread_dispatcher.cpp +++ b/src/tests/unit/test_subscription_thread_dispatcher.cpp @@ -24,6 +24,8 @@ #include #include +#include "subscription_thread_dispatcher.h" + namespace livekit { class SubscriptionThreadDispatcherTest : public ::testing::Test {