| Line | Branch | Exec | 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 | 7279 | static int apac_probe(const AVProbeData *p) | |
| 29 | { | ||
| 30 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7279 times.
|
7279 | if (AV_RB32(p->buf) == MKBETAG('A','P','A','C') && |
| 31 | ✗ | AV_RB32(p->buf + 8) == MKBETAG('P','R','O','F') && | |
| 32 | ✗ | AV_RB32(p->buf + 12) == MKBETAG('N','A','D',' ')) | |
| 33 | ✗ | return AVPROBE_SCORE_MAX; | |
| 34 | |||
| 35 | 7279 | return 0; | |
| 36 | } | ||
| 37 | |||
| 38 | ✗ | static int apac_read_header(AVFormatContext *s) | |
| 39 | { | ||
| 40 | ✗ | AVIOContext *pb = s->pb; | |
| 41 | uint32_t chunk_size; | ||
| 42 | AVStream *st; | ||
| 43 | int64_t pos; | ||
| 44 | |||
| 45 | ✗ | avio_skip(pb, 16); | |
| 46 | ✗ | chunk_size = avio_rl32(pb); | |
| 47 | ✗ | avio_skip(pb, chunk_size); | |
| 48 | ✗ | if (avio_rb32(pb) != MKBETAG('P','F','M','T')) | |
| 49 | ✗ | return AVERROR_INVALIDDATA; | |
| 50 | ✗ | chunk_size = avio_rl32(pb); | |
| 51 | ✗ | pos = avio_tell(pb); | |
| 52 | ✗ | avio_skip(pb, 2); | |
| 53 | ✗ | st = avformat_new_stream(s, NULL); | |
| 54 | ✗ | if (!st) | |
| 55 | ✗ | return AVERROR(ENOMEM); | |
| 56 | ✗ | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
| 57 | ✗ | st->codecpar->codec_id = AV_CODEC_ID_APAC; | |
| 58 | ✗ | st->codecpar->ch_layout.nb_channels = avio_rl16(pb); | |
| 59 | ✗ | st->codecpar->sample_rate = avio_rl32(pb); | |
| 60 | ✗ | if (st->codecpar->ch_layout.nb_channels <= 0 || | |
| 61 | ✗ | st->codecpar->ch_layout.nb_channels > 2 || | |
| 62 | ✗ | st->codecpar->sample_rate <= 0) | |
| 63 | ✗ | return AVERROR_INVALIDDATA; | |
| 64 | ✗ | avio_skip(pb, 2); | |
| 65 | ✗ | st->codecpar->bits_per_coded_sample = avio_rl16(pb); | |
| 66 | ✗ | avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); | |
| 67 | ✗ | avio_skip(pb, (chunk_size + pos) - avio_tell(pb) + (chunk_size & 1)); | |
| 68 | ✗ | if (avio_rb32(pb) != MKBETAG('P','A','D',' ')) | |
| 69 | ✗ | return AVERROR_INVALIDDATA; | |
| 70 | ✗ | avio_skip(pb, 4); | |
| 71 | |||
| 72 | ✗ | return 0; | |
| 73 | } | ||
| 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 | }; | ||
| 87 |