@@ -95,6 +95,7 @@ pub struct GlobalTimingInfo {
95
95
pub fts_at_gop_start : Timestamp ,
96
96
pub gop_rollover : bool ,
97
97
pub timing_settings : TimingSettings ,
98
+ pub mpeg_clock_freq : i64 ,
98
99
}
99
100
100
101
impl TimingContext {
@@ -132,12 +133,14 @@ impl TimingContext {
132
133
///
133
134
/// It also checks for PTS resets.
134
135
pub fn set_current_pts ( & mut self , pts : MpegClockTick ) {
136
+ let timing_info = GLOBAL_TIMING_INFO . read ( ) . unwrap ( ) ;
137
+
135
138
let prev_pts = self . current_pts ;
136
139
self . current_pts = pts;
137
140
if self . pts_set == PtsSet :: No {
138
141
self . pts_set = PtsSet :: Received
139
142
}
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( ) ) ;
141
144
debug ! ( msg_type = DebugMessageFlag :: VIDEO_STREAM ; " FTS: {} \n " , self . fts_now. to_hms_millis_time( ':' ) . unwrap( ) ) ;
142
145
143
146
// Check if PTS reset
@@ -162,7 +165,9 @@ impl TimingContext {
162
165
// Disables sync check. Used for several input formats.
163
166
0
164
167
} 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 ( )
166
171
} ;
167
172
168
173
// Previously in C equivalent code, its -0.2
@@ -221,7 +226,7 @@ impl TimingContext {
221
226
self . sync_pts = self . current_pts
222
227
- self
223
228
. 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 ) ;
225
230
226
231
if self . current_tref . as_u64 ( ) == 0
227
232
|| ( timing_info. total_frames_count - timing_info. frames_since_ref_time ) . as_u64 ( )
@@ -245,7 +250,7 @@ impl TimingContext {
245
250
debug ! (
246
251
msg_type = DebugMessageFlag :: TIME ;
247
252
"\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( ) ,
249
254
self . fts_offset. millis( )
250
255
) ;
251
256
debug ! (
@@ -262,7 +267,7 @@ impl TimingContext {
262
267
// sync_pts (set at the beginning of the last GOP) plus the
263
268
// time of the frames since then.
264
269
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 )
266
271
+ timing_info
267
272
. frames_since_ref_time
268
273
. as_timestamp ( timing_info. current_fps ) ;
@@ -277,14 +282,14 @@ impl TimingContext {
277
282
self . sync_pts = self . current_pts
278
283
- self
279
284
. 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 ) ;
281
286
// Set min_pts = sync_pts as this is used for fts_now
282
287
self . min_pts = self . sync_pts ;
283
288
284
289
debug ! (
285
290
msg_type = DebugMessageFlag :: TIME ;
286
291
"\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( ) ,
288
293
self . fts_offset. millis( )
289
294
) ;
290
295
}
@@ -305,7 +310,9 @@ impl TimingContext {
305
310
// CFS: Remove or think decent condition
306
311
if self . pts_set != PtsSet :: No {
307
312
// 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 ;
309
316
if !self . sync_pts2fts_set {
310
317
self . sync_pts2fts_pts = self . current_pts ;
311
318
self . sync_pts2fts_fts = self . fts_now ;
@@ -373,7 +380,7 @@ impl TimingContext {
373
380
info ! (
374
381
"Sync time stamps: PTS: {} " ,
375
382
self . sync_pts
376
- . as_timestamp( )
383
+ . as_timestamp( timing_info . mpeg_clock_freq )
377
384
. to_hms_millis_time( ':' )
378
385
. unwrap( )
379
386
) ;
@@ -385,7 +392,8 @@ impl TimingContext {
385
392
// Length first GOP to last GOP
386
393
let goplenms = gop_time - first_gop_time;
387
394
// 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 ;
389
397
390
398
info ! (
391
399
"Last FTS: {}" ,
@@ -548,6 +556,7 @@ impl GlobalTimingInfo {
548
556
no_sync : false ,
549
557
is_elementary_stream : false ,
550
558
} ,
559
+ mpeg_clock_freq : 0 ,
551
560
}
552
561
}
553
562
}
0 commit comments