FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/adp.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 33 36 91.7%
Functions: 3 3 100.0%
Branches: 17 22 77.3%

Line Branch Exec Source
1 /*
2 * ADP demuxer
3 * Copyright (c) 2013 James Almer
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 #include "libavutil/channel_layout.h"
23 #include "libavutil/intreadwrite.h"
24 #include "avformat.h"
25 #include "demux.h"
26 #include "internal.h"
27
28 7186 static int adp_probe(const AVProbeData *p)
29 {
30 7186 int i, changes = 0;
31 7186 uint8_t last = 0;
32
33
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7186 times.
7186 if (p->buf_size < 32)
34 return 0;
35
36
2/2
✓ Branch 0 taken 5111353 times.
✓ Branch 1 taken 748 times.
5112101 for (i = 0; i < p->buf_size - 3; i+=32) {
37
4/4
✓ Branch 0 taken 5105947 times.
✓ Branch 1 taken 5406 times.
✓ Branch 2 taken 1032 times.
✓ Branch 3 taken 5104915 times.
5111353 if (p->buf[i] != p->buf[i+2] || p->buf[i+1] != p->buf[i+3])
38 6438 return 0;
39
2/2
✓ Branch 0 taken 5049653 times.
✓ Branch 1 taken 55262 times.
5104915 if (p->buf[i] != last)
40 5049653 changes++;
41 5104915 last = p->buf[i];
42 }
43
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748 times.
748 if (changes <= 1)
44 return 0;
45
46
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 748 times.
748 return p->buf_size < 260 ? 1 : AVPROBE_SCORE_MAX / 4;
47 }
48
49 1 static int adp_read_header(AVFormatContext *s)
50 {
51 AVStream *st;
52
53 1 st = avformat_new_stream(s, NULL);
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!st)
55 return AVERROR(ENOMEM);
56
57 1 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
58 1 st->codecpar->codec_id = AV_CODEC_ID_ADPCM_DTK;
59 1 st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
60 1 st->codecpar->sample_rate = 48000;
61 1 st->start_time = 0;
62
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL)
63 1 st->duration = av_get_audio_frame_duration2(st->codecpar, avio_size(s->pb));
64
65 1 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
66
67 1 return 0;
68 }
69
70 34 static int adp_read_packet(AVFormatContext *s, AVPacket *pkt)
71 {
72 34 int ret, size = 1024;
73
74
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 33 times.
34 if (avio_feof(s->pb))
75 1 return AVERROR_EOF;
76
77 33 ret = av_get_packet(s->pb, pkt, size);
78
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 32 times.
33 if (ret < 0)
79 1 return ret;
80
81 32 pkt->stream_index = 0;
82
83 32 return ret;
84 }
85
86 const FFInputFormat ff_adp_demuxer = {
87 .p.name = "adp",
88 .p.long_name = NULL_IF_CONFIG_SMALL("ADP"),
89 .p.extensions = "adp,dtk",
90 .read_probe = adp_probe,
91 .read_header = adp_read_header,
92 .read_packet = adp_read_packet,
93 };
94