FFmpeg: libavformat/iss.c Source File

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 
29 #include "libavutil/channel_layout.h"
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 IssDemuxContext {
39   int packet_size;
40   int sample_start_pos;
41 } IssDemuxContext;
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 
69  static av_cold int iss_read_header(AVFormatContext *s)
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  if (sscanf(token, "%d", &iss->packet_size) != 1) {
80  av_log(s, AV_LOG_ERROR, "Failed parsing packet size\n");
81  return AVERROR_INVALIDDATA;
82  }
83  get_token(pb, token, sizeof(token)); //File ID
84  get_token(pb, token, sizeof(token)); //out size
85  get_token(pb, token, sizeof(token)); //stereo
86  if (sscanf(token, "%d", &stereo) != 1) {
87  av_log(s, AV_LOG_ERROR, "Failed parsing stereo flag\n");
88  return AVERROR_INVALIDDATA;
89  }
90  get_token(pb, token, sizeof(token)); //Unknown1
91  get_token(pb, token, sizeof(token)); //RateDivisor
92  if (sscanf(token, "%d", &rate_divisor) != 1) {
93  av_log(s, AV_LOG_ERROR, "Failed parsing rate_divisor\n");
94  return AVERROR_INVALIDDATA;
95  }
96  get_token(pb, token, sizeof(token)); //Unknown2
97  get_token(pb, token, sizeof(token)); //Version ID
98  get_token(pb, token, sizeof(token)); //Size
99 
100  if (iss->packet_size <= 0) {
101  av_log(s, AV_LOG_ERROR, "packet_size %d is invalid\n", iss->packet_size);
102  return AVERROR_INVALIDDATA;
103  }
104 
105  iss->sample_start_pos = avio_tell(pb);
106 
107  st = avformat_new_stream(s, NULL);
108  if (!st)
109  return AVERROR(ENOMEM);
110  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
111  st->codec->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS;
112  if (stereo) {
113  st->codec->channels = 2;
114  st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
115  } else {
116  st->codec->channels = 1;
117  st->codec->channel_layout = AV_CH_LAYOUT_MONO;
118  }
119  st->codec->sample_rate = 44100;
120  if(rate_divisor > 0)
121  st->codec->sample_rate /= rate_divisor;
122  st->codec->bits_per_coded_sample = 4;
123  st->codec->bit_rate = st->codec->channels * st->codec->sample_rate
124  * st->codec->bits_per_coded_sample;
125  st->codec->block_align = iss->packet_size;
126  avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate);
127 
128  return 0;
129 }
130 
131  static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
132 {
133  IssDemuxContext *iss = s->priv_data;
134  int ret = av_get_packet(s->pb, pkt, iss->packet_size);
135 
136  if(ret != iss->packet_size)
137  return AVERROR(EIO);
138 
139  pkt->stream_index = 0;
140  pkt->pts = avio_tell(s->pb) - iss->sample_start_pos;
141  if(s->streams[0]->codec->channels > 0)
142  pkt->pts /= s->streams[0]->codec->channels*2;
143  return 0;
144 }
145 
146  AVInputFormat ff_iss_demuxer = {
147  .name = "iss",
148  .long_name = NULL_IF_CONFIG_SMALL("Funcom ISS"),
149  .priv_data_size = sizeof(IssDemuxContext),
150  .read_probe = iss_probe,
151  .read_header = iss_read_header,
152  .read_packet = iss_read_packet,
153 };
NULL
#define NULL
Definition: coverity.c:32
s
const char * s
Definition: avisynth_c.h:631
AVIOContext
Bytestream IO Context.
Definition: avio.h:111
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
ff_iss_demuxer
AVInputFormat ff_iss_demuxer
Definition: iss.c:146
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1597
avpriv_set_pts_info
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.
Definition: utils.c:4149
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:86
AVCodecContext::block_align
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2324
AVFormatContext
Format I/O context.
Definition: avformat.h:1314
av_cold
#define av_cold
Definition: attributes.h:82
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3805
AVFormatContext::streams
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1382
get_token
static void get_token(AVIOContext *s, char *buf, int maxlen)
Definition: iss.c:43
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:252
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:442
AVCodecContext::bits_per_coded_sample
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:2917
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVERROR
#define AVERROR(e)
Definition: error.h:43
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:176
iss_read_header
static av_cold int iss_read_header(AVFormatContext *s)
Definition: iss.c:69
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2338
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:536
AVStream::codec
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:896
MAX_TOKEN_SIZE
#define MAX_TOKEN_SIZE
Definition: iss.c:36
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:462
ISS_SIG
#define ISS_SIG
Definition: iss.c:34
channel_layout.h
audio channel layout utility functions
read_probe
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
ISS_SIG_LEN
#define ISS_SIG_LEN
Definition: iss.c:35
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:638
AVStream
Stream structure.
Definition: avformat.h:877
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:1540
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:1549
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:2287
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1356
buf
void * buf
Definition: avisynth_c.h:553
IssDemuxContext::packet_size
int packet_size
Definition: iss.c:39
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:460
iss_probe
static int iss_probe(AVProbeData *p)
Definition: iss.c:61
IssDemuxContext::sample_start_pos
int sample_start_pos
Definition: iss.c:40
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:472
avformat.h
Main libavformat public API header.
c
static double c[64]
Definition: vsrc_mptestsrc.c:87
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:2288
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1342
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:661
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1469
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:85
iss_read_packet
static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: iss.c:131
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1444
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1460

Generated on Mon Feb 15 2016 15:20:46 for FFmpeg by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /