]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/avfilter.h
lavfi: switch to an AVOptions-based system.
[ffmpeg] / libavfilter / avfilter.h
index aff662f8f628135e450f80dc869d25d0f76eb7cd..66f57df150bd3ad5754682827255e49a627099f4 100644 (file)
@@ -23,6 +23,7 @@
 #define AVFILTER_AVFILTER_H
 
 #include "libavutil/avutil.h"
+#include "libavutil/frame.h"
 #include "libavutil/log.h"
 #include "libavutil/samplefmt.h"
 #include "libavutil/pixfmt.h"
@@ -54,6 +55,7 @@ typedef struct AVFilterLink    AVFilterLink;
 typedef struct AVFilterPad     AVFilterPad;
 typedef struct AVFilterFormats AVFilterFormats;
 
+#if FF_API_AVFILTERBUFFER
 /**
  * A reference-counted buffer data type used by the filter system. Filters
  * should not store pointers to this structure directly, but instead use the
@@ -61,22 +63,6 @@ typedef struct AVFilterFormats AVFilterFormats;
  */
 typedef struct AVFilterBuffer {
     uint8_t *data[8];           ///< buffer data for each plane/channel
-    int linesize[8];            ///< number of bytes per line
-
-    unsigned refcount;          ///< number of references to this buffer
-
-    /** private data to be used by a custom free function */
-    void *priv;
-    /**
-     * A pointer to the function to deallocate this buffer if the default
-     * function is not sufficient. This could, for example, add the memory
-     * back into a memory pool to be reused later without the overhead of
-     * reallocating it from scratch.
-     */
-    void (*free)(struct AVFilterBuffer *buf);
-
-    int format;                 ///< media format
-    int w, h;                   ///< width and height of the allocated buffer
 
     /**
      * pointers to the data planes/channels.
@@ -93,6 +79,21 @@ typedef struct AVFilterBuffer {
      * in order to access all channels.
      */
     uint8_t **extended_data;
+    int linesize[8];            ///< number of bytes per line
+
+    /** private data to be used by a custom free function */
+    void *priv;
+    /**
+     * A pointer to the function to deallocate this buffer if the default
+     * function is not sufficient. This could, for example, add the memory
+     * back into a memory pool to be reused later without the overhead of
+     * reallocating it from scratch.
+     */
+    void (*free)(struct AVFilterBuffer *buf);
+
+    int format;                 ///< media format
+    int w, h;                   ///< width and height of the allocated buffer
+    unsigned refcount;          ///< number of references to this buffer
 } AVFilterBuffer;
 
 #define AV_PERM_READ     0x01   ///< can read from the buffer
@@ -140,23 +141,6 @@ typedef struct AVFilterBufferRefVideoProps {
 typedef struct AVFilterBufferRef {
     AVFilterBuffer *buf;        ///< the buffer that this is a reference to
     uint8_t *data[8];           ///< picture/audio data for each plane
-    int linesize[8];            ///< number of bytes per line
-    int format;                 ///< media format
-
-    /**
-     * presentation timestamp. The time unit may change during
-     * filtering, as it is specified in the link and the filter code
-     * may need to rescale the PTS accordingly.
-     */
-    int64_t pts;
-    int64_t pos;                ///< byte position in stream, -1 if unknown
-
-    int perms;                  ///< permissions, see the AV_PERM_* flags
-
-    enum AVMediaType type;      ///< media type of buffer data
-    AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
-    AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
-
     /**
      * pointers to the data planes/channels.
      *
@@ -172,11 +156,30 @@ typedef struct AVFilterBufferRef {
      * in order to access all channels.
      */
     uint8_t **extended_data;
+    int linesize[8];            ///< number of bytes per line
+
+    AVFilterBufferRefVideoProps *video; ///< video buffer specific properties
+    AVFilterBufferRefAudioProps *audio; ///< audio buffer specific properties
+
+    /**
+     * presentation timestamp. The time unit may change during
+     * filtering, as it is specified in the link and the filter code
+     * may need to rescale the PTS accordingly.
+     */
+    int64_t pts;
+    int64_t pos;                ///< byte position in stream, -1 if unknown
+
+    int format;                 ///< media format
+
+    int perms;                  ///< permissions, see the AV_PERM_* flags
+
+    enum AVMediaType type;      ///< media type of buffer data
 } AVFilterBufferRef;
 
 /**
  * Copy properties of src to dst, without copying the actual data
  */
+attribute_deprecated
 void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src);
 
 /**
@@ -188,6 +191,7 @@ void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *s
  * @return      a new reference to the buffer with the same properties as the
  *              old, excluding any permissions denied by pmask
  */
