X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Favfilter.h;h=b3522f87d3f07fecce1926b42538b6d3c6eb531b;hb=3d8c80b611aa1e2f800dd9c8d8f350407f95c042;hp=7fbc160cbe6396c2eda5bb86625b95291dc7400a;hpb=6d58358a3a3274e84a4e34a348165fbb3f484587;p=ffmpeg diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 7fbc160cbe6..b3522f87d3f 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -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,48 +199,32 @@ 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 /** * A filter pad used for either input or output. + * + * @warning this struct will be removed from public API. + * users should call avfilter_pad_get_name() and avfilter_pad_get_type() + * to access the name and type fields; there should be no need to access + * any other fields from outside of libavfilter. */ struct AVFilterPad { /** @@ -258,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 @@ -269,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 @@ -286,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 @@ -294,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 @@ -357,55 +337,40 @@ struct AVFilterPad { * and another value on error. */ int (*config_props)(AVFilterLink *link); -}; - -#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); + /** + * The filter expects a fifo to be inserted on its input link, + * typically because it has a delay. + * + * input pads only. + */ + int needs_fifo; -/** Default handler for query_formats() */ -attribute_deprecated -int avfilter_default_query_formats(AVFilterContext *ctx); + int needs_writable; +}; #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 the name of an AVFilterPad. + * + * @param pads an array of AVFilterPads + * @param pad_idx index of the pad in the array it; is the caller's + * responsibility to ensure the index is valid + * + * @return name of the pad_idx'th pad in pads + */ +const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx); -/** 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 +/** + * Get the type of an AVFilterPad. + * + * @param pads an array of AVFilterPads + * @param pad_idx index of the pad in the array; it is the caller's + * responsibility to ensure the index is valid + * + * @return type of the pad_idx'th pad in pads + */ +enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx); /** * Filter definition. This defines the pads a filter contains, and all the @@ -414,15 +379,28 @@ 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 + + /***************************************************************** + * 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 @@ -441,14 +419,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 */ @@ -459,13 +430,19 @@ struct AVFilterContext { char *name; ///< name of this filter instance - unsigned input_count; ///< number of input pads 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 + unsigned nb_inputs; ///< number of input pads - unsigned output_count; ///< number of output 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 + unsigned nb_outputs; ///< number of output pads void *priv; ///< private data for use by the filter }; @@ -484,13 +461,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 */ @@ -498,35 +468,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. @@ -543,6 +489,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. @@ -551,6 +505,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; }; /** @@ -573,12 +543,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. @@ -590,9 +555,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 @@ -605,26 +571,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. */ @@ -704,26 +657,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); /** @@ -732,6 +673,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 */