@@ -16,15 +16,13 @@ use std::{fmt::Debug, sync::Arc};
1616
1717use libwebrtc:: { native:: user_timestamp:: UserTimestampHandler , prelude:: * , stats:: RtcStats } ;
1818use livekit_protocol as proto;
19- use parking_lot:: Mutex ;
2019
2120use super :: { remote_track, TrackInner } ;
2221use crate :: prelude:: * ;
2322
2423#[ derive( Clone ) ]
2524pub struct RemoteVideoTrack {
2625 inner : Arc < TrackInner > ,
27- user_timestamp_handler : Arc < Mutex < Option < UserTimestampHandler > > > ,
2826}
2927
3028impl Debug for RemoteVideoTrack {
@@ -46,7 +44,6 @@ impl RemoteVideoTrack {
4644 TrackKind :: Video ,
4745 MediaStreamTrack :: Video ( rtc_track) ,
4846 ) ) ,
49- user_timestamp_handler : Arc :: new ( Mutex :: new ( None ) ) ,
5047 }
5148 }
5249
@@ -101,24 +98,23 @@ impl RemoteVideoTrack {
10198 /// remote video track, if the user timestamp transformer is enabled and
10299 /// a timestamp has been received.
103100 pub fn last_user_timestamp ( & self ) -> Option < i64 > {
104- self . user_timestamp_handler
105- . lock ( )
106- . as_ref ( )
101+ self . rtc_track ( )
102+ . user_timestamp_handler ( )
107103 . and_then ( |h| h. last_user_timestamp ( ) )
108104 }
109105
110106 /// Returns a clone of the user timestamp handler, if one has been set.
111- ///
112- /// This can be passed to a `NativeVideoStream` via
113- /// `set_user_timestamp_handler` so that each frame's
114- /// `user_timestamp_us` field is populated automatically.
115107 pub fn user_timestamp_handler ( & self ) -> Option < UserTimestampHandler > {
116- self . user_timestamp_handler . lock ( ) . clone ( )
108+ self . rtc_track ( ) . user_timestamp_handler ( )
117109 }
118110
119111 /// Internal: set the handler that extracts user timestamps for this track.
112+ ///
113+ /// The handler is stored on the underlying `RtcVideoTrack`, so any
114+ /// `NativeVideoStream` created from this track will automatically
115+ /// pick it up — no manual wiring required.
120116 pub ( crate ) fn set_user_timestamp_handler ( & self , handler : UserTimestampHandler ) {
121- self . user_timestamp_handler . lock ( ) . replace ( handler) ;
117+ self . rtc_track ( ) . set_user_timestamp_handler ( handler) ;
122118 }
123119
124120 pub async fn get_stats ( & self ) -> RoomResult < Vec < RtcStats > > {
0 commit comments