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