WebRTC module

WebRtcTrackSender

[PacketProcessor]({#ref classicy_1_1PacketProcessor #}) that sends encoded media to a single libdatachannel Track via sendFrame().

WebRtcTrackSender

#include <icy/webrtc/tracksender.h>

Inherits: PacketProcessor

PacketProcessor that sends encoded media to a single libdatachannel Track via sendFrame().

Bind to one track (video or audio). Accepts the corresponding packet type from the PacketStream and converts timestamps from FFmpeg microseconds to the track's RTP clock rate.

Usage: auto vh = createVideoTrack(pc, codec); WebRtcTrackSender videoSender(vh);

PacketStream stream; stream.attachSource(capture); stream.attach(encoder, 1, true); stream.attach(&videoSender, 5, false); stream.start();

Only emits the packet downstream on successful send, so a chained recorder won't record frames that failed to transmit.

Accepts only the packet type that matches the bound track. Non-matching packets are passed through unchanged so mixed audio/video PacketStream chains can share one source cleanly.

Public Attributes

ReturnNameDescription
PacketSignalemitter

emitter

PacketSignal emitter

Public Methods

ReturnNameDescription
WebRtcTrackSenderConstruct an unbound sender. Call bind() before use.
WebRtcTrackSender explicitConstruct bound to a track handle from createVideoTrack() or createAudioTrack().
voidbindBind to a track. Can be called to rebind to a different track.
voidunbindUnbind from the current track.
voidprocess virtualSend an encoded media frame to the bound WebRTC track. Converts the FFmpeg microsecond timestamp to an RTP timestamp using the track's clock rate, then calls rtc::Track::sendFrame(). Only forwards the packet downstream on a successful send.
boolaccepts virtualReturn true only for the packet type that matches the bound track.
voidonStreamStateChange virtualCalled by the PacketStream when stream state changes. Logs when the stream is stopping; no other action is taken.
boolisVideo constTrue if this sender is bound to a video track.
boolbound constTrue if bound to any track.

WebRtcTrackSender

WebRtcTrackSender()

Construct an unbound sender. Call bind() before use.


WebRtcTrackSender

explicit

explicit WebRtcTrackSender(const TrackHandle & handle)

Construct bound to a track handle from createVideoTrack() or createAudioTrack().


bind

void bind(const TrackHandle & handle)

Bind to a track. Can be called to rebind to a different track.


unbind

void unbind()

Unbind from the current track.


process

virtual

virtual void process(IPacket & packet)

Send an encoded media frame to the bound WebRTC track. Converts the FFmpeg microsecond timestamp to an RTP timestamp using the track's clock rate, then calls rtc::Track::sendFrame(). Only forwards the packet downstream on a successful send.

Parameters


accepts

virtual

virtual bool accepts(IPacket * packet)

Return true only for the packet type that matches the bound track.

Parameters

  • packet Packet to test. May be nullptr.

Returns

True if the packet can be processed by this sender.


onStreamStateChange

virtual

virtual void onStreamStateChange(const PacketStreamState & state)

Called by the PacketStream when stream state changes. Logs when the stream is stopping; no other action is taken.

Parameters


isVideo

const

bool isVideo() const

True if this sender is bound to a video track.


bound

const

bool bound() const

True if bound to any track.

Private Attributes

ReturnNameDescription
std::shared_ptr< rtc::Track >_track
std::shared_ptr< rtc::RtpPacketizationConfig >_rtpConfig
std::atomic< TrackKind >_kind
std::mutex_mutex

_track

std::shared_ptr< rtc::Track > _track

_rtpConfig

std::shared_ptr< rtc::RtpPacketizationConfig > _rtpConfig

_kind

std::atomic< TrackKind > _kind {TrackKind::Unbound}

_mutex

std::mutex _mutex