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 | 228053 | AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) | |
46 | { | ||
47 | 228053 | AVFrame *frame = NULL; | |
48 | 228053 | FilterLinkInternal *const li = ff_link_internal(link); | |
49 | 228053 | int channels = link->ch_layout.nb_channels; | |
50 | 228053 | int align = av_cpu_max_align(); | |
51 | |||
52 |
2/2✓ Branch 0 taken 1474 times.
✓ Branch 1 taken 226579 times.
|
228053 | if (!li->frame_pool) { |
53 | 2948 | li->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, | |
54 | 1474 | nb_samples, link->format, align); | |
55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1474 times.
|
1474 | if (!li->frame_pool) |
56 | ✗ | return NULL; | |
57 | } else { | ||
58 | 226579 | int pool_channels = 0; | |
59 | 226579 | int pool_nb_samples = 0; | |
60 | 226579 | int pool_align = 0; | |
61 | 226579 | enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE; | |
62 | |||
63 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 226579 times.
|
226579 | 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 226579 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 225096 times.
✓ Branch 3 taken 1483 times.
|
226579 | if (pool_channels != channels || pool_nb_samples < nb_samples || |
70 |
2/4✓ Branch 0 taken 225096 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 225096 times.
|
225096 | pool_format != link->format || pool_align != align) { |
71 | |||
72 | 1483 | ff_frame_pool_uninit(&li->frame_pool); | |
73 | 2966 | li->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, | |
74 | 1483 | nb_samples, link->format, align); | |
75 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1483 times.
|
1483 | if (!li->frame_pool) |
76 | ✗ | return NULL; | |
77 | } | ||
78 | } | ||
79 | |||
80 | 228053 | frame = ff_frame_pool_get(li->frame_pool); | |
81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 228053 times.
|
228053 | if (!frame) |
82 | ✗ | return NULL; | |
83 | |||
84 | 228053 | frame->nb_samples = nb_samples; | |
85 |
3/4✓ Branch 0 taken 226041 times.
✓ Branch 1 taken 2012 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 226041 times.
|
454094 | if (link->ch_layout.order != AV_CHANNEL_ORDER_UNSPEC && |
86 | 226041 | av_channel_layout_copy(&frame->ch_layout, &link->ch_layout) < 0) { | |
87 | ✗ | av_frame_free(&frame); | |
88 | ✗ | return NULL; | |
89 | } | ||
90 | 228053 | frame->sample_rate = link->sample_rate; | |
91 | |||
92 | 228053 | av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format); | |
93 | |||
94 | 228053 | return frame; | |
95 | } | ||
96 | |||
97 | 228133 | AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples) | |
98 | { | ||
99 | 228133 | AVFrame *ret = NULL; | |
100 | |||
101 |
2/2✓ Branch 0 taken 397 times.
✓ Branch 1 taken 227736 times.
|
228133 | if (link->dstpad->get_buffer.audio) |
102 | 397 | ret = link->dstpad->get_buffer.audio(link, nb_samples); | |
103 | |||
104 |
2/2✓ Branch 0 taken 227736 times.
✓ Branch 1 taken 397 times.
|
228133 | if (!ret) |
105 | 227736 | ret = ff_default_get_audio_buffer(link, nb_samples); | |
106 | |||
107 | 228133 | return ret; | |
108 | } | ||
109 |