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.

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