Skip to content

Commit

Permalink
add a helper function to get sample entry type more easily
Browse files Browse the repository at this point in the history
  • Loading branch information
podborski committed Feb 21, 2024
1 parent e4506e7 commit 600ec26
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
27 changes: 27 additions & 0 deletions IsoLib/libisomediafile/src/MP4Movies.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,33 @@ MP4GetMovieIndTrack(MP4Movie theMovie, u32 trackIndex, MP4Track *outTrack)
return err;
}

MP4_EXTERN(MP4Err)
MP4GetMovieIndTrackSampleEntryType(MP4Movie theMovie, u32 idx, u32* SEType)
{
MP4Err err;
MP4Track trak;
MP4TrackReader reader;
MP4Handle sampleEntryH;

MP4NewHandle(0, &sampleEntryH);

err = MP4GetMovieIndTrack(theMovie, idx, &trak);
if(err) goto bail;

err = MP4CreateTrackReader(trak, &reader);
if(err) goto bail;

err = MP4TrackReaderGetCurrentSampleDescription(reader, sampleEntryH);
if(err) goto bail;

err = ISOGetSampleDescriptionType(sampleEntryH, SEType);

bail:
TEST_RETURN(err);
MP4DisposeHandle(sampleEntryH);
return err;
}

MP4_EXTERN(MP4Err)
MP4GetMovieTrack(MP4Movie theMovie, u32 trackID, MP4Track *outTrack)
{
Expand Down
9 changes: 9 additions & 0 deletions IsoLib/libisomediafile/src/MP4Movies.h
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,15 @@ extern "C"
* @return MP4Err error code
*/
MP4_EXTERN(MP4Err) MP4GetMovieIndTrack(MP4Movie theMovie, u32 trackIndex, MP4Track *outTrack);
/**
* @brief Get sample entry type of a track.
*
* @note This function only returns the first sample entry type.
* @param theMovie input movie object
* @param idx index of the track ranges between 1 and the number of tracks in theMovie.
* @param SEType [out] sample entry type (4CC)
*/
MP4_EXTERN(MP4Err) MP4GetMovieIndTrackSampleEntryType(MP4Movie theMovie, u32 idx, u32* SEType);

/*
MP4_EXTERN ( MP4Err )
Expand Down
25 changes: 25 additions & 0 deletions test/test_01_simple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <catch.hpp>
#include <ISOMovies.h>
#include <MP4Atoms.h>
#include "testdataPath.h"

#include <string>
Expand Down Expand Up @@ -118,6 +119,30 @@ TEST_CASE("01_simple.mp4")
CHECK(err == MP4NoErr);
CHECK(uiTrackCnt == 4);

for(uint32_t i=1; i<=uiTrackCnt; i++)
{
uint32_t type = 0;
err = MP4GetMovieIndTrackSampleEntryType(cMovieBox, i, &type);
CHECK(err == MP4NoErr);
switch (i)
{
case 1:
CHECK(type == MP4MPEGSampleEntryAtomType);
break;
case 2:
CHECK(type == MP4MPEGSampleEntryAtomType);
break;
case 3:
CHECK(type == MP4VisualSampleEntryAtomType);
break;
case 4:
CHECK(type == MP4AudioSampleEntryAtomType);
break;
default:
break;
}
}

// ISOGetTrackEnabled
u32 outEnabled;
ISOGetMovieTrack(cMovieBox, 101, &audioTrack);
Expand Down

0 comments on commit 600ec26

Please sign in to comment.