libgpac
Documentation of the core library of GPAC
Fragmented ISOBMFF Read
+ Collaboration diagram for Fragmented ISOBMFF Read:

Data Structures

struct  GF_ISOFragmentBoundaryInfo
 

Enumerations

enum  GF_ISOSegOpenMode { GF_ISOM_SEGMENT_NO_ORDER_FLAG = 1 , GF_ISOM_SEGMENT_SCALABLE_FLAG = 1<<1 }
 

Functions

Bool gf_isom_is_fragmented (GF_ISOFile *isom_file)
 
Bool gf_isom_is_track_fragmented (GF_ISOFile *isom_file, GF_ISOTrackID TrackID)
 
Bool gf_isom_has_segment (GF_ISOFile *isom_file, u32 *brand, u32 *version)
 
u32 gf_isom_segment_get_fragment_count (GF_ISOFile *isom_file)
 
u32 gf_isom_segment_get_track_fragment_count (GF_ISOFile *isom_file, u32 moof_index)
 
u32 gf_isom_segment_get_track_fragment_decode_time (GF_ISOFile *isom_file, u32 moof_index, u32 traf_index, u64 *decode_time)
 
u64 gf_isom_segment_get_fragment_size (GF_ISOFile *isom_file, u32 moof_index, u32 *moof_size)
 
void gf_isom_set_single_moof_mode (GF_ISOFile *isom_file, Bool mode)
 
GF_Err gf_isom_get_file_offset_for_time (GF_ISOFile *isom_file, Double start_time, u64 *offset)
 
GF_Err gf_isom_get_sidx_duration (GF_ISOFile *isom_file, u64 *sidx_dur, u32 *sidx_timescale)
 
GF_Err gf_isom_refresh_fragmented (GF_ISOFile *isom_file, u64 *MissingBytes, const char *new_location)
 
u64 gf_isom_get_current_tfdt (GF_ISOFile *isom_file, u32 trackNumber)
 
u64 gf_isom_get_smooth_next_tfdt (GF_ISOFile *isom_file, u32 trackNumber)
 
Bool gf_isom_is_smooth_streaming_moov (GF_ISOFile *isom_file)
 
GF_Err gf_isom_get_fragment_defaults (GF_ISOFile *isom_file, u32 trackNumber, u32 *defaultDuration, u32 *defaultSize, u32 *defaultDescriptionIndex, u32 *defaultRandomAccess, u8 *defaultPadding, u16 *defaultDegradationPriority)
 
Bool gf_isom_get_last_producer_time_box (GF_ISOFile *isom_file, GF_ISOTrackID *refTrackID, u64 *ntp, u64 *timestamp, Bool reset_info)
 
void gf_isom_enable_traf_map_templates (GF_ISOFile *isom_file)
 
Bool gf_isom_get_root_sidx_offsets (GF_ISOFile *isom_file, u64 *start, u64 *end)
 
Bool gf_isom_sample_is_fragment_start (GF_ISOFile *isom_file, u32 trackNumber, u32 sampleNum, GF_ISOFragmentBoundaryInfo *frag_info)
 
GF_Err gf_isom_release_segment (GF_ISOFile *isom_file, Bool reset_tables)
 
GF_Err gf_isom_reset_tables (GF_ISOFile *isom_file, Bool reset_sample_count)
 
GF_Err gf_isom_reset_data_offset (GF_ISOFile *isom_file, u64 *top_box_start)
 
GF_Err gf_isom_open_segment (GF_ISOFile *isom_file, const char *fileName, u64 start_range, u64 end_range, GF_ISOSegOpenMode flags)
 
GF_ISOTrackID gf_isom_get_highest_track_in_scalable_segment (GF_ISOFile *isom_file, u32 for_base_track)
 
void gf_isom_reset_fragment_info (GF_ISOFile *isom_file, Bool keep_sample_count)
 
