aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2020-04-07 16:41:48 +0200
committerAnton Khirnov <anton@khirnov.net>2020-05-22 14:38:57 +0200
commitbdd6aa25c1f413c66053537e0f98741a8b40f5dd (patch)
tree61a3af82a99e18c45ce9e5fae3ca35dc2fbe8ac4 /libavcodec
parentbf80725352d274aed2fdd8f2d457788b3c2e5e7e (diff)
downloadffmpeg-bdd6aa25c1f413c66053537e0f98741a8b40f5dd.tar.gz
avcodec.h: split bitstream filters API into its own header
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/Makefile1
-rw-r--r--libavcodec/aac_adtstoasc_bsf.c2
-rw-r--r--libavcodec/av1_frame_merge_bsf.c2
-rw-r--r--libavcodec/av1_frame_split_bsf.c2
-rw-r--r--libavcodec/av1_metadata_bsf.c1
-rw-r--r--libavcodec/avcodec.h285
-rw-r--r--libavcodec/bsf.c4
-rw-r--r--libavcodec/bsf.h324
-rw-r--r--libavcodec/bsf_internal.h5
-rw-r--r--libavcodec/chomp_bsf.c2
-rw-r--r--libavcodec/dca_core_bsf.c2
-rw-r--r--libavcodec/dump_extradata_bsf.c2
-rw-r--r--libavcodec/eac3_core_bsf.c2
-rw-r--r--libavcodec/extract_extradata_bsf.c2
-rw-r--r--libavcodec/filter_units_bsf.c1
-rw-r--r--libavcodec/h264_metadata_bsf.c1
-rw-r--r--libavcodec/h264_mp4toannexb_bsf.c1
-rw-r--r--libavcodec/h264_redundant_pps_bsf.c1
-rw-r--r--libavcodec/h265_metadata_bsf.c1
-rw-r--r--libavcodec/hapqa_extract_bsf.c2
-rw-r--r--libavcodec/hevc_mp4toannexb_bsf.c1
-rw-r--r--libavcodec/imx_dump_header_bsf.c2
-rw-r--r--libavcodec/mjpeg2jpeg_bsf.c2
-rw-r--r--libavcodec/mjpega_dump_header_bsf.c2
-rw-r--r--libavcodec/movsub_bsf.c2
-rw-r--r--libavcodec/mp3_header_decompress_bsf.c2
-rw-r--r--libavcodec/mpeg2_metadata_bsf.c1
-rw-r--r--libavcodec/mpeg4_unpack_bframes_bsf.c2
-rw-r--r--libavcodec/noise_bsf.c2
-rw-r--r--libavcodec/null_bsf.c2
-rw-r--r--libavcodec/prores_metadata_bsf.c2
-rw-r--r--libavcodec/remove_extradata_bsf.c1
-rw-r--r--libavcodec/trace_headers_bsf.c1
-rw-r--r--libavcodec/truehd_core_bsf.c2
-rw-r--r--libavcodec/vp9_metadata_bsf.c1
-rw-r--r--libavcodec/vp9_raw_reorder_bsf.c1
-rw-r--r--libavcodec/vp9_superframe_bsf.c3
-rw-r--r--libavcodec/vp9_superframe_split_bsf.c2
38 files changed, 368 insertions, 306 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 68e4ca0a67..3d38b4a05d 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -6,6 +6,7 @@ HEADERS = ac3_parser.h \
avcodec.h \
avdct.h \
avfft.h \
+ bsf.h \
codec_desc.h \
codec_id.h \
codec_par.h \
diff --git a/libavcodec/aac_adtstoasc_bsf.c b/libavcodec/aac_adtstoasc_bsf.c
index 1d0117fecb..69453c706f 100644
--- a/libavcodec/aac_adtstoasc_bsf.c
+++ b/libavcodec/aac_adtstoasc_bsf.c
@@ -21,7 +21,7 @@
#include "adts_header.h"
#include "adts_parser.h"
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "put_bits.h"
#include "get_bits.h"
diff --git a/libavcodec/av1_frame_merge_bsf.c b/libavcodec/av1_frame_merge_bsf.c
index c67b86c8d4..b5aa57e0ff 100644
--- a/libavcodec/av1_frame_merge_bsf.c
+++ b/libavcodec/av1_frame_merge_bsf.c
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_av1.h"
diff --git a/libavcodec/av1_frame_split_bsf.c b/libavcodec/av1_frame_split_bsf.c
index fc9eac0324..87dfc83103 100644
--- a/libavcodec/av1_frame_split_bsf.c
+++ b/libavcodec/av1_frame_split_bsf.c
@@ -32,7 +32,7 @@
#include "libavutil/avassert.h"
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_av1.h"
diff --git a/libavcodec/av1_metadata_bsf.c b/libavcodec/av1_metadata_bsf.c
index 21ad3ac2d1..ee1a63c1ec 100644
--- a/libavcodec/av1_metadata_bsf.c
+++ b/libavcodec/av1_metadata_bsf.c
@@ -19,6 +19,7 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_av1.h"
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index fe931a3b9c..f10b7a06ec 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -41,6 +41,7 @@
#include "libavutil/pixfmt.h"
#include "libavutil/rational.h"
+#include "bsf.h"
#include "codec_desc.h"
#include "codec_par.h"
#include "codec_id.h"
@@ -4382,106 +4383,7 @@ typedef struct AVBitStreamFilterContext {
*/
char *args;
} AVBitStreamFilterContext;
-#endif
-
-typedef struct AVBSFInternal AVBSFInternal;
-
-/**
- * The bitstream filter state.
- *
- * This struct must be allocated with av_bsf_alloc() and freed with
- * av_bsf_free().
- *
- * The fields in the struct will only be changed (by the caller or by the
- * filter) as described in their documentation, and are to be considered
- * immutable otherwise.
- */
-typedef struct AVBSFContext {
- /**
- * A class for logging and AVOptions
- */
- const AVClass *av_class;
-
- /**
- * The bitstream filter this context is an instance of.
- */
- const struct AVBitStreamFilter *filter;
-
- /**
- * Opaque libavcodec internal data. Must not be touched by the caller in any
- * way.
- */
- AVBSFInternal *internal;
-
- /**
- * Opaque filter-specific private data. If filter->priv_class is non-NULL,
- * this is an AVOptions-enabled struct.
- */
- void *priv_data;
-
- /**
- * Parameters of the input stream. This field is allocated in
- * av_bsf_alloc(), it needs to be filled by the caller before
- * av_bsf_init().
- */
- AVCodecParameters *par_in;
-
- /**
- * Parameters of the output stream. This field is allocated in
- * av_bsf_alloc(), it is set by the filter in av_bsf_init().
- */
- AVCodecParameters *par_out;
-
- /**
- * The timebase used for the timestamps of the input packets. Set by the
- * caller before av_bsf_init().
- */
- AVRational time_base_in;
-
- /**
- * The timebase used for the timestamps of the output packets. Set by the
- * filter in av_bsf_init().
- */
- AVRational time_base_out;
-} AVBSFContext;
-typedef struct AVBitStreamFilter {
- const char *name;
-
- /**
- * A list of codec ids supported by the filter, terminated by
- * AV_CODEC_ID_NONE.
- * May be NULL, in that case the bitstream filter works with any codec id.
- */
- const enum AVCodecID *codec_ids;
-
- /**
- * A class for the private data, used to declare bitstream filter private
- * AVOptions. This field is NULL for bitstream filters that do not declare
- * any options.
- *
- * If this field is non-NULL, the first member of the filter private data
- * must be a pointer to AVClass, which will be set by libavcodec generic
- * code to this class.
- */
- const AVClass *priv_class;
-
- /*****************************************************************
- * No fields below this line are part of the public API. They
- * may not be used outside of libavcodec and can be changed and
- * removed at will.
- * New public fields should be added right above.
- *****************************************************************
- */
-
- int priv_data_size;
- int (*init)(AVBSFContext *ctx);
- int (*filter)(AVBSFContext *ctx, AVPacket *pkt);
- void (*close)(AVBSFContext *ctx);
- void (*flush)(AVBSFContext *ctx);
-} AVBitStreamFilter;
-
-#if FF_API_OLD_BSF
/**
* @deprecated the old bitstream filtering API (using AVBitStreamFilterContext)
* is deprecated. Use the new bitstream filtering API (using AVBSFContext).
@@ -4521,196 +4423,11 @@ attribute_deprecated
const AVBitStreamFilter *av_bitstream_filter_next(const AVBitStreamFilter *f);
#endif
-/**
- * @return a bitstream filter with the specified name or NULL if no such
- * bitstream filter exists.
- */
-const AVBitStreamFilter *av_bsf_get_by_name(const char *name);
-
-/**
- * Iterate over all registered bitstream filters.
- *
- * @param opaque a pointer where libavcodec will store the iteration state. Must
- * point to NULL to start the iteration.
- *
- * @return the next registered bitstream filter or NULL when the iteration is
- * finished
- */
-const AVBitStreamFilter *av_bsf_iterate(void **opaque);
#if FF_API_NEXT
attribute_deprecated
const AVBitStreamFilter *av_bsf_next(void **opaque);
#endif
-/**
- * Allocate a context for a given bitstream filter. The caller must fill in the
- * context parameters as described in the documentation and then call
- * av_bsf_init() before sending any data to the filter.
- *
- * @param filter the filter for which to allocate an instance.
- * @param ctx a pointer into which the pointer to the newly-allocated context
- * will be written. It must be freed with av_bsf_free() after the
- * filtering is done.
- *
- * @return 0 on success, a negative AVERROR code on failure
- */
-int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx);
-
-/**
- * Prepare the filter for use, after all the parameters and options have been
- * set.
- */
-int av_bsf_init(AVBSFContext *ctx);
-
-/**
- * Submit a packet for filtering.
- *
- * After sending each packet, the filter must be completely drained by calling
- * av_bsf_receive_packet() repeatedly until it returns AVERROR(EAGAIN) or
- * AVERROR_EOF.
- *
- * @param pkt the packet to filter. The bitstream filter will take ownership of
- * the packet and reset the contents of pkt. pkt is not touched if an error occurs.
- * If pkt is empty (i.e. NULL, or pkt->data is NULL and pkt->side_data_elems zero),
- * it signals the end of the stream (i.e. no more non-empty packets will be sent;
- * sending more empty packets does nothing) and will cause the filter to output
- * any packets it may have buffered internally.
- *
- * @return 0 on success, a negative AVERROR on error. This function never fails if
- * pkt is empty.
- */
-int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt);
-
-/**
- * Retrieve a filtered packet.
- *
- * @param[out] pkt this struct will be filled with the contents of the filtered
- * packet. It is owned by the caller and must be freed using
- * av_packet_unref() when it is no longer needed.
- * This parameter should be "clean" (i.e. freshly allocated
- * with av_packet_alloc() or unreffed with av_packet_unref())
- * when this function is called. If this function returns
- * successfully, the contents of pkt will be completely
- * overwritten by the returned data. On failure, pkt is not
- * touched.
- *
- * @return 0 on success. AVERROR(EAGAIN) if more packets need to be sent to the
- * filter (using av_bsf_send_packet()) to get more output. AVERROR_EOF if there
- * will be no further output from the filter. Another negative AVERROR value if
- * an error occurs.
- *
- * @note one input packet may result in several output packets, so after sending
- * a packet with av_bsf_send_packet(), this function needs to be called
- * repeatedly until it stops returning 0. It is also possible for a filter to
- * output fewer packets than were sent to it, so this function may return
- * AVERROR(EAGAIN) immediately after a successful av_bsf_send_packet() call.
- */
-int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt);
-
-/**
- * Reset the internal bitstream filter state / flush internal buffers.
- */
-void av_bsf_flush(AVBSFContext *ctx);
-
-/**
- * Free a bitstream filter context and everything associated with it; write NULL
- * into the supplied pointer.
- */
-void av_bsf_free(AVBSFContext **ctx);
-
-/**
- * Get the AVClass for AVBSFContext. It can be used in combination with
- * AV_OPT_SEARCH_FAKE_OBJ for examining options.
- *
- * @see av_opt_find().
- */
-const AVClass *av_bsf_get_class(void);
-
-/**
- * Structure for chain/list of bitstream filters.
- * Empty list can be allocated by av_bsf_list_alloc().
- */
-typedef struct AVBSFList AVBSFList;
-
-/**
- * Allocate empty list of bitstream filters.
- * The list must be later freed by av_bsf_list_free()
- * or finalized by av_bsf_list_finalize().
- *
- * @return Pointer to @ref AVBSFList on success, NULL in case of failure
- */
-AVBSFList *av_bsf_list_alloc(void);
-
-/**
- * Free list of bitstream filters.
- *
- * @param lst Pointer to pointer returned by av_bsf_list_alloc()
- */
-void av_bsf_list_free(AVBSFList **lst);
-
-/**
- * Append bitstream filter to the list of bitstream filters.
- *
- * @param lst List to append to
- * @param bsf Filter context to be appended
- *
- * @return >=0 on success, negative AVERROR in case of failure
- */
-int av_bsf_list_append(AVBSFList *lst, AVBSFContext *bsf);
-
-/**
- * Construct new bitstream filter context given it's name and options
- * and append it to the list of bitstream filters.
- *
- * @param lst List to append to
- * @param bsf_name Name of the bitstream filter
- * @param options Options for the bitstream filter, can be set to NULL
- *
- * @return >=0 on success, negative AVERROR in case of failure
- */
-int av_bsf_list_append2(AVBSFList *lst, const char * bsf_name, AVDictionary **options);
-/**
- * Finalize list of bitstream filters.
- *
- * This function will transform @ref AVBSFList to single @ref AVBSFContext,
- * so the whole chain of bitstream filters can be treated as single filter
- * freshly allocated by av_bsf_alloc().
- * If the call is successful, @ref AVBSFList structure is freed and lst
- * will be set to NULL. In case of failure, caller is responsible for
- * freeing the structure by av_bsf_list_free()
- *
- * @param lst Filter list structure to be transformed
- * @param[out] bsf Pointer to be set to newly created @ref AVBSFContext structure
- * representing the chain of bitstream filters
- *
- * @return >=0 on success, negative AVERROR in case of failure
- */
-int av_bsf_list_finalize(AVBSFList **lst, AVBSFContext **bsf);
-
-/**
- * Parse string describing list of bitstream filters and create single
- * @ref AVBSFContext describing the whole chain of bitstream filters.
- * Resulting @ref AVBSFContext can be treated as any other @ref AVBSFContext freshly
- * allocated by av_bsf_alloc().
- *
- * @param str String describing chain of bitstream filters in format
- * `bsf1[=opt1=val1:opt2=val2][,bsf2]`
- * @param[out] bsf Pointer to be set to newly created @ref AVBSFContext structure
- * representing the chain of bitstream filters
- *
- * @return >=0 on success, negative AVERROR in case of failure
- */
-int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf);
-
-/**
- * Get null/pass-through bitstream filter.
- *
- * @param[out] bsf Pointer to be set to new instance of pass-through bitstream filter
- *
- * @return
- */
-int av_bsf_get_null_filter(AVBSFContext **bsf);
-
/* memory */
/**
diff --git a/libavcodec/bsf.c b/libavcodec/bsf.c
index 42c20df296..5e1c794a76 100644
--- a/libavcodec/bsf.c
+++ b/libavcodec/bsf.c
@@ -25,8 +25,10 @@
#include "libavutil/avstring.h"
#include "libavutil/bprint.h"
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
+#include "codec_desc.h"
+#include "codec_par.h"
#define IS_EMPTY(pkt) (!(pkt)->data && !(pkt)->side_data_elems)
diff --git a/libavcodec/bsf.h b/libavcodec/bsf.h
new file mode 100644
index 0000000000..264a10a9b8
--- /dev/null
+++ b/libavcodec/bsf.h
@@ -0,0 +1,324 @@
+/*
+ * Bitstream filters public API
+ *
+ * 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 AVCODEC_BSF_H
+#define AVCODEC_BSF_H
+
+#include "libavutil/dict.h"
+#include "libavutil/log.h"
+#include "libavutil/rational.h"
+
+#include "codec_id.h"
+#include "codec_par.h"
+#include "packet.h"
+
+/**
+ * @addtogroup lavc_core
+ * @{
+ */
+
+typedef struct AVBSFInternal AVBSFInternal;
+
+/**
+ * The bitstream filter state.
+ *
+ * This struct must be allocated with av_bsf_alloc() and freed with
+ * av_bsf_free().
+ *
+ * The fields in the struct will only be changed (by the caller or by the
+ * filter) as described in their documentation, and are to be considered
+ * immutable otherwise.
+ */
+typedef struct AVBSFContext {
+ /**
+ * A class for logging and AVOptions
+ */
+ const AVClass *av_class;
+
+ /**
+ * The bitstream filter this context is an instance of.
+ */
+ const struct AVBitStreamFilter *filter;
+
+ /**
+ * Opaque libavcodec internal data. Must not be touched by the caller in any
+ * way.
+ */
+ AVBSFInternal *internal;
+
+ /**
+ * Opaque filter-specific private data. If filter->priv_class is non-NULL,
+ * this is an AVOptions-enabled struct.
+ */
+ void *priv_data;
+
+ /**
+ * Parameters of the input stream. This field is allocated in
+ * av_bsf_alloc(), it needs to be filled by the caller before
+ * av_bsf_init().
+ */
+ AVCodecParameters *par_in;
+
+ /**
+ * Parameters of the output stream. This field is allocated in
+ * av_bsf_alloc(), it is set by the filter in av_bsf_init().
+ */
+ AVCodecParameters *par_out;
+
+ /**
+ * The timebase used for the timestamps of the input packets. Set by the
+ * caller before av_bsf_init().
+ */
+ AVRational time_base_in;
+
+ /**
+ * The timebase used for the timestamps of the output packets. Set by the
+ * filter in av_bsf_init().
+ */
+ AVRational time_base_out;
+} AVBSFContext;
+
+typedef struct AVBitStreamFilter {
+ const char *name;
+
+ /**
+ * A list of codec ids supported by the filter, terminated by
+ * AV_CODEC_ID_NONE.
+ * May be NULL, in that case the bitstream filter works with any codec id.
+ */
+ const enum AVCodecID *codec_ids;
+
+ /**
+ * A class for the private data, used to declare bitstream filter private
+ * AVOptions. This field is NULL for bitstream filters that do not declare
+ * any options.
+ *
+ * If this field is non-NULL, the first member of the filter private data
+ * must be a pointer to AVClass, which will be set by libavcodec generic
+ * code to this class.
+ */
+ const AVClass *priv_class;
+
+ /*****************************************************************
+ * No fields below this line are part of the public API. They
+ * may not be used outside of libavcodec and can be changed and
+ * removed at will.
+ * New public fields should be added right above.
+ *****************************************************************
+ */
+
+ int priv_data_size;
+ int (*init)(AVBSFContext *ctx);
+ int (*filter)(AVBSFContext *ctx, AVPacket *pkt);
+ void (*close)(AVBSFContext *ctx);
+ void (*flush)(AVBSFContext *ctx);
+} AVBitStreamFilter;
+
+/**
+ * @return a bitstream filter with the specified name or NULL if no such
+ * bitstream filter exists.
+ */
+const AVBitStreamFilter *av_bsf_get_by_name(const char *name);
+
+/**
+ * Iterate over all registered bitstream filters.
+ *
+ * @param opaque a pointer where libavcodec will store the iteration state. Must
+ * point to NULL to start the iteration.
+ *
+ * @return the next registered bitstream filter or NULL when the iteration is
+ * finished
+ */
+const AVBitStreamFilter *av_bsf_iterate(void **opaque);
+
+/**
+ * Allocate a context for a given bitstream filter. The caller must fill in the
+ * context parameters as described in the documentation and then call
+ * av_bsf_init() before sending any data to the filter.
+ *
+ * @param filter the filter for which to allocate an instance.
+ * @param ctx a pointer into which the pointer to the newly-allocated context
+ * will be written. It must be freed with av_bsf_free() after the
+ * filtering is done.
+ *
+ * @return 0 on success, a negative AVERROR code on failure
+ */
+int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx);
+
+/**
+ * Prepare the filter for use, after all the parameters and options have been
+ * set.
+ */
+int av_bsf_init(AVBSFContext *ctx);
+
+/**
+ * Submit a packet for filtering.
+ *
+ * After sending each packet, the filter must be completely drained by calling
+ * av_bsf_receive_packet() repeatedly until it returns AVERROR(EAGAIN) or
+ * AVERROR_EOF.
+ *
+ * @param pkt the packet to filter. The bitstream filter will take ownership of
+ * the packet and reset the contents of pkt. pkt is not touched if an error occurs.
+ * If pkt is empty (i.e. NULL, or pkt->data is NULL and pkt->side_data_elems zero),
+ * it signals the end of the stream (i.e. no more non-empty packets will be sent;
+ * sending more empty packets does nothing) and will cause the filter to output
+ * any packets it may have buffered internally.
+ *
+ * @return 0 on success, a negative AVERROR on error. This function never fails if
+ * pkt is empty.
+ */
+int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt);
+
+/**
+ * Retrieve a filtered packet.
+ *
+ * @param[out] pkt this struct will be filled with the contents of the filtered
+ * packet. It is owned by the caller and must be freed using
+ * av_packet_unref() when it is no longer needed.
+ * This parameter should be "clean" (i.e. freshly allocated
+ * with av_packet_alloc() or unreffed with av_packet_unref())
+ * when this function is called. If this function returns
+ * successfully, the contents of pkt will be completely
+ * overwritten by the returned data. On failure, pkt is not
+ * touched.
+ *
+ * @return 0 on success. AVERROR(EAGAIN) if more packets need to be sent to the
+ * filter (using av_bsf_send_packet()) to get more output. AVERROR_EOF if there
+ * will be no further output from the filter. Another negative AVERROR value if
+ * an error occurs.
+ *
+ * @note one input packet may result in several output packets, so after sending
+ * a packet with av_bsf_send_packet(), this function needs to be called
+ * repeatedly until it stops returning 0. It is also possible for a filter to
+ * output fewer packets than were sent to it, so this function may return
+ * AVERROR(EAGAIN) immediately after a successful av_bsf_send_packet() call.
+ */
+int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt);
+
+/**
+ * Reset the internal bitstream filter state / flush internal buffers.
+ */
+void av_bsf_flush(AVBSFContext *ctx);
+
+/**
+ * Free a bitstream filter context and everything associated with it; write NULL
+ * into the supplied pointer.
+ */
+void av_bsf_free(AVBSFContext **ctx);
+
+/**
+ * Get the AVClass for AVBSFContext. It can be used in combination with
+ * AV_OPT_SEARCH_FAKE_OBJ for examining options.
+ *
+ * @see av_opt_find().
+ */
+const AVClass *av_bsf_get_class(void);
+
+/**
+ * Structure for chain/list of bitstream filters.
+ * Empty list can be allocated by av_bsf_list_alloc().
+ */
+typedef struct AVBSFList AVBSFList;
+
+/**
+ * Allocate empty list of bitstream filters.
+ * The list must be later freed by av_bsf_list_free()
+ * or finalized by av_bsf_list_finalize().
+ *
+ * @return Pointer to @ref AVBSFList on success, NULL in case of failure
+ */
+AVBSFList *av_bsf_list_alloc(void);
+
+/**
+ * Free list of bitstream filters.
+ *
+ * @param lst Pointer to pointer returned by av_bsf_list_alloc()
+ */
+void av_bsf_list_free(AVBSFList **lst);
+
+/**
+ * Append bitstream filter to the list of bitstream filters.
+ *
+ * @param lst List to append to
+ * @param bsf Filter context to be appended
+ *
+ * @return >=0 on success, negative AVERROR in case of failure
+ */
+int av_bsf_list_append(AVBSFList *lst, AVBSFContext *bsf);
+
+/**
+ * Construct new bitstream filter context given it's name and options
+ * and append it to the list of bitstream filters.
+ *
+ * @param lst List to append to
+ * @param bsf_name Name of the bitstream filter
+ * @param options Options for the bitstream filter, can be set to NULL
+ *
+ * @return >=0 on success, negative AVERROR in case of failure
+ */
+int av_bsf_list_append2(AVBSFList *lst, const char * bsf_name, AVDictionary **options);
+/**
+ * Finalize list of bitstream filters.
+ *
+ * This function will transform @ref AVBSFList to single @ref AVBSFContext,
+ * so the whole chain of bitstream filters can be treated as single filter
+ * freshly allocated by av_bsf_alloc().
+ * If the call is successful, @ref AVBSFList structure is freed and lst
+ * will be set to NULL. In case of failure, caller is responsible for
+ * freeing the structure by av_bsf_list_free()
+ *
+ * @param lst Filter list structure to be transformed
+ * @param[out] bsf Pointer to be set to newly created @ref AVBSFContext structure
+ * representing the chain of bitstream filters
+ *
+ * @return >=0 on success, negative AVERROR in case of failure
+ */
+int av_bsf_list_finalize(AVBSFList **lst, AVBSFContext **bsf);
+
+/**
+ * Parse string describing list of bitstream filters and create single
+ * @ref AVBSFContext describing the whole chain of bitstream filters.
+ * Resulting @ref AVBSFContext can be treated as any other @ref AVBSFContext freshly
+ * allocated by av_bsf_alloc().
+ *
+ * @param str String describing chain of bitstream filters in format
+ * `bsf1[=opt1=val1:opt2=val2][,bsf2]`
+ * @param[out] bsf Pointer to be set to newly created @ref AVBSFContext structure
+ * representing the chain of bitstream filters
+ *
+ * @return >=0 on success, negative AVERROR in case of failure
+ */
+int av_bsf_list_parse_str(const char *str, AVBSFContext **bsf);
+
+/**
+ * Get null/pass-through bitstream filter.
+ *
+ * @param[out] bsf Pointer to be set to new instance of pass-through bitstream filter
+ *
+ * @return
+ */
+int av_bsf_get_null_filter(AVBSFContext **bsf);
+
+/**
+ * @}
+ */
+
+#endif // AVCODEC_BSF_H
diff --git a/libavcodec/bsf_internal.h b/libavcodec/bsf_internal.h
index d22c1b4f83..fefd5b8905 100644
--- a/libavcodec/bsf_internal.h
+++ b/libavcodec/bsf_internal.h
@@ -19,7 +19,10 @@
#ifndef AVCODEC_BSF_INTERNAL_H
#define AVCODEC_BSF_INTERNAL_H
-#include "avcodec.h"
+#include "libavutil/log.h"
+
+#include "bsf.h"
+#include "packet.h"
/**
* Called by the bitstream filters to get the next packet for filtering.
diff --git a/libavcodec/chomp_bsf.c b/libavcodec/chomp_bsf.c
index 19d073322c..48b9336466 100644
--- a/libavcodec/chomp_bsf.c
+++ b/libavcodec/chomp_bsf.c
@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
static int chomp_filter(AVBSFContext *ctx, AVPacket *pkt)
diff --git a/libavcodec/dca_core_bsf.c b/libavcodec/dca_core_bsf.c
index 0461d02244..b92e6a1ba6 100644
--- a/libavcodec/dca_core_bsf.c
+++ b/libavcodec/dca_core_bsf.c
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "bytestream.h"
#include "dca_syncwords.h"
diff --git a/libavcodec/dump_extradata_bsf.c b/libavcodec/dump_extradata_bsf.c
index d456a35598..b6ef8b3e6b 100644
--- a/libavcodec/dump_extradata_bsf.c
+++ b/libavcodec/dump_extradata_bsf.c
@@ -20,7 +20,7 @@
#include <string.h>
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "libavutil/log.h"
diff --git a/libavcodec/eac3_core_bsf.c b/libavcodec/eac3_core_bsf.c
index c584d69227..49c3389ee1 100644
--- a/libavcodec/eac3_core_bsf.c
+++ b/libavcodec/eac3_core_bsf.c
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "get_bits.h"
#include "ac3_parser_internal.h"
diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c
index d7ffa1bff2..1fead74b57 100644
--- a/libavcodec/extract_extradata_bsf.c
+++ b/libavcodec/extract_extradata_bsf.c
@@ -23,9 +23,9 @@
#include "libavutil/log.h"
#include "libavutil/opt.h"
-#include "avcodec.h"
#include "av1.h"
#include "av1_parse.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "bytestream.h"
#include "h2645_parse.h"
diff --git a/libavcodec/filter_units_bsf.c b/libavcodec/filter_units_bsf.c
index 7c3819c7b3..700dc06ef6 100644
--- a/libavcodec/filter_units_bsf.c
+++ b/libavcodec/filter_units_bsf.c
@@ -21,6 +21,7 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
diff --git a/libavcodec/h264_metadata_bsf.c b/libavcodec/h264_metadata_bsf.c
index cbe36687a0..99017653d0 100644
--- a/libavcodec/h264_metadata_bsf.c
+++ b/libavcodec/h264_metadata_bsf.c
@@ -21,6 +21,7 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_h264.h"
diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c
index 52fc9b90cf..2822644b10 100644
--- a/libavcodec/h264_mp4toannexb_bsf.c
+++ b/libavcodec/h264_mp4toannexb_bsf.c
@@ -26,6 +26,7 @@
#include "libavutil/mem.h"
#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "bytestream.h"
#include "h264.h"
diff --git a/libavcodec/h264_redundant_pps_bsf.c b/libavcodec/h264_redundant_pps_bsf.c
index 34885d320a..8f69780951 100644
--- a/libavcodec/h264_redundant_pps_bsf.c
+++ b/libavcodec/h264_redundant_pps_bsf.c
@@ -21,6 +21,7 @@
#include "libavutil/common.h"
#include "libavutil/mem.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_h264.h"
diff --git a/libavcodec/h265_metadata_bsf.c b/libavcodec/h265_metadata_bsf.c
index d5179bd489..749456157b 100644
--- a/libavcodec/h265_metadata_bsf.c
+++ b/libavcodec/h265_metadata_bsf.c
@@ -19,6 +19,7 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_h265.h"
diff --git a/libavcodec/hapqa_extract_bsf.c b/libavcodec/hapqa_extract_bsf.c
index 9fdcbe2886..1c8b0669b7 100644
--- a/libavcodec/hapqa_extract_bsf.c
+++ b/libavcodec/hapqa_extract_bsf.c
@@ -25,7 +25,7 @@
* extract one of the two textures of the HAQA
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "bytestream.h"
#include "hap.h"
diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c
index b63d58c551..a880d9ba9a 100644
--- a/libavcodec/hevc_mp4toannexb_bsf.c
+++ b/libavcodec/hevc_mp4toannexb_bsf.c
@@ -25,6 +25,7 @@
#include "libavutil/mem.h"
#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "bytestream.h"
#include "hevc.h"
diff --git a/libavcodec/imx_dump_header_bsf.c b/libavcodec/imx_dump_header_bsf.c
index 6f3d7e52b0..e2b6a15591 100644
--- a/libavcodec/imx_dump_header_bsf.c
+++ b/libavcodec/imx_dump_header_bsf.c
@@ -25,7 +25,7 @@
* modifies bitstream to fit in mov and be decoded by final cut pro decoder
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "bytestream.h"
diff --git a/libavcodec/mjpeg2jpeg_bsf.c b/libavcodec/mjpeg2jpeg_bsf.c
index b18a6bf79d..b30f391bf9 100644
--- a/libavcodec/mjpeg2jpeg_bsf.c
+++ b/libavcodec/mjpeg2jpeg_bsf.c
@@ -29,7 +29,7 @@
#include "libavutil/error.h"
#include "libavutil/intreadwrite.h"
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "jpegtables.h"
#include "mjpeg.h"
diff --git a/libavcodec/mjpega_dump_header_bsf.c b/libavcodec/mjpega_dump_header_bsf.c
index e8a440a69f..ab68f9c3e9 100644
--- a/libavcodec/mjpega_dump_header_bsf.c
+++ b/libavcodec/mjpega_dump_header_bsf.c
@@ -25,7 +25,7 @@
* modifies bitstream to be decoded by quicktime
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "bytestream.h"
#include "mjpeg.h"
diff --git a/libavcodec/movsub_bsf.c b/libavcodec/movsub_bsf.c
index bfc06a70f8..6e29fa8e50 100644
--- a/libavcodec/movsub_bsf.c
+++ b/libavcodec/movsub_bsf.c
@@ -20,7 +20,7 @@
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
static int text2movsub(AVBSFContext *ctx, AVPacket *out)
diff --git a/libavcodec/mp3_header_decompress_bsf.c b/libavcodec/mp3_header_decompress_bsf.c
index 158d96853e..44c174c21c 100644
--- a/libavcodec/mp3_header_decompress_bsf.c
+++ b/libavcodec/mp3_header_decompress_bsf.c
@@ -20,7 +20,7 @@
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "mpegaudiodecheader.h"
#include "mpegaudiodata.h"
diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c
index 8c6dad9625..b1e2d6128a 100644
--- a/libavcodec/mpeg2_metadata_bsf.c
+++ b/libavcodec/mpeg2_metadata_bsf.c
@@ -20,6 +20,7 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_mpeg2.h"
diff --git a/libavcodec/mpeg4_unpack_bframes_bsf.c b/libavcodec/mpeg4_unpack_bframes_bsf.c
index 6934cce73a..6f8595713d 100644
--- a/libavcodec/mpeg4_unpack_bframes_bsf.c
+++ b/libavcodec/mpeg4_unpack_bframes_bsf.c
@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "internal.h"
#include "mpeg4video.h"
diff --git a/libavcodec/noise_bsf.c b/libavcodec/noise_bsf.c
index b5f58f1230..6ebd369633 100644
--- a/libavcodec/noise_bsf.c
+++ b/libavcodec/noise_bsf.c
@@ -20,7 +20,7 @@
#include <stdlib.h>
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "libavutil/log.h"
diff --git a/libavcodec/null_bsf.c b/libavcodec/null_bsf.c
index 22d341a9ca..595945027d 100644
--- a/libavcodec/null_bsf.c
+++ b/libavcodec/null_bsf.c
@@ -21,7 +21,7 @@
* Null bitstream filter -- pass the input through unchanged.
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
const AVBitStreamFilter ff_null_bsf = {
diff --git a/libavcodec/prores_metadata_bsf.c b/libavcodec/prores_metadata_bsf.c
index 328ed88591..d971243a8b 100644
--- a/libavcodec/prores_metadata_bsf.c
+++ b/libavcodec/prores_metadata_bsf.c
@@ -28,6 +28,8 @@
#include "libavutil/common.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/opt.h"
+
+#include "bsf.h"
#include "bsf_internal.h"
typedef struct ProresMetadataContext {
diff --git a/libavcodec/remove_extradata_bsf.c b/libavcodec/remove_extradata_bsf.c
index 7ea12d260a..5783b075f0 100644
--- a/libavcodec/remove_extradata_bsf.c
+++ b/libavcodec/remove_extradata_bsf.c
@@ -22,6 +22,7 @@
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
enum RemoveFreq {
diff --git a/libavcodec/trace_headers_bsf.c b/libavcodec/trace_headers_bsf.c
index ffd4e5465b..8ee4dbd668 100644
--- a/libavcodec/trace_headers_bsf.c
+++ b/libavcodec/trace_headers_bsf.c
@@ -22,6 +22,7 @@
#include "libavutil/common.h"
#include "libavutil/log.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
diff --git a/libavcodec/truehd_core_bsf.c b/libavcodec/truehd_core_bsf.c
index 8235648588..cc2779cc2e 100644
--- a/libavcodec/truehd_core_bsf.c
+++ b/libavcodec/truehd_core_bsf.c
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "get_bits.h"
#include "mlp_parse.h"
diff --git a/libavcodec/vp9_metadata_bsf.c b/libavcodec/vp9_metadata_bsf.c
index 974a5fc6dd..2ca494e695 100644
--- a/libavcodec/vp9_metadata_bsf.c
+++ b/libavcodec/vp9_metadata_bsf.c
@@ -20,6 +20,7 @@
#include "libavutil/common.h"
#include "libavutil/opt.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "cbs.h"
#include "cbs_vp9.h"
diff --git a/libavcodec/vp9_raw_reorder_bsf.c b/libavcodec/vp9_raw_reorder_bsf.c
index ad9f4ce77a..6562399159 100644
--- a/libavcodec/vp9_raw_reorder_bsf.c
+++ b/libavcodec/vp9_raw_reorder_bsf.c
@@ -21,6 +21,7 @@
#include "libavutil/log.h"
#include "libavutil/mem.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "get_bits.h"
#include "put_bits.h"
diff --git a/libavcodec/vp9_superframe_bsf.c b/libavcodec/vp9_superframe_bsf.c
index 2584604817..57681e29e4 100644
--- a/libavcodec/vp9_superframe_bsf.c
+++ b/libavcodec/vp9_superframe_bsf.c
@@ -20,7 +20,8 @@
*/
#include "libavutil/avassert.h"
-#include "avcodec.h"
+
+#include "bsf.h"
#include "bsf_internal.h"
#include "get_bits.h"
diff --git a/libavcodec/vp9_superframe_split_bsf.c b/libavcodec/vp9_superframe_split_bsf.c
index 00f40aa96e..ed0444561a 100644
--- a/libavcodec/vp9_superframe_split_bsf.c
+++ b/libavcodec/vp9_superframe_split_bsf.c
@@ -24,7 +24,7 @@
#include <stddef.h>
-#include "avcodec.h"
+#include "bsf.h"
#include "bsf_internal.h"
#include "bytestream.h"
#include "get_bits.h"