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.

241 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 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. /* 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 pb_is_copied;
  85. int ffindex; ///< AVStream index
  86. int next_chunk;
  87. unsigned int chunk_count;
  88. int64_t *chunk_offsets;
  89. unsigned int stts_count;
  90. MOVStts *stts_data;
  91. unsigned int ctts_count;
  92. MOVStts *ctts_data;
  93. unsigned int stsc_count;
  94. MOVStsc *stsc_data;
  95. unsigned int stps_count;
  96. unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop
  97. int ctts_index;
  98. int ctts_sample;
  99. unsigned int sample_size; ///< may contain value calculated from stsd or value from stsz atom
  100. unsigned int stsz_sample_size; ///< always contains sample size from stsz atom
  101. unsigned int sample_count;
  102. int *sample_sizes;
  103. int keyframe_absent;
  104. unsigned int keyframe_count;
  105. int *keyframes;
  106. int time_scale;
  107. int64_t empty_duration; ///< empty duration of the first edit list entry
  108. int64_t start_time; ///< start time of the media
  109. int64_t time_offset; ///< time offset of the edit list entries
  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 timecode_track;
  120. int wrong_dts; ///< dts are wrong due to huge ctts offset (iMovie files)
  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. uint32_t tmcd_flags; ///< tmcd track flags
  128. int64_t track_end; ///< used for dts generation in fragmented movie files
  129. int start_pad; ///< amount of samples to skip due to enc-dec delay
  130. unsigned int rap_group_count;
  131. MOVSbgp *rap_group;
  132. int nb_frames_for_fps;
  133. int64_t duration_for_fps;
  134. int32_t *display_matrix;
  135. } MOVStreamContext;
  136. typedef struct MOVContext {
  137. AVClass *avclass;
  138. AVFormatContext *fc;
  139. int time_scale;
  140. int64_t duration; ///< duration of the longest track
  141. int found_moov; ///< 'moov' atom has been found
  142. int found_mdat; ///< 'mdat' atom has been found
  143. DVDemuxContext *dv_demux;
  144. AVFormatContext *dv_fctx;
  145. int isom; ///< 1 if file is ISO Media (mp4/3gp)
  146. MOVFragment fragment; ///< current fragment in moof atom
  147. MOVTrackExt *trex_data;
  148. unsigned trex_count;
  149. int itunes_metadata; ///< metadata are itunes style
  150. int chapter_track;
  151. int use_absolute_path;
  152. int ignore_editlist;
  153. int64_t next_root_atom; ///< offset of the next root atom
  154. int *bitrates; ///< bitrates read before streams creation
  155. int bitrates_count;
  156. int moov_retry;
  157. } MOVContext;
  158. int ff_mp4_read_descr_len(AVIOContext *pb);
  159. int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag);
  160. int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb);
  161. void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
  162. #define MP4ODescrTag 0x01
  163. #define MP4IODescrTag 0x02
  164. #define MP4ESDescrTag 0x03
  165. #define MP4DecConfigDescrTag 0x04
  166. #define MP4DecSpecificDescrTag 0x05
  167. #define MP4SLDescrTag 0x06
  168. #define MOV_TFHD_BASE_DATA_OFFSET 0x01
  169. #define MOV_TFHD_STSD_ID 0x02
  170. #define MOV_TFHD_DEFAULT_DURATION 0x08
  171. #define MOV_TFHD_DEFAULT_SIZE 0x10
  172. #define MOV_TFHD_DEFAULT_FLAGS 0x20
  173. #define MOV_TFHD_DURATION_IS_EMPTY 0x010000
  174. #define MOV_TFHD_DEFAULT_BASE_IS_MOOF 0x020000
  175. #define MOV_TRUN_DATA_OFFSET 0x01
  176. #define MOV_TRUN_FIRST_SAMPLE_FLAGS 0x04
  177. #define MOV_TRUN_SAMPLE_DURATION 0x100
  178. #define MOV_TRUN_SAMPLE_SIZE 0x200
  179. #define MOV_TRUN_SAMPLE_FLAGS 0x400
  180. #define MOV_TRUN_SAMPLE_CTS 0x800
  181. #define MOV_FRAG_SAMPLE_FLAG_DEGRADATION_PRIORITY_MASK 0x0000ffff
  182. #define MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC 0x00010000
  183. #define MOV_FRAG_SAMPLE_FLAG_PADDING_MASK 0x000e0000
  184. #define MOV_FRAG_SAMPLE_FLAG_REDUNDANCY_MASK 0x00300000
  185. #define MOV_FRAG_SAMPLE_FLAG_DEPENDED_MASK 0x00c00000
  186. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_MASK 0x03000000
  187. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO 0x02000000
  188. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES 0x01000000
  189. #define MOV_TKHD_FLAG_ENABLED 0x0001
  190. #define MOV_TKHD_FLAG_IN_MOVIE 0x0002
  191. #define MOV_TKHD_FLAG_IN_PREVIEW 0x0004
  192. #define MOV_TKHD_FLAG_IN_POSTER 0x0008
  193. #define TAG_IS_AVCI(tag) \
  194. ((tag) == MKTAG('a', 'i', '5', 'p') || \
  195. (tag) == MKTAG('a', 'i', '5', 'q') || \
  196. (tag) == MKTAG('a', 'i', '5', '2') || \
  197. (tag) == MKTAG('a', 'i', '5', '3') || \
  198. (tag) == MKTAG('a', 'i', '5', '5') || \
  199. (tag) == MKTAG('a', 'i', '5', '6') || \
  200. (tag) == MKTAG('a', 'i', '1', 'p') || \
  201. (tag) == MKTAG('a', 'i', '1', 'q') || \
  202. (tag) == MKTAG('a', 'i', '1', '2') || \
  203. (tag) == MKTAG('a', 'i', '1', '3') || \
  204. (tag) == MKTAG('a', 'i', '1', '5') || \
  205. (tag) == MKTAG('a', 'i', '1', '6') || \
  206. (tag) == MKTAG('A', 'V', 'i', 'n'))
  207. int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom);
  208. enum AVCodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
  209. int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
  210. void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout);
  211. #endif /* AVFORMAT_ISOM_H */