3 * Copyright (c) 2012 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 "libavcodec/internal.h"
27 static int pvf_probe(const AVProbeData
*p
)
29 if (!memcmp(p
->buf
, "PVF1\n", 5))
30 return AVPROBE_SCORE_MAX
;
34 static int pvf_read_header(AVFormatContext
*s
)
38 int bps
, channels
, sample_rate
;
41 ff_get_line(s
->pb
, buffer
, sizeof(buffer
));
42 if (sscanf(buffer
, "%d %d %d",
46 return AVERROR_INVALIDDATA
;
48 if (channels
<= 0 || channels
> FF_SANE_NB_CHANNELS
||
49 bps
<= 0 || bps
> INT_MAX
/ FF_SANE_NB_CHANNELS
|| sample_rate
<= 0)
50 return AVERROR_INVALIDDATA
;
52 st
= avformat_new_stream(s
, NULL
);
54 return AVERROR(ENOMEM
);
56 st
->codecpar
->codec_type
= AVMEDIA_TYPE_AUDIO
;
57 st
->codecpar
->channels
= channels
;
58 st
->codecpar
->sample_rate
= sample_rate
;
59 st
->codecpar
->codec_id
= ff_get_pcm_codec_id(bps
, 0, 1, 0xFFFF);
60 st
->codecpar
->bits_per_coded_sample
= bps
;
61 st
->codecpar
->block_align
= bps
* st
->codecpar
->channels
/ 8;
63 avpriv_set_pts_info(st
, 64, 1, st
->codecpar
->sample_rate
);
68 AVInputFormat ff_pvf_demuxer
= {
70 .long_name
= NULL_IF_CONFIG_SMALL("PVF (Portable Voice Format)"),
71 .read_probe
= pvf_probe
,
72 .read_header
= pvf_read_header
,
73 .read_packet
= ff_pcm_read_packet
,
74 .read_seek
= ff_pcm_read_seek
,
76 .flags
= AVFMT_GENERIC_INDEX
,