FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/astdec.c
Date: 2024-02-16 17:37:06
Exec Total Coverage
Lines: 43 55 78.2%
Functions: 3 3 100.0%
Branches: 19 34 55.9%

Line Branch Exec Source
1 /*
2 * AST demuxer
3 * Copyright (c) 2012 Paul B Mahol
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 "internal.h"
26 #include "ast.h"
27
28 7023 static int ast_probe(const AVProbeData *p)
29 {
30
2/2
✓ Branch 0 taken 7020 times.
✓ Branch 1 taken 3 times.
7023 if (AV_RL32(p->buf) != MKTAG('S','T','R','M'))
31 7020 return 0;
32
33
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (!AV_RB16(p->buf + 10) ||
34
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
3 !AV_RB16(p->buf + 12) || AV_RB16(p->buf + 12) > 256 ||
35
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 !AV_RB32(p->buf + 16) || AV_RB32(p->buf + 16) > 8*48000)
36 return AVPROBE_SCORE_MAX / 8;
37
38 3 return AVPROBE_SCORE_MAX / 3 * 2;
39 }
40
41 3 static int ast_read_header(AVFormatContext *s)
42 {
43 int depth;
44 AVStream *st;
45
46 3 st = avformat_new_stream(s, NULL);
47
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!st)
48 return AVERROR(ENOMEM);
49
50 3 avio_skip(s->pb, 8);
51 3 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
52 3 st->codecpar->codec_id = ff_codec_get_id(ff_codec_ast_tags, avio_rb16(s->pb));
53
54 3 depth = avio_rb16(s->pb);
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (depth != 16) {
56 avpriv_request_sample(s, "depth %d", depth);
57 return AVERROR_INVALIDDATA;
58 }
59
60 3 st->codecpar->ch_layout.nb_channels = avio_rb16(s->pb);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (!st->codecpar->ch_layout.nb_channels)
62 return AVERROR_INVALIDDATA;
63
64
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (st->codecpar->ch_layout.nb_channels == 2)
65 3 st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO;
66 else if (st->codecpar->ch_layout.nb_channels == 4)
67 st->codecpar->ch_layout = (AVChannelLayout)AV_CHANNEL_LAYOUT_4POINT0;
68
69 3 avio_skip(s->pb, 2);
70 3 st->codecpar->sample_rate = avio_rb32(s->pb);
71
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (st->codecpar->sample_rate <= 0)
72 return AVERROR_INVALIDDATA;
73 3 st->start_time = 0;
74 3 st->duration = avio_rb32(s->pb);
75 3 avio_skip(s->pb, 40);
76 3 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
77
78 3 return 0;
79 }
80
81 74 static int ast_read_packet(AVFormatContext *s, AVPacket *pkt)
82 {
83 uint32_t type, size;
84 int64_t pos;
85 int ret;
86
87
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 71 times.
74 if (avio_feof(s->pb))
88 3 return AVERROR_EOF;
89
90 71 pos = avio_tell(s->pb);
91 71 type = avio_rl32(s->pb);
92 71 size = avio_rb32(s->pb);
93
1/2
✓ Branch 0 taken 71 times.
✗ Branch 1 not taken.
71 if (!s->streams[0]->codecpar->ch_layout.nb_channels ||
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 71 times.
71 size > INT_MAX / s->streams[0]->codecpar->ch_layout.nb_channels)
95 return AVERROR_INVALIDDATA;
96
97 71 size *= s->streams[0]->codecpar->ch_layout.nb_channels;
98
2/2
✓ Branch 1 taken 3 times.
✓ Branch 2 taken 68 times.
71 if ((ret = avio_skip(s->pb, 24)) < 0) // padding
99 3 return ret;
100
101
1/2
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
68 if (type == MKTAG('B','L','C','K')) {
102 68 ret = av_get_packet(s->pb, pkt, size);
103 68 pkt->stream_index = 0;
104 68 pkt->pos = pos;
105 } else {
106 av_log(s, AV_LOG_ERROR, "unknown chunk %"PRIx32"\n", type);
107 avio_skip(s->pb, size);
108 ret = AVERROR_INVALIDDATA;
109 }
110
111 68 return ret;
112 }
113
114 const AVInputFormat ff_ast_demuxer = {
115 .name = "ast",
116 .long_name = NULL_IF_CONFIG_SMALL("AST (Audio Stream)"),
117 .read_probe = ast_probe,
118 .read_header = ast_read_header,
119 .read_packet = ast_read_packet,
120 .extensions = "ast",
121 .flags = AVFMT_GENERIC_INDEX,
122 .codec_tag = ff_ast_codec_tags_list,
123 };
124