[Freeswitch-branches] [commit] r10609 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
Author: gmaruzz Date: Fri Dec 5 02:25:00 2008 New Revision: 10609 Log: skypiax: cleaner Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.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 5 02:25:00 2008 @@ -58,7 +58,6 @@ #define WARNINGA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][WARNINGA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); #define NOTICA(...) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "rev "SKYPIAX_SVN_VERSION "[%p|%-7lx][NOTICA %-5d][%-10s][%2d,%2d,%2d] " __VA_ARGS__ ); -//#define SKYPIAX_P_LOG p ? p->owner : NULL, (unsigned long)pthread_self(), __LINE__, p ? p->name ? p->name : "none" : "none", p ? p->owner ? p->owner->_state : -1 : -1, p ? p->interface_state : -1, p ? p->skype_callflow : -1 #define SKYPIAX_P_LOG NULL, (unsigned long)55, __LINE__, p ? p->name ? p->name : "none" : "none", -1, p ? p->interface_state : -1, p ? p->skype_callflow : -1 /*********************************/ @@ -351,13 +350,9 @@ strncpy(msg_from_skype, (const char *) poCopyData->lpData, sizeof(msg_from_skype) - 2); - //howmany = strlen((const char *) poCopyData->lpData); howmany = strlen(msg_from_skype) + 1; - //switch_file_write(win32_AsteriskHandlesSkype->fdesc[1], (const char *) poCopyData->lpData, &howmany); switch_file_write(win32_AsteriskHandlesSkype->fdesc[1], msg_from_skype, &howmany); NOTICA("From Skype API: %s\n", SKYPIAX_P_LOG, (const char *) poCopyData->lpData); - //howmany=1; - //switch_file_write(win32_AsteriskHandlesSkype->fdesc[1], "\0", &howmany); lReturnCode = 1; } break; @@ -463,7 +458,6 @@ DWORD win32_dwThreadId; -//void *do_skype_thread(void *data) static void *SWITCH_THREAD_FUNC do_skype_thread(switch_thread_t * thread, void *obj) { /* create window class */ @@ -475,15 +469,6 @@ /* destroy main window */ /* destroy window class */ -#if 0 - res = pipe(p->AsteriskHandlesAst.fdesc); - if (res) { - ERRORA("Unable to create skype pipe, exiting skype thread\n", SKYPIAX_P_LOG); - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); - return NULL; - } -#endif //0 - struct skypiax_interface *p; p = obj; @@ -560,110 +545,6 @@ } -#undef PORTAUDIO_ENGAGE -#ifdef PORTAUDIO_ENGAGE -static switch_status_t engage_device(int sample_rate, int codec_ms) -{ - PaStreamParameters inputParameters, outputParameters; - PaError err; - - if (!globals.audio_stream) { - if (!sample_rate) { - sample_rate = globals.sample_rate; - } - if (!codec_ms) { - codec_ms = globals.codec_ms; - } - - if (!globals.read_codec.implementation) { - if (switch_core_codec_init - (&globals.read_codec, "L16", NULL, sample_rate, codec_ms, 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, - NULL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); - return SWITCH_STATUS_FALSE; - } - } - - switch_assert(globals.read_codec.implementation); - - if (!globals.write_codec.implementation) { - if (switch_core_codec_init - (&globals.write_codec, "L16", NULL, sample_rate, codec_ms, 1, - SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, - NULL) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); - switch_core_codec_destroy(&globals.read_codec); - return SWITCH_STATUS_FALSE; - } - } - - if (!globals.timer.timer_interface) { - if (switch_core_timer_init - (&globals.timer, globals.timer_name, codec_ms, - globals.read_codec.implementation->samples_per_packet, - module_pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n"); - switch_core_codec_destroy(&globals.read_codec); - switch_core_codec_destroy(&globals.write_codec); - return SWITCH_STATUS_FALSE; - } - } - - if (!globals.hold_timer.timer_interface) { - if (switch_core_timer_init - (&globals.hold_timer, globals.timer_name, codec_ms, - globals.read_codec.implementation->samples_per_packet, - module_pool) != SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, - "setup hold timer failed!\n"); - switch_core_codec_destroy(&globals.read_codec); - switch_core_codec_destroy(&globals.write_codec); - switch_core_timer_destroy(&globals.timer); - return SWITCH_STATUS_FALSE; - } - } - - globals.read_frame.rate = sample_rate; - globals.read_frame.codec = &globals.read_codec; - - switch_mutex_lock(globals.device_lock); - /* LOCKED ************************************************************************************************** */ - inputParameters.device = globals.indev; - inputParameters.channelCount = 1; - inputParameters.sampleFormat = SAMPLE_TYPE; - inputParameters.suggestedLatency = - Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency; - inputParameters.hostApiSpecificStreamInfo = NULL; - - outputParameters.device = globals.outdev; - outputParameters.channelCount = 1; - outputParameters.sampleFormat = SAMPLE_TYPE; - outputParameters.suggestedLatency = - Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency; - outputParameters.hostApiSpecificStreamInfo = NULL; - err = - OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, - sample_rate, paClipOff, - globals.read_codec.implementation->samples_per_packet); - /* UNLOCKED ************************************************************************************************* */ - switch_mutex_unlock(globals.device_lock); - - if (err != paNoError) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, - "Can't open audio device!\n"); - switch_core_codec_destroy(&globals.read_codec); - switch_core_codec_destroy(&globals.write_codec); - switch_core_timer_destroy(&globals.timer); - switch_core_timer_destroy(&globals.hold_timer); - return SWITCH_STATUS_FALSE; - } - } - - return SWITCH_STATUS_SUCCESS; -} -#endif // PORTAUDIO_ENGAGE - #define SKYPE_AUDIO #ifdef SKYPE_AUDIO @@ -676,7 +557,6 @@ struct skypiax_interface *p = obj; short in[GG]; short out[GG / 2]; - //int s, fd, len, sent; int s, fd, len; unsigned int sin_size; struct sockaddr_in my_addr; @@ -692,7 +572,6 @@ } memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; - //my_addr.sin_addr.s_addr = INADDR_ANY; my_addr.sin_addr.s_addr = htonl(0x7f000001); /* use the localhost */ my_addr.sin_port = htons(5556); //FIXME configurable! @@ -769,8 +648,6 @@ howmany = len; switch_file_write(p->audiopipe[1], totalbuf, &howmany); - //howmany = len/2; - //switch_file_write(p->audiopipe[1], out, &howmany); p->audiobuf_is_loaded = 0; //DEBUGA_SKYPE("read=====> req=%d recv=%d to sent=%d sent=%d\n", SKYPIAX_P_LOG, sizeof(short)*GG, len, (len*sizeof(short))/2, howmany); } @@ -797,7 +674,6 @@ switch_file_write(p->audioskypepipe[1], kill_cli_buff, &kill_cli_size); DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG); - //switch_sleep(1000000); #ifndef WIN32_SKYPIAX close(fd); @@ -833,14 +709,12 @@ int a; int i; unsigned int got; - //int exit=0; if (option_debug > 10) { WARNINGA("ENTERING FUNC\n", SKYPIAX_P_LOG); } memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; - //my_addr.sin_addr.s_addr = INADDR_ANY; my_addr.sin_addr.s_addr = htonl(0x7f000001); /* use the localhost */ my_addr.sin_port = htons(5558); //FIXME configurable! @@ -871,7 +745,6 @@ sin_size = sizeof(remote_addr); while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) { DEBUGA_SKYPE("ACCEPTED\n", SKYPIAX_P_LOG); - //while (1 && p->owner && p->owner->_state == SKYPIAX_STATE_UP) FIXME FIXME FIXME while (p->interface_state != SKYPIAX_STATE_DOWN && (p->skype_callflow == CALLFLOW_STATUS_INPROGRESS || p->skype_callflow == SKYPIAX_STATE_UP)) { @@ -880,21 +753,16 @@ fd_set fs; struct timeval to; - //exit=1; - - //fdselect = p->audioskypepipe[0]; fdselect = 1; FD_ZERO(&fs); FD_SET(fdselect, &fs); to.tv_usec = 100; to.tv_sec = 0; - //rt = select(fdselect + 1, &fs, NULL, NULL, &to); rt = 1; if (rt > 0) { got = (NN / 2) * sizeof(short); switch_file_read(p->audioskypepipe[0], in, &got); - //ERRORA("got %d\n", SKYPIAX_P_LOG, got); if (got > 0) { a = 0; @@ -924,7 +792,6 @@ #else closesocket(fd); #endif - //if (exit) break; } @@ -943,63 +810,18 @@ int skypiax_skypeaudio_init(struct skypiax_interface *p) { -//switch_file_t *readp = NULL; -//switch_file_t *writep = NULL; - switch_status_t rv; - //rv = switch_file_pipe_create_ex(&readp, &writep, APR_FULL_NONBLOCK, module_pool); rv = switch_file_pipe_create_ex(&p->audiopipe[0], &p->audiopipe[1], 2, module_pool); rv = switch_file_pipe_timeout_set(p->audiopipe[0], 100000); - //rv = switch_file_pipe_timeout_set(p->audiopipe[1], 10000); - //rv = switch_file_pipe_create(&readp, &writep, module_pool); - - //FIXME int c; -#if 0 -/* build the pipe that will be polled on by pbx */ - c = pipe(p->audiopipe); - if (c) { - ERRORA("Unable to create audio pipe\n", SKYPIAX_P_LOG); - if (option_debug > 10) { - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); - } - return -1; - } -#endif /* the pipe is our audio fd for pbx to poll on */ p->skypiax_sound_capt_fd = p->audiopipe[0]; - /* let's start the serial monitoring thread too, so we can have serial signaling */ - -/* - if (ast_pthread_create(&p->tcp_srv_thread, NULL, skypiax_do_tcp_srv_thread, p) < 0) { - ERRORA("Unable to start tcp_srv_thread thread.\n", SKYPIAX_P_LOG); - if (option_debug > 10) { - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); - } - return -1; - } -*/ - rv = switch_file_pipe_create_ex(&p->audioskypepipe[0], &p->audioskypepipe[1], 2, module_pool); rv = switch_file_pipe_timeout_set(p->audioskypepipe[0], 100); - //rv = switch_file_pipe_timeout_set(p->audioskypepipe[1], 10000); -#ifdef NOTDEF_WIN32_SKYPIAX - c = pipe(p->audioskypepipe); - if (c) { - ERRORA("Unable to create audioskypepipe\n", SKYPIAX_P_LOG); - if (option_debug > 10) { - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); - } - return -1; - } - fcntl(p->audioskypepipe[0], F_SETFL, O_NONBLOCK); - fcntl(p->audioskypepipe[1], F_SETFL, O_NONBLOCK); -#endif // WIN32_SKYPIAX - if (option_debug > 10) { DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } @@ -1010,10 +832,7 @@ struct skypiax_interface *p; short buf[640]; unsigned int samples; - //int fd; int rt; - //fd_set fs; - //struct timeval to; p = tech_pvt->p; @@ -1021,14 +840,6 @@ memset(buf, '\0', sizeof(buf)); -#if 0 - fd = p->audiopipe[0]; - FD_ZERO(&fs); - FD_SET(fd, &fs); - to.tv_usec = 100000; - to.tv_sec = 0; - rt = select(fd + 1, &fs, NULL, NULL, &to); -#endif rt = 1; if (rt > 0) { @@ -1041,7 +852,6 @@ if (samples) DEBUGA_SKYPE("read=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG, samples, SAMPLES_PER_FRAME * sizeof(short)); - //switch_sleep(1000); //do nothing } else { tech_pvt->read_frame.datalen = samples; @@ -1058,63 +868,10 @@ return SWITCH_STATUS_SUCCESS; } -#if 0 -//cicopet -struct ast_frame *skypiax_skypeaudio_read(struct skypiax_interface *p) -{ - static struct ast_frame f; - static short __buf[SKYPIAX_FRAME_SIZE + SKYPIAX_FRIENDLY_OFFSET / 2]; - short *buf; - int samples; - - if (option_debug > 100) { - DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); - } - memset(__buf, '\0', (SKYPIAX_FRAME_SIZE + SKYPIAX_FRIENDLY_OFFSET / 2)); - - buf = __buf + SKYPIAX_FRIENDLY_OFFSET / 2; - - f.frametype = SKYPIAX_FRAME_NULL; - f.subclass = 0; - f.samples = 0; - f.datalen = 0; - f.data = NULL; - f.offset = 0; - f.src = skypiax_type; - f.mallocd = 0; - f.delivery.tv_sec = 0; - f.delivery.tv_usec = 0; - - if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320) { - DEBUGA_SOUND("read=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG, samples, - SAMPLES_PER_FRAME * sizeof(short)); - switch_sleep(100); - //do nothing - } else { - //DEBUGA_SOUND("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples); - /* A real frame */ - f.frametype = SKYPIAX_FRAME_VOICE; - f.subclass = SKYPIAX_FORMAT_SLINEAR; - f.samples = SKYPIAX_FRAME_SIZE; - f.datalen = SKYPIAX_FRAME_SIZE * 2; - f.data = buf; - f.offset = SKYPIAX_FRIENDLY_OFFSET; - f.src = skypiax_type; - f.mallocd = 0; - } - - if (option_debug > 100) { - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); - } - return &f; -} -#endif //0 - #endif /* SKYPE_AUDIO */ static void tech_init(private_t * tech_pvt, switch_core_session_t * session, skypiax_interface_t * p) { - //struct skypiax_interface *p = NULL; DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); tech_pvt->read_frame.data = tech_pvt->databuf; @@ -1224,9 +981,6 @@ switch_clear_flag_locked(tech_pvt, TFLAG_IO); switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); switch_set_flag_locked(tech_pvt, TFLAG_HANGUP); - //switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CHANNEL after TFLAG_HUP\n"); - //switch_thread_cond_signal(tech_pvt->cond); break; case SWITCH_SIG_BREAK: switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, @@ -1268,8 +1022,6 @@ { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - //switch_time_t started = switch_time_now(); - //unsigned int elapsed; switch_byte_t *data; channel = switch_core_session_get_channel(session); @@ -1304,26 +1056,6 @@ "CHANNEL READ FRAME not IO\n"); return SWITCH_STATUS_FALSE; } -#if 0 - if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320) { - DEBUGA_SOUND("read=====> NOT GOOD samples=%d expected=%d\n", SKYPIAX_P_LOG, samples, - SAMPLES_PER_FRAME * sizeof(short)); - switch_sleep(100); - //do nothing - } else { - //DEBUGA_SOUND("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples); - /* A real frame */ - f.frametype = SKYPIAX_FRAME_VOICE; - f.subclass = SKYPIAX_FORMAT_SLINEAR; - f.samples = SKYPIAX_FRAME_SIZE; - f.datalen = SKYPIAX_FRAME_SIZE * 2; - f.data = buf; - f.offset = SKYPIAX_FRIENDLY_OFFSET; - f.src = skypiax_type; - f.mallocd = 0; - } -#endif - //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "============>\n"); if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) { @@ -1367,7 +1099,6 @@ { switch_channel_t *channel = NULL; private_t *tech_pvt = NULL; - //switch_frame_t *pframe; unsigned int sent; struct skypiax_interface *p = NULL; @@ -1400,225 +1131,6 @@ } -#if 0 -switch_file_t *readp = NULL; -switch_file_t *writep = NULL; - -void create_pipe(void *data) -{ - switch_status_t rv; - - //rv = switch_file_pipe_create_ex(&readp, &writep, APR_FULL_NONBLOCK, module_pool); - rv = switch_file_pipe_create_ex(&readp, &writep, 2, module_pool); - //rv = switch_file_pipe_create(&readp, &writep, module_pool); -} - -#if 0 -//testpipe.c - -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <stdlib.h> - -#include "testutil.h" -#include "apr_file_io.h" -#include "apr_errno.h" -#include "apr_general.h" -#include "apr_lib.h" -#include "apr_thread_proc.h" -#include "apr_strings.h" - -static apr_file_t *readp = NULL; -static apr_file_t *writep = NULL; - -static void create_pipe(abts_case * tc, void *data) -{ - apr_status_t rv; - - rv = apr_file_pipe_create(&readp, &writep, p); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - ABTS_PTR_NOTNULL(tc, readp); - ABTS_PTR_NOTNULL(tc, writep); -} - -static void close_pipe(abts_case * tc, void *data) -{ - apr_status_t rv; - apr_size_t nbytes = 256; - char buf[256]; - - rv = apr_file_close(readp); - rv = apr_file_close(writep); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - rv = apr_file_read(readp, buf, &nbytes); - ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EBADF(rv)); -} - -static void set_timeout(abts_case * tc, void *data) -{ - apr_status_t rv; - apr_interval_time_t timeout; - - rv = apr_file_pipe_create_ex(&readp, &writep, APR_WRITE_BLOCK, p); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - ABTS_PTR_NOTNULL(tc, readp); - ABTS_PTR_NOTNULL(tc, writep); - - rv = apr_file_pipe_timeout_get(writep, &timeout); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - ABTS_ASSERT(tc, "Timeout mismatch, expected -1", timeout == -1); - - rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1)); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - rv = apr_file_pipe_timeout_get(readp, &timeout); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - ABTS_ASSERT(tc, "Timeout mismatch, expected 1 second", timeout == apr_time_from_sec(1)); -} - -static void read_write(abts_case * tc, void *data) -{ - apr_status_t rv; - char *buf; - apr_size_t nbytes; - - nbytes = strlen("this is a test"); - buf = (char *) apr_palloc(p, nbytes + 1); - - rv = apr_file_pipe_create_ex(&readp, &writep, APR_WRITE_BLOCK, p); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - ABTS_PTR_NOTNULL(tc, readp); - ABTS_PTR_NOTNULL(tc, writep); - - rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1)); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - if (!rv) { - rv = apr_file_read(readp, buf, &nbytes); - ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_TIMEUP(rv)); - ABTS_SIZE_EQUAL(tc, 0, nbytes); - } -} - -static void read_write_notimeout(abts_case * tc, void *data) -{ - apr_status_t rv; - char *buf = "this is a test"; - char *input; - apr_size_t nbytes; - - nbytes = strlen("this is a test"); - - rv = apr_file_pipe_create(&readp, &writep, p); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - ABTS_PTR_NOTNULL(tc, readp); - ABTS_PTR_NOTNULL(tc, writep); - - rv = apr_file_write(writep, buf, &nbytes); - ABTS_SIZE_EQUAL(tc, strlen("this is a test"), nbytes); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - nbytes = 256; - input = apr_pcalloc(p, nbytes + 1); - rv = apr_file_read(readp, input, &nbytes); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - ABTS_SIZE_EQUAL(tc, strlen("this is a test"), nbytes); - ABTS_STR_EQUAL(tc, "this is a test", input); -} - -static void test_pipe_writefull(abts_case * tc, void *data) -{ - int iterations = 1000; - int i; - int bytes_per_iteration = 8000; - char *buf = (char *) malloc(bytes_per_iteration); - char responsebuf[128]; - apr_size_t nbytes; - int bytes_processed; - apr_proc_t proc = { 0 }; - apr_procattr_t *procattr; - const char *args[2]; - apr_status_t rv; - apr_exit_why_e why; - - rv = apr_procattr_create(&procattr, p); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - rv = apr_procattr_io_set(procattr, APR_CHILD_BLOCK, APR_CHILD_BLOCK, APR_CHILD_BLOCK); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - rv = apr_procattr_error_check_set(procattr, 1); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - args[0] = "readchild" EXTENSION; - args[1] = NULL; - rv = apr_proc_create(&proc, TESTBINPATH "readchild" EXTENSION, args, NULL, procattr, p); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - rv = apr_file_pipe_timeout_set(proc.in, apr_time_from_sec(10)); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - rv = apr_file_pipe_timeout_set(proc.out, apr_time_from_sec(10)); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - i = iterations; - do { - rv = apr_file_write_full(proc.in, buf, bytes_per_iteration, NULL); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - } while (--i); - - free(buf); - - rv = apr_file_close(proc.in); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - - nbytes = sizeof(responsebuf); - rv = apr_file_read(proc.out, responsebuf, &nbytes); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - bytes_processed = (int) apr_strtoi64(responsebuf, NULL, 10); - ABTS_INT_EQUAL(tc, iterations * bytes_per_iteration, bytes_processed); - - ABTS_ASSERT(tc, "wait for child process", - apr_proc_wait(&proc, NULL, &why, APR_WAIT) == APR_CHILD_DONE); - - ABTS_ASSERT(tc, "child terminated normally", why == APR_PROC_EXIT); -} - -abts_suite *testpipe(abts_suite * suite) -{ - suite = ADD_SUITE(suite) - - abts_run_test(suite, create_pipe, NULL); - abts_run_test(suite, close_pipe, NULL); - abts_run_test(suite, set_timeout, NULL); - abts_run_test(suite, close_pipe, NULL); - abts_run_test(suite, read_write, NULL); - abts_run_test(suite, close_pipe, NULL); - abts_run_test(suite, read_write_notimeout, NULL); - abts_run_test(suite, test_pipe_writefull, NULL); - abts_run_test(suite, close_pipe, NULL); - - return suite; -} - -#endif - -#endif static switch_status_t channel_answer_channel(switch_core_session_t * session) { private_t *tech_pvt; @@ -1671,64 +1183,6 @@ return SWITCH_STATUS_SUCCESS; } -#if 0 -/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines - that allocate memory or you will have 1 channel with memory allocated from another channel's pool! -*/ -static switch_call_cause_t channel_outgoing_channel(switch_core_session_t * session, - switch_event_t * var_event, - switch_caller_profile_t * - outbound_profile, - switch_core_session_t ** new_session, - switch_memory_pool_t ** pool, - switch_originate_flag_t flags) -{ - if ((*new_session = switch_core_session_request(skypiax_endpoint_interface, pool)) != 0) { - private_t *tech_pvt; - switch_channel_t *channel; - switch_caller_profile_t *caller_profile; - - switch_core_session_add_stream(*new_session, NULL); - if ((tech_pvt = - (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) { - tech_pvt->p = SKYPIAX_INTERFACES[2]; //FIXME - channel = switch_core_session_get_channel(*new_session); - tech_init(tech_pvt, *new_session, NULL); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, - "Hey where is my memory pool?\n"); - switch_core_session_destroy(new_session); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - } - - if (outbound_profile) { - char name[128]; - - snprintf(name, sizeof(name), "skypiax/%s", outbound_profile->destination_number); - switch_channel_set_name(channel, name); - - caller_profile = switch_caller_profile_clone(*new_session, outbound_profile); - switch_channel_set_caller_profile(channel, caller_profile); - tech_pvt->caller_profile = caller_profile; - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Doh! no caller profile\n"); - switch_core_session_destroy(new_session); - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - } - - skypiax_skype_call(tech_pvt->p, outbound_profile->destination_number, 30); - - switch_channel_set_flag(channel, CF_OUTBOUND); - switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND); - switch_channel_set_state(channel, CS_INIT); - return SWITCH_CAUSE_SUCCESS; - } - - return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; - -} -#endif // 0 //FIXME: moved below - static switch_status_t channel_receive_event(switch_core_session_t * session, switch_event_t * event) { @@ -1908,35 +1362,13 @@ Display *disp = NULL; Window root = -1; Window win = -1; -//int res; p = obj; DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); -/* - if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) { - ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG); - if (option_debug > 10) { - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); - } - return NULL; - } -*/ - switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], 2, module_pool); -#if 0 - res = pipe(p->AsteriskHandlesAst.fdesc); - if (res) { - ERRORA("Unable to create skype pipe, exiting skype thread\n", SKYPIAX_P_LOG); - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); - return NULL; - } - fcntl(p->AsteriskHandlesAst.fdesc[0], F_SETFL, O_NONBLOCK); - fcntl(p->AsteriskHandlesAst.fdesc[1], F_SETFL, O_NONBLOCK); -#endif - AsteriskHandlesAst = &p->AsteriskHandlesAst; //disp = XOpenDisplay(getenv("DISPLAY")); disp = XOpenDisplay(p->X11_display); @@ -1978,8 +1410,6 @@ ERRORA ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG); - //p->skype = 0; - //p->skype_thread = SKYPIAX_PTHREADT_NULL; DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); return NULL; } @@ -1989,8 +1419,6 @@ ERRORA ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n", SKYPIAX_P_LOG); - //p->skype = 0; - //p->skype_thread = SKYPIAX_PTHREADT_NULL; DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); return NULL; } @@ -2005,7 +1433,6 @@ b = buffer; while (1) { - //pthread_testcancel(); XNextEvent(disp, &an_event); switch (an_event.type) { case ClientMessage: @@ -2045,13 +1472,8 @@ ERRORA ("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n", SKYPIAX_P_LOG); - //p->skype = 0; - //p->skype_thread = SKYPIAX_PTHREADT_NULL; return NULL; } - //p->skype = 0; - //p->skype_thread = SKYPIAX_PTHREADT_NULL; - //pthread_cleanup_pop(1); //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); return NULL; @@ -2117,8 +1539,6 @@ ERRORA ("Sending message failed - probably Skype crashed.\n\nPlease shutdown Skypiax (Asterisk), then restart Skype from the menu, then launch Skypiax and try again.\n", SKYPIAX_P_LOG); - //p->skype = 0; - //p->skype_thread = SKYPIAX_PTHREADT_NULL; if (option_debug > 100) { DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } @@ -2153,21 +1573,11 @@ if (option_debug > 100) { DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); } - //DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); -//switch_sleep(1000000); memset(read_from_pipe, 0, 4096); memset(messaggio, 0, 4096); memset(messaggio_2, 0, 4096); -#if 0 - fd = p->AsteriskHandlesAst.fdesc[0]; - FD_ZERO(&fs); - FD_SET(fd, &fs); - to.tv_usec = 100; - to.tv_sec = 0; - rt = select(fd + 1, &fs, NULL, NULL, &to); -#endif rt = 1; if (rt > 0) { howmany = sizeof(read_from_pipe); @@ -2184,18 +1594,6 @@ DEBUGA_SKYPE("read_skype: howmany=%d, i=%d, a=%d, |||%s||| \n", SKYPIAX_P_LOG, howmany, i, a, messaggio); -#if 0 //FIXME wat's the use of this? - if (!strcasecmp(messaggio, "ERROR 68")) { /* not yet protocol specified, - just authorized */ - NOTICA - ("Please give the Skype client authorization to be connected by Skypiax (and to not ask you again)\n", - SKYPIAX_P_LOG); - sleep(1); - skypiax_skype_write(p, "PROTOCOL 6"); - switch_sleep(10000); - } -#endif - if (!strncasecmp(messaggio, "ERROR 92 CALL", 12)) { ERRORA("Skype got ERROR: |||%s|||, the number we called was not recognized\n", SKYPIAX_P_LOG, messaggio); @@ -2209,8 +1607,6 @@ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } p->interface_state = SKYPIAX_STATE_DOWN; - //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else { p->interface_state = SKYPIAX_STATE_DOWN; @@ -2256,9 +1652,6 @@ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } p->interface_state = SKYPIAX_STATE_DOWN; - //FIXME if(p->owner){ - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; - //FIXME } return CALLFLOW_INCOMING_HANGUP; } else { p->interface_state = SKYPIAX_STATE_DOWN; @@ -2318,7 +1711,6 @@ private_t *tech_pvt = NULL; switch_channel_t *channel = NULL; - //FIXME struct ast_frame f2 = { SKYPIAX_FRAME_DTMF, value[0], }; DEBUGA_SKYPE("Call %s received a DTMF: %s\n", SKYPIAX_P_LOG, id, value); tech_pvt = p->tech_pvt; @@ -2337,11 +1729,9 @@ switch_set_flag(tech_pvt, TFLAG_DTMF); switch_mutex_unlock(tech_pvt->flag_mutex); } - //FIXME ast_queue_frame(p->owner, &f2); } if (!strcasecmp(prop, "FAILUREREASON")) { - /* if (option_debug > 1) */ DEBUGA_SKYPE ("Skype has FAILED on skype_call %s. Let's wait for the FAILED message.\n", SKYPIAX_P_LOG, id); @@ -2363,7 +1753,6 @@ if (p->interface_state != SKYPIAX_STATE_DIALING) { /* we are not calling out */ - //FIXME if (!p->owner) if (1) { /* we are not inside an active call */ p->skype_callflow = CALLFLOW_STATUS_RINGING; @@ -2425,8 +1814,6 @@ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } //p->interface_state = SKYPIAX_STATE_DOWN; - //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else { p->interface_state = SKYPIAX_STATE_DOWN; @@ -2445,8 +1832,6 @@ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } p->interface_state = SKYPIAX_STATE_DOWN; - //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else { p->interface_state = SKYPIAX_STATE_DOWN; @@ -2463,8 +1848,6 @@ if (option_debug > 100) { DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } - //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else if (!strcasecmp(value, "REFUSED")) { if (!strcasecmp(id, p->skype_call_id)) { @@ -2480,8 +1863,6 @@ if (option_debug > 100) { DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } - //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else { /* we're here because were us that refused an incoming call */ @@ -2505,57 +1886,30 @@ if (option_debug > 1) DEBUGA_SKYPE("skype_call: %s is now active\n", SKYPIAX_P_LOG, id); - //FIXME if (p->owner) { - //FIXME ast_queue_control(p->owner, SKYPIAX_CONTROL_ANSWER); - //FIXME } if (option_debug > 1) DEBUGA_SKYPE("skype_call: %s SKYPIAX_CONTROL_ANSWER sent\n", SKYPIAX_P_LOG, id); - //FIXME if (p->owner) - if (1) { char msg_to_skype[1024]; -#if 0 - if (!p->tcp_srv_thread) { - if (1) { -#endif - //switch_thread_t *thread; - if (1) { - switch_threadattr_t *thd_attr = NULL; - - switch_threadattr_create(&thd_attr, module_pool); - switch_threadattr_detach_set(thd_attr, 1); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_thread_create(&p->tcp_srv_thread, thd_attr, - skypiax_do_tcp_srv_thread, p, module_pool); - DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG); -#if 0 - } - } -#endif - -#if 0 - if (!p->tcp_cli_thread) { - if (1) { -#endif - //switch_thread_t *thread; - //switch_threadattr_t *thd_attr = NULL; - - switch_threadattr_create(&thd_attr, module_pool); - switch_threadattr_detach_set(thd_attr, 1); - switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); - switch_thread_create(&p->tcp_cli_thread, thd_attr, - skypiax_do_tcp_cli_thread, p, module_pool); - DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG); - } -#if 0 - } + if (1) { + switch_threadattr_t *thd_attr = NULL; + switch_threadattr_create(&thd_attr, module_pool); + switch_threadattr_detach_set(thd_attr, 1); + switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + switch_thread_create(&p->tcp_srv_thread, thd_attr, + skypiax_do_tcp_srv_thread, p, module_pool); + DEBUGA_SKYPE("started tcp_srv_thread thread.\n", SKYPIAX_P_LOG); + + switch_threadattr_create(&thd_attr, module_pool); + switch_threadattr_detach_set(thd_attr, 1); + switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); + switch_thread_create(&p->tcp_cli_thread, thd_attr, + skypiax_do_tcp_cli_thread, p, module_pool); + DEBUGA_SKYPE("started tcp_cli_thread thread.\n", SKYPIAX_P_LOG); } -#endif - switch_sleep(100000); sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"5556\"", id); skypiax_skype_write(p, msg_to_skype); @@ -2618,27 +1972,6 @@ "Error spawning thread\n"); switch_core_session_destroy(&session); } -#if 0 - if (iax_set_codec - (tech_pvt, iaxevent->session, &iaxevent->ies.format, - &iaxevent->ies.capability, &iaxevent->ies.samprate, - IAX_SET) != SWITCH_STATUS_SUCCESS) { - iax_reject(iaxevent->session, "Codec Error!"); - switch_core_session_destroy(&session); - } else { - tech_pvt->iax_session = iaxevent->session; - tech_pvt->session = session; - iax_accept(tech_pvt->iax_session, tech_pvt->codec); - iax_ring_announce(tech_pvt->iax_session); - switch_channel_set_state(channel, CS_INIT); - if (switch_core_session_thread_launch(session) != - SWITCH_STATUS_SUCCESS) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, - "Error spawning thread\n"); - switch_core_session_destroy(&session); - } - } -#endif //0 } } else { switch_core_session_t *session = NULL; @@ -2693,18 +2026,10 @@ strncpy(rdest, "echo123", sizeof(rdest) - 1); if (option_debug) DEBUGA_SKYPE("Calling Skype, rdest is: %s\n", SKYPIAX_P_LOG, rdest); - //skypiax_skype_write(p, "GET AGC"); - //switch_sleep(10000); skypiax_skype_write(p, "SET AGC OFF"); switch_sleep(10000); - //skypiax_skype_write(p, "GET AGC"); - //switch_sleep(10000); - //skypiax_skype_write(p, "GET AEC"); - //switch_sleep(10000); skypiax_skype_write(p, "SET AEC OFF"); switch_sleep(10000); - //skypiax_skype_write(p, "GET AEC"); - //switch_sleep(300000); sprintf(msg_to_skype, "CALL %s", rdest); if (skypiax_skype_write(p, msg_to_skype) < 0) { @@ -2716,11 +2041,7 @@ return -1; } global_session = session; - //p->skype_call_ongoing = 1; - //if (p->owner) { - //ast_setstate(p->owner, SKYPIAX_STATE_RINGING); - //} //FIXME ast_queue_control(p->owner, SKYPIAX_CONTROL_RINGING); return 0; } @@ -2785,7 +2106,6 @@ */ static void *SWITCH_THREAD_FUNC skypiax_do_controldev_thread(switch_thread_t * thread, void *obj) -//void *skypiax_do_controldev_thread(void *data) { struct skypiax_interface *p = obj; int res; @@ -2805,8 +2125,6 @@ private_t *tech_pvt; switch_channel_t *channel; - //p->interface_state=SKYPIAX_STATE_DOWN; - //if (option_debug) DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG); tech_pvt = p->tech_pvt; @@ -2815,8 +2133,6 @@ channel = switch_core_session_get_channel(session); DEBUGA_SKYPE("before channel_on_hangup\n", SKYPIAX_P_LOG); - //switch_channel_set_state(channel, CS_HANGUP); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); DEBUGA_SKYPE("after channel_on_hangup\n", SKYPIAX_P_LOG);
participants (1)
-
FreeSWITCH SVN