annotate xa.c @ 4599:d80ca49779b1 libavformat

Add ticks_per_frame, this should hopefully fix the regressions caused by the time_base change.
author michael
date Thu, 26 Feb 2009 23:47:32 +0000
parents 49c1d3b27727
children a026efc0ca86
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 {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
45 switch(AV_RL32(p->buf)) {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
46 case XA00_TAG:
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
47 case XAI0_TAG:
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
48 case XAJ0_TAG:
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
49 return AVPROBE_SCORE_MAX;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
50 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
51 return 0;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
52 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
53
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
54 static int xa_read_header(AVFormatContext *s,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
55 AVFormatParameters *ap)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
56 {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
57 MaxisXADemuxContext *xa = s->priv_data;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
58 ByteIOContext *pb = s->pb;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
59 AVStream *st;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
60
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
61 /*Set up the XA Audio Decoder*/
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
62 st = av_new_stream(s, 0);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
63 if (!st)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
64 return AVERROR(ENOMEM);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
65
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
66 st->codec->codec_type = CODEC_TYPE_AUDIO;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
67 st->codec->codec_id = CODEC_ID_ADPCM_EA_MAXIS_XA;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
68 url_fskip(pb, 4); /* Skip the XA ID */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
69 xa->out_size = get_le32(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
70 url_fskip(pb, 2); /* Skip the tag */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
71 st->codec->channels = get_le16(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
72 st->codec->sample_rate = get_le32(pb);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
73 /* Value in file is average byte rate*/
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
74 st->codec->bit_rate = get_le32(pb) * 8;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
75 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
76 st->codec->bits_per_coded_sample = get_le16(pb);
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
77
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
78 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
79
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
80 return 0;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
81 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
82
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
83 static int xa_read_packet(AVFormatContext *s,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
84 AVPacket *pkt)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
85 {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
86 MaxisXADemuxContext *xa = s->priv_data;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
87 AVStream *st = s->streams[0];
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
88 ByteIOContext *pb = s->pb;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
89 unsigned int packet_size;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
90 int ret;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
91
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
92 if(xa->sent_bytes > xa->out_size)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
93 return AVERROR(EIO);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
94 /* 1 byte header and 14 bytes worth of samples * number channels per block */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
95 packet_size = 15*st->codec->channels;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
96
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
97 ret = av_get_packet(pb, pkt, packet_size);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
98 if(ret != packet_size)
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
99 return AVERROR(EIO);
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
100
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
101 pkt->stream_index = st->index;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
102 xa->sent_bytes += packet_size;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
103 pkt->pts = xa->audio_frame_counter;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
104 /* 14 bytes Samples per channel with 2 samples per byte */
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
105 xa->audio_frame_counter += 28 * st->codec->channels;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
106
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
107 return ret;
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
108 }
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
109
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
110 AVInputFormat xa_demuxer = {
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
111 "xa",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3220
diff changeset
112 NULL_IF_CONFIG_SMALL("Maxis XA File Format"),
3220
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
113 sizeof(MaxisXADemuxContext),
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
114 xa_probe,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
115 xa_read_header,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
116 xa_read_packet,
a0ccee85d6ad Maxis XA demuxer and decoder.
benoit
parents:
diff changeset
117 };