isom.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 {
  40. int count;
  41. int duration;
  42. } MOVStts;
  43. typedef struct {
  44. int first;
  45. int count;
  46. int id;
  47. } MOVStsc;
  48. typedef struct {
  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 {
  57. uint32_t type;
  58. int64_t size; /* total size (excluding the size and type fields) */
  59. } MOVAtom;
  60. struct MOVParseTableEntry;
  61. typedef struct {
  62. unsigned track_id;
  63. uint64_t base_data_offset;
  64. uint64_t moof_offset;
  65. unsigned stsd_id;
  66. unsigned duration;
  67. unsigned size;
  68. unsigned flags;
  69. } MOVFragment;
  70. typedef struct {
  71. unsigned track_id;
  72. unsigned stsd_id;
  73. unsigned duration;
  74. unsigned size;
  75. unsigned flags;
  76. } MOVTrackExt;
  77. typedef struct {
  78. unsigned int count;
  79. unsigned int index;
  80. } MOVSbgp;
  81. typedef struct MOVStreamContext {
  82. AVIOContext *pb;
  83. int ffindex; ///< AVStream index
  84. int next_chunk;
  85. unsigned int chunk_count;
  86. int64_t *chunk_offsets;
  87. unsigned int stts_count;
  88. MOVStts *stts_data;
  89. unsigned int ctts_count;
  90. MOVStts *ctts_data;
  91. unsigned int stsc_count;
  92. MOVStsc *stsc_data;
  93. unsigned int stps_count;
  94. unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop
  95. int ctts_index;
  96. int ctts_sample;
  97. unsigned int sample_size; ///< may contain value calculated from stsd or value from stsz atom
  98. unsigned int alt_sample_size; ///< always contains sample size from stsz atom
  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 empty_duration; ///< empty duration of the first edit list entry
  106. int64_t start_time; ///< start time of the media
  107. int64_t time_offset; ///< time offset of the edit list entries
  108. int current_sample;
  109. unsigned int bytes_per_frame;
  110. unsigned int samples_per_frame;
  111. int dv_audio_container;
  112. int pseudo_stream_id; ///< -1 means demux all ids
  113. int16_t audio_cid; ///< stsd audio compression id
  114. unsigned drefs_count;
  115. MOVDref *drefs;
  116. int dref_id;
  117. unsigned tref_type;
  118. unsigned trefs_count;
  119. uint32_t *trefs;
  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. } MOVStreamContext;
  133. typedef struct MOVContext {
  134. AVClass *avclass;
  135. AVFormatContext *fc;
  136. int time_scale;
  137. int64_t duration; ///< duration of the longest track
  138. int found_moov; ///< 'moov' atom has been found
  139. int found_mdat; ///< 'mdat' atom has been found
  140. DVDemuxContext *dv_demux;
  141. AVFormatContext *dv_fctx;
  142. int isom; ///< 1 if file is ISO Media (mp4/3gp)
  143. MOVFragment fragment; ///< current fragment in moof atom
  144. MOVTrackExt *trex_data;
  145. unsigned trex_count;
  146. int itunes_metadata; ///< metadata are itunes style
  147. int chapter_track;
  148. int use_absolute_path;
  149. int64_t next_root_atom; ///< offset of the next root atom
  150. } MOVContext;
  151. int ff_mp4_read_descr_len(AVIOContext *pb);
  152. int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag);
  153. int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb);
  154. void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
  155. #define MP4ODescrTag 0x01
  156. #define MP4IODescrTag 0x02
  157. #define MP4ESDescrTag 0x03
  158. #define MP4DecConfigDescrTag 0x04
  159. #define MP4DecSpecificDescrTag 0x05
  160. #define MP4SLDescrTag 0x06
  161. #define MOV_TFHD_BASE_DATA_OFFSET 0x01
  162. #define MOV_TFHD_STSD_ID 0x02
  163. #define MOV_TFHD_DEFAULT_DURATION 0x08
  164. #define MOV_TFHD_DEFAULT_SIZE 0x10
  165. #define MOV_TFHD_DEFAULT_FLAGS 0x20
  166. #define MOV_TFHD_DURATION_IS_EMPTY 0x010000
  167. #define MOV_TRUN_DATA_OFFSET 0x01
  168. #define MOV_TRUN_FIRST_SAMPLE_FLAGS 0x04
  169. #define MOV_TRUN_SAMPLE_DURATION 0x100
  170. #define MOV_TRUN_SAMPLE_SIZE 0x200
  171. #define MOV_TRUN_SAMPLE_FLAGS 0x400
  172. #define MOV_TRUN_SAMPLE_CTS 0x800
  173. #define MOV_FRAG_SAMPLE_FLAG_DEGRADATION_PRIORITY_MASK 0x0000ffff
  174. #define MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC 0x00010000
  175. #define MOV_FRAG_SAMPLE_FLAG_PADDING_MASK 0x000e0000
  176. #define MOV_FRAG_SAMPLE_FLAG_REDUNDANCY_MASK 0x00300000
  177. #define MOV_FRAG_SAMPLE_FLAG_DEPENDED_MASK 0x00c00000
  178. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_MASK 0x03000000
  179. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO 0x02000000
  180. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES 0x01000000
  181. int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom);
  182. enum AVCodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
  183. int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
  184. int ff_mov_read_chan(AVFormatContext *s, AVIOContext *pb, AVStream *st, int64_t size);
  185. void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout);
  186. #endif /* AVFORMAT_ISOM_H */