+attribute_deprecated
 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
 
 /**
@@ -195,44 +199,22 @@ AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask);
  * buffer, the buffer itself is also automatically freed.
  *
  * @param ref reference to the buffer, may be NULL
+ *
+ * @note it is recommended to use avfilter_unref_bufferp() instead of this
+ * function
  */
+attribute_deprecated
 void avfilter_unref_buffer(AVFilterBufferRef *ref);
 
-#if FF_API_FILTERS_PUBLIC
 /**
- * @addtogroup lavfi_deprecated
- * @deprecated Those functions are only useful inside filters and
- * user filters are not supported at this point.
- * @{
+ * Remove a reference to a buffer and set the pointer to NULL.
+ * If this is the last reference to the buffer, the buffer itself
+ * is also automatically freed.
+ *
+ * @param ref pointer to the buffer reference
  */
-struct AVFilterFormats {
-    unsigned format_count;      ///< number of formats
-    int *formats;               ///< list of media formats
-
-    unsigned refcount;          ///< number of references to this list
-    struct AVFilterFormats ***refs; ///< references to this list
-};
-
-attribute_deprecated
-AVFilterFormats *avfilter_make_format_list(const int *fmts);
-attribute_deprecated
-int avfilter_add_format(AVFilterFormats **avff, int fmt);
 attribute_deprecated
-AVFilterFormats *avfilter_all_formats(enum AVMediaType type);
-attribute_deprecated
-AVFilterFormats *avfilter_merge_formats(AVFilterFormats *a, AVFilterFormats *b);
-attribute_deprecated
-void avfilter_formats_ref(AVFilterFormats *formats, AVFilterFormats **ref);
-attribute_deprecated
-void avfilter_formats_unref(AVFilterFormats **ref);
-attribute_deprecated
-void avfilter_formats_changeref(AVFilterFormats **oldref,
-                                AVFilterFormats **newref);
-attribute_deprecated
-void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats);
-/**
- * @}
- */
+void avfilter_unref_bufferp(AVFilterBufferRef **ref);
 #endif
 
 #if FF_API_AVFILTERPAD_PUBLIC
@@ -264,7 +246,7 @@ struct AVFilterPad {
      *
      * Input pads only.
      */
-    int min_perms;
+    attribute_deprecated int min_perms;
 
     /**
      * Permissions which are not accepted on incoming buffers. Any buffer
@@ -275,16 +257,12 @@ struct AVFilterPad {
      *
      * Input pads only.
      */
-    int rej_perms;
+    attribute_deprecated int rej_perms;
 
     /**
-     * Callback called before passing the first slice of a new frame. If
-     * NULL, the filter layer will default to storing a reference to the
-     * picture inside the link structure.
-     *
-     * Input video pads only.
+     * @deprecated unused
      */
-    void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
+    int (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref);
 
     /**
      * Callback function to get a video buffer. If NULL, the filter system will
@@ -292,7 +270,7 @@ struct AVFilterPad {
      *
      * Input video pads only.
      */
-    AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h);
+    AVFrame *(*get_video_buffer)(AVFilterLink *link, int w, int h);
 
     /**
      * Callback function to get an audio buffer. If NULL, the filter system will
@@ -300,33 +278,29 @@ struct AVFilterPad {
      *
      * Input audio pads only.
      */
-    AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
-                                           int nb_samples);
+    AVFrame *(*get_audio_buffer)(AVFilterLink *link, int nb_samples);
 
     /**
-     * Callback called after the slices of a frame are completely sent. If
-     * NULL, the filter layer will default to releasing the reference stored
-     * in the link structure during start_frame().
-     *
-     * Input video pads only.
+     * @deprecated unused
      */