void gf_isom_reset_sample_count (GF_ISOFile *isom_file)
 
void gf_isom_reset_seq_num (GF_ISOFile *isom_file)
 
u64 gf_isom_get_fragmented_duration (GF_ISOFile *isom_file)
 
u32 gf_isom_get_fragments_count (GF_ISOFile *isom_file, Bool segments_only)
 
GF_Err gf_isom_get_fragmented_samples_info (GF_ISOFile *isom_file, GF_ISOTrackID trackID, u32 *nb_samples, u64 *duration)
 
u32 gf_isom_get_next_moof_number (GF_ISOFile *isom_file)
 

Detailed Description

This describes function specific to fragmented ISOBMF files


Data Structure Documentation

◆ GF_ISOFragmentBoundaryInfo

struct GF_ISOFragmentBoundaryInfo

Segment boundary information

Data Fields
u64 frag_start

fragment start offset

u64 mdat_end

mdat end offset

u64 seg_start_plus_one
const u8 * moof_template

serialized array of styp (if present) sidx (if present) and moof with only the current traf

u32 moof_template_size

size of serialized buffer

u64 sidx_start

sidx start, 0 if absent

u64 sidx_end

sidx end, 0 if absent

u64 first_dts

DTS of first sample in this fragment fotr the queried track

Enumeration Type Documentation

◆ GF_ISOSegOpenMode

Flags for gf_isom_open_segment

Enumerator
GF_ISOM_SEGMENT_NO_ORDER_FLAG 

do not check for movie fragment sequence number

GF_ISOM_SEGMENT_SCALABLE_FLAG 

the segment contains a scalable layer of the last opened segment

Function Documentation

◆ gf_isom_is_fragmented()

Bool gf_isom_is_fragmented ( GF_ISOFile isom_file)

checks if a movie file is fragmented

Parameters
isom_filethe target ISO file
Returns
GF_FALSE if movie isn't fragmented, GF_TRUE otherwise

◆ gf_isom_is_track_fragmented()

Bool gf_isom_is_track_fragmented ( GF_ISOFile isom_file,
GF_ISOTrackID  TrackID 
)

checks if a movie file is fragmented

Parameters
isom_filethe target ISO file
TrackIDthe target track
Returns
GF_FALSE if track isn't fragmented, GF_TRUE otherwise

◆ gf_isom_has_segment()

Bool gf_isom_has_segment ( GF_ISOFile isom_file,
u32 brand,
u32 version 
)

checks if a file has a top styp box

Parameters
isom_filethe target ISO file
brandset to the major brand of the styp box
versionset to version of the styp box
Returns
GF_TRUE of the file has a styp box, GF_FALSE otherwise

◆ gf_isom_segment_get_fragment_count()

u32 gf_isom_segment_get_fragment_count ( GF_ISOFile isom_file)

gets number of movie fragments in the file

Parameters
isom_filethe target ISO file
Returns
number of movie fragments in the file, 0 if none

◆ gf_isom_segment_get_track_fragment_count()

u32 gf_isom_segment_get_track_fragment_count ( GF_ISOFile isom_file,
u32  moof_index 
)

gets number of track fragments in the indicated movie fragment

Parameters
isom_filethe target ISO file
moof_indexthe target movie fragment (1-based index)
Returns
number of track fragments, 0 if none

◆ gf_isom_segment_get_track_fragment_decode_time()

u32 gf_isom_segment_get_track_fragment_decode_time ( GF_ISOFile isom_file,
u32  moof_index,
u32  traf_index,
u64 decode_time 
)

get the track fragment decode time of a track fragment

Parameters
isom_filethe target ISO file
moof_indexthe target movie fragment (1-based index)
traf_indexthe target track fragment (1-based index)
decode_timeset to the track fragment decode time if present, 0 otherwise
Returns
the track ID of the track fragment

◆ gf_isom_segment_get_fragment_size()

