[FFmpeg-devel] [PATCH 03/44] avformat/internal: Move muxing-only functions to new mux.h header

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Sat May 7 14:27:49 EEST 2022


Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
 libavdevice/alsa_enc.c           |  1 +
 libavdevice/opengl_enc.c         |  1 +
 libavdevice/pulse_audio_enc.c    |  1 +
 libavdevice/xv.c                 |  2 +-
 libavformat/dashenc.c            |  1 +
 libavformat/gxfenc.c             |  3 +-
 libavformat/hdsenc.c             |  3 +-
 libavformat/hlsenc.c             |  4 +-
 libavformat/internal.h           | 60 ----------------------
 libavformat/movenc.c             |  1 +
 libavformat/movenchint.c         |  2 +-
 libavformat/mux.c                |  2 +-
 libavformat/mux.h                | 88 ++++++++++++++++++++++++++++++++
 libavformat/mxfenc.c             |  2 +-
 libavformat/nullenc.c            |  2 +-
 libavformat/rtspenc.c            |  1 +
 libavformat/sapenc.c             |  1 +
 libavformat/segment.c            |  3 +-
 libavformat/smoothstreamingenc.c |  6 +--
 libavformat/uncodedframecrcenc.c |  1 +
 20 files changed, 106 insertions(+), 79 deletions(-)
 create mode 100644 libavformat/mux.h

diff --git a/libavdevice/alsa_enc.c b/libavdevice/alsa_enc.c
index fc5e5d9c94..3d6bccdc2a 100644
--- a/libavdevice/alsa_enc.c
+++ b/libavdevice/alsa_enc.c
@@ -44,6 +44,7 @@
 
 
 #include "libavformat/internal.h"
+#include "libavformat/mux.h"
 #include "avdevice.h"
 #include "alsa.h"
 
diff --git a/libavdevice/opengl_enc.c b/libavdevice/opengl_enc.c
index 9302979f46..06e8d3d7d3 100644
--- a/libavdevice/opengl_enc.c
+++ b/libavdevice/opengl_enc.c
@@ -57,6 +57,7 @@
 #include "libavutil/avstring.h"
 #include "libavformat/avformat.h"
 #include "libavformat/internal.h"
+#include "libavformat/mux.h"
 #include "libavdevice/avdevice.h"
 #include "opengl_enc_shaders.h"
 
diff --git a/libavdevice/pulse_audio_enc.c b/libavdevice/pulse_audio_enc.c
index 35beb14ead..d5928e2b3f 100644
--- a/libavdevice/pulse_audio_enc.c
+++ b/libavdevice/pulse_audio_enc.c
@@ -23,6 +23,7 @@
 #include <pulse/error.h>
 #include "libavformat/avformat.h"
 #include "libavformat/internal.h"
+#include "libavformat/mux.h"
 #include "libavformat/version.h"
 #include "libavutil/channel_layout.h"
 #include "libavutil/internal.h"
