Skip to content

Commit

Permalink
feat: add option to treat all trun boxes as version 1 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenda6 authored Feb 2, 2024
1 parent 904b590 commit 0ea43c5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/github-dev-snap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
cmake \
-DCMAKE_BUILD_TYPE="Release" \
-DBUILD_SHARED_LIBS=1 \
-DUSE_WORKAROUND_FOR_TRUN_VERSION_0=1 \
-S . \
-B build/
Expand Down
4 changes: 4 additions & 0 deletions packager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ else()
add_compile_options(-Wno-unknown-warning-option)
endif()

if(USE_WORKAROUND_FOR_TRUN_VERSION_0)
add_definitions(-DUSE_WORKAROUND_FOR_TRUN_VERSION_0=1)
endif()

# Global include paths.
# Project root, to reference internal headers as packager/foo/bar/...
include_directories(..)
Expand Down
8 changes: 8 additions & 0 deletions packager/media/formats/mp4/box_definitions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2716,6 +2716,13 @@ bool TrackFragmentRun::ReadWriteInternal(BoxBuffer* buffer) {
RCHECK(buffer->ReadWriteUInt32(&sample_flags[i]));

if (sample_composition_time_offsets_present) {
// TODO: MediaLive produces negative composition time offsets in box version 0.
// This is a workaround for that.
#ifdef USE_WORKAROUND_FOR_TRUN_VERSION_0
int32_t sample_offset = sample_composition_time_offsets[i];
RCHECK(buffer->ReadWriteInt32(&sample_offset));
sample_composition_time_offsets[i] = sample_offset;
#else
if (version == 0) {
uint32_t sample_offset = sample_composition_time_offsets[i];
RCHECK(buffer->ReadWriteUInt32(&sample_offset));
Expand All @@ -2725,6 +2732,7 @@ bool TrackFragmentRun::ReadWriteInternal(BoxBuffer* buffer) {
RCHECK(buffer->ReadWriteInt32(&sample_offset));
sample_composition_time_offsets[i] = sample_offset;
}
#endif
}
}

Expand Down

0 comments on commit 0ea43c5

Please sign in to comment.