]> git.sesse.net Git - ffmpeg/blob - libavfilter/video.c
Merge commit '906ffed9b1b8b06979eb656989aecacb1ae75a3a'
[ffmpeg] / libavfilter / video.c
1 /*
2  * Copyright 2007 Bobby Bingham
3  * Copyright Stefano Sabatini <stefasab gmail com>
4  * Copyright Vitor Sessak <vitor1001 gmail com>
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #include <string.h>
24 #include <stdio.h>
25
26 #include "libavutil/avassert.h"
27 #include "libavutil/buffer.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/mem.h"
30
31 #include "avfilter.h"
32 #include "internal.h"
33 #include "video.h"
34
35 #define BUFFER_ALIGN 32
36
37
38 AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
39 {
40     return ff_get_video_buffer(link->dst->outputs[0], w, h);
41 }
42
43 AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
44 {
45     int pool_width = 0;
46     int pool_height = 0;
47     int pool_align = 0;
48     enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
49
50     if (!link->video_frame_pool) {
51         link->video_frame_pool = ff_video_frame_pool_init(av_buffer_allocz, w, h,
52                                                           link->format, BUFFER_ALIGN);
53         if (!link->video_frame_pool)
54             return NULL;
55     } else {
56         if (ff_video_frame_pool_get_config(link->video_frame_pool,
57                                            &pool_width, &pool_height,
58                                            &pool_format, &pool_align) < 0) {
59             return NULL;
60         }
61
62         if (pool_width != w || pool_height != h ||
63             pool_format != link->format || pool_align != BUFFER_ALIGN) {
64
65             ff_video_frame_pool_uninit((FFVideoFramePool **)&link->video_frame_pool);
66             link->video_frame_pool = ff_video_frame_pool_init(av_buffer_allocz, w, h,
67                                                               link->format, BUFFER_ALIGN);
68             if (!link->video_frame_pool)
69                 return NULL;
70         }
71     }
72
73     return ff_video_frame_pool_get(link->video_frame_pool);
74 }
75
76 AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)
77 {
78     AVFrame *ret = NULL;
79
80     FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 0);
81
82     if (link->dstpad->get_video_buffer)
83         ret = link->dstpad->get_video_buffer(link, w, h);
84
85     if (!ret)
86         ret = ff_default_get_video_buffer(link, w, h);
87
88     return ret;
89 }