[vlc-commits] [Git][videolan/vlc][3.0.x] 8 commits: demux: mp4: set samples duration

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Wed Feb 21 19:43:25 UTC 2024



Rémi Denis-Courmont pushed to branch 3.0.x at VideoLAN / VLC


Commits:
3e324f65 by François Cartegnie at 2024-02-20T08:30:09+00:00
demux: mp4: set samples duration

(cherry picked from commit 096500ddebd4d621ea8ce96cdd93baa2ce05a2a8) (rebased)
rebased:
- vlc_tick_t is merged in 3.0
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
5eaa84f9 by Steve Lhomme at 2024-02-20T08:30:09+00:00
demux:mp4: i_nztime is an vlc_tick_t as the comment suggests

(cherry picked from commit 52f365152813cf692956ba37ff700ef3c5c7e1a5)
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
539fc944 by Steve Lhomme at 2024-02-20T08:30:09+00:00
demux:mp4: the result of MP4_TrackGetDTS() is always used as a vlc_tick_t

Also for the value returned by MP4_TrackGetPTSDelta()

(cherry picked from commit 2060b8b3e2aee1e080889766c802b978ee9ffe92) (edited)
edited:
- vlc_tick was merged in 3.0
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
fc759ab8 by Steve Lhomme at 2024-02-20T08:30:09+00:00
demux:mp4: simplify value check

No need to due the subtraction, the value is overwritten right after.

(cherry picked from commit 878df3f879ad8c87a1a5b35dd904bf7d52d31a34)
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
9229409a by Steve Lhomme at 2024-02-20T08:30:09+00:00
demux:mp4: the i_start in TrackTimeToSampleChunk() is a vlc_tick_t

That's the kind of data it is given

(cherry picked from commit 09f5070644fad4a9f101ae039c897702bbb63306)
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
7d59dda7 by Steve Lhomme at 2024-02-20T08:30:09+00:00
demux:mp4: separate stime_t & vlc_tick_t duration in MP4_GetInterleaving()

Thus max_continuity is effectively an vlc_tick_t which compares correctly to
DEMUX_TRACK_MAX_PRELOAD

(cherry picked from commit f2be7ebbed9b475e91ca3bfe842fb8a451f016ed)
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
091f734e by Steve Lhomme at 2024-02-20T08:30:09+00:00
demux:mp4: use a special timestamp rescaler to convert explicitly to vlc_tick_t

(cherry picked from commit 3b84ba41218c7d4f03f0abeb569067ace77ad25e) (edited)
edited:
* MP4_TrackTimeApplyELST was merged in 3.0
* the code around changes is slightly different
* DEMUX_GET_PTS_DELAY expects a int64_t, not a mtime_t
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -
c6883f93 by Steve Lhomme at 2024-02-20T08:30:09+00:00
demux:mp4: use a special timestamp rescaler to convert explicitly from vlc_tick_t

(cherry picked from commit ddfb4f086701bcdf2988402ec144ef7dfdd3c23d) (rebased)
rebased:
* the i_traf_start_time processing is different in 3.0 with i_moof_time involved
* the frag seek time doesn't use b_iframesync
* the code around the changes was slightly different
Signed-off-by: Steve Lhomme <robux4 at ycbcr.xyz>

- - - - -


1 changed file:

- modules/demux/mp4/mp4.c


Changes:

=====================================
modules/demux/mp4/mp4.c
=====================================
@@ -80,7 +80,7 @@ struct demux_sys_t
     uint64_t     i_duration;           /* Declared fragmented duration (movie time scale) */
     uint64_t     i_cumulated_duration; /* Same as above, but not from probing, (movie time scale) */
     uint32_t     i_timescale;          /* movie time scale */
-    uint64_t     i_nztime;             /* time position of the presentation (CLOCK_FREQ timescale) */
+    vlc_tick_t   i_nztime;             /* time position of the presentation (CLOCK_FREQ timescale) */
     unsigned int i_tracks;       /* number of tracks */
     mp4_track_t  *track;         /* array of track */
     float        f_fps;          /* number of frame per seconds */
