annotate aviheader.c @ 445:fe56e5a1dc05

last fix, hopefully ;(
author gabucino
date Sun, 15 Apr 2001 19:26:33 +0000
parents 0969d4ef0a34
children 747759a4a28f
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){
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
5 sh_audio_t *sh_audio=NULL;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
6 sh_video_t *sh_video=NULL;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
7 int stream_id=-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 //---- AVI header:
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
10 avi_header.idx_size=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 while(1){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 int id=stream_read_dword_le(demuxer->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
13 int chunksize,size2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
14 static int last_fccType=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
15 //
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 if(stream_eof(demuxer->stream)) break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17 //
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
18 if(id==mmioFOURCC('L','I','S','T')){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
19 int len=stream_read_dword_le(demuxer->stream)-4; // list size
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
20 id=stream_read_dword_le(demuxer->stream); // list type
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
21 if(verbose>=2) printf("LIST %.4s len=%d\n",&id,len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
22 if(id==listtypeAVIMOVIE){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
23 // found MOVI header
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
24 avi_header.movi_start=stream_tell(demuxer->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
25 avi_header.movi_end=avi_header.movi_start+len;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
26 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
27 len=(len+1)&(~1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 stream_skip(demuxer->stream,len);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 continue;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 size2=stream_read_dword_le(demuxer->stream);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
33 if(verbose>=2) printf("CHUNK %.4s len=%d\n",&id,size2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34 chunksize=(size2+1)&(~1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
35 switch(id){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
36 case ckidAVIMAINHDR: // read 'avih'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 stream_read(demuxer->stream,(char*) &avi_header.avih,MIN(size2,sizeof(avi_header.avih)));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
38 chunksize-=MIN(size2,sizeof(avi_header.avih));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
39 if(verbose) print_avih(&avi_header.avih);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
41 case ckidSTREAMHEADER: { // read 'strh'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 AVIStreamHeader h;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 stream_read(demuxer->stream,(char*) &h,MIN(size2,sizeof(h)));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 chunksize-=MIN(size2,sizeof(h));
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
45 ++stream_id;
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
46 if(h.fccType==streamtypeVIDEO){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
47 sh_video=new_sh_video(stream_id);
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
48 memcpy(&sh_video->video,&h,sizeof(h));
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
49 } else
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
50 if(h.fccType==streamtypeAUDIO){
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
51 sh_audio=new_sh_audio(stream_id);
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
52 memcpy(&sh_audio->audio,&h,sizeof(h));
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
53 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
54 last_fccType=h.fccType;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55 if(verbose>=1) print_strh(&h);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
56 break; }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 case ckidSTREAMFORMAT: { // read 'strf'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 if(last_fccType==streamtypeVIDEO){
433
0969d4ef0a34 malloc->calloc at wf/bih allocation
arpi_esp
parents: 432
diff changeset
59 sh_video->bih=calloc((chunksize<sizeof(BITMAPINFOHEADER))?sizeof(BITMAPINFOHEADER):chunksize,1);
0969d4ef0a34 malloc->calloc at wf/bih allocation
arpi_esp
parents: 432
diff changeset
60 // sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize);
0969d4ef0a34 malloc->calloc at wf/bih allocation
arpi_esp
parents: 432
diff changeset
61 if(verbose>=1) printf("found 'bih', %d bytes of %d\n",chunksize,sizeof(BITMAPINFOHEADER));
432
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 426
diff changeset
62 stream_read(demuxer->stream,(char*) sh_video->bih,chunksize);
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 426
diff changeset
63 chunksize=0;
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 426
diff changeset
64 // sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 426
diff changeset
65 // sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
66 // if(demuxer->video->id==-1) demuxer->video->id=stream_id;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68 if(last_fccType==streamtypeAUDIO){
433
0969d4ef0a34 malloc->calloc at wf/bih allocation
arpi_esp
parents: 432
diff changeset
69 sh_audio->wf=calloc((chunksize<sizeof(WAVEFORMATEX))?sizeof(WAVEFORMATEX):chunksize,1);
0969d4ef0a34 malloc->calloc at wf/bih allocation
arpi_esp
parents: 432
diff changeset
70 // sh_audio->wf=malloc(chunksize); memset(sh_audio->wf,0,chunksize);
0969d4ef0a34 malloc->calloc at wf/bih allocation
arpi_esp
parents: 432
diff changeset
71 if(verbose>=1) printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX));
432
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 426
diff changeset
72 stream_read(demuxer->stream,(char*) sh_audio->wf,chunksize);
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 426
diff changeset
73 chunksize=0;
5251b0c57e39 sh_audio->wf and sh_video->bih changed to dynamic (thanx to Jens Hoffmann)
arpi_esp
parents: 426
diff changeset
74 if(verbose>=1) print_wave_header(sh_audio->wf);
426
26e513f392b2 new stream selection code
arpi_esp
parents: 291
diff changeset
75 // if(demuxer->audio->id==-1) demuxer->audio->id=stream_id;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
76 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
79 case ckidAVINEWINDEX: if(!no_index){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
80 avi_header.idx_size=size2>>4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
81 if(verbose>=1) printf("Reading INDEX block, %d chunks for %d frames\n",
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 avi_header.idx_size,avi_header.avih.dwTotalFrames);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 avi_header.idx=malloc(avi_header.idx_size<<4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84 stream_read(demuxer->stream,(char*)avi_header.idx,avi_header.idx_size<<4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 chunksize-=avi_header.idx_size<<4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 if(verbose>=2) print_index();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 break;
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 if(chunksize>0) stream_skip(demuxer->stream,chunksize); else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
91 if(chunksize<0) printf("WARNING!!! chunksize=%d (id=%.4s)\n",chunksize,&id);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
96
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 #undef MIN
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98