annotate aviheader.c @ 399:33115689181a

some more fields in sh_video_t
author arpi_esp
date Sat, 14 Apr 2001 03:12:48 +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
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));
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
44 if(h.fccType==streamtypeVIDEO) memcpy(&sh_video_i.video,&h,sizeof(h));else
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
45 if(h.fccType==streamtypeAUDIO) memcpy(&sh_audio_i.audio,&h,sizeof(h));
1
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){
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
52 sh_video_t *sh_video=&sh_video_i; // FIXME!
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
53 stream_read(demuxer->stream,(char*) &sh_video->bih,MIN(size2,sizeof(sh_video->bih)));
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
54 chunksize-=MIN(size2,sizeof(sh_video->bih));
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
55 sh_video->fps=(float)sh_video->video.dwRate/(float)sh_video->video.dwScale;
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
56 sh_video->frametime=(float)sh_video->video.dwScale/(float)sh_video->video.dwRate;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57 if(demuxer->video->id==-1) demuxer->video->id=stream_id;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 if(last_fccType==streamtypeAUDIO){
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
60 sh_audio_t *sh_audio=&sh_audio_i; // FIXME!
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 int z=(chunksize<64)?chunksize:64;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 if(verbose>=2) printf("found 'wf', %d bytes of %d\n",chunksize,sizeof(WAVEFORMATEX));
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
63 stream_read(demuxer->stream,(char*) &sh_audio->wf,z);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 chunksize-=z;
291
da98e96499bb sh_audio/sh_video added, general codec cleanup
arpi_esp
parents: 1
diff changeset
65 if(verbose>=1) print_wave_header(&sh_audio->wf);
1
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