| 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/pixfmt.h" | ||
| 30 | |||
| 31 | #include "avfilter.h" | ||
| 32 | #include "avfilter_internal.h" | ||
| 33 | #include "filters.h" | ||
| 34 | #include "framepool.h" | ||
| 35 | #include "video.h" | ||
| 36 | |||
| 37 | const AVFilterPad ff_video_default_filterpad[1] = { | ||
| 38 | { | ||
| 39 | .name = "default", | ||
| 40 | .type = AVMEDIA_TYPE_VIDEO, | ||
| 41 | } | ||
| 42 | }; | ||
| 43 | |||
| 44 | 115332 | AVFrame *ff_null_get_video_buffer(AVFilterLink *link, int w, int h) | |
| 45 | { | ||
| 46 | 115332 | return ff_get_video_buffer(link->dst->outputs[0], w, h); | |
| 47 | } | ||
| 48 | |||
| 49 | 126015 | AVFrame *ff_default_get_video_buffer2(AVFilterLink *link, int w, int h, int align) | |
| 50 | { | ||
| 51 | 126015 | FilterLinkInternal *const li = ff_link_internal(link); | |
| 52 | 126015 | AVFrame *frame = NULL; | |
| 53 | 126015 | int pool_width = 0; | |
| 54 | 126015 | int pool_height = 0; | |
| 55 | 126015 | int pool_align = 0; | |
| 56 | 126015 | enum AVPixelFormat pool_format = AV_PIX_FMT_NONE; | |
| 57 | |||
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 126015 times.
|
126015 | if (li->l.hw_frames_ctx && |
| 59 | ✗ | ((AVHWFramesContext*)li->l.hw_frames_ctx->data)->format == link->format) { | |
| 60 | int ret; | ||
| 61 | ✗ | frame = av_frame_alloc(); | |
| 62 | |||
| 63 | ✗ | if (!frame) | |
| 64 | ✗ | return NULL; | |
| 65 | |||
| 66 | ✗ | ret = av_hwframe_get_buffer(li->l.hw_frames_ctx, frame, 0); | |
| 67 | ✗ | if (ret < 0) | |
| 68 | ✗ | av_frame_free(&frame); | |
| 69 | |||
| 70 | ✗ | return frame; | |
| 71 | } | ||
| 72 | |||
| 73 |
2/2✓ Branch 0 taken 9363 times.
✓ Branch 1 taken 116652 times.
|
126015 | if (!li->frame_pool) { |
| 74 | 18726 | li->frame_pool = ff_frame_pool_video_init(CONFIG_MEMORY_POISONING | |
| 75 | ? NULL | ||
| 76 | : av_buffer_allocz, | ||
| 77 | 9363 | w, h, link->format, align); | |
| 78 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9363 times.
|
9363 | if (!li->frame_pool) |
| 79 | ✗ | return NULL; | |
| 80 | } else { | ||
| 81 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 116652 times.
|
116652 | if (ff_frame_pool_get_video_config(li->frame_pool, |
| 82 | &pool_width, &pool_height, | ||
| 83 | &pool_format, &pool_align) < 0) { | ||
| 84 | ✗ | return NULL; | |
| 85 | } | ||
| 86 | |||
| 87 |
4/4✓ Branch 0 taken 116651 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 116648 times.
✓ Branch 3 taken 3 times.
|
116652 | if (pool_width != w || pool_height != h || |
| 88 |
2/4✓ Branch 0 taken 116648 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 116648 times.
|
116648 | pool_format != link->format || pool_align != align) { |
| 89 | |||
| 90 | 4 | ff_frame_pool_uninit(&li->frame_pool); | |
| 91 | 8 | li->frame_pool = ff_frame_pool_video_init(CONFIG_MEMORY_POISONING | |
| 92 | ? NULL | ||
| 93 | : av_buffer_allocz, | ||
| 94 | 4 | w, h, link->format, align); | |
| 95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (!li->frame_pool) |
| 96 | ✗ | return NULL; | |
| 97 | } | ||
| 98 | } | ||
| 99 | |||
| 100 | 126015 | frame = ff_frame_pool_get(li->frame_pool); | |
| 101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 126015 times.
|
126015 | if (!frame) |
| 102 | ✗ | return NULL; | |
| 103 | |||
| 104 | 126015 | frame->sample_aspect_ratio = link->sample_aspect_ratio; | |
| 105 | 126015 | frame->colorspace = link->colorspace; | |
| 106 | 126015 | frame->color_range = link->color_range; | |
| 107 | 126015 | frame->alpha_mode = link->alpha_mode; | |
| 108 | |||
| 109 | 126015 | return frame; | |
| 110 | } | ||
| 111 | |||
| 112 | 126015 | AVFrame *ff_default_get_video_buffer(AVFilterLink *link, int w, int h) | |
| 113 | { | ||
| 114 | 126015 | return ff_default_get_video_buffer2(link, w, h, av_cpu_max_align()); | |
| 115 | } | ||
| 116 | |||
| 117 | 238816 | AVFrame *ff_get_video_buffer(AVFilterLink *link, int w, int h) | |
| 118 | { | ||
| 119 | 238816 | AVFrame *ret = NULL; | |
| 120 | |||
| 121 | FF_TPRINTF_START(NULL, get_video_buffer); ff_tlog_link(NULL, link, 1); | ||
| 122 | |||
| 123 |
2/2✓ Branch 0 taken 116849 times.
✓ Branch 1 taken 121967 times.
|
238816 | if (link->dstpad->get_buffer.video) |
| 124 | 116849 | ret = link->dstpad->get_buffer.video(link, w, h); | |
| 125 | |||
| 126 |
2/2✓ Branch 0 taken 121967 times.
✓ Branch 1 taken 116849 times.
|
238816 | if (!ret) |
| 127 | 121967 | ret = ff_default_get_video_buffer(link, w, h); | |
| 128 | |||
| 129 | 238816 | return ret; | |
| 130 | } | ||
| 131 |