annotate xa.c @ 3517:001175066382 libavformat

Remove debugging trash.
author michael
date Thu, 26 Jun 2008 22:45:19 +0000
parents 7a0230981402
children 1d3d17de20ba
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 /**
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
23 * @file xa.c
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
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
30 #include "avformat.h"
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
31
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
32 #define XA00_TAG MKTAG('X', 'A', 0, 0)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
33 #define XAI0_TAG MKTAG('X', 'A', 'I', 0)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
34 #define XAJ0_TAG MKTAG('X', 'A', 'J', 0)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
35
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
36 typedef struct MaxisXADemuxContext {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
37 uint32_t out_size;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
38 uint32_t sent_bytes;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
39 uint32_t audio_frame_counter;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
40 } MaxisXADemuxContext;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
41
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
42 static int xa_probe(AVProbeData *p)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
43 {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
44 switch(AV_RL32(p->buf)) {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
45 case XA00_TAG:
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
46 case XAI0_TAG:
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
47 case XAJ0_TAG:
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
48 return AVPROBE_SCORE_MAX;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
49 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
50 return 0;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
51 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
52
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
53 static int xa_read_header(AVFormatContext *s,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
54 AVFormatParameters *ap)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
55 {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
56 MaxisXADemuxContext *xa = s->priv_data;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
57 ByteIOContext *pb = s->pb;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
58 AVStream *st;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
59
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
60 /*Set up the XA Audio Decoder*/
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
61 st = av_new_stream(s, 0);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
62 if (!st)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
63 return AVERROR(ENOMEM);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
64
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
65 st->codec->codec_type = CODEC_TYPE_AUDIO;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
66 st->codec->codec_id = CODEC_ID_ADPCM_EA_MAXIS_XA;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
67 url_fskip(pb, 4); /* Skip the XA ID */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
68 xa->out_size = get_le32(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
69 url_fskip(pb, 2); /* Skip the tag */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
70 st->codec->channels = get_le16(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
71 st->codec->sample_rate = get_le32(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
72 /* Value in file is average byte rate*/
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
73 st->codec->bit_rate = get_le32(pb) * 8;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
74 st->codec->block_align = get_le16(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
75 st->codec->bits_per_sample = get_le16(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
76
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
77 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
78
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
79 return 0;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
80 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
81
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
82 static int xa_read_packet(AVFormatContext *s,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
83 AVPacket *pkt)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
84 {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
85 MaxisXADemuxContext *xa = s->priv_data;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
86 AVStream *st = s->streams[0];
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
87 ByteIOContext *pb = s->pb;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
88 unsigned int packet_size;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
89 int ret;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
90
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
91 if(xa->sent_bytes > xa->out_size)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
92 return AVERROR(EIO);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
93 /* 1 byte header and 14 bytes worth of samples * number channels per block */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
94 packet_size = 15*st->codec->channels;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
95
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
96 ret = av_get_packet(pb, pkt, packet_size);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
97 if(ret != packet_size)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
98 return AVERROR(EIO);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
99
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
100 pkt->stream_index = st->index;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
101 xa->sent_bytes += packet_size;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
102 pkt->pts = xa->audio_frame_counter;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
103 /* 14 bytes Samples per channel with 2 samples per byte */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
104 xa->audio_frame_counter += 28 * st->codec->channels;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
105
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
106 return ret;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
107 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
108
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
109 AVInputFormat xa_demuxer = {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
110 "xa",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3220
diff changeset
111 NULL_IF_CONFIG_SMALL("Maxis XA File Format"),
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
112 sizeof(MaxisXADemuxContext),
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
113 xa_probe,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
114 xa_read_header,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
115 xa_read_packet,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
116 };