annotate demux_avi.c @ 168:bdc4a8fc04d8

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