FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/audio.c
Date: 2026-09-28 11:37:26
Exec Total Coverage
Lines: 38 48 79.2%
Functions: 4 5 80.0%
Branches: 20 28 71.4%

Line Branch Exec Source
1 /*
2 * Copyright (c) Stefano Sabatini | stefasab at gmail.com
3 * Copyright (c) S.N. Hemanth Meenakshisundaram | smeenaks at ucsd.edu
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 "libavutil/avassert.h"
23 #include "libavutil/channel_layout.h"
24 #include "libavutil/common.h"
25 #include "libavutil/cpu.h"
26 #include "libavutil/eval.h"
27
28 #include "audio.h"
29 #include "avfilter.h"
30 #include "avfilter_internal.h"
31 #include "filters.h"
32 #include "framepool.h"
33
34 const AVFilterPad ff_audio_default_filterpad[1] = {
35 {
36 .name = "default",
37 .type = AVMEDIA_TYPE_AUDIO,
38 }
39 };
40
41 ✗ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
42 {
43 ✗ return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
44 }
45
46 287956 AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
47 {
48 287956 AVFrame *frame = NULL;
49 287956 FilterLinkInternal *const li = ff_link_internal(link);
50 287956 int channels = link->ch_layout.nb_channels;
51 287956 int align = av_cpu_max_align();
52
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 287956 times.
287956 if (ff_frame_pool_audio_reinit(&li->frame_pool, channels, nb_samples,
54 287956 link->format, align) < 0)
55 ✗ return NULL;
56
57 287956 frame = ff_frame_pool_get(&li->frame_pool);
58
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 287956 times.
287956 if (!frame)
59 ✗ return NULL;
60
61 287956 frame->nb_samples = nb_samples;
62
3/4
✓ Branch 0 taken 252652 times.
✓ Branch 1 taken 35304 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 252652 times.
540608 if (link->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC &&
63 252652 av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) {
64 ✗ av_frame_free(&frame);
65 ✗ return NULL;
66 }
67 287956 frame->sample_rate = link->sample_rate;
68
69 287956 av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format);
70
71 287956 return frame;
72 }
73
74 287991 AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
75 {
76 287991 AVFrame *ret = NULL;
77
78
2/2
✓ Branch 0 taken 350 times.
✓ Branch 1 taken 287641 times.
287991 if (link->dstpad->get_buffer.audio)
79 350 ret = link->dstpad->get_buffer.audio(link, nb_samples);
80
81
2/2
✓ Branch 0 taken 287641 times.
✓ Branch 1 taken 350 times.
287991 if (!ret)
82 287641 ret = ff_default_get_audio_buffer(link, nb_samples);
83
84 287991 return ret;
85 }
86
87 19 int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx)
88 {
89 char *tail;
90 19 double srate = av_strtod(arg, &tail);
91
4/8
✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 19 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 19 times.
19 if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) {
92 ✗ av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg);
93 ✗ return AVERROR(EINVAL);
94 }
95 19 *ret = srate;
96 19 return 0;
97 }
98
99 73 int ff_parse_channel_layout(AVChannelLayout *ret, int *nret, const char *arg,
100 void *log_ctx)
101 {
102 73 AVChannelLayout chlayout = { 0 };
103 int res;
104
105 73 res = av_channel_layout_from_string(&chlayout, arg);
106
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 68 times.
73 if (res < 0) {
107 5 av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg);
108 5 return AVERROR(EINVAL);
109 }
110
111
3/4
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 13 times.
68 if (chlayout.order == AV_CHANNEL_ORDER_UNSPEC && !nret) {
112 ✗ av_log(log_ctx, AV_LOG_ERROR, "Unknown channel layout '%s' is not supported.\n", arg);
113 ✗ return AVERROR(EINVAL);
114 }
115 68 *ret = chlayout;
116
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 1 times.
68 if (nret)
117 67 *nret = chlayout.nb_channels;
118
119 68 return 0;
120 }
121