From c866583e1e31e6f648f2346fb9c5394d8d080587 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 23 Mar 2013 13:05:32 +0100 Subject: af: use af_lavrresample for format conversions, if possible Refactor to remove the duplicated format filter insertion code. Allow other format converting filters to be inserted on format mismatches. af_info.test_conversion checks whether conversion between two formats would work with the given filter; do this to avoid having to insert multiple conversion filters at once and such things. (Although this isn't ideal: what if we want to avoid af_format for some conversions? What if we want to split af_format in endian-swapping filters etc.?) Prefer af_lavrresample for conversions that it supports natively, otherwise let af_format handle the full conversion. --- audio/filter/af_format.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'audio/filter/af_format.c') diff --git a/audio/filter/af_format.c b/audio/filter/af_format.c index 37d29c1f80..720cff0bf0 100644 --- a/audio/filter/af_format.c +++ b/audio/filter/af_format.c @@ -75,6 +75,14 @@ static int check_format(int format) return AF_ERROR; } +static bool test_conversion(int src_format, int dst_format) +{ + // This is the fallback conversion filter, so this filter is always + // inserted on format mismatches if no other filter can handle it. + // Initializing the filter might still fail. + return true; +} + // Initialization and runtime control static int control(struct af_instance* af, int cmd, void* arg) { @@ -147,7 +155,7 @@ static int control(struct af_instance* af, int cmd, void* arg) mp_msg(MSGT_AFILTER, MSGL_ERR, "[format] %s is not a valid format\n", (char *)arg); return AF_ERROR; } - if(AF_OK != af->control(af,AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)) + if(AF_OK != af->control(af, AF_CONTROL_FORMAT_FMT | AF_CONTROL_SET,&format)) return AF_ERROR; return AF_OK; } @@ -301,7 +309,8 @@ struct af_info af_info_format = { "Anders", "", AF_FLAGS_REENTRANT, - af_open + af_open, + .test_conversion = test_conversion, }; static inline uint32_t load24bit(void* data, int pos) { -- cgit v1.2.3