Skip to content

Commit db98b0e

Browse files
committed
avfilter/avfilter: Avoid allocation for AVFilterInternal
To do this, allocate AVFilterInternal jointly with AVFilterContext and rename it to FFFilterContext in the process (similarly to AVStream/FFStream). The AVFilterInternal* will be removed from AVFilterContext on the next major bump. Signed-off-by: Andreas Rheinhardt <[email protected]>
1 parent cc36a9f commit db98b0e

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

libavfilter/avfilter.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad,
159159
src->outputs[srcpad] || dst->inputs[dstpad])
160160
return AVERROR(EINVAL);
161161

162-
if (!src->internal->initialized || !dst->internal->initialized) {
162+
if (!fffilterctx(src)->initialized || !fffilterctx(dst)->initialized) {
163163
av_log(src, AV_LOG_ERROR, "Filters must be initialized before linking.\n");
164164
return AVERROR(EINVAL);
165165
}
@@ -668,15 +668,17 @@ static int default_execute(AVFilterContext *ctx, avfilter_action_func *func, voi
668668

669669
AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
670670
{
671+
FFFilterContext *ctx;
671672
AVFilterContext *ret;
672673
int preinited = 0;
673674

674675
if (!filter)
675676
return NULL;
676677

677-
ret = av_mallocz(sizeof(AVFilterContext));
678-
if (!ret)
678+
ctx = av_mallocz(sizeof(*ctx));
679+
if (!ctx)
679680
return NULL;
681+
ret = &ctx->p;
680682

681683
ret->av_class = &avfilter_class;
682684
ret->filter = filter;
@@ -698,10 +700,7 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
698700
av_opt_set_defaults(ret->priv);
699701
}
700702

701-
ret->internal = av_mallocz(sizeof(*ret->internal));
702-
if (!ret->internal)
703-
goto err;
704-
ret->internal->execute = default_execute;
703+
ctx->execute = default_execute;
705704

706705
ret->nb_inputs = filter->nb_inputs;
707706
if (ret->nb_inputs ) {
@@ -735,7 +734,6 @@ AVFilterContext *ff_filter_alloc(const AVFilter *filter, const char *inst_name)
735734
av_freep(&ret->output_pads);
736735
ret->nb_outputs = 0;
737736
av_freep(&ret->priv);
738-
av_freep(&ret->internal);
739737
av_free(ret);
740738
return NULL;
741739
}
@@ -807,7 +805,6 @@ void avfilter_free(AVFilterContext *filter)
807805
av_expr_free(filter->enable);
808806
filter->enable = NULL;
809807
av_freep(&filter->var_values);
810-
av_freep(&filter->internal);
811808
av_free(filter);
812809
}
813810

@@ -891,9 +888,10 @@ int ff_filter_process_command(AVFilterContext *ctx, const char *cmd,
891888

892889
int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
893890
{
891+
FFFilterContext *ctxi = fffilterctx(ctx);
894892
int ret = 0;
895893

896-
if (ctx->internal->initialized) {
894+
if (ctxi->initialized) {
897895
av_log(ctx, AV_LOG_ERROR, "Filter already initialized\n");
898896
return AVERROR(EINVAL);
899897
}
@@ -908,7 +906,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
908906
ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE &&
909907
ctx->graph->internal->thread_execute) {
910908
ctx->thread_type = AVFILTER_THREAD_SLICE;
911-
ctx->internal->execute = ctx->graph->internal->thread_execute;
909+
ctxi->execute = ctx->graph->internal->thread_execute;
912910
} else {
913911
ctx->thread_type = 0;
914912
}
@@ -924,7 +922,7 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options)
924922
return ret;
925923
}
926924

927-
ctx->internal->initialized = 1;
925+
ctxi->initialized = 1;
928926

929927
return 0;
930928
}

libavfilter/graphparser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ int avfilter_graph_segment_init(AVFilterGraphSegment *seg, int flags)
626626

627627
if (p->filter_name)
628628
return fail_creation_pending(seg, p->filter_name, __func__);
629-
if (!p->filter || p->filter->internal->initialized)
629+
if (!p->filter || fffilterctx(p->filter)->initialized)
630630
continue;
631631

632632
ret = avfilter_init_dict(p->filter, NULL);

libavfilter/internal.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,28 @@ struct AVFilterGraphInternal {
133133
FFFrameQueueGlobal frame_queues;
134134
};
135135

136-
struct AVFilterInternal {
136+
typedef struct FFFilterContext {
137+
/**
138+
* The public AVFilterContext. See avfilter.h for it.
139+
*/
140+
AVFilterContext p;
141+
137142
avfilter_execute_func *execute;
138143

139144
// 1 when avfilter_init_*() was successfully called on this filter
140145
// 0 otherwise
141146
int initialized;
142-
};
147+
} FFFilterContext;
148+
149+
static inline FFFilterContext *fffilterctx(AVFilterContext *ctx)
150+
{
151+
return (FFFilterContext*)ctx;
152+
}
143153

144154
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func,
145155
void *arg, int *ret, int nb_jobs)
146156
{
147-
return ctx->internal->execute(ctx, func, arg, ret, nb_jobs);
157+
return fffilterctx(ctx)->execute(ctx, func, arg, ret, nb_jobs);
148158
}
149159

150160
enum FilterFormatsState {

0 commit comments

Comments
 (0)