From b6ad73e1fa57a47907d1e84067116025dadf0f22 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Mon, 1 Jan 2024 23:13:15 +0100 Subject: [PATCH] [xcode] Go back to wav as default format for RSP/DAAP transcoding But add "prefer_format" config option for mp3, incl. a check for an encoder. The config option is currently not added to owntone.conf.in, so is undocumented until decided what to do about possible alac support. --- src/conffile.c | 1 + src/transcode.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/conffile.c b/src/conffile.c index ef9e528a..bfbcfd72 100644 --- a/src/conffile.c +++ b/src/conffile.c @@ -111,6 +111,7 @@ static cfg_opt_t sec_library[] = CFG_BOOL("itunes_smartpl", cfg_false, CFGF_NONE), CFG_STR_LIST("no_decode", NULL, CFGF_NONE), CFG_STR_LIST("force_decode", NULL, CFGF_NONE), + CFG_STR("prefer_format", NULL, CFGF_NONE), CFG_BOOL("pipe_autostart", cfg_true, CFGF_NONE), CFG_INT("pipe_sample_rate", 44100, CFGF_NONE), CFG_INT("pipe_bits_per_sample", 16, CFGF_NONE), diff --git a/src/transcode.c b/src/transcode.c index 2ac4d09e..c0e51133 100644 --- a/src/transcode.c +++ b/src/transcode.c @@ -1804,9 +1804,12 @@ transcode_decode_setup_raw(enum transcode_profile profile, struct media_quality enum transcode_profile transcode_needed(const char *user_agent, const char *client_codecs, char *file_codectype) { - char *codectype; + const char *codectype; + const char *prefer_format; cfg_t *lib; bool force_xcode; + bool supports_mpeg; + bool supports_wav; int count; int i; @@ -1862,10 +1865,25 @@ transcode_needed(const char *user_agent, const char *client_codecs, char *file_c if (!force_xcode && strstr(client_codecs, file_codectype)) return XCODE_NONE; - else if (strstr(client_codecs, "mpeg")) - return XCODE_MP3; - else if (strstr(client_codecs, "wav")) + + supports_mpeg = strstr(client_codecs, "mpeg") && avcodec_find_encoder(AV_CODEC_ID_MP3); + supports_wav = strstr(client_codecs, "wav"); + + prefer_format = cfg_getstr(lib, "prefer_format"); + if (prefer_format) + { + if (strcmp(prefer_format, "wav") == 0 && supports_wav) + return XCODE_WAV; + else if (strcmp(prefer_format, "mpeg") == 0 && supports_mpeg) + return XCODE_MP3; + } + + // This order determines the default if user didn't configure a preference. + // The lossless formats are given highest preference. + if (supports_wav) return XCODE_WAV; + else if (supports_mpeg) + return XCODE_MP3; else return XCODE_UNKNOWN; }