#include "skypiax.h"
#define MDL_CHAT_PROTO "skype"
-#define TIMERS_ON
-#ifdef TIMERS_ON
#define TIMER_WRITE
-#else
-#undef TIMER_WRITE
-#endif
#ifdef WIN32
/***************/
return SWITCH_STATUS_FALSE;
}
-#ifdef TIMERS_ON
if (switch_core_timer_init(&tech_pvt->timer_read, "soft", 20, tech_pvt->read_codec.implementation->samples_per_packet, skypiax_module_pool) !=
SWITCH_STATUS_SUCCESS) {
ERRORA("setup timer failed\n", SKYPIAX_P_LOG);
}
switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
#ifdef TIMER_WRITE
if (switch_core_timer_init(&tech_pvt->timer_write, "soft", 20, tech_pvt->write_codec.implementation->samples_per_packet, skypiax_module_pool) !=
switch_core_codec_destroy(&tech_pvt->write_codec);
}
-#ifdef TIMERS_ON
switch_core_timer_destroy(&tech_pvt->timer_read);
-#endif// TIMERS_ON
#ifdef TIMER_WRITE
switch_core_timer_destroy(&tech_pvt->timer_write);
switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL;
switch_byte_t *data;
-//unsigned int len;
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
//switch_core_timer_next(&tech_pvt->timer_read);
- if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
- tech_pvt->read_frame.datalen = recv(tech_pvt->readfd, (char *) tech_pvt->read_frame.data, 320, 0); //seems that Skype only sends 320 bytes at time
- } else {
- tech_pvt->read_frame.datalen = 0;
- }
-
- //if (!skypiax_audio_read(tech_pvt)) {
- if (!tech_pvt->read_frame.datalen) {
+ if (!skypiax_audio_read(tech_pvt)) {
ERRORA("skypiax_audio_read ERROR\n", SKYPIAX_P_LOG);
DEBUGA_SKYPE("CHANNEL READ CONTINUE\n", SKYPIAX_P_LOG);
continue;
}
-#ifdef TIMERS_ON
switch_core_timer_check(&tech_pvt->timer_read, SWITCH_TRUE);
-#endif// TIMERS_ON
*frame = &tech_pvt->read_frame;
#if SWITCH_BYTE_ORDER == __BIG_ENDIAN
if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
{
switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL;
- unsigned int sent=0;
+ unsigned int sent;
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
}
#endif
-#if 0
sent = frame->datalen;
#ifdef WIN32
//switch_file_write(tech_pvt->audiopipe_cli[1], frame->data, &sent);
#else /* WIN32 */
//sent = write(tech_pvt->audiopipe_cli[1], frame->data, sent);
#endif /* WIN32 */
- //if (tech_pvt->flag_audio_cli == 0) {
+ if (tech_pvt->flag_audio_cli == 1) {
+ switch_sleep(1000); //1 millisec
+ }
+ if (tech_pvt->flag_audio_cli == 0) {
#ifdef TIMER_WRITE
switch_core_timer_next(&tech_pvt->timer_write);
#endif // TIMER_WRITE
- //while (tech_pvt->flag_audio_cli == 1) {
- //switch_sleep(1000); //10 millisec
- //WARNINGA("write now is 1\n", SKYPIAX_P_LOG);
- //}
- switch_mutex_lock(tech_pvt->flag_audio_cli_mutex);
memcpy(tech_pvt->audiobuf_cli, frame->data, frame->datalen);
tech_pvt->flag_audio_cli = 1;
- switch_mutex_unlock(tech_pvt->flag_audio_cli_mutex);
- //}
+ }
//NOTICA("write \n", SKYPIAX_P_LOG);
-#endif //0
-#ifdef TIMER_WRITE
-/* NONBLOCKING ? */
- switch_core_timer_next(&tech_pvt->timer_write);
- //switch_core_timer_check(&tech_pvt->timer_write, SWITCH_TRUE);
-#endif // TIMER_WRITE
- /* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
- if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
- sent = send(tech_pvt->writefd, (char *) frame->data, frame->datalen, 0);
- if (sent == -1) {
- ERRORA("EXIT? sent=%d\n", SKYPIAX_P_LOG, sent);
- } else if (sent != frame->datalen) {
- ERRORA("sent=%d\n", SKYPIAX_P_LOG, sent);
- }
- }
-
-
-#ifdef TIMER_WRITE
-/* BLOCKING ? */
- //switch_core_timer_check(&tech_pvt->timer_write, SWITCH_TRUE);
-#endif // TIMER_WRITE
if (sent != frame->datalen && sent != -1) {
DEBUGA_SKYPE("CLI PIPE write %d\n", SKYPIAX_P_LOG, sent);
}
{
DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id);
-#ifdef TIMERS_ON
switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
#ifdef TIMER_WRITE
switch_core_timer_sync(&tech_pvt->timer_write);
#endif // TIMER_WRITE
DEBUGA_SKYPE("%s CHANNEL got SWITCH_MESSAGE_INDICATE_AUDIO_SYNC\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
-#ifdef TIMERS_ON
switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
#ifdef TIMER_WRITE
switch_core_timer_sync(&tech_pvt->timer_write);
#endif // TIMER_WRITE
default:
{
-#ifdef TIMERS_ON
switch_core_timer_sync(&tech_pvt->timer_read);
-#endif// TIMERS_ON
#ifdef TIMER_WRITE
switch_core_timer_sync(&tech_pvt->timer_write);
skypiax_audio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
- switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].flag_audio_srv_mutex, SWITCH_MUTEX_NESTED, skypiax_module_pool);
- switch_mutex_init(&globals.SKYPIAX_INTERFACES[interface_id].flag_audio_cli_mutex, SWITCH_MUTEX_NESTED, skypiax_module_pool);
NOTICA
("WAITING roughly 10 seconds to find a running Skype client and connect to its SKYPE API for interface_id=%d\n",
SKYPIAX_P_LOG, interface_id);
start_port = *which_port;
my_addr.sin_port = htons(start_port);
-/* NONBLOCKING ? */
//fcntl(s, F_SETFL, O_NONBLOCK);
-
+ //tech_pvt->tcp_cli_port = start_port;
*which_port = start_port;
while (bind(s, (struct sockaddr *) &my_addr, sizeof(struct sockaddr)) < 0) {
DEBUGA_SKYPE("*which_port=%d, tech_pvt->tcp_cli_port=%d, tech_pvt->tcp_srv_port=%d\n", SKYPIAX_P_LOG, *which_port, tech_pvt->tcp_cli_port,
size = sizeof(int);
setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, size);
-
sockbufsize = 0;
size = sizeof(int);
getsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &sockbufsize, &size);
private_t *tech_pvt = obj;
int s;
unsigned int len;
- //unsigned int i;
- //unsigned int a;
+ unsigned int i;
+ unsigned int a;
#if defined(WIN32) && !defined(__CYGWIN__)
int sin_size;
#else /* WIN32 */
unsigned int sin_size;
#endif /* WIN32 */
unsigned int fd;
- //short srv_in[SAMPLES_PER_FRAME];
- //short srv_out[SAMPLES_PER_FRAME / 2];
+ short srv_in[SAMPLES_PER_FRAME];
+ short srv_out[SAMPLES_PER_FRAME / 2];
//struct sockaddr_in my_addr;
struct sockaddr_in remote_addr;
//int exit = 0;
unsigned int kill_cli_size;
short kill_cli_buff[SAMPLES_PER_FRAME];
- //short totalbuf[SAMPLES_PER_FRAME];
+ short totalbuf[SAMPLES_PER_FRAME];
int sockbufsize = 0;
unsigned int size = sizeof(int);
|| tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
|| tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
- tech_pvt->readfd = fd;
- //WARNINGA("read HERE\n", SKYPIAX_P_LOG);
- skypiax_sleep(100000);
-
-
-#ifdef NOLOOP
-
unsigned int fdselect;
int rt;
fd_set fs;
howmany = SAMPLES_PER_FRAME * sizeof(short);
- //while (tech_pvt->flag_audio_srv == 1) {
- //switch_sleep(1000); //10 millisec
- //WARNINGA("read now is 1\n", SKYPIAX_P_LOG);
- //}
- //if (tech_pvt->flag_audio_srv == 0) {
- //switch_mutex_lock(tech_pvt->flag_audio_srv_mutex);
+ if (tech_pvt->flag_audio_srv == 1) {
+ switch_sleep(1000); //1 millisec
+ }
+ if (tech_pvt->flag_audio_srv == 0) {
memcpy(tech_pvt->audiobuf_srv, totalbuf, SAMPLES_PER_FRAME * sizeof(short));
tech_pvt->flag_audio_srv = 1;
- //switch_mutex_unlock(tech_pvt->flag_audio_srv_mutex);
- //}
+ }
//NOTICA("read \n", SKYPIAX_P_LOG);
if (howmany != SAMPLES_PER_FRAME * sizeof(short)) {
ERRORA("howmany is %d, but was expected to be %d\n", SKYPIAX_P_LOG,
skypiax_sleep(10000);
}
-#endif// NOLOOP
}
/* let's send some frame in the pipes, so both tcp_cli and tcp_srv will have an occasion to die */
skypiax_sleep(2000);
DEBUGA_SKYPE("Skype incoming audio GONE\n", SKYPIAX_P_LOG);
skypiax_close_socket(fd);
- break;
}
}
}
int s;
//struct sockaddr_in my_addr;
struct sockaddr_in remote_addr;
-#ifdef NOVARS
unsigned int got;
unsigned int len;
unsigned int i;
unsigned int a;
+ unsigned int fd;
short cli_out[SAMPLES_PER_FRAME * 2];
short cli_in[SAMPLES_PER_FRAME];
-#endif// NOVARS
- unsigned int fd;
#ifdef WIN32
int sin_size;
#else
if (!(running && tech_pvt->running))
break;
-
-
-
-
while (tech_pvt->interface_state != SKYPIAX_STATE_DOWN
&& (tech_pvt->skype_callflow == CALLFLOW_STATUS_INPROGRESS
|| tech_pvt->skype_callflow == CALLFLOW_STATUS_EARLYMEDIA
|| tech_pvt->skype_callflow == CALLFLOW_STATUS_REMOTEHOLD || tech_pvt->skype_callflow == SKYPIAX_STATE_UP)) {
- tech_pvt->writefd = fd;
- //NOTICA("write HERE\n", SKYPIAX_P_LOG);
- skypiax_sleep(100000);
-#if 0
-#ifdef NOVARS
unsigned int fdselect;
int rt;
fd_set fs;
fdselect = fd;
FD_SET(fdselect, &fs);
-#endif// NOVARS
-#if 0
- rt = select(fdselect + 1, NULL, &fs, NULL, NULL);
+ //FIXME rt = select(fdselect + 1, NULL, &fs, NULL, &to);
while (tech_pvt->flag_audio_cli == 0) {
#ifdef WIN32
skypiax_sleep(100); //0.1 millisec
#else
- skypiax_sleep(1000); //10 millisec
+ skypiax_sleep(1000); //1 millisec
#endif //WIN32
- NOTICA("write now is 0\n", SKYPIAX_P_LOG);
+ //WARNINGA("write now is 0\n", SKYPIAX_P_LOG);
}
//ERRORA("write is now 1\n", SKYPIAX_P_LOG);
rt = 1;
-#endif //0
- //rt = select(fdselect + 1, NULL, &fs, NULL, NULL);
-#ifdef NOLOOP
if (rt > 0) {
int counter;
-#if 0
- while (tech_pvt->flag_audio_cli == 0) {
-#ifdef WIN32
- skypiax_sleep(100); //0.1 millisec
-#else
- skypiax_sleep(10000); //10 millisec
-#endif //WIN32
- WARNINGA("write now is 0\n", SKYPIAX_P_LOG);
- }
-#endif //0
-
+
/* until we drained the pipe to empty */
+ //for (counter = 0; counter < 10; counter++) {
for (counter = 0; counter < 1; counter++) {
/* read from the pipe the audio frame we are supposed to send out */
//got = skypiax_pipe_read(tech_pvt->audiopipe_cli[0], cli_in, SAMPLES_PER_FRAME * sizeof(short));
got = SAMPLES_PER_FRAME * sizeof(short);
- switch_mutex_lock(tech_pvt->flag_audio_cli_mutex);
memcpy(cli_in, tech_pvt->audiobuf_cli, SAMPLES_PER_FRAME * sizeof(short));
+ tech_pvt->flag_audio_cli = 0;
/* send the 16khz frame to the Skype client waiting for incoming audio to be sent to the remote party */
if (tech_pvt->skype_callflow != CALLFLOW_STATUS_REMOTEHOLD) {
len = send(fd, (char *) cli_out, got, 0);
- tech_pvt->flag_audio_cli = 0;
//skypiax_sleep(5000); //5 msec
if (len == -1) {
}
}
- switch_mutex_unlock(tech_pvt->flag_audio_cli_mutex);
} else {
WARNINGA("got is %d, but was expected to be %d\n", SKYPIAX_P_LOG, got, (int) (SAMPLES_PER_FRAME * sizeof(short)));
skypiax_sleep(1000);
}
-#endif// NOLOOP
-#endif// 0
}
DEBUGA_SKYPE("Skype outbound audio GONE\n", SKYPIAX_P_LOG);
skypiax_close_socket(fd);
- break;
}
}
}
{
unsigned int samples;
-#if 0
while (tech_pvt->flag_audio_srv == 0) {
#ifdef WIN32
skypiax_sleep(100); //0.1 millisec
#else
- skypiax_sleep(1000); //10 millisec
+ skypiax_sleep(1000); //1 millisec
#endif //WIN32
- WARNINGA("read now is 0\n", SKYPIAX_P_LOG);
+ //WARNINGA("read now is 0\n", SKYPIAX_P_LOG);
}
-#endif //0
//ERRORA("read is now 1\n", SKYPIAX_P_LOG);
//samples = skypiax_pipe_read(tech_pvt->audiopipe_srv[0], tech_pvt->read_frame.data, SAMPLES_PER_FRAME * sizeof(short));
samples = SAMPLES_PER_FRAME * sizeof(short);
- //switch_mutex_lock(tech_pvt->flag_audio_srv_mutex);
memcpy(tech_pvt->read_frame.data, tech_pvt->audiobuf_srv, SAMPLES_PER_FRAME * sizeof(short));
tech_pvt->flag_audio_srv = 0;
- //switch_mutex_unlock(tech_pvt->flag_audio_srv_mutex);
if (samples != SAMPLES_PER_FRAME * sizeof(short)) {
if (samples)