| 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 "avio_internal.h" | ||
| 24 | #include "demux.h" | ||
| 25 | #include "internal.h" | ||
| 26 | |||
| 27 | 7957 | static int binka_probe(const AVProbeData *p) | |
| 28 | { | ||
| 29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7957 times.
|
7957 | if (AV_RB32(p->buf) == MKBETAG('1', 'F', 'C', 'B') && |
| 30 | ✗ | (p->buf[4] == 1 || p->buf[4] == 2)) | |
| 31 | ✗ | return AVPROBE_SCORE_MAX; | |
| 32 | 7957 | return 0; | |
| 33 | } | ||
| 34 | |||
| 35 | ✗ | static int binka_read_header(AVFormatContext *s) | |
| 36 | { | ||
| 37 | ✗ | AVIOContext *pb = s->pb; | |
| 38 | AVStream *st; | ||
| 39 | int entries, offset; | ||
| 40 | |||
| 41 | ✗ | st = avformat_new_stream(s, NULL); | |
| 42 | ✗ | if (!st) | |
| 43 | ✗ | return AVERROR(ENOMEM); | |
| 44 | |||
| 45 | ✗ | avio_skip(pb, 5); | |
| 46 | |||
| 47 | ✗ | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
| 48 | ✗ | st->codecpar->codec_id = AV_CODEC_ID_BINKAUDIO_DCT; | |
| 49 | ✗ | st->codecpar->ch_layout.nb_channels = avio_r8(pb); | |
| 50 | ✗ | st->codecpar->sample_rate = avio_rl16(pb); | |
| 51 | ✗ | st->duration = avio_rl32(pb); | |
| 52 | |||
| 53 | ✗ | avio_skip(pb, 8); | |
| 54 | ✗ | entries = avio_rl16(pb); | |
| 55 | |||
| 56 | ✗ | offset = entries * 2 + 2; | |
| 57 | ✗ | avio_skip(pb, offset); | |
| 58 | |||
| 59 | ✗ | avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate); | |
| 60 | |||
| 61 | ✗ | return 0; | |
| 62 | } | ||
| 63 | |||
| 64 | ✗ | static int binka_read_packet(AVFormatContext *s, AVPacket *pkt) | |
| 65 | { | ||
| 66 | ✗ | AVIOContext *pb = s->pb; | |
| 67 | ✗ | AVStream *st = s->streams[0]; | |
| 68 | int64_t pos; | ||
| 69 | int pkt_size; | ||
| 70 | int ret; | ||
| 71 | |||
| 72 | ✗ | if (avio_feof(pb)) | |
| 73 | ✗ | return AVERROR_EOF; | |
| 74 | |||
| 75 | ✗ | pos = avio_tell(pb); | |
| 76 | ✗ | avio_skip(pb, 2); | |
| 77 | ✗ | pkt_size = avio_rl16(pb) + 4; | |
| 78 | ✗ | if (pkt_size <= 4) | |
| 79 | ✗ | return AVERROR_INVALIDDATA; | |
| 80 | ✗ | ret = av_new_packet(pkt, pkt_size); | |
| 81 | ✗ | if (ret < 0) | |
| 82 | ✗ | return ret; | |
| 83 | |||
| 84 | ✗ | ret = ffio_read_size(pb, pkt->data + 4, pkt_size - 4); | |
| 85 | ✗ | if (ret < 0) | |
| 86 | ✗ | return ret; | |
| 87 | ✗ | AV_WL32(pkt->data, pkt_size); | |
| 88 | |||
| 89 | ✗ | pkt->pos = pos; | |
| 90 | ✗ | pkt->stream_index = 0; | |
| 91 | ✗ | pkt->duration = av_get_audio_frame_duration2(st->codecpar, 0); | |
| 92 | |||
| 93 | ✗ | return 0; | |
| 94 | } | ||
| 95 | |||
| 96 | const FFInputFormat ff_binka_demuxer = { | ||
| 97 | .p.name = "binka", | ||
| 98 | .p.long_name = NULL_IF_CONFIG_SMALL("Bink Audio"), | ||
| 99 | .p.flags = AVFMT_GENERIC_INDEX, | ||
| 100 | .p.extensions = "binka", | ||
| 101 | .read_probe = binka_probe, | ||
| 102 | .read_header = binka_read_header, | ||
| 103 | .read_packet = binka_read_packet, | ||
| 104 | }; | ||
| 105 |