FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/iss.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 59 69 85.5%
Functions: 4 4 100.0%
Branches: 19 28 67.9%

Line Branch Exec Source
1 /*
2 * ISS (.iss) file demuxer
3 * Copyright (c) 2008 Jaikrishnan Menon <realityman@gmx.net>
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 * Funcom ISS file demuxer
25 * @author Jaikrishnan Menon
26 * @see http://wiki.multimedia.cx/index.php?title=FunCom_ISS
27 */
28
29 #include "libavutil/channel_layout.h"
30 #include "avformat.h"
31 #include "demux.h"
32 #include "internal.h"
33 #include "libavutil/avstring.h"
34
35 #define ISS_SIG "IMA_ADPCM_Sound"
36 #define ISS_SIG_LEN 15
37 #define MAX_TOKEN_SIZE 20
38
39 typedef struct IssDemuxContext {
40 int packet_size;
41 int sample_start_pos;
42 } IssDemuxContext;
43
44 10 static void get_token(AVIOContext *s, char *buf, int maxlen)
45 {
46 10 int i = 0;
47 char c;
48
49
2/2
✓ Branch 1 taken 57 times.
✓ Branch 2 taken 1 times.
68 while ((c = avio_r8(s))) {
50
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 48 times.
57 if(c == ' ')
51 9 break;
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (i < maxlen-1)
53 48 buf[i++] = c;
54 }
55
56
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 if(!c)
57 1 avio_r8(s);
58
59 10 buf[i] = 0; /* Ensure null terminated, but may be truncated */
60 10 }
61
62 7186 static int iss_probe(const AVProbeData *p)
63 {
64
2/2
✓ Branch 0 taken 7185 times.
✓ Branch 1 taken 1 times.
7186 if (strncmp(p->buf, ISS_SIG, ISS_SIG_LEN))
65 7185 return 0;
66
67 1 return AVPROBE_SCORE_MAX;
68 }
69
70 1 static av_cold int iss_read_header(AVFormatContext *s)
71 {
72 1 IssDemuxContext *iss = s->priv_data;
73 1 AVIOContext *pb = s->pb;
74 AVStream *st;
75 char token[MAX_TOKEN_SIZE];
76 int stereo, rate_divisor;
77
78 1 get_token(pb, token, sizeof(token)); //"IMA_ADPCM_Sound"
79 1 get_token(pb, token, sizeof(token)); //packet size
80
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (sscanf(token, "%d", &iss->packet_size) != 1) {
81 av_log(s, AV_LOG_ERROR, "Failed parsing packet size\n");
82 return AVERROR_INVALIDDATA;
83 }
84 1 get_token(pb, token, sizeof(token)); //File ID
85 1 get_token(pb, token, sizeof(token)); //out size
86 1 get_token(pb, token, sizeof(token)); //stereo
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (sscanf(token, "%d", &stereo) != 1) {
88 av_log(s, AV_LOG_ERROR, "Failed parsing stereo flag\n");
89 return AVERROR_INVALIDDATA;
90 }
91 1 get_token(pb, token, sizeof(token)); //Unknown1
92 1 get_token(pb, token, sizeof(token)); //RateDivisor
93
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (sscanf(token, "%d", &rate_divisor) != 1) {
94 av_log(s, AV_LOG_ERROR, "Failed parsing rate_divisor\n");
95 return AVERROR_INVALIDDATA;
96 }
97 1 get_token(pb, token, sizeof(token)); //Unknown2
98 1 get_token(pb, token, sizeof(token)); //Version ID
99 1 get_token(pb, token, sizeof(token)); //Size
100
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (iss->packet_size <= 0) {
102 av_log(s, AV_LOG_ERROR, "packet_size %d is invalid\n", iss->packet_size);
103 return AVERROR_INVALIDDATA;
104 }
105
106 1 iss->sample_start_pos = avio_tell(pb);
107
108 1 st = avformat_new_stream(s, NULL);
109
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!st)
110 return AVERROR(ENOMEM);
111 1 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
112 1 st->codecpar->codec_id = AV_CODEC_ID_ADPCM_IMA_ISS;
113
114
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (stereo) {
115 st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
116 } else {
117 1 st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_MONO;
118 }
119
120 1 st->codecpar->sample_rate = 44100;
121
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(rate_divisor > 0)
122 1 st->codecpar->sample_rate /= rate_divisor;
123 1 st->codecpar->bits_per_coded_sample = 4;
124 1 st->codecpar->bit_rate = st->codecpar->ch_layout.nb_channels *
125 1 st->codecpar->sample_rate *
126 1 st->codecpar->bits_per_coded_sample;
127 1 st->codecpar->block_align = iss->packet_size;
128 1 avpriv_set_pts_info(st, 32, 1, st->codecpar->sample_rate);
129
130 1 return 0;
131 }
132
133 120 static int iss_read_packet(AVFormatContext *s, AVPacket *pkt)
134 {
135 120 IssDemuxContext *iss = s->priv_data;
136 120 int ret = av_get_packet(s->pb, pkt, iss->packet_size);
137
138
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 119 times.
120 if(ret != iss->packet_size)
139 1 return AVERROR(EIO);
140
141 119 pkt->stream_index = 0;
142 119 pkt->pts = avio_tell(s->pb) - iss->sample_start_pos;
143
1/2
✓ Branch 0 taken 119 times.
✗ Branch 1 not taken.
119 if (s->streams[0]->codecpar->ch_layout.nb_channels > 0)
144 119 pkt->pts /= s->streams[0]->codecpar->ch_layout.nb_channels * 2;
145 119 return 0;
146 }
147
148 const FFInputFormat ff_iss_demuxer = {
149 .p.name = "iss",
150 .p.long_name = NULL_IF_CONFIG_SMALL("Funcom ISS"),
151 .priv_data_size = sizeof(IssDemuxContext),
152 .read_probe = iss_probe,
153 .read_header = iss_read_header,
154 .read_packet = iss_read_packet,
155 };
156