isom.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 MOVStreamContext {
  78. AVIOContext *pb;
  79. int ffindex; ///< AVStream index
  80. int next_chunk;
  81. unsigned int chunk_count;
  82. int64_t *chunk_offsets;
  83. unsigned int stts_count;
  84. MOVStts *stts_data;
  85. unsigned int ctts_count;
  86. MOVStts *ctts_data;
  87. unsigned int stsc_count;
  88. MOVStsc *stsc_data;
  89. unsigned int stps_count;
  90. unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop
  91. int ctts_index;
  92. int ctts_sample;
  93. unsigned int sample_size; ///< may contain value calculated from stsd or value from stsz atom
  94. unsigned int alt_sample_size; ///< always contains sample size from stsz atom
  95. unsigned int sample_count;
  96. int *sample_sizes;
  97. int keyframe_absent;
  98. unsigned int keyframe_count;
  99. int *keyframes;
  100. int time_scale;
  101. int64_t empty_duration; ///< empty duration of the first edit list entry
  102. int64_t start_time; ///< start time of the media
  103. int64_t time_offset; ///< time offset of the edit list entries
  104. int current_sample;
  105. unsigned int bytes_per_frame;
  106. unsigned int samples_per_frame;
  107. int dv_audio_container;
  108. int pseudo_stream_id; ///< -1 means demux all ids
  109. int16_t audio_cid; ///< stsd audio compression id
  110. unsigned drefs_count;
  111. MOVDref *drefs;
  112. int dref_id;
  113. int wrong_dts; ///< dts are wrong due to huge ctts offset (iMovie files)
  114. int width; ///< tkhd width
  115. int height; ///< tkhd height
  116. int dts_shift; ///< dts shift when ctts is negative
  117. uint32_t palette[256];
  118. int has_palette;
  119. int64_t data_size;
  120. uint32_t tmcd_flags; ///< tmcd track flags
  121. int64_t track_end; ///< used for dts generation in fragmented movie files
  122. } MOVStreamContext;
  123. typedef struct MOVContext {
  124. AVClass *avclass;
  125. AVFormatContext *fc;
  126. int time_scale;
  127. int64_t duration; ///< duration of the longest track
  128. int found_moov; ///< 'moov' atom has been found
  129. int found_mdat; ///< 'mdat' atom has been found
  130. DVDemuxContext *dv_demux;
  131. AVFormatContext *dv_fctx;
  132. int isom; ///< 1 if file is ISO Media (mp4/3gp)
  133. MOVFragment fragment; ///< current fragment in moof atom
  134. MOVTrackExt *trex_data;
  135. unsigned trex_count;
  136. int itunes_metadata; ///< metadata are itunes style
  137. int chapter_track;
  138. int use_absolute_path;
  139. int64_t next_root_atom; ///< offset of the next root atom
  140. } MOVContext;
  141. int ff_mp4_read_descr_len(AVIOContext *pb);
  142. int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag);
  143. int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb);
  144. void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id);
  145. #define MP4ODescrTag 0x01
  146. #define MP4IODescrTag 0x02
  147. #define MP4ESDescrTag 0x03
  148. #define MP4DecConfigDescrTag 0x04
  149. #define MP4DecSpecificDescrTag 0x05
  150. #define MP4SLDescrTag 0x06
  151. #define MOV_TFHD_BASE_DATA_OFFSET 0x01
  152. #define MOV_TFHD_STSD_ID 0x02
  153. #define MOV_TFHD_DEFAULT_DURATION 0x08
  154. #define MOV_TFHD_DEFAULT_SIZE 0x10
  155. #define MOV_TFHD_DEFAULT_FLAGS 0x20
  156. #define MOV_TFHD_DURATION_IS_EMPTY 0x010000
  157. #define MOV_TRUN_DATA_OFFSET 0x01
  158. #define MOV_TRUN_FIRST_SAMPLE_FLAGS 0x04
  159. #define MOV_TRUN_SAMPLE_DURATION 0x100
  160. #define MOV_TRUN_SAMPLE_SIZE 0x200
  161. #define MOV_TRUN_SAMPLE_FLAGS 0x400
  162. #define MOV_TRUN_SAMPLE_CTS 0x800
  163. #define MOV_FRAG_SAMPLE_FLAG_DEGRADATION_PRIORITY_MASK 0x0000ffff
  164. #define MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC 0x00010000
  165. #define MOV_FRAG_SAMPLE_FLAG_PADDING_MASK 0x000e0000
  166. #define MOV_FRAG_SAMPLE_FLAG_REDUNDANCY_MASK 0x00300000
  167. #define MOV_FRAG_SAMPLE_FLAG_DEPENDED_MASK 0x00c00000
  168. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_MASK 0x03000000
  169. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO 0x02000000
  170. #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES 0x01000000
  171. int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom);
  172. enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
  173. int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
  174. void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec);
  175. void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout);
  176. #endif /* AVFORMAT_ISOM_H */