annotate mov.c @ 2:06b1347b3c8e libavformat

fixed multidir compile
author bellard
date Fri, 29 Nov 2002 14:56:03 +0000
parents 05318cf2e886
children 215c0f0f916e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * MOV decoder.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 #include "avi.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #ifdef CONFIG_ZLIB
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <zlib.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 * First version by Francois Revol revol@free.fr
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 * Features and limitations:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 * - reads most of the QT files I have (at least the structure),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 * the exceptions are .mov with zlib compressed headers ('cmov' section). It shouldn't be hard to implement.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 * FIXED, Francois Revol, 07/17/2002
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 * - ffmpeg has nearly none of the usual QuickTime codecs,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 * although I succesfully dumped raw and mp3 audio tracks off .mov files.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 * - .mp4 parsing is still hazardous, although the format really is QuickTime with some minor changes
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 * (to make .mov parser crash maybe ?), despite what they say in the MPEG FAQ at
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 * http://mpeg.telecomitalialab.com/faq.htm
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 * - the code is quite ugly... maybe I won't do it recursive next time :-)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 * when coding this :) (it's a writer anyway)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 * Reference documents:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 * Apple:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 * http://developer.apple.com/techpubs/quicktime/qtdevdocs/QTFF/qtff.html
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 * http://developer.apple.com/techpubs/quicktime/qtdevdocs/PDF/QTFileFormat.pdf
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 * QuickTime is a trademark of Apple (AFAIK :))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 /* allows chunk splitting - should work now... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 /* in case you can't read a file, try commenting */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 #define MOV_SPLIT_CHUNKS
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 * XXX: static sux, even more in a multithreaded environment...
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 * Avoid them. This is here just to help debugging.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 static int debug_indent = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 void print_atom(const char *str, UINT32 type, UINT64 offset, UINT64 size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 unsigned int tag, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 tag = (unsigned int) type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 i=debug_indent;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 if(tag == 0) tag = MKTAG('N', 'U', 'L', 'L');
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 while(i--)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 printf("|");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 printf("parse:");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 printf(" %s: tag=%c%c%c%c offset=0x%x size=0x%x\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 str, tag & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 (tag >> 8) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 (tag >> 16) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 (tag >> 24) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 (unsigned int)offset,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 (unsigned int)size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 /* some streams in QT (and in MP4 mostly) aren't either video nor audio */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 /* so we first list them as this, then clean up the list of streams we give back, */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 /* getting rid of these */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 #define CODEC_TYPE_MOV_OTHER 2
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 static const CodecTag mov_video_tags[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 /* { CODEC_ID_, MKTAG('c', 'v', 'i', 'd') }, *//* Cinepak */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 /* { CODEC_ID_JPEG, MKTAG('j', 'p', 'e', 'g') }, *//* JPEG */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 /* { CODEC_ID_H263, MKTAG('r', 'a', 'w', ' ') }, *//* Uncompressed RGB */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 /* { CODEC_ID_H263, MKTAG('Y', 'u', 'v', '2') }, *//* Uncompressed YUV422 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 /* Graphics */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 /* Animation */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 /* Apple video */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 /* Kodak Photo CD */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format B) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 /* { CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') }, *//* embedded gif files as frames (usually one "click to play movie" frame) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 /* Sorenson video */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, /* Sorenson Video v1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', 'i') }, /* Sorenson Video v1 (from QT specs)*/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, /* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 /* { CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 { CODEC_ID_H263, MKTAG('h', '2', '6', '3') }, /* H263 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, /* DV NTSC */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 'p') }, /* DV PAL */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 { 0, 0 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 static const CodecTag mov_audio_tags[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 /* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 { CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') }, /* 8 bits */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 { CODEC_ID_PCM_U8, 0x20776172 }, /* 8 bits unsigned */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 { CODEC_ID_MP2, 0x6D730055 }, /* MPEG layer 3 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 { CODEC_ID_MP2, 0x5500736D }, /* MPEG layer 3 *//* XXX: check endianness */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 /* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 /* MP4 tags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 /* { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, *//* MPEG 4 AAC or audio ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 /* The standard for mpeg4 audio is still not normalised AFAIK anyway */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 { 0, 0 },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 /* the QuickTime file format is quite convoluted...
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 * it has lots of index tables, each indexing something in another one...
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 * Here we just use what is needed to read the chunks
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 typedef struct MOV_sample_to_chunk_tbl {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 long first;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 long count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 long id;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 } MOV_sample_to_chunk_tbl;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 typedef struct MOVStreamContext {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 int ffindex; /* the ffmpeg stream id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 long next_chunk;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 long chunk_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 INT64 *chunk_offsets;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 long sample_to_chunk_sz;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 MOV_sample_to_chunk_tbl *sample_to_chunk;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 long sample_to_chunk_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 long sample_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 long sample_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 long *sample_sizes;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 long time_scale;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 long current_sample;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 long left_in_chunk; /* how many samples before next chunk */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 /* specific MPEG4 header which is added at the beginning of the stream */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 int header_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 uint8_t *header_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 } MOVStreamContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 typedef struct MOVContext {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 int mp4; /* set to 1 as soon as we are sure that the file is an .mp4 file (even some header parsing depends on this) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 AVFormatContext *fc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 long time_scale;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 int found_moov; /* when both 'moov' and 'mdat' sections has been found */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 int found_mdat; /* we suppose we have enough data to read the file */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 INT64 mdat_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 INT64 mdat_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 int total_streams;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 /* some streams listed here aren't presented to the ffmpeg API, since they aren't either video nor audio
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 * but we need the info to be able to skip data from those streams in the 'mdat' section
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 MOVStreamContext *streams[MAX_STREAMS];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 INT64 next_chunk_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 int partial; /* != 0 : there is still to read in the current chunk (=id of the stream + 1) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 } MOVContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 struct MOVParseTableEntry;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 /* those functions parse an atom */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 /* return code:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 1: found what I wanted, exit
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 0: continue to parse next atom
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 -1: error occured, exit
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 typedef int (*mov_parse_function)(const struct MOVParseTableEntry *parse_table,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 ByteIOContext *pb,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 UINT32 atom_type,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 INT64 atom_offset, /* after the size and type field (and eventually the extended size) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 INT64 atom_size, /* total size (excluding the size and type fields) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 void *param);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 /* links atom IDs to parse functions */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 typedef struct MOVParseTableEntry {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 UINT32 type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 mov_parse_function func;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 } MOVParseTableEntry;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 static int parse_leaf(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 print_atom("leaf", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 if(atom_size>1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 url_fskip(pb, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 /* url_seek(pb, atom_offset+atom_size, SEEK_SET); */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 static int parse_default(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 UINT32 type, foo=0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 UINT64 offset, size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 UINT64 total_size = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 int err = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 foo=0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 print_atom("default", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 debug_indent++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 offset = atom_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 if(atom_size < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 atom_size = 0x0FFFFFFFFFFFFFFF;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 while((total_size < atom_size) && !url_feof(pb) && !err) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 size=atom_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 type=0L;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 if(atom_size >= 8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 type = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 total_size += 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 offset+=8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 // printf("type: %08lx sz: %08lx", type, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 if(size == 1) { /* 64 bit extended size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 size = get_be64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 offset+=8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 total_size+=8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 size-=8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 if(size == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 size = atom_size - total_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 size-=8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 for(i=0; parse_table[i].type != 0L && parse_table[i].type != type; i++);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 // printf(" i=%ld\n", i);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 if (parse_table[i].type == 0) { /* skip leaf atoms data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 // url_seek(pb, atom_offset+atom_size, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 print_atom("unknown", type, offset, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 url_fskip(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 } else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 err = (parse_table[i].func)(parse_table, pb, type, offset, size, param);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 offset+=size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 total_size+=size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 debug_indent--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 static int parse_mvhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 print_atom("mvhd", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
291 get_be32(pb); /* creation time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
292 get_be32(pb); /* modification time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
293 c->time_scale = get_be32(pb); /* time scale */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
294 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
295 printf("time scale = %li\n", c->time_scale);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
296 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
297 get_be32(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
298 get_be32(pb); /* preferred scale */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
299
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
300 get_be16(pb); /* preferred volume */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
301
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
302 url_fskip(pb, 10); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
303
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
304 url_fskip(pb, 36); /* display matrix */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
305
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
306 get_be32(pb); /* preview time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
307 get_be32(pb); /* preview duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
308 get_be32(pb); /* poster time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
309 get_be32(pb); /* selection time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
310 get_be32(pb); /* selection duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
311 get_be32(pb); /* current time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
312 get_be32(pb); /* next track ID */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
313
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
314 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
315 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
316
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
317 /* this atom should contain all header atoms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
318 static int parse_moov(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
319 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
320 int err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
321 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
322 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
323 print_atom("moov", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
324 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
325 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
326
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
327 err = parse_default(parse_table, pb, atom_type, atom_offset, atom_size, param);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
328 /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
329 /* so we don't parse the whole file if over a network */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
330 c->found_moov=1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
331 if(c->found_mdat)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
332 return 1; /* found both, just go */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
333 return 0; /* now go for mdat */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
334 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
335
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
336 /* this atom contains actual media data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
337 static int parse_mdat(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
338 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
339 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
340 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
341 print_atom("mdat", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
342 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
343 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
344
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
345 if(atom_size == 0) /* wrong one (MP4) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
346 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
347 c->found_mdat=1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
348 c->mdat_offset = atom_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
349 c->mdat_size = atom_size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
350 if(c->found_moov)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
351 return 1; /* found both, just go */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
352 url_fskip(pb, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
353 return 0; /* now go for moov */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
354 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
355
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
356 /* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
357 /* like the files created with Adobe Premiere 5.0, for samples see */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
358 /* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
359 static int parse_wide(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
360 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
361 int err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
362 UINT32 type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
363 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
364 print_atom("wide", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
365 debug_indent++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
366 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
367 if (atom_size < 8)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
368 return 0; /* continue */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
369 if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
370 url_fskip(pb, atom_size - 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
371 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
372 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
373 type = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
374 if (type != MKTAG('m', 'd', 'a', 't')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
375 url_fskip(pb, atom_size - 8);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
376 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
377 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
378 err = parse_mdat(parse_table, pb, type, atom_offset + 8, atom_size - 8, param);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
379 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
380 debug_indent--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
381 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
382 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
383 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
384
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
385 static int parse_trak(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
386 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
387 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
388 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
389 MOVStreamContext *sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
390 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
391 print_atom("trak", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
392 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
393
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
394 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
395 st = av_new_stream(c->fc, c->fc->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
396 if (!st) return -2;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
397 sc = av_malloc(sizeof(MOVStreamContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
398 sc->sample_to_chunk_index = -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
399 st->priv_data = sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
400 st->codec.codec_type = CODEC_TYPE_MOV_OTHER;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
401 c->streams[c->fc->nb_streams-1] = sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
402 return parse_default(parse_table, pb, atom_type, atom_offset, atom_size, param);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
403 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
404
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
405 static int parse_tkhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
406 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
407 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
408 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
409 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
410 print_atom("tkhd", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
411 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
412
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
413 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
414 st = c->fc->streams[c->fc->nb_streams-1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
415
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
416 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
417
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
418 get_byte(pb); get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
419 get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
420 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
421 MOV_TRACK_ENABLED 0x0001
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
422 MOV_TRACK_IN_MOVIE 0x0002
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
423 MOV_TRACK_IN_PREVIEW 0x0004
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
424 MOV_TRACK_IN_POSTER 0x0008
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
425 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
426
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
427 get_be32(pb); /* creation time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
428 get_be32(pb); /* modification time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
429 st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
430 get_be32(pb); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
431 get_be32(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
432 get_be32(pb); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
433 get_be32(pb); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
434
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
435 get_be16(pb); /* layer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
436 get_be16(pb); /* alternate group */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
437 get_be16(pb); /* volume */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
438 get_be16(pb); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
439
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
440 url_fskip(pb, 36); /* display matrix */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
441
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
442 /* those are fixed-point */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
443 st->codec.width = get_be32(pb) >> 16; /* track width */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
444 st->codec.height = get_be32(pb) >> 16; /* track height */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
445
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
446 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
447 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
448
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
449 static int parse_mdhd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
450 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
451 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
452 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
453 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
454 print_atom("mdhd", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
455 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
456
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
457 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
458 st = c->fc->streams[c->fc->nb_streams-1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
459
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
460 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
461
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
462 get_byte(pb); get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
463 get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
464
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
465 get_be32(pb); /* creation time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
466 get_be32(pb); /* modification time */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
467
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
468 c->streams[c->total_streams]->time_scale = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
469
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
470 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
471 printf("track[%i].time_scale = %li\n", c->fc->nb_streams-1, c->streams[c->total_streams]->time_scale); /* time scale */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
472 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
473 get_be32(pb); /* duration */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
474
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
475 get_be16(pb); /* language */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
476 get_be16(pb); /* quality */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
477
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
478 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
479 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
480
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
481 static int parse_hdlr(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
482 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
483 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
484 int len = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
485 char *buf;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
486 UINT32 type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
487 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
488 UINT32 ctype;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
489 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
490 print_atom("hdlr", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
491 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
492 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
493 st = c->fc->streams[c->fc->nb_streams-1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
494
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
495 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
496 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
497
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
498 /* component type */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
499 ctype = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
500 type = get_le32(pb); /* component subtype */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
501
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
502 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
503 printf("ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
504 printf("stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
505 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
506 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
507 /* XXX: yeah this is ugly... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
508 if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
509 if(type == MKTAG('v', 'i', 'd', 'e'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
510 puts("hdlr: vide");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
511 else if(type == MKTAG('s', 'o', 'u', 'n'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
512 puts("hdlr: soun");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
513 } else if(ctype == 0) { /* MP4 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
514 if(type == MKTAG('v', 'i', 'd', 'e'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
515 puts("hdlr: vide");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
516 else if(type == MKTAG('s', 'o', 'u', 'n'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
517 puts("hdlr: soun");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
518 else if(type == MKTAG('o', 'd', 's', 'm'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
519 puts("hdlr: odsm");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
520 else if(type == MKTAG('s', 'd', 's', 'm'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
521 puts("hdlr: sdsm");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
522 } else puts("hdlr: meta");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
523 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
524
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
525 if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
526 /* helps parsing the string hereafter... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
527 c->mp4 = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
528 if(type == MKTAG('v', 'i', 'd', 'e'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
529 st->codec.codec_type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
530 else if(type == MKTAG('s', 'o', 'u', 'n'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
531 st->codec.codec_type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
532 } else if(ctype == 0) { /* MP4 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
533 /* helps parsing the string hereafter... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
534 c->mp4 = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
535 if(type == MKTAG('v', 'i', 'd', 'e'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
536 st->codec.codec_type = CODEC_TYPE_VIDEO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
537 else if(type == MKTAG('s', 'o', 'u', 'n'))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
538 st->codec.codec_type = CODEC_TYPE_AUDIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
539 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
540 get_be32(pb); /* component manufacture */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
541 get_be32(pb); /* component flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
542 get_be32(pb); /* component flags mask */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
543
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
544 if(atom_size <= 24)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
545 return 0; /* nothing left to read */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
546 /* XXX: MP4 uses a C string, not a pascal one */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
547 /* component name */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
548
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
549 if(c->mp4) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
550 /* .mp4: C string */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
551 while(get_byte(pb) && (++len < (atom_size - 24)));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
552 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
553 /* .mov: PASCAL string */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
554 len = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
555 buf = av_malloc(len+1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
556 get_buffer(pb, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
557 buf[len] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
558 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
559 printf("**buf='%s'\n", buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
560 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
561 av_free(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
562 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
563 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
564 len = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
565 /* XXX: use a better heuristic */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
566 if(len < 32) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
567 /* assume that it is a Pascal like string */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
568 buf = av_malloc(len+1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
569 get_buffer(pb, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
570 buf[len] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
571 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
572 printf("**buf='%s'\n", buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
573 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
574 av_free(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
575 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
576 /* MP4 string */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
577 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
578 if (len == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
579 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
580 len = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
581 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
582 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
583 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
584
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
585 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
586 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
587
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
588 static int mp4_read_descr_len(ByteIOContext *pb)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
589 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
590 int c, len, count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
591
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
592 len = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
593 count = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
594 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
595 c = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
596 len = (len << 7) | (c & 0x7f);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
597 if ((c & 0x80) == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
598 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
599 if (++count == 4)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
600 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
601 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
602 return len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
603 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
604
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
605 static int mp4_read_descr(ByteIOContext *pb, int *tag)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
606 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
607 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
608 *tag = get_byte(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
609 len = mp4_read_descr_len(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
610 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
611 printf("MPEG4 description: tag=0x%02x len=%d\n", *tag, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
612 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
613 return len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
614 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
615
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
616 static int parse_stsd(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
617 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
618 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
619 int entries, size, samp_sz, frames_per_sample, id;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
620 UINT32 format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
621 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
622 MOVStreamContext *sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
623 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
624 print_atom("stsd", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
625 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
626 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
627 st = c->fc->streams[c->fc->nb_streams-1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
628 sc = (MOVStreamContext *)st->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
629
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
630 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
631 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
632
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
633 entries = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
634
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
635 while(entries--) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
636 size = get_be32(pb); /* size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
637 format = get_le32(pb); /* data format */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
638
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
639 get_be32(pb); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
640 get_be16(pb); /* reserved */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
641 get_be16(pb); /* index */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
642
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
643 /* for MPEG4: set codec type by looking for it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
644 id = codec_get_id(mov_video_tags, format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
645 if (id >= 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
646 AVCodec *codec;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
647 codec = avcodec_find_decoder(id);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
648 if (codec)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
649 st->codec.codec_type = codec->type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
650 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
651 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
652 printf("size=%d 4CC= %c%c%c%c codec_type=%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
653 size,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
654 (format >> 0) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
655 (format >> 8) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
656 (format >> 16) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
657 (format >> 24) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
658 st->codec.codec_type);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
659 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
660 if(st->codec.codec_type==CODEC_TYPE_VIDEO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
661 st->codec.codec_tag = format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
662 st->codec.codec_id = codec_get_id(mov_video_tags, format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
663 get_be16(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
664 get_be16(pb); /* revision level */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
665 get_be32(pb); /* vendor */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
666 get_be32(pb); /* temporal quality */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
667 get_be32(pb); /* spacial quality */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
668 st->codec.width = get_be16(pb); /* width */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
669 st->codec.height = get_be16(pb); /* height */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
670 #if 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
671 if (st->codec.codec_id == CODEC_ID_MPEG4) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
672 /* in some MPEG4 the width/height are not correct, so
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
673 we ignore this info */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
674 st->codec.width = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
675 st->codec.height = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
676 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
677 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
678 get_be32(pb); /* horiz resolution */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
679 get_be32(pb); /* vert resolution */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
680 get_be32(pb); /* data size, always 0 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
681 frames_per_sample = get_be16(pb); /* frame per samples */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
682 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
683 printf("frames/samples = %d\n", frames_per_sample);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
684 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
685 url_fskip(pb, 32); /* codec name */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
686
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
687 get_be16(pb); /* depth */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
688 get_be16(pb); /* colortable id */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
689
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
690 st->codec.frame_rate = 25 * FRAME_RATE_BASE;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
691
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
692 size -= (16+8*4+2+32+2*2);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
693 while (size >= 8) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
694 int atom_size, atom_type;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
695 INT64 start_pos;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
696
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
697 atom_size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
698 atom_type = get_le32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
699 size -= 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
700 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
701 printf("VIDEO: atom_type=%c%c%c%c atom_size=%d size_left=%d\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
702 (atom_type >> 0) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
703 (atom_type >> 8) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
704 (atom_type >> 16) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
705 (atom_type >> 24) & 0xff,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
706 atom_size, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
707 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
708 start_pos = url_ftell(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
709
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
710 switch(atom_type) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
711 case MKTAG('e', 's', 'd', 's'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
712 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
713 int tag, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
714 /* Well, broken but suffisant for some MP4 streams */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
715 get_be32(pb); /* version + flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
716 len = mp4_read_descr(pb, &tag);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
717 if (tag == 0x03) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
718 /* MP4ESDescrTag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
719 get_be16(pb); /* ID */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
720 get_byte(pb); /* priority */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
721 len = mp4_read_descr(pb, &tag);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
722 if (tag != 0x04)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
723 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
724 /* MP4DecConfigDescrTag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
725 get_byte(pb); /* objectTypeId */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
726 get_be32(pb); /* streamType + buffer size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
727 get_be32(pb); /* max bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
728 get_be32(pb); /* avg bit rate */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
729 len = mp4_read_descr(pb, &tag);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
730 if (tag != 0x05)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
731 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
732 /* MP4DecSpecificDescrTag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
733 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
734 printf("Specific MPEG4 header len=%d\n", len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
735 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
736 sc->header_data = av_mallocz(len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
737 if (sc->header_data) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
738 get_buffer(pb, sc->header_data, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
739 sc->header_len = len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
740 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
741 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
742 /* in any case, skip garbage */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
743 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
744 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
745 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
746 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
747 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
748 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
749 url_fskip(pb, (atom_size - 8) -
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
750 ((url_ftell(pb) - start_pos)));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
751 size -= atom_size - 8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
752 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
753 if (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
754 /* unknown extension */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
755 url_fskip(pb, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
756 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
757 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
758 st->codec.codec_tag = format;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
759
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
760 get_be16(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
761 get_be16(pb); /* revision level */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
762 get_be32(pb); /* vendor */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
763
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
764 st->codec.channels = get_be16(pb);/* channel count */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
765 samp_sz = get_be16(pb); /* sample size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
766 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
767 if(samp_sz != 16)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
768 puts("!!! stsd: audio sample size is not 16 bit !");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
769 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
770 st->codec.codec_id = codec_get_id(mov_audio_tags, format);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
771 /* handle specific s8 codec */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
772 if (st->codec.codec_id == CODEC_ID_PCM_S16BE && samp_sz == 8)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
773 st->codec.codec_id = CODEC_ID_PCM_S8;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
774
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
775 get_be16(pb); /* compression id = 0*/
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
776 get_be16(pb); /* packet size = 0 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
777
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
778 st->codec.sample_rate = ((get_be32(pb) >> 16));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
779 st->codec.bit_rate = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
780 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
781
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
782 get_be16(pb); get_be16(pb); /* */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
783 get_be16(pb); /* */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
784 get_be16(pb); /* */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
785 get_be16(pb); /* */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
786 get_be16(pb); /* */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
787 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
788 if(size > 16)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
789 url_fskip(pb, size-(16+20));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
790 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
791 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
792 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
793 if(len) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
794 buf = av_malloc(len+1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
795 get_buffer(pb, buf, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
796 buf[len] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
797 puts(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
798 av_free(buf);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
799 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
800 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
801 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
802 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
803
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
804 static int parse_stco(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
805 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
806 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
807 int entries, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
808 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
809 MOVStreamContext *sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
810 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
811 print_atom("stco", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
812 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
813 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
814 st = c->fc->streams[c->fc->nb_streams-1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
815 sc = (MOVStreamContext *)st->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
816
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
817 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
818 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
819
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
820 entries = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
821 sc->chunk_count = entries;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
822 sc->chunk_offsets = av_malloc(entries * sizeof(INT64));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
823 if(atom_type == MKTAG('s', 't', 'c', 'o')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
824 for(i=0; i<entries; i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
825 sc->chunk_offsets[i] = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
826 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
827 } else if(atom_type == MKTAG('c', 'o', '6', '4')) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
828 for(i=0; i<entries; i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
829 sc->chunk_offsets[i] = get_be64(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
830 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
831 } else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
832 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
833 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
834 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
835 for(i=0; i<entries; i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
836 printf("chunk offset=0x%Lx\n", sc->chunk_offsets[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
837 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
838 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
839 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
840 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
841 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
842
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
843 static int parse_stsc(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
844 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
845 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
846 int entries, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
847 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
848 MOVStreamContext *sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
849 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
850 print_atom("stsc", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
851 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
852 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
853 st = c->fc->streams[c->fc->nb_streams-1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
854 sc = (MOVStreamContext *)st->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
855
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
856 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
857 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
858
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
859 entries = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
860 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
861 printf("track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
862 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
863 sc->sample_to_chunk_sz = entries;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
864 sc->sample_to_chunk = av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
865 for(i=0; i<entries; i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
866 sc->sample_to_chunk[i].first = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
867 sc->sample_to_chunk[i].count = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
868 sc->sample_to_chunk[i].id = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
869 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
870 /* printf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id); */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
871 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
872 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
873 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
874 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
875
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
876 static int parse_stsz(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
877 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
878 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
879 int entries, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
880 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
881 MOVStreamContext *sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
882 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
883 print_atom("stsz", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
884 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
885 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
886 st = c->fc->streams[c->fc->nb_streams-1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
887 sc = (MOVStreamContext *)st->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
888
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
889 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
890 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
891
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
892 sc->sample_size = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
893 entries = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
894 sc->sample_count = entries;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
895 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
896 printf("sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
897 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
898 if(sc->sample_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
899 return 0; /* there isn't any table following */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
900 sc->sample_sizes = av_malloc(entries * sizeof(long));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
901 for(i=0; i<entries; i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
902 sc->sample_sizes[i] = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
903 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
904 /* printf("sample_sizes[]=%ld\n", sc->sample_sizes[i]); */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
905 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
906 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
907 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
908 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
909
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
910 static int parse_stts(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
911 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
912 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
913 int entries, i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
914 AVStream *st;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
915 MOVStreamContext *sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
916 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
917 print_atom("stts", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
918 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
919 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
920 st = c->fc->streams[c->fc->nb_streams-1];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
921 sc = (MOVStreamContext *)st->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
922
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
923 get_byte(pb); /* version */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
924 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
925 entries = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
926 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
927 printf("track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
928 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
929 for(i=0; i<entries; i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
930 int sample_duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
931
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
932 get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
933 sample_duration = get_be32(pb);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
934
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
935 if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
936 st->codec.frame_rate = FRAME_RATE_BASE * c->streams[c->total_streams]->time_scale;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
937 if (sample_duration)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
938 st->codec.frame_rate /= sample_duration;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
939 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
940 printf("VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
941 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
942 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
943 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
944 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
945 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
946
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
947 #ifdef CONFIG_ZLIB
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
948 static int null_read_packet(void *opaque, UINT8 *buf, int buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
949 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
950 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
951 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
952
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
953 static int parse_cmov(const MOVParseTableEntry *parse_table, ByteIOContext *pb, UINT32 atom_type, INT64 atom_offset, INT64 atom_size, void *param)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
954 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
955 MOVContext *c;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
956 ByteIOContext ctx;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
957 char *cmov_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
958 unsigned char *moov_data; /* uncompressed data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
959 long cmov_len, moov_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
960 int ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
961 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
962 print_atom("cmov", atom_type, atom_offset, atom_size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
963 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
964 c = (MOVContext *)param;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
965
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
966 get_be32(pb); /* dcom atom */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
967 if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' ))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
968 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
969 if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
970 puts("unknown compression for cmov atom !");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
971 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
972 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
973 get_be32(pb); /* cmvd atom */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
974 if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' ))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
975 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
976 moov_len = get_be32(pb); /* uncompressed size */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
977 cmov_len = atom_size - 6 * 4;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
978
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
979 cmov_data = av_malloc(cmov_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
980 if (!cmov_data)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
981 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
982 moov_data = av_malloc(moov_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
983 if (!moov_data) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
984 av_free(cmov_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
985 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
986 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
987 get_buffer(pb, cmov_data, cmov_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
988 if(uncompress (moov_data, &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
989 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
990 if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, null_read_packet, NULL, NULL) != 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
991 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
992 ctx.buf_end = ctx.buffer + moov_len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
993 ret = parse_default(parse_table, &ctx, MKTAG( 'm', 'o', 'o', 'v' ), 0, moov_len, param);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
994 av_free(moov_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
995 av_free(cmov_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
996 return ret;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
997 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
998 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
999
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1000 static const MOVParseTableEntry mov_default_parse_table[] = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1001 /* mp4 atoms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1002 { MKTAG( 'm', 'p', '4', 'a' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1003 { MKTAG( 'c', 'o', '6', '4' ), parse_stco },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1004 { MKTAG( 's', 't', 'c', 'o' ), parse_stco },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1005 { MKTAG( 'c', 'r', 'h', 'd' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1006 { MKTAG( 'c', 't', 't', 's' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1007 { MKTAG( 'c', 'p', 'r', 't' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1008 { MKTAG( 'u', 'r', 'l', ' ' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1009 { MKTAG( 'u', 'r', 'n', ' ' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1010 { MKTAG( 'd', 'i', 'n', 'f' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1011 { MKTAG( 'd', 'r', 'e', 'f' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1012 { MKTAG( 's', 't', 'd', 'p' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1013 { MKTAG( 'e', 's', 'd', 's' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1014 { MKTAG( 'e', 'd', 't', 's' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1015 { MKTAG( 'e', 'l', 's', 't' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1016 { MKTAG( 'u', 'u', 'i', 'd' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1017 { MKTAG( 'f', 'r', 'e', 'e' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1018 { MKTAG( 'h', 'd', 'l', 'r' ), parse_hdlr },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1019 { MKTAG( 'h', 'm', 'h', 'd' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1020 { MKTAG( 'h', 'i', 'n', 't' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1021 { MKTAG( 'n', 'm', 'h', 'd' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1022 { MKTAG( 'm', 'p', '4', 's' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1023 { MKTAG( 'm', 'd', 'i', 'a' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1024 { MKTAG( 'm', 'd', 'a', 't' ), parse_mdat },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1025 { MKTAG( 'm', 'd', 'h', 'd' ), parse_mdhd },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1026 { MKTAG( 'm', 'i', 'n', 'f' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1027 { MKTAG( 'm', 'o', 'o', 'v' ), parse_moov },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1028 { MKTAG( 'm', 'v', 'h', 'd' ), parse_mvhd },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1029 { MKTAG( 'i', 'o', 'd', 's' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1030 { MKTAG( 'o', 'd', 'h', 'd' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1031 { MKTAG( 'm', 'p', 'o', 'd' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1032 { MKTAG( 's', 't', 's', 'd' ), parse_stsd },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1033 { MKTAG( 's', 't', 's', 'z' ), parse_stsz },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1034 { MKTAG( 's', 't', 'b', 'l' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1035 { MKTAG( 's', 't', 's', 'c' ), parse_stsc },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1036 { MKTAG( 's', 'd', 'h', 'd' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1037 { MKTAG( 's', 't', 's', 'h' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1038 { MKTAG( 's', 'k', 'i', 'p' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1039 { MKTAG( 's', 'm', 'h', 'd' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1040 { MKTAG( 'd', 'p', 'n', 'd' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1041 { MKTAG( 's', 't', 's', 's' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1042 { MKTAG( 's', 't', 't', 's' ), parse_stts },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1043 { MKTAG( 't', 'r', 'a', 'k' ), parse_trak },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1044 { MKTAG( 't', 'k', 'h', 'd' ), parse_tkhd },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1045 { MKTAG( 't', 'r', 'e', 'f' ), parse_default }, /* not really */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1046 { MKTAG( 'u', 'd', 't', 'a' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1047 { MKTAG( 'v', 'm', 'h', 'd' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1048 { MKTAG( 'm', 'p', '4', 'v' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1049 /* extra mp4 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1050 { MKTAG( 'M', 'D', 'E', 'S' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1051 /* QT atoms */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1052 { MKTAG( 'c', 'h', 'a', 'p' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1053 { MKTAG( 'c', 'l', 'i', 'p' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1054 { MKTAG( 'c', 'r', 'g', 'n' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1055 { MKTAG( 'k', 'm', 'a', 't' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1056 { MKTAG( 'm', 'a', 't', 't' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1057 { MKTAG( 'r', 'd', 'r', 'f' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1058 { MKTAG( 'r', 'm', 'd', 'a' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1059 { MKTAG( 'r', 'm', 'd', 'r' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1060 //{ MKTAG( 'r', 'm', 'q', 'u' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1061 { MKTAG( 'r', 'm', 'r', 'a' ), parse_default },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1062 { MKTAG( 's', 'c', 'p', 't' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1063 { MKTAG( 's', 'y', 'n', 'c' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1064 { MKTAG( 's', 's', 'r', 'c' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1065 { MKTAG( 't', 'c', 'm', 'd' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1066 { MKTAG( 'w', 'i', 'd', 'e' ), parse_wide }, /* place holder */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1067 #ifdef CONFIG_ZLIB
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1068 { MKTAG( 'c', 'm', 'o', 'v' ), parse_cmov },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1069 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1070 { MKTAG( 'c', 'm', 'o', 'v' ), parse_leaf },
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1071 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1072 { 0L, parse_leaf }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1073 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1074
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1075 static void mov_free_stream_context(MOVStreamContext *sc)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1076 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1077 if(sc) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1078 av_free(sc->chunk_offsets);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1079 av_free(sc->sample_to_chunk);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1080 av_free(sc->header_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1081 av_free(sc);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1082 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1083 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1084
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1085 static uint32_t to_tag(uint8_t *buf)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1086 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1087 return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1088 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1089
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1090 static uint32_t to_be32(uint8_t *buf)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1091 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1092 return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1093 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1094
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1095 /* XXX: is it suffisant ? */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1096 static int mov_probe(AVProbeData *p)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1097 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1098 unsigned int offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1099 uint32_t tag;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1100
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1101 /* check file header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1102 if (p->buf_size <= 12)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1103 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1104 offset = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1105 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1106 /* ignore invalid offset */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1107 if ((offset + 8) > (unsigned int)p->buf_size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1108 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1109 tag = to_tag(p->buf + offset + 4);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1110 switch(tag) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1111 case MKTAG( 'm', 'o', 'o', 'v' ):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1112 case MKTAG( 'w', 'i', 'd', 'e' ):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1113 case MKTAG( 'f', 'r', 'e', 'e' ):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1114 case MKTAG( 'm', 'd', 'a', 't'):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1115 return AVPROBE_SCORE_MAX;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1116 case MKTAG( 'f', 't', 'y', 'p' ):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1117 case MKTAG( 's', 'k', 'i', 'p' ):
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1118 offset = to_be32(p->buf) + offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1119 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1120 default:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1121 /* unrecognized tag */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1122 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1123 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1124 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1125 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1126 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1127
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1128 static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1129 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1130 MOVContext *mov = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1131 ByteIOContext *pb = &s->pb;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1132 int i, j, nb, err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1133 INT64 size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1134
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1135 mov->fc = s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1136 #if 0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1137 /* XXX: I think we should auto detect */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1138 if(s->iformat->name[1] == 'p')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1139 mov->mp4 = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1140 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1141 if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1142 size = url_filesize(url_fileno(pb));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1143 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1144 size = 0x7FFFFFFFFFFFFFFF;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1145
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1146 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1147 printf("filesz=%Ld\n", size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1148 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1149
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1150 /* check MOV header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1151 err = parse_default(mov_default_parse_table, pb, 0L, 0LL, size, mov);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1152 if(err<0 || (!mov->found_moov || !mov->found_mdat)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1153 puts("header not found !!!");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1154 exit(1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1155 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1156 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1157 printf("on_parse_exit_offset=%d\n", (int) url_ftell(pb));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1158 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1159 /* some cleanup : make sure we are on the mdat atom */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1160 if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1161 url_fseek(pb, mov->mdat_offset, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1162
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1163 mov->next_chunk_offset = mov->mdat_offset; /* initialise reading */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1164
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1165 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1166 printf("mdat_reset_offset=%d\n", (int) url_ftell(pb));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1167 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1168
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1169 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1170 printf("streams= %d\n", s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1171 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1172 mov->total_streams = nb = s->nb_streams;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1173
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1174 #if 1
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1175 for(i=0; i<s->nb_streams;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1176 if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1177 av_free(s->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1178 for(j=i+1; j<s->nb_streams; j++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1179 s->streams[j-1] = s->streams[j];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1180 s->nb_streams--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1181 } else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1182 i++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1183 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1184 for(i=0; i<s->nb_streams;i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1185 MOVStreamContext *sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1186 sc = (MOVStreamContext *)s->streams[i]->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1187 sc->ffindex = i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1188 sc->is_ff_stream = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1189 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1190 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1191 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1192 printf("real streams= %d\n", s->nb_streams);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1193 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1194 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1195 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1196
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1197 /* Yes, this is ugly... I didn't write the specs of QT :p */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1198 /* XXX:remove useless commented code sometime */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1199 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1200 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1201 MOVContext *mov = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1202 MOVStreamContext *sc;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1203 INT64 offset = 0x0FFFFFFFFFFFFFFF;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1204 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1205 int st_id = 0, size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1206 size = 0x0FFFFFFF;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1207
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1208 #ifdef MOV_SPLIT_CHUNKS
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1209 if (mov->partial) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1210
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1211 int idx;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1212
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1213 st_id = mov->partial - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1214 idx = mov->streams[st_id]->sample_to_chunk_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1215 if (idx < 0) return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1216 size = mov->streams[st_id]->sample_sizes[mov->streams[st_id]->current_sample];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1217
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1218 mov->streams[st_id]->current_sample++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1219 mov->streams[st_id]->left_in_chunk--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1220
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1221 if(mov->streams[st_id]->left_in_chunk <= 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1222 mov->partial = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1223 offset = mov->next_chunk_offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1224 /* extract the sample */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1225
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1226 goto readchunk;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1227 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1228 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1229
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1230 again:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1231 for(i=0; i<mov->total_streams; i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1232 if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1233 && (mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] < offset)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1234 st_id = i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1235 offset = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1236 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1237 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1238 mov->streams[st_id]->next_chunk++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1239 if(offset==0x0FFFFFFFFFFFFFFF)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1240 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1241
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1242 if(mov->next_chunk_offset < offset) { /* some meta data */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1243 url_fskip(&s->pb, (offset - mov->next_chunk_offset));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1244 mov->next_chunk_offset = offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1245 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1246
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1247 //printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1248 if(!mov->streams[st_id]->is_ff_stream) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1249 url_fskip(&s->pb, (offset - mov->next_chunk_offset));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1250 mov->next_chunk_offset = offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1251 offset = 0x0FFFFFFFFFFFFFFF;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1252 goto again;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1253 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1254
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1255 /* now get the chunk size... */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1256
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1257 for(i=0; i<mov->total_streams; i++) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1258 if((mov->streams[i]->next_chunk < mov->streams[i]->chunk_count)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1259 && ((mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset) < size)) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1260 size = mov->streams[i]->chunk_offsets[mov->streams[i]->next_chunk] - offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1261 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1262 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1263 #ifdef MOV_SPLIT_CHUNKS
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1264 /* split chunks into samples */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1265 if(mov->streams[st_id]->sample_size == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1266 int idx;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1267 idx = mov->streams[st_id]->sample_to_chunk_index;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1268 if ((idx + 1 < mov->streams[st_id]->sample_to_chunk_sz)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1269 && (mov->streams[st_id]->next_chunk >= mov->streams[st_id]->sample_to_chunk[idx + 1].first))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1270 idx++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1271 mov->streams[st_id]->sample_to_chunk_index = idx;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1272 if(idx >= 0 && mov->streams[st_id]->sample_to_chunk[idx].count != 1) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1273 mov->partial = st_id+1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1274 /* we'll have to get those samples before next chunk */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1275 mov->streams[st_id]->left_in_chunk = (mov->streams[st_id]->sample_to_chunk[idx].count) - 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1276 size = mov->streams[st_id]->sample_sizes[mov->streams[st_id]->current_sample];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1277 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1278
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1279 mov->streams[st_id]->current_sample++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1280 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1281 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1282
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1283 readchunk:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1284 //printf("chunk: [%i] %lli -> %lli (%i)\n", st_id, offset, offset + size, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1285 if(size == 0x0FFFFFFF)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1286 size = mov->mdat_size + mov->mdat_offset - offset;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1287 if(size < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1288 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1289 if(size == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1290 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1291 url_fseek(&s->pb, offset, SEEK_SET);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1292 sc = mov->streams[st_id];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1293 if (sc->header_len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1294 av_new_packet(pkt, size + sc->header_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1295 memcpy(pkt->data, sc->header_data, sc->header_len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1296 get_buffer(&s->pb, pkt->data + sc->header_len, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1297 /* free header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1298 av_freep(&sc->header_data);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1299 sc->header_len = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1300 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1301 av_new_packet(pkt, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1302 get_buffer(&s->pb, pkt->data, pkt->size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1303 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1304 pkt->stream_index = sc->ffindex;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1305
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1306 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1307 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1308 printf("Packet (%d, %d, %ld) ", pkt->stream_index, st_id, pkt->size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1309 for(i=0; i<8; i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1310 printf("%02x ", pkt->data[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1311 for(i=0; i<8; i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1312 printf("%c ", (pkt->data[i]) & 0x7F);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1313 puts("");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1314 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1315 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1316
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1317 mov->next_chunk_offset = offset + size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1318
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1319 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1320 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1321
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1322 static int mov_read_close(AVFormatContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1323 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1324 int i;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1325 MOVContext *mov = s->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1326 for(i=0; i<mov->total_streams; i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1327 mov_free_stream_context(mov->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1328 for(i=0; i<s->nb_streams; i++)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1329 av_freep(&s->streams[i]);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1330 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1331 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1332
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1333 static AVInputFormat mov_iformat = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1334 "mov",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1335 "QuickTime/MPEG4 format",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1336 sizeof(MOVContext),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1337 mov_probe,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1338 mov_read_header,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1339 mov_read_packet,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1340 mov_read_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1341 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1342
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1343 int mov_init(void)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1344 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1345 av_register_input_format(&mov_iformat);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1346 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1347 }