#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/imgutils.h"
+#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/pixdesc.h"
#include "libavutil/rational.h"
if ((config_link = link->dstpad->config_props))
if ((ret = config_link(link)) < 0) {
- av_log(link->src, AV_LOG_ERROR,
+ av_log(link->dst, AV_LOG_ERROR,
"Failed to configure input pad on %s\n",
link->dst->name);
return ret;
static AVFilter *first_filter;
+#if !FF_API_NOCONST_GET_NAME
+const
+#endif
AVFilter *avfilter_get_by_name(const char *name)
{
- AVFilter *f = NULL;
+ const AVFilter *f = NULL;
if (!name)
return NULL;
static const AVClass *filter_child_class_next(const AVClass *prev)
{
- AVFilter *f = NULL;
+ const AVFilter *f = NULL;
while (prev && (f = avfilter_next(f)))
if (f->priv_class == prev)
return NULL;
}
+#define OFFSET(x) offsetof(AVFilterContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM
+static const AVOption avfilter_options[] = {
+ { "thread_type", "Allowed thread types", OFFSET(thread_type), AV_OPT_TYPE_FLAGS,
+ { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
+ { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE }, .unit = "thread_type" },
+ { NULL },
+};
+
static const AVClass avfilter_class = {
.class_name = "AVFilter",
.item_name = filter_name,
.version = LIBAVUTIL_VERSION_INT,
.child_next = filter_child_next,
.child_class_next = filter_child_class_next,
+ .option = avfilter_options,
};
+static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg,
+ int *ret, int nb_jobs)
+{
+ int i;
+
+ for (i = 0; i < nb_jobs; i++) {
+ int r = func(ctx, arg, i, nb_jobs);
+ if (ret)
+ ret[i] = r;
+ }
+ return 0;
+}
+
AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
{
AVFilterContext *ret;
goto err;
}
+ av_opt_set_defaults(ret);
if (filter->priv_class) {
*(const AVClass**)ret->priv = filter->priv_class;
av_opt_set_defaults(ret->priv);
}
+ ret->internal = av_mallocz(sizeof(*ret->internal));
+ if (!ret->internal)
+ goto err;
+ ret->internal->execute = default_execute;
+
ret->nb_inputs = avfilter_pad_count(filter->inputs);
if (ret->nb_inputs ) {
ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs);
goto err;
}
#if FF_API_FOO_COUNT
+FF_DISABLE_DEPRECATION_WARNINGS
ret->output_count = ret->nb_outputs;
ret->input_count = ret->nb_inputs;
+FF_ENABLE_DEPRECATION_WARNINGS
#endif
return ret;
av_freep(&ret->output_pads);
ret->nb_outputs = 0;
av_freep(&ret->priv);
+ av_freep(&ret->internal);
av_free(ret);
return NULL;
}
av_freep(&filter->inputs);
av_freep(&filter->outputs);
av_freep(&filter->priv);
+ av_freep(&filter->internal);
av_free(filter);
}
{
int ret = 0;
+ ret = av_opt_set_dict(ctx, options);
+ if (ret < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Error applying generic filter options.\n");
+ return ret;
+ }
+
+ if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS &&
+ ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
+ ctx->graph->internal->thread_execute) {
+ ctx->thread_type = AVFILTER_THREAD_SLICE;
+ ctx->internal->execute = ctx->graph->internal->thread_execute;
+ } else {
+ ctx->thread_type = 0;
+ }
+
if (ctx->filter->priv_class) {
ret = av_opt_set_dict(ctx->priv, options);
if (ret < 0) {
{
int (*filter_frame)(AVFilterLink *, AVFrame *);
AVFilterPad *dst = link->dstpad;
- AVFrame *out;
+ AVFrame *out = NULL;
+ int ret;
FF_DPRINTF_START(NULL, filter_frame);
ff_dlog_link(NULL, link, 1);
case AVMEDIA_TYPE_AUDIO:
out = ff_get_audio_buffer(link, frame->nb_samples);
break;
- default: return AVERROR(EINVAL);
+ default:
+ ret = AVERROR(EINVAL);
+ goto fail;
}
if (!out) {
- av_frame_free(&frame);
- return AVERROR(ENOMEM);
+ ret = AVERROR(ENOMEM);
+ goto fail;
}
- av_frame_copy_props(out, frame);
+
+ ret = av_frame_copy_props(out, frame);
+ if (ret < 0)
+ goto fail;
switch (link->type) {
case AVMEDIA_TYPE_VIDEO:
av_get_channel_layout_nb_channels(frame->channel_layout),
frame->format);
break;
- default: return AVERROR(EINVAL);
+ default:
+ ret = AVERROR(EINVAL);
+ goto fail;
}
av_frame_free(&frame);
out = frame;
return filter_frame(link, out);
+
+fail:
+ av_frame_free(&out);
+ av_frame_free(&frame);
+ return ret;
}
const AVClass *avfilter_get_class(void)