iss.c
Go to the documentation of this file.
1 /*
2  * ISS (.iss) file demuxer
3  * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * Funcom ISS file demuxer
25  * @author Jaikrishnan Menon
26  * @see http://wiki.multimedia.cx/index.php?title=FunCom_ISS
27  */
28 
30 #include "avformat.h"
31 #include "internal.h"
32 #include "libavutil/avstring.h"
33 
34 #define ISS_SIG "IMA_ADPCM_Sound"
35 #define ISS_SIG_LEN 15
36 #define MAX_TOKEN_SIZE 20
37 
38 typedef struct {
42 
43 static void get_token(AVIOContext *s, char *buf, int maxlen)
44 {
45  int i = 0;
46  char c;
47 
48  while ((c = avio_r8(s))) {
49  if(c == ' ')
50  break;
51  if (i < maxlen-1)
52  buf[i++] = c;
53  }
54 
55  if(!c)
56  avio_r8(s);
57 
58  buf[i] = 0; /* Ensure null terminated, but may be truncated */
59 }
60 
61 static int iss_probe(AVProbeData *p)
62 {
63  if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
64  return 0;
65 
66  return AVPROBE_SCORE_MAX;
67 }
68 
70 {
71  IssDemuxContext *iss = s->priv_data;
72  AVIOContext *pb = s->pb;
73  AVStream *st;
74  char token[MAX_TOKEN_SIZE];
75  int stereo, rate_divisor;
76 
77  get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
78  get_token(pb, token, sizeof(token)); //packet size
79  sscanf(token, "%d", &iss->packet_size);
80  get_token(pb, token, sizeof(token)); //File ID
81  get_token(pb, token, sizeof(token)); //out size
82  get_token(pb, token, sizeof(token)); //stereo
83  sscanf(token, "%d", &stereo);
84  get_token(pb, token, sizeof(token)); //Unknown1
85  get_token(pb, token, sizeof(token)); //RateDivisor
86  sscanf(token, "%d", &rate_divisor);
87  get_token(pb, token, sizeof(token)); //Unknown2
88  get_token(pb, token, sizeof(token)); //Version ID
89  get_token(pb, token, sizeof(token)); //Size
90 
91  if (iss->packet_size <= 0) {
92  av_log(s, AV_LOG_ERROR, "packet_size %d is invalid\n", iss->packet_size);
93  return AVERROR_INVALIDDATA;
94  }
95 
96  iss->sample_start_pos = avio_tell(pb);
97 
98  st = avformat_new_stream(s, NULL);
99  if (!st)
100  return AVERROR(ENOMEM);
103  if (stereo) {
104  st->codec->channels = 2;
106  } else {
107  st->codec->channels = 1;
109  }
110  st->codec->sample_rate = 44100;
111  if(rate_divisor > 0)
112  st->codec->sample_rate /= rate_divisor;
113  st->codec->bits_per_coded_sample = 4;
114  st->codec->bit_rate = st->codec->channels * st->codec->sample_rate
116  st->codec->block_align = iss->packet_size;
117  avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);
118 
119  return 0;
120 }
121 
123 {
124  IssDemuxContext *iss = s->priv_data;
125  int ret = av_get_packet(s->pb, pkt, iss->packet_size);
126 
127  if(ret != iss->packet_size)
128  return AVERROR(EIO);
129 
130  pkt->stream_index = 0;
131  pkt->pts = avio_tell(s->pb) - iss->sample_start_pos;
132  if(s->streams[0]->codec->channels > 0)
133  pkt->pts /= s->streams[0]->codec->channels*2;
134  return 0;
135 }
136 
138  .name = "iss",
139  .long_name = NULL_IF_CONFIG_SMALL("Funcom ISS"),
140  .priv_data_size = sizeof(IssDemuxContext),
144 };
const char * s
Definition: avisynth_c.h:668
Bytestream IO Context.
Definition: avio.h:68
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
AVInputFormat ff_iss_demuxer
Definition: iss.c:137
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
#define AV_CH_LAYOUT_STEREO
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Format I/O context.
Definition: avformat.h:944
#define av_cold
Definition: attributes.h:78
static AVPacket pkt
Definition: demuxing.c:56
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
AVStream ** streams
Definition: avformat.h:992
static void get_token(AVIOContext *s, char *buf, int maxlen)
Definition: iss.c:43
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:248
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_cold int iss_read_header(AVFormatContext *s)
Definition: iss.c:69
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
uint64_t channel_layout
Audio channel layout.
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:469
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:662
#define MAX_TOKEN_SIZE
Definition: iss.c:36
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:336
#define ISS_SIG
Definition: iss.c:34
int bit_rate
the average bitrate
audio channel layout utility functions
static int read_probe(AVProbeData *pd)
ret
Definition: avfilter.c:821
#define ISS_SIG_LEN
Definition: iss.c:35
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:517
Stream structure.
Definition: avformat.h:643
NULL
Definition: eval.c:55
enum AVMediaType codec_type
enum AVCodecID codec_id
int sample_rate
samples per second
AVIOContext * pb
I/O context.
Definition: avformat.h:977
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
void * buf
Definition: avisynth_c.h:594
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
Definition: libcdio.c:114
synthesis window for stochastic i
int packet_size
Definition: iss.c:39
This structure contains the data a format has to probe a file.
Definition: avformat.h:334
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
static int iss_probe(AVProbeData *p)
Definition: iss.c:61
int sample_start_pos
Definition: iss.c:40
#define AVPROBE_SCORE_MAX
maximum score, half of that is used for file-extension-based detection
Definition: avformat.h:340
Main libavformat public API header.
static double c[64]
int channels
number of audio channels
void * priv_data
Format private data.
Definition: avformat.h:964
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:461
#define AV_CH_LAYOUT_MONO
static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: iss.c:122
This structure stores compressed data.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...