FFmpeg
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 "demux.h"
32 #include "internal.h"
33 #include "libavutil/avstring.h"
34 
35 #define ISS_SIG "IMA_ADPCM_Sound"
36 #define ISS_SIG_LEN 15
37 #define MAX_TOKEN_SIZE 20
38 
39 typedef struct IssDemuxContext {
43 
44 static void get_token(AVIOContext *s, char *buf, int maxlen)
45 {
46  int i = 0;
47  char c;
48 
49  while ((c = avio_r8(s))) {
50  if(c == ' ')
51  break;
52  if (i < maxlen-1)
53  buf[i++] = c;
54  }
55 
56  if(!c)
57  avio_r8(s);
58 
59  buf[i] = 0; /* Ensure null terminated, but may be truncated */
60 }
61 
62 static int iss_probe(const AVProbeData *p)
63 {
64  if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
65  return 0;
66 
67  return AVPROBE_SCORE_MAX;
68 }
69 
71 {
72  IssDemuxContext *iss = s->priv_data;
73  AVIOContext *pb = s->pb;
74  AVStream *st;
75  char token[MAX_TOKEN_SIZE];
76  int stereo, rate_divisor;
77 
78  get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
79  get_token(pb, token, sizeof(token)); //packet size
80  if (sscanf(token, "%d", &iss->packet_size) != 1) {
81  av_log(s, AV_LOG_ERROR, "Failed parsing packet size\n");
82  return AVERROR_INVALIDDATA;
83  }
84  get_token(pb, token, sizeof(token)); //File ID
85  get_token(pb, token, sizeof(token)); //out size
86  get_token(pb, token, sizeof(token)); //stereo
87  if (sscanf(token, "%d", &stereo) != 1) {
88  av_log(s, AV_LOG_ERROR, "Failed parsing stereo flag\n");
89  return AVERROR_INVALIDDATA;
90  }
91  get_token(pb, token, sizeof(token)); //Unknown1
92  get_token(pb, token, sizeof(token)); //RateDivisor
93  if (sscanf(token, "%d", &rate_divisor) != 1) {
94  av_log(s, AV_LOG_ERROR, "Failed parsing rate_divisor\n");
95  return AVERROR_INVALIDDATA;
96  }
97  get_token(pb, token, sizeof(token)); //Unknown2
98  get_token(pb, token, sizeof(token)); //Version ID
99  get_token(pb, token, sizeof(token)); //Size
100 
101  if (iss->packet_size <= 0) {
102  av_log(s, AV_LOG_ERROR, "packet_size %d is invalid\n", iss->packet_size);
103  return AVERROR_INVALIDDATA;
104  }
105 
106  iss->sample_start_pos = avio_tell(pb);
107 
108  st = avformat_new_stream(s, NULL);
109  if (!st)
110  return AVERROR(ENOMEM);
113 
114  if (stereo) {
116  } else {
118  }
119 
120  st->codecpar->sample_rate = 44100;
121  if(rate_divisor > 0)
122  st->codecpar->sample_rate /= rate_divisor;
125  st->codecpar->sample_rate *
127  st->codecpar->block_align = iss->packet_size;
128  avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate);
129 
130  return 0;
131 }
132 
134 {
135  IssDemuxContext *iss = s->priv_data;
136  int ret = av_get_packet(s->pb, pkt, iss->packet_size);
137 
138  if(ret != iss->packet_size)
139  return AVERROR(EIO);
140 
141  pkt->stream_index = 0;
142  pkt->pts = avio_tell(s->pb) - iss->sample_start_pos;
143  if (s->streams[0]->codecpar->ch_layout.nb_channels > 0)
144  pkt->pts /= s->streams[0]->codecpar->ch_layout.nb_channels * 2;
145  return 0;
146 }
147 
149  .p.name = "iss",
150  .p.long_name = NULL_IF_CONFIG_SMALL("Funcom ISS"),
151  .priv_data_size = sizeof(IssDemuxContext),
155 };
iss_read_packet
static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: iss.c:133
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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. Frame references ownership and permissions
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:379
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:313
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:463
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: avformat.c:853
ISS_SIG
#define ISS_SIG
Definition: iss.c:35
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:494
pkt
AVPacket * pkt
Definition: movenc.c:60
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_read_callback.c:42
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:553
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:453
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
iss_read_header
static av_cold int iss_read_header(AVFormatContext *s)
Definition: iss.c:70
AV_CODEC_ID_ADPCM_IMA_ISS
@ AV_CODEC_ID_ADPCM_IMA_ISS
Definition: codec_id.h:394
IssDemuxContext::packet_size
int packet_size
Definition: iss.c:40
IssDemuxContext::sample_start_pos
int sample_start_pos
Definition: iss.c:41
AVFormatContext
Format I/O context.
Definition: avformat.h:1255
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:766
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:550
NULL
#define NULL
Definition: coverity.c:32
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:451
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:180
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:184
AVIOContext
Bytestream IO Context.
Definition: avio.h:160
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:303
FFInputFormat::p
AVInputFormat p
The public AVInputFormat.
Definition: demux.h:41
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:603
get_token
static void get_token(AVIOContext *s, char *buf, int maxlen)
Definition: iss.c:44
IssDemuxContext
Definition: iss.c:39
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:517
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:191
MAX_TOKEN_SIZE
#define MAX_TOKEN_SIZE
Definition: iss.c:37
demux.h
av_get_packet
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.
Definition: utils.c:104
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:743
avformat.h
ff_iss_demuxer
const FFInputFormat ff_iss_demuxer
Definition: iss.c:148
ISS_SIG_LEN
#define ISS_SIG_LEN
Definition: iss.c:36
channel_layout.h
AVPacket::stream_index
int stream_index
Definition: packet.h:526
read_probe
static int read_probe(const AVProbeData *p)
Definition: cdg.c:30
AVCodecParameters::bits_per_coded_sample
int bits_per_coded_sample
The number of bits per sample in the codedwords.
Definition: codec_par.h:110
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:378
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:501
FFInputFormat
Definition: demux.h:37
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:97
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
iss_probe
static int iss_probe(const AVProbeData *p)
Definition: iss.c:62
avstring.h