FFmpeg
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 "internal.h"
34 
36 
37 typedef struct CdataDemuxContext {
38  unsigned int channels;
39  unsigned int audio_pts;
41 
42 static int cdata_probe(const AVProbeData *p)
43 {
44  const uint8_t *b = p->buf;
45 
46  if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
47  return AVPROBE_SCORE_MAX/8;
48  return 0;
49 }
50 
52 {
53  CdataDemuxContext *cdata = s->priv_data;
54  AVIOContext *pb = s->pb;
55  unsigned int sample_rate, header;
56  AVStream *st;
57  AVChannelLayout channel_layout;
58 
59  header = avio_rb16(pb);
60  switch (header) {
61  case 0x0400:
62  channel_layout = (AVChannelLayout){ .nb_channels = 1, .order = AV_CHANNEL_ORDER_UNSPEC };
63  break;
64  case 0x0404:
65  channel_layout = (AVChannelLayout){ .nb_channels = 2, .order = AV_CHANNEL_ORDER_UNSPEC };
66  break;
67  case 0x040C:
68  channel_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_QUAD; break;
69  case 0x0414:
70  channel_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1_BACK; break;
71  default:
72  av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
73  return -1;
74  };
75  cdata->channels = channel_layout.nb_channels;
76 
77  sample_rate = avio_rb16(pb);
78  avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
79 
80  st = avformat_new_stream(s, NULL);
81  if (!st)
82  return AVERROR(ENOMEM);
84  st->codecpar->codec_tag = 0; /* no fourcc */
86  st->codecpar->ch_layout = channel_layout;
88  avpriv_set_pts_info(st, 64, 1, sample_rate);
89 
90  cdata->audio_pts = 0;
91  return 0;
92 }
93 
95 {
96  CdataDemuxContext *cdata = s->priv_data;
97  int packet_size = 76*cdata->channels;
98 
99  int ret = av_get_packet(s->pb, pkt, packet_size);
100  if (ret < 0)
101  return ret;
102  pkt->pts = cdata->audio_pts++;
103  return 0;
104 }
105 
107  .name = "ea_cdata",
108  .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
109  .priv_data_size = sizeof(CdataDemuxContext),
113  .extensions = "cdata",
114 };
cdata_read_header
static int cdata_read_header(AVFormatContext *s)
Definition: eacdata.c:51
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:51
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const struct AVCodec *c)
Add a new stream to a media file.
b
#define b
Definition: input.c:41
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:59
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
sample_rate
sample_rate
Definition: ffmpeg_filter.c:368
cdata_probe
static int cdata_probe(const AVProbeData *p)
Definition: eacdata.c:42
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:464
avpriv_set_pts_info
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:761
pkt
AVPacket * pkt
Definition: movenc.c:59
AVInputFormat
Definition: avformat.h:549
CdataDemuxContext::channels
unsigned int channels
Definition: eacdata.c:38
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_read_callback.c:41
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:554
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:454
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:112
AVFormatContext
Format I/O context.
Definition: avformat.h:1115
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:864
AV_CODEC_ID_ADPCM_EA_XAS
@ AV_CODEC_ID_ADPCM_EA_XAS
Definition: codec_id.h:394
ff_ea_cdata_demuxer
const AVInputFormat ff_ea_cdata_demuxer
Definition: eacdata.c:106
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:550
NULL
#define NULL
Definition: coverity.c:32
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:452
AVCodecParameters::ch_layout
AVChannelLayout ch_layout
Audio only.
Definition: codec_par.h:206
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:171
AVIOContext
Bytestream IO Context.
Definition: avio.h:166
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:307
header
static const uint8_t header[24]
Definition: sdr2.c:67
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:650
CdataDemuxContext
Definition: eacdata.c:37
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:484
AV_CHANNEL_LAYOUT_QUAD
#define AV_CHANNEL_LAYOUT_QUAD
Definition: channel_layout.h:391
CdataDemuxContext::audio_pts
unsigned int audio_pts
Definition: eacdata.c:39
av_get_packet
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:103
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:841
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:793
avformat.h
channel_layout.h
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:365
read_probe
static int read_probe(const AVProbeData *p)
Definition: cdg.c:29
cdata_read_packet
static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: eacdata.c:94
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:55
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:395
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27