Commit 051b8a74 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: mp4: add support for cslg

refs big_buck_bunny_720p_h264.mov
parent 256a0e57
......@@ -1507,6 +1507,32 @@ static int MP4_ReadBox_ctts( stream_t *p_stream, MP4_Box_t *p_box )
MP4_READBOX_EXIT( 1 );
}
static int MP4_ReadBox_cslg( stream_t *p_stream, MP4_Box_t *p_box )
{
MP4_READBOX_ENTER( MP4_Box_data_cslg_t, NULL );
unsigned i_version, i_flags;
MP4_GET1BYTE( i_version );
MP4_GET3BYTES( i_flags );
VLC_UNUSED(i_flags);
if( i_version > 1 )
MP4_READBOX_EXIT( 0 );
#define READ_CSLG(readbytes) {\
readbytes( p_box->data.p_cslg->ct_to_dts_shift );\
readbytes( p_box->data.p_cslg->i_least_delta );\
readbytes( p_box->data.p_cslg->i_max_delta );\
readbytes( p_box->data.p_cslg->i_composition_starttime );\
readbytes( p_box->data.p_cslg->i_composition_endtime ); }
if( i_version == 0 )
READ_CSLG(MP4_GET4BYTES)
else
READ_CSLG(MP4_GET8BYTES)
MP4_READBOX_EXIT( 1 );
}
static int MP4_ReadLengthDescriptor( uint8_t **pp_peek, int64_t *i_read )
{
......@@ -4210,6 +4236,7 @@ static const struct
{ ATOM_dref, MP4_ReadBox_LtdContainer, 0 },
{ ATOM_stts, MP4_ReadBox_stts, ATOM_stbl },
{ ATOM_ctts, MP4_ReadBox_ctts, ATOM_stbl },
{ ATOM_cslg, MP4_ReadBox_cslg, ATOM_stbl },
{ ATOM_stsd, MP4_ReadBox_LtdContainer, ATOM_stbl },
{ ATOM_stsz, MP4_ReadBox_stsz, ATOM_stbl },
{ ATOM_stsc, MP4_ReadBox_stsc, ATOM_stbl },
......
......@@ -87,6 +87,7 @@ typedef int64_t stime_t;
#define ATOM_stbl VLC_FOURCC( 's', 't', 'b', 'l' )
#define ATOM_stts VLC_FOURCC( 's', 't', 't', 's' )
#define ATOM_ctts VLC_FOURCC( 'c', 't', 't', 's' )
#define ATOM_cslg VLC_FOURCC( 'c', 's', 'l', 'g' )
#define ATOM_stsd VLC_FOURCC( 's', 't', 's', 'd' )
#define ATOM_stsz VLC_FOURCC( 's', 't', 's', 'z' )
#define ATOM_stz2 VLC_FOURCC( 's', 't', 'z', '2' )
......@@ -613,6 +614,16 @@ typedef struct MP4_Box_data_ctts_s
} MP4_Box_data_ctts_t;
typedef struct MP4_Box_data_cslg_s
{
int64_t ct_to_dts_shift;
int64_t i_least_delta;
int64_t i_max_delta;
int64_t i_composition_starttime;
int64_t i_composition_endtime;
} MP4_Box_data_cslg_t;
// https://developer.apple.com/library/mac/documentation/QuickTime/QTFF/QTFFChap3/qtff3.html#//apple_ref/doc/uid/TP40000939-CH205-125526
typedef struct MP4_Box_data_colr_s
{
......@@ -1630,6 +1641,7 @@ typedef union MP4_Box_data_s
MP4_Box_data_lcont_t *p_lcont;
MP4_Box_data_stts_t *p_stts;
MP4_Box_data_ctts_t *p_ctts;
MP4_Box_data_cslg_t *p_cslg;
MP4_Box_data_colr_t *p_colr;
MP4_Box_data_sbgp_t *p_sbgp;
......
......@@ -2628,6 +2628,11 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
msg_Warn( p_demux, "CTTS table of %"PRIu32" entries", ctts->i_entry_count );
int64_t i_cts_shift = 0;
const MP4_Box_t *p_cslg = MP4_BoxGet( p_demux_track->p_stbl, "cslg" );
if( p_cslg && BOXDATA(p_cslg) )
i_cts_shift = BOXDATA(p_cslg)->ct_to_dts_shift;
/* Create pts-dts table per chunk */
uint32_t i_index = 0;
uint32_t i_current_index_samples_left = 0;
......@@ -2670,7 +2675,7 @@ static int TrackCreateSamplesIndex( demux_t *p_demux,
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];
ck->p_sample_offset_pts[i] = ctts->pi_sample_offset[i_index] + i_cts_shift;
i_current_index_samples_left -= i_sample_count;
i_sample_count = 0;
assert( i == ck->i_entries_pts - 1 );
......@@ -2679,7 +2684,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];
ck->p_sample_offset_pts[i] = ctts->pi_sample_offset[i_index] + i_cts_shift;
i_sample_count -= i_current_index_samples_left;
i_current_index_samples_left = 0;
i_index++;
......@@ -2690,7 +2695,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];
ck->p_sample_offset_pts[i] = ctts->pi_sample_offset[i_index] + i_cts_shift;
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 );
......@@ -2699,7 +2704,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];
ck->p_sample_offset_pts[i] = ctts->pi_sample_offset[i_index] + i_cts_shift;
i_sample_count -= ctts->pi_sample_count[i_index];
i_index++;
}
......
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