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.

260 lines
8.0KB

  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 Libav.
  8. *
  9. * Libav 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. * Libav 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 Libav; 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 <stddef.h>
  26. #include <stdint.h>
  27. #include "libavutil/spherical.h"
  28. #include "libavutil/stereo3d.h"
  29. #include "avio.h"
  30. #include "internal.h"
  31. #include "dv.h"
  32. /* isom.c */
  33. extern const AVCodecTag ff_mp4_obj_type[];
  34. extern const AVCodecTag ff_codec_movvideo_tags[];
  35. extern const AVCodecTag ff_codec_movaudio_tags[];
  36. extern const AVCodecTag ff_codec_movsubtitle_tags[];
  37. int ff_mov_iso639_to_lang(const char lang[4], int mp4);
  38. int ff_mov_lang_to_iso639(unsigned code, char to[4]);
  39. /* the QuickTime file format is quite convoluted...
  40. * it has lots of index tables, each indexing something in another one...
  41. * Here we just use what is needed to read the chunks
  42. */
  43. typedef struct MOVStts {
  44. int count;
  45. int duration;
  46. } MOVStts;
  47. typedef struct MOVStsc {
  48. int first;
  49. int count;
  50. int id;
  51. } MOVStsc;
  52. typedef struct MOVDref {
  53. uint32_t type;
  54. char *path;
  55. char *dir;
  56. char volume[28];
  57. char filename[64];
  58. int16_t nlvl_to, nlvl_from;
  59. } MOVDref;
  60. typedef struct MOVAtom {
  61. uint32_t type;
  62. int64_t size; /* total size (excluding the size and type fields) */
  63. } MOVAtom;
  64. struct MOVParseTableEntry;
  65. typedef struct MOVFragment {
  66. unsigned track_id;
  67. uint64_t base_data_offset;
  68. uint64_t moof_offset;
  69. uint64_t implicit_offset;
  70. unsigned stsd_id;
  71. unsigned duration;
  72. unsigned size;
  73. unsigned flags;
  74. } MOVFragment;
  75. typedef struct MOVTrackExt {
  76. unsigned track_id;
  77. unsigned stsd_id;
  78. unsigned duration;
  79. unsigned size;
  80. unsigned flags;
  81. } MOVTrackExt;
  82. typedef struct MOVSbgp {
  83. unsigned int count;
  84. unsigned int index;
  85. } MOVSbgp;
  86. typedef struct MOVStreamContext {
  87. AVIOContext *pb;
  88. int ffindex; ///< AVStream index
  89. int next_chunk;
  90. unsigned int chunk_count;
  91. int64_t *chunk_offsets;
  92. unsigned int stts_count;
  93. MOVStts *stts_data;
  94. unsigned int ctts_count;
  95. MOVStts *ctts_data;
  96. unsigned int stsc_count;
  97. MOVStsc *stsc_data;
  98. unsigned int stsc_index;
  99. int stsc_sample;
  100. unsigned int stps_count;
  101. unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop
  102. int ctts_index;
  103. int ctts_sample;
  104. unsigned int sample_size;
  105. unsigned int sample_count;
  106. int *sample_sizes;
  107. int keyframe_absent;
  108. unsigned int keyframe_count;
  109. int *keyframes;
  110. int time_scale;
  111. int64_t time_offset; ///< time offset of the first edit list entry
  112. int current_sample;
  113. unsigned int bytes_per_frame;
  114. unsigned int samples_per_frame;
  115. int dv_audio_container;
  116. int pseudo_stream_id; ///< -1 means demux all ids
  117. int16_t audio_cid; ///< stsd audio compression id
  118. unsigned drefs_count;
  119. MOVDref *drefs;
  120. int dref_id;
  121. int width; ///< tkhd width
  122. int height; ///< tkhd height
  123. int dts_shift; ///< dts shift when ctts is negative
  124. uint32_t palette[256];
  125. int has_palette;
  126. int64_t data_size;
  127. int64_t track_end; ///< used for dts generation in fragmented movie files
  128. unsigned int rap_group_count;
  129. MOVSbgp *rap_group;
  130. /** extradata array (and size) for multiple stsd */
  131. uint8_t **extradata;
  132. int *extradata_size;
  133. int last_stsd_index;
  134. int stsd_count;
  135. int32_t *display_matrix;
  136. AVStereo3D *stereo3d;
  137. AVSphericalMapping *spherical;
  138. size_t spherical_size;
  139. } MOVStreamContext;
  140. typedef struct MOVContext {
  141. const AVClass *class; ///< class for private options
  142. AVFormatContext *fc;
  143. int time_scale;
  144. int64_t duration; ///< duration of the longest track
  145. int found_moov; ///< 'moov' atom has been found
  146. int found_mdat; ///< 'mdat' atom has been found
  147. DVDemuxContext *dv_demux;
  148. AVFormatContext *dv_fctx;
  149. int isom; ///< 1 if file is ISO Media (mp4/3gp)
  150. MOVFragment fragment; ///< current fragment in moof atom
  151. MOVTrackExt *trex_data;
  152. unsigned trex_count;
  153. int itunes_metadata; ///< metadata are itunes style
  154. int chapter_track;
  155. int seek_individually;
  156. int64_t next_root_atom; ///< offset of the next root atom
  157. int export_all;
  158. int export_xmp;
  159. int enable_drefs;
  160. int32_t movie_display_matrix[3][3]; ///< display matrix from mvhd
  161. } MOVContext;
  162. int ff_mp4_read_descr_len(AVIOContext *pb);
  163. int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag);
  164. int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb);
  165. void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
  166. #define MP4ODescrTag 0x01
  167. #define MP4IODescrTag 0x02
  168. #define MP4ESDescrTag 0x03
  169. #define MP4DecConfigDescrTag 0x04
  170. #define MP4DecSpecificDescrTag 0x05
  171. #define MP4SLDescrTag 0x06
  172. #define MOV_TFHD_BASE_DATA_OFFSET 0x01
  173. #define MOV_TFHD_STSD_ID 0x02
  174. #define MOV_TFHD_DEFAULT_DURATION 0x08
  175. #define MOV_TFHD_DEFAULT_SIZE 0x10
  176. #define MOV_TFHD_DEFAULT_FLAGS 0x20
  177. #define MOV_TFHD_DURATION_IS_EMPTY 0x010000
  178. #define MOV_TFHD_DEFAULT_BASE_IS_MOOF 0x020000
  179. #define MOV_TRUN_DATA_OFFSET 0x01
  180. #define MOV_TRUN_FIRST_SAMPLE_FLAGS 0x04
  181. #define MOV_TRUN_SAMPLE_DURATION 0x100
  182. #define MOV_TRUN_SAMPLE_SIZE 0x200
  183. #define MOV_TRUN_SAMPLE_FLAGS 0x400
  184. #define MOV_TRUN_SAMPLE_CTS 0x800
  185. #define MOV_FRAG_SAMPLE_FLAG_DEGRADATION_PRIORITY_MASK 0x0000ffff
  186. #define MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC 0x00010000
  187. #define MOV_FRAG_SAMPLE_FLAG_PADDING_MASK 0x000e0000
  188. #define MOV_FRAG_SAMPLE_FLAG_REDUNDANCY_MASK 0x00300000
  189. #define MOV_FRAG_SAMPLE_FLAG_DEPENDED_MASK 0x00c00000
  190. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_MASK 0x03000000
  191. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO 0x02000000
  192. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES 0x01000000
  193. #define MOV_TKHD_FLAG_ENABLED 0x0001
  194. #define MOV_TKHD_FLAG_IN_MOVIE 0x0002
  195. #define MOV_TKHD_FLAG_IN_PREVIEW 0x0004
  196. #define MOV_TKHD_FLAG_IN_POSTER 0x0008
  197. #define TAG_IS_AVCI(tag) \
  198. ((tag) == MKTAG('a', 'i', '5', 'p') || \
  199. (tag) == MKTAG('a', 'i', '5', 'q') || \
  200. (tag) == MKTAG('a', 'i', '5', '2') || \
  201. (tag) == MKTAG('a', 'i', '5', '3') || \
  202. (tag) == MKTAG('a', 'i', '5', '5') || \
  203. (tag) == MKTAG('a', 'i', '5', '6') || \
  204. (tag) == MKTAG('a', 'i', '1', 'p') || \
  205. (tag) == MKTAG('a', 'i', '1', 'q') || \
  206. (tag) == MKTAG('a', 'i', '1', '2') || \
  207. (tag) == MKTAG('a', 'i', '1', '3') || \
  208. (tag) == MKTAG('a', 'i', '1', '5') || \
  209. (tag) == MKTAG('a', 'i', '1', '6') || \
  210. (tag) == MKTAG('A', 'V', 'i', 'n'))
  211. int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb);
  212. int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
  213. /**
  214. * Compute codec id for 'lpcm' tag.
  215. * See CoreAudioTypes and AudioStreamBasicDescription at Apple.
  216. */
  217. static inline enum AVCodecID ff_mov_get_lpcm_codec_id(int bps, int flags)
  218. {
  219. /* lpcm flags:
  220. * 0x1 = float
  221. * 0x2 = big-endian
  222. * 0x4 = signed
  223. */
  224. return ff_get_pcm_codec_id(bps, flags & 1, flags & 2, flags & 4 ? -1 : 0);
  225. }
  226. #endif /* AVFORMAT_ISOM_H */