annotate aviheader.c @ 272:8ffe2f459851

- still more debug output to be able to fix 15/16 bpp problem
author acki2
date Sun, 01 Apr 2001 22:01:28 +0000
parents 3b5f5d1c5041
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
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
2 #define MIN(a,b) (((a)<(b))?(a):(b))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
3
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
4 void read_avi_header(int no_index){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
5
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
6 int stream_id=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 //---- AVI header:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 avi_header.idx_size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 int id=stream_read_dword_le(demuxer->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 int chunksize,size2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 static int last_fccType=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 //
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 if(stream_eof(demuxer->stream)) break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 //
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 if(id==mmioFOURCC('L','I','S','T')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 int len=stream_read_dword_le(demuxer->stream)-4; // list size
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 id=stream_read_dword_le(demuxer->stream); // list type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 if(verbose>=2) printf("LIST %.4s len=%d\n",&id,len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 if(id==listtypeAVIMOVIE){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 // found MOVI header
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 avi_header.movi_start=stream_tell(demuxer->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 avi_header.movi_end=avi_header.movi_start+len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 if(verbose>=1) printf("Found movie at 0x%X - 0x%X\n",avi_header.movi_start,avi_header.movi_end);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 len=(len+1)&(~1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
27 stream_skip(demuxer->stream,len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 size2=stream_read_dword_le(demuxer->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 if(verbose>=2) printf("CHUNK %.4s len=%d\n",&id,size2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 chunksize=(size2+1)&(~1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 switch(id){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 case ckidAVIMAINHDR: // read 'avih'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 stream_read(demuxer->stream,(char*) &avi_header.avih,MIN(size2,sizeof(avi_header.avih)));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 chunksize-=MIN(size2,sizeof(avi_header.avih));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 if(verbose) print_avih(&avi_header.avih);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 case ckidSTREAMHEADER: { // read 'strh'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 AVIStreamHeader h;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 stream_read(demuxer->stream,(char*) &h,MIN(size2,sizeof(h)));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 chunksize-=MIN(size2,sizeof(h));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 if(h.fccType==streamtypeVIDEO) memcpy(&avi_header.video,&h,sizeof(h));else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45 if(h.fccType==streamtypeAUDIO) memcpy(&avi_header.audio,&h,sizeof(h));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 last_fccType=h.fccType;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 if(verbose>=1) print_strh(&h);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 ++stream_id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 break; }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 case ckidSTREAMFORMAT: { // read 'strf'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 if(last_fccType==streamtypeVIDEO){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52 stream_read(demuxer->stream,(char*) &avi_header.bih,MIN(size2,sizeof(avi_header.bih)));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
53 chunksize-=MIN(size2,sizeof(avi_header.bih));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 // init_video_codec();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 // init_video_out();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 if(demuxer->video->id==-1) demuxer->video->id=stream_id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 if(last_fccType==streamtypeAUDIO){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 int z=(chunksize<64)?chunksize:64;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 if(verbose>=2) printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 stream_read(demuxer->stream,(char*) &avi_header.wf_ext,z);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 chunksize-=z;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63 if(verbose>=1) print_wave_header((WAVEFORMATEX*)&avi_header.wf_ext);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 // init_audio_codec();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 // init_audio_out();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 if(demuxer->audio->id==-1) demuxer->audio->id=stream_id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
70 case ckidAVINEWINDEX: if(!no_index){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
71 avi_header.idx_size=size2>>4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 if(verbose>=1) printf("Reading INDEX block, %d chunks for %d frames\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73 avi_header.idx_size,avi_header.avih.dwTotalFrames);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 avi_header.idx=malloc(avi_header.idx_size<<4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 stream_read(demuxer->stream,(char*)avi_header.idx,avi_header.idx_size<<4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 chunksize-=avi_header.idx_size<<4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 if(verbose>=2) print_index();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 if(chunksize>0) stream_skip(demuxer->stream,chunksize); else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 if(chunksize<0) printf("WARNING!!! chunksize=%d (id=%.4s)\n",chunksize,&id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 #undef MIN
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89