diff --git a/src/audio/playback/mixer.cpp b/src/audio/playback/mixer.cpp index dcb3a1aee..f37daa018 100644 --- a/src/audio/playback/mixer.cpp +++ b/src/audio/playback/mixer.cpp @@ -240,31 +240,43 @@ class logarithmic_mix_algo : public generic_mix_algo { }; struct state_audio_mixer final { - state_audio_mixer(const char *cfg) { - if (cfg) { - shared_ptr tmp(strdup(cfg), free); - char *item, *save_ptr; - char *copy = tmp.get(); - - while ((item = strtok_r(copy, ":", &save_ptr))) { - if (strncmp(item, "codec=", strlen("codec=")) == 0) { - audio_codec = item + strlen("codec="); - } else if (strncmp(item, "algo=", strlen("algo=")) == 0) { - string algo = item + strlen("algo="); - if (algo == "linear") { - mixing_algorithm = decltype(mixing_algorithm)(new linear_mix_algo()); - } else if (algo == "logarithmic") { - mixing_algorithm = decltype(mixing_algorithm)(new logarithmic_mix_algo()); - } else { - LOG(LOG_LEVEL_ERROR) << "Unknown mixing algorithm: " << algo << "\n"; - throw 1; - } + state_audio_mixer(const struct audio_playback_opts *opts) { + char copy[STR_LEN]; + snprintf_ch(copy, "%s", opts->cfg); + char *tmp = copy; + char *item = nullptr; + char *save_ptr = nullptr; + + while ((item = strtok_r(tmp, ":", &save_ptr)) != nullptr) { + if (strncmp(item, "codec=", strlen("codec=")) == 0) { + audio_codec = item + strlen("codec="); + } else if (strncmp(item, "algo=", strlen("algo=")) == + 0) { + string algo = item + strlen("algo="); + if (algo == "linear") { + mixing_algorithm = + decltype(mixing_algorithm)( + new linear_mix_algo< + sample_type_source, + sample_type_mixed>()); + } else if (algo == "logarithmic") { + mixing_algorithm = + decltype(mixing_algorithm)( + new logarithmic_mix_algo< + sample_type_source, + sample_type_mixed>()); } else { - LOG(LOG_LEVEL_ERROR) << "Unknown option: " << item << "\n"; + LOG(LOG_LEVEL_ERROR) + << "Unknown mixing algorithm: " + << algo << "\n"; throw 1; } - copy = nullptr; + } else { + LOG(LOG_LEVEL_ERROR) + << "Unknown option: " << item << "\n"; + throw 1; } + tmp = nullptr; } struct audio_codec_state *audio_coder = @@ -422,7 +434,7 @@ audio_play_mixer_init(const struct audio_playback_opts *opts) return INIT_NOERR; } try { - return new state_audio_mixer{opts->cfg}; + return new state_audio_mixer(opts); } catch (...) { return nullptr; }