Commit 096500dd authored by François Cartegnie's avatar François Cartegnie 🤞

demux: mp4: set samples duration

parent 35d7ea5e
......@@ -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 );
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment