[Freeswitch-branches] [commit] r11689 - freeswitch/branches/gmaruzz/mod_skypiax
FreeSWITCH SVN
gmaruzz at freeswitch.org
Sun Feb 8 06:02:51 PST 2009
Author: gmaruzz
Date: Sun Feb 8 08:02:51 2009
New Revision: 11689
Log:
skypiax: skypiax_protocol.c indent -gnu -ts4 -br -brs -cdw -lp -ce -nbfda -npcs -nprs -npsl -nbbo -saf -sai -saw -cs -bbo -nhnl -nut -sob -l90
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 08:02:51 2009
@@ -23,33 +23,35 @@
#endif /* WIN32 */
/*************************************/
-#if defined(WIN32) && !defined(__CYGWIN__)
-int skypiax_file_write(switch_file_t *pipe, short *buf, int howmany){
- switch_size_t quantity;
+#if defined(WIN32) && !defined(__CYGWIN__)
+int skypiax_file_write(switch_file_t * pipe, short *buf, int howmany)
+{
+ switch_size_t quantity;
- quantity = howmany;
+ quantity = howmany;
- switch_file_write(pipe, buf, &quantity);
+ switch_file_write(pipe, buf, &quantity);
- howmany = quantity;
+ howmany = quantity;
- return howmany;
+ return howmany;
}
#else /* WIN32 */
-int skypiax_file_write(int pipe, short *buf, int howmany){
- howmany = write(pipe, buf, howmany);
- return howmany;
+int skypiax_file_write(int pipe, short *buf, int howmany)
+{
+ howmany = write(pipe, buf, howmany);
+ return howmany;
}
#endif /* WIN32 */
-void * skypiax_do_tcp_srv_thread_func(void *obj)
+void *skypiax_do_tcp_srv_thread_func(void *obj)
{
private_t *tech_pvt = obj;
int s;
unsigned int len;
unsigned int i;
unsigned int a;
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
int sin_size;
#else /* WIN32 */
unsigned int sin_size;
@@ -116,14 +118,14 @@
to.tv_sec = 0;
rt = select(fdselect + 1, &fs, NULL, NULL, &to);
-#ifndef NOTDEF
if (rt > 0) {
len = recv(fd, (char *) srv_in, 320, 0); //seems that Skype only sends 320 bytes at time
- if (len == 320) {
+ if (len == 320) {
+ unsigned int howmany;
- if (SAMPLERATE_SKYPIAX == 8000) {
+ if (SAMPLERATE_SKYPIAX == 8000) {
a = 0;
for (i = 0; i < len / sizeof(short); i++) {
@@ -138,7 +140,6 @@
}
tech_pvt->audiobuf_is_loaded = 1;
} else {
- unsigned int howmany;
howmany = len / 2 / 2;
for (i = 0; i < howmany; i++)
@@ -156,140 +157,46 @@
tech_pvt->audiobuf_is_loaded = 0;
}
- } else if (SAMPLERATE_SKYPIAX == 16000) {
-
- if (!tech_pvt->audiobuf_is_loaded) {
- for (i = 0; i < (len / sizeof(short)); i++) {
- tech_pvt->audiobuf[i] = srv_in[i];
- }
- tech_pvt->audiobuf_is_loaded = 1;
- } else {
- unsigned int howmany = SAMPLES_PER_FRAME * sizeof(short);
-
- for (i = 0; i < (len / sizeof(short)); i++)
- totalbuf[i] = tech_pvt->audiobuf[i];
- for (a = 0; a < (len / sizeof(short)); a++) {
- totalbuf[i] = srv_in[a];
- i++;
- }
-
- howmany = skypiax_file_write(tech_pvt->audiopipe[1], totalbuf, howmany);
- tech_pvt->audiobuf_is_loaded = 0;
- }
-
- } else {
- ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
- }
-
- } else if (len == 0) {
- DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
- skypiax_sleep(1000);
- } else {
- ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
- exit = 1;
- break;
- }
-
-
-
-
-
-
-
- } else {
- if (rt)
- ERRORA("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
- skypiax_sleep(10000);
- }
-#endif // NOTDEF
-
-#ifdef NOTDEF
- if (rt > 0) {
-
- len = recv(fd, (char *) srv_in, 320, 0); //seems that Skype only sends 320 bytes at time
-
-
- if (SAMPLERATE_SKYPIAX == 8000) {
-
- if (len == 320) {
- a = 0;
- for (i = 0; i < len / sizeof(short); i++) {
- srv_out[a] = srv_in[i];
- i++;
- a++;
- }
+ } else if (SAMPLERATE_SKYPIAX == 16000) {
if (!tech_pvt->audiobuf_is_loaded) {
- for (i = 0; i < (len / sizeof(short)) / 2; i++) {
- tech_pvt->audiobuf[i] = srv_out[i];
+ for (i = 0; i < (len / sizeof(short)); i++) {
+ tech_pvt->audiobuf[i] = srv_in[i];
}
tech_pvt->audiobuf_is_loaded = 1;
} else {
- unsigned int howmany;
+ howmany = SAMPLES_PER_FRAME * sizeof(short);
- howmany = len / 2 / 2;
- for (i = 0; i < howmany; i++)
+ for (i = 0; i < (len / sizeof(short)); i++)
totalbuf[i] = tech_pvt->audiobuf[i];
-
- howmany = len / 2 / 2;
- for (a = 0; a < howmany; a++) {
- totalbuf[i] = srv_out[a];
+ for (a = 0; a < (len / sizeof(short)); a++) {
+ totalbuf[i] = srv_in[a];
i++;
}
- howmany = len;
-
howmany = skypiax_file_write(tech_pvt->audiopipe[1], totalbuf, howmany);
tech_pvt->audiobuf_is_loaded = 0;
}
- } else if (len == 0) {
- DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
- skypiax_sleep(1000);
} else {
- ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
- exit = 1;
- break;
- }
- } else if (SAMPLERATE_SKYPIAX == 16000) {
-
- if (len == 320) {
- if (!tech_pvt->audiobuf_is_loaded) {
- for (i = 0; i < (len / sizeof(short)); i++) {
- tech_pvt->audiobuf[i] = srv_in[i];
- }
- tech_pvt->audiobuf_is_loaded = 1;
- } else {
- unsigned int howmany = SAMPLES_PER_FRAME * sizeof(short);
-
- for (i = 0; i < (len / sizeof(short)); i++)
- totalbuf[i] = tech_pvt->audiobuf[i];
- for (a = 0; a < (len / sizeof(short)); a++) {
- totalbuf[i] = srv_in[a];
- i++;
- }
-
- howmany = skypiax_file_write(tech_pvt->audiopipe[1], totalbuf, howmany);
- tech_pvt->audiobuf_is_loaded = 0;
- }
- } else if (len == 0) {
- DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
- skypiax_sleep(1000);
- } else {
- ERRORA("SRV len=%d\n", SKYPIAX_P_LOG, len);
- exit = 1;
- break;
+ ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
}
+ } else if (len == 0) {
+ DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
+ skypiax_sleep(1000);
} else {
- ERRORA("SAMPLERATE_SKYPIAX can only be 8000 or 16000\n", SKYPIAX_P_LOG);
+ ERRORA("len=%d\n", SKYPIAX_P_LOG, len);
+ exit = 1;
+ break;
}
+
} else {
if (rt)
ERRORA("SRV rt=%d\n", SKYPIAX_P_LOG, rt);
skypiax_sleep(10000);
}
-#endif // NOTDEF
+
}
kill_cli_size = SAMPLES_PER_FRAME * sizeof(short);
@@ -303,7 +210,7 @@
len = skypiax_file_write(tech_pvt->audioskypepipe[1], kill_cli_buff, kill_cli_size);
DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG);
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
closesocket(fd);
#else
close(fd);
@@ -313,7 +220,7 @@
}
DEBUGA_SKYPE("server (I am it) GONE\n", SKYPIAX_P_LOG);
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
closesocket(s);
#else
close(s);
@@ -323,7 +230,7 @@
}
return NULL;
}
-void * skypiax_do_tcp_cli_thread_func(void *obj)
+void *skypiax_do_tcp_cli_thread_func(void *obj)
{
private_t *tech_pvt = obj;
int s;
@@ -369,8 +276,8 @@
if (option_debug > 100) {
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
}
-#if defined(WIN32) && !defined(__CYGWIN__)
- closesocket(s);
+#if defined(WIN32) && !defined(__CYGWIN__)
+ closesocket(s);
#else
close(s);
#endif
@@ -417,7 +324,7 @@
if (rt > 0) {
if ((SAMPLERATE_SKYPIAX - 8000) == 0) {
got = SAMPLES_PER_FRAME * sizeof(short);
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
skypiax_file_read(tech_pvt->audioskypepipe[0], cli_in, &got);
#else /* WIN32 */
got = read(tech_pvt->audioskypepipe[0], cli_in, got);
@@ -447,7 +354,7 @@
}
} else if (SAMPLERATE_SKYPIAX == 16000) {
got = SAMPLES_PER_FRAME * sizeof(short);
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
skypiax_file_read(tech_pvt->audioskypepipe[0], cli_in, &got);
#else /* WIN32 */
got = read(tech_pvt->audioskypepipe[0], cli_in, got);
@@ -484,8 +391,8 @@
}
DEBUGA_SKYPE("Skype server GONE\n", SKYPIAX_P_LOG);
-#if defined(WIN32) && !defined(__CYGWIN__)
- closesocket(s);
+#if defined(WIN32) && !defined(__CYGWIN__)
+ closesocket(s);
#else
close(fd);
#endif
@@ -493,7 +400,7 @@
}
DEBUGA_SKYPE("client (I am it) GONE\n", SKYPIAX_P_LOG);
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
closesocket(s);
#else
close(s);
@@ -507,7 +414,7 @@
int skypiax_skypeaudio_init(private_t * tech_pvt)
{
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
switch_status_t rv;
rv =
switch_file_pipe_create(&tech_pvt->audiopipe[0], &tech_pvt->audiopipe[1],
@@ -558,7 +465,7 @@
#endif /* WIN32 */
if (rt > 0) {
samples = SAMPLES_PER_FRAME * sizeof(short);
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
skypiax_file_read(tech_pvt->audiopipe[0], tech_pvt->read_frame.data, &samples);
#else /* WIN32 */
samples = read(tech_pvt->audiopipe[0], tech_pvt->read_frame.data, samples);
@@ -661,10 +568,12 @@
howmany = strlen(msg_from_skype) + 1;
//#if defined(WIN32) && !defined(__CYGWIN__)
- howmany = skypiax_file_write(tech_pvt->SkypiaxHandles.fdesc[1], (short *)msg_from_skype, howmany);
+ howmany =
+ skypiax_file_write(tech_pvt->SkypiaxHandles.fdesc[1], (short *) msg_from_skype,
+ howmany);
//NOTICA("From Skype API: %s\n", SKYPIAX_P_LOG, msg_from_skype);
//#else
- //howmany = write(tech_pvt->SkypiaxHandles.fdesc[1], msg_from_skype, howmany);
+ //howmany = write(tech_pvt->SkypiaxHandles.fdesc[1], msg_from_skype, howmany);
//NOTICA("From Skype API: %s\n", SKYPIAX_P_LOG, msg_from_skype);
//#endif
lReturnCode = 1;
@@ -799,7 +708,7 @@
DWORD win32_dwThreadId;
-void * skypiax_do_skypeapi_thread_func(void *obj)
+void *skypiax_do_skypeapi_thread_func(void *obj)
{
/* create window class */
/* create dummy/hidden window for processing messages */
@@ -811,14 +720,14 @@
/* destroy window class */
private_t *tech_pvt = obj;
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
switch_status_t rv;
switch_file_pipe_create(&tech_pvt->SkypiaxHandles.fdesc[0],
&tech_pvt->SkypiaxHandles.fdesc[1], skypiax_module_pool);
rv =
- switch_file_pipe_create(&tech_pvt->SkypiaxHandles.fdesc[0], &tech_pvt->SkypiaxHandles.fdesc[1],
- skypiax_module_pool);
+ switch_file_pipe_create(&tech_pvt->SkypiaxHandles.fdesc[0],
+ &tech_pvt->SkypiaxHandles.fdesc[1], skypiax_module_pool);
#else /* WIN32 */
if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
@@ -826,7 +735,6 @@
}
#endif /* WIN32 */
-
tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIAttach =
RegisterWindowMessage("SkypeControlAPIAttach");
tech_pvt->SkypiaxHandles.win32_uiGlobal_MsgID_SkypeControlAPIDiscover =
@@ -991,7 +899,7 @@
skypiax_sleep(1000);
}
-void * skypiax_do_skypeapi_thread_func(void *obj)
+void *skypiax_do_skypeapi_thread_func(void *obj)
{
private_t *tech_pvt = obj;
@@ -1003,14 +911,14 @@
DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
- if(!strlen(tech_pvt->X11_display))
- strcpy(tech_pvt->X11_display, getenv("DISPLAY"));
+ if (!strlen(tech_pvt->X11_display))
+ strcpy(tech_pvt->X11_display, getenv("DISPLAY"));
- if(!tech_pvt->tcp_srv_port)
- tech_pvt->tcp_srv_port = 10160;
+ if (!tech_pvt->tcp_srv_port)
+ tech_pvt->tcp_srv_port = 10160;
- if(!tech_pvt->tcp_cli_port)
- tech_pvt->tcp_cli_port = 10161;
+ if (!tech_pvt->tcp_cli_port)
+ tech_pvt->tcp_cli_port = 10161;
if (pipe(tech_pvt->SkypiaxHandles.fdesc)) {
fcntl(tech_pvt->SkypiaxHandles.fdesc[0], F_SETFL, O_NONBLOCK);
@@ -1021,7 +929,7 @@
if (!disp) {
ERRORA("Cannot open X Display '%s', exiting skype thread\n", SKYPIAX_P_LOG,
tech_pvt->X11_display);
- running=0;
+ running = 0;
return NULL;
} else {
DEBUGA_SKYPE("X Display '%s' opened\n", SKYPIAX_P_LOG, tech_pvt->X11_display);
@@ -1052,7 +960,7 @@
("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
SKYPIAX_P_LOG);
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
- running=0;
+ running = 0;
return NULL;
}
@@ -1062,7 +970,7 @@
("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
SKYPIAX_P_LOG);
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
- running=0;
+ running = 0;
return NULL;
}
@@ -1110,11 +1018,11 @@
ERRORA
("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n",
SKYPIAX_P_LOG);
- running=0;
+ running = 0;
return NULL;
}
DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
- running=0;
+ running = 0;
return NULL;
}
@@ -1222,7 +1130,7 @@
if (rt > 0) {
if (tech_pvt->SkypiaxHandles.fdesc[0]) {
howmany = sizeof(read_from_pipe);
-#if defined(WIN32) && !defined(__CYGWIN__)
+#if defined(WIN32) && !defined(__CYGWIN__)
skypiax_file_read(tech_pvt->SkypiaxHandles.fdesc[0], read_from_pipe, &howmany);
#else /* WIN32 */
howmany =
@@ -1322,7 +1230,9 @@
if (!strcasecmp(id, tech_pvt->skype_user)) {
tech_pvt->SkypiaxHandles.api_connected = 1;
- DEBUGA_SKYPE ("Skype MSG: messaggio: %s, currentuserhandle: %s, cuh: %s, skype_user: %s!\n", SKYPIAX_P_LOG, messaggio, obj, id, tech_pvt->skype_user);
+ DEBUGA_SKYPE
+ ("Skype MSG: messaggio: %s, currentuserhandle: %s, cuh: %s, skype_user: %s!\n",
+ SKYPIAX_P_LOG, messaggio, obj, id, tech_pvt->skype_user);
}
}
@@ -1438,11 +1348,11 @@
tech_pvt->interface_state = SKYPIAX_STATE_PRERING;
}
- if (!strcasecmp(prop, "DTMF")) {
+ if (!strcasecmp(prop, "DTMF")) {
DEBUGA_SKYPE("Call %s received a DTMF: %s\n", SKYPIAX_P_LOG, id, value);
- dtmf_received(tech_pvt, value);
+ dtmf_received(tech_pvt, value);
}
if (!strcasecmp(prop, "FAILUREREASON")) {
@@ -1596,7 +1506,7 @@
strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
DEBUGA_SKYPE("skype_call: %s is now UNPLACED\n", SKYPIAX_P_LOG, id);
} else if (!strcasecmp(value, "INPROGRESS")) {
- char msg_to_skype[1024];
+ char msg_to_skype[1024];
tech_pvt->skype_callflow = CALLFLOW_STATUS_INPROGRESS;
strncpy(tech_pvt->skype_call_id, id, sizeof(tech_pvt->skype_call_id) - 1);
tech_pvt->interface_state = SKYPIAX_STATE_UP;
@@ -1607,29 +1517,29 @@
DEBUGA_SKYPE("skype_call: %s SKYPIAX_CONTROL_ANSWER sent\n",
SKYPIAX_P_LOG, id);
- start_audio_threads(tech_pvt);
+ start_audio_threads(tech_pvt);
+
+ sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id,
+ tech_pvt->tcp_srv_port);
+ skypiax_skype_write(tech_pvt, msg_to_skype);
+ skypiax_sleep(100000);
+ sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id,
+ tech_pvt->tcp_cli_port);
+ skypiax_skype_write(tech_pvt, msg_to_skype);
+ skypiax_sleep(100000);
- sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"%d\"", id,
- tech_pvt->tcp_srv_port);
- skypiax_skype_write(tech_pvt, msg_to_skype);
- skypiax_sleep(100000);
- sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"%d\"", id,
- tech_pvt->tcp_cli_port);
- skypiax_skype_write(tech_pvt, msg_to_skype);
- skypiax_sleep(100000);
-
tech_pvt->skype_callflow = SKYPIAX_STATE_UP;
if (!strlen(tech_pvt->session_uuid_str)) {
DEBUGA_SKYPE("New Inbound Channel!\n", SKYPIAX_P_LOG);
- new_inbound_channel(tech_pvt);
- } else {
+ new_inbound_channel(tech_pvt);
+ } else {
DEBUGA_SKYPE("Outbound Channel Answered!\n", SKYPIAX_P_LOG);
- outbound_channel_answered(tech_pvt);
+ outbound_channel_answered(tech_pvt);
}
} else {
@@ -1700,4 +1610,3 @@
//FIXME ast_queue_control(tech_pvt->owner, SKYPIAX_CONTROL_RINGING);
return 0;
}
-
More information about the Freeswitch-branches
mailing list