/* stats */
int64_t i_dts_start;
int64_t i_duration;
+ bool b_hasbframes;
/* for later stco fix-up (fast start files) */
uint64_t i_stco_pos;
calloc(p_stream->i_entry_max, sizeof(mp4_entry_t));
p_stream->i_dts_start = 0;
p_stream->i_duration = 0;
+ p_stream->b_hasbframes = false;
p_input->p_sys = p_stream;
mp4_entry_t *e = &p_stream->entry[p_stream->i_entry_count];
e->i_pos = p_sys->i_pos;
e->i_size = p_data->i_buffer;
- e->i_pts_dts = p_data->i_pts - p_data->i_dts;
- if (e->i_pts_dts < 0)
- e->i_pts_dts = 0;
+
+ if ( p_data->i_dts > VLC_TS_INVALID && p_data->i_pts > p_data->i_dts )
+ {
+ e->i_pts_dts = p_data->i_pts - p_data->i_dts;
+ if ( !p_stream->b_hasbframes )
+ p_stream->b_hasbframes = true;
+ }
+ else e->i_pts_dts = 0;
+
e->i_length = p_data->i_length;
e->i_flags = p_data->i_flags;
}
bo_fix_32be(stts, 12, i_index);
- /* FIXME add ctts ?? FIXME */
+ /* composition time handling */
+ bo_t *ctts = NULL;
+ if ( p_stream->b_hasbframes && (ctts = box_full_new("ctts", 0, 0)) )
+ {
+ bo_add_32be(ctts, 0);
+ i_index = 0;
+ for (unsigned i = 0; i < p_stream->i_entry_count; i_index++)
+ {
+ int i_first = i;
+ mtime_t i_offset = p_stream->entry[i].i_pts_dts;
+
+ for (; i < p_stream->i_entry_count; ++i)
+ if (i == p_stream->i_entry_count || p_stream->entry[i].i_pts_dts != i_offset)
+ break;
+
+ bo_add_32be(ctts, i - i_first); // sample-count
+ bo_add_32be(ctts, i_offset * i_timescale / CLOCK_FREQ ); // sample-offset
+ }
+ bo_fix_32be(ctts, 12, i_index);
+ }
bo_t *stsz = box_full_new("stsz", 0, 0);
int i_size = 0;
box_gather(stbl, stts);
if (stss)
box_gather(stbl, stss);
+ if (ctts)
+ box_gather(stbl, ctts);
box_gather(stbl, stsc);
box_gather(stbl, stsz);
p_stream->i_stco_pos = stbl->len + 16;