2009-01-17 21:08:43 +01:00
|
|
|
/*
|
|
|
|
* ISS (.iss) file demuxer
|
|
|
|
* Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2009-01-17 21:08:43 +01:00
|
|
|
* Funcom ISS file demuxer
|
|
|
|
* @author Jaikrishnan Menon
|
2011-07-14 03:56:07 +02:00
|
|
|
* @see http://wiki.multimedia.cx/index.php?title=FunCom_ISS
|
2009-01-17 21:08:43 +01:00
|
|
|
*/
|
|
|
|
|
2012-04-07 22:45:48 +02:00
|
|
|
#include "libavutil/channel_layout.h"
|
2009-01-17 21:08:43 +01:00
|
|
|
#include "avformat.h"
|
2011-11-29 19:28:15 +01:00
|
|
|
#include "internal.h"
|
2009-01-17 21:08:43 +01:00
|
|
|
#include "libavutil/avstring.h"
|
|
|
|
|
|
|
|
#define ISS_SIG "IMA_ADPCM_Sound"
|
|
|
|
#define ISS_SIG_LEN 15
|
|
|
|
#define MAX_TOKEN_SIZE 20
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int packet_size;
|
|
|
|
int sample_start_pos;
|
|
|
|
} IssDemuxContext;
|
|
|
|
|
2011-02-20 11:04:12 +01:00
|
|
|
static void get_token(AVIOContext *s, char *buf, int maxlen)
|
2009-01-17 21:08:43 +01:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
char c;
|
|
|
|
|
2011-02-21 16:43:01 +01:00
|
|
|
while ((c = avio_r8(s))) {
|
2009-01-17 21:08:43 +01:00
|
|
|
if(c == ' ')
|
|
|
|
break;
|
|
|
|
if (i < maxlen-1)
|
|
|
|
buf[i++] = c;
|
|
|
|
}
|
|
|
|
|
2009-01-24 09:06:43 +01:00
|
|
|
if(!c)
|
2011-02-21 16:43:01 +01:00
|
|
|
avio_r8(s);
|
2009-01-24 09:06:43 +01:00
|
|
|
|
2009-01-17 21:08:43 +01:00
|
|
|
buf[i] = 0; /* Ensure null terminated, but may be truncated */
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iss_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
}
|
|
|
|
|
2012-01-12 13:20:36 +01:00
|
|
|
static av_cold int iss_read_header(AVFormatContext *s)
|
2009-01-17 21:08:43 +01:00
|
|
|
{
|
|
|
|
IssDemuxContext *iss = s->priv_data;
|
2011-02-20 11:04:12 +01:00
|
|
|
AVIOContext *pb = s->pb;
|
2009-01-17 21:08:43 +01:00
|
|
|
AVStream *st;
|
|
|
|
char token[MAX_TOKEN_SIZE];
|
|
|
|
int stereo, rate_divisor;
|
|
|
|
|
|
|
|
get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
|
|
|
|
get_token(pb, token, sizeof(token)); //packet size
|
|
|
|
sscanf(token, "%d", &iss->packet_size);
|
|
|
|
get_token(pb, token, sizeof(token)); //File ID
|
|
|
|
get_token(pb, token, sizeof(token)); //out size
|
|
|
|
get_token(pb, token, sizeof(token)); //stereo
|
|
|
|
sscanf(token, "%d", &stereo);
|
|
|
|
get_token(pb, token, sizeof(token)); //Unknown1
|
|
|
|
get_token(pb, token, sizeof(token)); //RateDivisor
|
|
|
|
sscanf(token, "%d", &rate_divisor);
|
|
|
|
get_token(pb, token, sizeof(token)); //Unknown2
|
|
|
|
get_token(pb, token, sizeof(token)); //Version ID
|
|
|
|
get_token(pb, token, sizeof(token)); //Size
|
|
|
|
|
2011-12-29 05:05:52 +01:00
|
|
|
if (iss->packet_size <= 0) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "packet_size %d is invalid\n", iss->packet_size);
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2011-03-03 20:11:45 +01:00
|
|
|
iss->sample_start_pos = avio_tell(pb);
|
2009-01-17 21:08:43 +01:00
|
|
|
|
2011-06-18 11:43:24 +02:00
|
|
|
st = avformat_new_stream(s, NULL);
|
2009-01-17 21:08:43 +01:00
|
|
|
if (!st)
|
|
|
|
return AVERROR(ENOMEM);
|
2010-03-31 01:30:55 +02:00
|
|
|
st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
|
2012-08-05 11:11:04 +02:00
|
|
|
st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS;
|
2012-04-07 22:45:48 +02:00
|
|
|
if (stereo) {
|
|
|
|
st->codec->channels = 2;
|
|
|
|
st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
|
|
|
|
} else {
|
|
|
|
st->codec->channels = 1;
|
|
|
|
st->codec->channel_layout = AV_CH_LAYOUT_MONO;
|
|
|
|
}
|
2009-01-17 21:08:43 +01:00
|
|
|
st->codec->sample_rate = 44100;
|
|
|
|
if(rate_divisor > 0)
|
|
|
|
st->codec->sample_rate /= rate_divisor;
|
|
|
|
st->codec->bits_per_coded_sample = 4;
|
|
|
|
st->codec->bit_rate = st->codec->channels * st->codec->sample_rate
|
|
|
|
* st->codec->bits_per_coded_sample;
|
|
|
|
st->codec->block_align = iss->packet_size;
|
2011-11-29 19:28:15 +01:00
|
|
|
avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);
|
2009-01-17 21:08:43 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
|
|
|
IssDemuxContext *iss = s->priv_data;
|
|
|
|
int ret = av_get_packet(s->pb, pkt, iss->packet_size);
|
|
|
|
|
2009-01-24 09:20:42 +01:00
|
|
|
if(ret != iss->packet_size)
|
|
|
|
return AVERROR(EIO);
|
2009-01-17 21:08:43 +01:00
|
|
|
|
|
|
|
pkt->stream_index = 0;
|
2011-03-03 20:11:45 +01:00
|
|
|
pkt->pts = avio_tell(s->pb) - iss->sample_start_pos;
|
2009-01-17 21:08:43 +01:00
|
|
|
if(s->streams[0]->codec->channels > 0)
|
|
|
|
pkt->pts /= s->streams[0]->codec->channels*2;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-25 23:03:28 +01:00
|
|
|
AVInputFormat ff_iss_demuxer = {
|
2012-05-19 18:13:17 +02:00
|
|
|
.name = "iss",
|
2012-07-24 23:51:41 +02:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Funcom ISS"),
|
2011-07-16 22:18:12 +02:00
|
|
|
.priv_data_size = sizeof(IssDemuxContext),
|
|
|
|
.read_probe = iss_probe,
|
|
|
|
.read_header = iss_read_header,
|
|
|
|
.read_packet = iss_read_packet,
|
2009-01-17 21:08:43 +01:00
|
|
|
};
|