FFmpeg
sws_ops_aarch64.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2026 Ramiro Polla
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdio.h>
22 
23 #include "libavutil/mem.h"
24 #include "libavutil/tree.h"
25 #include "libswscale/ops.h"
26 #include "libswscale/ops_chain.h"
27 
30 
31 #ifdef _WIN32
32 #include <io.h>
33 #include <fcntl.h>
34 #endif
35 
36 /*********************************************************************/
37 static int aarch64_op_impl_cmp(const void *a, const void *b)
38 {
39  const SwsAArch64OpImplParams *pa = (const SwsAArch64OpImplParams *) a;
40  const SwsAArch64OpImplParams *pb = (const SwsAArch64OpImplParams *) b;
41 
42  const ParamField **fields = op_fields[pa->op];
43  for (int i = 0; fields[i]; i++) {
44  const ParamField *field = fields[i];
45  int diff = field->cmp_val((void *) (((uintptr_t) pa) + field->offset),
46  (void *) (((uintptr_t) pb) + field->offset));
47  if (diff)
48  return diff;
49  }
50  return 0;
51 }
52 
53 /*********************************************************************/
54 /* Insert the SwsAArch64OpImplParams structure into the AVTreeNode. */
55 static int aarch64_collect_op(const SwsAArch64OpImplParams *params, struct AVTreeNode **root)
56 {
57  int ret = 0;
58 
59  struct AVTreeNode *node = av_tree_node_alloc();
60  SwsAArch64OpImplParams *copy = av_memdup(params, sizeof(*params));
61  if (!node || !copy) {
62  ret = AVERROR(ENOMEM);
63  goto error;
64  }
66  if (!node)
67  copy = NULL;
68 
69 error:
70  av_free(node);
71  av_free(copy);
72  return ret;
73 }
74 
75 static int register_op(SwsContext *ctx, void *opaque, SwsOpList *ops)
76 {
77  struct AVTreeNode **root = (struct AVTreeNode **) opaque;
78  int ret;
79 
80  /* Skip ops lists which include filtering, since this is still not
81  * supported. */
82  for (int i = 0; i < ops->num_ops; i++) {
83  const SwsOp *op = &ops->ops[i];
84  switch (op->op) {
85  case SWS_OP_READ:
86  case SWS_OP_WRITE:
87  if (op->rw.filter.op)
88  return 0;
89  break;
90  case SWS_OP_FILTER_H:
91  case SWS_OP_FILTER_V:
92  return 0;
93  }
94  }
95 
96  /* Use at most two full vregs during the widest precision section */
97  int block_size = (ff_sws_op_list_max_size(ops) == 4) ? 8 : 16;
98 
99  for (int i = 0; i < ops->num_ops; i++) {
100  SwsAArch64OpImplParams params = { 0 };
101  ret = convert_to_aarch64_impl(ctx, ops, i, block_size, &params);
102  if (ret == AVERROR(ENOTSUP))
103  continue;
104  if (ret < 0)
105  goto end;
106  ret = aarch64_collect_op(&params, root);
107  if (ret < 0)
108  goto end;
109  if (params.op == AARCH64_SWS_OP_LINEAR) {
110  /**
111  * Generate both sets of linear op functions that do use
112  * and do not use fmla (selected by SWS_BITEXACT).
113  */
114  params.linear.fmla = !params.linear.fmla;
115  ret = aarch64_collect_op(&params, root);
116  if (ret < 0)
117  goto end;
118  }
119  }
120 
121  ret = 0;
122 
123 end:
124  return ret;
125 }
126 
127 /*********************************************************************/
128 static void serialize_op(char *buf, size_t size, const SwsAArch64OpImplParams *params)
129 {
130  buf_appendf(&buf, &size, "{");
131  const ParamField **fields = op_fields[params->op];
132  for (int i = 0; fields[i]; i++) {
133  const ParamField *field = fields[i];
134  void *p = (void *) (((uintptr_t) params) + field->offset);
135  if (i)
136  buf_appendf(&buf, &size, ",");
137  buf_appendf(&buf, &size, " .%s = ", field->name);
138  field->print_val(&buf, &size, p);
139  }
140  buf_appendf(&buf, &size, " }");
141  av_assert0(size && "string buffer exhausted");
142 }
143 
144 /* Serialize SwsAArch64OpImplParams for one function. */
145 static int print_op(void *opaque, void *elem)
146 {
148  FILE *fp = (FILE *) opaque;
149 
150  char buf[256];
151  serialize_op(buf, sizeof(buf), params);
152  fprintf(fp, "%s,\n", buf);
153 
154  av_free(params);
155 
156  return 0;
157 }
158 
159 /*********************************************************************/
160 int main(int argc, char *argv[])
161 {
162  struct AVTreeNode *root = NULL;
163  int ret = 1;
164 
165 #ifdef _WIN32
166  _setmode(_fileno(stdout), _O_BINARY);
167 #endif
168 
170  if (!ctx)
171  goto fail;
172 
174  register_op);
175 
176  /**
177  * Generate a C file with all the unique function parameter entries
178  * collected by aarch64_enum_ops().
179  */
180  printf("/*\n");
181  printf(" * This file is automatically generated. Do not edit manually.\n");
182  printf(" * To regenerate, run: make fate-sws-ops-entries-aarch64 GEN=1\n");
183  printf(" */\n");
184  printf("\n");
185  av_tree_enumerate(root, stdout, NULL, print_op);
186 
187 fail:
188  av_tree_destroy(root);
190  return ret;
191 }
SWS_OP_READ
@ SWS_OP_READ
Definition: ops.h:39
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
printf
__device__ int printf(const char *,...)
ParamField
The following structure is used to describe one field from SwsAArch64OpImplParams.
Definition: ops_impl.c:186
av_tree_insert
void * av_tree_insert(AVTreeNode **tp, void *key, int(*cmp)(const void *key, const void *b), AVTreeNode **next)
Insert or remove an element.
Definition: tree.c:59
ff_sws_op_list_max_size
int ff_sws_op_list_max_size(const SwsOpList *ops)
Returns the size of the largest pixel type used in ops.
Definition: ops.c:778
ops.h
AVTreeNode::elem
void * elem
Definition: tree.c:28
b
#define b
Definition: input.c:43
av_tree_node_alloc
struct AVTreeNode * av_tree_node_alloc(void)
Allocate an AVTreeNode.
Definition: tree.c:34
ops_impl.c
av_tree_enumerate
void av_tree_enumerate(AVTreeNode *t, void *opaque, int(*cmp)(void *opaque, void *elem), int(*enu)(void *opaque, void *elem))
Apply enu(opaque, &elem) to all the elements in the tree in a given range.
Definition: tree.c:155
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
SwsAArch64LinearOp::fmla
uint8_t fmla
Definition: ops_impl.h:79
SwsOpList::num_ops
int num_ops
Definition: ops.h:267
ops_chain.h
AARCH64_SWS_OP_LINEAR
@ AARCH64_SWS_OP_LINEAR
Definition: ops_impl.h:60
op
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
Definition: anm.c:76
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:42
ctx
static AVFormatContext * ctx
Definition: movenc.c:49
field
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
Definition: writing_filters.txt:78
SWS_OP_FILTER_H
@ SWS_OP_FILTER_H
Definition: ops.h:62
op_fields
static const ParamField * op_fields[AARCH64_SWS_OP_TYPE_NB][MAX_LEVELS]
Definition: ops_impl.c:323
fields
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
Definition: filter_design.txt:155
fail
#define fail
Definition: test.h:478
NULL
#define NULL
Definition: coverity.c:32
aarch64_op_impl_cmp
static int aarch64_op_impl_cmp(const void *a, const void *b)
Definition: sws_ops_aarch64.c:37
AVTreeNode
Definition: tree.c:26
SWS_OP_FILTER_V
@ SWS_OP_FILTER_V
Definition: ops.h:63
print_op
static int print_op(void *opaque, void *elem)
Definition: sws_ops_aarch64.c:145
av_tree_destroy
void av_tree_destroy(AVTreeNode *t)
Definition: tree.c:146
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:186
sws_alloc_context
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
Definition: utils.c:1043
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
size
int size
Definition: twinvq_data.h:10344
SwsAArch64OpImplParams::op
SwsAArch64OpType op
Definition: ops_impl.h:93
SWS_OP_WRITE
@ SWS_OP_WRITE
Definition: ops.h:40
tree.h
diff
static av_always_inline int diff(const struct color_info *a, const struct color_info *b, const int trans_thresh)
Definition: vf_paletteuse.c:166
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
SwsAArch64OpImplParams::linear
SwsAArch64LinearOp linear
Definition: ops_impl.h:102
ops_impl_conv.c
SwsOpList::ops
SwsOp * ops
Definition: ops.h:266
ff_sws_enum_op_lists
int ff_sws_enum_op_lists(SwsContext *ctx, void *opaque, 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 ...
Definition: ops.c:1058
SwsOp
Definition: ops.h:210
ret
ret
Definition: filter_design.txt:187
convert_to_aarch64_impl
static int convert_to_aarch64_impl(SwsContext *ctx, const SwsOpList *ops, int n, int block_size, SwsAArch64OpImplParams *out)
Convert SwsOp to a SwsAArch64OpImplParams.
Definition: ops_impl_conv.c:59
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
main
int main(int argc, char *argv[])
Definition: sws_ops_aarch64.c:160
aarch64_collect_op
static int aarch64_collect_op(const SwsAArch64OpImplParams *params, struct AVTreeNode **root)
Definition: sws_ops_aarch64.c:55
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
register_op
static int register_op(SwsContext *ctx, void *opaque, SwsOpList *ops)
Definition: sws_ops_aarch64.c:75
SwsAArch64OpImplParams
SwsAArch64OpImplParams describes the parameters for an SwsAArch64OpType operation.
Definition: ops_impl.h:92
mem.h
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
sws_free_context
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
Definition: utils.c:2381
SwsOpList
Helper struct for representing a list of operations.
Definition: ops.h:265
serialize_op
static void serialize_op(char *buf, size_t size, const SwsAArch64OpImplParams *params)
Definition: sws_ops_aarch64.c:128
SwsContext
Main external API structure.
Definition: swscale.h:229