]> git.sesse.net Git - ffmpeg/commit
avfilter/formats: Factor checking for mergeability out of ff_merge_*
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Fri, 14 Aug 2020 14:47:01 +0000 (16:47 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 20 Aug 2020 20:01:45 +0000 (22:01 +0200)
commit06754f7bbf341062581accc27b5cce353e99fd82
tree5b2147a75ae5e37f3a3d2ebddf105b04343ddcf8
parent363f93460fbce0a2ea073f7f64edc597405982a1
avfilter/formats: Factor checking for mergeability out of ff_merge_*

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>
libavfilter/avfiltergraph.c
libavfilter/formats.c
libavfilter/formats.h