[Freeswitch-branches] [commit] r10885 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
FreeSWITCH SVN
gmaruzz at freeswitch.org
Fri Dec 19 09:32:01 PST 2008
Author: gmaruzz
Date: Fri Dec 19 12:32:01 2008
New Revision: 10885
Log:
sends and receive audio to/from remote skype client at native rate on linux, sound is nice :-)
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c Fri Dec 19 12:32:01 2008
@@ -30,6 +30,7 @@
switch_endpoint_interface_t *skypiax_endpoint_interface;
switch_memory_pool_t *skypiax_module_pool = NULL;
int running = 1;
+switch_core_session_t *global_session = NULL;
/*************************************************/
/*************************************************/
/*************************************************/
@@ -107,7 +108,7 @@
p->tech_pvt = tech_pvt;
}
- if (skypiax_codec(tech_pvt, SAMPLERATE, 20) != SWITCH_STATUS_SUCCESS) {
+ if (skypiax_codec(tech_pvt, SAMPLERATE_SKYPIAX, 20) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_docec FAILED\n");
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "skypiax_codec SUCCESS\n");
@@ -391,8 +392,10 @@
#endif
sent = frame->datalen;
- switch_file_write(p->audioskypepipe[1], (short *) frame->data, &sent);
- //DEBUGA_SKYPE("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
+ //DEBUGA_SKYPE("CLI PIPE to write %d\n", SKYPIAX_P_LOG, sent);
+ switch_file_write(p->audioskypepipe[1], frame->data, &sent);
+ if(sent != frame->datalen)
+ ERRORA("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
return SWITCH_STATUS_SUCCESS;
@@ -557,7 +560,7 @@
while (forever) {
if (!running)
break;
- switch_sleep(1000);
+ //switch_sleep(1000); //cicopet
res = skypiax_skype_read(p);
//if (res == CALLFLOW_INCOMING_HANGUP && p->interface_state != SKYPIAX_STATE_DOWN)
if (res == CALLFLOW_INCOMING_HANGUP) {
@@ -581,6 +584,8 @@
}
}
}
+ p->interface_state = SKYPIAX_STATE_DOWN;
+ global_session = NULL; //FIXME
}
}
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h Fri Dec 19 12:32:01 2008
@@ -46,7 +46,7 @@
#endif //WIN32
#define SAMPLES_PER_FRAME 320
-#define SAMPLERATE 16000
+#define SAMPLERATE_SKYPIAX 16000
//#define SKYPIAX_SVN_VERSION "SVN 123456"
#define SKYPIAX_SVN_VERSION SWITCH_VERSION_REVISION
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c Fri Dec 19 12:32:01 2008
@@ -12,7 +12,7 @@
/**********************************************************/
-switch_core_session_t *global_session = NULL;
+extern switch_core_session_t *global_session;
#ifdef WIN32
@@ -48,17 +48,16 @@
unsigned int len;
unsigned int i;
unsigned int a;
- short srv_in[SAMPLES_PER_FRAME];
int sin_size;
unsigned int fd;
#else
int len;
int i;
int a;
- short srv_in[SAMPLES_PER_FRAME];
unsigned int sin_size;
int fd;
#endif /* WIN32 */
+ short srv_in[SAMPLES_PER_FRAME];
struct sockaddr_in my_addr;
struct sockaddr_in remote_addr;
int exit = 0;
@@ -117,16 +116,17 @@
fdselect = fd;
FD_ZERO(&fs);
FD_SET(fdselect, &fs);
- to.tv_usec = 100000;
+ to.tv_usec = 50000;
to.tv_sec = 0;
+
rt = select(fdselect + 1, &fs, NULL, NULL, &to);
- //rt=1;
+ //rt=0;
if (rt > 0) {
- len = recv(fd, srv_in, sizeof(short) * SAMPLES_PER_FRAME, 0);
- //DEBUGA_SKYPE("recv %d\n", SKYPIAX_P_LOG, len);
+ //len = recv(fd, srv_in, sizeof(short) * SAMPLES_PER_FRAME, 0);
+ len = recv(fd, srv_in, 320, 0); //seems that Skype only sends 320 bytes at time
- if(SAMPLERATE == 8000) {
+ if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
/****************************************************************/
if (len > 0) {
@@ -165,29 +165,32 @@
} else if (len == 0) {
DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
- break;
+ switch_sleep(1000);
} else {
ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
exit = 1;
break;
}
/****************************************************************/
- } else if (SAMPLERATE == 16000) {
+ } else if (SAMPLERATE_SKYPIAX == 16000) {
/****************************************************************/
if (len > 0) {
if (len == SAMPLES_PER_FRAME * sizeof(short)) {
unsigned int howmany;
- DEBUGA_SKYPE("SRV recv %d\n", SKYPIAX_P_LOG, len);
howmany = len;
+ WARNINGA("SRV recv %d\n", SKYPIAX_P_LOG, len);
+
switch_file_write(p->audiopipe[1], srv_in, &howmany);
p->audiobuf_is_loaded = 0;
- DEBUGA_SKYPE("SRV PIPE WRITE=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, len, howmany);
+ WARNINGA("SRV PIPE WRITE=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*SAMPLES_PER_FRAME, len, len, howmany);
}else if (len == SAMPLES_PER_FRAME * sizeof(short) / 2) {
- unsigned int howmany;
- DEBUGA_SKYPE("SRV recv %d\n", SKYPIAX_P_LOG, len);
+
+#if 1
+
+
if (!p->audiobuf_is_loaded) {
for (i = 0; i < (len / sizeof(short)); i++) {
p->audiobuf[i] = srv_in[i];
@@ -206,19 +209,25 @@
switch_file_write(p->audiopipe[1], totalbuf, &howmany);
p->audiobuf_is_loaded = 0;
- DEBUGA_SKYPE("SRV PIPE WRITE=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, SAMPLES_PER_FRAME * sizeof(short), len, SAMPLES_PER_FRAME * sizeof(short), howmany);
+ //NOTICA("SRV PIPE WRITE=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, SAMPLES_PER_FRAME * sizeof(short), len, SAMPLES_PER_FRAME * sizeof(short), howmany);
}
+#endif
+
+
+
+
} else {
- ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
+ ERRORA("SRV len=%d\n", SKYPIAX_P_LOG, len);
}
} else if (len == 0) {
DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
- break;
+ switch_sleep(1000);
+ //break;
} else {
- ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
+ ERRORA("SRV len=%d\n", SKYPIAX_P_LOG, len);
exit = 1;
break;
}
@@ -228,9 +237,12 @@
} else {
- ERRORA("SAMPLERATE can only be 8000 or 16000\n", SKYPIAX_P_LOG);
+ ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
}
- }
+ } else {
+
+ ERRORA("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
+ }
}
kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
@@ -274,20 +286,18 @@
struct sockaddr_in my_addr;
struct sockaddr_in remote_addr;
unsigned int got;
+ short cli_in[SAMPLES_PER_FRAME];
+ short cli_out[SAMPLES_PER_FRAME * 2];
#ifdef WIN32
unsigned int len;
unsigned int i;
unsigned int a;
- short cli_in[SAMPLES_PER_FRAME];
- short cli_out[SAMPLES_PER_FRAME];
int sin_size;
unsigned int fd;
#else
int len;
int i;
int a;
- short cli_in[SAMPLES_PER_FRAME];
- short cli_out[SAMPLES_PER_FRAME];
unsigned int sin_size;
int fd;
#endif /* WIN32 */
@@ -346,17 +356,20 @@
fdselect = 1;
FD_ZERO(&fs);
FD_SET(fdselect, &fs);
- to.tv_usec = 10000;
+ to.tv_usec = 100000; //100ms
to.tv_sec = 0;
- rt = select(fdselect + 1, &fs, NULL, NULL, &to);
- //rt = 1;
+ //FIXME rt = select(fdselect + 1, &fs, NULL, NULL, &to);
+ //switch_sleep(1000);//FIXME
+ memset(cli_in, '\0', sizeof(cli_in));
+ rt = 1;
if (rt > 0) {
/*********************************************/
- if (SAMPLERATE == 8000) {
- got = (SAMPLES_PER_FRAME / 2) * sizeof(short);
+ if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
+ got = SAMPLES_PER_FRAME * sizeof(short);
switch_file_read(p->audioskypepipe[0], cli_in, &got);
if (got > 0) {
+ DEBUGA_SKYPE("CLI PIPE read %d\n", SKYPIAX_P_LOG, got);
a = 0;
for (i = 0; i < got / sizeof(short); i++) {
cli_out[a] = cli_in[i];
@@ -366,6 +379,7 @@
}
len = send(fd, cli_out, got * 2, 0);
+ DEBUGA_SKYPE("CLI PIPE send %d\n", SKYPIAX_P_LOG, len);
if (len == 0) {
ERRORA("Skype server GONE\n", SKYPIAX_P_LOG);
@@ -373,21 +387,24 @@
}
} else {
switch_sleep(1000);
- //ERRORA("Audio skype pipe give us: %u\n", SKYPIAX_P_LOG, got);
+ ERRORA("CLI PIPE give us: %u\n", SKYPIAX_P_LOG, got);
+ //break;
}
}
/*********************************************/
/*********************************************/
- else if (SAMPLERATE == 16000) {
+ else if (SAMPLERATE_SKYPIAX == 16000) {
got = SAMPLES_PER_FRAME * sizeof(short);
switch_file_read(p->audioskypepipe[0], cli_in, &got);
if (got > 0) {
- //DEBUGA_SKYPE("CLI PIPE read %d\n", SKYPIAX_P_LOG, got);
+ if(got != SAMPLES_PER_FRAME * sizeof(short) )
+ ERRORA("CLI PIPE read %d\n", SKYPIAX_P_LOG, got);
len = send(fd, cli_in, got, 0);
- //DEBUGA_SKYPE("CLI PIPE send %d\n", SKYPIAX_P_LOG, len);
+ if(len != got )
+ ERRORA("CLI PIPE send %d\n", SKYPIAX_P_LOG, len);
if (len == 0) {
ERRORA("Skype server GONE\n", SKYPIAX_P_LOG);
@@ -431,14 +448,14 @@
rv =
switch_file_pipe_create(&p->audiopipe[0], &p->audiopipe[1], skypiax_module_pool);
- rv = switch_file_pipe_timeout_set(p->audiopipe[0], 100000);
+ //rv = switch_file_pipe_timeout_set(p->audiopipe[0], 100);
/* the pipe is our audio fd for pbx to poll on */
p->skypiax_sound_capt_fd = p->audiopipe[0];
rv =
switch_file_pipe_create(&p->audioskypepipe[0], &p->audioskypepipe[1], skypiax_module_pool);
- rv = switch_file_pipe_timeout_set(p->audioskypepipe[0], 100000);
+ //rv = switch_file_pipe_timeout_set(p->audioskypepipe[0], 20000);
if (option_debug > 10) {
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
}
@@ -465,12 +482,12 @@
if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
if (samples)
- DEBUGA_SKYPE("SRV PIPE READ=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG,
+ ERRORA("SRV PIPE READ=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG,
samples, SAMPLES_PER_FRAME * sizeof(short));
//do nothing
} else {
tech_pvt->read_frame.datalen = samples;
- //DEBUGA_SKYPE("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples);
+ //NOTICA("SRV PIPE READ=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples);
/* A real frame */
}
} else {
@@ -678,7 +695,7 @@
p = obj;
switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
- switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100000);
+ //switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100);
win32_AsteriskHandlesSkype = &p->AsteriskHandlesAst;
@@ -862,7 +879,7 @@
switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
- switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100000);
+ //switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100);
AsteriskHandlesAst = &p->AsteriskHandlesAst;
//disp = XOpenDisplay(getenv("DISPLAY"));
disp = XOpenDisplay(p->X11_display);
@@ -928,7 +945,7 @@
b = buffer;
while (1) {
- usleep(1000);
+ //switch_sleep(10000);
XNextEvent(disp, &an_event);
if (!running)
break;
@@ -1201,7 +1218,9 @@
DEBUGA_SKYPE("Call %s received a DTMF: %s\n", SKYPIAX_P_LOG, id, value);
tech_pvt = p->tech_pvt;
- session = tech_pvt->session;
+ //if(tech_pvt)
+ session = tech_pvt->session;
+ //if(session)
channel = switch_core_session_get_channel(session);
if (channel) {
@@ -1288,7 +1307,6 @@
DEBUGA_SKYPE("We missed skype_call %s\n", SKYPIAX_P_LOG, id);
} else if (!strcasecmp(value, "FINISHED")) {
- global_session = NULL; //FIXME
//p->skype_callflow = CALLFLOW_STATUS_FINISHED;
if (option_debug)
DEBUGA_SKYPE("skype_call %s now is DOWN\n", SKYPIAX_P_LOG, id);
More information about the Freeswitch-branches
mailing list