/* #define DEBUG */
#include "libavcodec/imgconvert.h"
+#include "libavutil/pixdesc.h"
#include "avfilter.h"
+#include "internal.h"
unsigned avfilter_version(void) {
return LIBAVFILTER_VERSION_INT;
#define link_dpad(link) link->dst-> input_pads[link->dstpad]
#define link_spad(link) link->src->output_pads[link->srcpad]
-AVFilterPicRef *avfilter_ref_pic(AVFilterPicRef *ref, int pmask)
+AVFilterBufferRef *avfilter_ref_pic(AVFilterBufferRef *ref, int pmask)
{
- AVFilterPicRef *ret = av_malloc(sizeof(AVFilterPicRef));
+ AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef));
*ret = *ref;
ret->perms &= pmask;
ret->pic->refcount ++;
return ret;
}
-void avfilter_unref_pic(AVFilterPicRef *ref)
+void avfilter_unref_pic(AVFilterBufferRef *ref)
{
if(!(--ref->pic->refcount))
ref->pic->free(ref->pic);
link->dst = dst;
link->srcpad = srcpad;
link->dstpad = dstpad;
- link->format = PIX_FMT_NONE;
+ link->type = src->output_pads[srcpad].type;
+ assert(PIX_FMT_NONE == -1 && SAMPLE_FMT_NONE == -1);
+ link->format = -1;
return 0;
}
int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
unsigned in, unsigned out)
{
- av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s'\n",
- filt->name);
+ av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s' "
+ "between the filter '%s' and the filter '%s'\n",
+ filt->name, link->src->name, link->dst->name);
link->dst->inputs[link->dstpad] = NULL;
if(avfilter_link(filt, out, link->dst, link->dstpad)) {
link->dstpad = in;
filt->inputs[in] = link;
- /* if any information on supported colorspaces already exists on the
+ /* if any information on supported media formats already exists on the
* link, we need to preserve that */
if(link->out_formats)
avfilter_formats_changeref(&link->out_formats,
return 0;
}
-static void dprintf_picref(void *ctx, AVFilterPicRef *picref, int end)
+void ff_dprintf_picref(void *ctx, AVFilterBufferRef *picref, int end)
{
dprintf(ctx,
- "picref[%p data[%p, %p, %p, %p] linesize[%d, %d, %d, %d] pts:%"PRId64" s:%dx%d]%s",
+ "picref[%p data[%p, %p, %p, %p] linesize[%d, %d, %d, %d] pts:%"PRId64" pos:%"PRId64" a:%d/%d s:%dx%d]%s",
picref,
picref->data [0], picref->data [1], picref->data [2], picref->data [3],
picref->linesize[0], picref->linesize[1], picref->linesize[2], picref->linesize[3],
- picref->pts, picref->w, picref->h,
+ picref->pts, picref->pos,
+ picref->pixel_aspect.num, picref->pixel_aspect.den, picref->w, picref->h,
end ? "\n" : "");
}
-static void dprintf_link(void *ctx, AVFilterLink *link, int end)
+void ff_dprintf_link(void *ctx, AVFilterLink *link, int end)
{
dprintf(ctx,
"link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",
link, link->w, link->h,
- avcodec_get_pix_fmt_name(link->format),
+ av_pix_fmt_descriptors[link->format].name,
link->src ? link->src->filter->name : "",
link->dst ? link->dst->filter->name : "",
end ? "\n" : "");
}
-#define DPRINTF_START(ctx, func) dprintf(NULL, "%-16s: ", #func)
-
-AVFilterPicRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
+AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
{
- AVFilterPicRef *ret = NULL;
+ AVFilterBufferRef *ret = NULL;
- DPRINTF_START(NULL, get_video_buffer); dprintf_link(NULL, link, 0); dprintf(NULL, " perms:%d w:%d h:%d\n", perms, w, h);
+ FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " perms:%d w:%d h:%d\n", perms, w, h);
if(link_dpad(link).get_video_buffer)
ret = link_dpad(link).get_video_buffer(link, perms, w, h);
if(!ret)
ret = avfilter_default_get_video_buffer(link, perms, w, h);
- DPRINTF_START(NULL, get_video_buffer); dprintf_link(NULL, link, 0); dprintf(NULL, " returning "); dprintf_picref(NULL, ret, 1);
+ FF_DPRINTF_START(NULL, get_video_buffer); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " returning "); ff_dprintf_picref(NULL, ret, 1);
return ret;
}
int avfilter_request_frame(AVFilterLink *link)
{
- DPRINTF_START(NULL, request_frame); dprintf_link(NULL, link, 1);
+ FF_DPRINTF_START(NULL, request_frame); ff_dprintf_link(NULL, link, 1);
if(link_spad(link).request_frame)
return link_spad(link).request_frame(link);
/* XXX: should we do the duplicating of the picture ref here, instead of
* forcing the source filter to do it? */
-void avfilter_start_frame(AVFilterLink *link, AVFilterPicRef *picref)
+void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
{
- void (*start_frame)(AVFilterLink *, AVFilterPicRef *);
+ void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
AVFilterPad *dst = &link_dpad(link);
- DPRINTF_START(NULL, start_frame); dprintf_link(NULL, link, 0); dprintf(NULL, " "); dprintf_picref(NULL, picref, 1);
+ FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_picref(NULL, picref, 1);
if(!(start_frame = dst->start_frame))
start_frame = avfilter_default_start_frame;
link->cur_pic = avfilter_default_get_video_buffer(link, dst->min_perms, link->w, link->h);
link->srcpic = picref;
- link->cur_pic->pts = link->srcpic->pts;
- link->cur_pic->pixel_aspect = link->srcpic->pixel_aspect;
+ avfilter_copy_picref_props(link->cur_pic, link->srcpic);
}
else
link->cur_pic = picref;
void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
{
uint8_t *src[4], *dst[4];
- int i, j, hsub, vsub;
+ int i, j, vsub;
void (*draw_slice)(AVFilterLink *, int, int, int);
- DPRINTF_START(NULL, draw_slice); dprintf_link(NULL, link, 0); dprintf(NULL, " y:%d h:%d dir:%d\n", y, h, slice_dir);
+ FF_DPRINTF_START(NULL, draw_slice); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " y:%d h:%d dir:%d\n", y, h, slice_dir);
/* copy the slice if needed for permission reasons */
if(link->srcpic) {
- avcodec_get_chroma_sub_sample(link->format, &hsub, &vsub);
+ vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
for(i = 0; i < 4; i ++) {
if(link->srcpic->data[i]) {
static const AVClass avfilter_class = {
"AVFilter",
- filter_name
+ filter_name,
+ NULL,
+ LIBAVUTIL_VERSION_INT,
};
AVFilterContext *avfilter_open(AVFilter *filter, const char *inst_name)
filter->filter->uninit(filter);
for(i = 0; i < filter->input_count; i ++) {
- if(filter->inputs[i])
- filter->inputs[i]->src->outputs[filter->inputs[i]->srcpad] = NULL;
+ if(filter->inputs[i]) {
+ if (filter->inputs[i]->src)
+ filter->inputs[i]->src->outputs[filter->inputs[i]->srcpad] = NULL;
+ avfilter_formats_unref(&filter->inputs[i]->in_formats);
+ avfilter_formats_unref(&filter->inputs[i]->out_formats);
+ }
av_freep(&filter->inputs[i]);
}
for(i = 0; i < filter->output_count; i ++) {
- if(filter->outputs[i])
- filter->outputs[i]->dst->inputs[filter->outputs[i]->dstpad] = NULL;
+ if(filter->outputs[i]) {
+ if (filter->outputs[i]->dst)
+ filter->outputs[i]->dst->inputs[filter->outputs[i]->dstpad] = NULL;
+ avfilter_formats_unref(&filter->outputs[i]->in_formats);
+ avfilter_formats_unref(&filter->outputs[i]->out_formats);
+ }
av_freep(&filter->outputs[i]);
}