@@ -205,6 +205,16 @@ static int64_t MP4_rescale( int64_t i_value, uint32_t i_timescale, uint32_t i_ne
     return q * i_newscale + r * i_newscale / i_timescale;
 }
 
+static vlc_tick_t MP4_rescale_mtime( int64_t i_value, uint32_t i_timescale )
+{
+    return MP4_rescale(i_value, i_timescale, CLOCK_FREQ);
+}
+
+static int64_t MP4_rescale_qtime( vlc_tick_t i_value, uint32_t i_timescale )
+{
+    return MP4_rescale(i_value, CLOCK_FREQ, i_timescale);
+}
+
 static uint32_t stream_ReadU32( stream_t *s, void *p_read, uint32_t i_toread )
 {
     ssize_t i_return = 0;
@@ -406,7 +416,7 @@ static void MP4_TrackTimeApplyELST( const mp4_track_t *p_track, uint64_t i_movie
 }
 
 /* Return time in microsecond of a track */
-static inline mtime_t MP4_TrackGetDTS( demux_t *p_demux, mp4_track_t *p_track )
+static inline vlc_tick_t MP4_TrackGetDTS( demux_t *p_demux, mp4_track_t *p_track )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     const mp4_chunk_t *p_chunk = &p_track->chunk[p_track->i_chunk];
@@ -417,22 +427,69 @@ static inline mtime_t MP4_TrackGetDTS( demux_t *p_demux, mp4_track_t *p_track )
     /* now handle elst */
     MP4_TrackTimeApplyELST( p_track, p_sys->i_timescale, &sdts );
 
-    return MP4_rescale( sdts, p_track->i_timescale, CLOCK_FREQ );
+    return MP4_rescale_mtime( sdts, p_track->i_timescale );
 }
 
 static inline bool MP4_TrackGetPTSDelta( demux_t *p_demux, const mp4_track_t *p_track,
-                                         mtime_t *pi_delta )
+                                         vlc_tick_t *pi_delta )
 {
     VLC_UNUSED( p_demux );
     const mp4_chunk_t *ck = &p_track->chunk[p_track->i_chunk];
     stime_t delta;
     if( !MP4_ChunkGetSampleCTSDelta( ck, p_track->i_sample - ck->i_sample_first, &delta ) )
         return false;
-    *pi_delta = MP4_rescale( delta, p_track->i_timescale, CLOCK_FREQ );
+    *pi_delta = MP4_rescale_mtime( delta, p_track->i_timescale );
     return true;
 }
 
-static inline int64_t MP4_GetMoviePTS(demux_sys_t *p_sys )
+static inline mtime_t MP4_GetSamplesDuration( demux_t *p_demux, mp4_track_t *p_track,
+                                              unsigned i_nb_samples )
+{
+    VLC_UNUSED( p_demux );
+
+    const mp4_chunk_t *p_chunk = &p_track->chunk[p_track->i_chunk];
+    stime_t i_duration = 0;
+
+    /* Forward to right index, and set remaining count in that index */
+    unsigned i_index = 0;
+    unsigned i_remain = 0;
+    for( unsigned i = p_chunk->i_sample_first;
+         i<p_track->i_sample && i_index < p_chunk->i_entries_dts; )
+    {
+        if( p_track->i_sample - i >= p_chunk->p_sample_count_dts[i_index] )
+        {
+            i += p_chunk->p_sample_count_dts[i_index];
+            i_index++;
+        }
+        else
+        {
+            i_remain = p_track->i_sample - i;
+            break;
+        }
+    }
+
+    /* Compute total duration from all samples from index */
+    while( i_nb_samples > 0 && i_index < p_chunk->i_entries_dts )
+    {
+        if( i_nb_samples >= p_chunk->p_sample_count_dts[i_index] - i_remain )
+        {
+            i_duration += (p_chunk->p_sample_count_dts[i_index] - i_remain) *
+                          (int64_t) p_chunk->p_sample_delta_dts[i_index];
+            i_nb_samples -= (p_chunk->p_sample_count_dts[i_index] - i_remain);
+            i_index++;
+            i_remain = 0;
+        }
+        else
+        {
+            i_duration += i_nb_samples * p_chunk->p_sample_delta_dts[i_index];
+            break;
+        }
+    }
+
+    return MP4_rescale_mtime( i_duration, p_track->i_timescale );
+}
+
+static inline vlc_tick_t MP4_GetMoviePTS(demux_sys_t *p_sys )
 {
     return p_sys->i_nztime;
 }
