Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * RAW AC-4 demuxer | ||
3 | * Copyright (c) 2019 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/avassert.h" | ||
23 | #include "libavutil/crc.h" | ||
24 | #include "avformat.h" | ||
25 | #include "demux.h" | ||
26 | #include "rawdec.h" | ||
27 | |||
28 | 7186 | static int ac4_probe(const AVProbeData *p) | |
29 | { | ||
30 | 7186 | const uint8_t *buf = p->buf; | |
31 | 7186 | int left = p->buf_size; | |
32 | 7186 | int max_frames = 0; | |
33 | |||
34 |
1/2✓ Branch 0 taken 7186 times.
✗ Branch 1 not taken.
|
7186 | while (left > 7) { |
35 | int size; | ||
36 | |||
37 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7186 times.
|
7186 | if (buf[0] == 0xAC && |
38 | ✗ | (buf[1] == 0x40 || | |
39 | ✗ | buf[1] == 0x41)) { | |
40 | ✗ | size = (buf[2] << 8) | buf[3]; | |
41 | ✗ | if (size == 0xFFFF) | |
42 | ✗ | size = 3 + ((buf[4] << 16) | (buf[5] << 8) | buf[6]); | |
43 | ✗ | size += 4; | |
44 | ✗ | if (buf[1] == 0x41) | |
45 | ✗ | size += 2; | |
46 | ✗ | if (left < size) | |
47 | ✗ | break; | |
48 | ✗ | max_frames++; | |
49 | ✗ | left -= size; | |
50 | ✗ | buf += size; | |
51 | } else { | ||
52 | break; | ||
53 | } | ||
54 | } | ||
55 | |||
56 | 7186 | return FFMIN(AVPROBE_SCORE_MAX, max_frames * 7); | |
57 | } | ||
58 | |||
59 | ✗ | static int ac4_read_header(AVFormatContext *s) | |
60 | { | ||
61 | AVStream *st; | ||
62 | |||
63 | ✗ | st = avformat_new_stream(s, NULL); | |
64 | ✗ | if (!st) | |
65 | ✗ | return AVERROR(ENOMEM); | |
66 | |||
67 | ✗ | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
68 | ✗ | st->codecpar->codec_id = AV_CODEC_ID_AC4; | |
69 | |||
70 | ✗ | return 0; | |
71 | } | ||
72 | |||
73 | ✗ | static int ac4_read_packet(AVFormatContext *s, AVPacket *pkt) | |
74 | { | ||
75 | ✗ | AVIOContext *pb = s->pb; | |
76 | int64_t pos; | ||
77 | uint16_t sync; | ||
78 | int ret, size; | ||
79 | |||
80 | ✗ | if (avio_feof(s->pb)) | |
81 | ✗ | return AVERROR_EOF; | |
82 | |||
83 | ✗ | pos = avio_tell(s->pb); | |
84 | ✗ | sync = avio_rb16(pb); | |
85 | ✗ | size = avio_rb16(pb); | |
86 | ✗ | if (size == 0xffff) | |
87 | ✗ | size = avio_rb24(pb); | |
88 | |||
89 | ✗ | ret = av_get_packet(pb, pkt, size); | |
90 | ✗ | pkt->pos = pos; | |
91 | ✗ | pkt->stream_index = 0; | |
92 | |||
93 | ✗ | if (sync == 0xAC41) | |
94 | ✗ | avio_skip(pb, 2); | |
95 | |||
96 | ✗ | return ret; | |
97 | } | ||
98 | |||
99 | const FFInputFormat ff_ac4_demuxer = { | ||
100 | .p.name = "ac4", | ||
101 | .p.long_name = NULL_IF_CONFIG_SMALL("raw AC-4"), | ||
102 | .p.flags = AVFMT_GENERIC_INDEX, | ||
103 | .p.extensions = "ac4", | ||
104 | .read_probe = ac4_probe, | ||
105 | .read_header = ac4_read_header, | ||
106 | .read_packet = ac4_read_packet, | ||
107 | }; | ||
108 |