From b7144ad8bfbdf686a0fca4b639a6564c397c030f Mon Sep 17 00:00:00 2001 From: Kevin Mitchell Date: Thu, 10 Sep 2015 20:52:04 -0700 Subject: audio/format: revise af_format_conversion_score * (de)planarize -1 * pad 1 byte -8 * truncate 1 byte -1024 * float -> int 1048576 * (8 - dst_bytes) * int -> float -512 Now the score is negative if and only if the conversion is lossy (e.g. previously s24 -> float was given a negative (lossy) score), However, int->float is still considered bad (s16->float is worse than than s16->s32). This penalizes any loss of precision more than performance / bandwidth hits. For example, previously s24->s16p was considered equal to s24->u8. Finally, we penalize padding more than (de)planarizing as this will increase the output size for example with ao_lavc. --- audio/format.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'audio') diff --git a/audio/format.c b/audio/format.c index 444d4b2b74..100a0f3225 100644 --- a/audio/format.c +++ b/audio/format.c @@ -190,20 +190,25 @@ static int af_format_conversion_score(int dst_format, int src_format) if (af_fmt_is_float(dst_format) != af_fmt_is_float(src_format)) { int dst_bytes = af_fmt_to_bytes(dst_format); if (af_fmt_is_float(dst_format)) { - // For int->float, always prefer 32 bit float. - score -= dst_bytes == 4 ? 0 : 1; + // For int->float, consider a lower bound on the precision difference. + int bytes = (dst_bytes == 4 ? 3 : 6) - af_fmt_to_bytes(src_format); + if (bytes >= 0) { + score -= 8 * bytes; // excess precision + } else { + score += 1024 * (bytes - 1); // precision is lost (i.e. s32 -> float) + } } else { - // For float->int, always prefer highest bit depth int - score -= 8 - dst_bytes; + // float->int is the worst case. Penalize heavily and + // prefer highest bit depth int. + score -= 1048576 * (8 - dst_bytes); } - // Has to convert float<->int - Consider this the worst case. - score -= 2048; + score -= 512; // penalty for any float <-> int conversion } else { int bytes = af_fmt_to_bytes(dst_format) - af_fmt_to_bytes(src_format); if (bytes > 0) { - score -= 1 + bytes; // has to add padding + score -= 8 * bytes; // has to add padding } else if (bytes < 0) { - score -= 1024 - bytes; // has to reduce bit depth + score += 1024 * (bytes - 1); // has to reduce bit depth } } return score; -- cgit v1.2.3