annotate demux_avi.c @ 340:1f7c824033fb

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