FFmpeg
Loading...
Searching...
No Matches
xa.c
Go to the documentation of this file.
1/*
2 * Maxis XA (.xa) File Demuxer
3 * Copyright (c) 2008 Robert Marston
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
24 * Maxis XA File Demuxer
25 * by Robert Marston (rmarston@gmail.com)
26 * for more information on the XA audio format see
27 * http://wiki.multimedia.cx/index.php?title=Maxis_XA
28 */
29
31#include "avformat.h"
32#include "demux.h"
33#include "internal.h"
34
35#define XA00_TAG MKTAG('X', 'A', 0, 0)
36#define XAI0_TAG MKTAG('X', 'A', 'I', 0)
37#define XAJ0_TAG MKTAG('X', 'A', 'J', 0)
38
39typedef struct MaxisXADemuxContext {
40 uint32_t out_size;
41 uint32_t sent_bytes;
43
44static int xa_probe(const AVProbeData *p)
45{
46 int channels, srate, bits_per_sample;
47 if (p->buf_size < 24)
48 return 0;
49 switch(AV_RL32(p->buf)) {
50 case XA00_TAG:
51 case XAI0_TAG:
52 case XAJ0_TAG:
53 break;
54 default:
55 return 0;
56 }
57 channels = AV_RL16(p->buf + 10);
58 srate = AV_RL32(p->buf + 12);
59 bits_per_sample = AV_RL16(p->buf + 22);
60 if (!channels || channels > 8 || !srate || srate > 192000 ||
61 bits_per_sample < 4 || bits_per_sample > 32)
62 return 0;
64}
65
67{
68 MaxisXADemuxContext *xa = s->priv_data;
69 AVIOContext *pb = s->pb;
70 AVStream *st;
71
72 /*Set up the XA Audio Decoder*/
74 if (!st)
75 return AVERROR(ENOMEM);
76
79 avio_skip(pb, 4); /* Skip the XA ID */
80 xa->out_size = avio_rl32(pb);
81 avio_skip(pb, 2); /* Skip the tag */
84 avio_skip(pb, 4); /* Skip average byte rate */
85 avio_skip(pb, 2); /* Skip block align */
86 avio_skip(pb, 2); /* Skip bits-per-sample */
87
90
91 st->codecpar->bit_rate = av_clip(15LL * st->codecpar->ch_layout.nb_channels * 8 *
92 st->codecpar->sample_rate / 28, 0, INT_MAX);
93
95 st->start_time = 0;
96
97 return 0;
98}
99
101 AVPacket *pkt)
102{
103 MaxisXADemuxContext *xa = s->priv_data;
104 AVStream *st = s->streams[0];
105 AVIOContext *pb = s->pb;
106 unsigned int packet_size;
107 int ret;
108
109 if (xa->sent_bytes >= xa->out_size)
110 return AVERROR_EOF;
111 /* 1 byte header and 14 bytes worth of samples * number channels per block */
112 packet_size = 15*st->codecpar->ch_layout.nb_channels;
113
114 ret = av_get_packet(pb, pkt, packet_size);
115 if(ret < 0)
116 return ret;
117
118 pkt->stream_index = st->index;
119 xa->sent_bytes += packet_size;
120 pkt->duration = 28;
121
122 return ret;
123}
124
126 .p.name = "xa",
127 .p.long_name = NULL_IF_CONFIG_SMALL("Maxis XA"),
128 .priv_data_size = sizeof(MaxisXADemuxContext),
132};
const FFInputFormat ff_xa_demuxer
Definition xa.c:125
channels
Definition aptx.h:31
void avpriv_set_pts_info(AVStream *st, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition avformat.c:834
Main libavformat public API header.
#define AVPROBE_SCORE_EXTENSION
score for file extension
Definition avformat.h:481
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition utils.c:98
unsigned int avio_rl16(AVIOContext *s)
Definition aviobuf.c:717
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
unsigned int avio_rl32(AVIOContext *s)
Definition aviobuf.c:733
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
#define s(width, name)
Definition cbs_vp9.c:198
static int read_probe(const AVProbeData *p)
Definition cdg.c:30
#define av_clip
Definition common.h:100
#define NULL
Definition coverity.c:32
static AVPacket * pkt
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_ADPCM_EA_MAXIS_XA
Definition codec_id.h:396
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define AV_RL32(p)
#define AV_RL16(p)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
int nb_channels
Number of channels in this layout.
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition codec_par.h:99
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition codec_par.h:57
int sample_rate
The number of audio samples per second.
Definition codec_par.h:213
Format I/O context.
Definition avformat.h:1333
Bytestream IO Context.
Definition avio.h:160
This structure stores compressed data.
Definition packet.h:580
This structure contains the data a format has to probe a file.
Definition avformat.h:471
Stream structure.
Definition avformat.h:766
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition avformat.h:789
int index
stream index in AVFormatContext
Definition avformat.h:772
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition avformat.h:815
uint32_t sent_bytes
Definition xa.c:41
uint32_t out_size
Definition xa.c:40
static int xa_probe(const AVProbeData *p)
Definition xa.c:44
#define XA00_TAG
Definition xa.c:35
#define XAJ0_TAG
Definition xa.c:37
static int xa_read_header(AVFormatContext *s)
Definition xa.c:66
static int xa_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition xa.c:100
#define XAI0_TAG
Definition xa.c:36