Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sgpd_versions' into bugfix/memor…
Browse files Browse the repository at this point in the history
…y_leak
  • Loading branch information
podborski committed Jan 3, 2024
2 parents bb70213 + 490628f commit 1f76495
Show file tree
Hide file tree
Showing 23 changed files with 414 additions and 95 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check for C/C++ programs.
uses: jidicula/clang-format-action@v4.4.1
uses: jidicula/clang-format-action@v4.11.0
with:
clang-format-version: '13'
clang-format-version: '15'
check-path: 'IsoLib/libisomediafile'
20 changes: 20 additions & 0 deletions IsoLib/libisomediafile/src/ISOMovies.h
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,26 @@ extern "C"
* @todo rename the function to ISOGetOriginalFormat and parse the cinf and sinf as well
*/
ISO_EXTERN(ISOErr) ISOGetRESVOriginalFormat(MP4Handle sampleEntryH, u32 *outOrigFmt);
/**
* @brief Get scheme_type and scheme_version from the SchemeTypeBox in resv
* @ingroup SampleDescr
* @param sampleEntryH resv sample entry data
* @param schemeType [out] scheme_type 4CC
* @param schemeVersion [out] scheme_version
* @param schemeURI [out] scheme_uri
*/
ISO_EXTERN(ISOErr)
ISOGetRESVSchemeType(MP4Handle sampleEntryH, u32 *schemeType, u32 *schemeVersion,
char **schemeURI);
/**
* @brief Get the box from the SchemeInformationBox in resv
* @ingroup SampleDescr
* @param sampleEntryH resv sample entry data
* @param atomType type of the atom inside SchemeInformationBox
* @param outAtom [out] data of the found box
*/
ISO_EXTERN(ISOErr)
ISOGetRESVSchemeInfoAtom(MP4Handle sampleEntryH, u32 atomType, MP4Handle outAtom);
/**
* @brief Create a new HEVC sample entry.
* @ingroup SampleDescr
Expand Down
59 changes: 56 additions & 3 deletions IsoLib/libisomediafile/src/ISOSampleDescriptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,16 @@ ISOGetSampleDescriptionDimensions(MP4Handle sampleEntryH, u16 *width, u16 *heigh
err = sampleEntryHToAtomPtr(sampleEntryH, (MP4AtomPtr *)&entry, MP4VisualSampleEntryAtomType);
if(err) goto bail;

*width = (u16)entry->width;
*height = (u16)entry->height;
if(entry->type == MP4RestrictedVideoSampleEntryAtomType)
{
*width = (u16)((MP4RestrictedVideoSampleEntryAtomPtr)entry)->width;
*height = (u16)((MP4RestrictedVideoSampleEntryAtomPtr)entry)->height;
}
else
{
*width = (u16)entry->width;
*height = (u16)entry->height;
}

bail:
if(entry) entry->destroy((MP4AtomPtr)entry);
Expand Down Expand Up @@ -1381,7 +1389,8 @@ MP4_EXTERN(MP4Err) ISOGetRESVOriginalFormat(MP4Handle sampleEntryH, u32 *outOrig

if(entry->type != MP4RestrictedVideoSampleEntryAtomType) BAILWITHERROR(MP4BadParamErr);

rinf = (MP4RestrictedSchemeInfoAtomPtr)entry->MP4RestrictedSchemeInfo;
err = entry->getRinf((MP4AtomPtr)entry, (MP4AtomPtr *)&rinf);
if(err) goto bail;
if(!rinf)
{
BAILWITHERROR(MP4BadParamErr);
Expand All @@ -1399,6 +1408,50 @@ MP4_EXTERN(MP4Err) ISOGetRESVOriginalFormat(MP4Handle sampleEntryH, u32 *outOrig
return err;
}

ISO_EXTERN(ISOErr)
ISOGetRESVSchemeType(MP4Handle sampleEntryH, u32 *schemeType, u32 *schemeVersion, char **schemeURI)
{
MP4Err err;
MP4RestrictedVideoSampleEntryAtomPtr entry = NULL;

err = sampleEntryHToAtomPtr(sampleEntryH, (MP4AtomPtr *)&entry, MP4VisualSampleEntryAtomType);
if(err) goto bail;

if(entry->type != MP4RestrictedVideoSampleEntryAtomType) BAILWITHERROR(MP4BadParamErr);

err = entry->getScheme((MP4AtomPtr)entry, schemeType, schemeVersion, schemeURI);
if(err) goto bail;

bail:
if(entry) entry->destroy((MP4AtomPtr)entry);
return err;
}

ISO_EXTERN(ISOErr)
ISOGetRESVSchemeInfoAtom(MP4Handle sampleEntryH, u32 atomType, MP4Handle outAtom)
{
MP4Err err;
MP4RestrictedVideoSampleEntryAtomPtr entry = NULL;
MP4AtomPtr found;

if(outAtom == NULL) BAILWITHERROR(MP4BadParamErr);

err = sampleEntryHToAtomPtr(sampleEntryH, (MP4AtomPtr *)&entry, MP4VisualSampleEntryAtomType);
if(err) goto bail;

if(entry->type != MP4RestrictedVideoSampleEntryAtomType) BAILWITHERROR(MP4BadParamErr);

err = entry->getSchemeInfoAtom((MP4AtomPtr)entry, atomType, &found);
if(err) goto bail;

err = atomPtrToSampleEntryH(outAtom, found);
if(err) goto bail;

bail:
if(entry) entry->destroy((MP4AtomPtr)entry);
return err;
}

MP4_EXTERN(MP4Err)
ISONewHEVCSampleDescription(MP4Track theTrack, MP4Handle sampleDescriptionH, u32 dataReferenceIndex,
u32 length_size, MP4Handle first_sps, MP4Handle first_pps,
Expand Down
2 changes: 1 addition & 1 deletion IsoLib/libisomediafile/src/ItemInfoEntryAtom.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ static MP4Err createFromInputStream(MP4AtomPtr s, MP4AtomPtr proto, MP4InputStre
char inputstr[4096];
char *str;
u32 i;
char msgString[200];
char msgString[8192];
char typeString[8];

ISOItemInfoEntryAtomPtr self = (ISOItemInfoEntryAtomPtr)s;
Expand Down
12 changes: 9 additions & 3 deletions IsoLib/libisomediafile/src/MP4Atoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -1224,13 +1224,17 @@ typedef struct MP4SubSampleInformationAtom
MP4Err (*addEntry)(struct MP4SubSampleInformationAtom *self, u32 sample_delta,
u32 subsample_count, MP4Handle subsample_size_array,
MP4Handle subsample_priority_array, MP4Handle subsample_discardable_array);
MP4Err (*addEntry2)(struct MP4SubSampleInformationAtom *self, u32 sample_delta,
u32 subsample_count, MP4Handle subsample_size_array,
MP4Handle subsample_priority_array, MP4Handle subsample_discardable_array,
MP4Handle codec_specific_parameters_array);
u32 entry_count;
u32 *sample_delta;
u32 *subsample_count;
u32 **subsample_size;
u32 **subsample_priority;
u32 **discardable;
u32 **reserved;
u32 **codec_specific_parameters;
} MP4SubSampleInformationAtom, *MP4SubSampleInformationAtomPtr;

typedef struct MP4SyncSampleAtom
Expand Down Expand Up @@ -1493,7 +1497,7 @@ enum
typedef struct MP4TrackFragmentDecodeTimeAtom
{
MP4_FULL_ATOM
u32 baseMediaDecodeTime;
u64 baseMediaDecodeTime;
} MP4TrackFragmentDecodeTimeAtom, *MP4TrackFragmentDecodeTimeAtomPtr;

typedef struct MP4ItemPropertyContainerAtom
Expand Down Expand Up @@ -1648,11 +1652,11 @@ typedef struct MP4RestrictedVideoSampleEntryAtom
MP4_BASE_ATOM
COMMON_SAMPLE_ENTRY_FIELDS

MP4AtomPtr MP4RestrictedSchemeInfo;
u32 restriction_type;

MP4Err (*addSchemeInfoAtom)(struct MP4Atom *self, struct MP4Atom *theAtom);
MP4Err (*getSchemeInfoAtom)(struct MP4Atom *self, u32 theType, struct MP4Atom **theAtom);
MP4Err (*getRinf)(struct MP4Atom *self, struct MP4Atom **theAtom);
MP4Err (*getScheme)(struct MP4Atom *self, u32 *sch_type, u32 *sch_version, char **sch_url);

MP4Err (*transform)(struct MP4Atom *self, u32 sch_type, u32 sch_version, char *sch_url);
Expand Down Expand Up @@ -1792,6 +1796,8 @@ typedef struct MP4SampleGroupDescriptionAtom

u32 default_length; /* we only handle version 1 */