u64 gf_isom_segment_get_fragment_size ( GF_ISOFile isom_file,
u32  moof_index,
u32 moof_size 
)

get the movie fragment size, i.e. the size of moof, mdat and related boxes before moof/mdat

Parameters
isom_filethe target ISO file
moof_indexthe target movie fragment (1-based index)
moof_sizeset to moof box size, may be NULL
Returns
the movie fragemnt size

◆ gf_isom_set_single_moof_mode()

void gf_isom_set_single_moof_mode ( GF_ISOFile isom_file,
Bool  mode 
)

enables single moof mode. In single moof mode, file is parsed only one moof/mdat at a time in order to proceed to next moof, gf_isom_reset_data_offset must be called to parse the next moof

Parameters
isom_filethe target ISO file
modeif GF_TRUE, enables single moof mode; otherwise disables it

◆ gf_isom_get_file_offset_for_time()

GF_Err gf_isom_get_file_offset_for_time ( GF_ISOFile isom_file,
Double  start_time,
u64 offset 
)

gets closest file offset for the given time, when the file uses an segment index (sidx)

Parameters
isom_filethe target ISO file
start_timethe start time in seconds
offsetset to the file offset of the segment containing the desired time
Returns
error if any

◆ gf_isom_get_sidx_duration()

GF_Err gf_isom_get_sidx_duration ( GF_ISOFile isom_file,
u64 sidx_dur,
u32 sidx_timescale 
)

gets sidx duration, when the file uses an segment index (sidx)

Parameters
isom_filethe target ISO file
sidx_durset to the total duration documented in the segment index
sidx_timescaleset timescale used to represent the duration in the segment index
Returns
error if any

◆ gf_isom_refresh_fragmented()

GF_Err gf_isom_refresh_fragmented ( GF_ISOFile isom_file,
u64 MissingBytes,
const char *  new_location 
)

refreshes a fragmented file A file being downloaded may be a fragmented file. In this case only partial info is available once the file is successfully open (gf_isom_open_progressive), and since there is no information wrt number fragments (which could actually be generated on the fly at the sender side), you must call this function on regular basis in order to load newly downloaded fragments. Note this may result in Track/Movie duration changes and SampleCount change too ...