@@ -544,7 +601,7 @@ static uint32_t MP4_TrackGetRunSeq( mp4_track_t *p_track )
 
 /* Analyzes chunks to find max interleave length
  * sets flat flag if no interleaving is in use */
-static void MP4_GetInterleaving( demux_t *p_demux, uint64_t *pi_max_contiguous, bool *pb_flat )
+static void MP4_GetInterleaving( demux_t *p_demux, vlc_tick_t *pi_max_contiguous, bool *pb_flat )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
     *pi_max_contiguous = 0;
@@ -588,9 +645,9 @@ static void MP4_GetInterleaving( demux_t *p_demux, uint64_t *pi_max_contiguous,
 
         if( tk != nexttk )
         {
-            i_duration = MP4_rescale( i_duration, tk->i_timescale, CLOCK_FREQ );
-            if( i_duration > *pi_max_contiguous )
-                *pi_max_contiguous = i_duration;
+            vlc_tick_t i_dur = MP4_rescale_mtime( i_duration, tk->i_timescale );
+            if( i_dur > *pi_max_contiguous )
+                *pi_max_contiguous = i_dur;
             i_duration = 0;
 
             if( tk->i_chunk != tk->i_chunk_count )
@@ -1067,7 +1124,7 @@ static int Open( vlc_object_t * p_this )
 
     if( p_sys->i_tracks > 1 && !p_sys->b_fastseekable )
     {
-        uint64_t i_max_continuity;
+        vlc_tick_t i_max_continuity;
         bool b_flat;
         MP4_GetInterleaving( p_demux, &i_max_continuity, &b_flat );
         if( b_flat )
@@ -1292,7 +1349,7 @@ static int DemuxTrack( demux_t *p_demux, mp4_track_t *tk, uint64_t i_readpos,
         if( i_samplessize > 0 )
         {
             block_t *p_block;
-            int64_t i_delta;
+            vlc_tick_t i_delta;
 
             if( vlc_stream_Tell( p_demux->s ) != i_readpos )
             {
@@ -1335,6 +1392,8 @@ static int DemuxTrack( demux_t *p_demux, mp4_track_t *tk, uint64_t i_readpos,
             else
                 p_block->i_pts = VLC_TICK_INVALID;
 
+            p_block->i_length = MP4_GetSamplesDuration( p_demux, tk, i_nb_samples );
+
             MP4_Block_Send( p_demux, tk, p_block );
         }
 
@@ -1592,8 +1651,8 @@ static vlc_tick_t FragGetDemuxTimeFromTracksTime( demux_sys_t *p_sys )
     {
         if( p_sys->track[i].context.runs.i_count == 0 )
             continue;
-        vlc_tick_t i_ttime = MP4_rescale( p_sys->track[i].i_time,
-                                       p_sys->track[i].i_timescale, CLOCK_FREQ );
+        vlc_tick_t i_ttime = MP4_rescale_mtime( p_sys->track[i].i_time,
+                                             p_sys->track[i].i_timescale );
         i_time = __MIN( i_time, i_ttime );
     }
     return i_time;
@@ -1741,7 +1800,7 @@ static int FragSeekToTime( demux_t *p_demux, vlc_tick_t i_nztime, bool b_accurat
     const unsigned i_seek_track_index = GetSeekTrackIndex( p_sys );
     const unsigned i_seek_track_ID = p_sys->track[i_seek_track_index].i_track_ID;
 
-    if( MP4_rescale( i_nztime, CLOCK_FREQ, p_sys->i_timescale )
+    if( MP4_rescale_qtime( i_nztime, p_sys->i_timescale )
                      < GetMoovTrackDuration( p_sys, i_seek_track_ID ) )
     {
         i64 = p_sys->p_moov->i_pos;
@@ -1750,7 +1809,7 @@ static int FragSeekToTime( demux_t *p_demux, vlc_tick_t i_nztime, bool b_accurat
     else if( FragGetMoofBySidxIndex( p_demux, i_nztime, &i64, &i_sync_time ) == VLC_SUCCESS )
     {
         /* provides base offset */
-        i_segment_time = MP4_rescale( i_sync_time, CLOCK_FREQ, p_sys->i_timescale );
+        i_segment_time = MP4_rescale_qtime( i_sync_time, p_sys->i_timescale );
         msg_Dbg( p_demux, "seeking to sidx moof pos %" PRId64 " %" PRId64, i64, i_sync_time );
     }
     else
@@ -1769,14 +1828,14 @@ static int FragSeekToTime( demux_t *p_demux, vlc_tick_t i_nztime, bool b_accurat
 
         if( p_sys->b_fragments_probed && p_sys->p_fragsindex )
         {
-            stime_t i_basetime = MP4_rescale( i_sync_time, CLOCK_FREQ, p_sys->i_timescale );
+            stime_t i_basetime = MP4_rescale_qtime( i_sync_time, p_sys->i_timescale );
             if( !MP4_Fragments_Index_Lookup( p_sys->p_fragsindex, &i_basetime, &i64, i_seek_track_index ) )
             {
                 p_sys->b_error = (vlc_stream_Seek( p_demux->s, i_backup_pos ) != VLC_SUCCESS);
                 return VLC_EGENERIC;
             }
             msg_Dbg( p_demux, "seeking to fragment index pos %" PRId64 " %" PRId64, i64,
-                     MP4_rescale( i_basetime, p_sys->i_timescale, CLOCK_FREQ ) );
+                     MP4_rescale_mtime( i_basetime, p_sys->i_timescale ) );
         }
     }
 
@@ -1814,7 +1873,7 @@ static int FragSeekToTime( demux_t *p_demux, vlc_tick_t i_nztime, bool b_accurat
         }
         else
         {
-            stime_t i_tst = MP4_rescale( i_sync_time, CLOCK_FREQ, p_sys->track[i].i_timescale );
+            stime_t i_tst = MP4_rescale_qtime( i_sync_time, p_sys->track[i].i_timescale );
             FragTrunSeekToTime( &p_sys->track[i], i_tst );
             p_sys->track[i].i_next_block_flags |= BLOCK_FLAG_DISCONTINUITY;
         }
@@ -1847,7 +1906,7 @@ static int FragSeekToPos( demux_t *p_demux, double f, bool b_accurate )
         return VLC_EGENERIC;
 
     return FragSeekToTime( p_demux, (vlc_tick_t)( f *
-                           MP4_rescale( i_duration, p_sys->i_timescale, CLOCK_FREQ ) ), b_accurate );
+                           MP4_rescale_mtime( i_duration, p_sys->i_timescale ) ), b_accurate );
 }
 
 static bool imageTypeCompatible( const MP4_Box_data_data_t *p_data )
@@ -1937,7 +1996,7 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             if( i_duration > 0 )
             {
                 *pf = (double)p_sys->i_nztime /
-                      MP4_rescale( i_duration, p_sys->i_timescale, CLOCK_FREQ );
+                      MP4_rescale_mtime( i_duration, p_sys->i_timescale );
             }
             else
             {
@@ -1952,8 +2011,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                 return FragSeekToPos( p_demux, f, b );
             else if( p_sys->i_timescale > 0 )
             {
-                i64 = (int64_t)( f * MP4_rescale( p_sys->i_duration,
-                                                  p_sys->i_timescale, CLOCK_FREQ ) );
+                i64 = (int64_t)( f * MP4_rescale_mtime( p_sys->i_duration,
+                                                        p_sys->i_timescale ) );
                 return Seek( p_demux, i64, b );
             }
             else return VLC_EGENERIC;
@@ -1978,8 +2037,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
             pi64 = va_arg( args, int64_t * );
             if( p_sys->i_timescale > 0 )
             {
-                *pi64 = MP4_rescale( i_duration,
-                                     p_sys->i_timescale, CLOCK_FREQ );
+                *pi64 = MP4_rescale_mtime( i_duration,
+                                           p_sys->i_timescale );
             }
             else *pi64 = 0;
             return VLC_SUCCESS;
@@ -2155,8 +2214,8 @@ static int Control( demux_t *p_demux, int i_query, va_list args )
                      BOXDATA(p_load)->i_duration > 0 )
                 {
                     *va_arg(args, int64_t *) =
-                            MP4_rescale( BOXDATA(p_load)->i_duration,
-                                         p_sys->track[i].i_timescale, CLOCK_FREQ );
+                            MP4_rescale_mtime( BOXDATA(p_load)->i_duration,
+                                               p_sys->track[i].i_timescale );
                     return VLC_SUCCESS;
                 }
             }
@@ -2258,8 +2317,8 @@ static void LoadChapterApple( demux_t  *p_demux, mp4_track_t *tk )
 
     for( tk->i_sample = 0; tk->i_sample < tk->i_sample_count; tk->i_sample++ )
     {
-        const int64_t i_dts = MP4_TrackGetDTS( p_demux, tk );
-        int64_t i_pts_delta;
+        const vlc_tick_t i_dts = MP4_TrackGetDTS( p_demux, tk );
+        vlc_tick_t i_pts_delta;
         if ( !MP4_TrackGetPTSDelta( p_demux, tk, &i_pts_delta ) )
             i_pts_delta = 0;
         uint32_t i_nb_samples = 0;
@@ -2346,8 +2405,7 @@ static void LoadChapter( demux_t  *p_demux )
     {
         const uint64_t i_duration = __MAX(p_sys->i_duration, p_sys->i_cumulated_duration);
         p_sys->p_title->i_length =
-                MP4_rescale( i_duration,
-                             p_sys->i_timescale, CLOCK_FREQ );
+                MP4_rescale_mtime( i_duration, p_sys->i_timescale );
     }
 }
 
@@ -3032,7 +3090,7 @@ static int TrackGetNearestSeekPoint( demux_t *p_demux, mp4_track_t *p_track,
  * it also update elst field of the track
  */
 static int TrackTimeToSampleChunk( demux_t *p_demux, mp4_track_t *p_track,
-                                   int64_t i_start, uint32_t *pi_chunk,
+                                   vlc_tick_t i_start, uint32_t *pi_chunk,
                                    uint32_t *pi_sample )
 {
     demux_sys_t *p_sys = p_demux->p_sys;
@@ -3050,12 +3108,11 @@ static int TrackTimeToSampleChunk( demux_t *p_demux, mp4_track_t *p_track,
     if( p_track->p_elst && p_track->BOXDATA(p_elst)->i_entry_count > 0 )
     {
         MP4_Box_data_elst_t *elst = p_track->BOXDATA(p_elst);
-        int64_t i_mvt= MP4_rescale( i_start, CLOCK_FREQ, p_sys->i_timescale );
+        int64_t i_mvt= MP4_rescale_qtime( i_start, p_sys->i_timescale );
 
         /* now calculate i_start for this elst */
         /* offset */
-        i_start -= MP4_rescale( p_track->i_elst_time, p_sys->i_timescale, CLOCK_FREQ );
-        if( i_start < 0 )
+        if( i_start < MP4_rescale_mtime( p_track->i_elst_time, p_sys->i_timescale ) )
         {
             *pi_chunk = 0;
             *pi_sample= 0;
@@ -3063,7 +3120,7 @@ static int TrackTimeToSampleChunk( demux_t *p_demux, mp4_track_t *p_track,
             return VLC_SUCCESS;
         }
         /* to track time scale */
-        i_start  = MP4_rescale( i_start, CLOCK_FREQ, p_track->i_timescale );
+        i_start  = MP4_rescale_qtime( i_start, p_track->i_timescale );
         /* add elst offset */
         if( ( elst->i_media_rate_integer[p_track->i_elst] > 0 ||
              elst->i_media_rate_fraction[p_track->i_elst] > 0 ) &&
@@ -3080,7 +3137,7 @@ static int TrackTimeToSampleChunk( demux_t *p_demux, mp4_track_t *p_track,
     else
     {
         /* convert absolute time to in timescale unit */
-        i_start = MP4_rescale( i_start, CLOCK_FREQ, p_track->i_timescale );
+        i_start = MP4_rescale_qtime( i_start, p_track->i_timescale );
     }
 
     /* we start from sample 0/chunk 0, hope it won't take too much time */
@@ -3940,8 +3997,8 @@ static int MP4_TrackNextSample( demux_t *p_demux, mp4_track_t *p_track, uint32_t
     {
         demux_sys_t *p_sys = p_demux->p_sys;
         MP4_Box_data_elst_t *elst = p_track->BOXDATA(p_elst);
-        uint64_t i_mvt = MP4_rescale( MP4_TrackGetDTS( p_demux, p_track ),
-                                      CLOCK_FREQ, p_sys->i_timescale );
+        uint64_t i_mvt = MP4_rescale_qtime( MP4_TrackGetDTS( p_demux, p_track ),
+                                            p_sys->i_timescale );
         if( (unsigned int)p_track->i_elst < elst->i_entry_count &&
             i_mvt >= p_track->i_elst_time +
                      elst->i_segment_duration[p_track->i_elst] )
@@ -3966,7 +4023,7 @@ static void MP4_TrackSetELST( demux_t *p_demux, mp4_track_t *tk,
     if( tk->p_elst && tk->BOXDATA(p_elst)->i_entry_count > 0 )
     {
         MP4_Box_data_elst_t *elst = tk->BOXDATA(p_elst);
-        int64_t i_mvt= MP4_rescale( i_time, CLOCK_FREQ, p_sys->i_timescale );
+        int64_t i_mvt= MP4_rescale_qtime( i_time, p_sys->i_timescale );
 
         for( tk->i_elst = 0; (unsigned int)tk->i_elst < elst->i_entry_count; tk->i_elst++ )
         {
@@ -4383,7 +4440,7 @@ static int FragDemuxTrack( demux_t *p_demux, mp4_track_t *p_track,
         return VLC_DEMUXER_EOF;
 
     const stime_t i_demux_max_dts = (i_max_preload < UINT_MAX) ?
-                p_track->i_time + MP4_rescale( i_max_preload, CLOCK_FREQ, p_track->i_timescale ) :
+                p_track->i_time + MP4_rescale_qtime( i_max_preload, p_track->i_timescale ) :
                 INT64_MAX;
 
     for( uint32_t i = p_track->context.i_trun_sample; i < p_trun->i_sample_count; i++ )
@@ -4433,18 +4490,18 @@ static int FragDemuxTrack( demux_t *p_demux, mp4_track_t *p_track,
 
 #if 0
         msg_Dbg( p_demux, "tk(%i)=%"PRId64" mv=%"PRId64" pos=%"PRIu64, p_track->i_track_ID,
-                 VLC_TICK_0 + MP4_rescale( i_dts, p_track->i_timescale, CLOCK_FREQ ),
-                 VLC_TICK_0 + MP4_rescale( i_pts, p_track->i_timescale, CLOCK_FREQ ),
+                 VLC_TICK_0 + MP4_rescale_mtime( i_dts, p_track->i_timescale ),
+                 VLC_TICK_0 + MP4_rescale_mtime( i_pts, p_track->i_timescale ),
                  p_track->context.i_trun_sample_pos - i_read );
 #endif
         if ( p_track->p_es )
         {
-            p_block->i_dts = VLC_TICK_0 + MP4_rescale( i_dts, p_track->i_timescale, CLOCK_FREQ );
+            p_block->i_dts = VLC_TICK_0 + MP4_rescale_mtime( i_dts, p_track->i_timescale );
             if( p_track->fmt.i_cat == VIDEO_ES && !( p_trun->i_flags & MP4_TRUN_SAMPLE_TIME_OFFSET ) )
                 p_block->i_pts = VLC_TICK_INVALID;
             else
-                p_block->i_pts = VLC_TICK_0 + MP4_rescale( i_pts, p_track->i_timescale, CLOCK_FREQ );
-            p_block->i_length = MP4_rescale( dur, p_track->i_timescale, CLOCK_FREQ );
+                p_block->i_pts = VLC_TICK_0 + MP4_rescale_mtime( i_pts, p_track->i_timescale );
+            p_block->i_length = MP4_rescale_mtime( dur, p_track->i_timescale );
             MP4_Block_Send( p_demux, p_track, p_block );
         }
         else block_Release( p_block );
@@ -4500,7 +4557,7 @@ static int DemuxMoof( demux_t *p_demux )
             /* At least still have data to demux on this or next turns */
             i_status = VLC_DEMUXER_SUCCESS;
 
-            if( MP4_rescale( tk_tmp->i_time, tk_tmp->i_timescale, CLOCK_FREQ ) <= i_nztime + DEMUX_INCREMENT )
+            if( MP4_rescale_mtime( tk_tmp->i_time, tk_tmp->i_timescale ) <= i_nztime + DEMUX_INCREMENT )
             {
                 if( tk == NULL || tk_tmp->context.i_trun_sample_pos < tk->context.i_trun_sample_pos )
                     tk = tk_tmp;
@@ -4522,7 +4579,7 @@ static int DemuxMoof( demux_t *p_demux )
                     tk_tmp->context.i_temp != VLC_DEMUXER_SUCCESS )
                     continue;
 
-                vlc_tick_t i_nzdts = MP4_rescale( tk_tmp->i_time, tk_tmp->i_timescale, CLOCK_FREQ );
+                vlc_tick_t i_nzdts = MP4_rescale_mtime( tk_tmp->i_time, tk_tmp->i_timescale );
                 if ( i_nzdts <= i_nztime + DEMUX_TRACK_MAX_PRELOAD )
                 {
                     /* Found a better candidate to avoid seeking */
@@ -4560,7 +4617,7 @@ static int DemuxMoof( demux_t *p_demux )
             if( tk->b_ok || tk->b_chapters_source ||
                (!tk->b_selected && !p_sys->b_seekable) )
                 continue;
-            vlc_tick_t i_track_end = MP4_rescale( tk->i_time, tk->i_timescale, CLOCK_FREQ );
+            vlc_tick_t i_track_end = MP4_rescale_mtime( tk->i_time, tk->i_timescale );
             if( i_track_end < i_segment_end  )
                 i_segment_end = i_track_end;
         }
@@ -4690,7 +4747,7 @@ static int FragCreateTrunIndex( demux_t *p_demux, MP4_Box_t *p_moof,
                 if( i_moof_time != INT64_MAX )
                     i_traf_start_time = MP4_rescale( i_moof_time, p_sys->i_timescale, p_track->i_timescale );
                 else /* That should not happen */
-                    i_traf_start_time = MP4_rescale( p_sys->i_nztime, CLOCK_FREQ, p_track->i_timescale );
+                    i_traf_start_time = MP4_rescale_qtime( p_sys->i_nztime, p_track->i_timescale );
             }
         }
 
@@ -4762,7 +4819,7 @@ static int FragCreateTrunIndex( demux_t *p_demux, MP4_Box_t *p_moof,
                      p_track->context.runs.i_count,
                      i_track_defaultsampleduration,
                      i_track_defaultsamplesize,
-                     MP4_rescale( i_trun_dts, p_track->i_timescale, CLOCK_FREQ ), i_trun_data_offset );
+                     MP4_rescale_mtime( i_trun_dts, p_track->i_timescale ), i_trun_data_offset );
 #endif
             //************
             mp4_run_t *p_run = &p_track->context.runs.p_array[p_track->context.runs.i_count++];
@@ -4804,7 +4861,7 @@ static int FragCreateTrunIndex( demux_t *p_demux, MP4_Box_t *p_moof,
     return VLC_SUCCESS;
 }
 
-static int FragGetMoofBySidxIndex( demux_t *p_demux, vlc_tick_t i_target_time,
+static int FragGetMoofBySidxIndex( demux_t *p_demux, vlc_tick_t target_time,
                                    uint64_t *pi_moof_pos, vlc_tick_t *pi_sampletime )
 {
     const MP4_Box_t *p_sidx = MP4_BoxGet( p_demux->p_sys->p_root, "sidx" );
@@ -4812,7 +4869,7 @@ static int FragGetMoofBySidxIndex( demux_t *p_demux, vlc_tick_t i_target_time,
     if( !p_sidx || !((p_data = BOXDATA(p_sidx))) || !p_data->i_timescale )
         return VLC_EGENERIC;
 
-    i_target_time = MP4_rescale( i_target_time, CLOCK_FREQ, p_data->i_timescale );
+    stime_t i_target_time = MP4_rescale_qtime( target_time, p_data->i_timescale );
 
     /* sidx refers to offsets from end of sidx pos in the file + first offset */
     uint64_t i_pos = p_data->i_first_offset + p_sidx->i_pos + p_sidx->i_size;
@@ -4823,7 +4880,7 @@ static int FragGetMoofBySidxIndex( demux_t *p_demux, vlc_tick_t i_target_time,
             continue;
         if( i_time + p_data->p_items[i].i_subsegment_duration > i_target_time )
         {
-            *pi_sampletime = MP4_rescale( i_time, p_data->i_timescale, CLOCK_FREQ );
+            *pi_sampletime = MP4_rescale_mtime( i_time, p_data->i_timescale );
             *pi_moof_pos = i_pos;
             return VLC_SUCCESS;
         }
@@ -4850,7 +4907,7 @@ static int FragGetMoofByTfraIndex( demux_t *p_demux, const vlc_tick_t i_target_t
             mp4_track_t *p_track = MP4_GetTrackByTrackID( p_demux, p_data->i_track_ID );
             if ( p_track )
             {
-                stime_t i_track_target_time = MP4_rescale( i_target_time, CLOCK_FREQ, p_track->i_timescale );
+                stime_t i_track_target_time = MP4_rescale_qtime( i_target_time, p_track->i_timescale );
                 for ( uint32_t i = 0; i<p_data->i_number_of_entries; i += ( p_data->i_version == 1 ) ? 2 : 1 )
                 {
                     vlc_tick_t i_time;
@@ -4872,7 +4929,7 @@ static int FragGetMoofByTfraIndex( demux_t *p_demux, const vlc_tick_t i_target_t
                             break;
 
                         *pi_moof_pos = i_pos;
-                        *pi_sampletime = MP4_rescale( i_time, p_track->i_timescale, CLOCK_FREQ );
+                        *pi_sampletime = MP4_rescale_mtime( i_time, p_track->i_timescale );
                         return VLC_SUCCESS;
                     }
                     else
@@ -5078,7 +5135,7 @@ end:
         for( unsigned i = 0; i < p_sys->i_tracks; i++ )
         {
             const mp4_track_t *tk = &p_sys->track[i];
-            vlc_tick_t i_track_end = MP4_rescale( tk->i_time, tk->i_timescale, CLOCK_FREQ );
+            vlc_tick_t i_track_end = MP4_rescale_mtime( tk->i_time, tk->i_timescale );
             if( i_track_end > i_demux_end  )
                 i_demux_end = i_track_end;
         }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/be426a636a356e16a4b2f22790624748c338987a...c6883f9365a1c1bcb93482e53d8a92adcba4bd87

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/be426a636a356e16a4b2f22790624748c338987a...c6883f9365a1c1bcb93482e53d8a92adcba4bd87
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list