LiveKit C++ Client SDK v1.1.0
Real-time audio/video/data SDK for C++
Loading...
Searching...
No Matches
livekit::LocalAudioTrack Class Reference

Represents a user-provided audio track sourced from the local device. More...

#include <local_audio_track.h>

Inheritance diagram for livekit::LocalAudioTrack:
Collaboration diagram for livekit::LocalAudioTrack:

Public Member Functions

void mute ()
 Mutes the audio track.
 
void unmute ()
 Unmute the audio track.
 
std::string toString () const
 Return a human-readable string representation of the track.
 
std::shared_ptr< LocalTrackPublicationpublication () const noexcept
 Returns the publication that owns this track, or nullptr if the track is not published.
 
void setPublication (const std::shared_ptr< LocalTrackPublication > &publication) noexcept override
 Set the publication that owns this track.
 
- Public Member Functions inherited from livekit::Track
const std::string & sid () const noexcept
 
const std::string & name () const noexcept
 
TrackKind kind () const noexcept
 
StreamState streamState () const noexcept
 
bool muted () const noexcept
 
bool remote () const noexcept
 
std::optional< TrackSourcesource () const noexcept
 
std::optional< bool > simulcasted () const noexcept
 
std::optional< uint32_t > width () const noexcept
 
std::optional< uint32_t > height () const noexcept
 
std::optional< std::string > mimeType () const noexcept
 
bool hasHandle () const noexcept
 
uintptr_t ffiHandleId () const noexcept
 
std::future< std::vector< RtcStats > > getStats () const
 
void setStreamState (StreamState s) noexcept
 
void setMuted (bool m) noexcept
 
void setName (std::string n) noexcept
 

Static Public Member Functions

static std::shared_ptr< LocalAudioTrackcreateLocalAudioTrack (const std::string &name, const std::shared_ptr< AudioSource > &source)
 Creates a new local audio track backed by the given AudioSource.
 
static std::shared_ptr< LocalAudioTrackcreateLocalAudioTrack (const std::string &name, const std::shared_ptr< PlatformAudioSource > &source)
 Creates a new local audio track backed by the given PlatformAudioSource.
 

Additional Inherited Members

- Protected Member Functions inherited from livekit::Track
 Track (FfiHandle handle, std::string sid, std::string name, TrackKind kind, StreamState state, bool muted, bool remote)
 
void setPublicationFields (std::optional< TrackSource > source, std::optional< bool > simulcasted, std::optional< uint32_t > width, std::optional< uint32_t > height, std::optional< std::string > mime_type)
 

Detailed Description

Represents a user-provided audio track sourced from the local device.

LocalAudioTrack is used to publish microphone audio or any custom audio source to a LiveKit room. It wraps a platform-specific audio source and exposes simple controls such as mute() and unmute(). Muting a local audio track stops transmitting audio to the room, but the underlying source may continue capturing depending on platform behavior.

Typical usage:

auto source = AudioSource::create(...); auto track = LocalAudioTrack::createLocalAudioTrack("mic", source); if (auto lp = room->localParticipant().lock()) { lp->publishTrack(track); }

Muting a local audio track stops transmitting audio to the room, but the underlying source may continue capturing depending on platform behavior.

The track name provided during creation is visible to remote participants and can be used for debugging or UI display.

Member Function Documentation

◆ createLocalAudioTrack() [1/2]

static std::shared_ptr< LocalAudioTrack > livekit::LocalAudioTrack::createLocalAudioTrack ( const std::string &  name,
const std::shared_ptr< AudioSource > &  source 
)
static

Creates a new local audio track backed by the given AudioSource.

Parameters
nameHuman-readable name for the track. This may appear to remote participants and in analytics/debug logs.
sourceThe audio source that produces PCM frames for this track. The caller retains ownership and should use this source directly for frame capture.
Returns
A shared pointer to the newly constructed LocalAudioTrack.
Exceptions
std::invalid_argumentIf source is null.
std::runtime_errorIf the FFI request fails.

◆ createLocalAudioTrack() [2/2]

static std::shared_ptr< LocalAudioTrack > livekit::LocalAudioTrack::createLocalAudioTrack ( const std::string &  name,
const std::shared_ptr< PlatformAudioSource > &  source 
)
static

Creates a new local audio track backed by the given PlatformAudioSource.

Parameters
nameHuman-readable name for the track. This may appear to remote participants and in analytics/debug logs.
sourceThe platform source that captures microphone audio automatically through WebRTC's Audio Device Module.
Returns
A shared pointer to the newly constructed LocalAudioTrack.
Exceptions
std::invalid_argumentIf source is null.
std::runtime_errorIf the FFI request fails.
Note
This operation is not thread-safe.

◆ mute()

void livekit::LocalAudioTrack::mute ( )

Mutes the audio track.

A muted track stops sending audio to the room, but the track remains published and can be unmuted later without renegotiation.

Exceptions
std::runtime_errorIf the FFI request fails.

◆ setPublication()

void livekit::LocalAudioTrack::setPublication ( const std::shared_ptr< LocalTrackPublication > &  publication)
inlineoverridevirtualnoexcept

Set the publication that owns this track.

Parameters
publicationPublication that owns this track, or nullptr to clear the association.

Reimplemented from livekit::Track.

◆ toString()

std::string livekit::LocalAudioTrack::toString ( ) const

Return a human-readable string representation of the track.

Returns
String containing the track SID and name.

◆ unmute()

void livekit::LocalAudioTrack::unmute ( )

Unmute the audio track.

Resumes sending audio to the room.

Exceptions
std::runtime_errorIf the FFI request fails.

The documentation for this class was generated from the following file: