Skip to content

Commit 0831e33

Browse files
committed
define Track/TrackLocal/Remote Trait API
1 parent 17db241 commit 0831e33

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed

rtc

src/media_stream.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,55 @@
33
//! This module provides async-friendly wrappers around RTP media tracks.
44
55
use crate::runtime::{Mutex, Receiver, Sender};
6-
use rtc::rtp_transceiver::{RTCRtpReceiverId, RTCRtpSenderId};
6+
use rtc::rtp_transceiver::{RTCRtpReceiverId, RTCRtpSenderId, RtpStreamId, SSRC};
77
use rtc::shared::error::Result;
88

99
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};
1015

1116
#[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>);
1434
}
1535

1636
#[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>;
1955
}
2056

2157
/// A local track that sends RTP packets

0 commit comments

Comments
 (0)