@@ -95,6 +95,7 @@ pub struct GlobalTimingInfo {
9595 pub fts_at_gop_start : Timestamp ,
9696 pub gop_rollover : bool ,
9797 pub timing_settings : TimingSettings ,
98+ pub mpeg_clock_freq : i64 ,
9899}
99100
100101impl TimingContext {
@@ -132,12 +133,14 @@ impl TimingContext {
132133 ///
133134 /// It also checks for PTS resets.
134135 pub fn set_current_pts ( & mut self , pts : MpegClockTick ) {
136+ let timing_info = GLOBAL_TIMING_INFO . read ( ) . unwrap ( ) ;
137+
135138 let prev_pts = self . current_pts ;
136139 self . current_pts = pts;
137140 if self . pts_set == PtsSet :: No {
138141 self . pts_set = PtsSet :: Received
139142 }
140- debug ! ( msg_type = DebugMessageFlag :: VIDEO_STREAM ; "PTS: {} ({:8})" , self . current_pts. as_timestamp( ) . to_hms_millis_time( ':' ) . unwrap( ) , self . current_pts. as_i64( ) ) ;
143+ debug ! ( msg_type = DebugMessageFlag :: VIDEO_STREAM ; "PTS: {} ({:8})" , self . current_pts. as_timestamp( timing_info . mpeg_clock_freq ) . to_hms_millis_time( ':' ) . unwrap( ) , self . current_pts. as_i64( ) ) ;
141144 debug ! ( msg_type = DebugMessageFlag :: VIDEO_STREAM ; " FTS: {} \n " , self . fts_now. to_hms_millis_time( ':' ) . unwrap( ) ) ;
142145
143146 // Check if PTS reset
@@ -162,7 +165,9 @@ impl TimingContext {
162165 // Disables sync check. Used for several input formats.
163166 0
164167 } else {
165- ( self . current_pts - self . sync_pts ) . as_timestamp ( ) . seconds ( )
168+ ( self . current_pts - self . sync_pts )
169+ . as_timestamp ( timing_info. mpeg_clock_freq )
170+ . seconds ( )
166171 } ;
167172
168173 // Previously in C equivalent code, its -0.2
@@ -221,7 +226,7 @@ impl TimingContext {
221226 self . sync_pts = self . current_pts
222227 - self
223228 . current_tref
224- . as_mpeg_clock_tick ( timing_info. current_fps ) ;
229+ . as_mpeg_clock_tick ( timing_info. current_fps , timing_info . mpeg_clock_freq ) ;
225230
226231 if self . current_tref . as_u64 ( ) == 0
227232 || ( timing_info. total_frames_count - timing_info. frames_since_ref_time ) . as_u64 ( )
@@ -245,7 +250,7 @@ impl TimingContext {
245250 debug ! (
246251 msg_type = DebugMessageFlag :: TIME ;
247252 "\n First sync time PTS: {} {:+}ms (time before this PTS)\n " ,
248- self . min_pts. as_timestamp( ) . to_hms_millis_time( ':' ) . unwrap( ) ,
253+ self . min_pts. as_timestamp( timing_info . mpeg_clock_freq ) . to_hms_millis_time( ':' ) . unwrap( ) ,
249254 self . fts_offset. millis( )
250255 ) ;
251256 debug ! (
@@ -262,7 +267,7 @@ impl TimingContext {
262267 // sync_pts (set at the beginning of the last GOP) plus the
263268 // time of the frames since then.
264269 self . fts_offset = self . fts_offset
265- + ( self . sync_pts - self . min_pts ) . as_timestamp ( )
270+ + ( self . sync_pts - self . min_pts ) . as_timestamp ( timing_info . mpeg_clock_freq )
266271 + timing_info
267272 . frames_since_ref_time
268273 . as_timestamp ( timing_info. current_fps ) ;
@@ -277,14 +282,14 @@ impl TimingContext {
277282 self . sync_pts = self . current_pts
278283 - self
279284 . current_tref
280- . as_mpeg_clock_tick ( timing_info. current_fps ) ;
285+ . as_mpeg_clock_tick ( timing_info. current_fps , timing_info . mpeg_clock_freq ) ;
281286 // Set min_pts = sync_pts as this is used for fts_now
282287 self . min_pts = self . sync_pts ;
283288
284289 debug ! (
285290 msg_type = DebugMessageFlag :: TIME ;
286291 "\n New min PTS time: {} {:+}ms (time before this PTS)\n " ,
287- self . min_pts. as_timestamp( ) . to_hms_millis_time( ':' ) . unwrap( ) ,
292+ self . min_pts. as_timestamp( timing_info . mpeg_clock_freq ) . to_hms_millis_time( ':' ) . unwrap( ) ,
288293 self . fts_offset. millis( )
289294 ) ;
290295 }
@@ -305,7 +310,9 @@ impl TimingContext {
305310 // CFS: Remove or think decent condition
306311 if self . pts_set != PtsSet :: No {
307312 // If pts_set is TRUE we have min_pts
308- self . fts_now = ( self . current_pts - self . min_pts ) . as_timestamp ( ) + self . fts_offset ;
313+ self . fts_now = ( self . current_pts - self . min_pts )
314+ . as_timestamp ( timing_info. mpeg_clock_freq )
315+ + self . fts_offset ;
309316 if !self . sync_pts2fts_set {
310317 self . sync_pts2fts_pts = self . current_pts ;
311318 self . sync_pts2fts_fts = self . fts_now ;
@@ -373,7 +380,7 @@ impl TimingContext {
373380 info ! (
374381 "Sync time stamps: PTS: {} " ,
375382 self . sync_pts
376- . as_timestamp( )
383+ . as_timestamp( timing_info . mpeg_clock_freq )
377384 . to_hms_millis_time( ':' )
378385 . unwrap( )
379386 ) ;
@@ -385,7 +392,8 @@ impl TimingContext {
385392 // Length first GOP to last GOP
386393 let goplenms = gop_time - first_gop_time;
387394 // Length at last sync point
388- let ptslenms = ( self . sync_pts - tempmin_pts) . as_timestamp ( ) + self . fts_offset ;
395+ let ptslenms = ( self . sync_pts - tempmin_pts) . as_timestamp ( timing_info. mpeg_clock_freq )
396+ + self . fts_offset ;
389397
390398 info ! (
391399 "Last FTS: {}" ,
@@ -548,6 +556,7 @@ impl GlobalTimingInfo {
548556 no_sync : false ,
549557 is_elementary_stream : false ,
550558 } ,
559+ mpeg_clock_freq : 0 ,
551560 }
552561 }
553562}
0 commit comments