Skip to content

Commit 94d8519

Browse files
committed
Allow getting the timescale when demuxing AVIF.
1 parent 888ce90 commit 94d8519

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

mp4parse_capi/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ pub unsafe extern "C" fn mp4parse_avif_get_indice_table(
12971297
parser: *mut Mp4parseAvifParser,
12981298
track_id: u32,
12991299
indices: *mut Mp4parseByteData,
1300+
timescale: *mut u64,
13001301
) -> Mp4parseStatus {
13011302
if parser.is_null() {
13021303
return Mp4parseStatus::BadArg;
@@ -1306,10 +1307,35 @@ pub unsafe extern "C" fn mp4parse_avif_get_indice_table(
13061307
return Mp4parseStatus::BadArg;
13071308
}
13081309

1310+
if timescale.is_null() {
1311+
return Mp4parseStatus::BadArg;
1312+
}
1313+
13091314
// Initialize fields to default values to ensure all fields are always valid.
13101315
*indices = Default::default();
13111316

13121317
if let Some(sequence) = &(*parser).context.sequence {
1318+
// Use the top level timescale, and the track timescale if present.
1319+
let mut found_timescale = false;
1320+
if let Some(context_timescale) = sequence.timescale {
1321+
*timescale = context_timescale.0;
1322+
found_timescale = true;
1323+
}
1324+
let maybe_track_timescale = match sequence
1325+
.tracks
1326+
.iter()
1327+
.find(|track| track.track_id == Some(track_id))
1328+
{
1329+
Some(track) => track.timescale,
1330+
_ => None,
1331+
};
1332+
if let Some(track_timescale) = maybe_track_timescale {
1333+
found_timescale = true;
1334+
*timescale = track_timescale.0;
1335+
}
1336+
if !found_timescale {
1337+
return Mp4parseStatus::Invalid;
1338+
}
13131339
return get_indice_table(
13141340
sequence,
13151341
&mut (*parser).sample_table,

0 commit comments

Comments
 (0)