FFmpeg: libavformat/eacdata.c Source File

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 
31 #include "avformat.h"
32 #include "internal.h"
33 
34  typedef struct CdataDemuxContext {
35   unsigned int channels;
36   unsigned int audio_pts;
37 } CdataDemuxContext;
38 
39  static int cdata_probe(AVProbeData *p)
40 {
41  const uint8_t *b = p->buf;
42 
43  if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14))
44  return AVPROBE_SCORE_MAX/8;
45  return 0;
46 }
47 
48  static int cdata_read_header(AVFormatContext *s)
49 {
50  CdataDemuxContext *cdata = s->priv_data;
51  AVIOContext *pb = s->pb;
52  unsigned int sample_rate, header;
53  AVStream *st;
54  int64_t channel_layout = 0;
55 
56  header = avio_rb16(pb);
57  switch (header) {
58  case 0x0400: cdata->channels = 1; break;
59  case 0x0404: cdata->channels = 2; break;
60  case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD; break;
61  case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break;
62  default:
63  av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
64  return -1;
65  };
66 
67  sample_rate = avio_rb16(pb);
68  avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11);
69 
70  st = avformat_new_stream(s, NULL);
71  if (!st)
72  return AVERROR(ENOMEM);
73  st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
74  st->codec->codec_tag = 0; /* no fourcc */
75  st->codec->codec_id = AV_CODEC_ID_ADPCM_EA_XAS;
76  st->codec->channels = cdata->channels;
77  st->codec->channel_layout = channel_layout;
78  st->codec->sample_rate = sample_rate;
79  avpriv_set_pts_info(st, 64, 1, sample_rate);
80 
81  cdata->audio_pts = 0;
82  return 0;
83 }
84 
85  static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
86 {
87  CdataDemuxContext *cdata = s->priv_data;
88  int packet_size = 76*cdata->channels;
89 
90  int ret = av_get_packet(s->pb, pkt, packet_size);
91  if (ret < 0)
92  return ret;
93  pkt->pts = cdata->audio_pts++;
94  return 0;
95 }
96 
97  AVInputFormat ff_ea_cdata_demuxer = {
98  .name = "ea_cdata",
99  .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
100  .priv_data_size = sizeof(CdataDemuxContext),
101  .read_probe = cdata_probe,
102  .read_header = cdata_read_header,
103  .read_packet = cdata_read_packet,
104  .extensions = "cdata",
105 };
NULL
#define NULL
Definition: coverity.c:32
s
const char * s
Definition: avisynth_c.h:631
AVIOContext
Bytestream IO Context.
Definition: avio.h:111
cdata_read_packet
static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: eacdata.c:85
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4149
b
const char * b
Definition: vf_curves.c:109
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:282
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:683
AVFormatContext
Format I/O context.
Definition: avformat.h:1314
uint8_t
uint8_t
Definition: audio_convert.c:194
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3805
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:252
CdataDemuxContext::audio_pts
unsigned int audio_pts
Definition: eacdata.c:36
header
static const uint8_t header[24]
Definition: sdr2.c:67
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR
#define AVERROR(e)
Definition: error.h:43
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:176
AV_CH_LAYOUT_QUAD
#define AV_CH_LAYOUT_QUAD
Definition: channel_layout.h:94
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2338
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:536
AVStream::codec
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:896
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:462
read_probe
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
ff_ea_cdata_demuxer
AVInputFormat ff_ea_cdata_demuxer
Definition: eacdata.c:97
AV_CH_LAYOUT_5POINT1_BACK
#define AV_CH_LAYOUT_5POINT1_BACK
Definition: channel_layout.h:98
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:638
AVStream
Stream structure.
Definition: avformat.h:877
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
sample_rate
sample_rate
Definition: ffmpeg_filter.c:190
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:1540
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:1549
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:2287
AVFormatContext::pb
AVIOContext * pb
I/O context.
Definition: avformat.h:1356
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1564
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:460
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:472
avformat.h
Main libavformat public API header.
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:2288
CdataDemuxContext::channels
unsigned int channels
Definition: eacdata.c:35
AVFormatContext::priv_data
void * priv_data
Format private data.
Definition: avformat.h:1342
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:661
cdata_probe
static int cdata_probe(AVProbeData *p)
Definition: eacdata.c:39
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1444
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1460
cdata_read_header
static int cdata_read_header(AVFormatContext *s)
Definition: eacdata.c:48

Generated on Mon Feb 15 2016 15:20:46 for FFmpeg by   doxygen 1.8.6

AltStyle によって変換されたページ (->オリジナル) /