#include <icy/webrtc/mediabridge.h>Convenience wrapper that creates WebRTC tracks on a PeerConnection and exposes per-track sender/receiver adapters for PacketStream integration.
For video-only, leave audioCodec default (disabled). For audio-only, leave videoCodec default (disabled). For data-channel-only, don't create a MediaBridge at all.
For full control over individual tracks, use createVideoTrack(), createAudioTrack(), WebRtcTrackSender, and WebRtcTrackReceiver directly instead of this class.
The sender and receiver adapter objects are stable for the lifetime of the MediaBridge. attach() and detach() rebind or unbind the underlying WebRTC tracks without invalidating references previously obtained from videoSender(), audioSender(), videoReceiver(), or audioReceiver().
Example - send camera to browser:
MediaBridge bridge; bridge.attach(pc, {.videoCodec = {"H264", "libx264", 1280, 720, 30}});
PacketStream stream; stream.attachSource(capture); stream.attach(encoder, 1, true); stream.attach(&bridge.videoSender(), 5, false); stream.start();
Example - receive from browser and record:
bridge.videoReceiver().emitter += packetSlot(&recorder, &Recorder::onEncodedVideo);
The receiver emits owning encoded packets. Feed those into a decoder or recorder callback; see samples/media-recorder for a complete example.
| Return | Name | Description |
|---|---|---|
ThreadSignal< void()> | KeyframeRequested | Remote peer requests a keyframe. Connect to encoder to force IDR. |
ThreadSignal< void(unsigned int)> | BitrateEstimate | Remote peer reports estimated bandwidth (bits/sec). |
ThreadSignal< void()> KeyframeRequestedRemote peer requests a keyframe. Connect to encoder to force IDR.
ThreadSignal< void(unsigned int)> BitrateEstimateRemote peer reports estimated bandwidth (bits/sec).
| Return | Name | Description |
|---|---|---|
MediaBridge | Construct a detached bridge with stable sender and receiver adapters. | |
~MediaBridge | Destroy the bridge and release any attached PeerConnection state. | |
MediaBridge | Deleted copy constructor; MediaBridge owns live track and adapter state. | |
void | attach | Create tracks on the PeerConnection and set up handler chains. Only creates tracks for codecs with a non-empty encoder name. |
void | detach | Detach all tracks and adapters. |
void | requestKeyframe | Request an immediate keyframe (IDR) from the remote sender. Sends a PLI (Picture Loss Indication) RTCP message on the video track. No-op if no video track is attached. |
void | requestBitrate | Request that the remote sender reduce to a target bitrate. Sends a TMMBR RTCP message on the video track. |
WebRtcTrackSender & | videoSender | Video send processor. Attach to a PacketStream after a VideoEncoder. Throws if no video track was created. |
WebRtcTrackSender & | audioSender | Audio send processor. Attach to a PacketStream after an AudioEncoder. Throws if no audio track was created. |
WebRtcTrackReceiver & | videoReceiver | Video receive adapter. Attach as a PacketStream source. Only valid after a remote video track arrives. |
WebRtcTrackReceiver & | audioReceiver | Audio receive adapter. Attach as a PacketStream source. Only valid after a remote audio track arrives. |
std::shared_ptr< rtc::Track > | videoTrack const | The underlying libdatachannel video track, or nullptr if none was created. |
std::shared_ptr< rtc::Track > | audioTrack const | The underlying libdatachannel audio track, or nullptr if none was created. |
bool | hasVideo const | True if a video track was created at attach(). |
bool | hasAudio const | True if an audio track was created at attach(). |
bool | attached const | True if attach() has been called and a PeerConnection is held. |
MediaBridge()Construct a detached bridge with stable sender and receiver adapters.
~MediaBridge()Destroy the bridge and release any attached PeerConnection state.
MediaBridge(const MediaBridge &) = deleteDeleted copy constructor; MediaBridge owns live track and adapter state.
void attach(std::shared_ptr< rtc::PeerConnection > pc, const Options & opts)Create tracks on the PeerConnection and set up handler chains. Only creates tracks for codecs with a non-empty encoder name.
void detach()Detach all tracks and adapters.
void requestKeyframe()Request an immediate keyframe (IDR) from the remote sender. Sends a PLI (Picture Loss Indication) RTCP message on the video track. No-op if no video track is attached.
void requestBitrate(unsigned int bitrate)Request that the remote sender reduce to a target bitrate. Sends a TMMBR RTCP message on the video track.
bitrate Target bitrate in bits per second.WebRtcTrackSender & videoSender()Video send processor. Attach to a PacketStream after a VideoEncoder. Throws if no video track was created.
WebRtcTrackSender & audioSender()Audio send processor. Attach to a PacketStream after an AudioEncoder. Throws if no audio track was created.
WebRtcTrackReceiver & videoReceiver()Video receive adapter. Attach as a PacketStream source. Only valid after a remote video track arrives.
WebRtcTrackReceiver & audioReceiver()Audio receive adapter. Attach as a PacketStream source. Only valid after a remote audio track arrives.
const
std::shared_ptr< rtc::Track > videoTrack() constThe underlying libdatachannel video track, or nullptr if none was created.
const
std::shared_ptr< rtc::Track > audioTrack() constThe underlying libdatachannel audio track, or nullptr if none was created.
const
bool hasVideo() constTrue if a video track was created at attach().
const
bool hasAudio() constTrue if an audio track was created at attach().
const
bool attached() constTrue if attach() has been called and a PeerConnection is held.
| Return | Name | Description |
|---|---|---|
std::shared_ptr< rtc::PeerConnection > | _pc | |
WebRtcTrackSender | _videoSender | |
WebRtcTrackSender | _audioSender | |
TrackHandle | _videoHandle | |
TrackHandle | _audioHandle | |
WebRtcTrackReceiver | _videoReceiver | |
WebRtcTrackReceiver | _audioReceiver | |
std::shared_ptr< rtc::Track > | _videoReceiveTrack | |
std::shared_ptr< rtc::Track > | _audioReceiveTrack | |
std::mutex | _mutex |
std::shared_ptr< rtc::PeerConnection > _pcWebRtcTrackSender _videoSenderWebRtcTrackSender _audioSenderTrackHandle _videoHandleTrackHandle _audioHandleWebRtcTrackReceiver _videoReceiverWebRtcTrackReceiver _audioReceiverstd::shared_ptr< rtc::Track > _videoReceiveTrackstd::shared_ptr< rtc::Track > _audioReceiveTrackstd::mutex _mutex