Mercurial > mplayer.hg
annotate libmpdemux/demux_vqf.c @ 20400:f4518826ea84
Allow lowercase letters in AVI stream id, fixes bug #277
author | reimar |
---|---|
date | Mon, 23 Oct 2006 16:46:16 +0000 |
parents | 83c3afeab35d |
children | 1767c271d710 |
rev | line source |
---|---|
14276 | 1 #include "config.h" |
2 | |
3 #include <stdlib.h> | |
4 #include <stdio.h> | |
5 #include "bswap.h" | |
6 | |
7 #include "stream.h" | |
8 #include "demuxer.h" | |
9 #include "stheader.h" | |
17012 | 10 #include "libmpcodecs/vqf.h" |
14276 | 11 |
16175 | 12 static int demux_probe_vqf(demuxer_t* demuxer) |
14276 | 13 { |
14 char buf[KEYWORD_BYTES]; | |
15 stream_t *s; | |
16 s = demuxer->stream; | |
15818 | 17 if(stream_read(s,buf,KEYWORD_BYTES)!=KEYWORD_BYTES) |
18 return 0; | |
16175 | 19 if(memcmp(buf,"TWIN",KEYWORD_BYTES)==0) return DEMUXER_TYPE_VQF; /*version: 97012000*/ |
14276 | 20 return 0; |
21 } | |
22 | |
16175 | 23 static demuxer_t* demux_open_vqf(demuxer_t* demuxer) { |
14276 | 24 sh_audio_t* sh_audio; |
25 WAVEFORMATEX* w; | |
26 stream_t *s; | |
27 headerInfo *hi; | |
28 | |
29 s = demuxer->stream; | |
30 | |
31 sh_audio = new_sh_audio(demuxer,0); | |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
17636
diff
changeset
|
32 sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX)+sizeof(headerInfo)); |
14276 | 33 hi = (headerInfo *)&w[1]; |
34 memset(hi,0,sizeof(headerInfo)); | |
35 w->wFormatTag = 0x1; | |
36 sh_audio->format = mmioFOURCC('T','W','I','N'); /* TWinVQ */ | |
37 w->nChannels = sh_audio->channels = 2; | |
38 w->nSamplesPerSec = sh_audio->samplerate = 44100; | |
39 w->nAvgBytesPerSec = w->nSamplesPerSec*sh_audio->channels*2; | |
40 w->nBlockAlign = 0; | |
41 sh_audio->samplesize = 2; | |
42 w->wBitsPerSample = 8*sh_audio->samplesize; | |
43 w->cbSize = 0; | |
44 strcpy(hi->ID,"TWIN"); | |
45 stream_read(s,hi->ID+KEYWORD_BYTES,VERSION_BYTES); /* fourcc+version_id */ | |
46 while(1) | |
47 { | |
48 char chunk_id[4]; | |
49 unsigned chunk_size; | |
50 hi->size=chunk_size=stream_read_dword(s); /* include itself */ | |
51 stream_read(s,chunk_id,4); | |
52 if(*((uint32_t *)&chunk_id[0])==mmioFOURCC('C','O','M','M')) | |
53 { | |
54 char buf[chunk_size-8]; | |
55 unsigned i,subchunk_size; | |
56 if(stream_read(s,buf,chunk_size-8)!=chunk_size-8) return NULL; | |
57 i=0; | |
58 subchunk_size=be2me_32(*((uint32_t *)&buf[0])); | |
59 hi->channelMode=be2me_32(*((uint32_t *)&buf[4])); | |
60 w->nChannels=sh_audio->channels=hi->channelMode+1; /*0-mono;1-stereo*/ | |
61 hi->bitRate=be2me_32(*((uint32_t *)&buf[8])); | |
62 sh_audio->i_bps=hi->bitRate*1000/8; /* bitrate kbit/s */ | |
63 w->nAvgBytesPerSec = sh_audio->i_bps; | |
64 hi->samplingRate=be2me_32(*((uint32_t *)&buf[12])); | |
65 switch(hi->samplingRate){ | |
66 case 44: | |
67 w->nSamplesPerSec=44100; | |
68 break; | |
69 case 22: | |
70 w->nSamplesPerSec=22050; | |
71 break; | |
72 case 11: | |
73 w->nSamplesPerSec=11025; | |
74 break; | |
75 default: | |
76 w->nSamplesPerSec=hi->samplingRate*1000; | |
77 break; | |
78 } | |
79 sh_audio->samplerate=w->nSamplesPerSec; | |
80 hi->securityLevel=be2me_32(*((uint32_t *)&buf[16])); | |
81 w->nBlockAlign = 0; | |
82 sh_audio->samplesize = 4; | |
83 w->wBitsPerSample = 8*sh_audio->samplesize; | |
84 w->cbSize = 0; | |
85 i+=subchunk_size+4; | |
86 while(i<chunk_size-8) | |
87 { | |
88 unsigned slen,sid; | |
89 char sdata[chunk_size]; | |
90 sid=*((uint32_t *)&buf[i]); i+=4; | |
91 slen=be2me_32(*((uint32_t *)&buf[i])); i+=4; | |
92 if(sid==mmioFOURCC('D','S','I','Z')) | |
93 { | |
94 hi->Dsiz=be2me_32(*((uint32_t *)&buf[i])); | |
95 continue; /* describes the same info as size of DATA chunk */ | |
96 } | |
97 memcpy(sdata,&buf[i],slen); sdata[slen]=0; i+=slen; | |
98 if(sid==mmioFOURCC('N','A','M','E')) | |
99 { | |
100 memcpy(hi->Name,sdata,min(BUFSIZ,slen)); | |
101 demux_info_add(demuxer,"Title",sdata); | |
102 } | |
103 else | |
104 if(sid==mmioFOURCC('A','U','T','H')) | |
105 { | |
106 memcpy(hi->Auth,sdata,min(BUFSIZ,slen)); | |
107 demux_info_add(demuxer,"Author",sdata); | |
108 } | |
109 else | |
110 if(sid==mmioFOURCC('C','O','M','T')) | |
111 { | |
112 memcpy(hi->Comt,sdata,min(BUFSIZ,slen)); | |
113 demux_info_add(demuxer,"Comment",sdata); | |
114 } | |
115 else | |
116 if(sid==mmioFOURCC('(','c',')',' ')) | |
117 { | |
118 memcpy(hi->Cpyr,sdata,min(BUFSIZ,slen)); | |
119 demux_info_add(demuxer,"Copyright",sdata); | |
120 } | |
121 else | |
122 if(sid==mmioFOURCC('F','I','L','E')) | |
123 { | |
124 memcpy(hi->File,sdata,min(BUFSIZ,slen)); | |
125 } | |
126 else | |
127 if(sid==mmioFOURCC('A','L','B','M')) demux_info_add(demuxer,"Album",sdata); | |
128 else | |
129 if(sid==mmioFOURCC('Y','E','A','R')) demux_info_add(demuxer,"Date",sdata); | |
130 else | |
131 if(sid==mmioFOURCC('T','R','A','C')) demux_info_add(demuxer,"Track",sdata); | |
132 else | |
133 if(sid==mmioFOURCC('E','N','C','D')) demux_info_add(demuxer,"Encoder",sdata); | |
134 else | |
135 mp_msg(MSGT_DEMUX, MSGL_V, "Unhandled subchunk '%c%c%c%c'='%s'\n",((char *)&sid)[0],((char *)&sid)[1],((char *)&sid)[2],((char *)&sid)[3],sdata); | |
136 /* other stuff is unrecognized due untranslatable japan's idiomatics */ | |
137 } | |
138 } | |
139 else | |
140 if(*((uint32_t *)&chunk_id[0])==mmioFOURCC('D','A','T','A')) | |
141 { | |
142 demuxer->movi_start=stream_tell(s); | |
143 demuxer->movi_end=demuxer->movi_start+chunk_size-8; | |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16175
diff
changeset
|
144 mp_msg(MSGT_DEMUX, MSGL_V, "Found data at %"PRIX64" size %"PRIu64"\n",demuxer->movi_start,demuxer->movi_end); |
14276 | 145 /* Done! play it */ |
146 break; | |
147 } | |
148 else | |
149 { | |
150 mp_msg(MSGT_DEMUX, MSGL_V, "Unhandled chunk '%c%c%c%c' %u bytes\n",((char *)&chunk_id)[0],((char *)&chunk_id)[1],((char *)&chunk_id)[2],((char *)&chunk_id)[3],chunk_size); | |
151 stream_skip(s,chunk_size-8); /*unknown chunk type */ | |
152 } | |
153 } | |
154 | |
155 demuxer->audio->sh = sh_audio; | |
156 sh_audio->ds = demuxer->audio; | |
157 stream_seek(s,demuxer->movi_start); | |
158 demuxer->seekable=0; | |
159 return demuxer; | |
160 } | |
161 | |
16175 | 162 static int demux_vqf_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) { |
14276 | 163 sh_audio_t* sh_audio = demuxer->audio->sh; |
164 int l = sh_audio->wf->nAvgBytesPerSec; | |
165 off_t spos = stream_tell(demuxer->stream); | |
166 demux_packet_t* dp; | |
167 | |
168 if(stream_eof(demuxer->stream)) | |
169 return 0; | |
170 | |
171 dp = new_demux_packet(l); | |
172 ds->pts = spos / (float)(sh_audio->wf->nAvgBytesPerSec); | |
173 ds->pos = spos; | |
174 | |
175 l=stream_read(demuxer->stream,dp->buffer,l); | |
176 resize_demux_packet(dp,l); | |
177 ds_add_packet(ds,dp); | |
178 | |
179 return 1; | |
180 } | |
181 | |
17636 | 182 static void demux_seek_vqf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){ |
14276 | 183 #if 0 |
184 stream_t* s = demuxer->stream; | |
185 sh_audio_t* sh_audio = demuxer->audio->sh; | |
186 off_t base,pos; | |
187 | |
188 base = (flags & 1) ? demuxer->movi_start : stream_tell(s); | |
189 if(flags & 2) | |
190 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs); | |
191 else | |
192 pos = base + (rel_seek_secs*sh_audio->i_bps); | |
193 | |
194 pos -= (pos % (sh_audio->channels * sh_audio->samplesize) ); | |
195 stream_seek(s,pos); | |
196 #endif | |
197 } | |
198 | |
16175 | 199 static void demux_close_vqf(demuxer_t* demuxer) {} |
200 | |
201 | |
202 demuxer_desc_t demuxer_desc_vqf = { | |
203 "TwinVQ demuxer", | |
204 "vqf", | |
205 "VQF", | |
206 "Nick Kurshev", | |
207 "ported frm MPlayerXP", | |
208 DEMUXER_TYPE_VQF, | |
209 1, // safe autodetect | |
210 demux_probe_vqf, | |
211 demux_vqf_fill_buffer, | |
212 demux_open_vqf, | |
213 demux_close_vqf, | |
214 demux_seek_vqf, | |
215 NULL | |
216 }; |