-    void (*end_frame)(AVFilterLink *link);
+    int (*end_frame)(AVFilterLink *link);
 
     /**
-     * Slice drawing callback. This is where a filter receives video data
-     * and should do its processing.
-     *
-     * Input video pads only.
+     * @deprecated unused
      */
-    void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
+    int (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir);
 
     /**
-     * Samples filtering callback. This is where a filter receives audio data
-     * and should do its processing.
+     * Filtering callback. This is where a filter receives a frame with
+     * audio/video data and should do its processing.
      *
-     * Input audio pads only.
+     * Input pads only.
+     *
+     * @return >= 0 on success, a negative AVERROR on error. This function
+     * must ensure that samplesref is properly unreferenced on error if it
+     * hasn't been passed on to another filter.
      */
-    void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
+    int (*filter_frame)(AVFilterLink *link, AVFrame *frame);
 
     /**
      * Frame poll callback. This returns the number of immediately available
@@ -363,6 +337,16 @@ struct AVFilterPad {
      * and another value on error.
      */
     int (*config_props)(AVFilterLink *link);
+
+    /**
+     * The filter expects a fifo to be inserted on its input link,
+     * typically because it has a delay.
+     *
+     * input pads only.
+     */
+    int needs_fifo;
+
+    int needs_writable;
 };
 #endif
 
@@ -388,54 +372,6 @@ const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx);
  */
 enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx);
 
-#if FF_API_FILTERS_PUBLIC
-/** default handler for start_frame() for video inputs */
-attribute_deprecated
-void avfilter_default_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
-
-/** default handler for draw_slice() for video inputs */
-attribute_deprecated
-void avfilter_default_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
-
-/** default handler for end_frame() for video inputs */
-attribute_deprecated
-void avfilter_default_end_frame(AVFilterLink *link);
-
-#if FF_API_DEFAULT_CONFIG_OUTPUT_LINK
-/** default handler for config_props() for audio/video outputs */
-attribute_deprecated
-int avfilter_default_config_output_link(AVFilterLink *link);
-#endif
-
-/** default handler for get_video_buffer() for video inputs */
-attribute_deprecated
-AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
-                                                     int perms, int w, int h);
-
-/** Default handler for query_formats() */
-attribute_deprecated
-int avfilter_default_query_formats(AVFilterContext *ctx);
-#endif
-
-#if FF_API_FILTERS_PUBLIC
-/** start_frame() handler for filters which simply pass video along */
-attribute_deprecated
-void avfilter_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
-
-/** draw_slice() handler for filters which simply pass video along */
-attribute_deprecated
-void avfilter_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
-
-/** end_frame() handler for filters which simply pass video along */
-attribute_deprecated
-void avfilter_null_end_frame(AVFilterLink *link);
-
-/** get_video_buffer() handler for filters which simply pass video along */
-attribute_deprecated
-AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
-                                                  int perms, int w, int h);
-#endif
-
 /**
  * Filter definition. This defines the pads a filter contains, and all the
  * callback functions used to interact with the filter.
@@ -443,15 +379,34 @@ AVFilterBufferRef *avfilter_null_get_video_buffer(AVFilterLink *link,
 typedef struct AVFilter {
     const char *name;         ///< filter name
 
-    int priv_size;      ///< size of private data to allocate for the filter
+    /**
+     * A description for the filter. You should use the
+     * NULL_IF_CONFIG_SMALL() macro to define it.
+     */
+    const char *description;
+
+    const AVFilterPad *inputs;  ///< NULL terminated list of inputs. NULL if none
+    const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
+
+    /**
+     * A class for the private data, used to access filter private
+     * AVOptions.
+     */
+    const AVClass *priv_class;
+
+    /*****************************************************************
+     * All fields below this line are not part of the public API. They
+     * may not be used outside of libavfilter and can be changed and
+     * removed at will.
+     * New public fields should be added right above.
+     *****************************************************************
+     */
 
     /**
      * Filter initialization function. Args contains the user-supplied
      * parameters. FIXME: maybe an AVOption-based system would be better?
-     * opaque is data provided by the code requesting creation of the filter,
-     * and is used to pass data to the filter.
      */
