3 * Copyright (c) 2017 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/avstring.h"
23 #include "libavutil/intreadwrite.h"
28 static int sdx_probe(const AVProbeData
*p
)
30 if (AV_RB32(p
->buf
) == AV_RB32("SDX:"))
31 return AVPROBE_SCORE_EXTENSION
;
35 static int sdx_read_header(AVFormatContext
*s
)
41 while (!avio_feof(s
->pb
)) {
42 if (avio_r8(s
->pb
) == 0x1a)
45 if (avio_r8(s
->pb
) != 1)
46 return AVERROR_INVALIDDATA
;
47 length
= avio_r8(s
->pb
);
48 avio_skip(s
->pb
, length
);
50 depth
= avio_r8(s
->pb
);
52 st
= avformat_new_stream(s
, NULL
);
54 return AVERROR(ENOMEM
);
56 st
->codecpar
->codec_type
= AVMEDIA_TYPE_AUDIO
;
57 st
->codecpar
->channels
= 1;
58 st
->codecpar
->sample_rate
= avio_rl32(s
->pb
);
61 st
->codecpar
->codec_id
= AV_CODEC_ID_PCM_U8
;
64 st
->codecpar
->codec_id
= AV_CODEC_ID_PCM_U16LE
;
67 st
->codecpar
->codec_id
= AV_CODEC_ID_PCM_U24LE
;
70 st
->codecpar
->codec_id
= AV_CODEC_ID_PCM_U32LE
;
73 return AVERROR_INVALIDDATA
;
76 st
->codecpar
->block_align
= depth
/ 8;
81 AVInputFormat ff_sdx_demuxer
= {
83 .long_name
= NULL_IF_CONFIG_SMALL("Sample Dump eXchange"),
84 .read_probe
= sdx_probe
,
85 .read_header
= sdx_read_header
,
86 .read_packet
= ff_pcm_read_packet
,
87 .read_seek
= ff_pcm_read_seek
,
89 .flags
= AVFMT_GENERIC_INDEX
,