FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/audio.c
Date: 2024-07-24 19:24:46
Exec Total Coverage
Lines: 37 43 86.0%
Functions: 3 3 100.0%
Branches: 18 26 69.2%

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
27 #include "audio.h"
28 #include "avfilter.h"
29 #include "avfilter_internal.h"
30 #include "framepool.h"
31 #include "internal.h"
32
33 const AVFilterPad ff_audio_default_filterpad[1] = {
34 {
35 .name = "default",
36 .type = AVMEDIA_TYPE_AUDIO,
37 }
38 };
39
40 45 AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
41 {
42 45 return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
43 }
44
45 231998 AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
46 {
47 231998 AVFrame *frame = NULL;
48 231998 FilterLinkInternal *const li = ff_link_internal(link);
49 231998 int channels = link->ch_layout.nb_channels;
50 231998 int align = av_cpu_max_align();
51
52
2/2
✓ Branch 0 taken 1477 times.
✓ Branch 1 taken 230521 times.
231998 if (!li->frame_pool) {
53 2954 li->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
54 1477 nb_samples, link->format, align);
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1477 times.
1477 if (!li->frame_pool)
56 return NULL;
57 } else {
58 230521 int pool_channels = 0;
59 230521 int pool_nb_samples = 0;
60 230521 int pool_align = 0;
61 230521 enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE;
62
63
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 230521 times.
230521 if (ff_frame_pool_get_audio_config(li->frame_pool,
64 &pool_channels, &pool_nb_samples,
65 &pool_format, &pool_align) < 0) {
66 return NULL;
67 }
68
69
3/4
✓ Branch 0 taken 230521 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 229033 times.
✓ Branch 3 taken 1488 times.
230521 if (pool_channels != channels || pool_nb_samples < nb_samples ||
70
2/4
✓ Branch 0 taken 229033 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 229033 times.
229033 pool_format != link->format || pool_align != align) {
71
72 1488 ff_frame_pool_uninit(&li->frame_pool);
73 2976 li->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
74 1488 nb_samples, link->format, align);
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1488 times.
1488 if (!li->frame_pool)
76 return NULL;
77 }
78 }
79
80 231998 frame = ff_frame_pool_get(li->frame_pool);
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 231998 times.
231998 if (!frame)
82 return NULL;
83
84 231998 frame->nb_samples = nb_samples;
85
3/4
✓ Branch 0 taken 229986 times.
✓ Branch 1 taken 2012 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 229986 times.
461984 if (link->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC &&
86 229986 av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) {
87 av_frame_free(&frame);
88 return NULL;
89 }
90 231998 frame->sample_rate = link->sample_rate;
91
92 231998 av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format);
93
94 231998 return frame;
95 }
96
97 232078 AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
98 {
99 232078 AVFrame *ret = NULL;
100
101
2/2
✓ Branch 0 taken 397 times.
✓ Branch 1 taken 231681 times.
232078 if (link->dstpad->get_buffer.audio)
102 397 ret = link->dstpad->get_buffer.audio(link, nb_samples);
103
104
2/2
✓ Branch 0 taken 231681 times.
✓ Branch 1 taken 397 times.
232078 if (!ret)
105 231681 ret = ff_default_get_audio_buffer(link, nb_samples);
106
107 232078 return ret;
108 }
109