/src/ffmpeg/libavformat/apac.c
Line | Count | Source (jump to first uncovered line) |
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 | 924k | { |
30 | 924k | if (AV_RB32(p->buf) == MKBETAG('A','P','A','C') && |
31 | 924k | AV_RB32(p->buf + 8) == MKBETAG('P','R','O','F') && |
32 | 924k | AV_RB32(p->buf + 12) == MKBETAG('N','A','D',' ')) |
33 | 0 | return AVPROBE_SCORE_MAX; |
34 | | |
35 | 924k | return 0; |
36 | 924k | } |
37 | | |
38 | | static int apac_read_header(AVFormatContext *s) |
39 | 6.04k | { |
40 | 6.04k | AVIOContext *pb = s->pb; |
41 | 6.04k | uint32_t chunk_size; |
42 | 6.04k | AVStream *st; |
43 | 6.04k | int64_t pos; |
44 | | |
45 | 6.04k | avio_skip(pb, 16); |
46 | 6.04k | chunk_size = avio_rl32(pb); |
47 | 6.04k | avio_skip(pb, chunk_size); |
48 | 6.04k | if (avio_rb32(pb) != MKBETAG('P','F','M','T')) |
49 | 5.64k | return AVERROR_INVALIDDATA; |
50 | 395 | chunk_size = avio_rl32(pb); |
51 | 395 | pos = avio_tell(pb); |
52 | 395 | avio_skip(pb, 2); |
53 | 395 | st = avformat_new_stream(s, NULL); |
54 | 395 | if (!st) |
55 | 0 | return AVERROR(ENOMEM); |
56 | 395 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; |
57 | 395 | st->codecpar->codec_id = AV_CODEC_ID_APAC; |
58 | 395 | st->codecpar->ch_layout.nb_channels = avio_rl16(pb); |
59 | 395 | st->codecpar->sample_rate = avio_rl32(pb); |
60 | 395 | if (st->codecpar->ch_layout.nb_channels <= 0 || |
61 | 395 | st->codecpar->ch_layout.nb_channels > 2 || |
62 | 395 | st->codecpar->sample_rate <= 0) |
63 | 61 | return AVERROR_INVALIDDATA; |
64 | 334 | avio_skip(pb, 2); |
65 | 334 | st->codecpar->bits_per_coded_sample = avio_rl16(pb); |
66 | 334 | avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); |
67 | 334 | avio_skip(pb, (chunk_size + pos) - avio_tell(pb) + (chunk_size & 1)); |
68 | 334 | if (avio_rb32(pb) != MKBETAG('P','A','D',' ')) |
69 | 105 | return AVERROR_INVALIDDATA; |
70 | 229 | avio_skip(pb, 4); |
71 | | |
72 | 229 | return 0; |
73 | 334 | } |
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 | | }; |