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.

227 lines
7.3KB

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