2008-02-15 22:11:25 +00:00
|
|
|
/*
|
|
|
|
* Filter layer
|
|
|
|
* copyright (c) 2007 Bobby Bingham
|
|
|
|
*
|
|
|
|
* 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 FFMPEG_AVFILTER_H
|
|
|
|
#define FFMPEG_AVFILTER_H
|
|
|
|
|
2008-02-15 22:13:30 +00:00
|
|
|
#include <stddef.h>
|
2008-02-15 22:11:25 +00:00
|
|
|
#include "avcodec.h"
|
|
|
|
|
|
|
|
typedef struct AVFilterContext AVFilterContext;
|
|
|
|
typedef struct AVFilterLink AVFilterLink;
|
|
|
|
typedef struct AVFilterPad AVFilterPad;
|
|
|
|
|
|
|
|
/* TODO: look for other flags which may be useful in this structure (interlace
|
|
|
|
* flags, etc)
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* A reference-counted picture data type used by the filter system. Filters
|
|
|
|
* should not store pointers to this structure directly, but instead use the
|
|
|
|
* AVFilterPicRef structure below
|
|
|
|
*/
|
|
|
|
typedef struct AVFilterPic
|
|
|
|
{
|
|
|
|
uint8_t *data[4];
|
|
|
|
int linesize[4]; ///< number of bytes per line
|
|
|
|
enum PixelFormat format;
|
|
|
|
|
|
|
|
unsigned refcount;
|
|
|
|
void *priv;
|
|
|
|
void (*free)(struct AVFilterPic *pic);
|
|
|
|
} AVFilterPic;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A reference to an AVFilterPic. Since filters can manipulate the origin of
|
|
|
|
* a picture to, for example, crop image without any memcpy, the picture origin
|
2008-02-15 22:11:29 +00:00
|
|
|
* and dimensions are per-reference properties. Linesize is also useful for
|
|
|
|
* image flipping, frame to field filters, etc, and so is also per-reference.
|
2008-02-15 22:11:25 +00:00
|
|
|
*
|
2008-02-15 22:12:50 +00:00
|
|
|
* TODO: add anything necessary for frame reordering
|
2008-02-15 22:11:25 +00:00
|
|
|
*/
|
|
|
|
typedef struct AVFilterPicRef
|
|
|
|
{
|
|
|
|
AVFilterPic *pic;
|
|
|
|
uint8_t *data[4];
|
2008-02-15 22:11:29 +00:00
|
|
|
int linesize[4];
|
2008-02-15 22:11:25 +00:00
|
|
|
int w, h;
|
|
|
|
|
2008-02-15 22:12:50 +00:00
|
|
|
int64_t pts; ///< presentation timestamp in milliseconds
|
|
|
|
|
2008-02-15 22:11:25 +00:00
|
|
|
int perms; ///< permissions
|
|
|
|
#define AV_PERM_READ 0x01 ///< can read from the buffer
|
|
|
|
#define AV_PERM_WRITE 0x02 ///< can write to the buffer
|
|
|
|
#define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer
|
|
|
|
#define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times
|
|
|
|
} AVFilterPicRef;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new reference to a picture.
|
|
|
|
* @param ref An existing reference to the picture
|
2008-02-15 22:12:43 +00:00
|
|
|
* @param pmask A bitmask containing the allowable permissions in the new reference
|
2008-02-15 22:11:25 +00:00
|
|
|
* @return A new reference to the picture with the same properties as the old
|
|
|
|
*/
|
2008-02-15 22:12:43 +00:00
|
|
|
AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref, int pmask);
|
2008-02-15 22:11:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a reference to a picture. If this is the last reference to the
|
|
|
|
* picture, the picture itself is also automatically freed.
|
|
|
|
* @param ref Reference to the picture.
|
|
|
|
*/
|
|
|
|
void avfilter_unref_pic(AVFilterPicRef *ref);
|
|
|
|
|
|
|
|
struct AVFilterPad
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Pad name. The name is unique among inputs and among oututs, but an
|
|
|
|
* input may have the same name as an output.
|
|
|
|
*/
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* AVFilterPad type. Only video supported now, hopefully someone will
|
|
|
|
* add audio in the future.
|
|
|
|
*/
|
|
|
|
int type;
|
|
|
|
#define AV_PAD_VIDEO 0
|
|
|
|
|
2008-02-15 22:12:41 +00:00
|
|
|
/**
|
|
|
|
* Callback to get a list of supported formats. The returned list should
|
|
|
|
* be terminated by -1. This is used for both input and output pads and
|
|
|
|
* is required for both.
|
|
|
|
*/
|
|
|
|
int *(*query_formats)(AVFilterLink *link);
|
|
|
|
|
2008-02-15 22:11:25 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void (*start_frame)(AVFilterLink *link, AVFilterPicRef *picref);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback function to get a buffer. If NULL, the filter system will
|
|
|
|
* handle buffer requests. Only required for input video pads.
|
|
|
|
*/
|
|
|
|
AVFilterPicRef *(*get_video_buffer)(AVFilterLink *link, int perms);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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().
|
|
|
|
*/
|
|
|
|
void (*end_frame)(AVFilterLink *link);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Slice drawing callback. This is where a filter receives video data
|
|
|
|
* and should do its processing. Only required for input video pads.
|
|
|
|
*/
|
|
|
|
void (*draw_slice)(AVFilterLink *link, uint8_t *data[4], int y, int height);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Frame request callback. A call to this should result in at least one
|
|
|
|
* frame being output over the given link. Video output pads only.
|
|
|
|
*/
|
|
|
|
void (*request_frame)(AVFilterLink *link);
|
|
|
|
|
|
|
|
/**
|
2008-02-15 22:12:41 +00:00
|
|
|
* Link configuration callback. For output pads, this should set the link
|
|
|
|
* properties such as width/height. NOTE: this should not set the format
|
|
|
|
* property - that is negotiated between filters by the filter system using
|
|
|
|
* the query_formats() callback.
|
|
|
|
*
|
|
|
|
* For input pads, this should check the properties of the link, and update
|
|
|
|
* the filter's internal state as necessary.
|
2008-02-15 22:11:25 +00:00
|
|
|
*/
|
2008-02-15 22:12:41 +00:00
|
|
|
int (*config_props)(AVFilterLink *link);
|
2008-02-15 22:11:25 +00:00
|
|
|
};
|
|
|
|
|
2008-02-15 22:13:24 +00:00
|
|
|
/* the default implementations of filter entry points */
|
2008-02-15 22:11:25 +00:00
|
|
|
void avfilter_default_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
|
|
|
|
void avfilter_default_end_frame(AVFilterLink *link);
|
2008-02-15 22:13:24 +00:00
|
|
|
int avfilter_default_config_output_link(AVFilterLink *link);
|
2008-02-15 22:13:28 +00:00
|
|
|
int avfilter_default_config_input_link (AVFilterLink *link);
|
2008-02-15 22:13:24 +00:00
|
|
|
int *avfilter_default_query_output_formats(AVFilterLink *link);
|
|
|
|
AVFilterPicRef *avfilter_default_get_video_buffer(AVFilterLink *link,
|
|
|
|
int perms);
|
2008-02-15 22:11:25 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *name;
|
|
|
|
char *author;
|
|
|
|
|
|
|
|
int priv_size;
|
|
|
|
|
2008-02-15 22:12:37 +00:00
|
|
|
/**
|
|
|
|
* Filter initialization function. Args contains the user-supplied
|
|
|
|
* parameters. FIXME: maybe an AVOption-based system would be better?
|
2008-02-15 22:13:05 +00:00
|
|
|
* opaque is data provided by the code requesting creation of the filter,
|
|
|
|
* and is used to pass data to the filter.
|
2008-02-15 22:12:37 +00:00
|
|
|
*/
|
2008-02-15 22:13:13 +00:00
|
|
|
int (*init)(AVFilterContext *ctx, const char *args, void *opaque);
|
2008-02-15 22:11:25 +00:00
|
|
|
void (*uninit)(AVFilterContext *ctx);
|
|
|
|
|
|
|
|
const AVFilterPad *inputs; /// NULL terminated list of inputs. NULL if none
|
|
|
|
const AVFilterPad *outputs; /// NULL terminated list of outputs. NULL if none
|
|
|
|
} AVFilter;
|
|
|
|
|
|
|
|
struct AVFilterContext
|
|
|
|
{
|
|
|
|
AVClass *av_class;
|
|
|
|
|
|
|
|
AVFilter *filter;
|
|
|
|
|
2008-02-15 22:12:54 +00:00
|
|
|
char *name;
|
|
|
|
|
2008-02-15 22:13:10 +00:00
|
|
|
unsigned input_count;
|
2008-02-15 22:13:18 +00:00
|
|
|
AVFilterPad *input_pads;
|
2008-02-15 22:11:25 +00:00
|
|
|
AVFilterLink **inputs;
|
2008-02-15 22:13:10 +00:00
|
|
|
|
|
|
|
unsigned output_count;
|
2008-02-15 22:13:18 +00:00
|
|
|
AVFilterPad *output_pads;
|
2008-02-15 22:11:25 +00:00
|
|
|
AVFilterLink **outputs;
|
|
|
|
|
|
|
|
void *priv;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AVFilterLink
|
|
|
|
{
|
|
|
|
AVFilterContext *src;
|
|
|
|
unsigned int srcpad;
|
|
|
|
|
|
|
|
AVFilterContext *dst;
|
|
|
|
unsigned int dstpad;
|
|
|
|
|
|
|
|
int w, h;
|
|
|
|
enum PixelFormat format;
|
|
|
|
|
|
|
|
AVFilterPicRef *cur_pic;
|
2008-02-15 22:12:47 +00:00
|
|
|
AVFilterPicRef *outpic;
|
2008-02-15 22:11:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Link two filters together */
|
|
|
|
int avfilter_link(AVFilterContext *src, unsigned srcpad,
|
|
|
|
AVFilterContext *dst, unsigned dstpad);
|
|
|
|
|
2008-02-15 22:13:28 +00:00
|
|
|
/** Configure the colorspace, dimensions, etc of a link */
|
|
|
|
int avfilter_config_link(AVFilterLink *link);
|
|
|
|
|
2008-02-15 22:11:25 +00:00
|
|
|
AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms);
|
|
|
|
void avfilter_request_frame(AVFilterLink *link);
|
|
|
|
void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref);
|
|
|
|
void avfilter_end_frame(AVFilterLink *link);
|
|
|
|
void avfilter_draw_slice(AVFilterLink *link, uint8_t *data[4], int y, int h);
|
|
|
|
|
|
|
|
void avfilter_init(void);
|
|
|
|
void avfilter_uninit(void);
|
|
|
|
void avfilter_register(AVFilter *filter);
|
|
|
|
AVFilter *avfilter_get_by_name(char *name);
|
|
|
|
|
2008-02-15 22:12:54 +00:00
|
|
|
AVFilterContext *avfilter_create(AVFilter *filter, char *inst_name);
|
|
|
|
AVFilterContext *avfilter_create_by_name(char *name, char *inst_name);
|
2008-02-15 22:13:05 +00:00
|
|
|
int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque);
|
2008-02-15 22:11:25 +00:00
|
|
|
void avfilter_destroy(AVFilterContext *filter);
|
|
|
|
|
2008-02-15 22:12:41 +00:00
|
|
|
int *avfilter_make_format_list(int len, ...);
|
|
|
|
|
2008-02-15 22:13:30 +00:00
|
|
|
/**
|
|
|
|
* Insert a new pad
|
|
|
|
* @param idx Insertion point. Pad is inserted at the end if this point
|
|
|
|
* is beyond the end of the list of pads.
|
|
|
|
* @param count Pointer to the number of pads in the list
|
|
|
|
* @param padidx_off Offset within an AVFilterLink structure to the element
|
|
|
|
* to increment when inserting a new pad causes link
|
|
|
|
* numbering to change
|
|
|
|
* @param pads Pointer to the pointer to the beginning of the list of pads
|
|
|
|
* @param links Pointer to the pointer to the beginning of the list of links
|
|
|
|
* @param newpad The new pad to add. A copy is made when adding.
|
|
|
|
*/
|
|
|
|
void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
|
|
|
|
AVFilterPad **pads, AVFilterLink ***links,
|
|
|
|
AVFilterPad *newpad);
|
|
|
|
|
|
|
|
/** insert a new input pad for the filter */
|
|
|
|
static inline void avfilter_insert_inpad(AVFilterContext *f, unsigned index,
|
|
|
|
AVFilterPad *p)
|
|
|
|
{
|
|
|
|
avfilter_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad),
|
|
|
|
&f->input_pads, &f->inputs, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** insert a new output pad for the filter */
|
|
|
|
static inline void avfilter_insert_outpad(AVFilterContext *f, unsigned index,
|
|
|
|
AVFilterPad *p)
|
|
|
|
{
|
|
|
|
avfilter_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad),
|
|
|
|
&f->output_pads, &f->outputs, p);
|
|
|
|
}
|
|
|
|
|
2008-02-15 22:11:25 +00:00
|
|
|
#endif /* FFMPEG_AVFILTER_H */
|