From b8af8cb521eb54660830da10049089ef72f351f1 Mon Sep 17 00:00:00 2001 From: Marco Bascetta Date: Tue, 23 Jan 2018 17:55:41 +0100 Subject: [PATCH 02/23] audiofilters/alsa: fixed errors when compiled with THREADED_VERSION defined Also added ENABLE_ALSA_THREADED cmake option. --- CMakeLists.txt | 4 ++++ mediastreamer-config.h.cmake | 1 + src/audiofilters/alsa.c | 11 +++++++---- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 246acd77..0c42aeb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,7 @@ cmake_dependent_option(ENABLE_QSA "Enable QSA (QNX Sound Architecture) support." cmake_dependent_option(ENABLE_OSS "Enable OSS support." NO "ENABLE_SOUND;LINUX_OR_BSD" NO) cmake_dependent_option(ENABLE_PORTAUDIO "Enable portaudio native support." NO "ENABLE_SOUND" NO) cmake_dependent_option(ENABLE_PULSEAUDIO "Enable pulseaudio support." YES "ENABLE_SOUND" NO) +option(ENABLE_ALSA_THREADED "Build mediastreamer2 with threaded ALSA MSFilter." NO) option(ENABLE_G726 "Build mediastreamer2 with the G726 codec." NO) option(ENABLE_GSM "Build mediastreamer2 with the GSM codec." YES) option(ENABLE_BV16 "Build mediastreamer2 with the BV16 codec." YES) @@ -475,6 +476,9 @@ endif() if(ENABLE_ALSA) set(__ALSA_ENABLED__ 1) endif() +if(ENABLE_ALSA_THREADED) + set(__ALSA_THREADED_VERSION__ 1) +endif() if(ENABLE_ARTSC) set(__ARTS_ENABLED__ 1) endif() diff --git a/mediastreamer-config.h.cmake b/mediastreamer-config.h.cmake index e8db9848..7b3a497a 100644 --- a/mediastreamer-config.h.cmake +++ b/mediastreamer-config.h.cmake @@ -39,6 +39,7 @@ #cmakedefine HAVE_DTLS #cmakedefine __ALSA_ENABLED__ +#cmakedefine __ALSA_THREADED_VERSION__ #cmakedefine __ARTS_ENABLED__ #cmakedefine __MACSND_ENABLED__ #cmakedefine __MAC_AQ_ENABLED__ diff --git a/src/audiofilters/alsa.c b/src/audiofilters/alsa.c index 3e02c997..9ae01fa8 100644 --- a/src/audiofilters/alsa.c +++ b/src/audiofilters/alsa.c @@ -38,7 +38,9 @@ void ms_alsa_card_set_forced_sample_rate(int samplerate){ forced_rate=samplerate; } -//#define THREADED_VERSION +#ifdef __ALSA_THREADED_VERSION__ +# define THREADED_VERSION +#endif /* __ALSA_THREADED_VERSION__ */ /*in case of troubles with a particular driver, try incrementing ALSA_PERIOD_SIZE to 512, 1024, 2048, 4096... @@ -901,7 +903,8 @@ static void * alsa_write_thread(void *p){ while (ad->read_started) { - count = alsa_can_read(ad->handle,samples); + int size = 0; + count = alsa_can_read(ad->handle); if (count==24) { /* keep this value for this driver */ } else if (count<=0) @@ -914,7 +917,7 @@ static void * alsa_write_thread(void *p){ //count = samples; } - int size=count*2; + size = count*2; om=allocb(size,0); if ((err=alsa_read(ad->handle,om->b_wptr,count))<=0) @@ -1044,7 +1047,7 @@ void alsa_read_process(MSFilter *obj){ AlsaReadData *ad=(AlsaReadData*)obj->data; mblk_t *om=NULL; int samples=(160*ad->rate)/8000; - int size=samples*2*ad->nchannels; + size_t size = samples*2*ad->nchannels; ms_mutex_lock(&ad->mutex); while (ms_bufferizer_get_avail(ad->bufferizer)>=size){ -- 2.11.0