gsmopen: retry serial initialization if failed, zeroing audio buffers, slower retry on soundcard busy (EAGAIN)

This commit is contained in:
Giovanni Maruzzelli 2010-11-26 06:44:57 -06:00
parent c9fa092a9e
commit c7aefe934f
3 changed files with 36 additions and 13 deletions

View File

@ -158,7 +158,7 @@ typedef enum {
#define WARNINGA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "rev "GSMOPEN_SVN_VERSION "[%p|%-7lx][WARNINGA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
#define NOTICA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "rev "GSMOPEN_SVN_VERSION "[%p|%-7lx][NOTICA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ );
#define GSMOPEN_P_LOG NULL, (unsigned long)55, __LINE__, tech_pvt ? tech_pvt->name ? tech_pvt->name : "none" : "none", -1, tech_pvt ? tech_pvt->interface_state : -1, tech_pvt ? tech_pvt->phone_callflow : -1
#define GSMOPEN_P_LOG (void *)NULL, (unsigned long)55, __LINE__, tech_pvt ? tech_pvt->name ? tech_pvt->name : "none" : "none", -1, tech_pvt ? tech_pvt->interface_state : -1, tech_pvt ? tech_pvt->phone_callflow : -1
/*********************************/
#define GSMOPEN_CAUSE_NORMAL 1

View File

@ -3294,12 +3294,18 @@ int alsa_write(private_t * tech_pvt, short *data, int datalen)
time_t now_timestamp;
/* size_t frames = 0; */
snd_pcm_state_t state;
snd_pcm_sframes_t delayp1;
snd_pcm_sframes_t delayp2;
snd_pcm_sframes_t delayp1=0;
snd_pcm_sframes_t delayp2=0;
if(tech_pvt->no_sound==1){
return res;
}
memset(sizbuf, 255, sizeof(sizbuf));
memset(sizbuf2, 255, sizeof(sizbuf));
memset(silencebuf, 255, sizeof(sizbuf));
//ERRORA("data=%p, datalen=%d\n", GSMOPEN_P_LOG, (void *)data, datalen);
/* We have to digest the frame in 160-byte portions */
if (datalen > sizeof(sizbuf) - sizpos) {
@ -3307,8 +3313,11 @@ int alsa_write(private_t * tech_pvt, short *data, int datalen)
res = -1;
} else {
memcpy(sizbuf + sizpos, data, datalen);
memset(data, 255, datalen);
len += datalen;
pos = 0;
#ifdef ALSA_MONITOR
alsa_monitor_write(sizbuf, len);
#endif
@ -3456,6 +3465,7 @@ int alsa_write(private_t * tech_pvt, short *data, int datalen)
if (res == -ESTRPIPE) {
ERRORA("You've got some big problems\n", GSMOPEN_P_LOG);
} else if (res == -EAGAIN) {
DEBUGA_GSMOPEN("Momentarily busy\n", GSMOPEN_P_LOG);
res = 0;
} else if (res < 0) {
ERRORA("Error %d on audio write: \"%s\"\n", GSMOPEN_P_LOG, res, snd_strerror(res));
@ -3572,9 +3582,11 @@ int alsa_read(private_t * tech_pvt, short *data, int datalen)
return r;
} else if (r == -EAGAIN) {
DEBUGA_GSMOPEN("ALSA read -EAGAIN, the soundcard is not ready to be read by gsmopen\n", GSMOPEN_P_LOG);
int count=0;
while (r == -EAGAIN) {
gsmopen_sleep(1000);
gsmopen_sleep(10000);
DEBUGA_GSMOPEN("%d ALSA read -EAGAIN, the soundcard is not ready to be read by gsmopen\n", GSMOPEN_P_LOG, count);
count++;
if (tech_pvt->alsa_capture_is_mono) {
r = snd_pcm_readi(tech_pvt->alsac, buf + readpos, left);

View File

@ -1904,7 +1904,17 @@ static switch_status_t load_config(int reload_type)
if (globals.GSMOPEN_INTERFACES[interface_id].controldevprotocol != PROTOCOL_NO_SERIAL) {
res = gsmopen_serial_config(&globals.GSMOPEN_INTERFACES[interface_id]);
if (res) {
ERRORA("gsmopen_serial_config failed\n", GSMOPEN_P_LOG);
int count = 0;
ERRORA("gsmopen_serial_config failed, let's try again\n", GSMOPEN_P_LOG);
while(res && count < 5){
switch_sleep(100000); //0.1 seconds
res = gsmopen_serial_config(&globals.GSMOPEN_INTERFACES[interface_id]);
count++;
if (res) {
ERRORA("%d: gsmopen_serial_config failed, let's try again\n", GSMOPEN_P_LOG, count);
}
}
if (res) {
ERRORA("STARTING interface_id=%d FAILED\n", GSMOPEN_P_LOG, interface_id);
//return SWITCH_STATUS_FALSE;
globals.GSMOPEN_INTERFACES[interface_id].running=0;
@ -1914,6 +1924,7 @@ static switch_status_t load_config(int reload_type)
continue;
}
}
}
if(globals.GSMOPEN_INTERFACES[interface_id].no_sound==0){
#ifdef GSMOPEN_ALSA