annotate demux_mov.c @ 2264:7851375ea156

increased precission of s_xinc s_xinc2 (needed for the mmx2 bugfix) moved mmx variables to top to avoid alignment issues mmx2 code should work fine now if and only if the input width is %16=0 and the output width is %32=0 reordered some code (5% faster with a simply -benchmark) first line bug fixed (i hope i didnt introduce any new bugs with that ...) changed a lot of the vertical scale setup code, i hope i fixed something and didnt mess it up :) a few known bugs left (rightmost line is wrong) MMX2 code will only be used for upscaling & acceptable widthˇ­s 16bit dithering can be disabled
author michael
date Thu, 18 Oct 2001 22:27:13 +0000
parents 10b279d72a8f
children
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.
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
4
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
5 #include <stdio.h>
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
6 #include <stdlib.h>
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
7 #include <unistd.h>
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
8
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
9 #include "config.h"
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
10
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
11 #ifdef HAVE_PNG
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
12 // should be detected by ./configure...
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
13 #define HAVE_ZLIB
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
14 #endif
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
15
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
16 #include "mp_msg.h"
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1567
diff changeset
17 #include "help_mp.h"
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
18
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
19 #include "stream.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
20 #include "demuxer.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
21
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
22 #include "wine/mmreg.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
23 #include "wine/avifmt.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
24 #include "wine/vfw.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
25
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
26 #include "codec-cfg.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
27 #include "stheader.h"
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
28
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
29 #ifdef HAVE_ZLIB
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
30 #include <zlib.h>
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
31 #endif
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
32
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
33 typedef struct {
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
34 unsigned int pts; // duration
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
35 unsigned int size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
36 off_t pos;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
37 } mov_sample_t;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
38
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
39 typedef struct {
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
40 unsigned int sample; // number of the first sample in teh chunk
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
41 unsigned int size; // number of samples in the chunk
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
42 int desc; // for multiple codecs mode - not used
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
43 off_t pos;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
44 } mov_chunk_t;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
45
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
46 typedef struct {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
47 unsigned int first;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
48 unsigned int spc;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
49 unsigned int sdid;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
50 } mov_chunkmap_t;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
51
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
52 typedef struct {
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
53 unsigned int num;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
54 unsigned int dur;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
55 } mov_durmap_t;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
56
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
57 typedef struct {
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
58 int id;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
59 int type;
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
60 int pos;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
61 //
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
62 int timescale;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
63 unsigned int length;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
64 int samplesize; // 0 = variable
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
65 int duration; // 0 = variable
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
66 int width,height; // for video
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
67 unsigned int fourcc;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
68 //
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
69 int tkdata_len; // track data
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
70 unsigned char* tkdata;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
71 int stdata_len; // stream data
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
72 unsigned char* stdata;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
73 int samples_size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
74 mov_sample_t* samples;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
75 int chunks_size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
76 mov_chunk_t* chunks;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
77 int chunkmap_size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
78 mov_chunkmap_t* chunkmap;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
79 int durmap_size;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
80 mov_durmap_t* durmap;
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
81 } mov_track_t;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
82
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
83 void mov_build_index(mov_track_t* trak){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
84 int i,j,s;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
85 int last=trak->chunks_size;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
86 unsigned int pts=0;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
87 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
88 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
89 // process chunkmap:
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
90 i=trak->chunkmap_size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
91 while(i>0){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
92 --i;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
93 for(j=trak->chunkmap[i].first;j<last;j++){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
94 trak->chunks[j].desc=trak->chunkmap[i].sdid;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
95 trak->chunks[j].size=trak->chunkmap[i].spc;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
96 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
97 last=trak->chunkmap[i].first;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
98 }
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
99
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
100 // calc pts of chunks:
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
101 s=0;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
102 for(j=0;j<trak->chunks_size;j++){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
103 trak->chunks[j].sample=s;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
104 s+=trak->chunks[j].size;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
105 }
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
106
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
107 if(!trak->samples_size){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
108 // constant sampesize
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
109 if(trak->durmap_size==1 || (trak->durmap_size==2 && trak->durmap[1].num==1)){
2227
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
110 trak->duration=trak->durmap[0].dur;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
111 } 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
112 return;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
113 }
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
114
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
115 // calc pts:
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
116 s=0;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
117 for(j=0;j<trak->durmap_size;j++){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
118 for(i=0;i<trak->durmap[j].num;i++){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
119 trak->samples[s].pts=pts;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
120 ++s;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
121 pts+=trak->durmap[j].dur;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
122 }
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
123 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
124
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
125 // calc sample offsets
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
126 s=0;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
127 for(j=0;j<trak->chunks_size;j++){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
128 off_t pos=trak->chunks[j].pos;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
129 for(i=0;i<trak->chunks[j].size;i++){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
130 trak->samples[s].pos=pos;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
131 #if 0
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
132 printf("Sample %5d: pts=%8d off=0x%08X size=%d\n",s,
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
133 trak->samples[s].pts,
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
134 (int)trak->samples[s].pos,
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
135 trak->samples[s].size);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
136 #endif
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
137 pos+=trak->samples[s].size;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
138 ++s;
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 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
141
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
142 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
143
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
144 #define MOV_MAX_TRACKS 256
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
145
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
146 #define MOV_TRAK_UNKNOWN 0
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
147 #define MOV_TRAK_VIDEO 1
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
148 #define MOV_TRAK_AUDIO 2
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
149
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
150 typedef struct {
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
151 off_t moov_start;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
152 off_t moov_end;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
153 off_t mdat_start;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
154 off_t mdat_end;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
155 int track_db;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
156 mov_track_t* tracks[MOV_MAX_TRACKS];
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
157 } mov_priv_t;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
158
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
159 #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
160
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
161 int mov_check_file(demuxer_t* demuxer){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
162 int flags=0;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
163 mov_priv_t* priv=malloc(sizeof(mov_priv_t));
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
164
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
165 mp_msg(MSGT_DEMUX,MSGL_V,"Checking for MOV\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
166
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
167 memset(priv,0,sizeof(mov_priv_t));
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
168 demuxer->priv=priv;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
169
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
170 while(1){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
171 off_t len=stream_read_dword(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
172 unsigned int id=stream_read_dword(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
173 if(stream_eof(demuxer->stream)) break; // EOF
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
174 if(len<8) break; // invalid chunk
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
175 switch(id){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
176 case MOV_FOURCC('m','o','o','v'):
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
177 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie header found!\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
178 priv->moov_start=stream_tell(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
179 priv->moov_end=priv->moov_start+len-8;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
180 flags|=1;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
181 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
182 case MOV_FOURCC('m','d','a','t'):
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
183 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: Movie DATA found!\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
184 priv->mdat_start=stream_tell(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
185 priv->mdat_end=priv->mdat_start+len-8;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
186 flags|=2;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
187 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
188 default:
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
189 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
190 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
191 if(!stream_skip(demuxer->stream,len-8)) break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
192 }
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
193
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
194 if(flags==1)
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
195 mp_msg(MSGT_DEMUX,MSGL_WARN,"MOV: missing data (mdat) chunk! Maybe broken file...\n");
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
196 else if(flags==2)
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
197 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
198
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
199 return (flags==3);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
200 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
201
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
202 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
203 mov_priv_t* priv=demuxer->priv;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
204 while(1){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
205 off_t pos;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
206 off_t len;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
207 unsigned int id;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
208 //
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
209 pos=stream_tell(demuxer->stream);
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
210 // printf("stream_tell==%d\n",pos);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
211 if(pos>=endpos) return; // END
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
212 len=stream_read_dword(demuxer->stream);
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
213 // printf("len==%d\n",len);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
214 if(len<8) return; // error
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
215 len-=8;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
216 id=stream_read_dword(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
217 //
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
218 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
219 //
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
220 if(trak){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
221 switch(id){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
222 case MOV_FOURCC('t','k','h','d'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
223 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sTrack header!\n",level,"");
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
224 // read codec data
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
225 trak->tkdata_len=len;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
226 trak->tkdata=malloc(trak->tkdata_len);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
227 stream_read(demuxer->stream,trak->tkdata,trak->tkdata_len);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
228 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
229 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
230 case MOV_FOURCC('m','d','h','d'): {
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
231 unsigned int tmp;
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
232 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia header!\n",level,"");
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
233 #if 0
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
234 tmp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
235 printf("dword1: 0x%08X (%d)\n",tmp,tmp);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
236 tmp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
237 printf("dword2: 0x%08X (%d)\n",tmp,tmp);
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("dword3: 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("dword4: 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("dword5: 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("dword6: 0x%08X (%d)\n",tmp,tmp);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
246 #endif
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
247 stream_skip(demuxer->stream,12);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
248 // read timescale
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
249 trak->timescale=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
250 // read length
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
251 trak->length=stream_read_dword(demuxer->stream);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
252 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
253 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
254 case MOV_FOURCC('v','m','h','d'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
255 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sVideo header!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
256 trak->type=MOV_TRAK_VIDEO;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
257 // read video data
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
258 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
259 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
260 case MOV_FOURCC('s','m','h','d'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
261 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSound header!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
262 trak->type=MOV_TRAK_AUDIO;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
263 // read audio data
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
264 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
265 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
266 case MOV_FOURCC('s','t','s','d'): {
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
267 int i=stream_read_dword(demuxer->stream); // temp!
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
268 int count=stream_read_dword(demuxer->stream);
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
269 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
270 for(i=0;i<count;i++){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
271 off_t pos=stream_tell(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
272 off_t len=stream_read_dword(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
273 unsigned int fourcc=stream_read_dword_le(demuxer->stream);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
274 if(len<8) break; // error
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
275 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
276 if(!i){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
277 trak->fourcc=fourcc;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
278 // read codec data
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
279 trak->stdata_len=len-8;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
280 trak->stdata=malloc(trak->stdata_len);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
281 stream_read(demuxer->stream,trak->stdata,trak->stdata_len);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
282 if(trak->type==MOV_TRAK_VIDEO && trak->stdata_len>43){
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
283 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
284 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
285 }
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
286 mp_msg(MSGT_DEMUX,MSGL_V,"\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
287 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
288 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVvariableFourCC);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
289 if(!stream_seek(demuxer->stream,pos+len)) break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
290 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
291 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
292 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
293 case MOV_FOURCC('s','t','t','s'): {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
294 int temp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
295 int len=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
296 int i;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
297 int x=0;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
298 unsigned int pts=0;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
299 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
300 trak->durmap=malloc(sizeof(mov_durmap_t)*len);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
301 memset(trak->durmap,0,sizeof(mov_durmap_t)*len);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
302 trak->durmap_size=len;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
303 for(i=0;i<len;i++){
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
304 trak->durmap[i].num=stream_read_dword(demuxer->stream);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
305 trak->durmap[i].dur=stream_read_dword(demuxer->stream);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
306 pts+=trak->durmap[i].num*trak->durmap[i].dur;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
307 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
308 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
309 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
310 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
311 case MOV_FOURCC('s','t','s','c'): {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
312 int temp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
313 int len=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
314 int i;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
315 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
316 // read data:
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
317 trak->chunkmap_size=len;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
318 trak->chunkmap=malloc(sizeof(mov_chunkmap_t)*len);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
319 for(i=0;i<len;i++){
2103
3e55202cfdab ehh. first chunk is counted from 1. fixed...
arpi
parents: 2101
diff changeset
320 trak->chunkmap[i].first=stream_read_dword(demuxer->stream)-1;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
321 trak->chunkmap[i].spc=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
322 trak->chunkmap[i].sdid=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
323 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
324 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
325 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
326 case MOV_FOURCC('s','t','s','z'): {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
327 int temp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
328 int ss=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
329 int len=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
330 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
331 trak->samplesize=ss;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
332 if(!ss){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
333 // variable samplesize
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
334 int i;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
335 trak->samples=realloc(trak->samples,sizeof(mov_sample_t)*len);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
336 trak->samples_size=len;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
337 for(i=0;i<len;i++)
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
338 trak->samples[i].size=stream_read_dword(demuxer->stream);
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
339 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
340 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
341 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
342 case MOV_FOURCC('s','t','c','o'): {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
343 int temp=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
344 int len=stream_read_dword(demuxer->stream);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
345 int i;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
346 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
347 // extend array if needed:
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
348 if(len>trak->chunks_size){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
349 trak->chunks=realloc(trak->chunks,sizeof(mov_chunk_t)*len);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
350 trak->chunks_size=len;
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 // read elements:
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
353 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
354 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
355 }
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
356 case MOV_FOURCC('m','d','i','a'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
357 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia stream!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
358 lschunks(demuxer,level+1,pos+len,trak);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
359 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
360 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
361 case MOV_FOURCC('m','i','n','f'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
362 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sMedia info!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
363 lschunks(demuxer,level+1,pos+len,trak);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
364 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
365 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
366 case MOV_FOURCC('s','t','b','l'): {
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
367 mp_msg(MSGT_DEMUX,MSGL_V,"MOV: %*sSample info!\n",level,"");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
368 lschunks(demuxer,level+1,pos+len,trak);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
369 break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
370 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
371 }//switch(id)
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
372 } else
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
373 if(id==MOV_FOURCC('t','r','a','k')){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
374 // if(trak) printf("MOV: Warning! trak in trak?\n");
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
375 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
376 mp_msg(MSGT_DEMUX,MSGL_WARN,MSGTR_MOVtooManyTrk);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
377 return;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
378 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
379 trak=malloc(sizeof(mov_track_t));
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
380 memset(trak,0,sizeof(mov_track_t));
1567
5c7760aa4f94 printf->mp_msg/mp_dbg
arpi
parents: 1490
diff changeset
381 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
382 trak->id=priv->track_db;
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
383 priv->tracks[priv->track_db]=trak;
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
384 lschunks(demuxer,level+1,pos+len,trak);
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
385 mov_build_index(trak);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
386 switch(trak->type){
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
387 case MOV_TRAK_AUDIO: {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
388 sh_audio_t* sh=new_sh_audio(demuxer,priv->track_db);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
389 sh->format=trak->fourcc;
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
390 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
391 printf("Fourcc: %.4s\n",&trak->fourcc);
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
392 // Emulate WAVEFORMATEX struct:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
393 sh->wf=malloc(sizeof(WAVEFORMATEX));
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
394 memset(sh->wf,0,sizeof(WAVEFORMATEX));
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
395 sh->wf->nChannels=trak->stdata[17];
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
396 sh->wf->wBitsPerSample=trak->stdata[19];
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
397 sh->wf->nSamplesPerSec=trak->timescale;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
398 sh->wf->nAvgBytesPerSec=sh->wf->nChannels*((sh->wf->wBitsPerSample+7)/8)*sh->wf->nSamplesPerSec;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
399 // Selection:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
400 if(demuxer->audio->id==-1 || demuxer->audio->id==priv->track_db){
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
401 // (auto)selected audio track:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
402 demuxer->audio->id=priv->track_db;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
403 demuxer->audio->sh=sh; sh->ds=demuxer->audio;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
404 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
405 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
406 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
407 case MOV_TRAK_VIDEO: {
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
408 sh_video_t* sh=new_sh_video(demuxer,priv->track_db);
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
409 sh->format=trak->fourcc;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
410 sh->fps=trak->timescale;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
411 sh->frametime=1.0f/sh->fps;
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
412 sh->disp_w=trak->tkdata[77]|(trak->tkdata[76]<<8);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
413 sh->disp_h=trak->tkdata[81]|(trak->tkdata[80]<<8);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
414
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
415 // emulate BITMAPINFOHEADER:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
416 sh->bih=malloc(sizeof(BITMAPINFOHEADER));
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
417 memset(sh->bih,0,sizeof(BITMAPINFOHEADER));
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
418 sh->bih->biSize=40;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
419 sh->bih->biWidth=sh->disp_w;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
420 sh->bih->biHeight=sh->disp_h;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
421 sh->bih->biPlanes=0;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
422 sh->bih->biBitCount=16;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
423 sh->bih->biCompression=trak->fourcc;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
424 sh->bih->biSizeImage=sh->bih->biWidth*sh->bih->biHeight;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
425
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
426 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
427 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
428
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
429 if(demuxer->video->id==-1 || demuxer->video->id==priv->track_db){
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
430 // (auto)selected video track:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
431 demuxer->video->id=priv->track_db;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
432 demuxer->video->sh=sh; sh->ds=demuxer->video;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
433 }
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
434 break;
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
435 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
436 }
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
437 printf("--------------\n");
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
438 priv->track_db++;
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
439 trak=NULL;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
440 } else
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
441 #ifndef HAVE_ZLIB
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
442 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
443 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
444 return;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
445 }
2148
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
446 #else
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
447 if(id==MOV_FOURCC('c','m','o','v')){
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
448 // mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVcomprhdr);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
449 lschunks(demuxer,level+1,pos+len,NULL);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
450 } else
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
451 if(id==MOV_FOURCC('d','c','o','m')){
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
452 // int temp=stream_read_dword(demuxer->stream);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
453 unsigned int len=stream_read_dword(demuxer->stream);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
454 printf("Compressed header uses %.4s algo!\n",&len);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
455 } else
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
456 if(id==MOV_FOURCC('c','m','v','d')){
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
457 // int temp=stream_read_dword(demuxer->stream);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
458 unsigned int moov_sz=stream_read_dword(demuxer->stream);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
459 unsigned int cmov_sz=len-4;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
460 unsigned char* cmov_buf=malloc(cmov_sz);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
461 unsigned char* moov_buf=malloc(moov_sz+16);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
462 int zret;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
463 z_stream zstrm;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
464 stream_t* backup;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
465
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
466 printf("Compressed header size: %d / %d\n",cmov_sz,moov_sz);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
467
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
468 stream_read(demuxer->stream,cmov_buf,cmov_sz);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
469
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
470 zstrm.zalloc = (alloc_func)0;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
471 zstrm.zfree = (free_func)0;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
472 zstrm.opaque = (voidpf)0;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
473 zstrm.next_in = cmov_buf;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
474 zstrm.avail_in = cmov_sz;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
475 zstrm.next_out = moov_buf;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
476 zstrm.avail_out = moov_sz;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
477
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
478 zret = inflateInit(&zstrm);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
479 if (zret != Z_OK)
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
480 { fprintf(stderr,"QT cmov: inflateInit err %d\n",zret);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
481 return;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
482 }
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
483 zret = inflate(&zstrm, Z_NO_FLUSH);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
484 if ((zret != Z_OK) && (zret != Z_STREAM_END))
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
485 { fprintf(stderr,"QT cmov inflate: ERR %d\n",zret);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
486 return;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
487 }
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
488 #if 0
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
489 else {
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
490 FILE *DecOut;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
491 DecOut = fopen("Out.bin", "w");
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
492 fwrite(moov_buf, 1, moov_sz, DecOut);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
493 fclose(DecOut);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
494 }
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
495 #endif
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
496 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
497 zret = inflateEnd(&zstrm);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
498
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
499 backup=demuxer->stream;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
500 demuxer->stream=new_memory_stream(moov_buf,moov_sz);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
501 stream_skip(demuxer->stream,8);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
502 lschunks(demuxer,level+1,moov_sz,NULL); // parse uncompr. 'moov'
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
503 //free_stream(demuxer->stream);
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
504 demuxer->stream=backup;
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
505
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
506 }
0c6cef85d507 compressed headers support
arpi
parents: 2127
diff changeset
507 #endif
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
508
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
509 pos+=len+8;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
510 if(pos>=endpos) break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
511 if(!stream_seek(demuxer->stream,pos)) break;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
512 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
513 }
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
514
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
515 int mov_read_header(demuxer_t* demuxer){
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
516 mov_priv_t* priv=demuxer->priv;
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
517
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
518 printf("mov_read_header!\n");
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
519
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
520 // Parse header:
2100
6f6eb4f8e7a0 finished mov header and index processing
arpi
parents: 1973
diff changeset
521 stream_reset(demuxer->stream);
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
522 if(!stream_seek(demuxer->stream,priv->moov_start)) return 0; // ???
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
523 lschunks(demuxer, 0, priv->moov_end, NULL);
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
524
2127
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
525 #if 1
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
526 return 1;
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
527 #else
1973
5216f108cb4f all error/warn/info messages moved to help_mp-en.h for translation
arpi
parents: 1567
diff changeset
528 mp_msg(MSGT_DEMUX,MSGL_ERR,MSGTR_MOVnotyetsupp);
2127
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
529 return 0;
e6ce221dee06 .mov support can be disabled
arpi
parents: 2115
diff changeset
530 #endif
1490
71424eb2b282 MOV file support - not works yet
arpi
parents:
diff changeset
531 }
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
532
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
533 // return value:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
534 // 0 = EOF or no stream found
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
535 // 1 = successfully read a packet
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
536 int demux_mov_fill_buffer(demuxer_t *demuxer,demux_stream_t* ds){
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
537 mov_priv_t* priv=demuxer->priv;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
538 mov_track_t* trak=NULL;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
539 float pts;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
540
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
541 if(ds->id<0 || ds->id>=priv->track_db) return 0;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
542 trak=priv->tracks[ds->id];
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
543
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
544 if(trak->samplesize){
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
545 // read chunk:
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
546 if(trak->pos>=trak->chunks_size) return 0; // EOF
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
547 stream_seek(demuxer->stream,trak->chunks[trak->pos].pos);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
548 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale;
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
549 ds_read_packet(ds,demuxer->stream,trak->chunks[trak->pos].size*trak->samplesize,pts,trak->chunks[trak->pos].pos,0);
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
550 } else {
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
551 // read sample:
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
552 if(trak->pos>=trak->samples_size) return 0; // EOF
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
553 stream_seek(demuxer->stream,trak->samples[trak->pos].pos);
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
554 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
555 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
556 }
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
557 ++trak->pos;
2115
fe1cd4a5109a optimized demuxer for fixed samplesize (raw audio)
arpi
parents: 2103
diff changeset
558
2101
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
559 return 1;
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
560
4ca146a57d17 implemented simple demuxer
arpi
parents: 2100
diff changeset
561 }
2227
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
562
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
563 static float mov_seek_track(mov_track_t* trak,float pts,int flags){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
564
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
565 // printf("MOV track seek called %5.3f \n",pts);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
566 if(flags&2) pts*=trak->length; else pts*=(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
567
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
568 if(trak->samplesize){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
569 int sample=pts/trak->duration;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
570 // 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
571 if(!(flags&1)) sample+=trak->chunks[trak->pos].sample; // relative
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
572 trak->pos=0;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
573 while(trak->pos<trak->chunks_size && trak->chunks[trak->pos].sample<sample) ++trak->pos;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
574 pts=(float)(trak->chunks[trak->pos].sample*trak->duration)/(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
575 } else {
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
576 unsigned int ipts=pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
577 // printf("MOV track seek - sample: %d \n",ipts);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
578 if(!(flags&1)) ipts+=trak->samples[trak->pos].pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
579 trak->pos=0;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
580 while(trak->pos<trak->samples_size && trak->samples[trak->pos].pts<ipts) ++trak->pos;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
581 pts=(float)trak->samples[trak->pos].pts/(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
582 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
583
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
584 // printf("MOV track seek done: %5.3f \n",pts);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
585
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
586 return pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
587 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
588
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
589 void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
590 mov_priv_t* priv=demuxer->priv;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
591 demux_stream_t* ds;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
592
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
593 // printf("MOV seek called %5.3f flag=%d \n",pts,flags);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
594
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
595 ds=demuxer->video;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
596 if(ds && ds->id>=0 && ds->id<priv->track_db){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
597 mov_track_t* trak=priv->tracks[ds->id];
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
598 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
599 //if(!(flags&1)) pts+=ds->pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
600 pts=ds->pts=mov_seek_track(trak,pts,flags);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
601 flags=1; // absolute seconds
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
602 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
603
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
604 ds=demuxer->audio;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
605 if(ds && ds->id>=0 && ds->id<priv->track_db){
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
606 mov_track_t* trak=priv->tracks[ds->id];
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
607 //if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
608 //if(!(flags&1)) pts+=ds->pts;
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
609 ds->pts=mov_seek_track(trak,pts,flags);
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
610 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
611
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
612 }
10b279d72a8f mov seeking implemented
arpi
parents: 2148
diff changeset
613