| 1 | // Copyright 2025 LiveKit, Inc. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | use std::fmt::Debug; |
| 16 | |
| 17 | use crate::{ |
| 18 | imp::rtp_transceiver as imp_rt, |
| 19 | rtp_parameters::{RtpCodecCapability, RtpEncodingParameters}, |
| 20 | rtp_receiver::RtpReceiver, |
| 21 | rtp_sender::RtpSender, |
| 22 | RtcError, |
| 23 | }; |
| 24 | |
| 25 | #[derive(Debug, Clone)] |
| 26 | pub struct RtpTransceiverInit { |
| 27 | pub direction: RtpTransceiverDirection, |
| 28 | pub stream_ids: Vec<String>, |
| 29 | pub send_encodings: Vec<RtpEncodingParameters>, |
| 30 | } |
| 31 | |
| 32 | #[derive(Debug, Copy, Clone, PartialEq, Eq)] |
| 33 | pub enum RtpTransceiverDirection { |
| 34 | SendRecv, |
| 35 | SendOnly, |
| 36 | RecvOnly, |
| 37 | Inactive, |
| 38 | Stopped, |
| 39 | } |
| 40 | |
| 41 | #[derive(Clone)] |
| 42 | pub struct RtpTransceiver { |
| 43 | pub(crate) handle: imp_rt::RtpTransceiver, |
| 44 | } |
| 45 | |
| 46 | impl RtpTransceiver { |
| 47 | pub fn mid(&self) -> Option<String> { |
| 48 | self.handle.mid() |
| 49 | } |
| 50 | |
| 51 | pub fn current_direction(&self) -> Option<RtpTransceiverDirection> { |
| 52 | self.handle.current_direction() |
| 53 | } |
| 54 | |
| 55 | pub fn direction(&self) -> RtpTransceiverDirection { |
| 56 | self.handle.direction() |
| 57 | } |
| 58 | |
| 59 | pub fn set_direction(&self, direction: RtpTransceiverDirection) -> Result<(), RtcError> { |
| 60 | self.handle.set_direction(direction) |
| 61 | } |
| 62 | |
| 63 | pub fn sender(&self) -> RtpSender { |
| 64 | self.handle.sender() |
| 65 | } |
| 66 | |
| 67 | pub fn receiver(&self) -> RtpReceiver { |
| 68 | self.handle.receiver() |
| 69 | } |
| 70 | |
| 71 | pub fn set_codec_preferences(&self, codecs: Vec<RtpCodecCapability>) -> Result<(), RtcError> { |
| 72 | self.handle.set_codec_preferences(codecs) |
| 73 | } |
| 74 | |
| 75 | pub fn stop(&self) -> Result<(), RtcError> { |
| 76 | self.handle.stop() |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | impl Debug for RtpTransceiver { |
| 81 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 82 | f.debug_struct("RtpTransceiver") |
| 83 | .field("mid", &self.mid()) |
| 84 | .field("direction", &self.direction()) |
| 85 | .field("sender", &self.sender()) |
| 86 | .field("receiver", &self.receiver()) |
| 87 | .finish() |
| 88 | } |
| 89 | } |