Skip to main content

gosuto_livekit/room/track/
video_track.rs

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 gosuto_libwebrtc::prelude::*;
16use livekit_protocol as proto;
17use livekit_protocol::enum_dispatch;
18
19use super::track_dispatch;
20use crate::prelude::*;
21
22#[derive(Clone, Debug)]
23pub enum VideoTrack {
24    Local(LocalVideoTrack),
25    Remote(RemoteVideoTrack),
26}
27
28impl VideoTrack {
29    track_dispatch!([Local, Remote]);
30
31    #[inline]
32    pub fn rtc_track(&self) -> RtcVideoTrack {
33        match self {
34            Self::Local(track) => track.rtc_track(),
35            Self::Remote(track) => track.rtc_track(),
36        }
37    }
38}
39
40impl From<VideoTrack> for Track {
41    fn from(track: VideoTrack) -> Self {
42        match track {
43            VideoTrack::Local(track) => Self::LocalVideo(track),
44            VideoTrack::Remote(track) => Self::RemoteVideo(track),
45        }
46    }
47}
48
49impl TryFrom<Track> for VideoTrack {
50    type Error = &'static str;
51
52    fn try_from(track: Track) -> Result<Self, Self::Error> {
53        match track {
54            Track::LocalVideo(track) => Ok(Self::Local(track)),
55            Track::RemoteVideo(track) => Ok(Self::Remote(track)),
56            _ => Err("not a video track"),
57        }
58    }
59}