diff --git a/libavdevice/xv.c b/libavdevice/xv.c
index a346f8e306..348c289bea 100644
--- a/libavdevice/xv.c
+++ b/libavdevice/xv.c
@@ -35,7 +35,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/imgutils.h"
-#include "libavformat/internal.h"
+#include "libavformat/mux.h"
 #include "avdevice.h"
 
 typedef struct {
diff --git a/libavformat/dashenc.c b/libavformat/dashenc.c
index c90cb4c0fa..295b01e225 100644
--- a/libavformat/dashenc.c
+++ b/libavformat/dashenc.c
@@ -48,6 +48,7 @@
 #endif
 #include "internal.h"
 #include "isom.h"
+#include "mux.h"
 #include "os_support.h"
 #include "url.h"
 #include "vpcc.h"
diff --git a/libavformat/gxfenc.c b/libavformat/gxfenc.c
index e25d8764ba..0f971c039a 100644
--- a/libavformat/gxfenc.c
+++ b/libavformat/gxfenc.c
@@ -21,13 +21,12 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/intfloat.h"
-#include "libavutil/opt.h"
 #include "libavutil/mathematics.h"
-#include "libavutil/timecode.h"
 #include "avformat.h"
 #include "avio_internal.h"
 #include "internal.h"
 #include "gxf.h"
+#include "mux.h"
 
 #define GXF_SAMPLES_PER_FRAME 32768
 #define GXF_AUDIO_PACKET_SIZE 65536
diff --git a/libavformat/hdsenc.c b/libavformat/hdsenc.c
index 2a52019120..a8f340ac46 100644
--- a/libavformat/hdsenc.c
+++ b/libavformat/hdsenc.c
@@ -20,14 +20,13 @@
  */
 
 #include "config.h"
-#include <float.h>
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
 #include "avformat.h"
-#include "avio_internal.h"
 #include "internal.h"
+#include "mux.h"
 #include "os_support.h"
 
 #include "libavutil/avstring.h"
diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 14eb7c4530..f085780feb 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -22,7 +22,6 @@
 
 #include "config.h"
 #include "config_components.h"
-#include <float.h>
 #include <stdint.h>
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -36,11 +35,9 @@
 
 #include "libavutil/avassert.h"
 #include "libavutil/mathematics.h"
-#include "libavutil/parseutils.h"
 #include "libavutil/avstring.h"
 #include "libavutil/bprint.h"
 #include "libavutil/intreadwrite.h"
-#include "libavutil/random_seed.h"
 #include "libavutil/opt.h"
 #include "libavutil/log.h"
 #include "libavutil/time.h"
@@ -54,6 +51,7 @@
 #endif
 #include "hlsplaylist.h"
 #include "internal.h"
+#include "mux.h"
 #include "os_support.h"
 
 typedef enum {
diff --git a/libavformat/internal.h b/libavformat/internal.h
index 3ad76d992c..5ffc26600a 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -509,14 +509,6 @@ char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase);
  */
 int ff_hex_to_data(uint8_t *data, const char *p);
 
-/**
- * Add packet to an AVFormatContext's packet_buffer list, determining its
- * interleaved position using compare() function argument.
- * @return 0 on success, < 0 on error. pkt will always be blank on return.
- */
-int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
-                             int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *));
-
 void ff_read_frame_flush(AVFormatContext *s);
 
 #define NTP_OFFSET 2208988800ULL
@@ -564,22 +556,6 @@ int ff_sdp_write_media(char *buff, int size, const AVStream *st, int idx,
                        const char *dest_addr, const char *dest_type,
                        int port, int ttl, AVFormatContext *fmt);
 
-/**
- * Write a packet to another muxer than the one the user originally
- * intended. Useful when chaining muxers, where one muxer internally
- * writes a received packet to another muxer.
- *
- * @param dst the muxer to write the packet to
- * @param dst_stream the stream index within dst to write the packet to
- * @param pkt the packet to be written. It will be returned blank when
- *            av_interleaved_write_frame() is used, unchanged otherwise.
- * @param src the muxer the packet originally was intended for
- * @param interleave 0->use av_write_frame, 1->av_interleaved_write_frame
- * @return the value av_write_frame returned
- */
-int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
-                     AVFormatContext *src, int interleave);
-
 /**
  * Read a whole line of text from AVIOContext. Stop reading after reaching
  * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated,
@@ -766,20 +742,6 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt);
 int ff_add_attached_pic(AVFormatContext *s, AVStream *st, AVIOContext *pb,
                         AVBufferRef **buf, int size);
 
-/**
- * Interleave an AVPacket per dts so it can be muxed.
- * See the documentation of AVOutputFormat.interleave_packet for details.
- */
-int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
-                                 int flush, int has_packet);
-
-/**
- * Interleave packets directly in the order in which they arrive
- * without any sort of buffering.
- */
-int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt,
-                                     int flush, int has_packet);
-
 void ff_free_stream(AVFormatContext *s, AVStream *st);
 
 unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id);
@@ -891,19 +853,6 @@ int ff_rfps_add_frame(AVFormatContext *ic, AVStream *st, int64_t dts);
 
 void ff_rfps_calculate(AVFormatContext *ic);
 
-/**
- * Flags for AVFormatContext.write_uncoded_frame()
- */
-enum AVWriteUncodedFrameFlags {
-
-    /**
-     * Query whether the feature is possible on this stream.
-     * The frame argument is ignored.
-     */
-    AV_WRITE_UNCODED_FRAME_QUERY           = 0x0001,
-
-};
-
 /**
  * Copies the whilelists from one context to the other
  */
