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"
|
|
10 #include "../libmpcodecs/vqf.h"
|
|
11
|
|
12 extern void resync_audio_stream(sh_audio_t *sh_audio);
|
|
13
|
|
14 int demux_probe_vqf(demuxer_t* demuxer)
|
|
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;
|
14276
|
21 if(memcmp(buf,"TWIN",KEYWORD_BYTES)==0) return 1; /*version: 97012000*/
|
|
22 return 0;
|
|
23 }
|
|
24
|
|
25 demuxer_t* demux_open_vqf(demuxer_t* demuxer) {
|
|
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);
|
|
34 sh_audio->wf = w = (WAVEFORMATEX*)malloc(sizeof(WAVEFORMATEX)+sizeof(headerInfo));
|
|
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);
|
|
54 if(*((uint32_t *)&chunk_id[0])==mmioFOURCC('C','O','M','M'))
|
|
55 {
|
|
56 char buf[chunk_size-8];
|
|
57 unsigned i,subchunk_size;
|
|
58 if(stream_read(s,buf,chunk_size-8)!=chunk_size-8) return NULL;
|
|
59 i=0;
|
|
60 subchunk_size=be2me_32(*((uint32_t *)&buf[0]));
|
|
61 hi->channelMode=be2me_32(*((uint32_t *)&buf[4]));
|
|
62 w->nChannels=sh_audio->channels=hi->channelMode+1; /*0-mono;1-stereo*/
|
|
63 hi->bitRate=be2me_32(*((uint32_t *)&buf[8]));
|
|
64 sh_audio->i_bps=hi->bitRate*1000/8; /* bitrate kbit/s */
|
|
65 w->nAvgBytesPerSec = sh_audio->i_bps;
|
|
66 hi->samplingRate=be2me_32(*((uint32_t *)&buf[12]));
|
|
67 switch(hi->samplingRate){
|
|
68 case 44:
|
|
69 w->nSamplesPerSec=44100;
|
|
70 break;
|
|
71 case 22:
|
|
72 w->nSamplesPerSec=22050;
|
|
73 break;
|
|
74 case 11:
|
|
75 w->nSamplesPerSec=11025;
|
|
76 break;
|
|
77 default:
|
|
78 w->nSamplesPerSec=hi->samplingRate*1000;
|
|
79 break;
|
|
80 }
|
|
81 sh_audio->samplerate=w->nSamplesPerSec;
|
|
82 hi->securityLevel=be2me_32(*((uint32_t *)&buf[16]));
|
|
83 w->nBlockAlign = 0;
|
|
84 sh_audio->samplesize = 4;
|
|
85 w->wBitsPerSample = 8*sh_audio->samplesize;
|
|
86 w->cbSize = 0;
|
|
87 i+=subchunk_size+4;
|
|
88 while(i<chunk_size-8)
|
|
89 {
|
|
90 unsigned slen,sid;
|
|
91 char sdata[chunk_size];
|
|
92 sid=*((uint32_t *)&buf[i]); i+=4;
|
|
93 slen=be2me_32(*((uint32_t *)&buf[i])); i+=4;
|
|
94 if(sid==mmioFOURCC('D','S','I','Z'))
|
|
95 {
|
|
96 hi->Dsiz=be2me_32(*((uint32_t *)&buf[i]));
|
|
97 continue; /* describes the same info as size of DATA chunk */
|
|
98 }
|
|
99 memcpy(sdata,&buf[i],slen); sdata[slen]=0; i+=slen;
|
|
100 if(sid==mmioFOURCC('N','A','M','E'))
|
|
101 {
|
|
102 memcpy(hi->Name,sdata,min(BUFSIZ,slen));
|
|
103 demux_info_add(demuxer,"Title",sdata);
|
|
104 }
|
|
105 else
|
|
106 if(sid==mmioFOURCC('A','U','T','H'))
|
|
107 {
|
|
108 memcpy(hi->Auth,sdata,min(BUFSIZ,slen));
|
|
109 demux_info_add(demuxer,"Author",sdata);
|
|
110 }
|
|
111 else
|
|
112 if(sid==mmioFOURCC('C','O','M','T'))
|
|
113 {
|
|
114 memcpy(hi->Comt,sdata,min(BUFSIZ,slen));
|
|
115 demux_info_add(demuxer,"Comment",sdata);
|
|
116 }
|
|
117 else
|
|
118 if(sid==mmioFOURCC('(','c',')',' '))
|
|
119 {
|
|
120 memcpy(hi->Cpyr,sdata,min(BUFSIZ,slen));
|
|
121 demux_info_add(demuxer,"Copyright",sdata);
|
|
122 }
|
|
123 else
|
|
124 if(sid==mmioFOURCC('F','I','L','E'))
|
|
125 {
|
|
126 memcpy(hi->File,sdata,min(BUFSIZ,slen));
|
|
127 }
|
|
128 else
|
|
129 if(sid==mmioFOURCC('A','L','B','M')) demux_info_add(demuxer,"Album",sdata);
|
|
130 else
|
|
131 if(sid==mmioFOURCC('Y','E','A','R')) demux_info_add(demuxer,"Date",sdata);
|
|
132 else
|
|
133 if(sid==mmioFOURCC('T','R','A','C')) demux_info_add(demuxer,"Track",sdata);
|
|
134 else
|
|
135 if(sid==mmioFOURCC('E','N','C','D')) demux_info_add(demuxer,"Encoder",sdata);
|
|
136 else
|
|
137 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);
|
|
138 /* other stuff is unrecognized due untranslatable japan's idiomatics */
|
|
139 }
|
|
140 }
|
|
141 else
|
|
142 if(*((uint32_t *)&chunk_id[0])==mmioFOURCC('D','A','T','A'))
|
|
143 {
|
|
144 demuxer->movi_start=stream_tell(s);
|
|
145 demuxer->movi_end=demuxer->movi_start+chunk_size-8;
|
|
146 mp_msg(MSGT_DEMUX, MSGL_V, "Found data at %llX size %llu\n",demuxer->movi_start,demuxer->movi_end);
|
|
147 /* Done! play it */
|
|
148 break;
|
|
149 }
|
|
150 else
|
|
151 {
|
|
152 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);
|
|
153 stream_skip(s,chunk_size-8); /*unknown chunk type */
|
|
154 }
|
|
155 }
|
|
156
|
|
157 demuxer->audio->sh = sh_audio;
|
|
158 sh_audio->ds = demuxer->audio;
|
|
159 stream_seek(s,demuxer->movi_start);
|
|
160 demuxer->seekable=0;
|
|
161 return demuxer;
|
|
162 }
|
|
163
|
|
164 int demux_vqf_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) {
|
|
165 sh_audio_t* sh_audio = demuxer->audio->sh;
|
|
166 int l = sh_audio->wf->nAvgBytesPerSec;
|
|
167 off_t spos = stream_tell(demuxer->stream);
|
|
168 demux_packet_t* dp;
|
|
169
|
|
170 if(stream_eof(demuxer->stream))
|
|
171 return 0;
|
|
172
|
|
173 dp = new_demux_packet(l);
|
|
174 ds->pts = spos / (float)(sh_audio->wf->nAvgBytesPerSec);
|
|
175 ds->pos = spos;
|
|
176
|
|
177 l=stream_read(demuxer->stream,dp->buffer,l);
|
|
178 resize_demux_packet(dp,l);
|
|
179 ds_add_packet(ds,dp);
|
|
180
|
|
181 return 1;
|
|
182 }
|
|
183
|
|
184 void demux_seek_vqf(demuxer_t *demuxer,float rel_seek_secs,int flags){
|
|
185 #if 0
|
|
186 stream_t* s = demuxer->stream;
|
|
187 sh_audio_t* sh_audio = demuxer->audio->sh;
|
|
188 off_t base,pos;
|
|
189
|
|
190 base = (flags & 1) ? demuxer->movi_start : stream_tell(s);
|
|
191 if(flags & 2)
|
|
192 pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
|
|
193 else
|
|
194 pos = base + (rel_seek_secs*sh_audio->i_bps);
|
|
195
|
|
196 pos -= (pos % (sh_audio->channels * sh_audio->samplesize) );
|
|
197 stream_seek(s,pos);
|
|
198 resync_audio_stream(sh_audio);
|
|
199 #endif
|
|
200 }
|
|
201
|
|
202 void demux_close_vqf(demuxer_t* demuxer) {}
|