FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/audio.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 37 45 82.2%
Branches: 21 30 70.0%

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 "framepool.h"
30 #include "internal.h"
31
32 AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
33 {
34 return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
35 }
36
37 410163 AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
38 {
39 410163 AVFrame *frame = NULL;
40 410163 int channels = link->ch_layout.nb_channels;
41 #if FF_API_OLD_CHANNEL_LAYOUT
42 FF_DISABLE_DEPRECATION_WARNINGS
43 410163 int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
44 410163 int align = av_cpu_max_align();
45
46
3/4
✓ Branch 0 taken 557 times.
✓ Branch 1 taken 409606 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 557 times.
410163 av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels);
47 FF_ENABLE_DEPRECATION_WARNINGS
48 #endif
49
50
2/2
✓ Branch 0 taken 1440 times.
✓ Branch 1 taken 408723 times.
410163 if (!link->frame_pool) {
51 2880 link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
52 1440 nb_samples, link->format, align);
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1440 times.
1440 if (!link->frame_pool)
54 return NULL;
55 } else {
56 408723 int pool_channels = 0;
57 408723 int pool_nb_samples = 0;
58 408723 int pool_align = 0;
59 408723 enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE;
60
61
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 408723 times.
408723 if (ff_frame_pool_get_audio_config(link->frame_pool,
62 &pool_channels, &pool_nb_samples,
63 &pool_format, &pool_align) < 0) {
64 return NULL;
65 }
66
67
3/4
✓ Branch 0 taken 408723 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 406750 times.
✓ Branch 3 taken 1973 times.
408723 if (pool_channels != channels || pool_nb_samples < nb_samples ||
68
2/4
✓ Branch 0 taken 406750 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 406750 times.
406750 pool_format != link->format || pool_align != align) {
69
70 1973 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
71 3946 link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
72 1973 nb_samples, link->format, align);
73
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1973 times.
1973 if (!link->frame_pool)
74 return NULL;
75 }
76 }
77
78 410163 frame = ff_frame_pool_get(link->frame_pool);
79
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 410163 times.
410163 if (!frame)
80 return NULL;
81
82 410163 frame->nb_samples = nb_samples;
83 #if FF_API_OLD_CHANNEL_LAYOUT
84 FF_DISABLE_DEPRECATION_WARNINGS
85 410163 frame->channel_layout = link->channel_layout;
86 FF_ENABLE_DEPRECATION_WARNINGS
87 #endif
88
3/4
✓ Branch 0 taken 409606 times.
✓ Branch 1 taken 557 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 409606 times.
819769 if (link->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC &&
89 409606 av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) {
90 av_frame_free(&frame);
91 return NULL;
92 }
93 410163 frame->sample_rate = link->sample_rate;
94
95 410163 av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format);
96
97 410163 return frame;
98 }
99
100 410513 AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
101 {
102 410513 AVFrame *ret = NULL;
103
104
2/2
✓ Branch 0 taken 350 times.
✓ Branch 1 taken 410163 times.
410513 if (link->dstpad->get_buffer.audio)
105 350 ret = link->dstpad->get_buffer.audio(link, nb_samples);
106
107
2/2
✓ Branch 0 taken 410163 times.
✓ Branch 1 taken 350 times.
410513 if (!ret)
108 410163 ret = ff_default_get_audio_buffer(link, nb_samples);
109
110 410513 return ret;
111 }
112