Coverage Report

Created: 2026-04-01 07:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavformat/apac.c
Line
Count
Source
1
/*
2
 * APAC demuxer
3
 * Copyright (c) 2022 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/intreadwrite.h"
23
#include "avformat.h"
24
#include "demux.h"
25
#include "internal.h"
26
#include "rawdec.h"
27
28
static int apac_probe(const AVProbeData *p)
29
959k
{
30
959k
    if (AV_RB32(p->buf) == MKBETAG('A','P','A','C') &&
31
245
        AV_RB32(p->buf + 8) == MKBETAG('P','R','O','F') &&
32
25
        AV_RB32(p->buf + 12) == MKBETAG('N','A','D',' '))
33
0
        return AVPROBE_SCORE_MAX;
34
35
959k
    return 0;
36
959k
}
37
38
static int apac_read_header(AVFormatContext *s)
39
976
{
40
976
    AVIOContext *pb = s->pb;
41
976
    uint32_t chunk_size;
42
976
    AVStream *st;
43
976
    int64_t pos;
44
45
976
    avio_skip(pb, 16);
46
976
    chunk_size = avio_rl32(pb);
47
976
    avio_skip(pb, chunk_size);
48
976
    if (avio_rb32(pb) != MKBETAG('P','F','M','T'))
49
441
        return AVERROR_INVALIDDATA;
50
535
    chunk_size = avio_rl32(pb);
51
535
    pos = avio_tell(pb);
52
535
    avio_skip(pb, 2);
53
535
    st = avformat_new_stream(s, NULL);
54
535
    if (!st)
55
0
        return AVERROR(ENOMEM);
56
535
    st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
57
535
    st->codecpar->codec_id    = AV_CODEC_ID_APAC;
58
535
    st->codecpar->ch_layout.nb_channels = avio_rl16(pb);
59
535
    st->codecpar->sample_rate = avio_rl32(pb);
60
535
    if (st->codecpar->ch_layout.nb_channels <= 0 ||
61
524
        st->codecpar->ch_layout.nb_channels >  2 ||
62
506
        st->codecpar->sample_rate <= 0)
63
62
        return AVERROR_INVALIDDATA;
64
473
    avio_skip(pb, 2);
65
473
    st->codecpar->bits_per_coded_sample = avio_rl16(pb);
66
473
    avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
67
473
    avio_skip(pb, (chunk_size + pos) - avio_tell(pb) + (chunk_size & 1));
68
473
    if (avio_rb32(pb) != MKBETAG('P','A','D',' '))
69
164
        return AVERROR_INVALIDDATA;
70
309
    avio_skip(pb, 4);
71
72
309
    return 0;
73
473
}
74
75
const FFInputFormat ff_apac_demuxer = {
76
    .p.name         = "apac",
77
    .p.long_name    = NULL_IF_CONFIG_SMALL("raw APAC"),
78
    .p.extensions   = "apc",
79
    .p.flags        = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK | AVFMT_NOTIMESTAMPS,
80
    .p.priv_class   = &ff_raw_demuxer_class,
81
    .read_probe     = apac_probe,
82
    .read_header    = apac_read_header,
83
    .read_packet    = ff_raw_read_partial_packet,
84
    .raw_codec_id   = AV_CODEC_ID_APAC,
85
    .priv_data_size = sizeof(FFRawDemuxerContext),
86
};