History

avfilter/framepool: fix alignment requirements for audio and video filters

Paul B Mahol committed 4 years ago

Commit 17a59a61 parent 9da19c23 files · +18 −22Browse files

Unified · Split

3 files
  1. libavfilter/audio.c +5 −6
  2. libavfilter/framepool.c +8 −10
  3. libavfilter/video.c +5 −6
libavfilter/audio.c+5−6
@@ -22,15 +22,13 @@ · 21 unmodified lines
2222 #include "libavutil/avassert.h"
2323 #include "libavutil/channel_layout.h"
2424 #include "libavutil/common.h"
25+#include "libavutil/cpu.h"
2526
2627 #include "audio.h"
2728 #include "avfilter.h"
2829 #include "framepool.h"
2930 #include "internal.h"
3031
31−#define BUFFER_ALIGN 0
32−
33−
3432 AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
3533 {
3634 return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
@@ -41,12 +39,13 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) · 4 unmodified lines
4139 AVFrame *frame = NULL;
4240 int channels = link->channels;
4341 int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
42+ int align = av_cpu_max_align();
4443
4544 av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels);
4645
4746 if (!link->frame_pool) {
4847 link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
49− nb_samples, link->format, BUFFER_ALIGN);
48+ nb_samples, link->format, align);
5049 if (!link->frame_pool)
5150 return NULL;
5251 } else {
@@ -62,11 +61,11 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) · 9 unmodified lines
6261 }
6362
6463 if (pool_channels != channels || pool_nb_samples < nb_samples ||
65− pool_format != link->format || pool_align != BUFFER_ALIGN) {
64+ pool_format != link->format || pool_align != align) {
6665
6766 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
6867 link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,
69− nb_samples, link->format, BUFFER_ALIGN);
68+ nb_samples, link->format, align);
7069 if (!link->frame_pool)
7170 return NULL;
7271 }
libavfilter/framepool.c+8−10
@@ -76,27 +76,25 @@ FFFramePool *ff_frame_pool_video_init(AVBufferRef* (*alloc)(size_t size), · 75 unmodified lines
7676 }
7777
7878 if (!pool->linesize[0]) {
79− for(i = 1; i <= align; i += i) {
80− ret = av_image_fill_linesizes(pool->linesize, pool->format,
81− FFALIGN(pool->width, i));
82− if (ret < 0) {
83− goto fail;
84− }
85− if (!(pool->linesize[0] & (pool->align - 1)))
86− break;
79+ ret = av_image_fill_linesizes(pool->linesize, pool->format,
80+ FFALIGN(pool->width, align));
81+ if (ret < 0) {
82+ goto fail;
8783 }
8884
8985 for (i = 0; i < 4 && pool->linesize[i]; i++) {
9086 pool->linesize[i] = FFALIGN(pool->linesize[i], pool->align);
87+ if ((pool->linesize[i] & (pool->align - 1)))
88+ goto fail;
9189 }
9290 }
9391
9492 for (i = 0; i < 4 && pool->linesize[i]; i++) {
95− int h = FFALIGN(pool->height, 32);
93+ int h = pool->height;
9694 if (i == 1 || i == 2)
9795 h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
9896
99− pool->pools[i] = av_buffer_pool_init(pool->linesize[i] * h + 16 + 16 - 1,
97+ pool->pools[i] = av_buffer_pool_init(pool->linesize[i] * h + align,
10098 alloc);
10199 if (!pool->pools[i])
102100 goto fail;
libavfilter/video.c+5−6
@@ -24,6 +24,7 @@ · 23 unmodified lines
2424 #include <stdio.h>
2525
2626 #include "libavutil/buffer.h"
27+#include "libavutil/cpu.h"
2728 #include "libavutil/hwcontext.h"
2829 #include "libavutil/imgutils.h"
2930
@@ -32,9 +33,6 @@ · 2 unmodified lines
3233 #include "internal.h"
3334 #include "video.h"
3435
35−#define BUFFER_ALIGN 32
36−
37−
3836 AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
3937 {
4038 return ff_get_video_buffer(link->dst->outputs[0], w, h);
@@ -46,6 +44,7 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) · 5 unmodified lines
4644 int pool_width = 0;
4745 int pool_height = 0;
4846 int pool_align = 0;
47+ int align = av_cpu_max_align();
4948 enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
5049
5150 if (link->hw_frames_ctx &&
@@ -65,7 +64,7 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) · 13 unmodified lines
6564
6665 if (!link->frame_pool) {
6766 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
68− link->format, BUFFER_ALIGN);
67+ link->format, align);
6968 if (!link->frame_pool)
7069 return NULL;
7170 } else {
@@ -76,11 +75,11 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) · 4 unmodified lines
7675 }
7776
7877 if (pool_width != w || pool_height != h ||
79− pool_format != link->format || pool_align != BUFFER_ALIGN) {
78+ pool_format != link->format || pool_align != align) {
8079
8180 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
8281 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
83− link->format, BUFFER_ALIGN);
82+ link->format, align);
8483 if (!link->frame_pool)
8584 return NULL;
8685 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t