FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/pvfdec.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 3 23 13.0%
Functions: 1 2 50.0%
Branches: 1 16 6.2%

Line Branch Exec Source
1 /*
2 * PVF demuxer
3 * Copyright (c) 2012 Paul B Mahol
4 *
5 * This file is part of FFmpeg.
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "libavcodec/internal.h"
23 #include "avformat.h"
24 #include "demux.h"
25 #include "internal.h"
26 #include "pcm.h"
27
28 7186 static int pvf_probe(const AVProbeData *p)
29 {
30
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7186 times.
7186 if (!memcmp(p->buf, "PVF1\n", 5))
31 return AVPROBE_SCORE_MAX;
32 7186 return 0;
33 }
34
35 static int pvf_read_header(AVFormatContext *s)
36 {
37 char buffer[32];
38 AVStream *st;
39 int bps, channels, sample_rate;
40
41 avio_skip(s->pb, 5);
42 ff_get_line(s->pb, buffer, sizeof(buffer));
43 if (sscanf(buffer, "%d %d %d",
44 &channels,
45 &sample_rate,
46 &bps) != 3)
47 return AVERROR_INVALIDDATA;
48
49 if (channels <= 0 || channels > FF_SANE_NB_CHANNELS ||
50 bps <= 0 || bps > INT_MAX / FF_SANE_NB_CHANNELS || sample_rate <= 0)
51 return AVERROR_INVALIDDATA;
52
53 st = avformat_new_stream(s, NULL);
54 if (!st)
55 return AVERROR(ENOMEM);
56
57 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
58 st->codecpar->ch_layout.nb_channels = channels;
59 st->codecpar->sample_rate = sample_rate;
60 st->codecpar->codec_id = ff_get_pcm_codec_id(bps, 0, 1, 0xFFFF);
61 st->codecpar->bits_per_coded_sample = bps;
62 st->codecpar->block_align = bps * st->codecpar->ch_layout.nb_channels / 8;
63
64 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
65
66 return 0;
67 }
68
69 const FFInputFormat ff_pvf_demuxer = {
70 .p.name = "pvf",
71 .p.long_name = NULL_IF_CONFIG_SMALL("PVF (Portable Voice Format)"),
72 .p.extensions = "pvf",
73 .p.flags = AVFMT_GENERIC_INDEX,
74 .read_probe = pvf_probe,
75 .read_header = pvf_read_header,
76 .read_packet = ff_pcm_read_packet,
77 .read_seek = ff_pcm_read_seek,
78 };
79