[vlc-commits] demux: mp4: set samples duration
Francois Cartegnie
git at videolan.org
Fri Jan 5 17:13:31 CET 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jan 4 19:40:31 2018 +0100| [096500ddebd4d621ea8ce96cdd93baa2ce05a2a8] | committer: Francois Cartegnie
demux: mp4: set samples duration
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=096500ddebd4d621ea8ce96cdd93baa2ce05a2a8
---
modules/demux/mp4/mp4.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/modules/demux/mp4/mp4.c b/modules/demux/mp4/mp4.c
index 5be7031a1f..ee984fb764 100644
--- a/modules/demux/mp4/mp4.c
+++ b/modules/demux/mp4/mp4.c
@@ -369,6 +369,53 @@ static inline bool MP4_TrackGetPTSDelta( demux_t *p_demux, mp4_track_t *p_track,
return false;
}
+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( i_duration, p_track->i_timescale, CLOCK_FREQ );
+}
+
static inline int64_t MP4_GetMoviePTS(demux_sys_t *p_sys )
{
return p_sys->i_nztime;
@@ -1237,6 +1284,8 @@ static int DemuxTrack( demux_t *p_demux, mp4_track_t *tk, uint64_t i_readpos,
else
p_block->i_pts = VLC_TS_INVALID;
+ p_block->i_length = MP4_GetSamplesDuration( p_demux, tk, i_nb_samples );
+
MP4_Block_Send( p_demux, tk, p_block );
}
More information about the vlc-commits
mailing list