3 * Copyright (c) 2020 Paul B Mahol
5 * This file is part of FFmpeg.
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.
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.
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
22 #include "libavutil/channel_layout.h"
23 #include "libavutil/intreadwrite.h"
27 static int svs_probe(const AVProbeData *p)
32 if (memcmp(p->buf, "SVS\00", 4))
35 if (AV_RL32(p->buf + 16) == 0)
38 return AVPROBE_SCORE_MAX / 3;
41 static int svs_read_header(AVFormatContext *s)
46 st = avformat_new_stream(s, NULL);
48 return AVERROR(ENOMEM);
51 pitch = avio_rl32(s->pb);
54 s->internal->data_offset = avio_tell(s->pb);
55 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
56 st->codecpar->codec_id = AV_CODEC_ID_ADPCM_PSX;
57 st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
58 st->codecpar->channels = 2;
59 st->codecpar->sample_rate = av_rescale_rnd(pitch, 48000, 4096, AV_ROUND_INF);
60 st->codecpar->block_align = 32;
62 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL)
63 st->duration = av_get_audio_frame_duration2(st->codecpar,
64 avio_size(s->pb) - 32);
66 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
71 static int svs_read_packet(AVFormatContext *s, AVPacket *pkt)
78 ret = av_get_packet(s->pb, pkt, 32 * 256);
79 if (ret != 32 * 256) {
82 pkt->flags &= ~AV_PKT_FLAG_CORRUPT;
84 pkt->stream_index = 0;
89 const AVInputFormat ff_svs_demuxer = {
91 .long_name = NULL_IF_CONFIG_SMALL("Square SVS"),
92 .read_probe = svs_probe,
93 .read_header = svs_read_header,
94 .read_packet = svs_read_packet,