yading@11: /* yading@11: * ISO Media common code yading@11: * copyright (c) 2001 Fabrice Bellard yading@11: * copyright (c) 2002 Francois Revol yading@11: * copyright (c) 2006 Baptiste Coudurier yading@11: * yading@11: * This file is part of FFmpeg. yading@11: * yading@11: * FFmpeg is free software; you can redistribute it and/or yading@11: * modify it under the terms of the GNU Lesser General Public yading@11: * License as published by the Free Software Foundation; either yading@11: * version 2.1 of the License, or (at your option) any later version. yading@11: * yading@11: * FFmpeg is distributed in the hope that it will be useful, yading@11: * but WITHOUT ANY WARRANTY; without even the implied warranty of yading@11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU yading@11: * Lesser General Public License for more details. yading@11: * yading@11: * You should have received a copy of the GNU Lesser General Public yading@11: * License along with FFmpeg; if not, write to the Free Software yading@11: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA yading@11: */ yading@11: yading@11: #ifndef AVFORMAT_ISOM_H yading@11: #define AVFORMAT_ISOM_H yading@11: yading@11: #include "avio.h" yading@11: #include "internal.h" yading@11: #include "dv.h" yading@11: yading@11: /* isom.c */ yading@11: extern const AVCodecTag ff_mp4_obj_type[]; yading@11: extern const AVCodecTag ff_codec_movvideo_tags[]; yading@11: extern const AVCodecTag ff_codec_movaudio_tags[]; yading@11: extern const AVCodecTag ff_codec_movsubtitle_tags[]; yading@11: yading@11: int ff_mov_iso639_to_lang(const char lang[4], int mp4); yading@11: int ff_mov_lang_to_iso639(unsigned code, char to[4]); yading@11: yading@11: /* the QuickTime file format is quite convoluted... yading@11: * it has lots of index tables, each indexing something in another one... yading@11: * Here we just use what is needed to read the chunks yading@11: */ yading@11: yading@11: typedef struct MOVStts { yading@11: int count; yading@11: int duration; yading@11: } MOVStts; yading@11: yading@11: typedef struct MOVStsc { yading@11: int first; yading@11: int count; yading@11: int id; yading@11: } MOVStsc; yading@11: yading@11: typedef struct MOVDref { yading@11: uint32_t type; yading@11: char *path; yading@11: char *dir; yading@11: char volume[28]; yading@11: char filename[64]; yading@11: int16_t nlvl_to, nlvl_from; yading@11: } MOVDref; yading@11: yading@11: typedef struct MOVAtom { yading@11: uint32_t type; yading@11: int64_t size; /* total size (excluding the size and type fields) */ yading@11: } MOVAtom; yading@11: yading@11: struct MOVParseTableEntry; yading@11: yading@11: typedef struct MOVFragment { yading@11: unsigned track_id; yading@11: uint64_t base_data_offset; yading@11: uint64_t moof_offset; yading@11: unsigned stsd_id; yading@11: unsigned duration; yading@11: unsigned size; yading@11: unsigned flags; yading@11: } MOVFragment; yading@11: yading@11: typedef struct MOVTrackExt { yading@11: unsigned track_id; yading@11: unsigned stsd_id; yading@11: unsigned duration; yading@11: unsigned size; yading@11: unsigned flags; yading@11: } MOVTrackExt; yading@11: yading@11: typedef struct MOVSbgp { yading@11: unsigned int count; yading@11: unsigned int index; yading@11: } MOVSbgp; yading@11: yading@11: typedef struct MOVStreamContext { yading@11: AVIOContext *pb; yading@11: int pb_is_copied; yading@11: int ffindex; ///< AVStream index yading@11: int next_chunk; yading@11: unsigned int chunk_count; yading@11: int64_t *chunk_offsets; yading@11: unsigned int stts_count; yading@11: MOVStts *stts_data; yading@11: unsigned int ctts_count; yading@11: MOVStts *ctts_data; yading@11: unsigned int stsc_count; yading@11: MOVStsc *stsc_data; yading@11: unsigned int stps_count; yading@11: unsigned *stps_data; ///< partial sync sample for mpeg-2 open gop yading@11: int ctts_index; yading@11: int ctts_sample; yading@11: unsigned int sample_size; ///< may contain value calculated from stsd or value from stsz atom yading@11: unsigned int alt_sample_size; ///< always contains sample size from stsz atom yading@11: unsigned int sample_count; yading@11: int *sample_sizes; yading@11: int keyframe_absent; yading@11: unsigned int keyframe_count; yading@11: int *keyframes; yading@11: int time_scale; yading@11: int64_t empty_duration; ///< empty duration of the first edit list entry yading@11: int64_t start_time; ///< start time of the media yading@11: int64_t time_offset; ///< time offset of the edit list entries yading@11: int current_sample; yading@11: unsigned int bytes_per_frame; yading@11: unsigned int samples_per_frame; yading@11: int dv_audio_container; yading@11: int pseudo_stream_id; ///< -1 means demux all ids yading@11: int16_t audio_cid; ///< stsd audio compression id yading@11: unsigned drefs_count; yading@11: MOVDref *drefs; yading@11: int dref_id; yading@11: int timecode_track; yading@11: int wrong_dts; ///< dts are wrong due to huge ctts offset (iMovie files) yading@11: int width; ///< tkhd width yading@11: int height; ///< tkhd height yading@11: int dts_shift; ///< dts shift when ctts is negative yading@11: uint32_t palette[256]; yading@11: int has_palette; yading@11: int64_t data_size; yading@11: uint32_t tmcd_flags; ///< tmcd track flags yading@11: int64_t track_end; ///< used for dts generation in fragmented movie files yading@11: int start_pad; ///< amount of samples to skip due to enc-dec delay yading@11: unsigned int rap_group_count; yading@11: MOVSbgp *rap_group; yading@11: } MOVStreamContext; yading@11: yading@11: typedef struct MOVContext { yading@11: AVClass *avclass; yading@11: AVFormatContext *fc; yading@11: int time_scale; yading@11: int64_t duration; ///< duration of the longest track yading@11: int found_moov; ///< 'moov' atom has been found yading@11: int found_mdat; ///< 'mdat' atom has been found yading@11: DVDemuxContext *dv_demux; yading@11: AVFormatContext *dv_fctx; yading@11: int isom; ///< 1 if file is ISO Media (mp4/3gp) yading@11: MOVFragment fragment; ///< current fragment in moof atom yading@11: MOVTrackExt *trex_data; yading@11: unsigned trex_count; yading@11: int itunes_metadata; ///< metadata are itunes style yading@11: int chapter_track; yading@11: int use_absolute_path; yading@11: int ignore_editlist; yading@11: int64_t next_root_atom; ///< offset of the next root atom yading@11: } MOVContext; yading@11: yading@11: int ff_mp4_read_descr_len(AVIOContext *pb); yading@11: int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag); yading@11: int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb); yading@11: void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id); yading@11: yading@11: #define MP4ODescrTag 0x01 yading@11: #define MP4IODescrTag 0x02 yading@11: #define MP4ESDescrTag 0x03 yading@11: #define MP4DecConfigDescrTag 0x04 yading@11: #define MP4DecSpecificDescrTag 0x05 yading@11: #define MP4SLDescrTag 0x06 yading@11: yading@11: #define MOV_TFHD_BASE_DATA_OFFSET 0x01 yading@11: #define MOV_TFHD_STSD_ID 0x02 yading@11: #define MOV_TFHD_DEFAULT_DURATION 0x08 yading@11: #define MOV_TFHD_DEFAULT_SIZE 0x10 yading@11: #define MOV_TFHD_DEFAULT_FLAGS 0x20 yading@11: #define MOV_TFHD_DURATION_IS_EMPTY 0x010000 yading@11: yading@11: #define MOV_TRUN_DATA_OFFSET 0x01 yading@11: #define MOV_TRUN_FIRST_SAMPLE_FLAGS 0x04 yading@11: #define MOV_TRUN_SAMPLE_DURATION 0x100 yading@11: #define MOV_TRUN_SAMPLE_SIZE 0x200 yading@11: #define MOV_TRUN_SAMPLE_FLAGS 0x400 yading@11: #define MOV_TRUN_SAMPLE_CTS 0x800 yading@11: yading@11: #define MOV_FRAG_SAMPLE_FLAG_DEGRADATION_PRIORITY_MASK 0x0000ffff yading@11: #define MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC 0x00010000 yading@11: #define MOV_FRAG_SAMPLE_FLAG_PADDING_MASK 0x000e0000 yading@11: #define MOV_FRAG_SAMPLE_FLAG_REDUNDANCY_MASK 0x00300000 yading@11: #define MOV_FRAG_SAMPLE_FLAG_DEPENDED_MASK 0x00c00000 yading@11: #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_MASK 0x03000000 yading@11: yading@11: #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_NO 0x02000000 yading@11: #define MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES 0x01000000 yading@11: yading@11: int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom); yading@11: enum AVCodecID ff_mov_get_lpcm_codec_id(int bps, int flags); yading@11: yading@11: int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries); yading@11: void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout); yading@11: yading@11: #endif /* AVFORMAT_ISOM_H */