annotate demux_avi.c @ 487:5dd417ed3a21

vo_debug printfs...
author arpi_esp
date Tue, 17 Apr 2001 18:37:15 +0000
parents 26e513f392b2
children 8511095c5283
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1 // AVI file parser for DEMUXER v2.6 by A'rpi/ESP-team
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3 //static float avi_pts_frametime=1.0f/25.0f;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 static float avi_audio_pts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5 static float avi_video_pts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 static int skip_video_frames=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 static inline int avi_stream_id(unsigned int id){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 unsigned char *p=(unsigned char *)&id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 unsigned char a,b;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 a=p[0]-'0'; b=p[1]-'0';
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 if(a>9 || b>9) return 100; // invalid ID
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 return a*10+b;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 // Select ds from ID
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 static inline demux_stream_t* demux_avi_select_stream(demuxer_t *demux,unsigned int id){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 int stream_id=avi_stream_id(id);
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
20
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
21 // printf("demux_avi_select_stream(%d) {a:%d/v:%d}\n",stream_id,
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
22 // demux->audio->id,demux->video->id);
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
23
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
24 if(demux->video->id==-1)
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
25 if(avi_header.v_streams[stream_id])
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
26 demux->video->id=stream_id;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
27
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
28 if(demux->audio->id==-1)
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
29 if(avi_header.a_streams[stream_id])
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
30 demux->audio->id=stream_id;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
31
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
32 if(stream_id==demux->audio->id){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
33 if(!demux->audio->sh){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
34 demux->audio->sh=avi_header.a_streams[stream_id];
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
35 if(verbose) printf("Auto-selected AVI audio ID = %d\n",demux->audio->id);
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
36 }
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
37 return demux->audio;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
38 }
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
39 if(stream_id==demux->video->id){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
40 if(!demux->video->sh){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
41 demux->video->sh=avi_header.v_streams[stream_id];
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
42 if(verbose) printf("Auto-selected AVI video ID = %d\n",demux->video->id);
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
43 }
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
44 return demux->video;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
45 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 if(id!=mmioFOURCC('J','U','N','K')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 // unknown
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 if(verbose>=2) printf("Unknown chunk: %.4s (%X)\n",&id,id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 return NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 static int demux_avi_read_packet(demuxer_t *demux,unsigned int id,unsigned int len,int idxpos){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 int skip;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 float pts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 demux_stream_t *ds=demux_avi_select_stream(demux,id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 if(verbose>=3) printf("demux_avi.read_packet: %X\n",id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 if(ds==demux->audio){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 pts=avi_audio_pts;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 avi_audio_pts=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 if(ds==demux->video){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 // video
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 if(skip_video_frames>0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 // drop frame (seeking)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 --skip_video_frames;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 ds=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 pts=avi_video_pts;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 // ezt a 2 sort lehet hogy fell kell majd cserelni:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 //avi_video_pts+=avi_pts_frametime;
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 109
diff changeset
75 //avi_video_pts+=(float)avi_header.video.dwScale/(float)avi_header.video.dwRate;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 109
diff changeset
76 //avi_video_pts+=((sh_video_t*)ds->sh)->frametime;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 109
diff changeset
77 avi_video_pts+=(float)((sh_video_t*)(demux->video->sh))->video.dwScale/(float)((sh_video_t*)(demux->video->sh))->video.dwRate;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 avi_audio_pts=avi_video_pts;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 // len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 skip=(len+1)&(~1); // total bytes in this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 if(ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 if(verbose>=2) printf("DEMUX_AVI: Read %d data bytes from packet %04X\n",len,id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 ds_read_packet(ds,demux->stream,len,pts,idxpos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 skip-=len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 if(skip){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 if(verbose>=2) printf("DEMUX_AVI: Skipping %d bytes from packet %04X\n",skip,id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 stream_skip(demux->stream,skip);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 return ds?1:0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96 //static int num_elementary_packets100=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 //static int num_elementary_packets101=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 // 1 = successfully read a packet
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 int demux_avi_fill_buffer(demuxer_t *demux){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 int max_packs=128;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 do{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109 AVIINDEXENTRY *idx=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 demux->filepos=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 if(demux->filepos>=demux->endpos){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115 if(stream_eof(demux->stream)) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 if(avi_header.idx_size>0 && avi_header.idx_pos<avi_header.idx_size){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 unsigned int pos;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
119 //if(avi_header.idx_pos<0) printf("Fatal! idx_pos=%d\n",avi_header.idx_pos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 idx=&avi_header.idx[avi_header.idx_pos++];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 //printf("[%d]",avi_header.idx_pos);fflush(stdout);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
124
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
125 //stream_seek(demux->stream,idx.dwChunkOffset);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
126 //printf("IDX pos=%X idx.pos=%X idx.size=%X idx.flags=%X\n",demux->filepos,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
127 // pos-4,idx->dwChunkLength,idx->dwFlags);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
128 if(idx->dwFlags&AVIIF_LIST){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
129 // LIST
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132 if(!demux_avi_select_stream(demux,idx->ckid)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 if(verbose>2) printf("Skip chunk %.4s (0x%X) \n",&idx->ckid,idx->ckid);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 continue; // skip this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 pos=idx->dwChunkOffset+avi_header.idx_offset;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 if(pos<avi_header.movi_start || pos>=avi_header.movi_end){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 printf("ChunkOffset out of range! current=0x%X idx=0x%X \n",demux->filepos,pos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 if(pos!=demux->filepos){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 printf("Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 stream_seek(demux->stream,pos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 if(id!=idx->ckid){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 printf("ChunkID mismatch! raw=%.4s idx=%.4s \n",&id,&idx->ckid);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154 // if((len&(~1))!=(idx->dwChunkLength&(~1))){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 // if((len)!=(idx->dwChunkLength)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
156 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157 printf("ChunkSize mismatch! raw=%d idx=%d \n",len,idx->dwChunkLength);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 if(id==mmioFOURCC('L','I','S','T')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 id=stream_read_dword_le(demux->stream); // list type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 ret=demux_avi_read_packet(demux,id,len,avi_header.idx_pos-1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 if(!ret && skip_video_frames<=0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 if(--max_packs==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 printf("demux: file doesn't contain the selected audio or video stream\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 // 1 = successfully read a packet
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 int demux_avi_fill_buffer_ni(demuxer_t *demux,demux_stream_t* ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 int max_packs=128;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189 do{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 AVIINDEXENTRY *idx=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 int idx_pos=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 demux->filepos=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 if(ds==demux->video) idx_pos=avi_header.idx_pos_a++; else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 if(ds==demux->audio) idx_pos=avi_header.idx_pos_v++; else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 idx_pos=avi_header.idx_pos++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 if(avi_header.idx_size>0 && idx_pos<avi_header.idx_size){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 unsigned int pos;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 idx=&avi_header.idx[idx_pos];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 if(idx->dwFlags&AVIIF_LIST){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 // LIST
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 if(ds && demux_avi_select_stream(demux,idx->ckid)!=ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 if(verbose>2) printf("Skip chunk %.4s (0x%X) \n",&idx->ckid,idx->ckid);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 continue; // skip this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 pos=idx->dwChunkOffset+avi_header.idx_offset;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 if(pos<avi_header.movi_start || pos>=avi_header.movi_end){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213 printf("ChunkOffset out of range! current=0x%X idx=0x%X \n",demux->filepos,pos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 #if 0
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 if(pos!=demux->filepos){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 printf("Warning! pos=0x%X idx.pos=0x%X diff=%d \n",demux->filepos,pos,pos-demux->filepos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 stream_seek(demux->stream,pos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 if(stream_eof(demux->stream)) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 if(id!=idx->ckid){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 printf("ChunkID mismatch! raw=%.4s idx=%.4s \n",&id,&idx->ckid);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 // if((len&(~1))!=(idx->dwChunkLength&(~1))){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 // if((len)!=(idx->dwChunkLength)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 if((len!=idx->dwChunkLength)&&((len+1)!=idx->dwChunkLength)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 printf("ChunkSize mismatch! raw=%d idx=%d \n",len,idx->dwChunkLength);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 } else return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 ret=demux_avi_read_packet(demux,id,len,idx_pos);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 if(!ret && skip_video_frames<=0)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241 if(--max_packs==0){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 printf("demux: file doesn't contain the selected audio or video stream\n");
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 // return value:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 // 0 = EOF or no stream found
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 // 1 = successfully read a packet
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 int demux_avi_fill_buffer_nini(demuxer_t *demux,demux_stream_t* ds){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255 unsigned int id=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 unsigned int len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 int ret=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 int *fpos=NULL;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 if(ds==demux->video) fpos=&avi_header.idx_pos_a; else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 if(ds==demux->audio) fpos=&avi_header.idx_pos_v; else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 stream_seek(demux->stream,fpos[0]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 do{
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 demux->filepos=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 if(demux->filepos>=demux->endpos){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 demux->stream->eof=1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 if(stream_eof(demux->stream)) return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 id=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 len=stream_read_dword_le(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 if(id==mmioFOURCC('L','I','S','T')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278 id=stream_read_dword_le(demux->stream); // list type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 if(ds==demux_avi_select_stream(demux,id)){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
283 // read it!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 ret=demux_avi_read_packet(demux,id,len,avi_header.idx_pos-1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 // skip it!
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 int skip=(len+1)&(~1); // total bytes in this chunk
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 stream_skip(demux->stream,skip);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
291 } while(ret!=1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 fpos[0]=stream_tell(demux->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 return 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296