BlueGit

ict rusty-teams

Files

rusty-teams / vendor / libwebrtc / src / native / video_track.rs

video_track.rs

video_track.rs 2.0 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 std::sync::Arc;
16
17use cxx::SharedPtr;
18use parking_lot::Mutex;
19use sys_vt::ffi::video_to_media;
20use webrtc_sys::video_track as sys_vt;
21
22use super::media_stream_track::impl_media_stream_track;
23use super::packet_trailer::PacketTrailerHandler;
24use crate::media_stream_track::RtcTrackState;
25
26#[derive(Clone)]
27pub struct RtcVideoTrack {
28 pub(crate) sys_handle: SharedPtr<sys_vt::ffi::VideoTrack>,
29 packet_trailer_handler: Arc<Mutex<Option<PacketTrailerHandler>>>,
30}
31
32impl RtcVideoTrack {
33 impl_media_stream_track!(video_to_media);
34
35 pub(crate) fn new(sys_handle: SharedPtr<sys_vt::ffi::VideoTrack>) -> Self {
36 Self { sys_handle, packet_trailer_handler: Arc::new(Mutex::new(None)) }
37 }
38
39 pub fn sys_handle(&self) -> SharedPtr<sys_vt::ffi::MediaStreamTrack> {
40 video_to_media(self.sys_handle.clone())
41 }
42
43 /// Set the packet trailer handler for this track.
44 ///
45 /// When set, any `NativeVideoStream` created from this track will
46 /// automatically use this handler to populate `user_timestamp`
47 /// on each decoded frame.
48 pub fn set_packet_trailer_handler(&self, handler: PacketTrailerHandler) {
49 self.packet_trailer_handler.lock().replace(handler);
50 }
51
52 /// Get the packet trailer handler, if one has been set.
53 pub fn packet_trailer_handler(&self) -> Option<PacketTrailerHandler> {
54 self.packet_trailer_handler.lock().clone()
55 }
56}