FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavformat/dfpwmdec.c
Date: 2024-04-19 17:50:32
Exec Total Coverage
Lines: 14 16 87.5%
Functions: 1 1 100.0%
Branches: 2 4 50.0%

Line Branch Exec Source
1 /*
2 * RAW PCM demuxers
3 * Copyright (c) 2002 Fabrice Bellard
4 * Copyright (c) 2022 Jack Bruienne
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "libavutil/avstring.h"
24 #include "avformat.h"
25 #include "demux.h"
26 #include "internal.h"
27 #include "pcm.h"
28 #include "libavutil/log.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/avassert.h"
31
32 typedef struct DFPWMAudioDemuxerContext {
33 AVClass *class;
34 int sample_rate;
35 AVChannelLayout ch_layout;
36 } DFPWMAudioDemuxerContext;
37
38 1 static int dfpwm_read_header(AVFormatContext *s)
39 {
40 1 DFPWMAudioDemuxerContext *s1 = s->priv_data;
41 AVCodecParameters *par;
42 AVStream *st;
43 int ret;
44
45 1 st = avformat_new_stream(s, NULL);
46
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!st)
47 return AVERROR(ENOMEM);
48 1 par = st->codecpar;
49
50 1 par->codec_type = AVMEDIA_TYPE_AUDIO;
51 1 par->codec_id = AV_CODEC_ID_DFPWM;
52 1 par->sample_rate = s1->sample_rate;
53 1 ret = av_channel_layout_copy(&par->ch_layout, &s1->ch_layout);
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret < 0)
55 return ret;
56 1 par->bits_per_coded_sample = 1;
57 1 par->block_align = 1;
58
59 1 avpriv_set_pts_info(st, 64, 1, par->sample_rate);
60 1 return 0;
61 }
62
63 static const AVOption dfpwm_options[] = {
64 { "sample_rate", "", offsetof(DFPWMAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.i64 = 48000}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
65 { "ch_layout", "", offsetof(DFPWMAudioDemuxerContext, ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "mono"}, 0, 0, AV_OPT_FLAG_DECODING_PARAM },
66 { NULL },
67 };
68 static const AVClass dfpwm_demuxer_class = {
69 .class_name = "dfpwm demuxer",
70 .item_name = av_default_item_name,
71 .option = dfpwm_options,
72 .version = LIBAVUTIL_VERSION_INT,
73 };
74
75 const FFInputFormat ff_dfpwm_demuxer = {
76 .p.name = "dfpwm",
77 .p.long_name = NULL_IF_CONFIG_SMALL("raw DFPWM1a"),
78 .p.flags = AVFMT_GENERIC_INDEX,
79 .p.extensions = "dfpwm",
80 .p.priv_class = &dfpwm_demuxer_class,
81 .priv_data_size = sizeof(DFPWMAudioDemuxerContext),
82 .read_header = dfpwm_read_header,
83 .read_packet = ff_pcm_read_packet,
84 .read_seek = ff_pcm_read_seek,
85 .raw_codec_id = AV_CODEC_ID_DFPWM,
86 };
87