FFmpeg
Loading...
Searching...
No Matches
op_list_gen_template.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <stdbool.h>
20
21#include "libswscale/format.h"
22#include "libswscale/ops.h"
23#include "libswscale/swscale.h"
25
26#include "libavutil/error.h"
27#include "libavutil/macros.h"
28#include "libavutil/pixdesc.h"
29#include "libavutil/pixfmt.h"
30
31#define DUMMY_SIZE 16
32
36 int (*cb)(SwsContext *ctx, void *opaque, SwsOpList *ops);
37 void *opaque;
38
39 /* for slice threading */
40 enum AVPixelFormat src_start, src_end;
41 enum AVPixelFormat dst_start, dst_end;
42};
43
44static int enum_ops_fmt(const struct EnumFmtPriv *s,
45 enum AVPixelFormat src_fmt,
46 enum AVPixelFormat dst_fmt)
47{
48 int ret = 0;
49 SwsOpList *ops = NULL;
51 ff_fmt_from_pixfmt(src_fmt, &src);
52 ff_fmt_from_pixfmt(dst_fmt, &dst);
53 bool incomplete = ff_infer_colors(&src.color, &dst.color);
54 src.width = src.height = DUMMY_SIZE;
55
56 static const int dst_sizes[][2] = {
58 { DUMMY_SIZE, DUMMY_SIZE * 2 },
59 { DUMMY_SIZE * 2, DUMMY_SIZE },
60 { DUMMY_SIZE * 2, DUMMY_SIZE * 2 },
61 };
62
63 for (int i = 0; i < FF_ARRAY_ELEMS(dst_sizes); i++) {
64 dst.width = dst_sizes[i][0];
65 dst.height = dst_sizes[i][1];
66
67 ret = ff_sws_op_list_generate(s->ctx, &src, &dst, s->lut3d, &ops, &incomplete);
68 if (ret == AVERROR(ENOTSUP))
69 return 0; /* silently skip unsupported formats */
70 else if (ret < 0)
71 return ret;
72
73 ret = ff_sws_op_list_optimize(ops);
74 if (ret < 0)
75 goto fail;
76
77 ret = s->cb(s->ctx, s->opaque, ops);
78 if (ret < 0)
79 goto fail;
80
82 }
83
84fail:
86 return ret;
87}
88
89static int enum_fmt_slice(void *priv, int jobnr, int threadnr, int nb_jobs,
90 int nb_threads)
91{
92 const struct EnumFmtPriv *s = priv;
93 const enum AVPixelFormat src = s->src_start + jobnr;
94 int ret = 0;
95
96 for (enum AVPixelFormat dst = s->dst_start; dst <= s->dst_end; dst++) {
97 ret = enum_ops_fmt(s, src, dst);
98 if (ret < 0)
99 break;
100 }
101
102 return ret;
103}
104
110
112{
114 while (1) {
116 if (!next)
118 desc = next;
119 }
120}
121
122/**
123 * Helper function to enumerate over all possible (optimized) operation lists,
124 * under the current set of options in `ctx`, and run the given callback on
125 * each list.
126 *
127 * @param src_fmt If set (not AV_PIX_FMT_NONE), constrain the source format
128 * @param dst_fmt If set (not AV_PIX_FMT_NONE), constrain the destination format
129 * @param cb Callback to run on each op list. If ctx->threads != 1, this may be
130 * called from multiple threads.
131 * @return 0 on success, the return value if cb() < 0, or a negative error code
132 *
133 * @note `ops` belongs to sws_enum_op_lists(), but may be mutated by `cb`.
134 */
135static inline
137 enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt,
138 int (*cb)(SwsContext *ctx, void *opaque, SwsOpList *ops))
139{
140 struct EnumFmtPriv s = {
141 .ctx = ctx,
142 .cb = cb,
143 .opaque = opaque,
144 .lut3d = lut3d,
145 };
146
147 s.src_start = s.dst_start = first_pix_fmt();
148 s.src_end = s.dst_end = last_pix_fmt();
149 if (src_fmt != AV_PIX_FMT_NONE)
150 s.src_start = s.src_end = src_fmt;
151 if (dst_fmt != AV_PIX_FMT_NONE)
152 s.dst_start = s.dst_end = dst_fmt;
153
154 const int nb_fmts = s.src_end - s.src_start + 1;
155 return ff_sws_thread_exec(&s, enum_fmt_slice, ctx->threads, nb_fmts);
156}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
error code definitions
int ff_sws_op_list_generate(SwsContext *ctx, const SwsFormat *src, const SwsFormat *dst, const SwsLut3D *lut3d, SwsOpList **out_ops, bool *incomplete)
Generate an SwsOpList defining a conversion from src to dst, with an optional 3DLUT for converting be...
#define fail
Definition test.h:479
#define AVERROR(e)
Definition error.h:45
const char * desc
Definition libsvtav1.c:83
bool ff_infer_colors(SwsColor *src, SwsColor *dst)
Definition format.c:537
void ff_fmt_from_pixfmt(enum AVPixelFormat pixfmt, SwsFormat *fmt)
Subset of ff_fmt_from_frame() that sets default metadata for the format.
Definition format.c:480
Utility Preprocessor macros.
static int ff_sws_enum_op_lists(SwsContext *ctx, void *opaque, const SwsLut3D *lut3d, enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt, int(*cb)(SwsContext *ctx, void *opaque, SwsOpList *ops))
Helper function to enumerate over all possible (optimized) operation lists, under the current set of ...
static enum AVPixelFormat first_pix_fmt(void)
static enum AVPixelFormat last_pix_fmt(void)
static int enum_ops_fmt(const struct EnumFmtPriv *s, enum AVPixelFormat src_fmt, enum AVPixelFormat dst_fmt)
#define DUMMY_SIZE
static int enum_fmt_slice(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
void ff_sws_op_list_free(SwsOpList **p_ops)
Definition ops.c:659
int ff_sws_op_list_optimize(SwsOpList *ops)
Fuse compatible and eliminate redundant operations, as well as replacing some operations with more ef...
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition pixdesc.c:3479
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition pixdesc.c:3467
pixel format definitions
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
#define FF_ARRAY_ELEMS(a)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
enum AVPixelFormat dst_start dst_end
int(* cb)(SwsContext *ctx, void *opaque, SwsOpList *ops)
const SwsLut3D * lut3d
enum AVPixelFormat src_start src_end
Main external API structure.
Definition swscale.h:227
Append a set of operations for applying a gamut/tone mapping 3D LUT to the pixels.
Definition lut3d.h:50
Helper struct for representing a list of operations.
Definition ops.h:293
external API header
int ff_sws_thread_exec(void *priv, int(*func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), int nb_threads, int nb_jobs)
Helper for dispatching a single function across multiple threads.
Definition utils.c:2444
#define src
Definition vp8dsp.c:248
static AVFormatContext * ctx
Definition movenc.c:49
static double cb(void *priv, double x, double y)
Definition vf_geq.c:247