From d6251368772a170987387bdc508433c8fcf54cda Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 30 May 2012 13:59:30 +0200 Subject: lavfi: add channelsplit audio filter. --- libavfilter/Makefile | 1 + libavfilter/af_channelsplit.c | 146 ++++++++++++++++++++++++++++++++++++++++++ libavfilter/allfilters.c | 1 + libavfilter/formats.c | 12 ++++ libavfilter/formats.h | 5 ++ libavfilter/version.h | 2 +- 6 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 libavfilter/af_channelsplit.c (limited to 'libavfilter') diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 914f0c6..7e1a6d1 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -29,6 +29,7 @@ OBJS-$(CONFIG_AMIX_FILTER) += af_amix.o OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o OBJS-$(CONFIG_ASPLIT_FILTER) += split.o OBJS-$(CONFIG_ASYNCTS_FILTER) += af_asyncts.o +OBJS-$(CONFIG_CHANNELSPLIT_FILTER) += af_channelsplit.o OBJS-$(CONFIG_RESAMPLE_FILTER) += af_resample.o OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c new file mode 100644 index 0000000..c3e7ccf --- /dev/null +++ b/libavfilter/af_channelsplit.c @@ -0,0 +1,146 @@ +/* + * This file is part of Libav. + * + * Libav 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. + * + * Libav 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 Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Channel split filter + * + * Split an audio stream into per-channel streams. + */ + +#include "libavutil/audioconvert.h" +#include "libavutil/opt.h" + +#include "audio.h" +#include "avfilter.h" +#include "formats.h" +#include "internal.h" + +typedef struct ChannelSplitContext { + const AVClass *class; + + uint64_t channel_layout; + char *channel_layout_str; +} ChannelSplitContext; + +#define OFFSET(x) offsetof(ChannelSplitContext, x) +#define A AV_OPT_FLAG_AUDIO_PARAM +static const AVOption options[] = { + { "channel_layout", "Input channel layout.", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, { .str = "stereo" }, .flags = A }, + { NULL }, +}; + +static const AVClass channelsplit_class = { + .class_name = "channelsplit filter", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +static int init(AVFilterContext *ctx, const char *arg, void *opaque) +{ + ChannelSplitContext *s = ctx->priv; + int nb_channels; + int ret = 0, i; + + s->class = &channelsplit_class; + av_opt_set_defaults(s); + if ((ret = av_set_options_string(s, arg, "=", ":")) < 0) { + av_log(ctx, AV_LOG_ERROR, "Error parsing options string '%s'.\n", arg); + return ret; + } + if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) { + av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n", + s->channel_layout_str); + ret = AVERROR(EINVAL); + goto fail; + } + + nb_channels = av_get_channel_layout_nb_channels(s->channel_layout); + for (i = 0; i < nb_channels; i++) { + uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i); + AVFilterPad pad = { 0 }; + + pad.type = AVMEDIA_TYPE_AUDIO; + pad.name = av_get_channel_name(channel); + + ff_insert_outpad(ctx, i, &pad); + } + +fail: + av_opt_free(s); + return ret; +} + +static int query_formats(AVFilterContext *ctx) +{ + ChannelSplitContext *s = ctx->priv; + AVFilterChannelLayouts *in_layouts = NULL; + int i; + + ff_set_common_formats (ctx, ff_planar_sample_fmts()); + ff_set_common_samplerates(ctx, ff_all_samplerates()); + + ff_add_channel_layout(&in_layouts, s->channel_layout); + ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts); + + for (i = 0; i < ctx->output_count; i++) { + AVFilterChannelLayouts *out_layouts = NULL; + uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i); + + ff_add_channel_layout(&out_layouts, channel); + ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->in_channel_layouts); + } + + return 0; +} + +static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) +{ + AVFilterContext *ctx = inlink->dst; + int i; + + for (i = 0; i < ctx->output_count; i++) { + AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE); + + if (!buf_out) + return; + + buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i]; + buf_out->audio->channel_layout = + av_channel_layout_extract_channel(buf->audio->channel_layout, i); + + ff_filter_samples(ctx->outputs[i], buf_out); + } + avfilter_unref_buffer(buf); +} + +AVFilter avfilter_af_channelsplit = { + .name = "channelsplit", + .description = NULL_IF_CONFIG_SMALL("Split audio into per-channel streams"), + .priv_size = sizeof(ChannelSplitContext), + + .init = init, + .query_formats = query_formats, + + .inputs = (const AVFilterPad[]){{ .name = "default", + .type = AVMEDIA_TYPE_AUDIO, + .filter_samples = filter_samples, }, + { NULL }}, + .outputs = (const AVFilterPad[]){{ NULL }}, +}; diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 941ca6a..6814871 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -39,6 +39,7 @@ void avfilter_register_all(void) REGISTER_FILTER (ANULL, anull, af); REGISTER_FILTER (ASPLIT, asplit, af); REGISTER_FILTER (ASYNCTS, asyncts, af); + REGISTER_FILTER (CHANNELSPLIT,channelsplit,af); REGISTER_FILTER (RESAMPLE, resample, af); REGISTER_FILTER (ANULLSRC, anullsrc, asrc); diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 83bdcd7..1d58d95 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -220,6 +220,18 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type) return ret; } +AVFilterFormats *ff_planar_sample_fmts(void) +{ + AVFilterFormats *ret = NULL; + int fmt; + + for (fmt = 0; fmt < AV_SAMPLE_FMT_NB; fmt++) + if (av_sample_fmt_is_planar(fmt)) + ff_add_format(&ret, fmt); + + return ret; +} + AVFilterFormats *ff_all_samplerates(void) { AVFilterFormats *ret = av_mallocz(sizeof(*ret)); diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 8961cb1..c3e9522 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -160,6 +160,11 @@ int ff_add_format(AVFilterFormats **avff, int fmt); AVFilterFormats *ff_all_formats(enum AVMediaType type); /** + * Construct a formats list containing all planar sample formats. + */ +AVFilterFormats *ff_planar_sample_fmts(void); + +/** * Return a format list which contains the intersection of the formats of * a and b. Also, all the references of a, all the references of b, and * a and b themselves will be deallocated. diff --git a/libavfilter/version.h b/libavfilter/version.h index 9a64316..09cf4c6 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -29,7 +29,7 @@ #include "libavutil/avutil.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 20 +#define LIBAVFILTER_VERSION_MINOR 21 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ -- cgit v1.1 From 6d58358a3a3274e84a4e34a348165fbb3f484587 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 30 May 2012 10:31:48 +0200 Subject: lavfi: make avfilter_get_video_buffer() private on next bump. They are only useful inside filters and we don't allow user filters for now. --- libavfilter/avfilter.h | 14 +++----------- libavfilter/buffersrc.c | 4 ++-- libavfilter/vf_delogo.c | 4 ++-- libavfilter/vf_fieldorder.c | 2 +- libavfilter/vf_frei0r.c | 2 +- libavfilter/vf_gradfun.c | 2 +- libavfilter/vf_overlay.c | 2 +- libavfilter/vf_pad.c | 12 ++++++------ libavfilter/vf_pixdesctest.c | 4 ++-- libavfilter/vf_scale.c | 2 +- libavfilter/vf_transpose.c | 4 ++-- libavfilter/vf_vflip.c | 2 +- libavfilter/vf_yadif.c | 8 ++++---- libavfilter/video.c | 12 ++++++++---- libavfilter/video.h | 14 ++++++++++++++ libavfilter/vsrc_color.c | 2 +- libavfilter/vsrc_movie.c | 4 ++-- libavfilter/vsrc_testsrc.c | 3 +-- 18 files changed, 53 insertions(+), 44 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index c592372..7fbc160 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -573,19 +573,11 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, */ int avfilter_config_links(AVFilterContext *filter); -/** - * Request a picture buffer with a specific set of permissions. - * - * @param link the output link to the filter from which the buffer will - * be requested - * @param perms the required access permissions - * @param w the minimum width of the buffer to allocate - * @param h the minimum height of the buffer to allocate - * @return A reference to the buffer. This must be unreferenced with - * avfilter_unref_buffer when you are finished with it. - */ +#if FF_API_FILTERS_PUBLIC +attribute_deprecated AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h); +#endif /** * Create a buffer reference wrapped around an already allocated image diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 7af9f6c..3ffab60 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -109,8 +109,8 @@ int av_buffersrc_write_frame(AVFilterContext *buffer_filter, AVFrame *frame) case AVMEDIA_TYPE_VIDEO: CHECK_VIDEO_PARAM_CHANGE(buffer_filter, c, frame->width, frame->height, frame->format); - buf = avfilter_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE, - c->w, c->h); + buf = ff_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE, + c->w, c->h); av_image_copy(buf->data, buf->linesize, frame->data, frame->linesize, c->pix_fmt, c->w, c->h); break; diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 6fe4730..70aa12a 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -219,8 +219,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) AVFilterBufferRef *outpicref; if (inpicref->perms & AV_PERM_PRESERVE) { - outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - outlink->w, outlink->h); + outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, + outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outpicref, inpicref); outpicref->video->w = outlink->w; outpicref->video->h = outlink->h; diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c index ff1e332..67a6958 100644 --- a/libavfilter/vf_fieldorder.c +++ b/libavfilter/vf_fieldorder.c @@ -112,7 +112,7 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; - return avfilter_get_video_buffer(outlink, perms, w, h); + return ff_get_video_buffer(outlink, perms, w, h); } static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c index 85b4205..2a72fcc 100644 --- a/libavfilter/vf_frei0r.c +++ b/libavfilter/vf_frei0r.c @@ -432,7 +432,7 @@ static int source_config_props(AVFilterLink *outlink) static int source_request_frame(AVFilterLink *outlink) { Frei0rContext *frei0r = outlink->src->priv; - AVFilterBufferRef *picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); + AVFilterBufferRef *picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); picref->video->pixel_aspect = (AVRational) {1, 1}; picref->pts = frei0r->pts++; picref->pos = -1; diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c index 7fde16d..88872b3 100644 --- a/libavfilter/vf_gradfun.c +++ b/libavfilter/vf_gradfun.c @@ -190,7 +190,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) AVFilterBufferRef *outpicref; if (inpicref->perms & AV_PERM_PRESERVE) { - outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); + outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outpicref, inpicref); outpicref->video->w = outlink->w; outpicref->video->h = outlink->h; diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index 55f1cc3..ff7c348 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -205,7 +205,7 @@ static int config_output(AVFilterLink *outlink) static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, int w, int h) { - return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h); + return ff_get_video_buffer(link->dst->outputs[0], perms, w, h); } static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index 2e98aea..11c59b9 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -256,9 +256,9 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int { PadContext *pad = inlink->dst->priv; - AVFilterBufferRef *picref = avfilter_get_video_buffer(inlink->dst->outputs[0], perms, - w + (pad->w - pad->in_w), - h + (pad->h - pad->in_h)); + AVFilterBufferRef *picref = ff_get_video_buffer(inlink->dst->outputs[0], perms, + w + (pad->w - pad->in_w), + h + (pad->h - pad->in_h)); int plane; picref->video->w = w; @@ -327,9 +327,9 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) if(pad->needs_copy){ av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n"); avfilter_unref_buffer(outpicref); - outpicref = avfilter_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES, - FFMAX(inlink->w, pad->w), - FFMAX(inlink->h, pad->h)); + outpicref = ff_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES, + FFMAX(inlink->w, pad->w), + FFMAX(inlink->h, pad->h)); avfilter_copy_buffer_ref_props(outpicref, inpicref); } diff --git a/libavfilter/vf_pixdesctest.c b/libavfilter/vf_pixdesctest.c index 7eecdc0..353c57b 100644 --- a/libavfilter/vf_pixdesctest.c +++ b/libavfilter/vf_pixdesctest.c @@ -57,8 +57,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) AVFilterBufferRef *outpicref; int i; - outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - outlink->w, outlink->h); + outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, + outlink->w, outlink->h); outpicref = outlink->out_buf; avfilter_copy_buffer_ref_props(outpicref, picref); diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 6f33848..68ff845 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -265,7 +265,7 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) scale->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w; scale->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h; - outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); + outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outpicref, picref); outpicref->video->w = outlink->w; outpicref->video->h = outlink->h; diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c index 5e5feda..aa5c015 100644 --- a/libavfilter/vf_transpose.c +++ b/libavfilter/vf_transpose.c @@ -120,8 +120,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) { AVFilterLink *outlink = inlink->dst->outputs[0]; - outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - outlink->w, outlink->h); + outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, + outlink->w, outlink->h); outlink->out_buf->pts = picref->pts; if (picref->video->pixel_aspect.num == 0) { diff --git a/libavfilter/vf_vflip.c b/libavfilter/vf_vflip.c index 6d2f42e..bece2b2 100644 --- a/libavfilter/vf_vflip.c +++ b/libavfilter/vf_vflip.c @@ -50,7 +50,7 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, if (!(perms & AV_PERM_NEG_LINESIZES)) return ff_default_get_video_buffer(link, perms, w, h); - picref = avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h); + picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h); for (i = 0; i < 4; i ++) { int vsub = i == 1 || i == 2 ? flip->vsub : 0; diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index b498ab9..baf8b7a 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -208,8 +208,8 @@ static void return_frame(AVFilterContext *ctx, int is_second) } if (is_second) { - yadif->out = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE, link->w, link->h); + yadif->out = ff_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | + AV_PERM_REUSE, link->w, link->h); avfilter_copy_buffer_ref_props(yadif->out, yadif->cur); yadif->out->video->interlaced = 0; } @@ -268,8 +268,8 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) if (!yadif->prev) yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ); - yadif->out = avfilter_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE, link->w, link->h); + yadif->out = ff_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE | + AV_PERM_REUSE, link->w, link->h); avfilter_copy_buffer_ref_props(yadif->out, yadif->cur); yadif->out->video->interlaced = 0; diff --git a/libavfilter/video.c b/libavfilter/video.c index 33082a1..0e10bb7 100644 --- a/libavfilter/video.c +++ b/libavfilter/video.c @@ -67,7 +67,7 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end) AVFilterBufferRef *ff_null_get_video_buffer(AVFilterLink *link, int perms, int w, int h) { - return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h); + return ff_get_video_buffer(link->dst->outputs[0], perms, w, h); } /* TODO: set the buffer's priv member to a context structure for the whole @@ -138,7 +138,7 @@ fail: return NULL; } -AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h) +AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h) { AVFilterBufferRef *ret = NULL; @@ -173,7 +173,7 @@ static void default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) outlink = inlink->dst->outputs[0]; if (outlink) { - outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); + outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outlink->out_buf, picref); ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0)); } @@ -201,7 +201,7 @@ void ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) picref->perms, link->dstpad->min_perms, link->dstpad->rej_perms); - link->cur_buf = avfilter_get_video_buffer(link, dst->min_perms, link->w, link->h); + link->cur_buf = ff_get_video_buffer(link, dst->min_perms, link->w, link->h); link->src_buf = picref; avfilter_copy_buffer_ref_props(link->cur_buf, link->src_buf); } @@ -354,4 +354,8 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { ff_draw_slice(link, y, h, slice_dir); } +AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h) +{ + return ff_get_video_buffer(link, perms, w, h); +} #endif diff --git a/libavfilter/video.h b/libavfilter/video.h index 7c9f9a0..ce4e9c2 100644 --- a/libavfilter/video.h +++ b/libavfilter/video.h @@ -25,6 +25,20 @@ AVFilterBufferRef *ff_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h); AVFilterBufferRef *ff_null_get_video_buffer(AVFilterLink *link, int perms, int w, int h); +/** + * Request a picture buffer with a specific set of permissions. + * + * @param link the output link to the filter from which the buffer will + * be requested + * @param perms the required access permissions + * @param w the minimum width of the buffer to allocate + * @param h the minimum height of the buffer to allocate + * @return A reference to the buffer. This must be unreferenced with + * avfilter_unref_buffer when you are finished with it. + */ +AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms, + int w, int h); + void ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref); void ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir); void ff_null_end_frame(AVFilterLink *link); diff --git a/libavfilter/vsrc_color.c b/libavfilter/vsrc_color.c index 99ea0ad..bfd8493 100644 --- a/libavfilter/vsrc_color.c +++ b/libavfilter/vsrc_color.c @@ -140,7 +140,7 @@ static int color_config_props(AVFilterLink *inlink) static int color_request_frame(AVFilterLink *link) { ColorContext *color = link->src->priv; - AVFilterBufferRef *picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h); + AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h); picref->video->pixel_aspect = (AVRational) {1, 1}; picref->pts = color->pts++; picref->pos = -1; diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index ff3022c..f887e95 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -237,8 +237,8 @@ static int movie_get_frame(AVFilterLink *outlink) if (frame_decoded) { /* FIXME: avoid the memcpy */ - movie->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE2, outlink->w, outlink->h); + movie->picref = ff_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE | + AV_PERM_REUSE2, outlink->w, outlink->h); av_image_copy(movie->picref->data, movie->picref->linesize, movie->frame->data, movie->frame->linesize, movie->picref->format, outlink->w, outlink->h); diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index 7187241..a6159ef 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -132,8 +132,7 @@ static int request_frame(AVFilterLink *outlink) if (test->max_pts >= 0 && test->pts > test->max_pts) return AVERROR_EOF; - picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - test->w, test->h); + picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h); picref->pts = test->pts++; picref->pos = -1; picref->video->key_frame = 1; -- cgit v1.1 From 84b9fbe05578c8b4058e72bb0b203665a446a95a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Jun 2012 19:57:57 +0200 Subject: lavfi: add avfilter_pad_get_type() and avfilter_pad_get_name(). This will allow making AVFilterPad opaque for the calling apps, since those are the only two fields that can be useful to the users. --- libavfilter/avfilter.c | 10 ++++++++++ libavfilter/avfilter.h | 22 ++++++++++++++++++++++ libavfilter/version.h | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) (limited to 'libavfilter') diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 9b62be3..0507b2a 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -429,6 +429,16 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque return ret; } +const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx) +{ + return pads[pad_idx].name; +} + +enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx) +{ + return pads[pad_idx].type; +} + #if FF_API_DEFAULT_CONFIG_OUTPUT_LINK int avfilter_default_config_output_link(AVFilterLink *link) { diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 7fbc160..7ee18fb 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -359,6 +359,28 @@ struct AVFilterPad { int (*config_props)(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 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); + #if FF_API_FILTERS_PUBLIC /** default handler for start_frame() for video inputs */ attribute_deprecated diff --git a/libavfilter/version.h b/libavfilter/version.h index 09cf4c6..d8baf0e 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -29,7 +29,7 @@ #include "libavutil/avutil.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 21 +#define LIBAVFILTER_VERSION_MINOR 22 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ -- cgit v1.1 From 9d0bfc5052fa73ac8df89ec9992d77b07840fdf0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Jun 2012 20:12:42 +0200 Subject: lavfi: make AVFilterPad opaque after two major bumps. It will allow adding new fields to it without ABI breaks. --- libavfilter/af_anull.c | 1 + libavfilter/asink_anullsink.c | 1 + libavfilter/asrc_anullsrc.c | 1 + libavfilter/avfilter.h | 7 +++ libavfilter/buffersrc.c | 1 + libavfilter/internal.h | 126 ++++++++++++++++++++++++++++++++++++++++++ libavfilter/version.h | 3 + libavfilter/vf_aspect.c | 1 + libavfilter/vf_blackframe.c | 1 + libavfilter/vf_boxblur.c | 1 + libavfilter/vf_copy.c | 1 + libavfilter/vf_crop.c | 1 + libavfilter/vf_cropdetect.c | 1 + libavfilter/vf_delogo.c | 1 + libavfilter/vf_drawbox.c | 1 + libavfilter/vf_drawtext.c | 1 + libavfilter/vf_fade.c | 1 + libavfilter/vf_fieldorder.c | 1 + libavfilter/vf_format.c | 1 + libavfilter/vf_frei0r.c | 1 + libavfilter/vf_gradfun.c | 1 + libavfilter/vf_hflip.c | 1 + libavfilter/vf_hqdn3d.c | 1 + libavfilter/vf_null.c | 1 + libavfilter/vf_pad.c | 1 + libavfilter/vf_pixdesctest.c | 1 + libavfilter/vf_scale.c | 1 + libavfilter/vf_setpts.c | 1 + libavfilter/vf_showinfo.c | 1 + libavfilter/vf_slicify.c | 1 + libavfilter/vf_transpose.c | 1 + libavfilter/vf_unsharp.c | 1 + libavfilter/vf_vflip.c | 1 + libavfilter/vsink_nullsink.c | 1 + libavfilter/vsrc_color.c | 1 + libavfilter/vsrc_movie.c | 1 + libavfilter/vsrc_nullsrc.c | 1 + libavfilter/vsrc_testsrc.c | 1 + 38 files changed, 171 insertions(+) (limited to 'libavfilter') diff --git a/libavfilter/af_anull.c b/libavfilter/af_anull.c index 59b275c..294586e 100644 --- a/libavfilter/af_anull.c +++ b/libavfilter/af_anull.c @@ -23,6 +23,7 @@ #include "audio.h" #include "avfilter.h" +#include "internal.h" AVFilter avfilter_af_anull = { .name = "anull", diff --git a/libavfilter/asink_anullsink.c b/libavfilter/asink_anullsink.c index 3a505e7..b527850 100644 --- a/libavfilter/asink_anullsink.c +++ b/libavfilter/asink_anullsink.c @@ -17,6 +17,7 @@ */ #include "avfilter.h" +#include "internal.h" static void null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { } diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c index 8e99012..6f1c1e7 100644 --- a/libavfilter/asrc_anullsrc.c +++ b/libavfilter/asrc_anullsrc.c @@ -22,6 +22,7 @@ */ #include "avfilter.h" +#include "internal.h" #include "libavutil/audioconvert.h" typedef struct { diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 7ee18fb..157e72f 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -235,8 +235,14 @@ void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) */ #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 { /** @@ -358,6 +364,7 @@ struct AVFilterPad { */ int (*config_props)(AVFilterLink *link); }; +#endif /** * Get the name of an AVFilterPad. diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 3ffab60..ad9f45b 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -27,6 +27,7 @@ #include "avfilter.h" #include "buffersrc.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "vsrc_buffer.h" diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 4b53831..f6dc74b 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -26,6 +26,132 @@ #include "avfilter.h" +#if !FF_API_AVFILTERPAD_PUBLIC +/** + * A filter pad used for either input or output. + */ +struct AVFilterPad { + /** + * Pad name. The name is unique among inputs and among outputs, but an + * input may have the same name as an output. This may be NULL if this + * pad has no need to ever be referenced by name. + */ + const char *name; + + /** + * AVFilterPad type. + */ + enum AVMediaType type; + + /** + * Minimum required permissions on incoming buffers. Any buffer with + * insufficient permissions will be automatically copied by the filter + * system to a new buffer which provides the needed access permissions. + * + * Input pads only. + */ + int min_perms; + + /** + * Permissions which are not accepted on incoming buffers. Any buffer + * which has any of these permissions set will be automatically copied + * by the filter system to a new buffer which does not have those + * permissions. This can be used to easily disallow buffers with + * AV_PERM_REUSE. + * + * Input pads only. + */ + 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. + */ + void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref); + + /** + * Callback function to get a video buffer. If NULL, the filter system will + * use avfilter_default_get_video_buffer(). + * + * Input video pads only. + */ + AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h); + + /** + * Callback function to get an audio buffer. If NULL, the filter system will + * use avfilter_default_get_audio_buffer(). + * + * Input audio pads only. + */ + AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, + 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. + */ + void (*end_frame)(AVFilterLink *link); + + /** + * Slice drawing callback. This is where a filter receives video data + * and should do its processing. + * + * Input video pads only. + */ + void (*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. + * + * Input audio pads only. + */ + void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref); + + /** + * Frame poll callback. This returns the number of immediately available + * samples. It should return a positive value if the next request_frame() + * is guaranteed to return one frame (with no delay). + * + * Defaults to just calling the source poll_frame() method. + * + * Output pads only. + */ + int (*poll_frame)(AVFilterLink *link); + + /** + * Frame request callback. A call to this should result in at least one + * frame being output over the given link. This should return zero on + * success, and another value on error. + * + * Output pads only. + */ + int (*request_frame)(AVFilterLink *link); + + /** + * Link configuration callback. + * + * For output pads, this should set the link properties such as + * width/height. This should NOT set the format property - that is + * negotiated between filters by the filter system using the + * query_formats() callback before this function is called. + * + * For input pads, this should check the properties of the link, and update + * the filter's internal state as necessary. + * + * For both input and output filters, this should return zero on success, + * and another value on error. + */ + int (*config_props)(AVFilterLink *link); +}; +#endif + /** default handler for freeing audio/video buffer when there are no references left */ void ff_avfilter_default_free_buffer(AVFilterBuffer *buf); diff --git a/libavfilter/version.h b/libavfilter/version.h index d8baf0e..76fe166 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -59,5 +59,8 @@ #ifndef FF_API_FILTERS_PUBLIC #define FF_API_FILTERS_PUBLIC (LIBAVFILTER_VERSION_MAJOR < 3) #endif +#ifndef FF_API_AVFILTERPAD_PUBLIC +#define FF_API_AVFILTERPAD_PUBLIC (LIBAVFILTER_VERSION_MAJOR < 4) +#endif #endif // AVFILTER_VERSION_H diff --git a/libavfilter/vf_aspect.c b/libavfilter/vf_aspect.c index 0555afe..44bef91 100644 --- a/libavfilter/vf_aspect.c +++ b/libavfilter/vf_aspect.c @@ -25,6 +25,7 @@ #include "libavutil/mathematics.h" #include "avfilter.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c index 1d9a75d..a1f9732 100644 --- a/libavfilter/vf_blackframe.c +++ b/libavfilter/vf_blackframe.c @@ -29,6 +29,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_boxblur.c b/libavfilter/vf_boxblur.c index 21a0173..06917ec 100644 --- a/libavfilter/vf_boxblur.c +++ b/libavfilter/vf_boxblur.c @@ -30,6 +30,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" static const char *const var_names[] = { diff --git a/libavfilter/vf_copy.c b/libavfilter/vf_copy.c index 271a729..9ceb2f8 100644 --- a/libavfilter/vf_copy.c +++ b/libavfilter/vf_copy.c @@ -22,6 +22,7 @@ */ #include "avfilter.h" +#include "internal.h" #include "video.h" AVFilter avfilter_vf_copy = { diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c index f25278e..c884ce1 100644 --- a/libavfilter/vf_crop.c +++ b/libavfilter/vf_crop.c @@ -27,6 +27,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/eval.h" #include "libavutil/avstring.h" diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c index 38fd5c1..c890dab 100644 --- a/libavfilter/vf_cropdetect.c +++ b/libavfilter/vf_cropdetect.c @@ -26,6 +26,7 @@ #include "libavutil/imgutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 70aa12a..77382c9 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -30,6 +30,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" /** diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c index 47db049..eb129a2 100644 --- a/libavfilter/vf_drawbox.c +++ b/libavfilter/vf_drawbox.c @@ -29,6 +29,7 @@ #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" enum { Y, U, V, A }; diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 411bcbc..db66ad6 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -42,6 +42,7 @@ #include "avfilter.h" #include "drawutils.h" #include "formats.h" +#include "internal.h" #include "video.h" #undef time diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index 6b9cb66..00501dd 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -28,6 +28,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c index 67a6958..8921856 100644 --- a/libavfilter/vf_fieldorder.c +++ b/libavfilter/vf_fieldorder.c @@ -29,6 +29,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c index fff616b..1a50118 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -26,6 +26,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c index 2a72fcc..5488157 100644 --- a/libavfilter/vf_frei0r.c +++ b/libavfilter/vf_frei0r.c @@ -32,6 +32,7 @@ #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height); diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c index 88872b3..303e54c 100644 --- a/libavfilter/vf_gradfun.c +++ b/libavfilter/vf_gradfun.c @@ -38,6 +38,7 @@ #include "avfilter.h" #include "formats.h" #include "gradfun.h" +#include "internal.h" #include "video.h" DECLARE_ALIGNED(16, static const uint16_t, dither)[8][8] = { diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c index aff0f8c..af167e1 100644 --- a/libavfilter/vf_hflip.c +++ b/libavfilter/vf_hflip.c @@ -26,6 +26,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/pixdesc.h" #include "libavutil/intreadwrite.h" diff --git a/libavfilter/vf_hqdn3d.c b/libavfilter/vf_hqdn3d.c index 0a26dd0..f9b864e 100644 --- a/libavfilter/vf_hqdn3d.c +++ b/libavfilter/vf_hqdn3d.c @@ -28,6 +28,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_null.c b/libavfilter/vf_null.c index 470c3d2..26545dc 100644 --- a/libavfilter/vf_null.c +++ b/libavfilter/vf_null.c @@ -22,6 +22,7 @@ */ #include "avfilter.h" +#include "internal.h" #include "video.h" AVFilter avfilter_vf_null = { diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index 11c59b9..098fc80 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -26,6 +26,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/avstring.h" #include "libavutil/eval.h" diff --git a/libavfilter/vf_pixdesctest.c b/libavfilter/vf_pixdesctest.c index 353c57b..37dbe2d 100644 --- a/libavfilter/vf_pixdesctest.c +++ b/libavfilter/vf_pixdesctest.c @@ -25,6 +25,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 68ff845..58daf38 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -25,6 +25,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/avstring.h" #include "libavutil/eval.h" diff --git a/libavfilter/vf_setpts.c b/libavfilter/vf_setpts.c index d303851..77eef60 100644 --- a/libavfilter/vf_setpts.c +++ b/libavfilter/vf_setpts.c @@ -29,6 +29,7 @@ #include "libavutil/eval.h" #include "libavutil/mathematics.h" #include "avfilter.h" +#include "internal.h" #include "video.h" static const char *const var_names[] = { diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 1a8f16e..dbb67e9 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -26,6 +26,7 @@ #include "libavutil/imgutils.h" #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_slicify.c b/libavfilter/vf_slicify.c index fdc10be..636912d 100644 --- a/libavfilter/vf_slicify.c +++ b/libavfilter/vf_slicify.c @@ -24,6 +24,7 @@ */ #include "avfilter.h" +#include "internal.h" #include "video.h" #include "libavutil/pixdesc.h" diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c index aa5c015..5bcee9d 100644 --- a/libavfilter/vf_transpose.c +++ b/libavfilter/vf_transpose.c @@ -30,6 +30,7 @@ #include "libavutil/imgutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c index a5d301c..8010f2d 100644 --- a/libavfilter/vf_unsharp.c +++ b/libavfilter/vf_unsharp.c @@ -38,6 +38,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/common.h" #include "libavutil/mem.h" diff --git a/libavfilter/vf_vflip.c b/libavfilter/vf_vflip.c index bece2b2..0f528f1 100644 --- a/libavfilter/vf_vflip.c +++ b/libavfilter/vf_vflip.c @@ -25,6 +25,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vsink_nullsink.c b/libavfilter/vsink_nullsink.c index bdfcb8a..6f11158 100644 --- a/libavfilter/vsink_nullsink.c +++ b/libavfilter/vsink_nullsink.c @@ -17,6 +17,7 @@ */ #include "avfilter.h" +#include "internal.h" static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) { diff --git a/libavfilter/vsrc_color.c b/libavfilter/vsrc_color.c index bfd8493..de1f340 100644 --- a/libavfilter/vsrc_color.c +++ b/libavfilter/vsrc_color.c @@ -25,6 +25,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/pixdesc.h" #include "libavutil/colorspace.h" diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index f887e95..64f6e18 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -37,6 +37,7 @@ #include "libavformat/avformat.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vsrc_nullsrc.c b/libavfilter/vsrc_nullsrc.c index d145b0b..71094dc 100644 --- a/libavfilter/vsrc_nullsrc.c +++ b/libavfilter/vsrc_nullsrc.c @@ -27,6 +27,7 @@ #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" static const char *const var_names[] = { "E", diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index a6159ef..36f18b6 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -38,6 +38,7 @@ #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { -- cgit v1.1 From 9baeff9506a890c8f9f27c08cf331f827c24726a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Jun 2012 21:25:10 +0200 Subject: lavfi: replace AVFilterContext.input/output_count with nb_inputs/outputs This is more consistent with naming in the rest of Libav. --- libavfilter/af_amix.c | 6 ++--- libavfilter/af_channelsplit.c | 4 +-- libavfilter/audio.c | 2 +- libavfilter/avfilter.c | 58 +++++++++++++++++++++++++------------------ libavfilter/avfilter.h | 11 ++++++-- libavfilter/avfiltergraph.c | 34 ++++++++++++------------- libavfilter/formats.c | 4 +-- libavfilter/graphparser.c | 4 +-- libavfilter/internal.h | 10 ++++++-- libavfilter/split.c | 10 ++++---- libavfilter/version.h | 5 +++- libavfilter/video.c | 6 ++--- 12 files changed, 90 insertions(+), 64 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index 3fc2e84..003a8e8 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -454,10 +454,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) AVFilterLink *outlink = ctx->outputs[0]; int i; - for (i = 0; i < ctx->input_count; i++) + for (i = 0; i < ctx->nb_inputs; i++) if (ctx->inputs[i] == inlink) break; - if (i >= ctx->input_count) { + if (i >= ctx->nb_inputs) { av_log(ctx, AV_LOG_ERROR, "unknown input link\n"); return; } @@ -518,7 +518,7 @@ static void uninit(AVFilterContext *ctx) av_freep(&s->input_state); av_freep(&s->input_scale); - for (i = 0; i < ctx->input_count; i++) + for (i = 0; i < ctx->nb_inputs; i++) av_freep(&ctx->input_pads[i].name); } diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c index c3e7ccf..c9b31fa 100644 --- a/libavfilter/af_channelsplit.c +++ b/libavfilter/af_channelsplit.c @@ -99,7 +99,7 @@ static int query_formats(AVFilterContext *ctx) ff_add_channel_layout(&in_layouts, s->channel_layout); ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts); - for (i = 0; i < ctx->output_count; i++) { + for (i = 0; i < ctx->nb_outputs; i++) { AVFilterChannelLayouts *out_layouts = NULL; uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i); @@ -115,7 +115,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) { + for (i = 0; i < ctx->nb_outputs; i++) { AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE); if (!buf_out) diff --git a/libavfilter/audio.c b/libavfilter/audio.c index 81a042b..31839bb 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -156,7 +156,7 @@ void ff_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesr { AVFilterLink *outlink = NULL; - if (inlink->dst->output_count) + if (inlink->dst->nb_outputs) outlink = inlink->dst->outputs[0]; if (outlink) { diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 0507b2a..bf76997 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -70,8 +70,8 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, { AVFilterLink *link; - if (src->output_count <= srcpad || dst->input_count <= dstpad || - src->outputs[srcpad] || dst->inputs[dstpad]) + if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad || + src->outputs[srcpad] || dst->inputs[dstpad]) return -1; if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) { @@ -138,7 +138,7 @@ int avfilter_config_links(AVFilterContext *filter) unsigned i; int ret; - for (i = 0; i < filter->input_count; i ++) { + for (i = 0; i < filter->nb_inputs; i ++) { AVFilterLink *link = filter->inputs[i]; if (!link) continue; @@ -156,7 +156,7 @@ int avfilter_config_links(AVFilterContext *filter) return ret; if (!(config_link = link->srcpad->config_props)) { - if (link->src->input_count != 1) { + if (link->src->nb_inputs != 1) { av_log(link->src, AV_LOG_ERROR, "Source filters and filters " "with more than one input " "must set config_props() " @@ -171,15 +171,15 @@ int avfilter_config_links(AVFilterContext *filter) } if (link->time_base.num == 0 && link->time_base.den == 0) - link->time_base = link->src && link->src->input_count ? + link->time_base = link->src && link->src->nb_inputs ? link->src->inputs[0]->time_base : AV_TIME_BASE_Q; if (link->type == AVMEDIA_TYPE_VIDEO) { if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den) - link->sample_aspect_ratio = link->src->input_count ? + link->sample_aspect_ratio = link->src->nb_inputs ? link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1}; - if (link->src->input_count) { + if (link->src->nb_inputs) { if (!link->w) link->w = link->src->inputs[0]->w; if (!link->h) @@ -249,7 +249,7 @@ int ff_poll_frame(AVFilterLink *link) if (link->srcpad->poll_frame) return link->srcpad->poll_frame(link); - for (i = 0; i < link->src->input_count; i++) { + for (i = 0; i < link->src->nb_inputs; i++) { int val; if (!link->src->inputs[i]) return -1; @@ -339,27 +339,31 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in goto err; } - ret->input_count = pad_count(filter->inputs); - if (ret->input_count) { - ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count); + ret->nb_inputs = pad_count(filter->inputs); + if (ret->nb_inputs ) { + ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs); if (!ret->input_pads) goto err; - memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count); - ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count); + memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs); + ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs); if (!ret->inputs) goto err; } - ret->output_count = pad_count(filter->outputs); - if (ret->output_count) { - ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count); + ret->nb_outputs = pad_count(filter->outputs); + if (ret->nb_outputs) { + ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs); if (!ret->output_pads) goto err; - memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count); - ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count); + memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs); + ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs); if (!ret->outputs) goto err; } +#if FF_API_FOO_COUNT + ret->output_count = ret->nb_outputs; + ret->input_count = ret->nb_inputs; +#endif *filter_ctx = ret; return 0; @@ -367,10 +371,10 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in err: av_freep(&ret->inputs); av_freep(&ret->input_pads); - ret->input_count = 0; + ret->nb_inputs = 0; av_freep(&ret->outputs); av_freep(&ret->output_pads); - ret->output_count = 0; + ret->nb_outputs = 0; av_freep(&ret->priv); av_free(ret); return AVERROR(ENOMEM); @@ -384,7 +388,7 @@ void avfilter_free(AVFilterContext *filter) if (filter->filter->uninit) filter->filter->uninit(filter); - for (i = 0; i < filter->input_count; i++) { + for (i = 0; i < filter->nb_inputs; i++) { if ((link = filter->inputs[i])) { if (link->src) link->src->outputs[link->srcpad - link->src->output_pads] = NULL; @@ -397,7 +401,7 @@ void avfilter_free(AVFilterContext *filter) } av_freep(&link); } - for (i = 0; i < filter->output_count; i++) { + for (i = 0; i < filter->nb_outputs; i++) { if ((link = filter->outputs[i])) { if (link->dst) link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL; @@ -453,14 +457,20 @@ void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, void avfilter_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p) { - ff_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad), + ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad), &f->input_pads, &f->inputs, p); +#if FF_API_FOO_COUNT + f->input_count = f->nb_inputs; +#endif } void avfilter_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p) { - ff_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad), + ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad), &f->output_pads, &f->outputs, p); +#if FF_API_FOO_COUNT + f->output_count = f->nb_outputs; +#endif } int avfilter_poll_frame(AVFilterLink *link) { diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 157e72f..aff662f 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -488,15 +488,22 @@ struct AVFilterContext { char *name; ///< name of this filter instance - unsigned input_count; ///< number of input pads +#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 output_count; ///< number of output pads +#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 void *priv; ///< private data for use by the filter + + unsigned nb_inputs; ///< number of input pads + unsigned nb_outputs; ///< number of output pads }; /** diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 42bf1f7..4521f79 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -109,7 +109,7 @@ static int graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx) for (i = 0; i < graph->filter_count; i++) { filt = graph->filters[i]; - for (j = 0; j < filt->input_count; j++) { + for (j = 0; j < filt->nb_inputs; j++) { if (!filt->inputs[j] || !filt->inputs[j]->src) { av_log(log_ctx, AV_LOG_ERROR, "Input pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any source\n", @@ -118,7 +118,7 @@ static int graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx) } } - for (j = 0; j < filt->output_count; j++) { + for (j = 0; j < filt->nb_outputs; j++) { if (!filt->outputs[j] || !filt->outputs[j]->dst) { av_log(log_ctx, AV_LOG_ERROR, "Output pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any destination\n", @@ -144,7 +144,7 @@ static int graph_config_links(AVFilterGraph *graph, AVClass *log_ctx) for (i=0; i < graph->filter_count; i++) { filt = graph->filters[i]; - if (!filt->output_count) { + if (!filt->nb_outputs) { if ((ret = avfilter_config_links(filt))) return ret; } @@ -181,7 +181,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) for (i = 0; i < graph->filter_count; i++) { AVFilterContext *filter = graph->filters[i]; - for (j = 0; j < filter->input_count; j++) { + for (j = 0; j < filter->nb_inputs; j++) { AVFilterLink *link = filter->inputs[j]; int convert_needed = 0; @@ -315,7 +315,7 @@ static int pick_format(AVFilterLink *link) #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \ do { \ - for (i = 0; i < filter->input_count; i++) { \ + for (i = 0; i < filter->nb_inputs; i++) { \ AVFilterLink *link = filter->inputs[i]; \ fmt_type fmt; \ \ @@ -323,7 +323,7 @@ do { \ continue; \ fmt = link->out_ ## list->var[0]; \ \ - for (j = 0; j < filter->output_count; j++) { \ + for (j = 0; j < filter->nb_outputs; j++) { \ AVFilterLink *out_link = filter->outputs[j]; \ list_type *fmts; \ \ @@ -380,19 +380,19 @@ static void swap_samplerates_on_filter(AVFilterContext *filter) int sample_rate; int i, j; - for (i = 0; i < filter->input_count; i++) { + for (i = 0; i < filter->nb_inputs; i++) { link = filter->inputs[i]; if (link->type == AVMEDIA_TYPE_AUDIO && link->out_samplerates->format_count == 1) break; } - if (i == filter->input_count) + if (i == filter->nb_inputs) return; sample_rate = link->out_samplerates->formats[0]; - for (i = 0; i < filter->output_count; i++) { + for (i = 0; i < filter->nb_outputs; i++) { AVFilterLink *outlink = filter->outputs[i]; int best_idx, best_diff = INT_MAX; @@ -427,19 +427,19 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter) uint64_t chlayout; int i, j; - for (i = 0; i < filter->input_count; i++) { + for (i = 0; i < filter->nb_inputs; i++) { link = filter->inputs[i]; if (link->type == AVMEDIA_TYPE_AUDIO && link->out_channel_layouts->nb_channel_layouts == 1) break; } - if (i == filter->input_count) + if (i == filter->nb_inputs) return; chlayout = link->out_channel_layouts->channel_layouts[0]; - for (i = 0; i < filter->output_count; i++) { + for (i = 0; i < filter->nb_outputs; i++) { AVFilterLink *outlink = filter->outputs[i]; int best_idx, best_score = INT_MIN; @@ -480,20 +480,20 @@ static void swap_sample_fmts_on_filter(AVFilterContext *filter) int format, bps; int i, j; - for (i = 0; i < filter->input_count; i++) { + for (i = 0; i < filter->nb_inputs; i++) { link = filter->inputs[i]; if (link->type == AVMEDIA_TYPE_AUDIO && link->out_formats->format_count == 1) break; } - if (i == filter->input_count) + if (i == filter->nb_inputs) return; format = link->out_formats->formats[0]; bps = av_get_bytes_per_sample(format); - for (i = 0; i < filter->output_count; i++) { + for (i = 0; i < filter->nb_outputs; i++) { AVFilterLink *outlink = filter->outputs[i]; int best_idx, best_score = INT_MIN; @@ -549,10 +549,10 @@ static int pick_formats(AVFilterGraph *graph) for (i = 0; i < graph->filter_count; i++) { AVFilterContext *filter = graph->filters[i]; - for (j = 0; j < filter->input_count; j++) + for (j = 0; j < filter->nb_inputs; j++) if ((ret = pick_format(filter->inputs[j])) < 0) return ret; - for (j = 0; j < filter->output_count; j++) + for (j = 0; j < filter->nb_outputs; j++) if ((ret = pick_format(filter->outputs[j])) < 0) return ret; } diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 1d58d95..36af528 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -330,13 +330,13 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) { \ int count = 0, i; \ \ - for (i = 0; i < ctx->input_count; i++) { \ + for (i = 0; i < ctx->nb_inputs; i++) { \ if (ctx->inputs[i]) { \ ref(fmts, &ctx->inputs[i]->out_fmts); \ count++; \ } \ } \ - for (i = 0; i < ctx->output_count; i++) { \ + for (i = 0; i < ctx->nb_outputs; i++) { \ if (ctx->outputs[i]) { \ ref(fmts, &ctx->outputs[i]->in_fmts); \ count++; \ diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index b3f295f..5f77084 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -226,7 +226,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx, { int pad, ret; - for (pad = 0; pad < filt_ctx->input_count; pad++) { + for (pad = 0; pad < filt_ctx->nb_inputs; pad++) { AVFilterInOut *p = *curr_inputs; if (p) { @@ -254,7 +254,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx, return AVERROR(EINVAL); } - pad = filt_ctx->output_count; + pad = filt_ctx->nb_outputs; while (pad--) { AVFilterInOut *currlinkn = av_mallocz(sizeof(AVFilterInOut)); if (!currlinkn) diff --git a/libavfilter/internal.h b/libavfilter/internal.h index f6dc74b..01b8f66 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -183,16 +183,22 @@ void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, static inline void ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p) { - ff_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad), + ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad), &f->input_pads, &f->inputs, p); +#if FF_API_FOO_COUNT + f->input_count = f->nb_inputs; +#endif } /** Insert a new output pad for the filter. */ static inline void ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p) { - ff_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad), + ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad), &f->output_pads, &f->outputs, p); +#if FF_API_FOO_COUNT + f->output_count = f->nb_outputs; +#endif } /** diff --git a/libavfilter/split.c b/libavfilter/split.c index 95c1b9a..b7d0378 100644 --- a/libavfilter/split.c +++ b/libavfilter/split.c @@ -59,7 +59,7 @@ static void split_uninit(AVFilterContext *ctx) { int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) av_freep(&ctx->output_pads[i].name); } @@ -68,7 +68,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) ff_start_frame(ctx->outputs[i], avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); } @@ -78,7 +78,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) ff_draw_slice(ctx->outputs[i], y, h, slice_dir); } @@ -87,7 +87,7 @@ static void end_frame(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) ff_end_frame(ctx->outputs[i]); avfilter_unref_buffer(inlink->cur_buf); @@ -115,7 +115,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) ff_filter_samples(inlink->dst->outputs[i], avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE)); } diff --git a/libavfilter/version.h b/libavfilter/version.h index 76fe166..562147b 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -29,7 +29,7 @@ #include "libavutil/avutil.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 22 +#define LIBAVFILTER_VERSION_MINOR 23 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ @@ -62,5 +62,8 @@ #ifndef FF_API_AVFILTERPAD_PUBLIC #define FF_API_AVFILTERPAD_PUBLIC (LIBAVFILTER_VERSION_MAJOR < 4) #endif +#ifndef FF_API_FOO_COUNT +#define FF_API_FOO_COUNT (LIBAVFILTER_VERSION_MAJOR < 4) +#endif #endif // AVFILTER_VERSION_H diff --git a/libavfilter/video.c b/libavfilter/video.c index 0e10bb7..a00f8c1 100644 --- a/libavfilter/video.c +++ b/libavfilter/video.c @@ -169,7 +169,7 @@ static void default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) { AVFilterLink *outlink = NULL; - if (inlink->dst->output_count) + if (inlink->dst->nb_outputs) outlink = inlink->dst->outputs[0]; if (outlink) { @@ -220,7 +220,7 @@ static void default_end_frame(AVFilterLink *inlink) { AVFilterLink *outlink = NULL; - if (inlink->dst->output_count) + if (inlink->dst->nb_outputs) outlink = inlink->dst->outputs[0]; avfilter_unref_buffer(inlink->cur_buf); @@ -261,7 +261,7 @@ static void default_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir { AVFilterLink *outlink = NULL; - if (inlink->dst->output_count) + if (inlink->dst->nb_outputs) outlink = inlink->dst->outputs[0]; if (outlink) -- cgit v1.1 From 2f296e39a17cd947c6675c20ff61a2d993ff0de2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 13 Jun 2012 10:10:31 +0200 Subject: lavfi: allow building without swscale. --- libavfilter/Makefile | 4 +++- libavfilter/allfilters.c | 5 +---- libavfilter/avfiltergraph.c | 9 +++++++-- 3 files changed, 11 insertions(+), 7 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 7e1a6d1..955a97c 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -1,8 +1,9 @@ NAME = avfilter -FFLIBS = avutil swscale +FFLIBS = avutil FFLIBS-$(CONFIG_ASYNCTS_FILTER) += avresample FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec FFLIBS-$(CONFIG_RESAMPLE_FILTER) += avresample +FFLIBS-$(CONFIG_SCALE_FILTER) += swscale HEADERS = avfilter.h \ avfiltergraph.h \ @@ -63,6 +64,7 @@ OBJS-$(CONFIG_OCV_FILTER) += vf_libopencv.o OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o +OBJS-$(CONFIG_SCALE_FILTER) += vf_scale.o OBJS-$(CONFIG_SELECT_FILTER) += vf_select.o OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o OBJS-$(CONFIG_SETPTS_FILTER) += vf_setpts.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 6814871..118f09d 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -73,6 +73,7 @@ void avfilter_register_all(void) REGISTER_FILTER (OVERLAY, overlay, vf); REGISTER_FILTER (PAD, pad, vf); REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf); + REGISTER_FILTER (SCALE, scale, vf); REGISTER_FILTER (SELECT, select, vf); REGISTER_FILTER (SETDAR, setdar, vf); REGISTER_FILTER (SETPTS, setpts, vf); @@ -113,8 +114,4 @@ void avfilter_register_all(void) extern AVFilter avfilter_asink_abuffer; avfilter_register(&avfilter_asink_abuffer); } - { - extern AVFilter avfilter_vf_scale; - avfilter_register(&avfilter_vf_scale); - } } diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 4521f79..0a863e5 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -213,11 +213,16 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) /* couldn't merge format lists. auto-insert conversion filter */ switch (link->type) { case AVMEDIA_TYPE_VIDEO: + if (!(filter = avfilter_get_by_name("scale"))) { + av_log(log_ctx, AV_LOG_ERROR, "'scale' filter " + "not present, cannot convert pixel formats.\n"); + return AVERROR(EINVAL); + } + snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d", scaler_count++); snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts); - if ((ret = avfilter_graph_create_filter(&convert, - avfilter_get_by_name("scale"), + if ((ret = avfilter_graph_create_filter(&convert, filter, inst_name, scale_args, NULL, graph)) < 0) return ret; -- cgit v1.1 From 24b2f4ed21e463a4bd3beec16f2bdef4a15241c1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 13 Jun 2012 10:12:08 +0200 Subject: avfiltergraph: remove a redundant call to avfilter_get_by_name(). --- libavfilter/avfiltergraph.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 0a863e5..3d463a8 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -236,8 +236,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) snprintf(inst_name, sizeof(inst_name), "auto-inserted resampler %d", resampler_count++); - if ((ret = avfilter_graph_create_filter(&convert, - avfilter_get_by_name("resample"), + if ((ret = avfilter_graph_create_filter(&convert, filter, inst_name, NULL, NULL, graph)) < 0) return ret; break; -- cgit v1.1 From 9cdf74f904f76b2a1da474a2290c7e9ed34dd431 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 13 Jun 2012 10:52:35 +0200 Subject: lavfi/audio: use av_samples_copy() instead of custom code. Fixes a possible invalid write, found by Nicolas George. --- libavfilter/audio.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'libavfilter') diff --git a/libavfilter/audio.c b/libavfilter/audio.c index 31839bb..a6fef9d 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -185,10 +185,6 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) /* prepare to copy the samples if the buffer has insufficient permissions */ if ((dst->min_perms & samplesref->perms) != dst->min_perms || dst->rej_perms & samplesref->perms) { - int i, planar = av_sample_fmt_is_planar(samplesref->format); - int planes = !planar ? 1: - av_get_channel_layout_nb_channels(samplesref->audio->channel_layout); - av_log(link->dst, AV_LOG_DEBUG, "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n", samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms); @@ -199,8 +195,10 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate; /* Copy actual data into new samples buffer */ - for (i = 0; i < planes; i++) - memcpy(link->cur_buf->extended_data[i], samplesref->extended_data[i], samplesref->linesize[0]); + av_samples_copy(link->cur_buf->extended_data, samplesref->extended_data, + 0, 0, samplesref->audio->nb_samples, + av_get_channel_layout_nb_channels(link->channel_layout), + link->format); avfilter_unref_buffer(samplesref); } else -- cgit v1.1