annotate demux_avi.c @ 950:de1e10c4da3c

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