[PATCH] lavfi/avfiltergraph: fix channel substitution score.
Only count the number of channels that are present on input. Fix a case where input FL+FR+BL gives a better score to 6.1 than quad because BL+BR→SL+SR counts as two remapped channels while BL→BL+BR counts as one preserved and one extra. Signed-off-by: Nicolas George <george@nsup.org> --- libavfilter/avfiltergraph.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) There are more issues in this score logic. For example stereo+BR→stereo+SL is accepted because of the BL+BR→SL+SR substitution, this is wrong. The obvious fix would be to change "(out_chlayout & cmp1)" into "(out_chlayout & cmp1) == cmp1", i.e. only accept a substitution if the target is entirely available in the output, but that would break the case stereo+BR→stereo+SL. I do not have time for a more complete fix right now, but I believe the present patch is valid and useful by itself. diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index a859ecb..7d358a4 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -923,13 +923,14 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter) for (k = 0; k < FF_ARRAY_ELEMS(ch_subst); k++) { uint64_t cmp0 = ch_subst[k][0]; uint64_t cmp1 = ch_subst[k][1]; + uint64_t mapped = in_chlayout & cmp0; if (( in_chlayout & cmp0) && (!(out_chlayout & cmp0)) && (out_chlayout & cmp1) && (!( in_chlayout & cmp1))) { in_chlayout &= ~cmp0; out_chlayout &= ~cmp1; /* add score for channel match, minus a deduction for having to do the substitution */ - score += 10 * av_get_channel_layout_nb_channels(cmp1) - 2; + score += 10 * av_get_channel_layout_nb_channels(mapped) - 2; } } -- 2.1.3
On Sun, Dec 07, 2014 at 01:31:59PM +0100, Nicolas George wrote:
Only count the number of channels that are present on input. Fix a case where input FL+FR+BL gives a better score to 6.1 than quad because BL+BR→SL+SR counts as two remapped channels while BL→BL+BR counts as one preserved and one extra.
Signed-off-by: Nicolas George <george@nsup.org> --- libavfilter/avfiltergraph.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
There are more issues in this score logic. For example stereo+BR→stereo+SL is accepted because of the BL+BR→SL+SR substitution, this is wrong.
The obvious fix would be to change "(out_chlayout & cmp1)" into "(out_chlayout & cmp1) == cmp1", i.e. only accept a substitution if the target is entirely available in the output, but that would break the case stereo+BR→stereo+SL.
I do not have time for a more complete fix right now, but I believe the present patch is valid and useful by itself.
LGTM though this is your code, you know it much better than i do [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Awnsering whenever a program halts or runs forever is On a turing machine, in general impossible (turings halting problem). On any real computer, always possible as a real computer has a finite number of states N, and will either halt in less than N cycles or never halt.
Le septidi 17 frimaire, an CCXXIII, Michael Niedermayer a écrit :
LGTM though this is your code, you know it much better than i do
Actually no, it is not my code, I just had to tweak it for unknown channel layouts. I thought it was yours or Stefano's, but I just checked: the score logic is Anton's and the channel substitution is from Justin, both after the fork. Well, I suppose that makes me the one who knows this part best on this side of the fork, but I will wait some more time before requesting a merge in case Stefano or Clément wants to have a look at it. Regards, -- Nicolas George
On Sun, Dec 07, 2014 at 02:15:24PM +0100, Nicolas George wrote:
Le septidi 17 frimaire, an CCXXIII, Michael Niedermayer a écrit :
LGTM though this is your code, you know it much better than i do
Actually no, it is not my code, I just had to tweak it for unknown channel layouts. I thought it was yours or Stefano's, but I just checked: the score logic is Anton's and the channel substitution is from Justin, both after the fork.
you are correct, i misremembered [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB When the tyrant has disposed of foreign enemies by conquest or treaty, and there is nothing more to fear from them, then he is always stirring up some war or other, in order that the people may require a leader. -- Plato
participants (2)
-
Michael Niedermayer -
Nicolas George