... | ... |
@@ -27,6 +27,9 @@ |
27 | 27 |
#include "avfilter.h" |
28 | 28 |
#include "internal.h" |
29 | 29 |
|
30 |
+#define BUFFER_ALIGN 0 |
|
31 |
+ |
|
32 |
+ |
|
30 | 33 |
AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples) |
31 | 34 |
{ |
32 | 35 |
return ff_get_audio_buffer(link->dst->outputs[0], nb_samples); |
... | ... |
@@ -34,29 +37,48 @@ AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples) |
34 | 34 |
|
35 | 35 |
AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) |
36 | 36 |
{ |
37 |
- AVFrame *frame = av_frame_alloc(); |
|
37 |
+ AVFrame *frame = NULL; |
|
38 | 38 |
int channels = link->channels; |
39 |
- int ret; |
|
40 | 39 |
|
41 | 40 |
av_assert0(channels == av_get_channel_layout_nb_channels(link->channel_layout) || !av_get_channel_layout_nb_channels(link->channel_layout)); |
42 | 41 |
|
42 |
+ if (!link->frame_pool) { |
|
43 |
+ link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, |
|
44 |
+ nb_samples, link->format, BUFFER_ALIGN); |
|
45 |
+ if (!link->frame_pool) |
|
46 |
+ return NULL; |
|
47 |
+ } else { |
|
48 |
+ int pool_channels = 0; |
|
49 |
+ int pool_nb_samples = 0; |
|
50 |
+ int pool_align = 0; |
|
51 |
+ enum AVSampleFormat pool_format = AV_SAMPLE_FMT_NONE; |
|
52 |
+ |
|
53 |
+ if (ff_frame_pool_get_audio_config(link->frame_pool, |
|
54 |
+ &pool_channels, &pool_nb_samples, |
|
55 |
+ &pool_format, &pool_align) < 0) { |
|
56 |
+ return NULL; |
|
57 |
+ } |
|
58 |
+ |
|
59 |
+ if (pool_channels != channels || pool_nb_samples < nb_samples || |
|
60 |
+ pool_format != link->format || pool_align != BUFFER_ALIGN) { |
|
61 |
+ |
|
62 |
+ ff_frame_pool_uninit((FFFramePool **)&link->frame_pool); |
|
63 |
+ link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels, |
|
64 |
+ nb_samples, link->format, BUFFER_ALIGN); |
|
65 |
+ if (!link->frame_pool) |
|
66 |
+ return NULL; |
|
67 |
+ } |
|
68 |
+ } |
|
69 |
+ |
|
70 |
+ frame = ff_frame_pool_get(link->frame_pool); |
|
43 | 71 |
if (!frame) |
44 | 72 |
return NULL; |
45 | 73 |
|
46 |
- frame->nb_samples = nb_samples; |
|
47 |
- frame->format = link->format; |
|
48 |
- av_frame_set_channels(frame, link->channels); |
|
74 |
+ frame->nb_samples = nb_samples; |
|
49 | 75 |
frame->channel_layout = link->channel_layout; |
50 |
- frame->sample_rate = link->sample_rate; |
|
51 |
- ret = av_frame_get_buffer(frame, 0); |
|
52 |
- if (ret < 0) { |
|
53 |
- av_frame_free(&frame); |
|
54 |
- return NULL; |
|
55 |
- } |
|
56 |
- |
|
57 |
- av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, |
|
58 |
- link->format); |
|
76 |
+ frame->sample_rate = link->sample_rate; |
|
59 | 77 |
|
78 |
+ av_samples_set_silence(frame->extended_data, 0, nb_samples, channels, link->format); |
|
60 | 79 |
|
61 | 80 |
return frame; |
62 | 81 |
} |