-    int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
+    int (*init)(AVFilterContext *ctx, const char *args);
 
     /**
      * Filter uninitialization function. Should deallocate any memory held
@@ -470,14 +425,7 @@ typedef struct AVFilter {
      */
     int (*query_formats)(AVFilterContext *);
 
-    const AVFilterPad *inputs;  ///< NULL terminated list of inputs. NULL if none
-    const AVFilterPad *outputs; ///< NULL terminated list of outputs. NULL if none
-
-    /**
-     * A description for the filter. You should use the
-     * NULL_IF_CONFIG_SMALL() macro to define it.
-     */
-    const char *description;
+    int priv_size;      ///< size of private data to allocate for the filter
 } AVFilter;
 
 /** An instance of a filter */
@@ -488,22 +436,21 @@ struct AVFilterContext {
 
     char *name;                     ///< name of this filter instance
 
+    AVFilterPad   *input_pads;      ///< array of input pads
+    AVFilterLink **inputs;          ///< array of pointers to input links
 #if FF_API_FOO_COUNT
     unsigned input_count;           ///< @deprecated use nb_inputs
 #endif
-    AVFilterPad   *input_pads;      ///< array of input pads
-    AVFilterLink **inputs;          ///< array of pointers to input links
+    unsigned    nb_inputs;          ///< number of input pads
 
+    AVFilterPad   *output_pads;     ///< array of output pads
+    AVFilterLink **outputs;         ///< array of pointers to output links
 #if FF_API_FOO_COUNT
     unsigned output_count;          ///< @deprecated use nb_outputs
 #endif
-    AVFilterPad   *output_pads;     ///< array of output pads
-    AVFilterLink **outputs;         ///< array of pointers to output links
+    unsigned    nb_outputs;         ///< number of output pads
 
     void *priv;                     ///< private data for use by the filter
-
-    unsigned nb_inputs;             ///< number of input pads
-    unsigned nb_outputs;            ///< number of output pads
 };
 
 /**
@@ -520,13 +467,6 @@ struct AVFilterLink {
     AVFilterContext *dst;       ///< dest filter
     AVFilterPad *dstpad;        ///< input pad on the dest filter
 
-    /** stage of the initialization of the link properties (dimensions, etc) */
-    enum {
-        AVLINK_UNINIT = 0,      ///< not started
-        AVLINK_STARTINIT,       ///< started, but incomplete
-        AVLINK_INIT             ///< complete
-    } init_state;
-
     enum AVMediaType type;      ///< filter media type
 
     /* These parameters apply only to video */
