annotate iss.c @ 4273:ed5196e6e112 libavformat

Move av_read_frame/parser related buffer variables from AVFormatContext to AVStream, this is required if we want to allow the user to pull frames from specific streams at some point in the future.
author michael
date Thu, 22 Jan 2009 23:35:31 +0000
parents f7c35963d089
children ef4f40b555b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4244
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
1 /*
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
2 * ISS (.iss) file demuxer
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
3 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
4 *
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
5 * This file is part of FFmpeg.
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
6 *
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
11 *
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
15 * Lesser General Public License for more details.
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
16 *
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
20 */
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
21
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
22 /**
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
23 * @file iss.c
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
24 * Funcom ISS file demuxer
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
25 * @author Jaikrishnan Menon
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
26 * for more information on the .iss file format, visit:
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
27 * http://wiki.multimedia.cx/index.php?title=FunCom_ISS
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
28 */
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
29
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
30 #include "avformat.h"
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
31 #include "libavutil/avstring.h"
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
32
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
33 #define ISS_SIG "IMA_ADPCM_Sound"
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
34 #define ISS_SIG_LEN 15
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
35 #define MAX_TOKEN_SIZE 20
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
36
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
37 typedef struct {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
38 int packet_size;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
39 int sample_start_pos;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
40 } IssDemuxContext;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
41
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
42 static void get_token(ByteIOContext *s, char *buf, int maxlen)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
43 {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
44 int i = 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
45 char c;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
46
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
47 while ((c = get_byte(s))) {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
48 if(c == ' ')
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
49 break;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
50 if (i < maxlen-1)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
51 buf[i++] = c;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
52 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
53
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
54 buf[i] = 0; /* Ensure null terminated, but may be truncated */
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
55 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
56
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
57 static int iss_probe(AVProbeData *p)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
58 {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
59 if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
60 return 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
61
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
62 return AVPROBE_SCORE_MAX;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
63 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
64
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
65 static av_cold int iss_read_header(AVFormatContext *s, AVFormatParameters *ap)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
66 {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
67 IssDemuxContext *iss = s->priv_data;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
68 ByteIOContext *pb = s->pb;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
69 AVStream *st;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
70 char token[MAX_TOKEN_SIZE];
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
71 int stereo, rate_divisor;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
72
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
73 get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
74 get_token(pb, token, sizeof(token)); //packet size
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
75 sscanf(token, "%d", &iss->packet_size);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
76 get_token(pb, token, sizeof(token)); //File ID
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
77 get_token(pb, token, sizeof(token)); //out size
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
78 get_token(pb, token, sizeof(token)); //stereo
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
79 sscanf(token, "%d", &stereo);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
80 get_token(pb, token, sizeof(token)); //Unknown1
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
81 get_token(pb, token, sizeof(token)); //RateDivisor
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
82 sscanf(token, "%d", &rate_divisor);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
83 get_token(pb, token, sizeof(token)); //Unknown2
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
84 get_token(pb, token, sizeof(token)); //Version ID
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
85 get_token(pb, token, sizeof(token)); //Size
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
86
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
87 iss->sample_start_pos = url_ftell(pb);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
88
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
89 st = av_new_stream(s, 0);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
90 if (!st)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
91 return AVERROR(ENOMEM);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
92 st->codec->codec_type = CODEC_TYPE_AUDIO;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
93 st->codec->codec_id = CODEC_ID_ADPCM_IMA_ISS;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
94 st->codec->channels = stereo ? 2 : 1;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
95 st->codec->sample_rate = 44100;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
96 if(rate_divisor > 0)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
97 st->codec->sample_rate /= rate_divisor;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
98 st->codec->bits_per_coded_sample = 4;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
99 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
100 * st->codec->bits_per_coded_sample;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
101 st->codec->block_align = iss->packet_size;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
102 av_set_pts_info(st, 32, 1, st->codec->sample_rate);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
103
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
104 return 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
105 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
106
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
107 static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
108 {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
109 IssDemuxContext *iss = s->priv_data;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
110 int ret = av_get_packet(s->pb, pkt, iss->packet_size);
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
111
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
112 if(ret < 0)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
113 return ret;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
114
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
115 pkt->stream_index = 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
116 pkt->pts = url_ftell(s->pb) - iss->sample_start_pos;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
117 if(s->streams[0]->codec->channels > 0)
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
118 pkt->pts /= s->streams[0]->codec->channels*2;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
119 return 0;
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
120 }
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
121
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
122 AVInputFormat iss_demuxer = {
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
123 "ISS",
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
124 NULL_IF_CONFIG_SMALL("Funcom ISS format"),
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
125 sizeof(IssDemuxContext),
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
126 iss_probe,
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
127 iss_read_header,
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
128 iss_read_packet,
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
129 };
f7c35963d089 added demuxer for FunCom ISS audio files,
stefang
parents:
diff changeset
130