u32 default_group_description_index; /* only after version 2 */

u32 groupCount;

sampleGroupEntry *groups;
Expand Down
24 changes: 24 additions & 0 deletions IsoLib/libisomediafile/src/MP4FileMappingInputStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,29 @@ static MP4Err skipData(struct MP4InputStreamRecord *s, u64 bytes, char *msg)
return err;
}

static MP4Err rewindData(struct MP4InputStreamRecord *s, u64 bytes, char *msg)
{
MP4Err err;
MP4FileMappingInputStreamPtr self = (MP4FileMappingInputStreamPtr)s;

err = MP4NoErr;

CHECK_AVAIL(bytes)
self->available += bytes;
self->current_offset -= bytes;

if(msg && self->debugging)
{
doIndent(s);
fprintf(stdout, "%s = [%lld bytes of data rewinded]\n", msg, bytes);
}

bail:
TEST_RETURN(err);

return err;
}

static MP4Err readData(struct MP4InputStreamRecord *s, u64 bytes, char *outData, char *msg)
{
MP4Err err;
Expand Down Expand Up @@ -223,6 +246,7 @@ MP4Err MP4CreateFileMappingInputStream(struct FileMappingObjectRecord *mapping,
is->read32 = read32;
is->readData = readData;
is->skipData = skipData;
is->rewindData = rewindData;
is->getStreamOffset = getStreamOffset;
is->getFileMappingObject = getFileMappingObject;
is->mapping = mapping;
Expand Down
5 changes: 5 additions & 0 deletions IsoLib/libisomediafile/src/MP4Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ derivative works. Copyright (c) 1999.
} \
}

