|
3 | 3 | //! This module provides async-friendly wrappers around RTP media tracks. |
4 | 4 |
|
5 | 5 | use crate::runtime::{Mutex, Receiver, Sender}; |
6 | | -use rtc::rtp_transceiver::{RTCRtpReceiverId, RTCRtpSenderId}; |
| 6 | +use rtc::rtp_transceiver::{RTCRtpReceiverId, RTCRtpSenderId, RtpStreamId, SSRC}; |
7 | 7 | use rtc::shared::error::Result; |
8 | 8 |
|
9 | 9 | pub use rtc::media_stream::{MediaStreamId, MediaStreamTrack, MediaStreamTrackId}; |
| 10 | +use rtc::media_stream::{ |
| 11 | + MediaStreamTrackState, MediaTrackCapabilities, MediaTrackConstraints, MediaTrackSettings, |
| 12 | +}; |
| 13 | +use rtc::rtp_transceiver::rtp_sender::{RTCRtpCodec, RtpCodecKind}; |
| 14 | +use rtc::{rtcp, rtp}; |
10 | 15 |
|
11 | 16 | #[async_trait::async_trait] |
12 | | -pub trait TrackLocal: Send + Sync + 'static { |
13 | | - async fn close(&self) -> Result<()>; |
| 17 | +pub trait Track: Send + Sync + 'static { |
| 18 | + async fn stream_id(&self) -> MediaStreamId; |
| 19 | + async fn track_id(&self) -> MediaStreamTrackId; |
| 20 | + async fn label(&self) -> String; |
| 21 | + async fn kind(&self) -> RtpCodecKind; |
| 22 | + async fn rid(&self, ssrc: SSRC) -> Option<RtpStreamId>; |
| 23 | + async fn codec(&self, ssrc: SSRC) -> Option<RTCRtpCodec>; |
| 24 | + async fn ssrcs(&self) -> Vec<SSRC>; |
| 25 | + async fn enabled(&self) -> bool; |
| 26 | + async fn set_enabled(&self, enabled: bool); |
| 27 | + async fn muted(&self) -> bool; |
| 28 | + async fn ready_state(&self) -> MediaStreamTrackState; |
| 29 | + async fn stop(&self); |
| 30 | + async fn get_capabilities(&self) -> MediaTrackCapabilities; |
| 31 | + async fn get_constraints(&self) -> MediaTrackConstraints; |
| 32 | + async fn get_settings(&self) -> MediaTrackSettings; |
| 33 | + async fn apply_constraints(&self, constraints: Option<MediaTrackConstraints>); |
14 | 34 | } |
15 | 35 |
|
16 | 36 | #[async_trait::async_trait] |
17 | | -pub trait TrackRemote: Send + Sync + 'static { |
18 | | - async fn close(&self) -> Result<()>; |
| 37 | +pub trait TrackLocal: Track { |
| 38 | + async fn write_rtp(&self, packet: rtp::Packet) -> Result<()>; |
| 39 | + async fn write_rtcp(&self, packets: Vec<Box<dyn rtcp::Packet>>) -> Result<()>; |
| 40 | +} |
| 41 | + |
| 42 | +#[derive(Debug, Clone)] |
| 43 | +pub enum TrackRemoteEvent { |
| 44 | + OnMute, |
| 45 | + OnUnmute, |
| 46 | + OnEnded, |
| 47 | + OnRtpPacket(rtp::Packet), |
| 48 | + OnRtcpPacket(Vec<Box<dyn rtcp::Packet>>), |
| 49 | +} |
| 50 | + |
| 51 | +#[async_trait::async_trait] |
| 52 | +pub trait TrackRemote: Track { |
| 53 | + async fn write_rtcp(&self, packets: Vec<Box<dyn rtcp::Packet>>) -> Result<()>; |
| 54 | + async fn poll(&self) -> Option<TrackRemoteEvent>; |
19 | 55 | } |
20 | 56 |
|
21 | 57 | /// A local track that sends RTP packets |
|
0 commit comments