Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@ if(NOT ISOBMFF_BUILD_LIB_ONLY)
add_subdirectory(IsoLib/isoiff_tool)
add_subdirectory(IsoLib/pcm_audio_example)
add_subdirectory(IsoLib/vvc_base)
add_subdirectory(IsoLib/pcm_sniffer)
add_subdirectory(test)
endif()
2 changes: 1 addition & 1 deletion IsoLib/favs_example/src/demux_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ISOErr playMyMovie(struct ParamStruct *parameters, char *filename) {

/* Write Sample Entry NAL Units in the beginning of the trak output file */
MP4NewHandle(0, &sampleEntryNALs);
err = ISOGetHEVCNALUs(sampleEntryH, sampleEntryNALs, parameters->hevcExtractionMode);
err = ISOGetHEVCNALUsFromSampleEntry(sampleEntryH, sampleEntryNALs, parameters->hevcExtractionMode);
if(err)
{
printf("Failed to extract NAL units with mode %u (err = %d)\n", parameters->hevcExtractionMode, err);
Expand Down
2 changes: 1 addition & 1 deletion IsoLib/libisomediafile/src/ISOMovies.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ extern "C"
* @param extraction_mode if set to 0 - get them all; 1 - hvcC only; 2 - lhvC only
*/
ISO_EXTERN(ISOErr)
ISOGetHEVCNALUs(MP4Handle sampleEntryH, MP4Handle nalus, u32 extraction_mode);
ISOGetHEVCNALUsFromSampleEntry(MP4Handle sampleEntryH, MP4Handle nalus, u32 extraction_mode);
/**
* @brief Gets a restricted video parameter set (AVC or HEVC), placing it in the given handle
* @ingroup SampleDescr
Expand Down
13 changes: 1 addition & 12 deletions IsoLib/libisomediafile/src/ISOSampleDescriptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,7 @@ ISOGetHEVCSampleDescriptionPS(MP4Handle sampleEntryH, MP4Handle ps, u32 where, u
}

MP4_EXTERN(MP4Err)
ISOGetHEVCNALUs(MP4Handle sampleEntryH, MP4Handle nalus, u32 extraction_mode)
ISOGetHEVCNALUsFromSampleEntry(MP4Handle sampleEntryH, MP4Handle nalus, u32 extraction_mode)
{
MP4Err err = MP4NoErr;
MP4VisualSampleEntryAtomPtr entry = NULL;
Expand All @@ -1211,17 +1211,6 @@ ISOGetHEVCNALUs(MP4Handle sampleEntryH, MP4Handle nalus, u32 extraction_mode)
err = sampleEntryHToAtomPtr(sampleEntryH, (MP4AtomPtr *)&entry, MP4VisualSampleEntryAtomType);
if(err) goto bail;

if(entry->type == MP4EncVisualSampleEntryAtomType ||
entry->type == MP4RestrictedVideoSampleEntryAtomType)
{
u32 origFmt = 0;
err = ISOGetOriginalFormat(sampleEntryH, &origFmt);
if(origFmt != ISOHEVCSampleEntryAtomType && origFmt != ISOLHEVCSampleEntryAtomType)
BAILWITHERROR(MP4BadParamErr);
}
else if(entry->type != ISOHEVCSampleEntryAtomType && entry->type != ISOLHEVCSampleEntryAtomType)
BAILWITHERROR(MP4BadParamErr);

MP4GetListEntryAtom(entry->ExtensionAtomList, ISOHEVCConfigAtomType, (MP4AtomPtr *)&hvcC);
MP4GetListEntryAtom(entry->ExtensionAtomList, ISOLHEVCConfigAtomType, (MP4AtomPtr *)&lhvC);

Expand Down
3 changes: 2 additions & 1 deletion IsoLib/libisomediafile/src/MP4Atoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ enum
MP4MetadataLocaleBoxType = MP4_FOUR_CHAR_CODE('l', 'o', 'c', 'a'),
MP4MetadataSetupBoxType = MP4_FOUR_CHAR_CODE('s', 'e', 't', 'u'),
MP4GroupsListBoxType = MP4_FOUR_CHAR_CODE('g', 'r', 'p', 'l'),
MP4AlternativeEntityGroup = MP4_FOUR_CHAR_CODE('a', 'l', 't', 'r')
MP4AlternativeEntityGroup = MP4_FOUR_CHAR_CODE('a', 'l', 't', 'r'),
MP4T35SampleGroupEntry = MP4_FOUR_CHAR_CODE('i', 't', '3', '5')

};

Expand Down
37 changes: 37 additions & 0 deletions IsoLib/libisomediafile/src/MP4Media.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,41 @@ ISOAddGroupDescription(MP4Media media, u32 groupType, MP4Handle description, u32

bail:
TEST_RETURN(err);
return err;
}

MP4_EXTERN(MP4Err)
ISOAddT35GroupDescription(MP4Media media, MP4Handle itu_t_t35_data, u32 complete_message_flag,
u32 *index)
{
MP4Err err;
MP4MediaAtomPtr mdia;
MP4Handle description = NULL;
MP4Handle prefix = NULL;

if(media == NULL || itu_t_t35_data == NULL)
{
BAILWITHERROR(MP4BadParamErr);
}
mdia = (MP4MediaAtomPtr)media;

err = MP4NewHandle(1, &prefix);
if(err) goto bail;
(*prefix)[0] = (complete_message_flag ? 0x80 : 0x00);

err = MP4NewHandle(0, &description);
if(err) goto bail;
err = MP4HandleCat(description, prefix);
if(err) goto bail;
err = MP4HandleCat(description, itu_t_t35_data);
if(err) goto bail;

err = mdia->addGroupDescription(mdia, MP4T35SampleGroupEntry, description, index);

bail:
if(prefix) MP4DisposeHandle(prefix);
if(description) MP4DisposeHandle(description);
TEST_RETURN(err);
return err;
}

Expand Down Expand Up @@ -327,6 +361,9 @@ ISOGetSampleGroupSampleNumbers(MP4Media media, u32 groupType, u32 groupIndex,
return err;
}

/* TODO: add an API that will get sample numbers based on T35 header (if it35 is used for marking
* samples) */

MP4_EXTERN(MP4Err)
ISOSetSampleDependency(MP4Media media, s32 sample_index, MP4Handle dependencies)
{
Expand Down
27 changes: 27 additions & 0 deletions IsoLib/libisomediafile/src/MP4Movies.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,33 @@ MP4GetMovieIndTrackSampleEntryType(MP4Movie theMovie, u32 idx, u32 *SEType)
return err;
}

MP4_EXTERN(MP4Err)
MP4GetMovieIndTrackNALUnitLength(MP4Movie theMovie, u32 idx, u32 *naluLength)
{
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 = ISOGetNALUnitLength(sampleEntryH, naluLength);

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

MP4_EXTERN(MP4Err)
MP4GetMovieTrack(MP4Movie theMovie, u32 trackID, MP4Track *outTrack)
{
Expand Down
23 changes: 23 additions & 0 deletions IsoLib/libisomediafile/src/MP4Movies.h
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,16 @@ extern "C"
*/
MP4_EXTERN(MP4Err) MP4GetMovieIndTrackSampleEntryType(MP4Movie theMovie, u32 idx, u32 *SEType);

/**
* @brief Get number of bytes that is used to signal the length of a NAL unit.
*
* @note This function only returns the NALU length of the first sample entry.
* @param theMovie input movie object
* @param idx index of the track ranges between 1 and the number of tracks in theMovie.
* @param naluLength [out] number of bytes to signal NAL unit length.
*/
MP4_EXTERN(MP4Err) MP4GetMovieIndTrackNALUnitLength(MP4Movie theMovie, u32 idx, u32 *naluLength);

/*
MP4_EXTERN ( MP4Err )
MP4GetMovieInitialBIFSTrack( MP4Movie theMovie, MP4Track *outBIFSTrack );
Expand Down Expand Up @@ -1098,6 +1108,19 @@ extern "C"
*/
MP4_EXTERN(MP4Err)
ISOAddGroupDescription(MP4Media media, u32 groupType, MP4Handle description, u32 *index);
/**
* @brief Adds a T.35 Sample Group Description to the indicated media.
*
* @param media input media object
* @param itu_t_t35_data pre-serialized (big-endian) T.35 data that will go inside sgpd
* @param complete_message_flag If set to 1 indicates that the entire T.35 is stored in
* itu_t_t35_data
* @param index output index of the added group
* @return MP4Err error code
*/
MP4_EXTERN(MP4Err)
ISOAddT35GroupDescription(MP4Media media, MP4Handle itu_t_t35_data, u32 complete_message_flag,
u32 *index);
/**
* @brief Returns in the handle ‘description’ the group description associated with the given
* group index of the given group type.
Expand Down
4 changes: 4 additions & 0 deletions IsoLib/libisomediafile/src/SampleTableAtom.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,10 @@ static MP4Err getSampleGroupSampleNumbers(struct MP4SampleTableAtom *self, u32 g
(*outSampleNumbers)[(*outSampleCnt)++] = i;
}
}
else
{
/* TODO: make sure we can also get it based on default_group_description_index, */
}

bail:
TEST_RETURN(err);
Expand Down
28 changes: 21 additions & 7 deletions IsoLib/libisomediafile/src/SegmentIndexAtom.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ static MP4Err createFromInputStream(MP4AtomPtr s, MP4AtomPtr proto, MP4InputStre
MP4Err err;
u32 i;
u32 tmp32;
char debug_buffer[70];
u16 tmpReferenceCount = 0;

MP4SegmentIndexAtomPtr self = (MP4SegmentIndexAtomPtr)s;

Expand All @@ -211,36 +213,48 @@ static MP4Err createFromInputStream(MP4AtomPtr s, MP4AtomPtr proto, MP4InputStre
GET32(firstOffset);

GET16(reserved1);
GET16(referenceCount);
GET16_V(tmpReferenceCount);

for(i = 0; i < self->referenceCount; i++)
for(i = 0; i < tmpReferenceCount; i++)
{

u8 referenceType;
u32 referencedSize;
u32 subsegmentDuration;
u8 startsWithSAP;
u8 SAPType;
u32 SAPDeltaTime;

GET32_V(tmp32);
snprintf(debug_buffer, sizeof(debug_buffer), "\nEntry %d of %d", i, self->referenceCount);
DEBUG_MSG(debug_buffer);

GET32_V_NOMSG(tmp32);
referenceType = (tmp32 >> 31) & 0x01;
referencedSize = tmp32 & 0x7FFF;
referencedSize = tmp32 & 0x7FFFFFFF;
snprintf(debug_buffer, sizeof(debug_buffer), "reference_type = %d", referenceType);
DEBUG_MSG(debug_buffer);
snprintf(debug_buffer, sizeof(debug_buffer), "referenced_size = %d", referencedSize);
DEBUG_MSG(debug_buffer);
GET32_V(subsegmentDuration);
GET32_V(tmp32);
GET32_V_NOMSG(tmp32);
startsWithSAP = (tmp32 >> 31) & 0x01;
SAPType = (tmp32 >> 28) & 0x07;
SAPDeltaTime = tmp32 & 0x0FFFFFFF;
snprintf(debug_buffer, sizeof(debug_buffer), "starts_with_SAP = %d", startsWithSAP);
DEBUG_MSG(debug_buffer);
snprintf(debug_buffer, sizeof(debug_buffer), "SAP_type = %d", SAPType);
DEBUG_MSG(debug_buffer);
snprintf(debug_buffer, sizeof(debug_buffer), "SAP_delta_time = %d", SAPDeltaTime);
DEBUG_MSG(debug_buffer);

err = addReference(self, referenceType, referencedSize, subsegmentDuration, startsWithSAP,
SAPType, SAPDeltaTime);
if(err) goto bail;
}

assert(self->referenceCount == tmpReferenceCount);
assert(self->bytesRead == self->size);
bail:
TEST_RETURN(err);

return err;
}

Expand Down
8 changes: 7 additions & 1 deletion IsoLib/libisomediafile/src/TimeToSampleAtom.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ static MP4Err extendLastSampleDuration(struct MP4TimeToSampleAtom *self, u32 dur
err = MP4NoErr;
current = (sttsEntryPtr)self->currentEntry;

if(current == NULL)
{
/* lets treat it as the first sample */
err = addSample(self, duration);
goto bail;
}

if(current->sampleCount == 1)
{
current->sampleDuration += duration;
Expand All @@ -163,7 +170,6 @@ static MP4Err extendLastSampleDuration(struct MP4TimeToSampleAtom *self, u32 dur

bail:
TEST_RETURN(err);

return err;
}

Expand Down
27 changes: 17 additions & 10 deletions IsoLib/libisomediafile/src/TrackFragmentAtom.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,28 +691,35 @@ static MP4Err mergeSampleAuxiliaryInformation(struct MP4TrackFragmentAtom *self,

for(i = 0; i < self->saizList->entryCount; i++)
{
MP4SampleAuxiliaryInformationSizesAtomPtr saizOfTraf;
MP4SampleAuxiliaryInformationOffsetsAtomPtr saioOfTraf;
MP4SampleAuxiliaryInformationSizesAtomPtr saizOfStbl;
MP4SampleAuxiliaryInformationOffsetsAtomPtr saioOfStbl;
MP4SampleAuxiliaryInformationSizesAtomPtr saizOfTraf = NULL;
MP4SampleAuxiliaryInformationOffsetsAtomPtr saioOfTraf = NULL;
MP4SampleAuxiliaryInformationSizesAtomPtr saizOfStbl = NULL;
MP4SampleAuxiliaryInformationOffsetsAtomPtr saioOfStbl = NULL;

err = MP4GetListEntry(self->saizList, i, (char **)&saizOfTraf);
if(err || !saizOfTraf) continue;

err = MP4GetListEntry(self->saioList, i, (char **)&saioOfTraf);
if(err || !saioOfTraf) continue;

err = stbl->getSampleAuxiliaryInformation(
stbl, (saizOfTraf->flags & 1), saizOfTraf->aux_info_type, saizOfTraf->aux_info_type_parameter,
&saizOfStbl, &saioOfStbl);
if(err) goto bail;

err = saizOfStbl->mergeSizes((MP4AtomPtr)saizOfStbl, (MP4AtomPtr)saizOfTraf);
if(err) goto bail;
err = saioOfStbl->mergeOffsets((MP4AtomPtr)saioOfStbl, (MP4AtomPtr)saioOfTraf,
tfhd->base_data_offset);
if(err) goto bail;
/* Defensive checks: if stbl had no saiz/saio, skip merging */
if(saizOfStbl && saioOfStbl)
{
err = saizOfStbl->mergeSizes((MP4AtomPtr)saizOfStbl, (MP4AtomPtr)saizOfTraf);
if(err) goto bail;
err = saioOfStbl->mergeOffsets((MP4AtomPtr)saioOfStbl, (MP4AtomPtr)saioOfTraf,
tfhd->base_data_offset);
if(err) goto bail;
}
}

bail:
TEST_RETURN(err);

return err;
}

Expand Down
54 changes: 54 additions & 0 deletions IsoLib/pcm_sniffer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
cmake_minimum_required(VERSION 3.16)

# Name & languages
project(pcm_sniffer LANGUAGES C CXX)

# C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Includes: libisomediafile core + HM
include_directories(
../libisomediafile/src

# HM
../HM/source/Lib
../HM/source/Lib/TLibCommon
../HM/source/Lib/TLibDecoder
)

# Platform-specific include roots for libisomediafile
include_directories(
# Linux
$<$<PLATFORM_ID:Linux>:${CMAKE_CURRENT_LIST_DIR}/../libisomediafile/linux>
# Windows
$<$<PLATFORM_ID:Windows>:${CMAKE_CURRENT_LIST_DIR}/../libisomediafile/w32>
# macOS
$<$<PLATFORM_ID:Darwin>:${CMAKE_CURRENT_LIST_DIR}/../libisomediafile/macosx>
)

# common warnings
if (MSVC)
add_compile_options(/W4)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else()
add_compile_options(-Wall -Wextra -Wpedantic)
endif()


# ---- Executable ----
add_executable(
pcm_sniffer
pcm_sniffer.cpp
)

# Link libraries
target_link_libraries(
pcm_sniffer

PRIVATE
libisomediafile
TLibDecoder
TLibCommon
)
Loading
Loading