FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/eacdata.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 34 45 75.6%
Branches: 8 21 38.1%

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