@@ -1000,15 +949,6 @@ struct AVBPrint;
  */
 int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf);
 
-/**
- * Find the next packet in the interleaving queue for the given stream.
- *
- * @return a pointer to a packet if one was found, NULL otherwise.
- */
-const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);
-
-int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset);
-
 int ff_lock_avformat(void);
 int ff_unlock_avformat(void);
 
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index c2aed6329f..d32328d40c 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -61,6 +61,7 @@
 #include "rtpenc.h"
 #include "mov_chan.h"
 #include "movenc_ttml.h"
+#include "mux.h"
 #include "ttmlenc.h"
 #include "version.h"
 #include "vpcc.h"
diff --git a/libavformat/movenchint.c b/libavformat/movenchint.c
index 35212f2c5d..aaaaa3ac7b 100644
--- a/libavformat/movenchint.c
+++ b/libavformat/movenchint.c
@@ -21,7 +21,7 @@
 
 #include "movenc.h"
 #include "libavutil/intreadwrite.h"
-#include "internal.h"
+#include "mux.h"
 #include "rtpenc_chain.h"
 #include "avio_internal.h"
 #include "rtp.h"
diff --git a/libavformat/mux.c b/libavformat/mux.c
index 1c1fbf275c..f1ae1c874e 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -21,6 +21,7 @@
 
 #include "avformat.h"
 #include "internal.h"
+#include "mux.h"
 #include "version.h"
 #include "libavcodec/bsf.h"
 #include "libavcodec/internal.h"
@@ -30,7 +31,6 @@
 #include "libavutil/pixdesc.h"
 #include "libavutil/timestamp.h"
 #include "libavutil/avassert.h"
-#include "libavutil/avstring.h"
 #include "libavutil/internal.h"
 #include "libavutil/mathematics.h"
 
diff --git a/libavformat/mux.h b/libavformat/mux.h
new file mode 100644
index 0000000000..d1dc2fa2cb
--- /dev/null
+++ b/libavformat/mux.h
@@ -0,0 +1,88 @@
+/*
+ * copyright (c) 2001 Fabrice Bellard
+ *
+ * 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 AVFORMAT_MUX_H
+#define AVFORMAT_MUX_H
+
+#include <stdint.h>
+#include "libavcodec/packet.h"
+#include "avformat.h"
+
+/**
+ * Add packet to an AVFormatContext's packet_buffer list, determining its
+ * interleaved position using compare() function argument.
+ * @return 0 on success, < 0 on error. pkt will always be blank on return.
+ */
+int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt,
+                             int (*compare)(AVFormatContext *, const AVPacket *, const AVPacket *));
+
+/**
+ * Interleave an AVPacket per dts so it can be muxed.
+ * See the documentation of AVOutputFormat.interleave_packet for details.
+ */
+int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *pkt,
+                                 int flush, int has_packet);
+
+/**
+ * Interleave packets directly in the order in which they arrive
+ * without any sort of buffering.
+ */
+int ff_interleave_packet_passthrough(AVFormatContext *s, AVPacket *pkt,
+                                     int flush, int has_packet);
+
+/**
+ * Find the next packet in the interleaving queue for the given stream.
+ *
+ * @return a pointer to a packet if one was found, NULL otherwise.
+ */
+const AVPacket *ff_interleaved_peek(AVFormatContext *s, int stream);
+
+int ff_get_muxer_ts_offset(AVFormatContext *s, int stream_index, int64_t *offset);
+
+/**
+ * Write a packet to another muxer than the one the user originally
+ * intended. Useful when chaining muxers, where one muxer internally
+ * writes a received packet to another muxer.
+ *
+ * @param dst the muxer to write the packet to
+ * @param dst_stream the stream index within dst to write the packet to
+ * @param pkt the packet to be written. It will be returned blank when
+ *            av_interleaved_write_frame() is used, unchanged otherwise.
+ * @param src the muxer the packet originally was intended for
+ * @param interleave 0->use av_write_frame, 1->av_interleaved_write_frame
+ * @return the value av_write_frame returned
+ */
+int ff_write_chained(AVFormatContext *dst, int dst_stream, AVPacket *pkt,
+                     AVFormatContext *src, int interleave);
+
+/**
+ * Flags for AVFormatContext.write_uncoded_frame()
+ */
+enum AVWriteUncodedFrameFlags {
+
+    /**
+     * Query whether the feature is possible on this stream.
+     * The frame argument is ignored.
+     */
+    AV_WRITE_UNCODED_FRAME_QUERY           = 0x0001,
+
+};
+
+#endif /* AVFORMAT_MUX_H */
diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c
index 8bc1a2807c..2061b2eede 100644
--- a/libavformat/mxfenc.c
+++ b/libavformat/mxfenc.c
@@ -38,7 +38,6 @@
  */
 
 #include <inttypes.h>
