Line | Branch | Exec | Source |
---|---|---|---|
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/buffer.h" | ||
27 | #include "libavutil/cpu.h" | ||
28 | #include "libavutil/hwcontext.h" | ||
29 | #include "libavutil/imgutils.h" | ||
30 | |||
31 | #include "avfilter.h" | ||
32 | #include "framepool.h" | ||
33 | #include "internal.h" | ||
34 | #include "video.h" | ||
35 | |||
36 | const AVFilterPad ff_video_default_filterpad[1] = { | ||
37 | { | ||
38 | .name = "default", | ||
39 | .type = AVMEDIA_TYPE_VIDEO, | ||
40 | } | ||
41 | }; | ||
42 | |||
43 | 43031 | AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h) | |
44 | { | ||
45 | 43031 | return ff_get_video_buffer(link->dst->outputs[0], w, h); | |
46 | } | ||
47 | |||
48 | 53596 | AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align) | |
49 | { | ||
50 | 53596 | AVFrame *frame = NULL; | |
51 | 53596 | int pool_width = 0; | |
52 | 53596 | int pool_height = 0; | |
53 | 53596 | int pool_align = 0; | |
54 | 53596 | enum AVPixelFormat pool_format = AV_PIX_FMT_NONE; | |
55 | |||
56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53596 times.
|
53596 | if (link->hw_frames_ctx && |
57 | ✗ | ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) { | |
58 | int ret; | ||
59 | ✗ | frame = av_frame_alloc(); | |
60 | |||
61 | ✗ | if (!frame) | |
62 | ✗ | return NULL; | |
63 | |||
64 | ✗ | ret = av_hwframe_get_buffer(link->hw_frames_ctx, frame, 0); | |
65 | ✗ | if (ret < 0) | |
66 | ✗ | av_frame_free(&frame); | |
67 | |||
68 | ✗ | return frame; | |
69 | } | ||
70 | |||
71 |
2/2✓ Branch 0 taken 4947 times.
✓ Branch 1 taken 48649 times.
|
53596 | if (!link->frame_pool) { |
72 | 9894 | link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h, | |
73 | 4947 | link->format, align); | |
74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4947 times.
|
4947 | if (!link->frame_pool) |
75 | ✗ | return NULL; | |
76 | } else { | ||
77 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 48649 times.
|
48649 | if (ff_frame_pool_get_video_config(link->frame_pool, |
78 | &pool_width, &pool_height, | ||
79 | &pool_format, &pool_align) < 0) { | ||
80 | ✗ | return NULL; | |
81 | } | ||
82 | |||
83 |
3/4✓ Branch 0 taken 48648 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 48648 times.
✗ Branch 3 not taken.
|
48649 | if (pool_width != w || pool_height != h || |
84 |
2/4✓ Branch 0 taken 48648 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48648 times.
|
48648 | pool_format != link->format || pool_align != align) { |
85 | |||
86 | 1 | ff_frame_pool_uninit((FFFramePool **)&link->frame_pool); | |
87 | 2 | link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h, | |
88 | 1 | link->format, align); | |
89 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!link->frame_pool) |
90 | ✗ | return NULL; | |
91 | } | ||
92 | } | ||
93 | |||
94 | 53596 | frame = ff_frame_pool_get(link->frame_pool); | |
95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 53596 times.
|
53596 | if (!frame) |
96 | ✗ | return NULL; | |
97 | |||
98 | 53596 | frame->sample_aspect_ratio = link->sample_aspect_ratio; | |
99 | |||
100 | 53596 | return frame; | |
101 | } | ||
102 | |||
103 | 53596 | AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) | |
104 | { | ||
105 | 53596 | return ff_default_get_video_buffer2(link, w, h, av_cpu_max_align()); | |
106 | } | ||
107 | |||
108 | 93929 | AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h) | |
109 | { | ||
110 | 93929 | AVFrame *ret = NULL; | |
111 | |||
112 | FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 1); | ||
113 | |||
114 |
2/2✓ Branch 0 taken 43919 times.
✓ Branch 1 taken 50010 times.
|
93929 | if (link->dstpad->get_buffer.video) |
115 | 43919 | ret = link->dstpad->get_buffer.video(link, w, h); | |
116 | |||
117 |
2/2✓ Branch 0 taken 50010 times.
✓ Branch 1 taken 43919 times.
|
93929 | if (!ret) |
118 | 50010 | ret = ff_default_get_video_buffer(link, w, h); | |
119 | |||
120 | 93929 | return ret; | |
121 | } | ||
122 |