You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

313 lines
9.7KB

  1. /*
  2. * ISO Media common code
  3. * copyright (c) 2001 Fabrice Bellard
  4. * copyright (c) 2002 Francois Revol <revol@free.fr>
  5. * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr>
  6. *
  7. * This file is part of FFmpeg.
  8. *
  9. * FFmpeg is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * FFmpeg is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with FFmpeg; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #ifndef AVFORMAT_ISOM_H
  24. #define AVFORMAT_ISOM_H
  25. #include "avio.h"
  26. #include "internal.h"
  27. #include "dv.h"
  28. /* isom.c */
  29. extern const AVCodecTag ff_mp4_obj_type[];
  30. extern const AVCodecTag ff_codec_movvideo_tags[];
  31. extern const AVCodecTag ff_codec_movaudio_tags[];
  32. extern const AVCodecTag ff_codec_movsubtitle_tags[];
  33. int ff_mov_iso639_to_lang(const char lang[4], int mp4);
  34. int ff_mov_lang_to_iso639(unsigned code, char to[4]);
  35. struct AVAESCTR;
  36. /* the QuickTime file format is quite convoluted...
  37. * it has lots of index tables, each indexing something in another one...
  38. * Here we just use what is needed to read the chunks
  39. */
  40. typedef struct MOVStts {
  41. int count;
  42. int duration;
  43. } MOVStts;
  44. typedef struct MOVStsc {
  45. int first;
  46. int count;
  47. int id;
  48. } MOVStsc;
  49. typedef struct MOVElst {
  50. int64_t duration;
  51. int64_t time;
  52. float rate;
  53. } MOVElst;
  54. typedef struct MOVDref {
  55. uint32_t type;
  56. char *path;
  57. char *dir;
  58. char volume[28];
  59. char filename[64];
  60. int16_t nlvl_to, nlvl_from;
  61. } MOVDref;
  62. typedef struct MOVAtom {
  63. uint32_t type;
  64. int64_t size; /* total size (excluding the size and type fields) */
  65. } MOVAtom;
  66. struct MOVParseTableEntry;
  67. typedef struct MOVFragment {
  68. unsigned track_id;
  69. uint64_t base_data_offset;
  70. uint64_t moof_offset;
  71. uint64_t implicit_offset;
  72. unsigned stsd_id;
  73. unsigned duration;
  74. unsigned size;
  75. unsigned flags;
  76. int64_t time;
  77. } MOVFragment;
  78. typedef struct MOVTrackExt {
  79. unsigned track_id;
  80. unsigned stsd_id;
  81. unsigned duration;
  82. unsigned size;
  83. unsigned flags;
  84. } MOVTrackExt;
  85. typedef struct MOVSbgp {
  86. unsigned int count;
  87. unsigned int index;
  88. } MOVSbgp;
  89. typedef struct MOVFragmentIndexItem {
  90. int64_t moof_offset;
  91. int64_t time;
  92. int headers_read;
  93. } MOVFragmentIndexItem;
  94. typedef struct MOVFragmentIndex {
  95. unsigned track_id;
  96. unsigned item_count;
  97. unsigned current_item;
  98. MOVFragmentIndexItem *items;
  99. } MOVFragmentIndex;
  100. typedef struct MOVStreamContext {
  101. AVIOContext *pb;
  102. int pb_is_copied;
  103. int ffindex; ///< AVStream index
  104. int next_chunk;
  105. unsigned int chunk_count;
  106. int64_t *chunk_offsets;
  107. unsigned int stts_count;
  108. MOVStts *stts_data;
  109. unsigned int ctts_count;
  110. MOVStts *ctts_data;
  111. unsigned int stsc_count;
  112. MOVStsc *stsc_data;
  113. int stsc_index;
  114. int stsc_sample;
  115. unsigned int stps_count;
  116. unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop
  117. MOVElst *elst_data;
  118. unsigned int elst_count;
  119. int ctts_index;
  120. int ctts_sample;
  121. unsigned int sample_size; ///< may contain value calculated from stsd or value from stsz atom
  122. unsigned int stsz_sample_size; ///< always contains sample size from stsz atom
  123. unsigned int sample_count;
  124. int *sample_sizes;
  125. int keyframe_absent;
  126. unsigned int keyframe_count;
  127. int *keyframes;
  128. int time_scale;
  129. int64_t time_offset; ///< time offset of the edit list entries
  130. int current_sample;
  131. unsigned int bytes_per_frame;
  132. unsigned int samples_per_frame;
  133. int dv_audio_container;
  134. int pseudo_stream_id; ///< -1 means demux all ids
  135. int16_t audio_cid; ///< stsd audio compression id
  136. unsigned drefs_count;
  137. MOVDref *drefs;
  138. int dref_id;
  139. int timecode_track;
  140. int width; ///< tkhd width
  141. int height; ///< tkhd height
  142. int dts_shift; ///< dts shift when ctts is negative
  143. uint32_t palette[256];
  144. int has_palette;
  145. int64_t data_size;
  146. uint32_t tmcd_flags; ///< tmcd track flags
  147. int64_t track_end; ///< used for dts generation in fragmented movie files
  148. int start_pad; ///< amount of samples to skip due to enc-dec delay
  149. unsigned int rap_group_count;
  150. MOVSbgp *rap_group;
  151. int nb_frames_for_fps;
  152. int64_t duration_for_fps;
  153. /** extradata array (and size) for multiple stsd */
  154. uint8_t **extradata;
  155. int *extradata_size;
  156. int last_stsd_index;
  157. int stsd_count;
  158. int32_t *display_matrix;
  159. uint32_t format;
  160. struct {
  161. int use_subsamples;
  162. uint8_t* auxiliary_info;
  163. uint8_t* auxiliary_info_end;
  164. uint8_t* auxiliary_info_pos;
  165. uint8_t auxiliary_info_default_size;
  166. uint8_t* auxiliary_info_sizes;
  167. size_t auxiliary_info_sizes_count;
  168. struct AVAESCTR* aes_ctr;
  169. } cenc;
  170. } MOVStreamContext;
  171. typedef struct MOVContext {
  172. const AVClass *class; ///< class for private options
  173. AVFormatContext *fc;
  174. int time_scale;
  175. int64_t duration; ///< duration of the longest track
  176. int found_moov; ///< 'moov' atom has been found
  177. int found_mdat; ///< 'mdat' atom has been found
  178. int found_hdlr_mdta; ///< 'hdlr' atom with type 'mdta' has been found
  179. int trak_index; ///< Index of the current 'trak'
  180. char **meta_keys;
  181. unsigned meta_keys_count;
  182. DVDemuxContext *dv_demux;
  183. AVFormatContext *dv_fctx;
  184. int isom; ///< 1 if file is ISO Media (mp4/3gp)
  185. MOVFragment fragment; ///< current fragment in moof atom
  186. MOVTrackExt *trex_data;
  187. unsigned trex_count;
  188. int itunes_metadata; ///< metadata are itunes style
  189. int handbrake_version;
  190. int chapter_track;
  191. int use_absolute_path;
  192. int ignore_editlist;
  193. int ignore_chapters;
  194. int seek_individually;
  195. int64_t next_root_atom; ///< offset of the next root atom
  196. int export_all;
  197. int export_xmp;
  198. int *bitrates; ///< bitrates read before streams creation
  199. int bitrates_count;
  200. int moov_retry;
  201. int use_mfra_for;
  202. int has_looked_for_mfra;
  203. MOVFragmentIndex** fragment_index_data;
  204. unsigned fragment_index_count;
  205. int fragment_index_complete;
  206. int atom_depth;
  207. unsigned int aax_mode; ///< 'aax' file has been detected
  208. uint8_t file_key[20];
  209. uint8_t file_iv[20];
  210. void *activation_bytes;
  211. int activation_bytes_size;
  212. void *audible_fixed_key;
  213. int audible_fixed_key_size;
  214. struct AVAES *aes_decrypt;
  215. uint8_t *decryption_key;
  216. int decryption_key_len;
  217. int enable_drefs;
  218. } MOVContext;
  219. int ff_mp4_read_descr_len(AVIOContext *pb);
  220. int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag);
  221. int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb);
  222. void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
  223. #define MP4ODescrTag 0x01
  224. #define MP4IODescrTag 0x02
  225. #define MP4ESDescrTag 0x03
  226. #define MP4DecConfigDescrTag 0x04
  227. #define MP4DecSpecificDescrTag 0x05
  228. #define MP4SLDescrTag 0x06
  229. #define MOV_TFHD_BASE_DATA_OFFSET 0x01
  230. #define MOV_TFHD_STSD_ID 0x02
  231. #define MOV_TFHD_DEFAULT_DURATION 0x08
  232. #define MOV_TFHD_DEFAULT_SIZE 0x10
  233. #define MOV_TFHD_DEFAULT_FLAGS 0x20
  234. #define MOV_TFHD_DURATION_IS_EMPTY 0x010000
  235. #define MOV_TFHD_DEFAULT_BASE_IS_MOOF 0x020000
  236. #define MOV_TRUN_DATA_OFFSET 0x01
  237. #define MOV_TRUN_FIRST_SAMPLE_FLAGS 0x04
  238. #define MOV_TRUN_SAMPLE_DURATION 0x100
  239. #define MOV_TRUN_SAMPLE_SIZE 0x200
  240. #define MOV_TRUN_SAMPLE_FLAGS 0x400
  241. #define MOV_TRUN_SAMPLE_CTS 0x800
  242. #define MOV_FRAG_SAMPLE_FLAG_DEGRADATION_PRIORITY_MASK 0x0000ffff
  243. #define MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC 0x00010000
  244. #define MOV_FRAG_SAMPLE_FLAG_PADDING_MASK 0x000e0000
  245. #define MOV_FRAG_SAMPLE_FLAG_REDUNDANCY_MASK 0x00300000
  246. #define MOV_FRAG_SAMPLE_FLAG_DEPENDED_MASK 0x00c00000
  247. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_MASK 0x03000000
  248. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO 0x02000000
  249. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES 0x01000000
  250. #define MOV_TKHD_FLAG_ENABLED 0x0001
  251. #define MOV_TKHD_FLAG_IN_MOVIE 0x0002
  252. #define MOV_TKHD_FLAG_IN_PREVIEW 0x0004
  253. #define MOV_TKHD_FLAG_IN_POSTER 0x0008
  254. #define TAG_IS_AVCI(tag) \
  255. ((tag) == MKTAG('a', 'i', '5', 'p') || \
  256. (tag) == MKTAG('a', 'i', '5', 'q') || \
  257. (tag) == MKTAG('a', 'i', '5', '2') || \
  258. (tag) == MKTAG('a', 'i', '5', '3') || \
  259. (tag) == MKTAG('a', 'i', '5', '5') || \
  260. (tag) == MKTAG('a', 'i', '5', '6') || \
  261. (tag) == MKTAG('a', 'i', '1', 'p') || \
  262. (tag) == MKTAG('a', 'i', '1', 'q') || \
  263. (tag) == MKTAG('a', 'i', '1', '2') || \
  264. (tag) == MKTAG('a', 'i', '1', '3') || \
  265. (tag) == MKTAG('a', 'i', '1', '5') || \
  266. (tag) == MKTAG('a', 'i', '1', '6') || \
  267. (tag) == MKTAG('a', 'i', 'v', 'x') || \
  268. (tag) == MKTAG('A', 'V', 'i', 'n'))
  269. int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb);
  270. enum AVCodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
  271. int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
  272. void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout);
  273. #define FF_MOV_FLAG_MFRA_AUTO -1
  274. #define FF_MOV_FLAG_MFRA_DTS 1
  275. #define FF_MOV_FLAG_MFRA_PTS 2
  276. #endif /* AVFORMAT_ISOM_H */