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.

323 lines
10KB

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