diff options
Diffstat (limited to 'libavfilter/avfilter.c')
-rw-r--r-- | libavfilter/avfilter.c | 134 |
1 files changed, 101 insertions, 33 deletions
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 2f5c37d3af..9473c355fe 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -2,20 +2,20 @@ * filter layer * Copyright (c) 2007 Bobby Bingham * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * 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. * - * Libav is distributed in the hope that it will be useful, + * 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 Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -24,24 +24,36 @@ #include "libavutil/pixdesc.h" #include "libavutil/rational.h" #include "libavutil/audioconvert.h" +#include "libavutil/avassert.h" +#include "libavutil/avstring.h" #include "avfilter.h" #include "formats.h" #include "internal.h" unsigned avfilter_version(void) { + av_assert0(LIBAVFILTER_VERSION_MICRO >= 100); return LIBAVFILTER_VERSION_INT; } const char *avfilter_configuration(void) { - return LIBAV_CONFIGURATION; + return FFMPEG_CONFIGURATION; } const char *avfilter_license(void) { #define LICENSE_PREFIX "libavfilter license: " - return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1; + return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; +} + +void ff_command_queue_pop(AVFilterContext *filter) +{ + AVFilterCommand *c= filter->command_queue; + av_freep(&c->arg); + av_freep(&c->command); + filter->command_queue= c->next; + av_free(c); } void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, @@ -95,6 +107,17 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, return 0; } +void avfilter_link_free(AVFilterLink **link) +{ + if (!*link) + return; + + if ((*link)->pool) + ff_free_pool((*link)->pool); + + av_freep(link); +} + int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, unsigned filt_srcpad_idx, unsigned filt_dstpad_idx) { @@ -122,12 +145,12 @@ int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, if (link->out_formats) avfilter_formats_changeref(&link->out_formats, &filt->outputs[filt_dstpad_idx]->out_formats); - if (link->out_samplerates) - avfilter_formats_changeref(&link->out_samplerates, - &filt->outputs[filt_dstpad_idx]->out_samplerates); if (link->out_channel_layouts) ff_channel_layouts_changeref(&link->out_channel_layouts, &filt->outputs[filt_dstpad_idx]->out_channel_layouts); + if (link->out_samplerates) + avfilter_formats_changeref(&link->out_samplerates, + &filt->outputs[filt_dstpad_idx]->out_samplerates); return 0; } @@ -140,9 +163,13 @@ int avfilter_config_links(AVFilterContext *filter) for (i = 0; i < filter->input_count; i ++) { AVFilterLink *link = filter->inputs[i]; + AVFilterLink *inlink = link->src->input_count ? + link->src->inputs[0] : NULL; if (!link) continue; + link->current_pts = AV_NOPTS_VALUE; + switch (link->init_state) { case AVLINK_INIT: continue; @@ -166,26 +193,43 @@ int avfilter_config_links(AVFilterContext *filter) } else if ((ret = config_link(link)) < 0) return ret; - if (link->time_base.num == 0 && link->time_base.den == 0) - link->time_base = link->src && link->src->input_count ? - link->src->inputs[0]->time_base : AV_TIME_BASE_Q; + switch (link->type) { + case AVMEDIA_TYPE_VIDEO: + if (!link->time_base.num && !link->time_base.den) + link->time_base = inlink ? inlink->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->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1}; + link->sample_aspect_ratio = inlink ? + inlink->sample_aspect_ratio : (AVRational){1,1}; - if (link->src->input_count) { + if (inlink) { if (!link->w) - link->w = link->src->inputs[0]->w; + link->w = inlink->w; if (!link->h) - link->h = link->src->inputs[0]->h; + link->h = inlink->h; } else if (!link->w || !link->h) { av_log(link->src, AV_LOG_ERROR, "Video source filters must set their output link's " "width and height\n"); return AVERROR(EINVAL); } + break; + + case AVMEDIA_TYPE_AUDIO: + if (inlink) { + if (!link->sample_rate) + link->sample_rate = inlink->sample_rate; + if (!link->time_base.num && !link->time_base.den) + link->time_base = inlink->time_base; + } else if (!link->sample_rate) { + av_log(link->src, AV_LOG_ERROR, + "Audio source filters must set their output link's " + "sample_rate\n"); + return AVERROR(EINVAL); + } + + if (!link->time_base.num && !link->time_base.den) + link->time_base = (AVRational) {1, link->sample_rate}; } if ((config_link = link->dstpad->config_props)) @@ -203,7 +247,7 @@ void ff_dlog_link(void *ctx, AVFilterLink *link, int end) { if (link->type == AVMEDIA_TYPE_VIDEO) { av_dlog(ctx, - "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s", + "link[%p s:%dx%d fmt:%s %s->%s]%s", link, link->w, link->h, av_pix_fmt_descriptors[link->format].name, link->src ? link->src->filter->name : "", @@ -214,8 +258,8 @@ void ff_dlog_link(void *ctx, AVFilterLink *link, int end) av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout); av_dlog(ctx, - "link[%p r:%"PRId64" cl:%s fmt:%-16s %-16s->%-16s]%s", - link, link->sample_rate, buf, + "link[%p r:%d cl:%s fmt:%s %s->%s]%s", + link, (int)link->sample_rate, buf, av_get_sample_fmt_name(link->format), link->src ? link->src->filter->name : "", link->dst ? link->dst->filter->name : "", @@ -252,7 +296,27 @@ int avfilter_poll_frame(AVFilterLink *link) return min; } -#define MAX_REGISTERED_AVFILTERS_NB 64 +void ff_update_link_current_pts(AVFilterLink *link, int64_t pts) +{ + if (pts == AV_NOPTS_VALUE) + return; + link->current_pts = pts; /* TODO use duration */ + if (link->graph && link->age_index >= 0) + ff_avfilter_graph_update_heap(link->graph, link); +} + +int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags) +{ + if(!strcmp(cmd, "ping")){ + av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name); + return 0; + }else if(filter->filter->process_command) { + return filter->filter->process_command(filter, cmd, arg, res, res_len, flags); + } + return AVERROR(ENOSYS); +} + +#define MAX_REGISTERED_AVFILTERS_NB 128 static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1]; @@ -271,8 +335,13 @@ AVFilter *avfilter_get_by_name(const char *name) int avfilter_register(AVFilter *filter) { - if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB) - return -1; + if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB) { + av_log(NULL, AV_LOG_ERROR, + "Maximum number of registered filters %d reached, " + "impossible to register filter with name '%s'\n", + MAX_REGISTERED_AVFILTERS_NB, filter->name); + return AVERROR(ENOMEM); + } registered_avfilters[next_registered_avfilter_idx++] = filter; return 0; @@ -373,6 +442,9 @@ void avfilter_free(AVFilterContext *filter) int i; AVFilterLink *link; + if (!filter) + return; + if (filter->filter->uninit) filter->filter->uninit(filter); @@ -387,7 +459,7 @@ void avfilter_free(AVFilterContext *filter) ff_channel_layouts_unref(&link->in_channel_layouts); ff_channel_layouts_unref(&link->out_channel_layouts); } - av_freep(&link); + avfilter_link_free(&link); } for (i = 0; i < filter->output_count; i++) { if ((link = filter->outputs[i])) { @@ -400,7 +472,7 @@ void avfilter_free(AVFilterContext *filter) ff_channel_layouts_unref(&link->in_channel_layouts); ff_channel_layouts_unref(&link->out_channel_layouts); } - av_freep(&link); + avfilter_link_free(&link); } av_freep(&filter->name); @@ -409,6 +481,9 @@ void avfilter_free(AVFilterContext *filter) av_freep(&filter->inputs); av_freep(&filter->outputs); av_freep(&filter->priv); + while(filter->command_queue){ + ff_command_queue_pop(filter); + } av_free(filter); } @@ -420,10 +495,3 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque ret = filter->filter->init(filter, args, opaque); return ret; } - -#if FF_API_DEFAULT_CONFIG_OUTPUT_LINK -int avfilter_default_config_output_link(AVFilterLink *link) -{ - return 0; -} -#endif |