annotate demux_avi.c @ 31:1fc618eba830

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