summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorKevin Mitchell <kevmitch@gmail.com>2015-09-10 20:52:04 -0700
committerKevin Mitchell <kevmitch@gmail.com>2015-09-10 23:58:09 -0700
commitb7144ad8bfbdf686a0fca4b639a6564c397c030f (patch)
tree5761546ff7ede274a9547e7b48a496859889aaaa /audio
parent269f271b7373091790be61fe38e37eb2c8cb98f8 (diff)
downloadmpv-b7144ad8bfbdf686a0fca4b639a6564c397c030f.tar.bz2
mpv-b7144ad8bfbdf686a0fca4b639a6564c397c030f.tar.xz
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.
Diffstat (limited to 'audio')
-rw-r--r--audio/format.c21
1 files changed, 13 insertions, 8 deletions
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;