@@ -534,35 +474,11 @@ struct AVFilterLink {
     int h;                      ///< agreed upon image height
     AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio
     /* These two parameters apply only to audio */
-    uint64_t channel_layout;    ///< channel layout of current buffer (see libavutil/audioconvert.h)
-#if FF_API_SAMPLERATE64
-    int64_t sample_rate;        ///< samples per second
-#else
+    uint64_t channel_layout;    ///< channel layout of current buffer (see libavutil/channel_layout.h)
     int sample_rate;            ///< samples per second
-#endif
 
     int format;                 ///< agreed upon media format
 
-    /**
-     * Lists of formats supported by the input and output filters respectively.
-     * These lists are used for negotiating the format to actually be used,
-     * which will be loaded into the format member, above, when chosen.
-     */
-    AVFilterFormats *in_formats;
-    AVFilterFormats *out_formats;
-
-    /**
-     * The buffer reference currently being sent across the link by the source
-     * filter. This is used internally by the filter system to allow
-     * automatic copying of buffers which do not have sufficient permissions
-     * for the destination. This should not be accessed directly by the
-     * filters.
-     */
-    AVFilterBufferRef *src_buf;
-
-    AVFilterBufferRef *cur_buf;
-    AVFilterBufferRef *out_buf;
-
     /**
      * Define the time base used by the PTS of the frames/samples
      * which will pass through this link.
@@ -579,6 +495,14 @@ struct AVFilterLink {
      * New public fields should be added right above.
      *****************************************************************
      */
+    /**
+     * Lists of formats supported by the input and output filters respectively.
+     * These lists are used for negotiating the format to actually be used,
+     * which will be loaded into the format member, above, when chosen.
+     */
+    AVFilterFormats *in_formats;
+    AVFilterFormats *out_formats;
+
     /**
      * Lists of channel layouts and sample rates used for automatic
      * negotiation.
@@ -587,6 +511,22 @@ struct AVFilterLink {
     AVFilterFormats *out_samplerates;
     struct AVFilterChannelLayouts  *in_channel_layouts;
     struct AVFilterChannelLayouts *out_channel_layouts;
+
+    /**
+     * Audio only, the destination filter sets this to a non-zero value to
+     * request that buffers with the given number of samples should be sent to
+     * it. AVFilterPad.needs_fifo must also be set on the corresponding input
+     * pad.
+     * Last buffer before EOF will be padded with silence.
+     */
+    int request_samples;
+
+    /** stage of the initialization of the link properties (dimensions, etc) */
+    enum {
+        AVLINK_UNINIT = 0,      ///< not started
+        AVLINK_STARTINIT,       ///< started, but incomplete
+        AVLINK_INIT             ///< complete
+    } init_state;
 };
 
 /**
@@ -609,12 +549,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
  */
 int avfilter_config_links(AVFilterContext *filter);
 
-#if FF_API_FILTERS_PUBLIC
-attribute_deprecated
-AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
-                                          int w, int h);
-#endif
-
+#if FF_API_AVFILTERBUFFER
 /**
  * Create a buffer reference wrapped around an already allocated image
  * buffer.
@@ -626,9 +561,10 @@ AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms,
  * @param h the height of the image specified by the data and linesize arrays
  * @param format the pixel format of the image specified by the data and linesize arrays
  */
+attribute_deprecated
 AVFilterBufferRef *
 avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
-                                          int w, int h, enum PixelFormat format);
+                                          int w, int h, enum AVPixelFormat format);
 
 /**
  * Create an audio buffer reference wrapped around an already
@@ -641,26 +577,13 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int
  * @param sample_fmt     the format of each sample in the buffer to allocate
  * @param channel_layout the channel layout of the buffer
  */
+attribute_deprecated
 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
                                                              int linesize,
                                                              int perms,
                                                              int nb_samples,
                                                              enum AVSampleFormat sample_fmt,
                                                              uint64_t channel_layout);
-
-#if FF_API_FILTERS_PUBLIC
-attribute_deprecated
-int avfilter_request_frame(AVFilterLink *link);
-
-attribute_deprecated
-int avfilter_poll_frame(AVFilterLink *link);
-
-attribute_deprecated
-void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref);
-attribute_deprecated
-void avfilter_end_frame(AVFilterLink *link);
-attribute_deprecated
-void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir);
 #endif
 
 /** Initialize the filter system. Register all builtin filters. */
@@ -740,26 +663,14 @@ void avfilter_free(AVFilterContext *filter);
 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
                            unsigned filt_srcpad_idx, unsigned filt_dstpad_idx);
 
-#if FF_API_FILTERS_PUBLIC
-attribute_deprecated
-void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
-                         AVFilterPad **pads, AVFilterLink ***links,
-                         AVFilterPad *newpad);
-
-attribute_deprecated
-void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
-                           AVFilterPad *p);
-attribute_deprecated
-void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
-                            AVFilterPad *p);
-#endif
-
+#if FF_API_AVFILTERBUFFER
 /**
  * Copy the frame properties of src to dst, without copying the actual
  * image data.
  *
  * @return 0 on success, a negative number on error.
  */
+attribute_deprecated
 int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
 
 /**
@@ -768,6 +679,8 @@ int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src);
  *
  * @return 0 on success, a negative number on error.
  */
+attribute_deprecated
 int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src);
+#endif
 
 #endif /* AVFILTER_AVFILTER_H */