[FFmpeg-devel] [PATCH 04/24] fftools/ffmpeg: move a few inline function into a new header

Anton Khirnov anton at khirnov.net
Sat Nov 4 09:56:13 EET 2023


Will allow to use them in future commits without including the whole
ffmpeg.h.
---
 fftools/ffmpeg.c       |  1 +
 fftools/ffmpeg.h       | 21 ------------------
 fftools/ffmpeg_dec.c   |  1 +
 fftools/ffmpeg_demux.c |  1 +
 fftools/ffmpeg_mux.c   |  1 +
 fftools/ffmpeg_utils.h | 50 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 54 insertions(+), 21 deletions(-)
 create mode 100644 fftools/ffmpeg_utils.h

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 46a85b41a8..cdb16ef90b 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -99,6 +99,7 @@
 
 #include "cmdutils.h"
 #include "ffmpeg.h"
+#include "ffmpeg_utils.h"
 #include "sync_queue.h"
 
 const char program_name[] = "ffmpeg";
diff --git a/fftools/ffmpeg.h b/fftools/ffmpeg.h
index 0983d026cd..d52c954df5 100644
--- a/fftools/ffmpeg.h
+++ b/fftools/ffmpeg.h
@@ -880,17 +880,6 @@ int trigger_fix_sub_duration_heartbeat(OutputStream *ost, const AVPacket *pkt);
 int fix_sub_duration_heartbeat(InputStream *ist, int64_t signal_pts);
 void update_benchmark(const char *fmt, ...);
 
-/**
- * Merge two return codes - return one of the error codes if at least one of
- * them was negative, 0 otherwise.
- * Currently just picks the first one, eventually we might want to do something
- * more sophisticated, like sorting them by priority.
- */
-static inline int err_merge(int err0, int err1)
-{
-    return (err0 < 0) ? err0 : FFMIN(err1, 0);
-}
-
 #define SPECIFIER_OPT_FMT_str  "%s"
 #define SPECIFIER_OPT_FMT_i    "%i"
 #define SPECIFIER_OPT_FMT_i64  "%"PRId64
@@ -942,14 +931,4 @@ extern const char * const opt_name_frame_rates[];
 extern const char * const opt_name_top_field_first[];
 #endif
 
-static inline void pkt_move(void *dst, void *src)
-{
-    av_packet_move_ref(dst, src);
-}
-
-static inline void frame_move(void *dst, void *src)
-{
-    av_frame_move_ref(dst, src);
-}
-
 #endif /* FFTOOLS_FFMPEG_H */
diff --git a/fftools/ffmpeg_dec.c b/fftools/ffmpeg_dec.c
index fcee8b65ac..8795a94c1a 100644
--- a/fftools/ffmpeg_dec.c
+++ b/fftools/ffmpeg_dec.c
@@ -30,6 +30,7 @@
 #include "libavfilter/buffersrc.h"
 
 #include "ffmpeg.h"
+#include "ffmpeg_utils.h"
 #include "thread_queue.h"
 
 struct Decoder {
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index 350f233ab7..ec96daf26b 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -20,6 +20,7 @@
 #include <stdint.h>
 
 #include "ffmpeg.h"
+#include "ffmpeg_utils.h"
 
 #include "libavutil/avassert.h"
 #include "libavutil/avstring.h"
diff --git a/fftools/ffmpeg_mux.c b/fftools/ffmpeg_mux.c
index 7a924dba6c..30c033036d 100644
--- a/fftools/ffmpeg_mux.c
+++ b/fftools/ffmpeg_mux.c
@@ -22,6 +22,7 @@
 
 #include "ffmpeg.h"
 #include "ffmpeg_mux.h"
+#include "ffmpeg_utils.h"
 #include "objpool.h"
 #include "sync_queue.h"
 #include "thread_queue.h"
diff --git a/fftools/ffmpeg_utils.h b/fftools/ffmpeg_utils.h
new file mode 100644
index 0000000000..20cde94969
--- /dev/null
+++ b/fftools/ffmpeg_utils.h
@@ -0,0 +1,50 @@
+/*
+ * 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 FFTOOLS_FFMPEG_UTILS_H
+#define FFTOOLS_FFMPEG_UTILS_H
+
+#include <stdint.h>
+
+#include "libavutil/common.h"
+#include "libavutil/frame.h"
+
+#include "libavcodec/packet.h"
+
+/**
+ * Merge two return codes - return one of the error codes if at least one of
+ * them was negative, 0 otherwise.
+ * Currently just picks the first one, eventually we might want to do something
+ * more sophisticated, like sorting them by priority.
+ */
+static inline int err_merge(int err0, int err1)
+{
+    return (err0 < 0) ? err0 : FFMIN(err1, 0);
+}
+
+static inline void pkt_move(void *dst, void *src)
+{
+    av_packet_move_ref(dst, src);
+}
+
+static inline void frame_move(void *dst, void *src)
+{
+    av_frame_move_ref(dst, src);
+}
+
+#endif // FFTOOLS_FFMPEG_UTILS_H
-- 
2.42.0



More information about the ffmpeg-devel mailing list