To do this, allocate AVFilterGraphInternal jointly with AVFilterGraph and rename it to FFFilterGraph in the process (similarly to AVStream/FFStream). The AVFilterGraphInternal* will be removed on the next major version bump.
Unified · Split
| @@ -187,7 +187,7 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, · 186 unmodified lines | ||
| 187 | 187 | av_assert0(AV_PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1); |
| 188 | 188 | link->format = -1; |
| 189 | 189 | link->colorspace = AVCOL_SPC_UNSPECIFIED; |
| 190 | − ff_framequeue_init(&li->fifo, &src->graph->internal->frame_queues); | |
| 190 | + ff_framequeue_init(&li->fifo, &fffiltergraph(src->graph)->frame_queues); | |
| 191 | 191 | |
| 192 | 192 | return 0; |
| 193 | 193 | } |
| @@ -904,9 +904,9 @@ int avfilter_init_dict(AVFilterContext *ctx, AVDictionary **options) · 710 unmodified lines | ||
| 904 | 904 | |
| 905 | 905 | if (ctx->filter->flags & AVFILTER_FLAG_SLICE_THREADS && |
| 906 | 906 | ctx->thread_type & ctx->graph->thread_type & AVFILTER_THREAD_SLICE && |
| 907 | − ctx->graph->internal->thread_execute) { | |
| 907 | + fffiltergraph(ctx->graph)->thread_execute) { | |
| 908 | 908 | ctx->thread_type = AVFILTER_THREAD_SLICE; |
| 909 | − ctxi->execute = ctx->graph->internal->thread_execute; | |
| 909 | + ctxi->execute = fffiltergraph(ctx->graph)->thread_execute; | |
| 910 | 910 | } else { |
| 911 | 911 | ctx->thread_type = 0; |
| 912 | 912 | } |
| @@ -78,11 +78,20 @@ typedef struct AVFilterCommand { · 77 unmodified lines | ||
| 78 | 78 | struct AVFilterCommand *next; |
| 79 | 79 | } AVFilterCommand; |
| 80 | 80 | |
| 81 | −struct AVFilterGraphInternal { | |
| 81 | +typedef struct FFFilterGraph { | |
| 82 | + /** | |
| 83 | + * The public AVFilterGraph. See avfilter.h for it. | |
| 84 | + */ | |
| 85 | + AVFilterGraph p; | |
| 82 | 86 | void *thread; |
| 83 | 87 | avfilter_execute_func *thread_execute; |
| 84 | 88 | FFFrameQueueGlobal frame_queues; |
| 85 | −}; | |
| 89 | +} FFFilterGraph; | |
| 90 | + | |
| 91 | +static inline FFFilterGraph *fffiltergraph(AVFilterGraph *graph) | |
| 92 | +{ | |
| 93 | + return (FFFilterGraph*)graph; | |
| 94 | +} | |
| 86 | 95 | |
| 87 | 96 | /** |
| 88 | 97 | * Update the position of a link in the age heap. |
| @@ -119,8 +128,8 @@ int ff_filter_activate(AVFilterContext *filter); · 30 unmodified lines | ||
| 119 | 128 | int ff_filter_opt_parse(void *logctx, const AVClass *priv_class, |
| 120 | 129 | AVDictionary **options, const char *args); |
| 121 | 130 | |
| 122 | −int ff_graph_thread_init(AVFilterGraph *graph); | |
| 131 | +int ff_graph_thread_init(FFFilterGraph *graph); | |
| 123 | 132 | |
| 124 | −void ff_graph_thread_free(AVFilterGraph *graph); | |
| 133 | +void ff_graph_thread_free(FFFilterGraph *graph); | |
| 125 | 134 | |
| 126 | 135 | #endif /* AVFILTER_AVFILTER_INTERNAL_H */ |
| @@ -67,33 +67,30 @@ static const AVClass filtergraph_class = { · 66 unmodified lines | ||
| 67 | 67 | }; |
| 68 | 68 | |
| 69 | 69 | #if !HAVE_THREADS |
| 70 | −void ff_graph_thread_free(AVFilterGraph *graph) | |
| 70 | +void ff_graph_thread_free(FFFilterGraph *graph) | |
| 71 | 71 | { |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | −int ff_graph_thread_init(AVFilterGraph *graph) | |
| 74 | +int ff_graph_thread_init(FFFilterGraph *graph) | |
| 75 | 75 | { |
| 76 | − graph->thread_type = 0; | |
| 77 | − graph->nb_threads = 1; | |
| 76 | + graph->p.thread_type = 0; | |
| 77 | + graph->p.nb_threads = 1; | |
| 78 | 78 | return 0; |
| 79 | 79 | } |
| 80 | 80 | #endif |
| 81 | 81 | |
| 82 | 82 | AVFilterGraph *avfilter_graph_alloc(void) |
| 83 | 83 | { |
| 84 | − AVFilterGraph *ret = av_mallocz(sizeof(*ret)); | |
| 85 | − if (!ret) | |
| 86 | − return NULL; | |
| 84 | + FFFilterGraph *graph = av_mallocz(sizeof(*graph)); | |
| 85 | + AVFilterGraph *ret; | |
| 87 | 86 | |
| 88 | − ret->internal = av_mallocz(sizeof(*ret->internal)); | |
| 89 | − if (!ret->internal) { | |
| 90 | − av_freep(&ret); | |
| 87 | + if (!graph) | |
| 91 | 88 | return NULL; |
| 92 | − } | |
| 93 | 89 | |
| 90 | + ret = &graph->p; | |
| 94 | 91 | ret->av_class = &filtergraph_class; |
| 95 | 92 | av_opt_set_defaults(ret); |
| 96 | − ff_framequeue_global_init(&ret->internal->frame_queues); | |
| 93 | + ff_framequeue_global_init(&graph->frame_queues); | |
| 97 | 94 | |
| 98 | 95 | return ret; |
| 99 | 96 | } |
| @@ -119,6 +116,7 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, AVFilterContext *filter · 19 unmodified lines | ||
| 119 | 116 | void avfilter_graph_free(AVFilterGraph **graphp) |
| 120 | 117 | { |
| 121 | 118 | AVFilterGraph *graph = *graphp; |
| 119 | + FFFilterGraph *graphi = fffiltergraph(graph); | |
| 122 | 120 | |
| 123 | 121 | if (!graph) |
| 124 | 122 | return; |
| @@ -126,14 +124,13 @@ void avfilter_graph_free(AVFilterGraph **graphp) · 1 unmodified line | ||
| 126 | 124 | while (graph->nb_filters) |
| 127 | 125 | avfilter_free(graph->filters[0]); |
| 128 | 126 | |
| 129 | − ff_graph_thread_free(graph); | |
| 127 | + ff_graph_thread_free(graphi); | |
| 130 | 128 | |
| 131 | 129 | av_freep(&graph->sink_links); |
| 132 | 130 | |
| 133 | 131 | av_opt_free(graph); |
| 134 | 132 | |
| 135 | 133 | av_freep(&graph->filters); |
| 136 | − av_freep(&graph->internal); | |
| 137 | 134 | av_freep(graphp); |
| 138 | 135 | } |
| 139 | 136 | |
| @@ -169,12 +166,13 @@ AVFilterContext *avfilter_graph_alloc_filter(AVFilterGraph *graph, · 29 unmodified lines | ||
| 169 | 166 | const char *name) |
| 170 | 167 | { |
| 171 | 168 | AVFilterContext **filters, *s; |
| 169 | + FFFilterGraph *graphi = fffiltergraph(graph); | |
| 172 | 170 | |
| 173 | − if (graph->thread_type && !graph->internal->thread_execute) { | |
| 171 | + if (graph->thread_type && !graphi->thread_execute) { | |
| 174 | 172 | if (graph->execute) { |
| 175 | − graph->internal->thread_execute = graph->execute; | |
| 173 | + graphi->thread_execute = graph->execute; | |
| 176 | 174 | } else { |
| 177 | − int ret = ff_graph_thread_init(graph); | |
| 175 | + int ret = ff_graph_thread_init(graphi); | |
| 178 | 176 | if (ret < 0) { |
| 179 | 177 | av_log(graph, AV_LOG_ERROR, "Error initializing threading: %s.\n", av_err2str(ret)); |
| 180 | 178 | return NULL; |
| @@ -58,7 +58,7 @@ static void slice_thread_uninit(ThreadContext *c) · 57 unmodified lines | ||
| 58 | 58 | static int thread_execute(AVFilterContext *ctx, avfilter_action_func *func, |
| 59 | 59 | void *arg, int *ret, int nb_jobs) |
| 60 | 60 | { |
| 61 | − ThreadContext *c = ctx->graph->internal->thread; | |
| 61 | + ThreadContext *c = fffiltergraph(ctx->graph)->thread; | |
| 62 | 62 | |
| 63 | 63 | if (nb_jobs <= 0) |
| 64 | 64 | return 0; |
| @@ -79,8 +79,9 @@ static int thread_init_internal(ThreadContext *c, int nb_threads) · 14 unmodified lines | ||
| 79 | 79 | return FFMAX(nb_threads, 1); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | −int ff_graph_thread_init(AVFilterGraph *graph) | |
| 82 | +int ff_graph_thread_init(FFFilterGraph *graphi) | |
| 83 | 83 | { |
| 84 | + AVFilterGraph *graph = &graphi->p; | |
| 84 | 85 | int ret; |
| 85 | 86 | |
| 86 | 87 | if (graph->nb_threads == 1) { |
| @@ -88,27 +89,27 @@ int ff_graph_thread_init(AVFilterGraph *graph) · 1 unmodified line | ||
| 88 | 89 | return 0; |
| 89 | 90 | } |
| 90 | 91 | |
| 91 | − graph->internal->thread = av_mallocz(sizeof(ThreadContext)); | |
| 92 | − if (!graph->internal->thread) | |
| 92 | + graphi->thread = av_mallocz(sizeof(ThreadContext)); | |
| 93 | + if (!graphi->thread) | |
| 93 | 94 | return AVERROR(ENOMEM); |
| 94 | 95 | |
| 95 | − ret = thread_init_internal(graph->internal->thread, graph->nb_threads); | |
| 96 | + ret = thread_init_internal(graphi->thread, graph->nb_threads); | |
| 96 | 97 | if (ret <= 1) { |
| 97 | − av_freep(&graph->internal->thread); | |
| 98 | + av_freep(&graphi->thread); | |
| 98 | 99 | graph->thread_type = 0; |
| 99 | 100 | graph->nb_threads = 1; |
| 100 | 101 | return (ret < 0) ? ret : 0; |
| 101 | 102 | } |
| 102 | 103 | graph->nb_threads = ret; |
| 103 | 104 | |
| 104 | − graph->internal->thread_execute = thread_execute; | |
| 105 | + graphi->thread_execute = thread_execute; | |
| 105 | 106 | |
| 106 | 107 | return 0; |
| 107 | 108 | } |
| 108 | 109 | |
| 109 | −void ff_graph_thread_free(AVFilterGraph *graph) | |
| 110 | +void ff_graph_thread_free(FFFilterGraph *graph) | |
| 110 | 111 | { |
| 111 | − if (graph->internal->thread) | |
| 112 | − slice_thread_uninit(graph->internal->thread); | |
| 113 | − av_freep(&graph->internal->thread); | |
| 112 | + if (graph->thread) | |
| 113 | + slice_thread_uninit(graph->thread); | |
| 114 | + av_freep(&graph->thread); | |
| 114 | 115 | } |