@@ -240,32 +240,50 @@ class logarithmic_mix_algo : public generic_mix_algo<source_t, intermediate_t> {
240
240
};
241
241
242
242
struct state_audio_mixer final {
243
- state_audio_mixer (const char *cfg) {
244
- if (cfg) {
245
- shared_ptr<char > tmp (strdup (cfg), free);
246
- char *item, *save_ptr;
247
- char *copy = tmp.get ();
248
-
249
- while ((item = strtok_r (copy, " :" , &save_ptr))) {
250
- if (strncmp (item, " codec=" , strlen (" codec=" )) == 0 ) {
251
- audio_codec = item + strlen (" codec=" );
252
- } else if (strncmp (item, " algo=" , strlen (" algo=" )) == 0 ) {
253
- string algo = item + strlen (" algo=" );
254
- if (algo == " linear" ) {
255
- mixing_algorithm = decltype (mixing_algorithm)(new linear_mix_algo<sample_type_source, sample_type_mixed>());
256
- } else if (algo == " logarithmic" ) {
257
- mixing_algorithm = decltype (mixing_algorithm)(new logarithmic_mix_algo<sample_type_source, sample_type_mixed>());
258
- } else {
259
- LOG (LOG_LEVEL_ERROR) << " Unknown mixing algorithm: " << algo << " \n " ;
260
- throw 1 ;
261
- }
243
+ private:
244
+ void parse_opts (const struct audio_playback_opts *opts) noexcept (false )
245
+ {
246
+ char copy[STR_LEN];
247
+ snprintf_ch (copy, " %s" , opts->cfg );
248
+ char *tmp = copy;
249
+ char *item = nullptr ;
250
+ char *save_ptr = nullptr ;
251
+
252
+ while ((item = strtok_r (tmp, " :" , &save_ptr)) != nullptr ) {
253
+ if (strncmp (item, " codec=" , strlen (" codec=" )) == 0 ) {
254
+ audio_codec = item + strlen (" codec=" );
255
+ } else if (strncmp (item, " algo=" , strlen (" algo=" )) ==
256
+ 0 ) {
257
+ string algo = item + strlen (" algo=" );
258
+ if (algo == " linear" ) {
259
+ mixing_algorithm =
260
+ decltype (mixing_algorithm)(
261
+ new linear_mix_algo<
262
+ sample_type_source,
263
+ sample_type_mixed>());
264
+ } else if (algo == " logarithmic" ) {
265
+ mixing_algorithm =
266
+ decltype (mixing_algorithm)(
267
+ new logarithmic_mix_algo<
268
+ sample_type_source,
269
+ sample_type_mixed>());
262
270
} else {
263
- LOG (LOG_LEVEL_ERROR) << " Unknown option: " << item << " \n " ;
271
+ LOG (LOG_LEVEL_ERROR)
272
+ << " Unknown mixing algorithm: "
273
+ << algo << " \n " ;
264
274
throw 1 ;
265
275
}
266
- copy = nullptr ;
276
+ } else {
277
+ LOG (LOG_LEVEL_ERROR)
278
+ << " Unknown option: " << item << " \n " ;
279
+ throw 1 ;
267
280
}
281
+ tmp = nullptr ;
268
282
}
283
+ }
284
+ public:
285
+ state_audio_mixer (const struct audio_playback_opts *opts) {
286
+ parse_opts (opts);
269
287
270
288
struct audio_codec_state *audio_coder =
271
289
audio_codec_init_cfg (audio_codec.c_str (), AUDIO_CODER);
@@ -422,7 +440,7 @@ audio_play_mixer_init(const struct audio_playback_opts *opts)
422
440
return INIT_NOERR;
423
441
}
424
442
try {
425
- return new state_audio_mixer{ opts-> cfg } ;
443
+ return new state_audio_mixer ( opts) ;
426
444
} catch (...) {
427
445
return nullptr ;
428
446
}
0 commit comments