Allow iteration over filter options.
Showing the changes to libavfilter/avfilter.c (1 of 4 files). Show all
Unified · Split
| @@ -432,13 +432,48 @@ static const char *default_filter_name(void *filter_ctx) · 431 unmodified lines | ||
| 432 | 432 | return ctx->name ? ctx->name : ctx->filter->name; |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | +static void *filter_child_next(void *obj, void *prev) | |
| 436 | +{ | |
| 437 | + AVFilterContext *ctx = obj; | |
| 438 | + if (!prev && ctx->filter && ctx->filter->priv_class) | |
| 439 | + return ctx->priv; | |
| 440 | + return NULL; | |
| 441 | +} | |
| 442 | + | |
| 443 | +static const AVClass *filter_child_class_next(const AVClass *prev) | |
| 444 | +{ | |
| 445 | + AVFilter **filter_ptr = NULL; | |
| 446 | + | |
| 447 | + /* find the filter that corresponds to prev */ | |
| 448 | + while (prev && *(filter_ptr = av_filter_next(filter_ptr))) | |
| 449 | + if ((*filter_ptr)->priv_class == prev) | |
| 450 | + break; | |
| 451 | + | |
| 452 | + /* could not find filter corresponding to prev */ | |
| 453 | + if (prev && !(*filter_ptr)) | |
| 454 | + return NULL; | |
| 455 | + | |
| 456 | + /* find next filter with specific options */ | |
| 457 | + while (*(filter_ptr = av_filter_next(filter_ptr))) | |
| 458 | + if ((*filter_ptr)->priv_class) | |
| 459 | + return (*filter_ptr)->priv_class; | |
| 460 | + return NULL; | |
| 461 | +} | |
| 462 | + | |
| 435 | 463 | static const AVClass avfilter_class = { |
| 436 | 464 | .class_name = "AVFilter", |
| 437 | 465 | .item_name = default_filter_name, |
| 438 | 466 | .version = LIBAVUTIL_VERSION_INT, |
| 439 | 467 | .category = AV_CLASS_CATEGORY_FILTER, |
| 468 | + .child_next = filter_child_next, | |
| 469 | + .child_class_next = filter_child_class_next, | |
| 440 | 470 | }; |
| 441 | 471 | |
| 472 | +const AVClass *avfilter_get_class(void) | |
| 473 | +{ | |
| 474 | + return &avfilter_class; | |
| 475 | +} | |
| 476 | + | |
| 442 | 477 | int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name) |
| 443 | 478 | { |
| 444 | 479 | AVFilterContext *ret; |