annotate libmpdemux/demux_mov.c @ 2481:0e9a5504a246

libdl checking added
author alex
date Fri, 26 Oct 2001 13:39:15 +0000
parents 8d00b25169af
children 22bfa362af42
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
1 // QuickTime MOV file parser by A'rpi
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
2 // based on TOOLS/movinfo.c by me & Al3x
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
3 // compressed header support from moov.c of the openquicktime lib.
2386
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
4 // References: http://openquicktime.sf.net/, http://www.heroinewarrior.com/
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
5
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
6 #include <stdio.h>
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
7 #include <stdlib.h>
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
8 #include <unistd.h>
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
9
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
10 #include "config.h"
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
11
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
12 #ifdef HAVE_PNG
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
13 // should be detected by ./configure...
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
14 #define HAVE_ZLIB
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
15 #endif
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
16
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
17 #include "mp_msg.h"
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1567
diff changeset
18 #include "help_mp.h"
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
19
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
20 #include "stream.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
21 #include "demuxer.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
22 #include "stheader.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
23
2386
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
24 #include "bswap.h"
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
25
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
26 #ifdef HAVE_ZLIB
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
27 #include <zlib.h>
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
28 #endif
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
29
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
30 typedef struct {
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
31 unsigned int pts; // duration
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
32 unsigned int size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
33 off_t pos;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
34 } mov_sample_t;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
35
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
36 typedef struct {
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
37 unsigned int sample; // number of the first sample in teh chunk
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
38 unsigned int size; // number of samples in the chunk
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
39 int desc; // for multiple codecs mode - not used
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
40 off_t pos;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
41 } mov_chunk_t;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
42
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
43 typedef struct {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
44 unsigned int first;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
45 unsigned int spc;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
46 unsigned int sdid;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
47 } mov_chunkmap_t;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
48
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
49 typedef struct {
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
50 unsigned int num;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
51 unsigned int dur;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
52 } mov_durmap_t;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
53
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
54 typedef struct {
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
55 int id;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
56 int type;
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
57 int pos;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
58 //
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
59 int timescale;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
60 unsigned int length;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
61 int samplesize; // 0 = variable
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
62 int duration; // 0 = variable
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
63 int width,height; // for video
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
64 unsigned int fourcc;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
65 //
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
66 int tkdata_len; // track data
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
67 unsigned char* tkdata;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
68 int stdata_len; // stream data
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
69 unsigned char* stdata;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
70 int samples_size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
71 mov_sample_t* samples;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
72 int chunks_size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
73 mov_chunk_t* chunks;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
74 int chunkmap_size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
75 mov_chunkmap_t* chunkmap;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
76 int durmap_size;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
77 mov_durmap_t* durmap;
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
78 } mov_track_t;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
79
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
80 void mov_build_index(mov_track_t* trak){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
81 int i,j,s;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
82 int last=trak->chunks_size;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
83 unsigned int pts=0;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
84 printf("MOV track: %d chunks, %d samples\n",trak->chunks_size,trak->samples_size);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
85 printf("pts=%d scale=%d time=%5.3f\n",trak->length,trak->timescale,(float)trak->length/(float)trak->timescale);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
86 // process chunkmap:
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
87 i=trak->chunkmap_size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
88 while(i>0){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
89 --i;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
90 for(j=trak->chunkmap[i].first;j<last;j++){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
91 trak->chunks[j].desc=trak->chunkmap[i].sdid;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
92 trak->chunks[j].size=trak->chunkmap[i].spc;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
93 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
94 last=trak->chunkmap[i].first;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
95 }
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
96
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
97 // calc pts of chunks:
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
98 s=0;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
99 for(j=0;j<trak->chunks_size;j++){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
100 trak->chunks[j].sample=s;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
101 s+=trak->chunks[j].size;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
102 }
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
103
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
104 if(!trak->samples_size){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
105 // constant sampesize
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
106 if(trak->durmap_size==1 || (trak->durmap_size==2 && trak->durmap[1].num==1)){
2227
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
107 trak->duration=trak->durmap[0].dur;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
108 } else printf("*** constant samplesize & variable duration not yet supported! ***\nContact the author if you have such sample file!\n");
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
109 return;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
110 }
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
111
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
112 // calc pts:
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
113 s=0;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
114 for(j=0;j<trak->durmap_size;j++){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
115 for(i=0;i<trak->durmap[j].num;i++){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
116 trak->samples[s].pts=pts;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
117 ++s;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
118 pts+=trak->durmap[j].dur;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
119 }
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
120 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
121
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
122 // calc sample offsets
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
123 s=0;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
124 for(j=0;j<trak->chunks_size;j++){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
125 off_t pos=trak->chunks[j].pos;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
126 for(i=0;i<trak->chunks[j].size;i++){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
127 trak->samples[s].pos=pos;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
128 #if 0
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
129 printf("Sample %5d: pts=%8d off=0x%08X size=%d\n",s,
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
130 trak->samples[s].pts,
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
131 (int)trak->samples[s].pos,
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
132 trak->samples[s].size);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
133 #endif
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
134 pos+=trak->samples[s].size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
135 ++s;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
136 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
137 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
138
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
139 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
140
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
141 #define MOV_MAX_TRACKS 256
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
142
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
143 #define MOV_TRAK_UNKNOWN 0
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
144 #define MOV_TRAK_VIDEO 1
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
145 #define MOV_TRAK_AUDIO 2
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
146
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
147 typedef struct {
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
148 off_t moov_start;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
149 off_t moov_end;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
150 off_t mdat_start;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
151 off_t mdat_end;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
152 int track_db;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
153 mov_track_t* tracks[MOV_MAX_TRACKS];
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
154 } mov_priv_t;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
155
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
156 #define MOV_FOURCC(a,b,c,d) ((a<<24)|(b<<16)|(c<<8)|(d))
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
157
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
158 int mov_check_file(demuxer_t* demuxer){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
159 int flags=0;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
160 mov_priv_t* priv=malloc(sizeof(mov_priv_t));
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
161
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
162 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for MOV\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
163
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
164 memset(priv,0,sizeof(mov_priv_t));
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
165 demuxer->priv=priv;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
166
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
167 while(1){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
168 off_t len=stream_read_dword(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
169 unsigned int id=stream_read_dword(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
170 if(stream_eof(demuxer->stream)) break; // EOF
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
171 if(len<8) break; // invalid chunk
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
172 switch(id){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
173 case MOV_FOURCC('m','o','o','v'):
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
174 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
175 priv->moov_start=stream_tell(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
176 priv->moov_end=priv->moov_start+len-8;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
177 flags|=1;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
178 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
179 case MOV_FOURCC('m','d','a','t'):
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
180 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie DATA found!\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
181 priv->mdat_start=stream_tell(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
182 priv->mdat_end=priv->mdat_start+len-8;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
183 flags|=2;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
184 break;
2429
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
185 case MOV_FOURCC('f','r','e','e'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
186 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
187 case MOV_FOURCC('w','i','d','e'):
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
188 default:
2429
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
189 id = bswap_32(id);
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
190 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: unknown chunk: %.4s %d\n",&id,(int)len);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
191 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
192 if(!stream_skip(demuxer->stream,len-8)) break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
193 }
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
194
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
195 if(flags==1)
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
196 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing data (mdat) chunk! Maybe broken file...\n");
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
197 else if(flags==2)
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
198 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing header (moov/cmov) chunk! Maybe broken file...\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
199
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
200 return (flags==3);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
201 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
202
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
203 static void lschunks(demuxer_t* demuxer,int level,off_t endpos,mov_track_t* trak){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
204 mov_priv_t* priv=demuxer->priv;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
205 while(1){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
206 off_t pos;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
207 off_t len;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
208 unsigned int id;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
209 //
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
210 pos=stream_tell(demuxer->stream);
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
211 // printf("stream_tell==%d\n",pos);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
212 if(pos>=endpos) return; // END
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
213 len=stream_read_dword(demuxer->stream);
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
214 // printf("len==%d\n",len);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
215 if(len<8) return; // error
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
216 len-=8;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
217 id=stream_read_dword(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
218 //
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
219 mp_msg(MSGT_DEMUX,MSGL_DBG2,"lschunks %.4s %d\n",&id,(int)len);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
220 //
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
221 if(trak){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
222 switch(id){
2429
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
223 case MOV_FOURCC('u','d','t','a'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
224 /* here not supported :p */
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
225 break;
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
226 case MOV_FOURCC('t','k','h','d'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
227 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sTrack header!\n",level,"");
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
228 // read codec data
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
229 trak->tkdata_len=len;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
230 trak->tkdata=malloc(trak->tkdata_len);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
231 stream_read(demuxer->stream,trak->tkdata,trak->tkdata_len);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
232 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
233 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
234 case MOV_FOURCC('m','d','h','d'): {
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
235 unsigned int tmp;
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
236 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia header!\n",level,"");
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
237 #if 0
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
238 tmp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
239 printf("dword1: 0x%08X (%d)\n",tmp,tmp);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
240 tmp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
241 printf("dword2: 0x%08X (%d)\n",tmp,tmp);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
242 tmp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
243 printf("dword3: 0x%08X (%d)\n",tmp,tmp);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
244 tmp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
245 printf("dword4: 0x%08X (%d)\n",tmp,tmp);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
246 tmp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
247 printf("dword5: 0x%08X (%d)\n",tmp,tmp);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
248 tmp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
249 printf("dword6: 0x%08X (%d)\n",tmp,tmp);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
250 #endif
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
251 stream_skip(demuxer->stream,12);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
252 // read timescale
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
253 trak->timescale=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
254 // read length
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
255 trak->length=stream_read_dword(demuxer->stream);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
256 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
257 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
258 case MOV_FOURCC('v','m','h','d'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
259 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sVideo header!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
260 trak->type=MOV_TRAK_VIDEO;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
261 // read video data
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
262 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
263 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
264 case MOV_FOURCC('s','m','h','d'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
265 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSound header!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
266 trak->type=MOV_TRAK_AUDIO;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
267 // read audio data
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
268 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
269 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
270 case MOV_FOURCC('s','t','s','d'): {
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
271 int i=stream_read_dword(demuxer->stream); // temp!
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
272 int count=stream_read_dword(demuxer->stream);
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
273 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sDescription list! (cnt:%d)\n",level,"",count);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
274 for(i=0;i<count;i++){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
275 off_t pos=stream_tell(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
276 off_t len=stream_read_dword(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
277 unsigned int fourcc=stream_read_dword_le(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
278 if(len<8) break; // error
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
279 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*s desc #%d: %.4s",level,"",i,&fourcc);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
280 if(!i){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
281 trak->fourcc=fourcc;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
282 // read codec data
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
283 trak->stdata_len=len-8;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
284 trak->stdata=malloc(trak->stdata_len);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
285 stream_read(demuxer->stream,trak->stdata,trak->stdata_len);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
286 if(trak->type==MOV_TRAK_VIDEO && trak->stdata_len>43){
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
287 mp_msg(MSGT_DEMUX,MSGL_V," '%.*s'",trak->stdata_len-43,trak->stdata+43);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
288 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
289 }
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
290 mp_msg(MSGT_DEMUX,MSGL_V,"\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
291 if(fourcc!=trak->fourcc && i)
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1567
diff changeset
292 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
293 if(!stream_seek(demuxer->stream,pos+len)) break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
294 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
295 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
296 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
297 case MOV_FOURCC('s','t','t','s'): {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
298 int temp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
299 int len=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
300 int i;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
301 int x=0;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
302 unsigned int pts=0;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
303 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample duration table! (%d blocks)\n",level,"",len);
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
304 trak->durmap=malloc(sizeof(mov_durmap_t)*len);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
305 memset(trak->durmap,0,sizeof(mov_durmap_t)*len);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
306 trak->durmap_size=len;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
307 for(i=0;i<len;i++){
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
308 trak->durmap[i].num=stream_read_dword(demuxer->stream);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
309 trak->durmap[i].dur=stream_read_dword(demuxer->stream);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
310 pts+=trak->durmap[i].num*trak->durmap[i].dur;
2386
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
311
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
312 if(i==0)
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
313 {
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
314 sh_video_t* sh=new_sh_video(demuxer,priv->track_db);
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
315 if (!sh->fps)
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
316 sh->fps = trak->timescale/trak->durmap[i].dur;
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
317 /* initial fps */
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
318 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
319 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
320 if(trak->length!=pts) printf("Warning! pts=%d length=%d\n",pts,trak->length);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
321 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
322 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
323 case MOV_FOURCC('s','t','s','c'): {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
324 int temp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
325 int len=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
326 int i;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
327 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample->Chunk mapping table! (%d blocks)\n",level,"",len);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
328 // read data:
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
329 trak->chunkmap_size=len;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
330 trak->chunkmap=malloc(sizeof(mov_chunkmap_t)*len);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
331 for(i=0;i<len;i++){
2103
3e55202cfdab ehh. first chunk is counted from 1. fixed...
arpi
parents: 2101
diff changeset
332 trak->chunkmap[i].first=stream_read_dword(demuxer->stream)-1;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
333 trak->chunkmap[i].spc=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
334 trak->chunkmap[i].sdid=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
335 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
336 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
337 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
338 case MOV_FOURCC('s','t','s','z'): {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
339 int temp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
340 int ss=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
341 int len=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
342 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample size table! len=%d ss=%d\n",level,"",len,ss);
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
343 trak->samplesize=ss;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
344 if(!ss){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
345 // variable samplesize
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
346 int i;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
347 trak->samples=realloc(trak->samples,sizeof(mov_sample_t)*len);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
348 trak->samples_size=len;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
349 for(i=0;i<len;i++)
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
350 trak->samples[i].size=stream_read_dword(demuxer->stream);
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
351 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
352 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
353 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
354 case MOV_FOURCC('s','t','c','o'): {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
355 int temp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
356 int len=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
357 int i;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
358 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sChunk offset table! (%d chunks)\n",level,"",len);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
359 // extend array if needed:
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
360 if(len>trak->chunks_size){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
361 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
362 trak->chunks_size=len;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
363 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
364 // read elements:
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
365 for(i=0;i<len;i++) trak->chunks[i].pos=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
366 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
367 }
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
368 case MOV_FOURCC('m','d','i','a'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
369 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia stream!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
370 lschunks(demuxer,level+1,pos+len,trak);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
371 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
372 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
373 case MOV_FOURCC('m','i','n','f'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
374 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia info!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
375 lschunks(demuxer,level+1,pos+len,trak);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
376 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
377 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
378 case MOV_FOURCC('s','t','b','l'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
379 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample info!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
380 lschunks(demuxer,level+1,pos+len,trak);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
381 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
382 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
383 }//switch(id)
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
384 } else
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
385 if(id==MOV_FOURCC('t','r','a','k')){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
386 // if(trak) printf("MOV: Warning! trak in trak?\n");
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
387 if(priv->track_db>=MOV_MAX_TRACKS){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1567
diff changeset
388 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVtooManyTrk);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
389 return;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
390 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
391 trak=malloc(sizeof(mov_track_t));
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
392 memset(trak,0,sizeof(mov_track_t));
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
393 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Track #%d:\n",priv->track_db);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
394 trak->id=priv->track_db;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
395 priv->tracks[priv->track_db]=trak;
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
396 lschunks(demuxer,level+1,pos+len,trak);
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
397 mov_build_index(trak);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
398 switch(trak->type){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
399 case MOV_TRAK_AUDIO: {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
400 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
401 sh->format=trak->fourcc;
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
402 printf("!!! audio bits: %d chans: %d\n",trak->stdata[19],trak->stdata[17]);
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
403 printf("Fourcc: %.4s\n",&trak->fourcc);
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
404 // Emulate WAVEFORMATEX struct:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
405 sh->wf=malloc(sizeof(WAVEFORMATEX));
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
406 memset(sh->wf,0,sizeof(WAVEFORMATEX));
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
407 sh->wf->nChannels=trak->stdata[17];
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
408 sh->wf->wBitsPerSample=trak->stdata[19];
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
409 sh->wf->nSamplesPerSec=trak->timescale;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
410 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*((sh->wf->wBitsPerSample+7)/8)*sh->wf->nSamplesPerSec;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
411 // Selection:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
412 if(demuxer->audio->id==-1 || demuxer->audio->id==priv->track_db){
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
413 // (auto)selected audio track:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
414 demuxer->audio->id=priv->track_db;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
415 demuxer->audio->sh=sh; sh->ds=demuxer->audio;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
416 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
417 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
418 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
419 case MOV_TRAK_VIDEO: {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
420 sh_video_t* sh=new_sh_video(demuxer,priv->track_db);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
421 sh->format=trak->fourcc;
2386
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
422 if(!sh->fps) sh->fps=trak->timescale;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
423 sh->frametime=1.0f/sh->fps;
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
424 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
425 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
426
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
427 // emulate BITMAPINFOHEADER:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
428 sh->bih=malloc(sizeof(BITMAPINFOHEADER));
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
429 memset(sh->bih,0,sizeof(BITMAPINFOHEADER));
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
430 sh->bih->biSize=40;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
431 sh->bih->biWidth=sh->disp_w;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
432 sh->bih->biHeight=sh->disp_h;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
433 sh->bih->biPlanes=0;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
434 sh->bih->biBitCount=16;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
435 sh->bih->biCompression=trak->fourcc;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
436 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
437
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
438 printf("Image size: %d x %d\n",sh->disp_w,sh->disp_h);
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
439 printf("Fourcc: %.4s Codec: '%.*s'\n",&trak->fourcc,trak->stdata_len-43,trak->stdata+43);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
440
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
441 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
442 // (auto)selected video track:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
443 demuxer->video->id=priv->track_db;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
444 demuxer->video->sh=sh; sh->ds=demuxer->video;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
445 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
446 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
447 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
448 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
449 printf("--------------\n");
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
450 priv->track_db++;
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
451 trak=NULL;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
452 } else
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
453 #ifndef HAVE_ZLIB
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
454 if(id==MOV_FOURCC('c','m','o','v')){
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1567
diff changeset
455 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
456 return;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
457 }
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
458 #else
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
459 if(id==MOV_FOURCC('c','m','o','v')){
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
460 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
461 lschunks(demuxer,level+1,pos+len,NULL);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
462 } else
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
463 if(id==MOV_FOURCC('d','c','o','m')){
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
464 // int temp=stream_read_dword(demuxer->stream);
2386
a48da0b47b02 compression algo detection fix (bswap) and fps fix
alex
parents: 2338
diff changeset
465 unsigned int len=bswap_32(stream_read_dword(demuxer->stream));
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
466 printf("Compressed header uses %.4s algo!\n",&len);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
467 } else
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
468 if(id==MOV_FOURCC('c','m','v','d')){
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
469 // int temp=stream_read_dword(demuxer->stream);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
470 unsigned int moov_sz=stream_read_dword(demuxer->stream);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
471 unsigned int cmov_sz=len-4;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
472 unsigned char* cmov_buf=malloc(cmov_sz);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
473 unsigned char* moov_buf=malloc(moov_sz+16);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
474 int zret;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
475 z_stream zstrm;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
476 stream_t* backup;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
477
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
478 printf("Compressed header size: %d / %d\n",cmov_sz,moov_sz);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
479
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
480 stream_read(demuxer->stream,cmov_buf,cmov_sz);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
481
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
482 zstrm.zalloc = (alloc_func)0;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
483 zstrm.zfree = (free_func)0;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
484 zstrm.opaque = (voidpf)0;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
485 zstrm.next_in = cmov_buf;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
486 zstrm.avail_in = cmov_sz;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
487 zstrm.next_out = moov_buf;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
488 zstrm.avail_out = moov_sz;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
489
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
490 zret = inflateInit(&zstrm);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
491 if (zret != Z_OK)
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
492 { fprintf(stderr,"QT cmov: inflateInit err %d\n",zret);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
493 return;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
494 }
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
495 zret = inflate(&zstrm, Z_NO_FLUSH);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
496 if ((zret != Z_OK) && (zret != Z_STREAM_END))
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
497 { fprintf(stderr,"QT cmov inflate: ERR %d\n",zret);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
498 return;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
499 }
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
500 #if 0
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
501 else {
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
502 FILE *DecOut;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
503 DecOut = fopen("Out.bin", "w");
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
504 fwrite(moov_buf, 1, moov_sz, DecOut);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
505 fclose(DecOut);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
506 }
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
507 #endif
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
508 if(moov_sz != zstrm.total_out) printf("Warning! moov size differs cmov: %d zlib: %d\n",moov_sz,zstrm.total_out);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
509 zret = inflateEnd(&zstrm);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
510
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
511 backup=demuxer->stream;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
512 demuxer->stream=new_memory_stream(moov_buf,moov_sz);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
513 stream_skip(demuxer->stream,8);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
514 lschunks(demuxer,level+1,moov_sz,NULL); // parse uncompr. 'moov'
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
515 //free_stream(demuxer->stream);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
516 demuxer->stream=backup;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
517
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
518 }
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
519 #endif
2429
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
520 else if (id==MOV_FOURCC('u','d','t','a'))
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
521 {
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
522 unsigned int udta_id;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
523 off_t udta_len;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
524 off_t udta_size = len;
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
525
2429
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
526 mp_msg(MSGT_DEMUX, MSGL_DBG2, "mov: user data record found\n");
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
527 mp_msg(MSGT_DEMUX, MSGL_INFO, "Quicktime Clip Info:\n");
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
528
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
529 while((len > 8) && (udta_size > 8))
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
530 {
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
531 udta_len = stream_read_dword(demuxer->stream);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
532 udta_id = stream_read_dword(demuxer->stream);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
533 udta_size -= 8;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
534 mp_msg(MSGT_DEMUX, MSGL_DBG2, "udta_id: %.4s (len: %d)\n", &udta_id, udta_len);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
535 switch (udta_id)
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
536 {
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
537 case MOV_FOURCC(0xa9,'c','p','y'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
538 case MOV_FOURCC(0xa9,'i','n','f'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
539 case MOV_FOURCC(0xa9,'n','a','m'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
540 case MOV_FOURCC(0xa9,'A','R','T'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
541 case MOV_FOURCC(0xa9,'d','i','r'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
542 case MOV_FOURCC(0xa9,'c','m','t'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
543 case MOV_FOURCC(0xa9,'r','e','q'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
544 {
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
545 off_t text_len = stream_read_word(demuxer->stream);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
546 char text[text_len+2+1];
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
547 stream_read(demuxer->stream, (char *)&text, text_len+2);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
548 text[text_len+2] = 0x0;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
549 switch(udta_id)
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
550 {
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
551 case MOV_FOURCC(0xa9,'c','p','y'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
552 mp_msg(MSGT_DEMUX, MSGL_INFO, " Copyright: %s\n", &text[2]);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
553 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
554 case MOV_FOURCC(0xa9,'i','n','f'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
555 mp_msg(MSGT_DEMUX, MSGL_INFO, " Info: %s\n", &text[2]);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
556 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
557 case MOV_FOURCC(0xa9,'n','a','m'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
558 mp_msg(MSGT_DEMUX, MSGL_INFO, " Name: %s\n", &text[2]);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
559 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
560 case MOV_FOURCC(0xa9,'A','R','T'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
561 mp_msg(MSGT_DEMUX, MSGL_INFO, " Artist: %s\n", &text[2]);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
562 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
563 case MOV_FOURCC(0xa9,'d','i','r'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
564 mp_msg(MSGT_DEMUX, MSGL_INFO, " Director: %s\n", &text[2]);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
565 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
566 case MOV_FOURCC(0xa9,'c','m','t'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
567 mp_msg(MSGT_DEMUX, MSGL_INFO, " Comment: %s\n", &text[2]);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
568 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
569 case MOV_FOURCC(0xa9,'r','e','q'):
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
570 mp_msg(MSGT_DEMUX, MSGL_INFO, " Requests(codec): %s\n", &text[2]);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
571 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
572 }
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
573 udta_size -= 4+text_len;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
574 break;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
575 }
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
576 default:
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
577 {
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
578 char dump[udta_len-4];
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
579 stream_read(demuxer->stream, (char *)&dump, udta_len-4-4);
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
580 udta_size -= udta_len;
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
581 }
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
582 }
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
583 }
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
584 } /* eof udta */
8d00b25169af handling free chunk (wide needs implementation) and displaying clip info (datas from udta chunk)
alex
parents: 2419
diff changeset
585
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
586 pos+=len+8;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
587 if(pos>=endpos) break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
588 if(!stream_seek(demuxer->stream,pos)) break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
589 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
590 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
591
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
592 int mov_read_header(demuxer_t* demuxer){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
593 mov_priv_t* priv=demuxer->priv;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
594
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
595 printf("mov_read_header!\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
596
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
597 // Parse header:
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
598 stream_reset(demuxer->stream);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
599 if(!stream_seek(demuxer->stream,priv->moov_start)) return 0; // ???
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
600 lschunks(demuxer, 0, priv->moov_end, NULL);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
601
2127
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
602 #if 1
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
603 return 1;
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
604 #else
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1567
diff changeset
605 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVnotyetsupp);
2127
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
606 return 0;
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
607 #endif
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
608 }
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
609
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
610 // return value:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
611 // 0 = EOF or no stream found
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
612 // 1 = successfully read a packet
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
613 int demux_mov_fill_buffer(demuxer_t *demuxer,demux_stream_t* ds){
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
614 mov_priv_t* priv=demuxer->priv;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
615 mov_track_t* trak=NULL;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
616 float pts;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
617
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
618 if(ds->id<0 || ds->id>=priv->track_db) return 0;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
619 trak=priv->tracks[ds->id];
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
620
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
621 if(trak->samplesize){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
622 // read chunk:
2419
24ba3dfb8e89 compressed mov audio fixed
arpi
parents: 2386
diff changeset
623 int x;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
624 if(trak->pos>=trak->chunks_size) return 0; // EOF
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
625 stream_seek(demuxer->stream,trak->chunks[trak->pos].pos);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
626 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale;
2419
24ba3dfb8e89 compressed mov audio fixed
arpi
parents: 2386
diff changeset
627 x=trak->chunks[trak->pos].size*trak->samplesize;
24ba3dfb8e89 compressed mov audio fixed
arpi
parents: 2386
diff changeset
628 x/=ds->ss_div; x*=ds->ss_mul; // compression ratio fix
24ba3dfb8e89 compressed mov audio fixed
arpi
parents: 2386
diff changeset
629 ds_read_packet(ds,demuxer->stream,x,pts,trak->chunks[trak->pos].pos,0);
24ba3dfb8e89 compressed mov audio fixed
arpi
parents: 2386
diff changeset
630 if(ds==demuxer->audio) printf("sample %d bytes pts %5.3f\n",trak->chunks[trak->pos].size*trak->samplesize,pts);
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
631 } else {
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
632 // read sample:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
633 if(trak->pos>=trak->samples_size) return 0; // EOF
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
634 stream_seek(demuxer->stream,trak->samples[trak->pos].pos);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
635 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
636 ds_read_packet(ds,demuxer->stream,trak->samples[trak->pos].size,pts,trak->samples[trak->pos].pos,0);
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
637 }
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
638 ++trak->pos;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
639
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
640 return 1;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
641
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
642 }
2227
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
643
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
644 static float mov_seek_track(mov_track_t* trak,float pts,int flags){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
645
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
646 // printf("MOV track seek called %5.3f \n",pts);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
647 if(flags&2) pts*=trak->length; else pts*=(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
648
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
649 if(trak->samplesize){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
650 int sample=pts/trak->duration;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
651 // printf("MOV track seek - chunk: %d (pts: %5.3f dur=%d) \n",sample,pts,trak->duration);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
652 if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
653 trak->pos=0;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
654 while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
655 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
656 } else {
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
657 unsigned int ipts=pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
658 // printf("MOV track seek - sample: %d \n",ipts);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
659 if(!(flags&1)) ipts+=trak->samples[trak->pos].pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
660 trak->pos=0;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
661 while(trak->pos<trak->samples_size && trak->samples[trak->pos].pts<ipts) ++trak->pos;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
662 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
663 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
664
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
665 // printf("MOV track seek done: %5.3f \n",pts);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
666
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
667 return pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
668 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
669
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
670 void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
671 mov_priv_t* priv=demuxer->priv;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
672 demux_stream_t* ds;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
673
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
674 // printf("MOV seek called %5.3f flag=%d \n",pts,flags);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
675
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
676 ds=demuxer->video;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
677 if(ds && ds->id>=0 && ds->id<priv->track_db){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
678 mov_track_t* trak=priv->tracks[ds->id];
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
679 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
680 //if(!(flags&1)) pts+=ds->pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
681 pts=ds->pts=mov_seek_track(trak,pts,flags);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
682 flags=1; // absolute seconds
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
683 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
684
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
685 ds=demuxer->audio;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
686 if(ds && ds->id>=0 && ds->id<priv->track_db){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
687 mov_track_t* trak=priv->tracks[ds->id];
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
688 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
689 //if(!(flags&1)) pts+=ds->pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
690 ds->pts=mov_seek_track(trak,pts,flags);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
691 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
692
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
693 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
694