[commit] r11695 - freeswitch/branches/gmaruzz/mod_skypiax
Author: gmaruzz Date: Sun Feb 8 12:51:05 2009 New Revision: 11695 Log: skypiax: cleaning skypiax_protocol.c Modified: freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c Modified: freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c ============================================================================== --- freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c (original) +++ freeswitch/branches/gmaruzz/mod_skypiax/skypiax_protocol.c Sun Feb 8 12:51:05 2009 @@ -213,7 +213,7 @@ } } else if (len == 0) { - DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG); + DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG); skypiax_sleep(1000); } else { ERRORA("len=%d\n", SKYPIAX_P_LOG, len); @@ -246,7 +246,7 @@ break; } - DEBUGA_SKYPE("server (I am it) GONE\n", SKYPIAX_P_LOG); + DEBUGA_SKYPE("incoming audio server (I am it) GONE\n", SKYPIAX_P_LOG); skypiax_close_socket(s); if (option_debug > 100) { DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); @@ -262,22 +262,16 @@ struct sockaddr_in my_addr; struct sockaddr_in remote_addr; unsigned int got; -#ifdef WIN32 unsigned int len; unsigned int i; unsigned int a; - int sin_size; unsigned int fd; short cli_out[SAMPLES_PER_FRAME * 2]; short cli_in[SAMPLES_PER_FRAME]; +#ifdef WIN32 + int sin_size; #else - int len; - int i; - int a; unsigned int sin_size; - int fd; - short cli_out[SAMPLES_PER_FRAME * 2]; - short cli_in[SAMPLES_PER_FRAME]; #endif /* WIN32 */ if (option_debug > 100) { @@ -286,7 +280,7 @@ memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_addr.s_addr = htonl(0x7f000001); /* use the localhost */ - my_addr.sin_port = htons(tech_pvt->tcp_cli_port); //FIXME configurable! + my_addr.sin_port = htons(tech_pvt->tcp_cli_port); if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { ERRORA("socket Error\n", SKYPIAX_P_LOG); @@ -343,11 +337,18 @@ rt = select(fdselect + 1, &fs, NULL, NULL, &to); #endif /* WIN32 */ if (rt > 0) { - if ((SAMPLERATE_SKYPIAX - 8000) == 0) { - got = SAMPLES_PER_FRAME * sizeof(short); - got = skypiax_pipe_read(tech_pvt->audioskypepipe[0], cli_in, got); - if (got > 0) { + /* read from the pipe the audio frame we are supposed to send out */ + got = skypiax_pipe_read(tech_pvt->audioskypepipe[0], cli_in, SAMPLES_PER_FRAME * sizeof(short)); + if (got != SAMPLES_PER_FRAME * sizeof(short)) { + ERRORA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got, + SAMPLES_PER_FRAME * sizeof(short)); + } + + if (got == SAMPLES_PER_FRAME * sizeof(short)) { + if (SAMPLERATE_SKYPIAX == 8000) { + + /* we're upsampling from 8khz to 16khz, cli_out will contain two times each sample from cli_in */ a = 0; for (i = 0; i < got / sizeof(short); i++) { cli_out[a] = cli_in[i]; @@ -355,60 +356,50 @@ cli_out[a] = cli_in[i]; a++; } - -#ifdef WIN32 - len = send(fd, (char *) cli_out, got * 2, 0); -#else /* WIN32 */ - len = send(fd, cli_out, got * 2, 0); -#endif /* WIN32 */ - if (len == 0) { - ERRORA("Skype server GONE\n", SKYPIAX_P_LOG); - break; + got = got * 2; + } else if (SAMPLERATE_SKYPIAX == 16000) { + /* we're NOT upsampling, cli_out will contain just ALL samples from cli_in */ + for (i = 0; i < got / sizeof(short); i++) { + cli_out[i] = cli_in[i]; } } else { - skypiax_sleep(1000); - ERRORA("CLI PIPE give us: %u\n", SKYPIAX_P_LOG, got); + ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG); } - } else if (SAMPLERATE_SKYPIAX == 16000) { - got = SAMPLES_PER_FRAME * sizeof(short); - got = skypiax_pipe_read(tech_pvt->audioskypepipe[0], cli_in, got); - - if (got > 0) { - if (got != SAMPLES_PER_FRAME * sizeof(short)) - ERRORA("CLI PIPE read %d\n", SKYPIAX_P_LOG, got); + /* send the 16khz frame to the Skype client waiting for incoming audio */ #ifdef WIN32 - len = send(fd, (char *) cli_in, got, 0); + len = send(fd, (char *) cli_out, got, 0); #else /* WIN32 */ - len = send(fd, cli_in, got, 0); -#endif /* WIN32 */ - - if (len != got && len != -1) - DEBUGA_SKYPE("CLI PIPE send %d\n", SKYPIAX_P_LOG, len); - - if (len == 0) { - ERRORA("Skype server GONE\n", SKYPIAX_P_LOG); + len = send(fd, cli_out, got, 0); +#endif /* WIN32 */ + + if (len == -1) { break; - } - } else { - skypiax_sleep(1000); - ERRORA("CLI PIPE give us: %u\n", SKYPIAX_P_LOG, got); - } + } else if (len != got){ + ERRORA("len=%d\n", SKYPIAX_P_LOG, len); + skypiax_sleep(1000); + break; } + } else { + + ERRORA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got, SAMPLES_PER_FRAME * sizeof(short)); + skypiax_sleep(10000); + + } } else { - skypiax_sleep(1000); if (rt) - ERRORA("select give us: %u\n", SKYPIAX_P_LOG, rt); + ERRORA("CLI rt=%d\n", SKYPIAX_P_LOG, rt); + skypiax_sleep(10000); } - } - DEBUGA_SKYPE("Skype server GONE\n", SKYPIAX_P_LOG); - skypiax_close_socket(s); + } + DEBUGA_SKYPE("Skype outbound audio GONE\n", SKYPIAX_P_LOG); + skypiax_close_socket(fd); break; } - DEBUGA_SKYPE("client (I am it) GONE\n", SKYPIAX_P_LOG); + DEBUGA_SKYPE("outbound audio server (I am it) GONE\n", SKYPIAX_P_LOG); skypiax_close_socket(s); if (option_debug > 100) { DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); @@ -441,9 +432,6 @@ /* the pipe is the audio fd for asterisk to poll on during a call */ tech_pvt->skypiax_sound_capt_fd = tech_pvt->audiopipe[0]; - if (option_debug > 10) { - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); - } return 0; }
participants (1)
-
FreeSWITCH SVN