isom.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 codec_movvideo_tags[];
  31. extern const AVCodecTag 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;
  94. unsigned int sample_count;
  95. int *sample_sizes;
  96. unsigned int keyframe_count;
  97. int *keyframes;
  98. int time_scale;
  99. int64_t time_offset; ///< time offset of the first edit list entry
  100. int current_sample;
  101. unsigned int bytes_per_frame;
  102. unsigned int samples_per_frame;
  103. int dv_audio_container;
  104. int pseudo_stream_id; ///< -1 means demux all ids
  105. int16_t audio_cid; ///< stsd audio compression id
  106. unsigned drefs_count;
  107. MOVDref *drefs;
  108. int dref_id;
  109. int wrong_dts; ///< dts are wrong due to huge ctts offset (iMovie files)
  110. int width; ///< tkhd width
  111. int height; ///< tkhd height
  112. int dts_shift; ///< dts shift when ctts is negative
  113. } MOVStreamContext;
  114. typedef struct MOVContext {
  115. AVFormatContext *fc;
  116. int time_scale;
  117. int64_t duration; ///< duration of the longest track
  118. int found_moov; ///< 'moov' atom has been found
  119. int found_mdat; ///< 'mdat' atom has been found
  120. DVDemuxContext *dv_demux;
  121. AVFormatContext *dv_fctx;
  122. int isom; ///< 1 if file is ISO Media (mp4/3gp)
  123. MOVFragment fragment; ///< current fragment in moof atom
  124. MOVTrackExt *trex_data;
  125. unsigned trex_count;
  126. int itunes_metadata; ///< metadata are itunes style
  127. int chapter_track;
  128. } MOVContext;
  129. int ff_mp4_read_descr_len(AVIOContext *pb);
  130. int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag);
  131. int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb);
  132. #define MP4IODescrTag 0x02
  133. #define MP4ESDescrTag 0x03
  134. #define MP4DecConfigDescrTag 0x04
  135. #define MP4DecSpecificDescrTag 0x05
  136. int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom);
  137. enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags);
  138. int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries);
  139. void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec);
  140. void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout);
  141. #endif /* AVFORMAT_ISOM_H */