annotate eacdata.c @ 3792:a6d4e93e171b libavformat

fix version string ul
author bcoudurier
date Fri, 29 Aug 2008 16:56:36 +0000
parents 7a0230981402
children 49c1d3b27727
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2701
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
1 /*
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
2 * Electronic Arts .cdata file Demuxer
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
3 * Copyright (c) 2007 Peter Ross
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
4 *
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
5 * This file is part of FFmpeg.
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
6 *
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
11 *
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
16 *
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
20 */
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
21
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
22 /**
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
23 * @file eacdata.c
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
24 * Electronic Arts cdata Format Demuxer
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
25 * by Peter Ross (suxen_drol at hotmail dot com)
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
26 *
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
27 * Technical details here:
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
28 * http://wiki.multimedia.cx/index.php?title=EA_Command_And_Conquer_3_Audio_Codec
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
29 */
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
30
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
31 #include "avformat.h"
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
32
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
33 typedef struct {
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
34 unsigned int channels;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
35 unsigned int audio_pts;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
36 } CdataDemuxContext;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
37
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
38 static int cdata_probe(AVProbeData *p)
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
39 {
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
40 const uint8_t *b = p->buf;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
41
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
42 if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C))
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
43 return AVPROBE_SCORE_MAX/8;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
44 return 0;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
45 }
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
46
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
47 static int cdata_read_header(AVFormatContext *s, AVFormatParameters *ap)
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
48 {
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
49 CdataDemuxContext *cdata = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2701
diff changeset
50 ByteIOContext *pb = s->pb;
2701
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
51 unsigned int sample_rate, header;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
52 AVStream *st;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
53
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
54 header = get_be16(pb);
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
55 switch (header) {
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
56 case 0x0400: cdata->channels = 1; break;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
57 case 0x0404: cdata->channels = 2; break;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
58 case 0x040C: cdata->channels = 4; break;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
59 default:
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
60 av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header);
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
61 return -1;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
62 };
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
63
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
64 sample_rate = get_be16(pb);
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
65 url_fskip(pb, 12);
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
66
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
67 st = av_new_stream(s, 0);
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
68 if (!st)
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
69 return AVERROR(ENOMEM);
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
70 st->codec->codec_type = CODEC_TYPE_AUDIO;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
71 st->codec->codec_tag = 0; /* no fourcc */
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
72 st->codec->codec_id = CODEC_ID_ADPCM_EA_XAS;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
73 st->codec->channels = cdata->channels;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
74 st->codec->sample_rate = sample_rate;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
75 av_set_pts_info(st, 64, 1, sample_rate);
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
76
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
77 cdata->audio_pts = 0;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
78 return 0;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
79 }
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
80
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
81 static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt)
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
82 {
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
83 CdataDemuxContext *cdata = s->priv_data;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
84 int packet_size = 76*cdata->channels;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
85
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2701
diff changeset
86 if (av_get_packet(s->pb, pkt, packet_size) != packet_size)
2701
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
87 return AVERROR(EIO);
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
88 pkt->pts = cdata->audio_pts++;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
89 return 1;
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
90 }
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
91
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
92 AVInputFormat ea_cdata_demuxer = {
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
93 "ea_cdata",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 2771
diff changeset
94 NULL_IF_CONFIG_SMALL("Electronic Arts cdata"),
2701
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
95 sizeof(CdataDemuxContext),
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
96 cdata_probe,
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
97 cdata_read_header,
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
98 cdata_read_packet,
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
99 .extensions = "cdata",
25028505671c add support for demuxing Electronic Arts .cdata files
aurel
parents:
diff changeset
100 };