Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Copyright (c) 2021 Paul B Mahol | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #include "libavutil/intreadwrite.h" | ||
22 | #include "avformat.h" | ||
23 | #include "demux.h" | ||
24 | #include "internal.h" | ||
25 | |||
26 | 7186 | static int binka_probe(const AVProbeData *p) | |
27 | { | ||
28 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7186 times.
|
7186 | if (AV_RB32(p->buf) == MKBETAG('1', 'F', 'C', 'B') && |
29 | ✗ | (p->buf[4] == 1 || p->buf[4] == 2)) | |
30 | ✗ | return AVPROBE_SCORE_MAX; | |
31 | 7186 | return 0; | |
32 | } | ||
33 | |||
34 | ✗ | static int binka_read_header(AVFormatContext *s) | |
35 | { | ||
36 | ✗ | AVIOContext *pb = s->pb; | |
37 | AVStream *st; | ||
38 | int entries, offset; | ||
39 | |||
40 | ✗ | st = avformat_new_stream(s, NULL); | |
41 | ✗ | if (!st) | |
42 | ✗ | return AVERROR(ENOMEM); | |
43 | |||
44 | ✗ | avio_skip(pb, 5); | |
45 | |||
46 | ✗ | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
47 | ✗ | st->codecpar->codec_id = AV_CODEC_ID_BINKAUDIO_DCT; | |
48 | ✗ | st->codecpar->ch_layout.nb_channels = avio_r8(pb); | |
49 | ✗ | st->codecpar->sample_rate = avio_rl16(pb); | |
50 | ✗ | st->duration = avio_rl32(pb); | |
51 | |||
52 | ✗ | avio_skip(pb, 8); | |
53 | ✗ | entries = avio_rl16(pb); | |
54 | |||
55 | ✗ | offset = entries * 2 + 2; | |
56 | ✗ | avio_skip(pb, offset); | |
57 | |||
58 | ✗ | avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); | |
59 | |||
60 | ✗ | return 0; | |
61 | } | ||
62 | |||
63 | ✗ | static int binka_read_packet(AVFormatContext *s, AVPacket *pkt) | |
64 | { | ||
65 | ✗ | AVIOContext *pb = s->pb; | |
66 | ✗ | AVStream *st = s->streams[0]; | |
67 | int64_t pos; | ||
68 | int pkt_size; | ||
69 | int ret; | ||
70 | |||
71 | ✗ | if (avio_feof(pb)) | |
72 | ✗ | return AVERROR_EOF; | |
73 | |||
74 | ✗ | pos = avio_tell(pb); | |
75 | ✗ | avio_skip(pb, 2); | |
76 | ✗ | pkt_size = avio_rl16(pb) + 4; | |
77 | ✗ | if (pkt_size <= 4) | |
78 | ✗ | return AVERROR(EIO); | |
79 | ✗ | ret = av_new_packet(pkt, pkt_size); | |
80 | ✗ | if (ret < 0) | |
81 | ✗ | return ret; | |
82 | |||
83 | ✗ | avio_read(pb, pkt->data + 4, pkt_size - 4); | |
84 | ✗ | AV_WL32(pkt->data, pkt_size); | |
85 | |||
86 | ✗ | pkt->pos = pos; | |
87 | ✗ | pkt->stream_index = 0; | |
88 | ✗ | pkt->duration = av_get_audio_frame_duration2(st->codecpar, 0); | |
89 | |||
90 | ✗ | return 0; | |
91 | } | ||
92 | |||
93 | const FFInputFormat ff_binka_demuxer = { | ||
94 | .p.name = "binka", | ||
95 | .p.long_name = NULL_IF_CONFIG_SMALL("Bink Audio"), | ||
96 | .p.flags = AVFMT_GENERIC_INDEX, | ||
97 | .p.extensions = "binka", | ||
98 | .read_probe = binka_probe, | ||
99 | .read_header = binka_read_header, | ||
100 | .read_packet = binka_read_packet, | ||
101 | }; | ||
102 |