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
22#include "libavutil/avassert.h"22#include "libavutil/avassert.h"
23#include "libavutil/channel_layout.h"23#include "libavutil/channel_layout.h"
24#include "libavutil/common.h"24#include "libavutil/common.h"
25#include "libavutil/cpu.h"
25 26
26#include "audio.h"27#include "audio.h"
27#include "avfilter.h"28#include "avfilter.h"
28#include "framepool.h"29#include "framepool.h"
29#include "internal.h"30#include "internal.h"
30 31
31#define BUFFER_ALIGN 0
32
33
34AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)32AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
35{33{
36 return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);34 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
41 AVFrame *frame = NULL;39 AVFrame *frame = NULL;
42 int channels = link->channels;40 int channels = link->channels;
43 int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);41 int channel_layout_nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
42 int align = av_cpu_max_align();
44 43
45 av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels);44 av_assert0(channels == channel_layout_nb_channels || !channel_layout_nb_channels);
46 45
47 if (!link->frame_pool) {46 if (!link->frame_pool) {
48 link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,47 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);
50 if (!link->frame_pool)49 if (!link->frame_pool)
51 return NULL;50 return NULL;
52 } else {51 } else {
@@ -62,11 +61,11 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples) · 9 unmodified lines
62 }61 }
63 62
64 if (pool_channels != channels || pool_nb_samples < nb_samples ||63 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) {
66 65
67 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);66 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
68 link->frame_pool = ff_frame_pool_audio_init(av_buffer_allocz, channels,67 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);
70 if (!link->frame_pool)69 if (!link->frame_pool)
71 return NULL;70 return NULL;
72 }71 }
libavfilter/framepool.c+8−10
@@ -76,27 +76,25 @@ FFFramePool *ff_frame_pool_video_init(AVBufferRef* (*alloc)(size_t size), · 75 unmodified lines
76 }76 }
77 77
78 if (!pool->linesize[0]) {78 if (!pool->linesize[0]) {
79 for(i = 1; i <= align; i += i) {79 ret = av_image_fill_linesizes(pool->linesize, pool->format,
80 ret = av_image_fill_linesizes(pool->linesize, pool->format,80 FFALIGN(pool->width, align));
81 FFALIGN(pool->width, i));81 if (ret < 0) {
82 if (ret < 0) {82 goto fail;
83 goto fail;
84 }
85 if (!(pool->linesize[0] & (pool->align - 1)))
86 break;
87 }83 }
88 84
89 for (i = 0; i < 4 && pool->linesize[i]; i++) {85 for (i = 0; i < 4 && pool->linesize[i]; i++) {
90 pool->linesize[i] = FFALIGN(pool->linesize[i], pool->align);86 pool->linesize[i] = FFALIGN(pool->linesize[i], pool->align);
87 if ((pool->linesize[i] & (pool->align - 1)))
88 goto fail;
91 }89 }
92 }90 }
93 91
94 for (i = 0; i < 4 && pool->linesize[i]; i++) {92 for (i = 0; i < 4 && pool->linesize[i]; i++) {
95 int h = FFALIGN(pool->height, 32);93 int h = pool->height;
96 if (i == 1 || i == 2)94 if (i == 1 || i == 2)
97 h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);95 h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
98 96
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,
100 alloc);98 alloc);
101 if (!pool->pools[i])99 if (!pool->pools[i])
102 goto fail;100 goto fail;
libavfilter/video.c+5−6
@@ -24,6 +24,7 @@ · 23 unmodified lines
24#include <stdio.h>24#include <stdio.h>
25 25
26#include "libavutil/buffer.h"26#include "libavutil/buffer.h"
27#include "libavutil/cpu.h"
27#include "libavutil/hwcontext.h"28#include "libavutil/hwcontext.h"
28#include "libavutil/imgutils.h"29#include "libavutil/imgutils.h"
29 30
@@ -32,9 +33,6 @@ · 2 unmodified lines
32#include "internal.h"33#include "internal.h"
33#include "video.h"34#include "video.h"
34 35
35#define BUFFER_ALIGN 32
36
37
38AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)36AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
39{37{
40 return ff_get_video_buffer(link->dst->outputs[0], w, h);38 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
46 int pool_width = 0;44 int pool_width = 0;
47 int pool_height = 0;45 int pool_height = 0;
48 int pool_align = 0;46 int pool_align = 0;
47 int align = av_cpu_max_align();
49 enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;48 enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
50 49
51 if (link->hw_frames_ctx &&50 if (link->hw_frames_ctx &&
@@ -65,7 +64,7 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) · 13 unmodified lines
65 64
66 if (!link->frame_pool) {65 if (!link->frame_pool) {
67 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,66 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
68 link->format, BUFFER_ALIGN);67 link->format, align);
69 if (!link->frame_pool)68 if (!link->frame_pool)
70 return NULL;69 return NULL;
71 } else {70 } else {
@@ -76,11 +75,11 @@ AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) · 4 unmodified lines
76 }75 }
77 76
78 if (pool_width != w || pool_height != h ||77 if (pool_width != w || pool_height != h ||
79 pool_format != link->format || pool_align != BUFFER_ALIGN) {78 pool_format != link->format || pool_align != align) {
80 79
81 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);80 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
82 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,81 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
83 link->format, BUFFER_ALIGN);82 link->format, align);
84 if (!link->frame_pool)83 if (!link->frame_pool)
85 return NULL;84 return NULL;
86 }85 }

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