WebRtcTrackSender
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
| Return | Name | Description |
|---|---|---|
PacketSignal | emitter |
emitter
PacketSignal emitterPublic Methods
| Return | Name | Description |
|---|---|---|
WebRtcTrackSender | Construct an unbound sender. Call bind() before use. | |
WebRtcTrackSender explicit | Construct bound to a track handle from createVideoTrack() or createAudioTrack(). | |
void | bind | Bind to a track. Can be called to rebind to a different track. |
void | unbind | Unbind from the current track. |
void | process virtual | 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. |
bool | accepts virtual | Return true only for the packet type that matches the bound track. |
void | onStreamStateChange virtual | Called by the PacketStream when stream state changes. Logs when the stream is stopping; no other action is taken. |
bool | isVideo const | True if this sender is bound to a video track. |
bool | bound const | True 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
packetAn av::VideoPacket or av::AudioPacket carrying the encoded frame data and a microsecond timestamp.
accepts
virtual
virtual bool accepts(IPacket * packet)Return true only for the packet type that matches the bound track.
Parameters
packetPacket 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
stateNew PacketStream state.
isVideo
const
bool isVideo() constTrue if this sender is bound to a video track.
bound
const
bool bound() constTrue if bound to any track.
Private Attributes
| Return | Name | Description |
|---|---|---|
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