From 96e05f19c9e4452f6b6bef1ee0ababd55b70e469 Mon Sep 17 00:00:00 2001 From: aymeric Date: Fri, 24 Oct 2008 15:25:56 +0000 Subject: [PATCH] delay for bugguy alsa driver git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@117 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- linphone/mediastreamer2/src/alsa.c | 59 +++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 6 deletions(-) diff --git a/linphone/mediastreamer2/src/alsa.c b/linphone/mediastreamer2/src/alsa.c index 3c7798439..85c0fc00e 100644 --- a/linphone/mediastreamer2/src/alsa.c +++ b/linphone/mediastreamer2/src/alsa.c @@ -208,10 +208,33 @@ static snd_pcm_t * alsa_open_r(const char *pcmdev,int bits,int stereo,int rate) return NULL; } #endif - if (alsa_set_params(pcm_handle,0,bits,stereo,rate)<0){ - snd_pcm_close(pcm_handle); - return NULL; + + { + struct timeval tv1; + struct timeval tv2; + struct timezone tz; + int diff = 0; + err = gettimeofday(&tv1, &tz); + while (1) { + if (!(alsa_set_params(pcm_handle,0,bits,stereo,rate)<0)){ + ms_message("alsa_open_r: Audio params set"); + break; + } + if (!gettimeofday(&tv2, &tz) && !err) { + diff = ((tv2.tv_sec - tv1.tv_sec) * 1000000) + (tv2.tv_usec - tv1.tv_usec); + } else { + diff = -1; + } + if ((diff < 0) || (diff > 3000000)) { /* 3 secondes */ + ms_error("alsa_open_r: Error setting params for more than 3 seconds"); + snd_pcm_close(pcm_handle); + return NULL; + } + ms_warning("alsa_open_r: Error setting params (for %d micros)", diff); + usleep(200000); } + } + err=snd_pcm_start(pcm_handle); if (err<0){ ms_warning("snd_pcm_start() failed: %s", snd_strerror(err)); @@ -227,10 +250,34 @@ static snd_pcm_t * alsa_open_w(const char *pcmdev,int bits,int stereo,int rate) ms_warning("alsa_open_w: Error opening PCM device %s",pcmdev ); return NULL; } - if (alsa_set_params(pcm_handle,1,bits,stereo,rate)<0){ - snd_pcm_close(pcm_handle); - return NULL; + + { + struct timeval tv1; + struct timeval tv2; + struct timezone tz; + int diff = 0; + int err; + err = gettimeofday(&tv1, &tz); + while (1) { + if (!(alsa_set_params(pcm_handle,1,bits,stereo,rate)<0)){ + ms_message("alsa_open_w: Audio params set"); + break; + } + if (!gettimeofday(&tv2, &tz) && !err) { + diff = ((tv2.tv_sec - tv1.tv_sec) * 1000000) + (tv2.tv_usec - tv1.tv_usec); + } else { + diff = -1; + } + if ((diff < 0) || (diff > 3000000)) { /* 3 secondes */ + ms_error("alsa_open_w: Error setting params for more than 3 seconds"); + snd_pcm_close(pcm_handle); + return NULL; + } + ms_warning("alsa_open_w: Error setting params (for %d micros)", diff); + usleep(200000); } + } + return pcm_handle; }