#define REWIND_DATA(length, var) \
err = inputStream->rewindData(inputStream, length, var); \
if(err) goto bail; \
self->bytesRead -= length;

#define PUTBYTES(src, len) \
if((self->bytesWritten + len) > self->size) \
{ \
Expand Down
3 changes: 2 additions & 1 deletion IsoLib/libisomediafile/src/MP4InputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ derivative works. Copyright (c) 1999.
MP4Err (*read32)(struct MP4InputStreamRecord * self, u32 * outVal, char *msg); \
MP4Err (*readData)(struct MP4InputStreamRecord * self, u64 bytes, char *outData, char *msg); \
u64 (*getStreamOffset)(struct MP4InputStreamRecord * self); \
MP4Err (*skipData)(struct MP4InputStreamRecord * self, u64 bytes, char *msg);
MP4Err (*skipData)(struct MP4InputStreamRecord * self, u64 bytes, char *msg); \
MP4Err (*rewindData)(struct MP4InputStreamRecord * self, u64 bytes, char *msg);

typedef struct MP4InputStreamRecord
{
Expand Down
1 change: 1 addition & 0 deletions IsoLib/libisomediafile/src/MP4LinkedList.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ MP4Err MP4MakeLinkedList(MP4LinkedList *outList)
newList = (MP4LinkedList)calloc(1, sizeof(MP4List));
TESTMALLOC(newList)
newList->foundEntryNumber = -1;
newList->entryCount = 0;
*outList = newList;
bail:
return err;
Expand Down
24 changes: 24 additions & 0 deletions IsoLib/libisomediafile/src/MP4MemoryInputStream.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ static MP4Err skipData(struct MP4InputStreamRecord *s, u64 bytes, char *msg)
return err;
}

static MP4Err rewindData(struct MP4InputStreamRecord *s, u64 bytes, char *msg)
{
MP4Err err;
MP4FileMappingInputStreamPtr self = (MP4FileMappingInputStreamPtr)s;

err = MP4NoErr;

CHECK_AVAIL(bytes)
self->available += bytes;
self->current_offset -= bytes;

if(msg && self->debugging)
{
doIndent(s);
fprintf(stdout, "%s = [%lld bytes of data rewinded]\n", msg, bytes);
}

bail:
TEST_RETURN(err);

return err;
}

static MP4Err readData(struct MP4InputStreamRecord *s, u64 bytes, char *outData, char *msg)
{
MP4Err err;
Expand Down Expand Up @@ -221,6 +244,7 @@ MP4Err MP4CreateMemoryInputStream(char *base, u32 size, MP4InputStreamPtr *outSt
is->read32 = read32;
is->readData = readData;
is->skipData = skipData;
is->rewindData = rewindData;
is->getStreamOffset = getStreamOffset;
is->msg = msg;
is->getFileMappingObject = getFileMappingObject;
Expand Down
1 change: 1 addition & 0 deletions IsoLib/libisomediafile/src/MP4Movies.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ MP4_EXTERN(MP4Err)
MP4GetMovieTrackCount(MP4Movie theMovie, u32 *outTrackCount)
{
GETMOVIEATOM(theMovie);
if(movieAtom == NULL) BAILWITHERROR(MP4BadDataErr);
*outTrackCount = movieAtom->getTrackCount(movieAtom);
bail:
TEST_RETURN(err);
Expand Down
19 changes: 19 additions & 0 deletions IsoLib/libisomediafile/src/MP4Movies.h
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,25 @@ extern "C"
MP4Handle subsample_size_array,
MP4Handle subsample_priority_array,
MP4Handle subsample_discardable_array);
/**
* @brief Same as MP4AddSubSampleInformationEntry but also allows to add the codec specific
* parameters
*
* @param subsample
* @param sample_delta
* @param subsample_count
* @param subsample_size_array
* @param subsample_priority_array
* @param subsample_discardable_array
* @param codec_specific_parameters_array
* @return MP4Err error code
*/
MP4_EXTERN(MP4Err)
MP4AddSubSampleInformationEntry2(MP4GenericAtom subsample, u32 sample_delta, u32 subsample_count,
MP4Handle subsample_size_array,
MP4Handle subsample_priority_array,
MP4Handle subsample_discardable_array,
MP4Handle codec_specific_parameters_array);
/**
* @brief Add track to a track group ID.
*
Expand Down
2 changes: 1 addition & 1 deletion IsoLib/libisomediafile/src/MP4TrackReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ typedef struct MP4TrackReaderStruct
{
TRACK_READER_ENTRIES
u32 isODTrack;
} * MP4TrackReaderPtr;
} *MP4TrackReaderPtr;

MP4Err MP4CreateODTrackReader(MP4Movie theMovie, MP4Track theTrack, MP4TrackReaderPtr *outReader);
MP4Err MP4CreateOrdinaryTrackReader(MP4Movie theMovie, MP4Track theTrack,
Expand Down
6 changes: 4 additions & 2 deletions IsoLib/libisomediafile/src/MovieFragmentAtom.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ static MP4Err mergeFragments(struct MP4MovieFragmentAtom *self, MP4MovieAtomPtr
if(tfdt->baseMediaDecodeTime < initialMediaDuration) BAILWITHERROR(MP4InvalidMediaErr);

if(tfdt->baseMediaDecodeTime > initialMediaDuration)
err = mdia->extendLastSampleDuration(mdia,
tfdt->baseMediaDecodeTime - (u32)initialMediaDuration);
{
u32 duration = (tfdt->baseMediaDecodeTime - initialMediaDuration) & 0xffffffff;
err = mdia->extendLastSampleDuration(mdia, duration);
}
if(err) goto bail;
}

Expand Down
22 changes: 22 additions & 0 deletions IsoLib/libisomediafile/src/MovieTracks.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,28 @@ MP4AddSubSampleInformationEntry(MP4GenericAtom subsample, u32 sample_delta, u32
return err;
}

MP4_EXTERN(MP4Err)
MP4AddSubSampleInformationEntry2(MP4GenericAtom subsample, u32 sample_delta, u32 subsample_count,
MP4Handle subsample_size_array, MP4Handle subsample_priority_array,
MP4Handle subsample_discardable_array,
MP4Handle codec_specific_parameters_array)
{
MP4Err err;
MP4SubSampleInformationAtomPtr subs;

err = MP4NoErr;
if(subsample == NULL) BAILWITHERROR(MP4BadParamErr);
subs = (MP4SubSampleInformationAtomPtr)subsample;

err = subs->addEntry2(subs, sample_delta, subsample_count, subsample_size_array,
subsample_priority_array, subsample_discardable_array,
codec_specific_parameters_array);

bail:
TEST_RETURN(err);
return err;
}

MP4_EXTERN(MP4Err) MP4AddTrackGroup(MP4Track theTrack, u32 groupID, u32 dependencyType)
{
MP4Err err;
Expand Down
Loading

0 comments on commit 1f76495

Please sign in to comment.