Mercurial > mplayer.hg
annotate aviheader.c @ 445:fe56e5a1dc05
last fix, hopefully ;(
author | gabucino |
---|---|
date | Sun, 15 Apr 2001 19:26:33 +0000 |
parents | 0969d4ef0a34 |
children | 747759a4a28f |
rev | line source |
---|---|
1 | 1 |
2 #define MIN(a,b) (((a)<(b))?(a):(b)) | |
3 | |
4 void read_avi_header(int no_index){ | |
426 | 5 sh_audio_t *sh_audio=NULL; |
6 sh_video_t *sh_video=NULL; | |
1 | 7 int stream_id=-1; |
8 | |
9 //---- AVI header: | |
10 avi_header.idx_size=0; | |
11 while(1){ | |
12 int id=stream_read_dword_le(demuxer->stream); | |
13 int chunksize,size2; | |
14 static int last_fccType=0; | |
15 // | |
16 if(stream_eof(demuxer->stream)) break; | |
17 // | |
18 if(id==mmioFOURCC('L','I','S','T')){ | |
19 int len=stream_read_dword_le(demuxer->stream)-4; // list size | |
20 id=stream_read_dword_le(demuxer->stream); // list type | |
21 if(verbose>=2) printf("LIST %.4s len=%d\n",&id,len); | |
22 if(id==listtypeAVIMOVIE){ | |
23 // found MOVI header | |
24 avi_header.movi_start=stream_tell(demuxer->stream); | |
25 avi_header.movi_end=avi_header.movi_start+len; | |
26 if(verbose>=1) printf("Found movie at 0x%X - 0x%X\n",avi_header.movi_start,avi_header.movi_end); | |
27 len=(len+1)&(~1); | |
28 stream_skip(demuxer->stream,len); | |
29 } | |
30 continue; | |
31 } | |
32 size2=stream_read_dword_le(demuxer->stream); | |
33 if(verbose>=2) printf("CHUNK %.4s len=%d\n",&id,size2); | |
34 chunksize=(size2+1)&(~1); | |
35 switch(id){ | |
36 case ckidAVIMAINHDR: // read 'avih' | |
37 stream_read(demuxer->stream,(char*) &avi_header.avih,MIN(size2,sizeof(avi_header.avih))); | |
38 chunksize-=MIN(size2,sizeof(avi_header.avih)); | |
39 if(verbose) print_avih(&avi_header.avih); | |
40 break; | |
41 case ckidSTREAMHEADER: { // read 'strh' | |
42 AVIStreamHeader h; | |
43 stream_read(demuxer->stream,(char*) &h,MIN(size2,sizeof(h))); | |
44 chunksize-=MIN(size2,sizeof(h)); | |
426 | 45 ++stream_id; |
46 if(h.fccType==streamtypeVIDEO){ | |
47 sh_video=new_sh_video(stream_id); | |
48 memcpy(&sh_video->video,&h,sizeof(h)); | |
49 } else | |
50 if(h.fccType==streamtypeAUDIO){ | |
51 sh_audio=new_sh_audio(stream_id); | |
52 memcpy(&sh_audio->audio,&h,sizeof(h)); | |
53 } | |
1 | 54 last_fccType=h.fccType; |
55 if(verbose>=1) print_strh(&h); | |
56 break; } | |
57 case ckidSTREAMFORMAT: { // read 'strf' | |
58 if(last_fccType==streamtypeVIDEO){ | |
433 | 59 sh_video->bih=calloc((chunksize<sizeof(BITMAPINFOHEADER))?sizeof(BITMAPINFOHEADER):chunksize,1); |
60 // sh_video->bih=malloc(chunksize); memset(sh_video->bih,0,chunksize); | |
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 | 66 // if(demuxer->video->id==-1) demuxer->video->id=stream_id; |
1 | 67 } else |
68 if(last_fccType==streamtypeAUDIO){ | |
433 | 69 sh_audio->wf=calloc((chunksize<sizeof(WAVEFORMATEX))?sizeof(WAVEFORMATEX):chunksize,1); |
70 // sh_audio->wf=malloc(chunksize); memset(sh_audio->wf,0,chunksize); | |
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 | 75 // if(demuxer->audio->id==-1) demuxer->audio->id=stream_id; |
1 | 76 } |
77 break; | |
78 } | |
79 case ckidAVINEWINDEX: if(!no_index){ | |
80 avi_header.idx_size=size2>>4; | |
81 if(verbose>=1) printf("Reading INDEX block, %d chunks for %d frames\n", | |
82 avi_header.idx_size,avi_header.avih.dwTotalFrames); | |
83 avi_header.idx=malloc(avi_header.idx_size<<4); | |
84 stream_read(demuxer->stream,(char*)avi_header.idx,avi_header.idx_size<<4); | |
85 chunksize-=avi_header.idx_size<<4; | |
86 if(verbose>=2) print_index(); | |
87 break; | |
88 } | |
89 } | |
90 if(chunksize>0) stream_skip(demuxer->stream,chunksize); else | |
91 if(chunksize<0) printf("WARNING!!! chunksize=%d (id=%.4s)\n",chunksize,&id); | |
92 | |
93 } | |
94 | |
95 } | |
96 | |
97 #undef MIN | |
98 |