Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ add_library(livekit
include/livekit/audio_source.h
include/livekit/audio_stream.h
include/livekit/room.h
include/livekit/room_event_types.h
include/livekit/room_delegate.h
include/livekit/ffi_handle.h
include/livekit/ffi_client.h
Expand Down
12 changes: 6 additions & 6 deletions examples/simple_room/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,9 @@ class SimpleRoomDelegate : public livekit::RoomDelegate {
void onParticipantConnected(
livekit::Room & /*room*/,
const livekit::ParticipantConnectedEvent &ev) override {
std::cout << "[Room] participant connected: identity=" << ev.identity
<< " name=" << ev.name << "\n";
std::cout << "[Room] participant connected: identity="
<< ev.participant->identity()
<< " name=" << ev.participant->name() << "\n";
}

void onTrackSubscribed(livekit::Room & /*room*/,
Expand All @@ -172,19 +173,18 @@ class SimpleRoomDelegate : public livekit::RoomDelegate {
<< participant_identity << " track_sid=" << track_sid
<< " name=" << track_name;
if (ev.track) {
std::cout << " kind=" << static_cast<int>(ev.track->kind()) << "\n";
std::cout << " kind=" << static_cast<int>(ev.track->kind());
}
if (ev.publication) {
std::cout << " source=" << static_cast<int>(ev.publication->source())
<< "\n";
std::cout << " source=" << static_cast<int>(ev.publication->source());
}
std::cout << std::endl;

// If this is a VIDEO track, create a VideoStream and attach to renderer
if (ev.track && ev.track->kind() == TrackKind::KIND_VIDEO) {
VideoStream::Options opts;
opts.format = livekit::VideoBufferType::RGBA;
auto video_stream = VideoStream::fromTrack(ev.track, opts);
std::cout << "after fromTrack " << std::endl;
if (!video_stream) {
std::cerr << "Failed to create VideoStream for track " << track_sid
<< "\n";
Expand Down
1 change: 1 addition & 0 deletions include/livekit/audio_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AudioFrame {
AudioFrame(std::vector<std::int16_t> data, int sample_rate, int num_channels,
int samples_per_channel);
AudioFrame(); // Default constructor
virtual ~AudioFrame() = default;

/**
* Create a new zero-initialized AudioFrame instance.
Expand Down
3 changes: 1 addition & 2 deletions include/livekit/audio_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class AudioSource {
* @param queue_size_ms Max buffer duration for the internal queue in ms.
*/
AudioSource(int sample_rate, int num_channels, int queue_size_ms = 1000);

~AudioSource();
virtual ~AudioSource() = default;

AudioSource(const AudioSource &) = delete;
AudioSource &operator=(const AudioSource &) = delete;
Expand Down
2 changes: 1 addition & 1 deletion include/livekit/audio_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class AudioStream {
TrackSource track_source,
const Options &options);

~AudioStream();
virtual ~AudioStream();

/// No copy, assignment constructors.
AudioStream(const AudioStream &) = delete;
Expand Down
1 change: 1 addition & 0 deletions include/livekit/livekit.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "remote_track_publication.h"
#include "room.h"
#include "room_delegate.h"
#include "room_event_types.h"
#include "track_publication.h"
#include "video_frame.h"
#include "video_source.h"
Expand Down
5 changes: 4 additions & 1 deletion include/livekit/local_participant.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#include "livekit/ffi_handle.h"
#include "livekit/participant.h"
#include "livekit/room_delegate.h"
#include "livekit/room_event_types.h"
#include "livekit/rpc_error.h"

#include <cstdint>
Expand Down Expand Up @@ -203,6 +203,9 @@ class LocalParticipant : public Participant {
const std::string &caller_identity,
const std::string &payload,
double response_timeout);
// Called by Room events like kTrackMuted.
std::shared_ptr<TrackPublication>
findTrackPublication(const std::string &sid) const override;
friend class Room;

private:
Expand Down
6 changes: 6 additions & 0 deletions include/livekit/participant.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Participant {
name_(std::move(name)), identity_(std::move(identity)),
metadata_(std::move(metadata)), attributes_(std::move(attributes)),
kind_(kind), reason_(reason) {}
virtual ~Participant() = default;

// Plain getters (caller ensures threading)
const std::string &sid() const noexcept { return sid_; }
Expand Down Expand Up @@ -72,6 +73,11 @@ class Participant {
reason_ = reason;
}

protected:
virtual std::shared_ptr<TrackPublication>
findTrackPublication(const std::string &sid) const = 0;
friend class Room;

private:
FfiHandle handle_;
std::string sid_, name_, identity_, metadata_;
Expand Down
15 changes: 11 additions & 4 deletions include/livekit/remote_participant.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RemoteTrackPublication;

class RemoteParticipant : public Participant {
public:
using TrackPublicationMap =
using PublicationMap =
std::unordered_map<std::string, std::shared_ptr<RemoteTrackPublication>>;

RemoteParticipant(FfiHandle handle, std::string sid, std::string name,
Expand All @@ -37,20 +37,27 @@ class RemoteParticipant : public Participant {
ParticipantKind kind, DisconnectReason reason);

// A dictionary of track publications associated with the participant.
const TrackPublicationMap &track_publications() const noexcept {
const PublicationMap &trackPublications() const noexcept {
return track_publications_;
}

// Optional: non-const access if you want to mutate in-place.
TrackPublicationMap &mutable_track_publications() noexcept {
PublicationMap &mutableTrackPublications() noexcept {
return track_publications_;
}

// C++ equivalent of Python's __repr__
std::string to_string() const;

protected:
// Called by Room events like kTrackMuted. This is internal plumbing and not
// intended to be called directly by SDK users.
std::shared_ptr<TrackPublication>
findTrackPublication(const std::string &sid) const override;
friend class Room;

private:
TrackPublicationMap track_publications_;
PublicationMap track_publications_;
};

// Convenience for logging / streaming
Expand Down
3 changes: 2 additions & 1 deletion include/livekit/room.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include "livekit/ffi_client.h"
#include "livekit/ffi_handle.h"
#include "livekit/room_delegate.h"
#include "livekit/room_event_types.h"
#include <memory>
#include <mutex>

Expand Down Expand Up @@ -185,6 +185,7 @@ class Room {
std::unique_ptr<LocalParticipant> local_participant_;
std::unordered_map<std::string, std::shared_ptr<RemoteParticipant>>
remote_participants_;
ConnectionState connection_state_ = ConnectionState::Disconnected;

void OnEvent(const proto::FfiEvent &event);
};
Expand Down
Loading
Loading