FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/video.c
Date: 2022-11-26 13:19:19
Exec Total Coverage
Lines: 33 45 73.3%
Branches: 16 30 53.3%

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 40851 AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
37 {
38 40851 return ff_get_video_buffer(link->dst->outputs[0], w, h);
39 }
40
41 46390 AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align)
42 {
43 46390 AVFrame *frame = NULL;
44 46390 int pool_width = 0;
45 46390 int pool_height = 0;
46 46390 int pool_align = 0;
47 46390 enum AVPixelFormat pool_format = AV_PIX_FMT_NONE;
48
49
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46390 times.
46390 if (link->hw_frames_ctx &&
50 ((AVHWFramesContext*)link->hw_frames_ctx->data)->format == link->format) {
51 int ret;
52 frame = av_frame_alloc();
53
54 if (!frame)
55 return NULL;
56
57 ret = av_hwframe_get_buffer(link->hw_frames_ctx, frame, 0);
58 if (ret < 0)
59 av_frame_free(&frame);
60
61 return frame;
62 }
63
64
2/2
✓ Branch 0 taken 4771 times.
✓ Branch 1 taken 41619 times.
46390 if (!link->frame_pool) {
65 9542 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
66 4771 link->format, align);
67
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4771 times.
4771 if (!link->frame_pool)
68 return NULL;
69 } else {
70
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 41619 times.
41619 if (ff_frame_pool_get_video_config(link->frame_pool,
71 &pool_width, &pool_height,
72 &pool_format, &pool_align) < 0) {
73 return NULL;
74 }
75
76
3/4
✓ Branch 0 taken 41618 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 41618 times.
✗ Branch 3 not taken.
41619 if (pool_width != w || pool_height != h ||
77
2/4
✓ Branch 0 taken 41618 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 41618 times.
41618 pool_format != link->format || pool_align != align) {
78
79 1 ff_frame_pool_uninit((FFFramePool **)&link->frame_pool);
80 2 link->frame_pool = ff_frame_pool_video_init(av_buffer_allocz, w, h,
81 1 link->format, align);
82
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!link->frame_pool)
83 return NULL;
84 }
85 }
86
87 46390 frame = ff_frame_pool_get(link->frame_pool);
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46390 times.
46390 if (!frame)
89 return NULL;
90
91 46390 frame->sample_aspect_ratio = link->sample_aspect_ratio;
92
93 46390 return frame;
94 }
95
96 46390 AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h)
97 {
98 46390 return ff_default_get_video_buffer2(link, w, h, av_cpu_max_align());
99 }
100
101 87907 AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h)
102 {
103 87907 AVFrame *ret = NULL;
104
105 FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 1);
106
107
2/2
✓ Branch 0 taken 41721 times.
✓ Branch 1 taken 46186 times.
87907 if (link->dstpad->get_buffer.video)
108 41721 ret = link->dstpad->get_buffer.video(link, w, h);
109
110
2/2
✓ Branch 0 taken 46186 times.
✓ Branch 1 taken 41721 times.
87907 if (!ret)
111 46186 ret = ff_default_get_video_buffer(link, w, h);
112
113 87907 return ret;
114 }
115