Line | Branch | Exec | Source |
---|---|---|---|
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 "libavutil/channel_layout.h" | ||
32 | #include "avformat.h" | ||
33 | #include "demux.h" | ||
34 | #include "internal.h" | ||
35 | |||
36 | #include "libavutil/channel_layout.h" | ||
37 | |||
38 | typedef struct CdataDemuxContext { | ||
39 | unsigned int channels; | ||
40 | unsigned int audio_pts; | ||
41 | } CdataDemuxContext; | ||
42 | |||
43 | 7186 | static int cdata_probe(const AVProbeData *p) | |
44 | { | ||
45 | 7186 | const uint8_t *b = p->buf; | |
46 | |||
47 |
3/10✓ Branch 0 taken 169 times.
✓ Branch 1 taken 7017 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 169 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
|
7186 | if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14)) |
48 | 169 | return AVPROBE_SCORE_MAX/8; | |
49 | 7017 | return 0; | |
50 | } | ||
51 | |||
52 | 1 | static int cdata_read_header(AVFormatContext *s) | |
53 | { | ||
54 | 1 | CdataDemuxContext *cdata = s->priv_data; | |
55 | 1 | AVIOContext *pb = s->pb; | |
56 | unsigned int sample_rate, header; | ||
57 | AVStream *st; | ||
58 | AVChannelLayout channel_layout; | ||
59 | |||
60 | 1 | header = avio_rb16(pb); | |
61 |
1/5✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | switch (header) { |
62 | 1 | case 0x0400: | |
63 | 1 | channel_layout = (AVChannelLayout){ .nb_channels = 1, .order = AV_CHANNEL_ORDER_UNSPEC }; | |
64 | 1 | 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 | 1 | cdata->channels = channel_layout.nb_channels; | |
77 | |||
78 | 1 | sample_rate = avio_rb16(pb); | |
79 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11); |
80 | |||
81 | 1 | st = avformat_new_stream(s, NULL); | |
82 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!st) |
83 | ✗ | return AVERROR(ENOMEM); | |
84 | 1 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
85 | 1 | st->codecpar->codec_tag = 0; /* no fourcc */ | |
86 | 1 | st->codecpar->codec_id = AV_CODEC_ID_ADPCM_EA_XAS; | |
87 | 1 | st->codecpar->ch_layout = channel_layout; | |
88 | 1 | st->codecpar->sample_rate = sample_rate; | |
89 | 1 | avpriv_set_pts_info(st, 64, 1, sample_rate); | |
90 | |||
91 | 1 | cdata->audio_pts = 0; | |
92 | 1 | return 0; | |
93 | } | ||
94 | |||
95 | 601 | static int cdata_read_packet(AVFormatContext *s, AVPacket *pkt) | |
96 | { | ||
97 | 601 | CdataDemuxContext *cdata = s->priv_data; | |
98 | 601 | int packet_size = 76*cdata->channels; | |
99 | |||
100 | 601 | int ret = av_get_packet(s->pb, pkt, packet_size); | |
101 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 600 times.
|
601 | if (ret < 0) |
102 | 1 | return ret; | |
103 | 600 | pkt->pts = cdata->audio_pts++; | |
104 | 600 | return 0; | |
105 | } | ||
106 | |||
107 | const FFInputFormat ff_ea_cdata_demuxer = { | ||
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), | ||
112 | .read_probe = cdata_probe, | ||
113 | .read_header = cdata_read_header, | ||
114 | .read_packet = cdata_read_packet, | ||
115 | }; | ||
116 |