Skip to content

Commit ae44819

Browse files
committed
Handle non-compliant files
Blackmagic Design DaVinci Resolve Studio can write mp4 file with `ctts version 1` but mark it as `ctts version 0`. Always interpreting the `sample_offset` as signed is safe even if we have `ctts version 0`. We need offset >= 6.6 hours (a frame, after being decoded, should wait 6.6 hours before being displayed) for getting overflow.
1 parent eb35bf7 commit ae44819

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

core/box.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2724,12 +2724,11 @@ void isom_update_cache_timestamp
27242724
static inline uint64_t isom_make_cts
27252725
(
27262726
uint64_t dts,
2727-
uint32_t sample_offset,
2728-
int32_t ctd_shift
2727+
uint32_t sample_offset
27292728
)
27302729
{
27312730
if( sample_offset != ISOM_NON_OUTPUT_SAMPLE_OFFSET )
2732-
return ctd_shift ? (dts + (int32_t)sample_offset) : (dts + sample_offset);
2731+
return dts + (int32_t)sample_offset;
27332732
else
27342733
return LSMASH_TIMESTAMP_UNDEFINED;
27352734
}
@@ -2744,7 +2743,7 @@ static inline uint64_t isom_make_cts_adjust
27442743
)
27452744
{
27462745
if( sample_offset != ISOM_NON_OUTPUT_SAMPLE_OFFSET )
2747-
return ctd_shift ? (dts + (int32_t)sample_offset + ctd_shift) : (dts + sample_offset);
2746+
return dts + (int32_t)sample_offset + ctd_shift;
27482747
else
27492748
return LSMASH_TIMESTAMP_UNDEFINED;
27502749
}

core/timeline.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static int isom_get_cts_from_info_list( isom_timeline_t *timeline, uint32_t samp
461461
isom_sample_info_t *info = (isom_sample_info_t *)lsmash_list_get_entry_data( timeline->info_list, sample_number );
462462
if( !info )
463463
return LSMASH_ERR_NAMELESS;
464-
*cts = isom_make_cts( *cts, info->offset, timeline->ctd_shift );
464+
*cts = isom_make_cts( *cts, info->offset );
465465
return 0;
466466
}
467467

@@ -555,7 +555,7 @@ static lsmash_sample_t *isom_get_lpcm_sample_from_media_timeline( isom_timeline_
555555
return NULL;
556556
/* Get sample info. */
557557
sample->dts = timeline->last_accessed_lpcm_bunch_dts + sample_number_offset * bunch->duration;
558-
sample->cts = isom_make_cts( sample->dts, bunch->offset, timeline->ctd_shift );
558+
sample->cts = isom_make_cts( sample->dts, bunch->offset );
559559
sample->pos = sample_pos;
560560
sample->length = bunch->length;
561561
sample->index = bunch->index;
@@ -578,7 +578,7 @@ static lsmash_sample_t *isom_get_sample_from_media_timeline( isom_timeline_t *ti
578578
return NULL;
579579
/* Get sample info. */
580580
sample->dts = dts;
581-
sample->cts = isom_make_cts( dts, info->offset, timeline->ctd_shift );
581+
sample->cts = isom_make_cts( dts, info->offset );
582582
sample->pos = info->pos;
583583
sample->length = info->length;
584584
sample->index = info->index;
@@ -593,7 +593,7 @@ static int isom_get_lpcm_sample_info_from_media_timeline( isom_timeline_t *timel
593593
return LSMASH_ERR_NAMELESS;
594594
uint64_t sample_number_offset = sample_number - timeline->last_accessed_lpcm_bunch_first_sample_number;
595595
sample->dts = timeline->last_accessed_lpcm_bunch_dts + sample_number_offset * bunch->duration;
596-
sample->cts = isom_make_cts( sample->dts, bunch->offset, timeline->ctd_shift );
596+
sample->cts = isom_make_cts( sample->dts, bunch->offset );
597597
sample->pos = bunch->pos + sample_number_offset * bunch->length;
598598
sample->length = bunch->length;
599599
sample->index = bunch->index;
@@ -611,7 +611,7 @@ static int isom_get_sample_info_from_media_timeline( isom_timeline_t *timeline,
611611
if( !info )
612612
return LSMASH_ERR_NAMELESS;
613613
sample->dts = dts;
614-
sample->cts = isom_make_cts( dts, info->offset, timeline->ctd_shift );
614+
sample->cts = isom_make_cts( dts, info->offset );
615615
sample->pos = info->pos;
616616
sample->length = info->length;
617617
sample->index = info->index;
@@ -2018,7 +2018,7 @@ int lsmash_get_media_timestamps( lsmash_root_t *root, uint32_t track_ID, lsmash_
20182018
return LSMASH_ERR_NAMELESS;
20192019
}
20202020
ts[i].dts = dts;
2021-
ts[i].cts = isom_make_cts( dts, info->offset, timeline->ctd_shift );
2021+
ts[i].cts = isom_make_cts( dts, info->offset );
20222022
dts += info->duration;
20232023
++i;
20242024
}
@@ -2034,7 +2034,7 @@ int lsmash_get_media_timestamps( lsmash_root_t *root, uint32_t track_ID, lsmash_
20342034
for( uint32_t j = 0; j < bunch->sample_count; j++ )
20352035
{
20362036
ts[i].dts = dts;
2037-
ts[i].cts = isom_make_cts( dts, bunch->offset, timeline->ctd_shift );
2037+
ts[i].cts = isom_make_cts( dts, bunch->offset );
20382038
dts += bunch->duration;
20392039
++i;
20402040
}

0 commit comments

Comments
 (0)