2004-12-29 19:51:56 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2006-11-29 15:02:45 +00:00
|
|
|
#include "libavutil/common.h"
|
2008-12-13 09:53:08 +00:00
|
|
|
#include "libavutil/intreadwrite.h"
|
2006-12-07 11:58:07 +00:00
|
|
|
#include "mpbswap.h"
|
2004-12-29 19:51:56 +00:00
|
|
|
|
2007-03-15 18:36:36 +00:00
|
|
|
#include "stream/stream.h"
|
2004-12-29 19:51:56 +00:00
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "libmpcodecs/vqf.h"
|
2004-12-29 19:51:56 +00:00
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static int demux_probe_vqf(demuxer_t* demuxer)
|
2004-12-29 19:51:56 +00:00
|
|
|
{
|
|
|
|
char buf[KEYWORD_BYTES];
|
|
|
|
stream_t *s;
|
|
|
|
s = demuxer->stream;
|
2005-06-26 15:21:27 +00:00
|
|
|
if(stream_read(s,buf,KEYWORD_BYTES)!=KEYWORD_BYTES)
|
|
|
|
return 0;
|
2005-08-05 19:57:47 +00:00
|
|
|
if(memcmp(buf,"TWIN",KEYWORD_BYTES)==0) return DEMUXER_TYPE_VQF; /*version: 97012000*/
|
2004-12-29 19:51:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static demuxer_t* demux_open_vqf(demuxer_t* demuxer) {
|
2004-12-29 19:51:56 +00:00
|
|
|
sh_audio_t* sh_audio;
|
|
|
|
WAVEFORMATEX* w;
|
|
|
|
stream_t *s;
|
|
|
|
headerInfo *hi;
|
|
|
|
|
|
|
|
s = demuxer->stream;
|
|
|
|
|
|
|
|
sh_audio = new_sh_audio(demuxer,0);
|
2006-07-13 16:41:13 +00:00
|
|
|
sh_audio->wf = w = malloc(sizeof(WAVEFORMATEX)+sizeof(headerInfo));
|
2004-12-29 19:51:56 +00:00
|
|
|
hi = (headerInfo *)&w[1];
|
|
|
|
memset(hi,0,sizeof(headerInfo));
|
|
|
|
w->wFormatTag = 0x1;
|
|
|
|
sh_audio->format = mmioFOURCC('T','W','I','N'); /* TWinVQ */
|
|
|
|
w->nChannels = sh_audio->channels = 2;
|
|
|
|
w->nSamplesPerSec = sh_audio->samplerate = 44100;
|
|
|
|
w->nAvgBytesPerSec = w->nSamplesPerSec*sh_audio->channels*2;
|
|
|
|
w->nBlockAlign = 0;
|
|
|
|
sh_audio->samplesize = 2;
|
|
|
|
w->wBitsPerSample = 8*sh_audio->samplesize;
|
|
|
|
w->cbSize = 0;
|
|
|
|
strcpy(hi->ID,"TWIN");
|
|
|
|
stream_read(s,hi->ID+KEYWORD_BYTES,VERSION_BYTES); /* fourcc+version_id */
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
char chunk_id[4];
|
|
|
|
unsigned chunk_size;
|
|
|
|
hi->size=chunk_size=stream_read_dword(s); /* include itself */
|
|
|
|
stream_read(s,chunk_id,4);
|
2008-12-14 15:17:18 +00:00
|
|
|
if (chunk_size < 8) return NULL;
|
|
|
|
chunk_size -= 8;
|
2008-12-13 09:53:08 +00:00
|
|
|
if(AV_RL32(chunk_id)==mmioFOURCC('C','O','M','M'))
|
2004-12-29 19:51:56 +00:00
|
|
|
{
|
2008-12-14 15:17:18 +00:00
|
|
|
char buf[BUFSIZ];
|
2004-12-29 19:51:56 +00:00
|
|
|
unsigned i,subchunk_size;
|
2008-12-14 15:17:18 +00:00
|
|
|
if (chunk_size > sizeof(buf) || chunk_size < 20) return NULL;
|
|
|
|
if(stream_read(s,buf,chunk_size)!=chunk_size) return NULL;
|
2004-12-29 19:51:56 +00:00
|
|
|
i=0;
|
2008-12-13 09:53:08 +00:00
|
|
|
subchunk_size = AV_RB32(buf);
|
|
|
|
hi->channelMode = AV_RB32(buf + 4);
|
2004-12-29 19:51:56 +00:00
|
|
|
w->nChannels=sh_audio->channels=hi->channelMode+1; /*0-mono;1-stereo*/
|
2008-12-13 09:53:08 +00:00
|
|
|
hi->bitRate = AV_RB32(buf + 8);
|
2004-12-29 19:51:56 +00:00
|
|
|
sh_audio->i_bps=hi->bitRate*1000/8; /* bitrate kbit/s */
|
|
|
|
w->nAvgBytesPerSec = sh_audio->i_bps;
|
2008-12-13 09:53:08 +00:00
|
|
|
hi->samplingRate = AV_RB32(buf + 12);
|
2004-12-29 19:51:56 +00:00
|
|
|
switch(hi->samplingRate){
|
|
|
|
case 44:
|
|
|
|
w->nSamplesPerSec=44100;
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
w->nSamplesPerSec=22050;
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
w->nSamplesPerSec=11025;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
w->nSamplesPerSec=hi->samplingRate*1000;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
sh_audio->samplerate=w->nSamplesPerSec;
|
2008-12-13 09:53:08 +00:00
|
|
|
hi->securityLevel = AV_RB32(buf + 16);
|
2004-12-29 19:51:56 +00:00
|
|
|
w->nBlockAlign = 0;
|
|
|
|
sh_audio->samplesize = 4;
|
|
|
|
w->wBitsPerSample = 8*sh_audio->samplesize;
|
|
|
|
w->cbSize = 0;
|
2008-12-14 15:17:18 +00:00
|
|
|
if (subchunk_size > chunk_size - 4) continue;
|
2004-12-29 19:51:56 +00:00
|
|
|
i+=subchunk_size+4;
|
2008-12-14 15:17:18 +00:00
|
|
|
while(i + 8 < chunk_size)
|
2004-12-29 19:51:56 +00:00
|
|
|
{
|
|
|
|
unsigned slen,sid;
|
2008-12-14 15:17:18 +00:00
|
|
|
char sdata[BUFSIZ];
|
2008-12-13 09:53:08 +00:00
|
|
|
sid = AV_RL32(buf + i); i+=4;
|
|
|
|
slen = AV_RB32(buf + i); i+=4;
|
2008-12-14 15:17:18 +00:00
|
|
|
if (slen > sizeof(sdata) - 1 || slen > chunk_size - i) break;
|
2004-12-29 19:51:56 +00:00
|
|
|
if(sid==mmioFOURCC('D','S','I','Z'))
|
|
|
|
{
|
2008-12-13 09:53:08 +00:00
|
|
|
hi->Dsiz=AV_RB32(buf + i);
|
2004-12-29 19:51:56 +00:00
|
|
|
continue; /* describes the same info as size of DATA chunk */
|
|
|
|
}
|
|
|
|
memcpy(sdata,&buf[i],slen); sdata[slen]=0; i+=slen;
|
|
|
|
if(sid==mmioFOURCC('N','A','M','E'))
|
|
|
|
{
|
2006-12-09 12:24:11 +00:00
|
|
|
memcpy(hi->Name,sdata,FFMIN(BUFSIZ,slen));
|
2004-12-29 19:51:56 +00:00
|
|
|
demux_info_add(demuxer,"Title",sdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if(sid==mmioFOURCC('A','U','T','H'))
|
|
|
|
{
|
2006-12-09 12:24:11 +00:00
|
|
|
memcpy(hi->Auth,sdata,FFMIN(BUFSIZ,slen));
|
2004-12-29 19:51:56 +00:00
|
|
|
demux_info_add(demuxer,"Author",sdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if(sid==mmioFOURCC('C','O','M','T'))
|
|
|
|
{
|
2006-12-09 12:24:11 +00:00
|
|
|
memcpy(hi->Comt,sdata,FFMIN(BUFSIZ,slen));
|
2004-12-29 19:51:56 +00:00
|
|
|
demux_info_add(demuxer,"Comment",sdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if(sid==mmioFOURCC('(','c',')',' '))
|
|
|
|
{
|
2006-12-09 12:24:11 +00:00
|
|
|
memcpy(hi->Cpyr,sdata,FFMIN(BUFSIZ,slen));
|
2004-12-29 19:51:56 +00:00
|
|
|
demux_info_add(demuxer,"Copyright",sdata);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if(sid==mmioFOURCC('F','I','L','E'))
|
|
|
|
{
|
2006-12-09 12:24:11 +00:00
|
|
|
memcpy(hi->File,sdata,FFMIN(BUFSIZ,slen));
|
2004-12-29 19:51:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if(sid==mmioFOURCC('A','L','B','M')) demux_info_add(demuxer,"Album",sdata);
|
|
|
|
else
|
|
|
|
if(sid==mmioFOURCC('Y','E','A','R')) demux_info_add(demuxer,"Date",sdata);
|
|
|
|
else
|
|
|
|
if(sid==mmioFOURCC('T','R','A','C')) demux_info_add(demuxer,"Track",sdata);
|
|
|
|
else
|
|
|
|
if(sid==mmioFOURCC('E','N','C','D')) demux_info_add(demuxer,"Encoder",sdata);
|
|
|
|
else
|
|
|
|
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);
|
|
|
|
/* other stuff is unrecognized due untranslatable japan's idiomatics */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-12-13 09:53:08 +00:00
|
|
|
if(AV_RL32(chunk_id)==mmioFOURCC('D','A','T','A'))
|
2004-12-29 19:51:56 +00:00
|
|
|
{
|
|
|
|
demuxer->movi_start=stream_tell(s);
|
2008-12-14 15:17:18 +00:00
|
|
|
demuxer->movi_end=demuxer->movi_start+chunk_size;
|
2005-10-13 18:33:56 +00:00
|
|
|
mp_msg(MSGT_DEMUX, MSGL_V, "Found data at %"PRIX64" size %"PRIu64"\n",demuxer->movi_start,demuxer->movi_end);
|
2004-12-29 19:51:56 +00:00
|
|
|
/* Done! play it */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-13 09:44:51 +00:00
|
|
|
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);
|
2008-12-14 15:17:18 +00:00
|
|
|
stream_skip(s,chunk_size); /*unknown chunk type */
|
2004-12-29 19:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-05 14:11:48 +00:00
|
|
|
demuxer->audio->id = 0;
|
2004-12-29 19:51:56 +00:00
|
|
|
demuxer->audio->sh = sh_audio;
|
|
|
|
sh_audio->ds = demuxer->audio;
|
|
|
|
stream_seek(s,demuxer->movi_start);
|
|
|
|
demuxer->seekable=0;
|
|
|
|
return demuxer;
|
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static int demux_vqf_fill_buffer(demuxer_t* demuxer, demux_stream_t *ds) {
|
2004-12-29 19:51:56 +00:00
|
|
|
sh_audio_t* sh_audio = demuxer->audio->sh;
|
|
|
|
int l = sh_audio->wf->nAvgBytesPerSec;
|
|
|
|
off_t spos = stream_tell(demuxer->stream);
|
|
|
|
demux_packet_t* dp;
|
|
|
|
|
|
|
|
if(stream_eof(demuxer->stream))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
dp = new_demux_packet(l);
|
|
|
|
ds->pts = spos / (float)(sh_audio->wf->nAvgBytesPerSec);
|
|
|
|
ds->pos = spos;
|
|
|
|
|
|
|
|
l=stream_read(demuxer->stream,dp->buffer,l);
|
|
|
|
resize_demux_packet(dp,l);
|
|
|
|
ds_add_packet(ds,dp);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-02-17 01:57:41 +00:00
|
|
|
static void demux_seek_vqf(demuxer_t *demuxer,float rel_seek_secs,float audio_delay,int flags){
|
2004-12-29 19:51:56 +00:00
|
|
|
#if 0
|
|
|
|
stream_t* s = demuxer->stream;
|
|
|
|
sh_audio_t* sh_audio = demuxer->audio->sh;
|
|
|
|
off_t base,pos;
|
|
|
|
|
2008-01-29 15:11:38 +00:00
|
|
|
base = (flags & SEEK_ABSOLUTE) ? demuxer->movi_start : stream_tell(s);
|
|
|
|
if(flags & SEEK_FACTOR)
|
2004-12-29 19:51:56 +00:00
|
|
|
pos = base + ((demuxer->movi_end - demuxer->movi_start)*rel_seek_secs);
|
|
|
|
else
|
|
|
|
pos = base + (rel_seek_secs*sh_audio->i_bps);
|
|
|
|
|
|
|
|
pos -= (pos % (sh_audio->channels * sh_audio->samplesize) );
|
|
|
|
stream_seek(s,pos);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2005-08-05 19:57:47 +00:00
|
|
|
static void demux_close_vqf(demuxer_t* demuxer) {}
|
|
|
|
|
|
|
|
|
2008-01-13 16:00:39 +00:00
|
|
|
const demuxer_desc_t demuxer_desc_vqf = {
|
2005-08-05 19:57:47 +00:00
|
|
|
"TwinVQ demuxer",
|
|
|
|
"vqf",
|
|
|
|
"VQF",
|
|
|
|
"Nick Kurshev",
|
|
|
|
"ported frm MPlayerXP",
|
|
|
|
DEMUXER_TYPE_VQF,
|
|
|
|
1, // safe autodetect
|
|
|
|
demux_probe_vqf,
|
|
|
|
demux_vqf_fill_buffer,
|
|
|
|
demux_open_vqf,
|
|
|
|
demux_close_vqf,
|
|
|
|
demux_seek_vqf,
|
|
|
|
NULL
|
|
|
|
};
|