#define AVFILTER_AVFILTER_H
#include "libavutil/avutil.h"
+#include "libavutil/frame.h"
#include "libavutil/log.h"
#include "libavutil/samplefmt.h"
#include "libavutil/pixfmt.h"
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
*/
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.
* 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
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.
*
* 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);
/**
* @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);
/**
* 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
*
* Input pads only.
*/
- int min_perms;
+ attribute_deprecated int min_perms;
/**
* Permissions which are not accepted on incoming buffers. Any buffer
*
* 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
*
* 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
*
* 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
* 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
*/
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.
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
*/
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 */
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
};
/**
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 */
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.
* 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.
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;
};
/**
*/
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.
* @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
* @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. */
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);
/**
*
* @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 */