@@ -6,6 +6,7 @@ pub mod media_stream_track;
66pub mod rtc_rtp_encoding_parameters;
77pub mod rtc_rtp_send_parameters;
88pub mod stats;
9+ pub mod transceiver;
910
1011use std:: {
1112 sync:: {
@@ -43,6 +44,12 @@ pub use self::{
4344 RtcMediaSourceStatsMediaType , RtcOutboundRtpStreamStatsMediaType ,
4445 RtcStats , RtcStatsIceCandidatePairState , RtcStatsType , get_peer_stats,
4546 } ,
47+ transceiver:: {
48+ RtcRtpTransceiver , RtpTransceiverDirection , RtpTransceiverInit ,
49+ add_transceiver, get_transceiver_direction, get_transceiver_mid,
50+ get_transceivers, set_transceiver_direction, set_transceiver_recv,
51+ set_transceiver_send, stop_transceiver,
52+ } ,
4653} ;
4754// Re-exporting since it is used in the generated code.
4855pub use crate :: {
@@ -387,85 +394,6 @@ impl From<sys::PeerConnectionState> for PeerConnectionState {
387394 }
388395}
389396
390- /// [RTCRtpTransceiverDirection][1] representation.
391- ///
392- /// [1]: https://w3.org/TR/webrtc#dom-rtcrtptransceiverdirection
393- #[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
394- pub enum RtpTransceiverDirection {
395- /// The [RTCRtpTransceiver]'s [RTCRtpSender] will offer to send RTP, and
396- /// will send RTP if the remote peer accepts. The [RTCRtpTransceiver]'s
397- /// [RTCRtpReceiver] will offer to receive RTP, and will receive RTP if the
398- /// remote peer accepts.
399- ///
400- /// [RTCRtpReceiver]: https://w3.org/TR/webrtc#dom-rtcrtpreceiver
401- /// [RTCRtpSender]: https://w3.org/TR/webrtc#dom-rtcrtpsender
402- /// [RTCRtpTransceiver]: https://w3.org/TR/webrtc#dom-rtcrtptransceiver
403- SendRecv ,
404-
405- /// The [RTCRtpTransceiver]'s [RTCRtpSender] will offer to send RTP, and
406- /// will send RTP if the remote peer accepts. The [RTCRtpTransceiver]'s
407- /// [RTCRtpReceiver] will not offer to receive RTP, and will not receive
408- /// RTP.
409- ///
410- /// [RTCRtpReceiver]: https://w3.org/TR/webrtc#dom-rtcrtpreceiver
411- /// [RTCRtpSender]: https://w3.org/TR/webrtc#dom-rtcrtpsender
412- /// [RTCRtpTransceiver]: https://w3.org/TR/webrtc#dom-rtcrtptransceiver
413- SendOnly ,
414-
415- /// The [RTCRtpTransceiver]'s [RTCRtpSender] will not offer to send RTP,
416- /// and will not send RTP. The [RTCRtpTransceiver]'s [RTCRtpReceiver] will
417- /// offer to receive RTP, and will receive RTP if the remote peer accepts.
418- ///
419- /// [RTCRtpReceiver]: https://w3.org/TR/webrtc#dom-rtcrtpreceiver
420- /// [RTCRtpSender]: https://w3.org/TR/webrtc#dom-rtcrtpsender
421- /// [RTCRtpTransceiver]: https://w3.org/TR/webrtc#dom-rtcrtptransceiver
422- RecvOnly ,
423-
424- /// The [RTCRtpTransceiver]'s [RTCRtpSender] will not offer to send RTP,
425- /// and will not send RTP. The [RTCRtpTransceiver]'s [RTCRtpReceiver] will
426- /// not offer to receive RTP, and will not receive RTP.
427- ///
428- /// [RTCRtpReceiver]: https://w3.org/TR/webrtc#dom-rtcrtpreceiver
429- /// [RTCRtpSender]: https://w3.org/TR/webrtc#dom-rtcrtpsender
430- /// [RTCRtpTransceiver]: https://w3.org/TR/webrtc#dom-rtcrtptransceiver
431- Inactive ,
432-
433- /// The [RTCRtpTransceiver] will neither send nor receive RTP. It will
434- /// generate a zero port in the offer. In answers, its [RTCRtpSender] will
435- /// not offer to send RTP, and its [RTCRtpReceiver] will not offer to
436- /// receive RTP. This is a terminal state.
437- ///
438- /// [RTCRtpReceiver]: https://w3.org/TR/webrtc#dom-rtcrtpreceiver
439- /// [RTCRtpSender]: https://w3.org/TR/webrtc#dom-rtcrtpsender
440- /// [RTCRtpTransceiver]: https://w3.org/TR/webrtc#dom-rtcrtptransceiver
441- Stopped ,
442- }
443-
444- impl From < sys:: RtpTransceiverDirection > for RtpTransceiverDirection {
445- fn from ( state : sys:: RtpTransceiverDirection ) -> Self {
446- match state {
447- sys:: RtpTransceiverDirection :: kSendRecv => Self :: SendRecv ,
448- sys:: RtpTransceiverDirection :: kSendOnly => Self :: SendOnly ,
449- sys:: RtpTransceiverDirection :: kRecvOnly => Self :: RecvOnly ,
450- sys:: RtpTransceiverDirection :: kInactive => Self :: Inactive ,
451- sys:: RtpTransceiverDirection :: kStopped => Self :: Stopped ,
452- _ => unreachable ! ( ) ,
453- }
454- }
455- }
456-
457- impl From < RtpTransceiverDirection > for sys:: RtpTransceiverDirection {
458- fn from ( state : RtpTransceiverDirection ) -> Self {
459- match state {
460- RtpTransceiverDirection :: SendRecv => Self :: kSendRecv,
461- RtpTransceiverDirection :: SendOnly => Self :: kSendOnly,
462- RtpTransceiverDirection :: RecvOnly => Self :: kRecvOnly,
463- RtpTransceiverDirection :: Inactive => Self :: kInactive,
464- RtpTransceiverDirection :: Stopped => Self :: kStopped,
465- }
466- }
467- }
468-
469397/// [RTCSdpType] representation.
470398///
471399/// [RTCSdpType]: https://w3.org/TR/webrtc#dom-rtcsdptype
@@ -601,48 +529,6 @@ pub struct AudioProcessingConstraints {
601529 pub echo_cancellation : Option < bool > ,
602530}
603531
604- /// Representation of an [RTCRtpTransceiverInit][0].
605- ///
606- /// [0]: https://w3.org/TR/webrtc#dom-rtcrtptransceiverinit
607- pub struct RtpTransceiverInit {
608- /// Direction of the [RTCRtpTransceiver].
609- ///
610- /// [RTCRtpTransceiver]: https://w3.org/TR/webrtc#dom-rtcrtptransceiver
611- pub direction : RtpTransceiverDirection ,
612-
613- /// Sequence containing parameters for sending [RTP] encodings of media.
614- ///
615- /// [RTP]: https://en.wikipedia.org/wiki/Real-time_Transport_Protocol
616- pub send_encodings : Vec < RtcRtpEncodingParameters > ,
617- }
618-
619- /// Representation of a permanent pair of an [RTCRtpSender] and an
620- /// [RTCRtpReceiver], along with some shared state.
621- ///
622- /// [RTCRtpSender]: https://w3.org/TR/webrtc#dom-rtcrtpsender
623- /// [RTCRtpReceiver]: https://w3.org/TR/webrtc#dom-rtcrtpreceiver
624- #[ derive( Clone ) ]
625- pub struct RtcRtpTransceiver {
626- /// [`PeerConnection`] that this [`RtcRtpTransceiver`] belongs to.
627- pub peer : RustOpaque < Arc < PeerConnection > > ,
628-
629- /// Rust side [`RtpTransceiver`].
630- pub transceiver : RustOpaque < Arc < RtpTransceiver > > ,
631-
632- /// [Negotiated media ID (mid)][1] which the local and remote peers have
633- /// agreed upon to uniquely identify the [MediaStream]'s pairing of sender
634- /// and receiver.
635- ///
636- /// [MediaStream]: https://w3.org/TR/mediacapture-streams#dom-mediastream
637- /// [1]: https://w3.org/TR/webrtc#dfn-media-stream-identification-tag
638- pub mid : Option < String > ,
639-
640- /// Preferred [`direction`][1] of this [`RtcRtpTransceiver`].
641- ///
642- /// [1]: https://w3.org/TR/webrtc#dom-rtcrtptransceiver-direction
643- pub direction : RtpTransceiverDirection ,
644- }
645-
646532/// Representation of a track event, sent when a new [`MediaStreamTrack`] is
647533/// added to an [`RtcRtpTransceiver`] as part of a [`PeerConnection`].
648534#[ derive( Clone ) ]
@@ -951,86 +837,6 @@ pub fn set_remote_description(
951837 peer. set_remote_description ( kind. into ( ) , & sdp)
952838}
953839
954- /// Creates a new [`RtcRtpTransceiver`] and adds it to the set of transceivers
955- /// of the specified [`PeerConnection`].
956- pub fn add_transceiver (
957- peer : RustOpaque < Arc < PeerConnection > > ,
958- media_type : MediaType ,
959- init : RtpTransceiverInit ,
960- ) -> anyhow:: Result < RtcRtpTransceiver > {
961- PeerConnection :: add_transceiver ( peer, media_type. into ( ) , init)
962- }
963-
964- /// Returns a sequence of [`RtcRtpTransceiver`] objects representing the RTP
965- /// transceivers currently attached to the specified [`PeerConnection`].
966- #[ expect( clippy:: needless_pass_by_value, reason = "FFI" ) ]
967- #[ must_use]
968- pub fn get_transceivers (
969- peer : RustOpaque < Arc < PeerConnection > > ,
970- ) -> Vec < RtcRtpTransceiver > {
971- Webrtc :: get_transceivers ( & peer)
972- }
973-
974- /// Changes the preferred `direction` of the specified [`RtcRtpTransceiver`].
975- #[ expect( clippy:: needless_pass_by_value, reason = "FFI" ) ]
976- pub fn set_transceiver_direction (
977- transceiver : RustOpaque < Arc < RtpTransceiver > > ,
978- direction : RtpTransceiverDirection ,
979- ) -> anyhow:: Result < ( ) > {
980- transceiver. set_direction ( direction)
981- }
982-
983- /// Changes the receive direction of the specified [`RtcRtpTransceiver`].
984- #[ expect( clippy:: needless_pass_by_value, reason = "FFI" ) ]
985- pub fn set_transceiver_recv (
986- transceiver : RustOpaque < Arc < RtpTransceiver > > ,
987- recv : bool ,
988- ) -> anyhow:: Result < ( ) > {
989- transceiver. set_recv ( recv)
990- }
991-
992- /// Changes the send direction of the specified [`RtcRtpTransceiver`].
993- #[ expect( clippy:: needless_pass_by_value, reason = "FFI" ) ]
994- pub fn set_transceiver_send (
995- transceiver : RustOpaque < Arc < RtpTransceiver > > ,
996- send : bool ,
997- ) -> anyhow:: Result < ( ) > {
998- transceiver. set_send ( send)
999- }
1000-
1001- /// Returns the [negotiated media ID (mid)][1] of the specified
1002- /// [`RtcRtpTransceiver`].
1003- ///
1004- /// [1]: https://w3.org/TR/webrtc#dfn-media-stream-identification-tag
1005- #[ expect( clippy:: needless_pass_by_value, reason = "FFI" ) ]
1006- #[ must_use]
1007- pub fn get_transceiver_mid (
1008- transceiver : RustOpaque < Arc < RtpTransceiver > > ,
1009- ) -> Option < String > {
1010- transceiver. mid ( )
1011- }
1012-
1013- /// Returns the preferred direction of the specified [`RtcRtpTransceiver`].
1014- #[ expect( clippy:: needless_pass_by_value, reason = "FFI" ) ]
1015- #[ must_use]
1016- pub fn get_transceiver_direction (
1017- transceiver : RustOpaque < Arc < RtpTransceiver > > ,
1018- ) -> RtpTransceiverDirection {
1019- transceiver. direction ( ) . into ( )
1020- }
1021-
1022- /// Irreversibly marks the specified [`RtcRtpTransceiver`] as stopping, unless
1023- /// it's already stopped.
1024- ///
1025- /// This will immediately cause the transceiver's sender to no longer send, and
1026- /// its receiver to no longer receive.
1027- #[ expect( clippy:: needless_pass_by_value, reason = "FFI" ) ]
1028- pub fn stop_transceiver (
1029- transceiver : RustOpaque < Arc < RtpTransceiver > > ,
1030- ) -> anyhow:: Result < ( ) > {
1031- transceiver. stop ( )
1032- }
1033-
1034840/// Replaces the specified [`AudioTrack`] (or [`VideoTrack`]) on the
1035841/// [`sys::RtpTransceiverInterface`]'s `sender`.
1036842///
0 commit comments