3189
|
1 /*
|
3198
|
2 * IFF (.iff) file demuxer
|
3189
|
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 iff.c
|
3198
|
24 * IFF file demuxer
|
3189
|
25 * by Jaikrishnan Menon
|
|
26 * for more information on the .iff file format, visit:
|
|
27 * http://wiki.multimedia.cx/index.php?title=IFF
|
|
28 */
|
|
29
|
|
30 #include "avformat.h"
|
|
31
|
|
32 #define ID_8SVX MKTAG('8','S','V','X')
|
|
33 #define ID_VHDR MKTAG('V','H','D','R')
|
|
34 #define ID_ATAK MKTAG('A','T','A','K')
|
|
35 #define ID_RLSE MKTAG('R','L','S','E')
|
|
36 #define ID_CHAN MKTAG('C','H','A','N')
|
|
37
|
|
38 #define ID_FORM MKTAG('F','O','R','M')
|
|
39 #define ID_ANNO MKTAG('A','N','N','O')
|
|
40 #define ID_AUTH MKTAG('A','U','T','H')
|
|
41 #define ID_CHRS MKTAG('C','H','R','S')
|
|
42 #define ID_COPYRIGHT MKTAG('(','c',')',' ')
|
|
43 #define ID_CSET MKTAG('C','S','E','T')
|
|
44 #define ID_FVER MKTAG('F','V','E','R')
|
|
45 #define ID_NAME MKTAG('N','A','M','E')
|
|
46 #define ID_TEXT MKTAG('T','E','X','T')
|
|
47 #define ID_BODY MKTAG('B','O','D','Y')
|
|
48
|
|
49 #define LEFT 2
|
|
50 #define RIGHT 4
|
|
51 #define STEREO 6
|
|
52
|
|
53 #define PACKET_SIZE 1024
|
|
54
|
|
55 typedef enum {COMP_NONE, COMP_FIB, COMP_EXP} svx8_compression_t;
|
|
56
|
|
57 typedef struct {
|
|
58 uint32_t body_size;
|
|
59 uint32_t sent_bytes;
|
|
60 uint32_t audio_frame_count;
|
|
61 } IffDemuxContext;
|
|
62
|
|
63 static int iff_probe(AVProbeData *p)
|
|
64 {
|
|
65 const uint8_t *d = p->buf;
|
|
66
|
|
67 if ( AV_RL32(d) == ID_FORM &&
|
|
68 AV_RL32(d+8) == ID_8SVX)
|
|
69 return AVPROBE_SCORE_MAX;
|
|
70 return 0;
|
|
71 }
|
|
72
|
|
73 static int iff_read_header(AVFormatContext *s,
|
|
74 AVFormatParameters *ap)
|
|
75 {
|
|
76 IffDemuxContext *iff = s->priv_data;
|
|
77 ByteIOContext *pb = s->pb;
|
|
78 AVStream *st;
|
|
79 uint32_t chunk_id, data_size;
|
3200
|
80 int padding, done = 0;
|
3189
|
81
|
|
82 st = av_new_stream(s, 0);
|
|
83 if (!st)
|
|
84 return AVERROR(ENOMEM);
|
|
85
|
|
86 st->codec->channels = 1;
|
|
87 url_fskip(pb, 12);
|
|
88
|
|
89 while(!done && !url_feof(pb)) {
|
|
90 chunk_id = get_le32(pb);
|
|
91 data_size = get_be32(pb);
|
|
92 padding = data_size & 1;
|
|
93
|
|
94 switch(chunk_id) {
|
|
95 case ID_VHDR:
|
|
96 url_fskip(pb, 12);
|
|
97 st->codec->sample_rate = get_be16(pb);
|
|
98 url_fskip(pb, 1);
|
|
99 st->codec->codec_tag = get_byte(pb);
|
|
100 url_fskip(pb, 4);
|
|
101 break;
|
|
102
|
|
103 case ID_BODY:
|
|
104 iff->body_size = data_size;
|
|
105 done = 1;
|
|
106 break;
|
|
107
|
|
108 case ID_CHAN:
|
|
109 st->codec->channels = (get_be32(pb) < 6) ? 1 : 2;
|
|
110 break;
|
|
111
|
|
112 default:
|
|
113 url_fseek(pb, data_size + padding, SEEK_CUR);
|
|
114 break;
|
|
115 }
|
|
116 }
|
|
117
|
|
118 if(!st->codec->sample_rate)
|
|
119 return AVERROR_INVALIDDATA;
|
|
120
|
|
121 av_set_pts_info(st, 32, 1, st->codec->sample_rate);
|
|
122 st->codec->codec_type = CODEC_TYPE_AUDIO;
|
|
123
|
|
124 switch(st->codec->codec_tag) {
|
|
125 case COMP_NONE:
|
|
126 st->codec->codec_id = CODEC_ID_PCM_S8;
|
|
127 break;
|
|
128 case COMP_FIB:
|
|
129 st->codec->codec_id = CODEC_ID_8SVX_FIB;
|
|
130 break;
|
|
131 case COMP_EXP:
|
|
132 st->codec->codec_id = CODEC_ID_8SVX_EXP;
|
|
133 break;
|
|
134 default:
|
|
135 av_log(s, AV_LOG_ERROR, "iff: unknown compression method\n");
|
|
136 return -1;
|
|
137 }
|
|
138
|
|
139 st->codec->bits_per_sample = 8;
|
|
140 st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_sample;
|
|
141 st->codec->block_align = st->codec->channels * st->codec->bits_per_sample;
|
|
142
|
|
143 return 0;
|
|
144 }
|
|
145
|
|
146 static int iff_read_packet(AVFormatContext *s,
|
|
147 AVPacket *pkt)
|
|
148 {
|
|
149 IffDemuxContext *iff = s->priv_data;
|
|
150 ByteIOContext *pb = s->pb;
|
|
151 int ret;
|
|
152
|
|
153 if(iff->sent_bytes > iff->body_size)
|
|
154 return AVERROR(EIO);
|
|
155 ret = av_get_packet(pb, pkt, PACKET_SIZE);
|
|
156
|
|
157 if(iff->sent_bytes == 0)
|
|
158 pkt->flags |= PKT_FLAG_KEY;
|
|
159
|
|
160 iff->sent_bytes += PACKET_SIZE;
|
|
161 pkt->stream_index = 0;
|
|
162 pkt->pts = iff->audio_frame_count;
|
|
163 iff->audio_frame_count += ret / s->streams[0]->codec->channels;
|
|
164 return ret;
|
|
165 }
|
|
166
|
|
167 AVInputFormat iff_demuxer = {
|
|
168 "IFF",
|
|
169 "IFF format",
|
|
170 sizeof(IffDemuxContext),
|
|
171 iff_probe,
|
|
172 iff_read_header,
|
|
173 iff_read_packet,
|
|
174 };
|