demux: libmp4: fix regression in trun reading (fix #19170)
[vlc.git] / modules / demux / mp4 / mp4.h
blob99cb9bbb5eae4b681362755f30974a30add15f62
1 /*****************************************************************************
2 * mp4.h : MP4 file input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2004, 2010, 2014 VLC authors and VideoLAN
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
20 *****************************************************************************/
21 #ifndef VLC_MP4_MP4_H_
22 #define VLC_MP4_MP4_H_
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #include <vlc_common.h>
29 #include "libmp4.h"
30 #include "fragments.h"
31 #include "../asf/asfpacket.h"
33 /* Contain all information about a chunk */
34 typedef struct
36 uint64_t i_offset; /* absolute position of this chunk in the file */
37 uint32_t i_sample_description_index; /* index for SampleEntry to use */
38 uint32_t i_sample_count; /* how many samples in this chunk */
39 uint32_t i_sample_first; /* index of the first sample in this chunk */
40 uint32_t i_sample; /* index of the next sample to read in this chunk */
41 uint32_t i_virtual_run_number; /* chunks interleaving sequence */
43 /* now provide way to calculate pts, dts, and offset without too
44 much memory and with fast access */
46 /* with this we can calculate dts/pts without waste memory */
47 uint64_t i_first_dts; /* DTS of the first sample */
48 uint64_t i_duration; /* total duration of all samples */
50 uint32_t i_entries_dts;
51 uint32_t *p_sample_count_dts;
52 uint32_t *p_sample_delta_dts; /* dts delta */
54 uint32_t i_entries_pts;
55 uint32_t *p_sample_count_pts;
56 int32_t *p_sample_offset_pts; /* pts-dts */
58 uint32_t *p_sample_size;
59 /* TODO if needed add pts
60 but quickly *add* support for edts and seeking */
62 } mp4_chunk_t;
64 typedef struct
66 uint64_t i_offset;
67 stime_t i_first_dts;
68 const MP4_Box_t *p_trun;
69 } mp4_run_t;
71 typedef enum RTP_timstamp_synchronization_s
73 UNKNOWN_SYNC = 0, UNSYNCHRONIZED = 1, SYNCHRONIZED = 2, RESERVED = 3
74 } RTP_timstamp_synchronization_t;
76 /* Contain all needed information for read all track with vlc */
77 typedef struct
79 unsigned int i_track_ID;/* this should be unique */
81 int b_ok; /* The track is usable */
82 int b_enable; /* is the trak enable by default */
83 bool b_selected; /* is the trak being played */
84 bool b_chapters_source; /* True when used for chapter only */
85 bool b_forced_spu; /* forced track selection (never done by default/priority) */
86 uint32_t i_switch_group;
88 bool b_mac_encoding;
90 es_format_t fmt;
91 uint32_t i_block_flags;
92 uint32_t i_next_block_flags;
93 uint8_t rgi_chans_reordering[AOUT_CHAN_MAX];
94 bool b_chans_reorder;
95 es_out_id_t *p_es;
97 /* display size only ! */
98 int i_width;
99 int i_height;
100 float f_rotation;
102 /* more internal data */
103 uint32_t i_timescale; /* time scale for this track only */
105 /* elst */
106 int i_elst; /* current elst */
107 int64_t i_elst_time; /* current elst start time (in movie time scale)*/
108 const MP4_Box_t *p_elst; /* elst (could be NULL) */
110 /* give the next sample to read, i_chunk is to find quickly where
111 the sample is located */
112 uint32_t i_sample; /* next sample to read */
113 uint32_t i_chunk; /* chunk where next sample is stored */
114 /* total count of chunk and sample */
115 uint32_t i_chunk_count;
116 uint32_t i_sample_count;
118 mp4_chunk_t *chunk; /* always defined for each chunk */
120 /* sample size, p_sample_size defined only if i_sample_size == 0
121 else i_sample_size is size for all sample */
122 uint32_t i_sample_size;
123 uint32_t *p_sample_size; /* XXX perhaps add file offset if take
124 // too much time to do sumations each time*/
126 uint32_t i_sample_first; /* i_sample_first value
127 of the next chunk */
128 uint64_t i_first_dts; /* i_first_dts value
129 of the next chunk */
131 const MP4_Box_t *p_track;
132 const MP4_Box_t *p_stbl; /* will contain all timing information */
133 const MP4_Box_t *p_stsd; /* will contain all data to initialize decoder */
134 const MP4_Box_t *p_sample;/* point on actual sdsd */
136 #if 0
137 bool b_codec_need_restart;
138 #endif
140 mtime_t i_time; // track scaled
142 /* rrtp reception hint track */
143 MP4_Box_t *p_sdp; /* parsed for codec and other info */
144 RTP_timstamp_synchronization_t sync_mode; /* whether track is already in sync */
146 /* First recorded RTP timestamp offset.
147 * Needed for rrtp synchronization */
148 int32_t i_tsro_offset;
150 struct
152 /* for moof parsing */
153 /* tfhd defaults */
154 uint32_t i_default_sample_size;
155 uint32_t i_default_sample_duration;
157 struct
159 mp4_run_t *p_array;
160 uint32_t i_current;
161 uint32_t i_count;
162 } runs;
163 uint64_t i_trun_sample;
164 uint64_t i_trun_sample_pos;
166 } context;
168 /* ASF packets handling */
169 const MP4_Box_t *p_asf;
170 mtime_t i_dts_backup;
171 mtime_t i_pts_backup;
172 asf_track_info_t asfinfo;
173 } mp4_track_t;
175 int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample );
176 int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample );
177 int SetupSpuES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample );
178 int SetupCCES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample );
179 void SetupMeta( vlc_meta_t *p_meta, MP4_Box_t *p_udta );
181 /* format of RTP reception hint track sample constructor */
182 typedef struct
184 uint8_t type;
185 int8_t trackrefindex;
186 uint16_t length;
187 uint32_t samplenumber;
188 uint32_t sampleoffset; /* indicates where the payload is located within sample */
189 uint16_t bytesperblock;
190 uint16_t samplesperblock;
192 } mp4_rtpsampleconstructor_t;
194 #endif