-#include <math.h>
 #include <time.h>
 
 #include "libavutil/opt.h"
@@ -56,6 +55,7 @@
 #include "avio_internal.h"
 #include "internal.h"
 #include "avc.h"
+#include "mux.h"
 #include "mxf.h"
 #include "config.h"
 #include "version.h"
diff --git a/libavformat/nullenc.c b/libavformat/nullenc.c
index d4769d5920..3deca5a7ed 100644
--- a/libavformat/nullenc.c
+++ b/libavformat/nullenc.c
@@ -20,7 +20,7 @@
  */
 
 #include "avformat.h"
-#include "internal.h"
+#include "mux.h"
 
 static int null_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
diff --git a/libavformat/rtspenc.c b/libavformat/rtspenc.c
index 5c7e0b4e8b..21b204381b 100644
--- a/libavformat/rtspenc.c
+++ b/libavformat/rtspenc.c
@@ -24,6 +24,7 @@
 #if HAVE_POLL_H
 #include <poll.h>
 #endif
+#include "mux.h"
 #include "network.h"
 #include "os_support.h"
 #include "rtsp.h"
diff --git a/libavformat/sapenc.c b/libavformat/sapenc.c
index 9319ee6f80..8eb9d3b92a 100644
--- a/libavformat/sapenc.c
+++ b/libavformat/sapenc.c
@@ -27,6 +27,7 @@
 #include "libavutil/intreadwrite.h"
 #include "libavutil/time.h"
 #include "internal.h"
+#include "mux.h"
 #include "network.h"
 #include "os_support.h"
 #include "rtpenc_chain.h"
diff --git a/libavformat/segment.c b/libavformat/segment.c
index ef0529a920..fa435d9f32 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -26,12 +26,11 @@
 
 #include "config_components.h"
 
-#include <float.h>
 #include <time.h>
 
 #include "avformat.h"
-#include "avio_internal.h"
 #include "internal.h"
+#include "mux.h"
 
 #include "libavutil/avassert.h"
 #include "libavutil/internal.h"
diff --git a/libavformat/smoothstreamingenc.c b/libavformat/smoothstreamingenc.c
index c67f0cba43..1713dd9009 100644
--- a/libavformat/smoothstreamingenc.c
+++ b/libavformat/smoothstreamingenc.c
@@ -20,24 +20,20 @@
  */
 
 #include "config.h"
-#include <float.h>
 #if HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
 #include "avformat.h"
-#include "avio_internal.h"
 #include "internal.h"
+#include "mux.h"
 #include "os_support.h"
 #include "avc.h"
 #include "url.h"
-#include "isom.h"
 
 #include "libavutil/opt.h"
 #include "libavutil/avstring.h"
-#include "libavutil/file.h"
 #include "libavutil/mathematics.h"
-#include "libavutil/intreadwrite.h"
 
 typedef struct Fragment {
     int64_t start_time, duration;
diff --git a/libavformat/uncodedframecrcenc.c b/libavformat/uncodedframecrcenc.c
index 1ad37071a6..99990616d3 100644
--- a/libavformat/uncodedframecrcenc.c
+++ b/libavformat/uncodedframecrcenc.c
@@ -23,6 +23,7 @@
 #include "libavutil/bprint.h"
 #include "libavutil/imgutils.h"
 #include "libavutil/pixdesc.h"
+#include "libavformat/mux.h"
 #include "avformat.h"
 #include "internal.h"
 
-- 
2.32.0



More information about the ffmpeg-devel mailing list