FFmpeg
Loading...
Searching...
No Matches
eacdata.c
Go to the documentation of this file.
1/*
2 * Electronic Arts .cdata file Demuxer
3 * Copyright (c) 2007 Peter Ross
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 * Electronic Arts cdata Format Demuxer
25 * by Peter Ross (pross@xvid.org)
26 *
27 * Technical details here:
28 * http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec
29 */
30
32#include "avformat.h"
33#include "demux.h"
34#include "internal.h"
35
37
38typedef struct CdataDemuxContext {
39 unsigned int channels;
40 unsigned int audio_pts;
42
43static int cdata_probe(const AVProbeData *p)
44{
45 const uint8_t *b = p->buf;
46
47 if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
48 return AVPROBE_SCORE_MAX/8;
49 return 0;
50}
51
53{
54 CdataDemuxContext *cdata = s->priv_data;
55 AVIOContext *pb = s->pb;
56 unsigned int sample_rate, header;
57 AVStream *st;
58 AVChannelLayout channel_layout;
59
60 header = avio_rb16(pb);
61 switch (header) {
62 case 0x0400:
63 channel_layout = (AVChannelLayout){ .nb_channels = 1, .order = AV_CHANNEL_ORDER_UNSPEC };
64 break;
65 case 0x0404:
66 channel_layout = (AVChannelLayout){ .nb_channels = 2, .order = AV_CHANNEL_ORDER_UNSPEC };
67 break;
68 case 0x040C:
69 channel_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD; break;
70 case 0x0414:
71 channel_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK; break;
72 default:
73 av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
74 return -1;
75 };
76 cdata->channels = channel_layout.nb_channels;
77
78 sample_rate = avio_rb16(pb);
79 avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
80
82 if (!st)
83 return AVERROR(ENOMEM);
85 st->codecpar->codec_tag = 0; /* no fourcc */
87 st->codecpar->ch_layout = channel_layout;
88 st->codecpar->sample_rate = sample_rate;
89 avpriv_set_pts_info(st, 64, 1, sample_rate);
90
91 cdata->audio_pts = 0;
92 return 0;
93}
94
96{
97 CdataDemuxContext *cdata = s->priv_data;
98 int packet_size = 76*cdata->channels;
99
100 int ret = av_get_packet(s->pb, pkt, packet_size);
101 if (ret < 0)
102 return ret;
103 pkt->pts = cdata->audio_pts++;
104 return 0;
105}
106
108 .p.name = "ea_cdata",
109 .p.long_name = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
110 .p.extensions = "cdata",
111 .priv_data_size = sizeof(CdataDemuxContext),
115};
const FFInputFormat ff_ea_cdata_demuxer
Definition eacdata.c:107
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_MAX
maximum score
Definition avformat.h:483
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_rb16(AVIOContext *s)
Definition aviobuf.c:749
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition aviobuf.c:321
int avio_r8(AVIOContext *s)
Definition aviobuf.c:606
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
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
static AVPacket * pkt
static int cdata_probe(const AVProbeData *p)
Definition eacdata.c:43
static int cdata_read_header(AVFormatContext *s)
Definition eacdata.c:52
static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition eacdata.c:95
static int read_header(FFV1Context *f, RangeCoder *c)
Definition ffv1dec.c:578
@ AV_CODEC_ID_ADPCM_EA_XAS
Definition codec_id.h:395
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_QUAD
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
#define AVERROR(e)
Definition error.h:45
#define AV_LOG_INFO
Standard information.
Definition log.h:221
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
#define b
Definition input.c:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition internal.h:88
static const uint8_t header[24]
Definition sdr2.c:68
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
AVChannelLayout ch_layout
The channel layout and number of channels.
Definition codec_par.h:207
enum AVMediaType codec_type
General type of the encoded data.
Definition codec_par.h:53
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition codec_par.h:61
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
unsigned int channels
Definition eacdata.c:39
unsigned int audio_pts
Definition eacdata.c:40
#define av_log(a,...)