BlueGit

ict rusty-teams

Files

rusty-teams / vendor / libwebrtc / src / media_stream_track.rs

media_stream_track.rs

media_stream_track.rs 2.3 KiB Download Raw
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
15use crate::{audio_track::RtcAudioTrack, enum_dispatch, video_track::RtcVideoTrack};
16
17#[derive(Debug, Copy, Clone, PartialEq, Eq)]
18pub enum RtcTrackState {
19 Live,
20 Ended,
21}
22
23#[derive(Debug, Clone)]
24pub enum MediaStreamTrack {
25 Video(RtcVideoTrack),
26 Audio(RtcAudioTrack),
27}
28
29#[cfg(not(target_arch = "wasm32"))]
30impl MediaStreamTrack {
31 enum_dispatch!(
32 [Video, Audio];
33 pub(crate) fn sys_handle(self: &Self) -> cxx::SharedPtr<webrtc_sys::media_stream::ffi::MediaStreamTrack>;
34 );
35}
36
37impl MediaStreamTrack {
38 enum_dispatch!(
39 [Video, Audio];
40 pub fn id(self: &Self) -> String;
41 pub fn enabled(self: &Self) -> bool;
42 pub fn set_enabled(self: &Self, enabled: bool) -> bool;
43 pub fn state(self: &Self) -> RtcTrackState;
44 );
45}
46
47macro_rules! media_stream_track {
48 () => {
49 pub fn id(&self) -> String {
50 self.handle.id()
51 }
52
53 pub fn enabled(&self) -> bool {
54 self.handle.enabled()
55 }
56
57 pub fn set_enabled(&self, enabled: bool) -> bool {
58 self.handle.set_enabled(enabled)
59 }
60
61 pub fn state(&self) -> RtcTrackState {
62 self.handle.state().into()
63 }
64
65 #[cfg(not(target_arch = "wasm32"))]
66 pub(crate) fn sys_handle(
67 &self,
68 ) -> cxx::SharedPtr<webrtc_sys::media_stream::ffi::MediaStreamTrack> {
69 self.handle.sys_handle()
70 }
71 };
72}
73
74pub(crate) use media_stream_track;
75
76impl From<RtcAudioTrack> for MediaStreamTrack {
77 fn from(track: RtcAudioTrack) -> Self {
78 Self::Audio(track)
79 }
80}
81
82impl From<RtcVideoTrack> for MediaStreamTrack {
83 fn from(track: RtcVideoTrack) -> Self {
84 Self::Video(track)
85 }
86}