[FFmpeg-devel] [PATCH v2 2/3] avfilter/mapping: implement dynamic routing logic.
cenzhanquan2 at gmail.com
cenzhanquan2 at gmail.com
Mon Jul 21 15:04:43 EEST 2025
From: zhanquan cen <cenzhanquan2 at gmail.com>
---
mapping.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
mapping.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 95 insertions(+)
create mode 100644 mapping.c
create mode 100644 mapping.h
diff --git a/mapping.c b/mapping.c
new file mode 100644
index 0000000000..53fa2fb3b5
--- /dev/null
+++ b/mapping.c
@@ -0,0 +1,51 @@
+
+/*
+ * filter layer
+ * Copyright (c) 2007 Bobby Bingham
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "mapping.h"
+int avfilter_parse_mapping(const char *map_str, int **map, int nb_map)
+{
+ int *new_map = NULL;
+ int new_nb_map = 0;
+ if (!map_str || nb_map <= 0)
+ return AVERROR(EINVAL);
+ new_map = av_calloc(nb_map, sizeof(*new_map));
+ if (!new_map)
+ return AVERROR(ENOMEM);
+ while (1) {
+ char *p;
+ int n = strtol(map_str, &p, 0);
+ if (map_str == p)
+ break;
+ map_str = p;
+ if (new_nb_map >= nb_map) {
+ av_freep(&new_map);
+ return AVERROR(EINVAL);
+ }
+ new_map[new_nb_map++] = n;
+ }
+ if (!new_nb_map) {
+ av_freep(&new_map);
+ return AVERROR(EINVAL);
+ }
+ av_freep(map);
+ *map = new_map;
+ return 0;
+}
\ No newline at end of file
diff --git a/mapping.h b/mapping.h
new file mode 100644
index 0000000000..2c1d90ef93
--- /dev/null
+++ b/mapping.h
@@ -0,0 +1,44 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFILTER_MAPPING_H
+#define AVFILTER_MAPPING_H
+
+#include <stddef.h>
+#include <stdlib.h>
+#include "libavutil/error.h"
+#include "libavutil/mem.h"
+
+/**
+ * @file
+ * control routing for src filter
+ */
+
+/**
+ * Parse the mapping definition.
+ *
+ * @param map_str The mapping definition string.
+ * @param map Pointer to an array that will hold the parsed mapping relationships.
+ * The array will be allocated by this function and should be freed
+ * by the caller using av_freep().
+ * @param nb_map The number of mappings expected in the map array.
+ * @return 0 on success, a negative AVERROR code on error.
+ */
+int avfilter_parse_mapping(const char *map_str, int **map, int nb_map);
+
+#endif /* AVFILTER_MAPPING_H */
\ No newline at end of file
--
2.34.1
More information about the ffmpeg-devel
mailing list