This function should also be called when using memory read (gmem://) to refresh the underlying bitstream after appendin data to your blob. In the case where the file is not fragmented, no further box parsing will be done.

Parameters
isom_filethe target ISO file
MissingBytesset to the number of missing bytes to parse the last incomplete top-level box found
new_locationif set, the previous bitstream is changed to this new location, otherwise it is refreshed (disk flush)
Returns
error if any

◆ gf_isom_get_current_tfdt()

u64 gf_isom_get_current_tfdt ( GF_ISOFile isom_file,
u32  trackNumber 
)

gets the current track fragment decode time of the track (the one of the last fragment parsed).

Parameters
isom_filethe target ISO file
trackNumberthe target track
Returns
the track fragment decode time in media timescale

◆ gf_isom_get_smooth_next_tfdt()

u64 gf_isom_get_smooth_next_tfdt ( GF_ISOFile isom_file,
u32  trackNumber 
)

gets the estimated DTS of the first sample of the next segment for SmoothStreaming files (no tfdt, no tfxd)

Parameters
isom_filethe target ISO file
trackNumberthe target track
Returns
the next track fragment decode time in media timescale

◆ gf_isom_is_smooth_streaming_moov()

Bool gf_isom_is_smooth_streaming_moov ( GF_ISOFile isom_file)

checks if the movie is a smooth streaming recomputed initial movie

Parameters
isom_filethe target ISO file
Returns
GF_TRUE if the file init segment (moov) was generated from external meta-data (smooth streaming)

◆ gf_isom_get_fragment_defaults()

GF_Err gf_isom_get_fragment_defaults ( GF_ISOFile isom_file,
u32  trackNumber,
u32 defaultDuration,
u32 defaultSize,
u32 defaultDescriptionIndex,
u32 defaultRandomAccess,
u8 defaultPadding,
u16 defaultDegradationPriority 
)

gets default values of samples in a track to use for track fragments default. Each variable is optional and if set will contain the default value for this track samples

Parameters
isom_filethe target ISO file
trackNumberthe target track
defaultDurationset to the default duration of samples, 0 if not computable
defaultSizeset to the default size of samples, 0 if not computable
defaultDescriptionIndexset to the default sample description index of samples, 0 if not computable
defaultRandomAccessset to the default sync flag of samples, 0 if not computable
defaultPaddingset to the default padding bits of samples, 0 if not computable
defaultDegradationPriorityset to the default degradation priority of samples, 0 if not computable
Returns
error if any

◆ gf_isom_get_last_producer_time_box()

Bool gf_isom_get_last_producer_time_box ( GF_ISOFile isom_file,
GF_ISOTrackID refTrackID,
u64 ntp,
u64 timestamp,
Bool  reset_info 
)

gets last UTC/timestamp values indicated for the reference track in the file if any (pfrt box)

Parameters
isom_filethe target ISO file
refTrackIDset to the ID of the reference track used by the pfrt box
ntpset to the NTP timestamp found
timestampset to the corresponding media timestamp in refTrackID timescale
reset_infoif GF_TRUE, discards current NTP mapping info; this will trigger parsing of the next prft box found. If not set, subsequent pfrt boxes will not be parsed until the function is called with reset_info=GF_TRUE
Returns
GF_FALSE if no info found, GF_TRUE if OK

◆ gf_isom_enable_traf_map_templates()

void gf_isom_enable_traf_map_templates ( GF_ISOFile isom_file)

enables storage of traf templates (serialized sidx/moof/traf without trun/senc) at segment boundaries This is mostly used to recreate identical segment information when refragmenting a file

Parameters
isom_filethe target ISO file

◆ gf_isom_get_root_sidx_offsets()

Bool gf_isom_get_root_sidx_offsets ( GF_ISOFile isom_file,
u64 start,
u64 end 
)

get byte range of root sidx if any

Parameters
isom_filethe target ISO file
startset to start offset (0=first byte) of the root sidx
endset to end offset (0 if no sidx) of the root sidx
Returns
true if success

◆ gf_isom_sample_is_fragment_start()

Bool gf_isom_sample_is_fragment_start ( GF_ISOFile isom_file,
u32  trackNumber,
u32  sampleNum,
GF_ISOFragmentBoundaryInfo frag_info 
)

checks if a sample is a fragment start Only use this function if gf_isom_enable_traf_map_templates has been called

Parameters
isom_filethe target ISO file
trackNumberthe target track
sampleNumthe target sample number
frag_infofilled with information on fragment boundaries (optional - can be NULL)
Returns
GF_TRUE if this sample was the first sample of a traf in the fragmented source file, GF_FALSE otherwise

◆ gf_isom_release_segment()

GF_Err gf_isom_release_segment ( GF_ISOFile isom_file,
Bool  reset_tables 
)

releases current movie segment. This closes the associated file IO object.

Note
seeking in the file is no longer possible when tables are rested
Warning
The sample count is not reseted after the release of tables. use gf_isom_reset_tables for this
Parameters
isom_filethe target ISO file
reset_tablesif set, sample information for all tracks setup as segment are destroyed, along with all PSSH boxes. This allows keeping the memory footprint low when playing segments.
Returns
error if any

◆ gf_isom_reset_tables()

GF_Err gf_isom_reset_tables ( GF_ISOFile isom_file,
Bool  reset_sample_count 
)

resets sample information for all tracks setup. This allows keeping the memory footprint low when playing DASH/CMAF segments

Note
seeking in the file is then no longer possible
Parameters
isom_filethe target ISO file
reset_sample_countif GF_TRUE, sets sample count of all tracks back to 0
Returns
error if any

◆ gf_isom_reset_data_offset()

GF_Err gf_isom_reset_data_offset ( GF_ISOFile isom_file,
u64 top_box_start 
)

sets the offset for parsing from the input buffer to 0 (used to reclaim input buffer)

Parameters
isom_filethe target ISO file
top_box_startset to the byte offset in the source buffer of the first top level box, may be NULL
Returns
error if any

◆ gf_isom_open_segment()

GF_Err gf_isom_open_segment ( GF_ISOFile isom_file,
const char *  fileName,
u64  start_range,
u64  end_range,
GF_ISOSegOpenMode  flags 
)

opens a new segment file. Access to samples in previous segments is no longer possible if end_range>start_range, restricts the URL to the given byterange when parsing

Parameters
isom_filethe target ISO file
fileNamethe file name of the new segment to open
start_rangethe start offset in bytes in the file of the segment data
end_rangethe end offset in bytes in the file of the segment data
flagsflags to use when opening the segment
Returns
error if any

◆ gf_isom_get_highest_track_in_scalable_segment()

GF_ISOTrackID gf_isom_get_highest_track_in_scalable_segment ( GF_ISOFile isom_file,
u32  for_base_track 
)

returns the track ID of the track containing the highest enhancement layer for the given base track

Parameters
isom_filethe target ISO file
for_base_trackthe number of the base track
Returns
the track ID of the highest enahnacement track

◆ gf_isom_reset_fragment_info()

void gf_isom_reset_fragment_info ( GF_ISOFile isom_file,
Bool  keep_sample_count 
)

resets internal info (track fragement decode time, number of samples, next moof number)used with fragments and segment.

Note
This should be called when seeking (with keep_sample_count=0) or when loading a media segments with the same timing as the previously loaded segment
Parameters
isom_filethe target ISO file
keep_sample_countif GF_TRUE, does not reset the sample count on tracks

◆ gf_isom_reset_sample_count()

void gf_isom_reset_sample_count ( GF_ISOFile isom_file)

resets sample count to 0 and next moof number to 0. When doing scalable media, should be called before opening the segment containing the base layer in order to make sure the sample count base number is always the same (ie 1) on all tracks

Parameters
isom_filethe target ISO file

◆ gf_isom_reset_seq_num()

void gf_isom_reset_seq_num ( GF_ISOFile isom_file)

resets moof sequence number to 0

Parameters
isom_filethe target ISO file

◆ gf_isom_get_fragmented_duration()

u64 gf_isom_get_fragmented_duration ( GF_ISOFile isom_file)

gets the duration of movie+fragments

Parameters
isom_filethe target ISO file
Returns
the duration in movie timescale, 0 if unknown or if error

◆ gf_isom_get_fragments_count()

u32 gf_isom_get_fragments_count ( GF_ISOFile isom_file,
Bool  segments_only 
)

gets the number of fragments or segments when the file is opened in GF_ISOM_OPEN_READ_DUMP mode

Parameters
isom_filethe target ISO file
segments_onlyif set to GF_TRUE, counts segments (sidx), otherwise counts fragments
Returns
the number of segments or fragments

◆ gf_isom_get_fragmented_samples_info()

GF_Err gf_isom_get_fragmented_samples_info ( GF_ISOFile isom_file,
GF_ISOTrackID  trackID,
u32 nb_samples,
u64 duration 
)

gets total sample number and duration when the file is opened in GF_ISOM_OPEN_READ_DUMP mode

Parameters
isom_filethe target ISO file
trackIDthe ID of the target track
nb_samplesset to the number of samples in the track
durationset to the total duration in media timescale
Returns
error if any

◆ gf_isom_get_next_moof_number()

u32 gf_isom_get_next_moof_number ( GF_ISOFile isom_file)

gets the number of the next moof to be produced

Parameters
isom_filethe target ISO file
Returns
number of the next moof