annotate xa.c @ 5479:17744e7f9e4c libavformat

Remove a useless local variable.
author lucabe
date Mon, 28 Dec 2009 13:41:09 +0000
parents a026efc0ca86
children dec5ac461e93
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
1 /*
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
2 * Maxis XA (.xa) File Demuxer
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
3 * Copyright (c) 2008 Robert Marston
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
4 *
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
5 * This file is part of FFmpeg.
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
6 *
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
11 *
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
15 * Lesser General Public License for more details.
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
16 *
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
20 */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
21
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
22 /**
4331
49c1d3b27727 Use full internal pathname in doxygen @file directives.
diego
parents: 4201
diff changeset
23 * @file libavformat/xa.c
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
24 * Maxis XA File Demuxer
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
25 * by Robert Marston (rmarston@gmail.com)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
26 * for more information on the XA audio format see
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
27 * http://wiki.multimedia.cx/index.php?title=Maxis_XA
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
28 */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
29
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 3908
diff changeset
30 #include "libavutil/intreadwrite.h"
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
31 #include "avformat.h"
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
32
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
33 #define XA00_TAG MKTAG('X', 'A', 0, 0)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
34 #define XAI0_TAG MKTAG('X', 'A', 'I', 0)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
35 #define XAJ0_TAG MKTAG('X', 'A', 'J', 0)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
36
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
37 typedef struct MaxisXADemuxContext {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
38 uint32_t out_size;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
39 uint32_t sent_bytes;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
40 uint32_t audio_frame_counter;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
41 } MaxisXADemuxContext;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
42
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
43 static int xa_probe(AVProbeData *p)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
44 {
5180
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
45 int channels, srate, bits_per_sample;
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
46 if (p->buf_size < 24)
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
47 return 0;
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
48 switch(AV_RL32(p->buf)) {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
49 case XA00_TAG:
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
50 case XAI0_TAG:
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
51 case XAJ0_TAG:
5180
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
52 break;
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
53 default:
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
54 return 0;
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
55 }
5180
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
56 channels = AV_RL16(p->buf + 10);
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
57 srate = AV_RL32(p->buf + 12);
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
58 bits_per_sample = AV_RL16(p->buf + 22);
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
59 if (!channels || channels > 8 || !srate || srate > 192000 ||
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
60 bits_per_sample < 4 || bits_per_sample > 32)
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
61 return 0;
a026efc0ca86 Add more sanity checks for header elements, rejecting files with clearly
reimar
parents: 4331
diff changeset
62 return AVPROBE_SCORE_MAX/2;
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
63 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
64
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
65 static int xa_read_header(AVFormatContext *s,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
66 AVFormatParameters *ap)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
67 {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
68 MaxisXADemuxContext *xa = s->priv_data;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
69 ByteIOContext *pb = s->pb;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
70 AVStream *st;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
71
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
72 /*Set up the XA Audio Decoder*/
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
73 st = av_new_stream(s, 0);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
74 if (!st)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
75 return AVERROR(ENOMEM);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
76
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
77 st->codec->codec_type = CODEC_TYPE_AUDIO;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
78 st->codec->codec_id = CODEC_ID_ADPCM_EA_MAXIS_XA;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
79 url_fskip(pb, 4); /* Skip the XA ID */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
80 xa->out_size = get_le32(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
81 url_fskip(pb, 2); /* Skip the tag */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
82 st->codec->channels = get_le16(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
83 st->codec->sample_rate = get_le32(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
84 /* Value in file is average byte rate*/
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
85 st->codec->bit_rate = get_le32(pb) * 8;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
86 st->codec->block_align = get_le16(pb);
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3424
diff changeset
87 st->codec->bits_per_coded_sample = get_le16(pb);
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
88
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
89 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
90
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
91 return 0;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
92 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
93
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
94 static int xa_read_packet(AVFormatContext *s,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
95 AVPacket *pkt)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
96 {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
97 MaxisXADemuxContext *xa = s->priv_data;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
98 AVStream *st = s->streams[0];
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
99 ByteIOContext *pb = s->pb;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
100 unsigned int packet_size;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
101 int ret;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
102
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
103 if(xa->sent_bytes > xa->out_size)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
104 return AVERROR(EIO);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
105 /* 1 byte header and 14 bytes worth of samples * number channels per block */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
106 packet_size = 15*st->codec->channels;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
107
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
108 ret = av_get_packet(pb, pkt, packet_size);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
109 if(ret != packet_size)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
110 return AVERROR(EIO);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
111
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
112 pkt->stream_index = st->index;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
113 xa->sent_bytes += packet_size;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
114 pkt->pts = xa->audio_frame_counter;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
115 /* 14 bytes Samples per channel with 2 samples per byte */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
116 xa->audio_frame_counter += 28 * st->codec->channels;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
117
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
118 return ret;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
119 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
120
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
121 AVInputFormat xa_demuxer = {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
122 "xa",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3220
diff changeset
123 NULL_IF_CONFIG_SMALL("Maxis XA File Format"),
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
124 sizeof(MaxisXADemuxContext),
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
125 xa_probe,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
126 xa_read_header,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
127 xa_read_packet,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
128 };