summaryrefslogtreecommitdiff
path: root/libavfilter/avfiltergraph.c
Commit message (Collapse)AuthorAge
* avfilter/avfiltergraph: Fix use-after-free when inserting auto-converterAndreas Rheinhardt2021-10-08
| | | | | | | | | | | | | | | | | | | | When inserting an auto-resampler, it may be that the configuration of the filters that the auto-resampler is supposed to connect is already partially merged, i.e. converter->inputs[0].incfg.foo and converter->outputs[0].outcfg.foo (where foo is one of formats, samplerates, channel_layouts) can coincide. Therefore merging the converter filter's input link might modify the outcfg of the converter' outlink. Yet the current code in avfiltergraph.c used pointers from before merging the inlink for merging the outlink, leading to a use-after-free in command lines like: $ ffmpeg -f lavfi -i anullsrc=cl=stereo -lavfi channelsplit,axcorrelate -f null - Fix this by not using outdated values when merging the outlink. This is a regression since 85a6404d7e6c759ddf71d6374812d7ff719728ec. Found-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter: Replace query_formats callback with union of list and callbackAndreas Rheinhardt2021-10-05
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If one looks at the many query_formats callbacks in existence, one will immediately recognize that there is one type of default callback for video and a slightly different default callback for audio: It is "return ff_set_common_formats_from_list(ctx, pix_fmts);" for video with a filter-specific pix_fmts list. For audio, it is the same with a filter-specific sample_fmts list together with ff_set_common_all_samplerates() and ff_set_common_all_channel_counts(). This commit allows to remove the boilerplate query_formats callbacks by replacing said callback with a union consisting the old callback and pointers for pixel and sample format arrays. For the not uncommon case in which these lists only contain a single entry (besides the sentinel) enum AVPixelFormat and enum AVSampleFormat fields are also added to the union to store them directly in the AVFilter, thereby avoiding a relocation. The state of said union will be contained in a new, dedicated AVFilter field (the nb_inputs and nb_outputs fields have been shrunk to uint8_t in order to create a hole for this new field; this is no problem, as the maximum of all the nb_inputs is four; for nb_outputs it is only two). The state's default value coincides with the earlier default of query_formats being unset, namely that the filter accepts all formats (and also sample rates and channel counts/layouts for audio) provided that these properties agree coincide for all inputs and outputs. By using different union members for audio and video filters the type-unsafety of using the same functions for audio and video lists will furthermore be more confined to formats.c than before. When the new fields are used, they will also avoid allocations: Currently something nearly equivalent to ff_default_query_formats() is called after every successful call to a query_formats callback; yet in the common case that the newly allocated AVFilterFormats are not used at all (namely if there are no free links) these newly allocated AVFilterFormats are freed again without ever being used. Filters no longer using the callback will not exhibit this any more. Reviewed-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/avfiltergraph: Remove always-true checkAndreas Rheinhardt2021-10-02
| | | | | | Always true since bc1a985ba030e9861d24965d42792850b43a43ea. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/avfiltergraph: Free AVFilterGraph options properlyAndreas Rheinhardt2021-10-02
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/avfiltergraph: Simplify adding filter to graphAndreas Rheinhardt2021-10-02
| | | | | | | | | | By reallocating the array of pointers to the AVFilterContexts before allocating the new AVFilterContext one can avoid freeing the new AVFilterContext in case the array could not be reallocated. Also switch to av_realloc_array() while just at it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/avfiltergraph: add an "auto" constant to the threads optionJames Almer2021-09-04
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avfilter/avfiltergraph: Remove dead checksAndreas Rheinhardt2021-08-20
| | | | | | | | | These checks emit warnings in case the channel layouts lists are inconsistent; yet since 69f5f6ea375950b4845b241ee27054bfc8f00343 a function that is called earlier errors out if they are inconsistent. Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/avfiltergraph: Don't use AVClass * for logcontextAndreas Rheinhardt2021-08-20
| | | | | | | Forgotten in 57fa314090ab006808911fd790053b534749aa53. Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* lavfi/formats: rename AVFilterNegotiation.nb to nb_mergersNicolas George2021-08-20
|
* lavfi/formats: describe conversion in negotiation structure.Nicolas George2021-08-14
|
* lavfi/formats: put merge functions in structures.Nicolas George2021-08-14
| | | | | It makes the code clearer and will allow adding new stages of negotiation easier.
* avfilter/formats: Factor common function combinations outAndreas Rheinhardt2021-08-13
| | | | | | | | | | | Several combinations of functions happen quite often in query_format functions; e.g. ff_set_common_formats(ctx, ff_make_format_list(sample_fmts)) is very common. This commit therefore adds functions that are equivalent to commonly used function combinations in order to reduce code duplication. Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avfilter/avfiltergraph: Remove NULL checks after dereferencesMichael Niedermayer2021-05-19
| | | | | | Fixes: CID1398579 Dereference before null check Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avfilter: Remove deprecated resample_lavr_optsAndreas Rheinhardt2021-04-27
| | | | | | | Deprecated in 3796fb2692f87d0000fc0aa4572ac025a6469c2b. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* lavfi: check the validity of formats lists.Nicolas George2020-09-08
| | | | | | | | | | | Part of the code expects valid lists, in particular no duplicates. These tests allow to catch bugs in filters (unlikely but possible) and to give a clear message when the error comes from the user ((a)formats) or the application (buffersink). If we decide to switch to a more efficient merging algorithm, possibly sorting the lists, these functions will be the preferred place for pre-processing, and can be renamed accordingly.
* lavfi: regroup formats lists in a single structure.Nicolas George2020-09-08
| | | | | | | | | | | | | | | It will allow to refernce it as a whole without clunky macros. Most of the changes have been automatically made with sed: sed -i ' s/-> *in_formats/->incfg.formats/g; s/-> *out_formats/->outcfg.formats/g; s/-> *in_channel_layouts/->incfg.channel_layouts/g; s/-> *out_channel_layouts/->outcfg.channel_layouts/g; s/-> *in_samplerates/->incfg.samplerates/g; s/-> *out_samplerates/->outcfg.samplerates/g; ' src/libavfilter/*(.)
* avfilter/avfiltergraph: Remove unused macro parameterAndreas Rheinhardt2020-08-24
| | | | | Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avfilter/formats: Factor checking for mergeability out of ff_merge_*Andreas Rheinhardt2020-08-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The callers of the ff_merge_*() functions fall into two categories with quite different needs: One caller is can_merge_formats() which only wants to test for mergeability without it merging anything. In order to do so, it duplicates the lists it intends to test and resets their owners so that they are not modified by ff_merge_*(). It also means that it needs to receive the merged list (and not only an int containing whether the lists are mergeable) to properly free it. The other callers want the lists to be actually merged. But given the fact that ff_merge_*() automatically updates the owners of the lists, they only want the information whether the merge succeeded or not; they don't want a link to the new list. Therefore this commit splits these functions in two: ff_merge_*() for the latter callers and ff_can_merge_*() for the former. ff_merge_*() doesn't need to return a pointer to the combined list at all and hence these functions have been modified to return an int, which allows to distinguish between incompability and memory allocation failures. ff_can_merge_*() meanwhile doesn't modify its arguments at all obviating the need for copies. This in turn implies that there is no reason to return a pointer to the new list, as nothing needs to be freed. These functions therefore return an int as well. This allowed to completely remove can_merge_formats() in avfiltergraph.c. Notice that no ff_can_merge_channel_layouts() has been created, because there is currently no caller for this. It could be added if needed. Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* lavfi: remove needs_fifo.Nicolas George2020-08-20
|
* Revert "lavfi/avfiltergraph: add check before free the format"Andreas Rheinhardt2020-08-12
| | | | | | | | | | | | This reverts commit f156f4ab2317f22bfef33c7eaead0d5d5f162903. The checks added by said commit are nonsense because they did not help in case ff_merge_samplerates() or ff_merge_formats() returned NULL while freeing one of its arguments: Said freeing does not change the local variables of can_merge_formats(). Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* lavfi/avfiltergraph: add check before free the formatJun Zhao2019-08-20
| | | | | | | | ff_merge_samplerates will be deallocate a or b in some case, so add a check before free the format. Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
* Use AV_PIX_FMT_FLAG_ALPHA for detecting transparency where nb_components was ↵Marton Balint2018-04-30
| | | | | | | | | | used Temporarily keep the old method for ffmpeg_filters.c choose_pix_fmt and avfiltergraph.c pick_format() until a paletted pixel format without alpha is introduced. Signed-off-by: Marton Balint <cus@passwd.hu>
* avfilter/avfiltergraph: remove ugly dead codePaul B Mahol2017-12-11
| | | | | | Remnant of old merge. Signed-off-by: Paul B Mahol <onemda@gmail.com>
* avfilter/avfiltergraph: pass correct audio/video flagsPaul B Mahol2017-11-20
| | | | | | Previously video flags where set for audio option. Signed-off-by: Paul B Mahol <onemda@gmail.com>
* lavfi: check links properties after configuring them.Nicolas George2017-11-02
| | | | | | | | For now, check the image size. Inspired by a patch from Paul B Mahol. Invalid sizes would be detected later by allocation failures, detecting problems earlier is cleaner.
* Merge commit '96a47364d1cf346a5d0437e054b1b10d44d8d969'James Almer2017-10-21
|\ | | | | | | | | | | | | * commit '96a47364d1cf346a5d0437e054b1b10d44d8d969': lavfi: Drop deprecated non-const filter retrieval Merged-by: James Almer <jamrial@gmail.com>
| * lavfi: Drop deprecated non-const filter retrievalVittorio Giovara2017-03-23
| | | | | | | | Deprecated in 10/2013.
* | Merge commit 'c5c7cfd5e80d4c36568c01cc40abfde341657ad9'James Almer2017-10-21
|\| | | | | | | | | | | | | * commit 'c5c7cfd5e80d4c36568c01cc40abfde341657ad9': lavfi: Drop deprecated functions to open a filter or a filterchain Merged-by: James Almer <jamrial@gmail.com>
| * lavfi: Drop deprecated functions to open a filter or a filterchainVittorio Giovara2017-03-23
| | | | | | | | Deprecated in 03/2013.
| * avfiltergraph: check the query_formats() return valueAnton Khirnov2016-05-23
| |
* | lavfi: print the error message when threading init fails.Nicolas George2017-06-19
| |
* | lavfi/avfiltergraph: only return EOF in avfilter_graph_request_oldest if all ↵Marton Balint2017-05-07
| | | | | | | | | | | | | | | | | | | | | | | | | | sinks EOFed Fixes a regression introduced in 32c59a115d3cc757676b5384a5ea44b5a7a7b872, becoming effective in 912969a33e313c57c906e87a7e2367b78a2160f4. Fixes trimmed output of ffmpeg -f lavfi -i "sine=d=0.01" -f lavfi -i "sine=d=1" -filter_complex "[0:a]anull[a1];[1:a]anull[a2]" -map "[a1]" -f null none -map "[a2]" -f framecrc - Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Marton Balint <cus@passwd.hu>
* | avfilter/avfiltergraph: Check for allocation failure in ↵Michael Niedermayer2017-03-31
| | | | | | | | | | | | | | | | | | avfilter_graph_queue_command() Fixes: CID1396538 Reviewed-by: Paul B Mahol <onemda@gmail.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | lavfi: deprecate AVFilterGraph->resample_lavr_optsRostislav Pehlivanov2017-03-18
| | | | | | | | | | | | | | Not used by anything at all since we don't auto insert lavr filters. Reviewed-by: wm4 <nfxjfg@googlemail.com> Signed-off-by: Rostislav Pehlivanov <atomnuker@gmail.com>
* | avfilter/avfiltergraph: Add assert to write down in machine readable form ↵Michael Niedermayer2017-01-21
| | | | | | | | | | | | | | | | what is assumed about sample rates in swap_samplerates_on_filter() Fixes CID1397292 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | lavfi: do not call ff_filter_frame() with activate.Nicolas George2017-01-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | avfilter_graph_request_oldest() does work that should be done by either the filter or the application. The principle of this function, calling ff_request_frame() from outside the filter was always shaky. This version is less elegant since it requires making special cases for each filter, but it is more robust since it no longer calls ff_request_frame() directly without notifying the filter. Eventually, avfilter_graph_request_oldest() will be deprecated for a function to just run the graph.
* | lavfi, ffmpeg: simplify filter names.Nicolas George2017-01-12
| | | | | | | | | | | | The names are only used for technical output and debugging. Make them similar to C identifiers for easier quick reading of debug dumps.
* | lavfi: avfilter_graph_request_oldest: request a frame again before returning.Nicolas George2016-12-23
| | | | | | | | | | | | | | | | | | With min_samples, if a frame arrives but is too small, it clears frame_wanted_out. In most cases, the destination filter would be activated again later because of frame_wanted_out on its own outputs, but not sinks. avfilter_graph_request_oldest() is doing the work of the sink itself, and is therefore allowed to use frame_blocked_in.
* | lavfi: make filter_frame non-recursive.Nicolas George2016-12-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A lot of changes happen at the same time: - Add a framequeue fifo to AVFilterLink. - split AVFilterLink.status into status_in and status_out: requires changes to the few filters and programs that use it directly (f_interleave, split, filtfmts). - Add a field ready to AVFilterContext, marking when the filter is ready and its activation priority. - Add flags to mark blocked links. - Change ff_filter_frame() to enqueue the frame. - Change all filtering functions to update the ready field and the blocked flags. - Update ff_filter_graph_run_once() to use the ready field. - buffersrc: always push the frame immediately.
* | avfiltergraph.c: restore disabling of auto conversionsBurt P2016-08-10
| | | | | | | | | | | | | | | | Restore a check added in 440af105f2306d3c7b3b3f4d7530bab910d49cb9 but lost sometime after. avfilter_graph_set_auto_convert() will have an effect once again. Signed-off-by: Burt P <pburt0@gmail.com>
* | avfilter/avfiltergraph: Clear graph pointers in ff_filter_graph_remove_filter()Michael Niedermayer2016-05-27
| | | | | | | | | | | | | | When a filter is no longer part of a graph, its pointers should be cleared so no stale pointers remain. Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | lavfi: make request_frame() non-recursive.Nicolas George2015-12-22
| | | | | | | | | | | | | | Instead of calling the input filter request_frame() method, ff_request_frame() now marks the link and returns immediately. buffersink is changed to activate the marked filters until a frame is obtained.
* | lavfi: rename link.current_pts to current_pts_us.Nicolas George2015-12-22
| | | | | | | | | | | | | | This field is used for fast comparison between link ages, it is in AV_TIME_BASE units, in other words microseconds, µs =~ us. Renaming it allows a second field in link time base units.
* | avfilter/avfiltergraph: fix -Wunused-result warningsGanesh Ajjanagadde2015-10-16
| | | | | | | | | | | | | | | | | | | | | | | | Commit bf0d2d6030c239f91e0368a20fb2dc0705bfec99 introduced av_warn_unused_result to avfilter/formats, whose associated warnings were mostly fixed in 6aaac24d72a7da631173209841a3944fcb4a3309. This fixes the issues in avfilter/avfiltergraph. Tested with FATE. Reviewed-by: Ronald S. Bultje <rsbultje@gmail.com> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* | avfilter/all: propagate errors of functions from avfilter/formatsGanesh Ajjanagadde2015-10-14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many of the functions from avfilter/formats can return errors, usually AVERROR(ENOMEM). This propagates the return values. All of these were found by using av_warn_unused_result, demonstrating its utility. Tested with FATE. I am least sure of the changes to avfilter/filtergraph, since I don't know what/how reduce_format is intended to behave and how it should react to errors. Fixes: CID 1325680, 1325679, 1325678. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Previous version Reviewed-by: Nicolas George <george@nsup.org> Previous version Reviewed-by: Clément Bœsch <u@pkh.me> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde@gmail.com>
* | Merge commit 'e65e4cbbda03ca3c9087f069c9867d518415fca1'Hendrik Leppkes2015-09-05
|\| | | | | | | | | | | | | * commit 'e65e4cbbda03ca3c9087f069c9867d518415fca1': lavfi: Drop deprecated *_count suffixed variables Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
| * lavfi: Drop deprecated *_count suffixed variablesVittorio Giovara2015-08-28
| | | | | | | | Deprecated in 06/2012.
* | avfilter/avfiltergraph: Implement and use find_best_sample_fmt_of_2()Michael Niedermayer2015-08-16
| | | | | | | | | | | | | | | | Similar to the pixel format code Fixes Ticket3847 Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* | avfilter/avfiltergraph: Rename ff_avfilter_graph_config_pointers to ↵Michael Niedermayer2015-05-18
| | | | | | | | | | | | | | | | graph_config_pointers. The function is static and only used once in the file its defined in. Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
* | avfilter/avfiltergraph: assert that the heap_bubble index is validMichael Niedermayer2015-02-18
| | | | | | | | | | | | This might help coverity Signed-off-by: Michael Niedermayer <michaelni@gmx.at>