1 /***************************************************************************** 2 * mp4.h : MP4 file input module for vlc 3 ***************************************************************************** 4 * Copyright (C) 2001-2004, 2010, 2014 VLC authors and VideoLAN 5 * 6 * 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. 11 * 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. 16 * 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_ 23 24 /***************************************************************************** 25 * Preamble 26 *****************************************************************************/ 27 28 #include <vlc_common.h> 29 #include "libmp4.h" 30 #include "fragments.h" 31 #include "../asf/asfpacket.h" 32 33 /* Contain all information about a chunk */ 34 typedef struct 35 { 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 */ 42 43 /* now provide way to calculate pts, dts, and offset without too 44 much memory and with fast access */ 45 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 */ 49 50 uint32_t i_entries_dts; 51 uint32_t *p_sample_count_dts; 52 uint32_t *p_sample_delta_dts; /* dts delta */ 53 54 uint32_t i_entries_pts; 55 uint32_t *p_sample_count_pts; 56 int32_t *p_sample_offset_pts; /* pts-dts */ 57 58 uint32_t *p_sample_size; 59 /* TODO if needed add pts 60 but quickly *add* support for edts and seeking */ 61 62 } mp4_chunk_t; 63 64 typedef struct 65 { 66 uint64_t i_offset; 67 stime_t i_first_dts; 68 const MP4_Box_t *p_trun; 69 } mp4_run_t; 70 71 typedef enum RTP_timstamp_synchronization_s 72 { 73 UNKNOWN_SYNC = 0, UNSYNCHRONIZED = 1, SYNCHRONIZED = 2, RESERVED = 3 74 } RTP_timstamp_synchronization_t; 75 76 /* Contain all needed information for read all track with vlc */ 77 typedef struct 78 { 79 unsigned int i_track_ID;/* this should be unique */ 80 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; 87 88 bool b_mac_encoding; 89 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; 96 97 /* display size only ! */ 98 int i_width; 99 int i_height; 100 float f_rotation; 101 102 /* more internal data */ 103 uint32_t i_timescale; /* time scale for this track only */ 104 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) */ 109 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; 117 118 mp4_chunk_t *chunk; /* always defined for each chunk */ 119 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*/ 125 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 */ 130 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 */ 135 136 #if 0 137 bool b_codec_need_restart; 138 #endif 139 140 mtime_t i_time; // track scaled 141 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 */ 145 146 /* First recorded RTP timestamp offset. 147 * Needed for rrtp synchronization */ 148 int32_t i_tsro_offset; 149 150 struct 151 { 152 /* for moof parsing */ 153 /* tfhd defaults */ 154 uint32_t i_default_sample_size; 155 uint32_t i_default_sample_duration; 156 157 struct 158 { 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; 165 166 int i_temp; 167 } context; 168 169 /* ASF packets handling */ 170 const MP4_Box_t *p_asf; 171 mtime_t i_dts_backup; 172 mtime_t i_pts_backup; 173 asf_track_info_t asfinfo; 174 } mp4_track_t; 175 176 int SetupVideoES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample ); 177 int SetupAudioES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample ); 178 int SetupSpuES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample ); 179 int SetupCCES( demux_t *p_demux, mp4_track_t *p_track, MP4_Box_t *p_sample ); 180 void SetupMeta( vlc_meta_t *p_meta, MP4_Box_t *p_udta ); 181 182 /* format of RTP reception hint track sample constructor */ 183 typedef struct 184 { 185 uint8_t type; 186 int8_t trackrefindex; 187 uint16_t length; 188 uint32_t samplenumber; 189 uint32_t sampleoffset; /* indicates where the payload is located within sample */ 190 uint16_t bytesperblock; 191 uint16_t samplesperblock; 192 193 } mp4_rtpsampleconstructor_t; 194 195 #endif 196