From 612e4d1116cdb7340ce29465821af949c8ed2d8e Mon Sep 17 00:00:00 2001 From: Marco Bascetta Date: Wed, 17 Jan 2018 09:13:19 +0100 Subject: [PATCH 12/23] voip/audiostream: do not istantiate av_player resampler when not needed --- src/voip/audiostream.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/voip/audiostream.c b/src/voip/audiostream.c index 28a49e27..27d8cfe1 100644 --- a/src/voip/audiostream.c +++ b/src/voip/audiostream.c @@ -415,7 +415,9 @@ static void unplumb_av_player(AudioStream *stream){ ms_connection_helper_unlink(&ch,player->player,-1,player->audiopin); if (player->decoder) ms_connection_helper_unlink(&ch,player->decoder,0,0); - ms_connection_helper_unlink(&ch,player->resampler,0,0); + if (player->resampler) { + ms_connection_helper_unlink(&ch,player->resampler,0,0); + } ms_connection_helper_unlink(&ch,stream->outbound_mixer,1,-1); /*and attach back*/ if (reattach) ms_ticker_attach(stream->ms.sessions.ticker,stream->soundread); @@ -467,8 +469,16 @@ static void configure_av_player(AudioStream *stream, const MSFmtDescriptor *audi ms_filter_call_method(stream->outbound_mixer,MS_FILTER_GET_SAMPLE_RATE,&stream_rate); ms_filter_call_method(stream->outbound_mixer,MS_FILTER_GET_NCHANNELS,&stream_channels); - ms_filter_call_method(player->resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&stream_channels); - ms_filter_call_method(player->resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&stream_rate); + + if (audiofmt->rate != stream_rate || audiofmt->nchannels != stream_channels ) { + ms_message("AudioStream [%p] av_player needs resampler", stream); + ms_filter_call_method(player->resampler,MS_FILTER_SET_OUTPUT_NCHANNELS,&stream_channels); + ms_filter_call_method(player->resampler,MS_FILTER_SET_OUTPUT_SAMPLE_RATE,&stream_rate); + } else { + ms_filter_destroy(player->resampler); + player->resampler=NULL; + } + if (videofmt){ MSPinFormat pf; pf.pin=0; @@ -491,7 +501,9 @@ static void plumb_av_player(AudioStream *stream){ ms_connection_helper_link(&ch,player->player,-1,player->audiopin); if (player->decoder) ms_connection_helper_link(&ch,player->decoder,0,0); - ms_connection_helper_link(&ch,player->resampler,0,0); + if (player->resampler) { + ms_connection_helper_link(&ch,player->resampler,0,0); + } /*detach the outbound graph before attaching to the outbound mixer*/ if (reattach) ms_ticker_detach(stream->ms.sessions.ticker,stream->soundread); ms_connection_helper_link(&ch,stream->outbound_mixer,1,-1); -- 2.11.0