[vlc-commits] demux: mp4: only have unsigned pts offsets

Francois Cartegnie git at videolan.org
Sun Feb 7 20:21:46 UTC 2021


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Feb  4 21:09:21 2021 +0100| [5132db8ad6840d04fbca1a0ea23db5cd1e5ac0a6] | committer: Francois Cartegnie

demux: mp4: only have unsigned pts offsets

since dts_shift is always computed, that should be
always positive.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5132db8ad6840d04fbca1a0ea23db5cd1e5ac0a6
---

 modules/demux/mp4/mp4.c | 13 ++++++++-----
 modules/demux/mp4/mp4.h |  2 +-
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 2f12ab7c7e..9a838c95ae 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -2720,7 +2720,7 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
 
             /* allocate them */
             ck->p_sample_count_pts = calloc( ck->i_entries_pts, sizeof( uint32_t ) );
-            ck->p_sample_offset_pts = calloc( ck->i_entries_pts, sizeof( int32_t ) );
+            ck->p_sample_offset_pts = calloc( ck->i_entries_pts, sizeof( uint32_t ) );
             if( !ck->p_sample_count_pts || !ck->p_sample_offset_pts )
             {
                 free( ck->p_sample_count_pts );
@@ -2735,12 +2735,15 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
 
             for( uint32_t i = 0; i < ck->i_entries_pts; i++ )
             {
+                int64_t i_ctsdelta = ctts->pi_sample_offset[i_index] + i_cts_shift;
+                if( i_ctsdelta < 0 ) /* should not */
+                    i_ctsdelta = 0;
                 if ( i_current_index_samples_left )
                 {
                     if ( i_current_index_samples_left > i_sample_count )
                     {
                         ck->p_sample_count_pts[i] = i_sample_count;
-                        ck->p_sample_offset_pts[i] = ctts->pi_sample_offset[i_index] + i_cts_shift;
+                        ck->p_sample_offset_pts[i] = i_ctsdelta;
                         i_current_index_samples_left -= i_sample_count;
                         i_sample_count = 0;
                         assert( i == ck->i_entries_pts - 1 );
@@ -2749,7 +2752,7 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
                     else
                     {
                         ck->p_sample_count_pts[i] = i_current_index_samples_left;
-                        ck->p_sample_offset_pts[i] = ctts->pi_sample_offset[i_index] + i_cts_shift;
+                        ck->p_sample_offset_pts[i] = i_ctsdelta;
                         i_sample_count -= i_current_index_samples_left;
                         i_current_index_samples_left = 0;
                         i_index++;
@@ -2760,7 +2763,7 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
                     if ( ctts->pi_sample_count[i_index] > i_sample_count )
                     {
                         ck->p_sample_count_pts[i] = i_sample_count;
-                        ck->p_sample_offset_pts[i] = ctts->pi_sample_offset[i_index] + i_cts_shift;
+                        ck->p_sample_offset_pts[i] = i_ctsdelta;
                         i_current_index_samples_left = ctts->pi_sample_count[i_index] - i_sample_count;
                         i_sample_count = 0;
                         assert( i == ck->i_entries_pts - 1 );
@@ -2769,7 +2772,7 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
                     else
                     {
                         ck->p_sample_count_pts[i] = ctts->pi_sample_count[i_index];
-                        ck->p_sample_offset_pts[i] = ctts->pi_sample_offset[i_index] + i_cts_shift;
+                        ck->p_sample_offset_pts[i] = i_ctsdelta;
                         i_sample_count -= ctts->pi_sample_count[i_index];
                         i_index++;
                     }
diff --git a/modules/demux/mp4/mp4.h b/modules/demux/mp4/mp4.h
index 5dc0bdbe20..27b0adf892 100644
--- a/modules/demux/mp4/mp4.h
+++ b/modules/demux/mp4/mp4.h
@@ -52,7 +52,7 @@ typedef struct
 
     uint32_t     i_entries_pts;
     uint32_t     *p_sample_count_pts;
-    int32_t      *p_sample_offset_pts;  /* pts-dts */
+    uint32_t     *p_sample_offset_pts;  /* pts-dts */
 
     uint32_t     *p_sample_size;
     /* TODO if needed add pts



More information about the vlc-commits mailing list