[commit] r10608 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
Author: gmaruzz Date: Fri Dec 5 02:06:43 2008 New Revision: 10608 Log: skypiax: 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/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:06:43 2008 @@ -58,11 +58,9 @@ #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 - /*********************************/ #define SKYPIAX_CAUSE_NORMAL 1 /*********************************/ @@ -111,15 +109,12 @@ /*********************************/ - - #define SKYPIAX_MAX_INTERFACES 64 SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load); SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown); //SWITCH_MODULE_RUNTIME_FUNCTION(mod_skypiax_runtime); -SWITCH_MODULE_DEFINITION(mod_skypiax, mod_skypiax_load, mod_skypiax_shutdown, NULL); //mod_skypiax_runtime); - +SWITCH_MODULE_DEFINITION(mod_skypiax, mod_skypiax_load, mod_skypiax_shutdown, NULL); //mod_skypiax_runtime); switch_endpoint_interface_t *skypiax_endpoint_interface; static switch_memory_pool_t *module_pool = NULL; @@ -142,135 +137,136 @@ #endif //WIN32_SKYPIAX - typedef enum { - TFLAG_IO = (1 << 0), - TFLAG_INBOUND = (1 << 1), - TFLAG_OUTBOUND = (1 << 2), - TFLAG_DTMF = (1 << 3), - TFLAG_VOICE = (1 << 4), - TFLAG_HANGUP = (1 << 5), - TFLAG_LINEAR = (1 << 6), - TFLAG_CODEC = (1 << 7), - TFLAG_BREAK = (1 << 8) + TFLAG_IO = (1 << 0), + TFLAG_INBOUND = (1 << 1), + TFLAG_OUTBOUND = (1 << 2), + TFLAG_DTMF = (1 << 3), + TFLAG_VOICE = (1 << 4), + TFLAG_HANGUP = (1 << 5), + TFLAG_LINEAR = (1 << 6), + TFLAG_CODEC = (1 << 7), + TFLAG_BREAK = (1 << 8) } TFLAGS; typedef enum { - GFLAG_MY_CODEC_PREFS = (1 << 0) + GFLAG_MY_CODEC_PREFS = (1 << 0) } GFLAGS; - static struct { - int debug; - char *ip; - int port; - char *dialplan; - char *codec_string; - char *codec_order[SWITCH_MAX_CODECS]; - int codec_order_last; - char *codec_rates_string; - char *codec_rates[SWITCH_MAX_CODECS]; - int codec_rates_last; - unsigned int flags; - int fd; - int calls; - char hold_music[256]; - switch_mutex_t *mutex; + int debug; + char *ip; + int port; + char *dialplan; + char *codec_string; + char *codec_order[SWITCH_MAX_CODECS]; + int codec_order_last; + char *codec_rates_string; + char *codec_rates[SWITCH_MAX_CODECS]; + int codec_rates_last; + unsigned int flags; + int fd; + int calls; + char hold_music[256]; + switch_mutex_t *mutex; } globals; struct skypiax_interface { - char interface_id[80]; - char name[80]; - char dialplan[80]; - char context[80]; - char dial_regex[256]; - char fail_dial_regex[256]; - char hold_music[256]; - char type[256]; - char X11_display[256]; - struct AsteriskHandles AsteriskHandlesAst; - - int interface_state; /*!< \brief 'state' of the interface (channel) */ - char language[80]; /*!< \brief default Asterisk dialplan language for this interface */ - char exten[80]; /*!< \brief default Asterisk dialplan extension for this interface */ - int skypiax_sound_rate; /*!< \brief rate of the sound device, in Hz, eg: 8000 */ - switch_file_t *skypiax_sound_capt_fd; /*!< \brief file descriptor for sound capture dev */ - char callid_name[50]; - char callid_number[50]; - double playback_boost; - double capture_boost; - int stripmsd; - switch_thread_t *skype_thread; - char skype_call_id[512]; - int skype_call_ongoing; - char skype_friends[4096]; - char skype_fullname[512]; - char skype_displayname[512]; - int skype_callflow; /*!< \brief 'callflow' of the skype interface (as opposed to phone interface) */ - int skype; /*!< \brief config flag, bool, Skype support on this interface (0 if false, -1 if true) */ - int control_to_send; - switch_file_t *audiopipe[2]; - switch_file_t *audioskypepipe[2]; - switch_thread_t *tcp_srv_thread; - switch_thread_t *tcp_cli_thread; - short audiobuf[160]; - int audiobuf_is_loaded; - - //int phonebook_listing; - //int phonebook_querying; - //int phonebook_listing_received_calls; - - //int phonebook_first_entry; - //int phonebook_last_entry; - //int phonebook_number_lenght; - //int phonebook_text_lenght; - FILE *phonebook_writing_fp; - int skypiax_dir_entry_extension_prefix; - void *tech_pvt; + char interface_id[80]; + char name[80]; + char dialplan[80]; + char context[80]; + char dial_regex[256]; + char fail_dial_regex[256]; + char hold_music[256]; + char type[256]; + char X11_display[256]; + struct AsteriskHandles AsteriskHandlesAst; + + int interface_state; /*!< \brief 'state' of the interface (channel) */ + char language[80]; /*!< \brief default Asterisk dialplan language for this interface */ + char exten[80]; /*!< \brief default Asterisk dialplan extension for this interface */ + int skypiax_sound_rate; /*!< \brief rate of the sound device, in Hz, eg: 8000 */ + switch_file_t *skypiax_sound_capt_fd; /*!< \brief file descriptor for sound capture dev */ + char callid_name[50]; + char callid_number[50]; + double playback_boost; + double capture_boost; + int stripmsd; + switch_thread_t *skype_thread; + char skype_call_id[512]; + int skype_call_ongoing; + char skype_friends[4096]; + char skype_fullname[512]; + char skype_displayname[512]; + int skype_callflow; /*!< \brief 'callflow' of the skype interface (as opposed to phone interface) */ + int skype; /*!< \brief config flag, bool, Skype support on this interface (0 if false, -1 if true) */ + int control_to_send; + switch_file_t *audiopipe[2]; + switch_file_t *audioskypepipe[2]; + switch_thread_t *tcp_srv_thread; + switch_thread_t *tcp_cli_thread; + short audiobuf[160]; + int audiobuf_is_loaded; + + //int phonebook_listing; + //int phonebook_querying; + //int phonebook_listing_received_calls; + + //int phonebook_first_entry; + //int phonebook_last_entry; + //int phonebook_number_lenght; + //int phonebook_text_lenght; + FILE *phonebook_writing_fp; + int skypiax_dir_entry_extension_prefix; + void *tech_pvt; }; typedef struct skypiax_interface skypiax_interface_t; static skypiax_interface_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES]; - struct private_object { - unsigned int flags; - switch_codec_t read_codec; - switch_codec_t write_codec; - switch_frame_t read_frame; - unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; - switch_core_session_t *session; - switch_caller_profile_t *caller_profile; - switch_mutex_t *mutex; - switch_mutex_t *flag_mutex; - skypiax_interface_t *p; - //switch_thread_cond_t *cond; + unsigned int flags; + switch_codec_t read_codec; + switch_codec_t write_codec; + switch_frame_t read_frame; + unsigned char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE]; + switch_core_session_t *session; + switch_caller_profile_t *caller_profile; + switch_mutex_t *mutex; + switch_mutex_t *flag_mutex; + skypiax_interface_t *p; + //switch_thread_cond_t *cond; }; typedef struct private_object private_t; - - - SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string); -SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string); +SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, + globals.codec_rates_string); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip); - - -static switch_status_t channel_on_init(switch_core_session_t *session); -static switch_status_t channel_on_hangup(switch_core_session_t *session); -static switch_status_t channel_on_routing(switch_core_session_t *session); -static switch_status_t channel_on_exchange_media(switch_core_session_t *session); -static switch_status_t channel_on_soft_execute(switch_core_session_t *session); -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); -static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id); -static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id); -static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig); +static switch_status_t channel_on_init(switch_core_session_t * session); +static switch_status_t channel_on_hangup(switch_core_session_t * session); +static switch_status_t channel_on_routing(switch_core_session_t * session); +static switch_status_t channel_on_exchange_media(switch_core_session_t * session); +static switch_status_t channel_on_soft_execute(switch_core_session_t * session); +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); +static switch_status_t channel_read_frame(switch_core_session_t * session, + switch_frame_t ** frame, switch_io_flag_t flags, + int stream_id); +static switch_status_t channel_write_frame(switch_core_session_t * session, + switch_frame_t * frame, switch_io_flag_t flags, + int stream_id); +static switch_status_t channel_kill_channel(switch_core_session_t * session, int sig); int option_debug = 100; switch_core_session_t *global_session = NULL; @@ -310,17 +306,16 @@ SKYPECONTROLAPI_ATTACH_API_AVAILABLE = 0x8001 }; - char -*strsep(char **stringp, const char *delim) + *strsep(char **stringp, const char *delim) { char *res; if (!stringp || !*stringp || !**stringp) - return (char*)0; + return (char *) 0; res = *stringp; - while(**stringp && !strchr(delim, **stringp)) + while (**stringp && !strchr(delim, **stringp)) ++(*stringp); if (**stringp) { @@ -331,8 +326,6 @@ return res; } - - LRESULT APIENTRY skypiax_skype_present(HWND hWindow, UINT uiMessage, WPARAM uiParam, LPARAM ulParam) { @@ -349,20 +342,20 @@ break; case WM_COPYDATA: if (win32_hGlobal_SkypeAPIWindowHandle == (HWND) uiParam) { - unsigned int howmany; - char msg_from_skype[2048]; - + unsigned int howmany; + char msg_from_skype[2048]; PCOPYDATASTRUCT poCopyData = (PCOPYDATASTRUCT) ulParam; - memset(msg_from_skype, '\0', sizeof(msg_from_skype)); - strncpy(msg_from_skype, (const char *) poCopyData->lpData, sizeof(msg_from_skype) -2); + memset(msg_from_skype, '\0', sizeof(msg_from_skype)); + 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); + 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; @@ -471,7 +464,7 @@ DWORD win32_dwThreadId; //void *do_skype_thread(void *data) -static void *SWITCH_THREAD_FUNC do_skype_thread(switch_thread_t *thread, void *obj) +static void *SWITCH_THREAD_FUNC do_skype_thread(switch_thread_t * thread, void *obj) { /* create window class */ /* create dummy/hidden window for processing messages */ @@ -487,14 +480,15 @@ 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; + return NULL; } #endif //0 struct skypiax_interface *p; p = obj; - switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], 2, module_pool); + switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0], + &p->AsteriskHandlesAst.fdesc[1], 2, module_pool); win32_AsteriskHandlesSkype = &p->AsteriskHandlesAst; @@ -535,146 +529,149 @@ #endif /* __CYGWIN__ */ - - #endif //WIN32_SKYPIAX - -static switch_status_t skypiax_codec(private_t *tech_pvt, int sample_rate, int codec_ms) +static switch_status_t skypiax_codec(private_t * tech_pvt, int sample_rate, int codec_ms) { - if (switch_core_codec_init(&tech_pvt->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; - } - - if (switch_core_codec_init(&tech_pvt->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(&tech_pvt->read_codec); - return SWITCH_STATUS_FALSE; - } - - tech_pvt->read_frame.rate = sample_rate; - tech_pvt->read_frame.codec = &tech_pvt->read_codec; + if (switch_core_codec_init + (&tech_pvt->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; + } + + if (switch_core_codec_init + (&tech_pvt->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(&tech_pvt->read_codec); + return SWITCH_STATUS_FALSE; + } + tech_pvt->read_frame.rate = sample_rate; + tech_pvt->read_frame.codec = &tech_pvt->read_codec; - switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec); - switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); + switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec); + switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } + #undef PORTAUDIO_ENGAGE #ifdef PORTAUDIO_ENGAGE static switch_status_t engage_device(int sample_rate, int codec_ms) { - PaStreamParameters inputParameters, outputParameters; - PaError err; + 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; - 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; - } - } + 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; + return SWITCH_STATUS_SUCCESS; } #endif // PORTAUDIO_ENGAGE - #define SKYPE_AUDIO #ifdef SKYPE_AUDIO #define SAMPLES_PER_FRAME 160 #define NN 160 #define GG 160 -static void *SWITCH_THREAD_FUNC skypiax_do_tcp_srv_thread(switch_thread_t *thread, void *obj) +static void *SWITCH_THREAD_FUNC skypiax_do_tcp_srv_thread(switch_thread_t * thread, + void *obj) { struct skypiax_interface *p = obj; short in[GG]; @@ -696,8 +693,8 @@ 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! + my_addr.sin_addr.s_addr = htonl(0x7f000001); /* use the localhost */ + my_addr.sin_port = htons(5556); //FIXME configurable! if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { ERRORA("socket Error\n", SKYPIAX_P_LOG); @@ -721,87 +718,82 @@ sin_size = sizeof(remote_addr); while ((fd = accept(s, (struct sockaddr *) &remote_addr, &sin_size)) > 0) { DEBUGA_SKYPE("ACCEPTED\n", SKYPIAX_P_LOG); - while (p->interface_state != SKYPIAX_STATE_DOWN && (p->skype_callflow == CALLFLOW_STATUS_INPROGRESS ||p->skype_callflow == SKYPIAX_STATE_UP)) { - - int fdselect; - int rt; - fd_set fs; - struct timeval to; - - exit=1; - - - - - - - fdselect = fd; - FD_ZERO(&fs); - FD_SET(fdselect, &fs); - to.tv_usec = 100; - to.tv_sec = 0; - rt = select(fdselect + 1, &fs, NULL, NULL, &to); - if (rt > 0) { - - len = recv(fd, in, sizeof(short) * GG, 0); - //DEBUGA_SKYPE("recv %d\n", SKYPIAX_P_LOG, len); - if (len > 0) { - a = 0; - for (i = 0; i < len / sizeof(short); i++) { - out[a] = in[i]; - i++; - a++; - } - - if (!p->audiobuf_is_loaded) { - for (i = 0; i < (len / sizeof(short)) / 2; i++) { - p->audiobuf[i] = out[i]; + while (p->interface_state != SKYPIAX_STATE_DOWN + && (p->skype_callflow == CALLFLOW_STATUS_INPROGRESS + || p->skype_callflow == SKYPIAX_STATE_UP)) { + + int fdselect; + int rt; + fd_set fs; + struct timeval to; + + exit = 1; + + fdselect = fd; + FD_ZERO(&fs); + FD_SET(fdselect, &fs); + to.tv_usec = 100; + to.tv_sec = 0; + rt = select(fdselect + 1, &fs, NULL, NULL, &to); + if (rt > 0) { + + len = recv(fd, in, sizeof(short) * GG, 0); + //DEBUGA_SKYPE("recv %d\n", SKYPIAX_P_LOG, len); + if (len > 0) { + a = 0; + for (i = 0; i < len / sizeof(short); i++) { + out[a] = in[i]; + i++; + a++; } - p->audiobuf_is_loaded = 1; - } else { - unsigned int howmany; + + if (!p->audiobuf_is_loaded) { + for (i = 0; i < (len / sizeof(short)) / 2; i++) { + p->audiobuf[i] = out[i]; + } + p->audiobuf_is_loaded = 1; + } else { + unsigned int howmany; short totalbuf[GG]; - howmany = len/2/2; - for(i=0; i<howmany; i++) - totalbuf[i] = p->audiobuf[i]; - - howmany = len/2/2; - for(a=0; a<howmany; a++){ - totalbuf[i] = out[a]; - i++; + howmany = len / 2 / 2; + for (i = 0; i < howmany; i++) + totalbuf[i] = p->audiobuf[i]; + + howmany = len / 2 / 2; + for (a = 0; a < howmany; a++) { + totalbuf[i] = out[a]; + i++; } 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); - } + 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); + } - } else if (len == 0) { - DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG); - break; - } else { - ERRORA("len=%d\n", SKYPIAX_P_LOG, len); - exit = 1; - break; + } else if (len == 0) { + DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG); + break; + } else { + ERRORA("len=%d\n", SKYPIAX_P_LOG, len); + exit = 1; + break; + } } - } } - - - kill_cli_size=320; + kill_cli_size = 320; switch_file_write(p->audiopipe[1], kill_cli_buff, &kill_cli_size); - kill_cli_size=320; + kill_cli_size = 320; switch_file_write(p->audioskypepipe[1], kill_cli_buff, &kill_cli_size); p->interface_state = SKYPIAX_STATE_DOWN; - kill_cli_size=320; + kill_cli_size = 320; switch_file_write(p->audiopipe[1], kill_cli_buff, &kill_cli_size); - kill_cli_size=320; + kill_cli_size = 320; switch_file_write(p->audioskypepipe[1], kill_cli_buff, &kill_cli_size); DEBUGA_SKYPE("Skype client GONE\n", SKYPIAX_P_LOG); @@ -827,7 +819,8 @@ } return NULL; } -static void *SWITCH_THREAD_FUNC skypiax_do_tcp_cli_thread(switch_thread_t *thread, void *obj) +static void *SWITCH_THREAD_FUNC skypiax_do_tcp_cli_thread(switch_thread_t * thread, + void *obj) //void *skypiax_do_tcp_cli_thread(void *data) { struct skypiax_interface *p = obj; @@ -848,8 +841,8 @@ 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! + my_addr.sin_addr.s_addr = htonl(0x7f000001); /* use the localhost */ + my_addr.sin_port = htons(5558); //FIXME configurable! if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { ERRORA("socket Error\n", SKYPIAX_P_LOG); @@ -865,9 +858,9 @@ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } #ifndef WIN32_SKYPIAX - close(s); + close(s); #else - closesocket(s); + closesocket(s); #endif return NULL; } @@ -879,54 +872,50 @@ 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)) { - int fdselect; - int rt; - 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; - for (i = 0; i < got / sizeof(short); i++) { - out[a] = in[i]; - a++; - out[a] = in[i]; - a++; - } + while (p->interface_state != SKYPIAX_STATE_DOWN + && (p->skype_callflow == CALLFLOW_STATUS_INPROGRESS + || p->skype_callflow == SKYPIAX_STATE_UP)) { + int fdselect; + int rt; + 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; + for (i = 0; i < got / sizeof(short); i++) { + out[a] = in[i]; + a++; + out[a] = in[i]; + a++; + } - len = send(fd, out, got * 2, 0); + len = send(fd, out, got * 2, 0); - if (len == 0) { - ERRORA("Skype server GONE\n", SKYPIAX_P_LOG); - break; + if (len == 0) { + ERRORA("Skype server GONE\n", SKYPIAX_P_LOG); + break; + } + } else { + switch_sleep(1000); + //ERRORA("Audio skype pipe give us: %u\n", SKYPIAX_P_LOG, got); } - } else { - switch_sleep(1000); - //ERRORA("Audio skype pipe give us: %u\n", SKYPIAX_P_LOG, got); } - } } ERRORA("Skype server GONE\n", SKYPIAX_P_LOG); @@ -936,7 +925,7 @@ closesocket(fd); #endif //if (exit) - break; + break; } WARNINGA("client (I am it) GONE\n", SKYPIAX_P_LOG); @@ -951,21 +940,19 @@ return NULL; } - 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); + 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 @@ -995,9 +982,11 @@ } */ - 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); + 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) { @@ -1009,16 +998,16 @@ } fcntl(p->audioskypepipe[0], F_SETFL, O_NONBLOCK); fcntl(p->audioskypepipe[1], F_SETFL, O_NONBLOCK); -#endif// WIN32_SKYPIAX +#endif // WIN32_SKYPIAX if (option_debug > 10) { DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } return 0; } -static switch_status_t skypiax_skypeaudio_read(private_t *tech_pvt) +static switch_status_t skypiax_skypeaudio_read(private_t * tech_pvt) { - struct skypiax_interface *p; + struct skypiax_interface *p; short buf[640]; unsigned int samples; //int fd; @@ -1026,10 +1015,9 @@ //fd_set fs; //struct timeval to; - p = tech_pvt->p; - - //DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); + p = tech_pvt->p; + //DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); memset(buf, '\0', sizeof(buf)); @@ -1041,32 +1029,31 @@ to.tv_sec = 0; rt = select(fd + 1, &fs, NULL, NULL, &to); #endif - rt=1; + rt = 1; if (rt > 0) { + samples = SAMPLES_PER_FRAME * sizeof(short); - samples = SAMPLES_PER_FRAME * sizeof(short); - - switch_file_read(p->audiopipe[0], tech_pvt->read_frame.data, &samples); + switch_file_read(p->audiopipe[0], tech_pvt->read_frame.data, &samples); - //if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320) - if (samples != SAMPLES_PER_FRAME * sizeof(short)) { - 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; - //DEBUGA_SKYPE("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples); - /* A real frame */ - } + //if ((samples = read(p->audiopipe[0], buf, SAMPLES_PER_FRAME * sizeof(short))) != 320) + if (samples != SAMPLES_PER_FRAME * sizeof(short)) { + 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; + //DEBUGA_SKYPE("read=====> GOOD samples=%d\n", SKYPIAX_P_LOG, samples); + /* A real frame */ + } } else { DEBUGA_SKYPE("select returned %d\n", SKYPIAX_P_LOG, rt); - } - //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); + //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); return SWITCH_STATUS_SUCCESS; } @@ -1124,280 +1111,292 @@ #endif //0 #endif /* SKYPE_AUDIO */ -static void tech_init(private_t *tech_pvt, switch_core_session_t *session, skypiax_interface_t *p) +static void tech_init(private_t * tech_pvt, switch_core_session_t * session, + skypiax_interface_t * p) { - //struct skypiax_interface *p = NULL; + //struct skypiax_interface *p = NULL; - DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); - tech_pvt->read_frame.data = tech_pvt->databuf; - tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); - switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); - switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session)); - switch_core_session_set_private(session, tech_pvt); - tech_pvt->session = session; - if(p){ - tech_pvt->p=p; - p->tech_pvt=tech_pvt; - - } -if ( skypiax_codec(tech_pvt, 8000, 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"); -} + DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); + tech_pvt->read_frame.data = tech_pvt->databuf; + tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf); + switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, + switch_core_session_get_pool(session)); + switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, + switch_core_session_get_pool(session)); + switch_core_session_set_private(session, tech_pvt); + tech_pvt->session = session; + if (p) { + tech_pvt->p = p; + p->tech_pvt = tech_pvt; - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); + } + if (skypiax_codec(tech_pvt, 8000, 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"); + } + + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } + /* State methods they get called when the state changes to the specific state returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it. */ -static switch_status_t channel_on_init(switch_core_session_t *session) +static switch_status_t channel_on_init(switch_core_session_t * session) { - switch_channel_t *channel; - private_t *tech_pvt = NULL; - - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); + switch_channel_t *channel; + private_t *tech_pvt = NULL; - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - switch_set_flag_locked(tech_pvt, TFLAG_IO); + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); - /* Move channel's state machine to ROUTING. This means the call is trying - to get from the initial start where the call because, to the point - where a destination has been identified. If the channel is simply - left in the initial state, nothing will happen. */ - switch_channel_set_state(channel, CS_ROUTING); - switch_mutex_lock(globals.mutex); - globals.calls++; - switch_mutex_unlock(globals.mutex); + channel = switch_core_session_get_channel(session); + assert(channel != NULL); + switch_set_flag_locked(tech_pvt, TFLAG_IO); + + /* Move channel's state machine to ROUTING. This means the call is trying + to get from the initial start where the call because, to the point + where a destination has been identified. If the channel is simply + left in the initial state, nothing will happen. */ + switch_channel_set_state(channel, CS_ROUTING); + switch_mutex_lock(globals.mutex); + globals.calls++; + switch_mutex_unlock(globals.mutex); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL INIT\n", switch_channel_get_name(channel)); - return SWITCH_STATUS_SUCCESS; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL INIT\n", + switch_channel_get_name(channel)); + return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_routing(switch_core_session_t *session) +static switch_status_t channel_on_routing(switch_core_session_t * session) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + channel = switch_core_session_get_channel(session); + assert(channel != NULL); - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n", switch_channel_get_name(channel)); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL ROUTING\n", + switch_channel_get_name(channel)); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_execute(switch_core_session_t *session) +static switch_status_t channel_on_execute(switch_core_session_t * session) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); + channel = switch_core_session_get_channel(session); + assert(channel != NULL); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel)); + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", + switch_channel_get_name(channel)); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig) +static switch_status_t channel_kill_channel(switch_core_session_t * session, int sig) { - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); + channel = switch_core_session_get_channel(session); + assert(channel != NULL); - switch (sig) { - case SWITCH_SIG_KILL: - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL got SWITCH_SIG_KILL\n", switch_channel_get_name(channel)); - 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, "%s CHANNEL got SWITCH_SIG_BREAK\n", switch_channel_get_name(channel)); - switch_set_flag_locked(tech_pvt, TFLAG_BREAK); - break; - default: - break; - } + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + + switch (sig) { + case SWITCH_SIG_KILL: + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "%s CHANNEL got SWITCH_SIG_KILL\n", + switch_channel_get_name(channel)); + 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, + "%s CHANNEL got SWITCH_SIG_BREAK\n", + switch_channel_get_name(channel)); + switch_set_flag_locked(tech_pvt, TFLAG_BREAK); + break; + default: + break; + } - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_exchange_media(switch_core_session_t *session) +static switch_status_t channel_on_exchange_media(switch_core_session_t * session) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n"); - return SWITCH_STATUS_SUCCESS; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL LOOPBACK\n"); + return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_on_soft_execute(switch_core_session_t *session) +static switch_status_t channel_on_soft_execute(switch_core_session_t * session) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n"); - return SWITCH_STATUS_SUCCESS; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL TRANSMIT\n"); + return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf) +static switch_status_t channel_send_dtmf(switch_core_session_t * session, + const switch_dtmf_t * dtmf) { - private_t *tech_pvt = switch_core_session_get_private(session); - switch_assert(tech_pvt != NULL); + private_t *tech_pvt = switch_core_session_get_private(session); + switch_assert(tech_pvt != NULL); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, switch_io_flag_t flags, int stream_id) -{ - 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); - assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); - tech_pvt->read_frame.flags = SFF_NONE; - *frame = NULL; +static switch_status_t channel_read_frame(switch_core_session_t * session, + switch_frame_t ** frame, switch_io_flag_t flags, + int stream_id) +{ + 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); + assert(channel != NULL); + + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); + tech_pvt->read_frame.flags = SFF_NONE; + *frame = NULL; + if (skypiax_skypeaudio_read(tech_pvt) != SWITCH_STATUS_SUCCESS) { -if ( skypiax_skypeaudio_read(tech_pvt) != SWITCH_STATUS_SUCCESS ) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "skypiax_skypeaudio_read ERROR\n"); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_skypeaudio_read ERROR\n"); - -} else { - switch_set_flag_locked(tech_pvt, TFLAG_VOICE); - //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_skypeaudio_read SUCCESS\n"); - -} + } else { + switch_set_flag_locked(tech_pvt, TFLAG_VOICE); + //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "skypiax_skypeaudio_read SUCCESS\n"); - while (switch_test_flag(tech_pvt, TFLAG_IO)) { - if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { - switch_clear_flag(tech_pvt, TFLAG_BREAK); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL READ FRAME goto CNG\n"); - goto cng; - } + } - if (!switch_test_flag(tech_pvt, TFLAG_IO)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL READ FRAME not IO\n"); - return SWITCH_STATUS_FALSE; - } + while (switch_test_flag(tech_pvt, TFLAG_IO)) { + if (switch_test_flag(tech_pvt, TFLAG_BREAK)) { + switch_clear_flag(tech_pvt, TFLAG_BREAK); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "CHANNEL READ FRAME goto CNG\n"); + goto cng; + } + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "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; - } + 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"); - + //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)) { - switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); - if (!tech_pvt->read_frame.datalen) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL READ CONTINUE\n"); - continue; - } - *frame = &tech_pvt->read_frame; + if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) { + switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); + if (!tech_pvt->read_frame.datalen) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "CHANNEL READ CONTINUE\n"); + continue; + } + *frame = &tech_pvt->read_frame; #ifdef BIGENDIAN - if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) { - switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2); - } + if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) { + switch_swap_linear((*frame)->data, (int) (*frame)->datalen / 2); + } #endif - return SWITCH_STATUS_SUCCESS; - } - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL READ no TFLAG_IO\n"); - return SWITCH_STATUS_FALSE; + return SWITCH_STATUS_SUCCESS; + } - } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL READ no TFLAG_IO\n"); + return SWITCH_STATUS_FALSE; + } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL READ FALSE\n"); - return SWITCH_STATUS_FALSE; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL READ FALSE\n"); + return SWITCH_STATUS_FALSE; - cng: - data = (switch_byte_t *) tech_pvt->read_frame.data; - data[0] = 65; - data[1] = 0; - tech_pvt->read_frame.datalen = 2; - tech_pvt->read_frame.flags = SFF_CNG; - *frame = &tech_pvt->read_frame; - return SWITCH_STATUS_SUCCESS; +cng: + data = (switch_byte_t *) tech_pvt->read_frame.data; + data[0] = 65; + data[1] = 0; + tech_pvt->read_frame.datalen = 2; + tech_pvt->read_frame.flags = SFF_CNG; + *frame = &tech_pvt->read_frame; + return SWITCH_STATUS_SUCCESS; } -static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id) -{ - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - //switch_frame_t *pframe; - unsigned int sent; - struct skypiax_interface *p=NULL; +static switch_status_t channel_write_frame(switch_core_session_t * session, + switch_frame_t * frame, switch_io_flag_t flags, + int stream_id) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + //switch_frame_t *pframe; + unsigned int sent; + struct skypiax_interface *p = NULL; - //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL WRITE FRAME\n"); + //switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CHANNEL WRITE FRAME\n"); - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + channel = switch_core_session_get_channel(session); + assert(channel != NULL); - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); - p=tech_pvt->p; - assert(p != NULL); + p = tech_pvt->p; + assert(p != NULL); - if (!switch_test_flag(tech_pvt, TFLAG_IO)) { + if (!switch_test_flag(tech_pvt, TFLAG_IO)) { ERRORA("CIAPA \n", SKYPIAX_P_LOG); - return SWITCH_STATUS_FALSE; - } + return SWITCH_STATUS_FALSE; + } #ifdef BIGENDIAN - if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) { - switch_swap_linear(frame->data, (int) frame->datalen / 2); - } + if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) { + switch_swap_linear(frame->data, (int) frame->datalen / 2); + } #endif - sent = frame->datalen; - switch_file_write(p->audioskypepipe[1], (short *) frame->data, &sent); - //ERRORA("sent %d\n", SKYPIAX_P_LOG, sent); + sent = frame->datalen; + switch_file_write(p->audioskypepipe[1], (short *) frame->data, &sent); + //ERRORA("sent %d\n", SKYPIAX_P_LOG, sent); - - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } @@ -1407,12 +1406,13 @@ void create_pipe(void *data) { - switch_status_t rv; + 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); +} - //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 @@ -1445,325 +1445,325 @@ static apr_file_t *readp = NULL; static apr_file_t *writep = NULL; -static void create_pipe(abts_case *tc, void *data) +static void create_pipe(abts_case * tc, void *data) { - apr_status_t rv; + 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_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_close(readp); - rv = apr_file_close(writep); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); +static void close_pipe(abts_case * tc, void *data) +{ + apr_status_t rv; + apr_size_t nbytes = 256; + char buf[256]; - rv = apr_file_read(readp, buf, &nbytes); - ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_EBADF(rv)); -} + rv = apr_file_close(readp); + rv = apr_file_close(writep); + ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); -static void set_timeout(abts_case *tc, void *data) + 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; + 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_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_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_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)); + 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) +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); + apr_status_t rv; + char *buf; + apr_size_t nbytes; - 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); + nbytes = strlen("this is a test"); + buf = (char *) apr_palloc(p, nbytes + 1); - rv = apr_file_pipe_timeout_set(readp, apr_time_from_sec(1)); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); + 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); - 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); - } + 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) +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"); + apr_status_t rv; + char *buf = "this is a test"; + char *input; + apr_size_t nbytes; - 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); + nbytes = strlen("this is a test"); - rv = apr_file_write(writep, buf, &nbytes); - ABTS_SIZE_EQUAL(tc, strlen("this is a test"), nbytes); - ABTS_INT_EQUAL(tc, APR_SUCCESS, 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); - 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); + 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) +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); + 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_procattr_error_check_set(procattr, 1); - 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); - 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.out, apr_time_from_sec(10)); + ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - rv = apr_file_pipe_timeout_set(proc.in, apr_time_from_sec(10)); + i = iterations; + do { + rv = apr_file_write_full(proc.in, buf, bytes_per_iteration, NULL); ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); + } while (--i); - rv = apr_file_pipe_timeout_set(proc.out, apr_time_from_sec(10)); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); + free(buf); - i = iterations; - do { - rv = apr_file_write_full(proc.in, buf, bytes_per_iteration, NULL); - ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - } while (--i); + rv = apr_file_close(proc.in); + ABTS_INT_EQUAL(tc, APR_SUCCESS, rv); - free(buf); + 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); - 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, "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_ASSERT(tc, "child terminated normally", why == APR_PROC_EXIT); } -abts_suite *testpipe(abts_suite *suite) +abts_suite *testpipe(abts_suite * suite) { - suite = ADD_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); + 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; + return suite; } - - - #endif - #endif -static switch_status_t channel_answer_channel(switch_core_session_t *session) +static switch_status_t channel_answer_channel(switch_core_session_t * session) { - private_t *tech_pvt; - switch_channel_t *channel = NULL; - struct skypiax_interface *p; + private_t *tech_pvt; + switch_channel_t *channel = NULL; + struct skypiax_interface *p; - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + channel = switch_core_session_get_channel(session); + assert(channel != NULL); - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); - p=tech_pvt->p; + p = tech_pvt->p; - DEBUGA_SKYPE("ANSWERED! \n", SKYPIAX_P_LOG); + DEBUGA_SKYPE("ANSWERED! \n", SKYPIAX_P_LOG); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } - -static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg) +static switch_status_t channel_receive_message(switch_core_session_t * session, + switch_core_session_message_t * msg) { - switch_channel_t *channel; - private_t *tech_pvt; - struct skypiax_interface *p; + switch_channel_t *channel; + private_t *tech_pvt; + struct skypiax_interface *p; - channel = switch_core_session_get_channel(session); - assert(channel != NULL); + channel = switch_core_session_get_channel(session); + assert(channel != NULL); - tech_pvt = (private_t *) switch_core_session_get_private(session); - assert(tech_pvt != NULL); + tech_pvt = (private_t *) switch_core_session_get_private(session); + assert(tech_pvt != NULL); - p=tech_pvt->p; + p = tech_pvt->p; - switch (msg->message_id) { - case SWITCH_MESSAGE_INDICATE_ANSWER: - { - //WARNINGA("TO BE ANSWERED! \n", SKYPIAX_P_LOG); - DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id); - channel_answer_channel(session); - } - break; - default: - { - WARNINGA("MSG_ID=%d\n", SKYPIAX_P_LOG, msg->message_id); - } - break; - } + switch (msg->message_id) { + case SWITCH_MESSAGE_INDICATE_ANSWER: + { + //WARNINGA("TO BE ANSWERED! \n", SKYPIAX_P_LOG); + DEBUGA_SKYPE("MSG_ID=%d, TO BE ANSWERED!\n", SKYPIAX_P_LOG, msg->message_id); + channel_answer_channel(session); + } + break; + default: + { + WARNINGA("MSG_ID=%d\n", SKYPIAX_P_LOG, msg->message_id); + } + break; + } - return SWITCH_STATUS_SUCCESS; + 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; - } +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; + 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) +static switch_status_t channel_receive_event(switch_core_session_t * session, + switch_event_t * event) { - struct private_object *tech_pvt = switch_core_session_get_private(session); - char *body = switch_event_get_body(event); - switch_assert(tech_pvt != NULL); + struct private_object *tech_pvt = switch_core_session_get_private(session); + char *body = switch_event_get_body(event); + switch_assert(tech_pvt != NULL); - if (!body) { - body = ""; - } + if (!body) { + body = ""; + } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "event: |||%s|||\n", body); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "event: |||%s|||\n", body); - return SWITCH_STATUS_SUCCESS; + return SWITCH_STATUS_SUCCESS; } - - switch_state_handler_table_t skypiax_state_handlers = { - /*.on_init */ channel_on_init, - /*.on_routing */ channel_on_routing, - /*.on_execute */ channel_on_execute, - /*.on_hangup */ channel_on_hangup, - /*.on_exchange_media */ channel_on_exchange_media, - /*.on_soft_execute */ channel_on_soft_execute + /*.on_init */ channel_on_init, + /*.on_routing */ channel_on_routing, + /*.on_execute */ channel_on_execute, + /*.on_hangup */ channel_on_hangup, + /*.on_exchange_media */ channel_on_exchange_media, + /*.on_soft_execute */ channel_on_soft_execute }; switch_io_routines_t skypiax_io_routines = { - /*.outgoing_channel */ channel_outgoing_channel, - /*.read_frame */ channel_read_frame, - /*.write_frame */ channel_write_frame, - /*.kill_channel */ channel_kill_channel, - /*.send_dtmf */ channel_send_dtmf, - /*.receive_message */ channel_receive_message, - /*.receive_event */ channel_receive_event + /*.outgoing_channel */ channel_outgoing_channel, + /*.read_frame */ channel_read_frame, + /*.write_frame */ channel_write_frame, + /*.kill_channel */ channel_kill_channel, + /*.send_dtmf */ channel_send_dtmf, + /*.receive_message */ channel_receive_message, + /*.receive_event */ channel_receive_event }; + #define SKYPE_THREAD #ifndef WIN32_SKYPIAX #ifdef SKYPE_THREAD @@ -1899,7 +1899,7 @@ switch_sleep(1000); } -static void *SWITCH_THREAD_FUNC do_skype_thread(switch_thread_t *thread, void *obj) +static void *SWITCH_THREAD_FUNC do_skype_thread(switch_thread_t * thread, void *obj) { struct skypiax_interface *p; @@ -1911,7 +1911,7 @@ //int res; p = obj; - DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); + DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); /* if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) { @@ -1923,28 +1923,31 @@ } */ - switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], 2, module_pool); + 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; + 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); if (!disp) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open X Display '%s', exiting skype thread\n", p->X11_display); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "Cannot open X Display '%s', exiting skype thread\n", + p->X11_display); return NULL; } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "X Display '%s' opened\n", p->X11_display); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "X Display '%s' opened\n", + p->X11_display); } int xfd; @@ -1977,7 +1980,7 @@ SKYPIAX_P_LOG); //p->skype = 0; //p->skype_thread = SKYPIAX_PTHREADT_NULL; - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); return NULL; } @@ -1988,7 +1991,7 @@ SKYPIAX_P_LOG); //p->skype = 0; //p->skype_thread = SKYPIAX_PTHREADT_NULL; - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); return NULL; } @@ -2022,9 +2025,9 @@ strcat(buffer, buf); if (i < 20) { /* last fragment */ - unsigned int howmany; + unsigned int howmany; - howmany = strlen(b) + 1; + howmany = strlen(b) + 1; switch_file_write(AsteriskHandlesAst->fdesc[1], b, &howmany); //write(AsteriskHandlesAst->fdesc[1], "\0", 1); @@ -2049,17 +2052,14 @@ //p->skype = 0; //p->skype_thread = SKYPIAX_PTHREADT_NULL; //pthread_cleanup_pop(1); - //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); + //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); return NULL; } - #endif /* SKYPE_THREAD */ #else // WIN32_SKYPIAX - - #endif // WIN32_SKYPIAX #define CONTROLDEV_THREAD @@ -2109,9 +2109,9 @@ } AsteriskHandlesAst = &p->AsteriskHandlesAst; - if (option_debug > 101) { - DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype); - } + if (option_debug > 101) { + DEBUGA_SKYPE("SENDING: |||%s||||\n", SKYPIAX_P_LOG, msg_to_skype); + } if (!skypiax_skype_send_message(AsteriskHandlesAst, msg_to_skype)) { ERRORA @@ -2135,7 +2135,6 @@ } #endif //0 - int skypiax_skype_read(struct skypiax_interface *p) { @@ -2154,7 +2153,7 @@ if (option_debug > 100) { DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); } - //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); @@ -2169,10 +2168,10 @@ to.tv_sec = 0; rt = select(fd + 1, &fs, NULL, NULL, &to); #endif - rt=1; + rt = 1; if (rt > 0) { howmany = sizeof(read_from_pipe); - switch_file_read(p->AsteriskHandlesAst.fdesc[0], read_from_pipe, &howmany); + switch_file_read(p->AsteriskHandlesAst.fdesc[0], read_from_pipe, &howmany); a = 0; for (i = 0; i < howmany; i++) { @@ -2185,7 +2184,7 @@ 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 0 //FIXME wat's the use of this? if (!strcasecmp(messaggio, "ERROR 68")) { /* not yet protocol specified, just authorized */ NOTICA @@ -2198,25 +2197,24 @@ #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); - p->skype_callflow = CALLFLOW_STATUS_FINISHED; - if (option_debug) - DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG); - p->skype_call_id[0] = '\0'; - - if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) { - if (option_debug > 100) { - 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; - } + ERRORA("Skype got ERROR: |||%s|||, the number we called was not recognized\n", + SKYPIAX_P_LOG, messaggio); + p->skype_callflow = CALLFLOW_STATUS_FINISHED; + if (option_debug) + DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG); + p->skype_call_id[0] = '\0'; + + if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) { + if (option_debug > 100) { + 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; + } } strncpy(messaggio_2, messaggio, sizeof(messaggio) - 1); @@ -2247,26 +2245,24 @@ strncpy(p->skype_displayname, &messaggio_2[10], 511); } if (!strcasecmp(messaggio, "ERROR")) { - ERRORA - ("Skype got ERROR: |||%s|||\n", - SKYPIAX_P_LOG, messaggio); - p->skype_callflow = CALLFLOW_STATUS_FINISHED; - if (option_debug) - DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG); - p->skype_call_id[0] = '\0'; - - if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) { - if (option_debug > 100) { - 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; - } + ERRORA("Skype got ERROR: |||%s|||\n", SKYPIAX_P_LOG, messaggio); + p->skype_callflow = CALLFLOW_STATUS_FINISHED; + if (option_debug) + DEBUGA_SKYPE("skype_call now is DOWN\n", SKYPIAX_P_LOG); + p->skype_call_id[0] = '\0'; + + if (p->interface_state != SKYPIAX_STATE_HANGUP_REQUESTED) { + if (option_debug > 100) { + 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; + } } if (!strcasecmp(messaggio, "CALL")) { @@ -2293,13 +2289,17 @@ if (!strcasecmp(prop, "PARTNER_HANDLE")) { strncpy(p->callid_number, value, sizeof(p->callid_number) - 1); - WARNINGA("the skype_call %s caller PARTNER_HANDLE (p->callid_number) is: %s\n", SKYPIAX_P_LOG, id, p->callid_number); + WARNINGA + ("the skype_call %s caller PARTNER_HANDLE (p->callid_number) is: %s\n", + SKYPIAX_P_LOG, id, p->callid_number); return CALLFLOW_INCOMING_RING; } if (!strcasecmp(prop, "PARTNER_DISPNAME")) { snprintf(p->callid_name, sizeof(p->callid_name) - 1, "%s%s%s", value, where ? " " : "", where ? where : ""); - WARNINGA("the skype_call %s caller PARTNER_DISPNAME (p->callid_name) is: %s\n", SKYPIAX_P_LOG, id, p->callid_name); + WARNINGA + ("the skype_call %s caller PARTNER_DISPNAME (p->callid_name) is: %s\n", + SKYPIAX_P_LOG, id, p->callid_name); } if (!strcasecmp(prop, "CONF_ID") && !strcasecmp(value, "0")) { DEBUGA_SKYPE("the skype_call %s is NOT a conference call\n", SKYPIAX_P_LOG, @@ -2313,32 +2313,30 @@ p->interface_state = SKYPIAX_STATE_PRERING; } - if (!strcasecmp(prop, "DTMF")) { - switch_core_session_t *session = NULL; - private_t *tech_pvt = NULL; - switch_channel_t *channel = NULL; + if (!strcasecmp(prop, "DTMF")) { + switch_core_session_t *session = NULL; + 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; - session = tech_pvt->session; - channel = switch_core_session_get_channel(session); - - - - if (channel) { - switch_dtmf_t dtmf = { (char) value[0], switch_core_default_dtmf_duration(0) }; - if (globals.debug) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n", dtmf.digit, switch_channel_get_name(channel)); - } - switch_mutex_lock(tech_pvt->flag_mutex); - switch_channel_queue_dtmf(channel, &dtmf); - switch_set_flag(tech_pvt, TFLAG_DTMF); - switch_mutex_unlock(tech_pvt->flag_mutex); - } - - + tech_pvt = p->tech_pvt; + session = tech_pvt->session; + channel = switch_core_session_get_channel(session); + + if (channel) { + switch_dtmf_t dtmf = + { (char) value[0], switch_core_default_dtmf_duration(0) }; + if (globals.debug) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n", + dtmf.digit, switch_channel_get_name(channel)); + } + switch_mutex_lock(tech_pvt->flag_mutex); + switch_channel_queue_dtmf(channel, &dtmf); + switch_set_flag(tech_pvt, TFLAG_DTMF); + switch_mutex_unlock(tech_pvt->flag_mutex); + } //FIXME ast_queue_frame(p->owner, &f2); } @@ -2348,7 +2346,7 @@ ("Skype has FAILED on skype_call %s. Let's wait for the FAILED message.\n", SKYPIAX_P_LOG, id); } - if (!strcasecmp(prop, "DURATION") && (!strcasecmp(value, "1"))) { + if (!strcasecmp(prop, "DURATION") && (!strcasecmp(value, "1"))) { if (strcasecmp(id, p->skype_call_id)) { strncpy(p->skype_call_id, id, sizeof(p->skype_call_id) - 1); if (option_debug > 1) @@ -2358,7 +2356,6 @@ } } - if (!strcasecmp(prop, "STATUS")) { if (!strcasecmp(value, "RINGING")) { @@ -2417,7 +2414,7 @@ DEBUGA_SKYPE("We missed skype_call %s\n", SKYPIAX_P_LOG, id); } else if (!strcasecmp(value, "FINISHED")) { - global_session = NULL; //FIXME + 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); @@ -2429,7 +2426,7 @@ } //p->interface_state = SKYPIAX_STATE_DOWN; //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; + //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else { p->interface_state = SKYPIAX_STATE_DOWN; @@ -2449,7 +2446,7 @@ } p->interface_state = SKYPIAX_STATE_DOWN; //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; + //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else { p->interface_state = SKYPIAX_STATE_DOWN; @@ -2467,7 +2464,7 @@ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; + //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else if (!strcasecmp(value, "REFUSED")) { if (!strcasecmp(id, p->skype_call_id)) { @@ -2484,7 +2481,7 @@ DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } //FIXME if(p->owner) - //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; + //FIXME p->owner->hangupcause = SKYPIAX_CAUSE_NORMAL; return CALLFLOW_INCOMING_HANGUP; } else { /* we're here because were us that refused an incoming call */ @@ -2509,164 +2506,155 @@ 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 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); + 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 (1) { + char msg_to_skype[1024]; #if 0 - if (!p->tcp_srv_thread) { - if(1) - { + 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); + //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) - { + if (!p->tcp_cli_thread) { + if (1) { #endif - //switch_thread_t *thread; - //switch_threadattr_t *thd_attr = NULL; + //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); - } + 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 - } - + } - } + } #endif - switch_sleep(100000); - sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"5556\"", id); - skypiax_skype_write(p, msg_to_skype); - switch_sleep(100000); - sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"5558\"", id); - skypiax_skype_write(p, msg_to_skype); - switch_sleep(100000); - } + switch_sleep(100000); + sprintf(msg_to_skype, "ALTER CALL %s SET_OUTPUT PORT=\"5556\"", id); + skypiax_skype_write(p, msg_to_skype); + switch_sleep(100000); + sprintf(msg_to_skype, "ALTER CALL %s SET_INPUT PORT=\"5558\"", id); + skypiax_skype_write(p, msg_to_skype); + switch_sleep(100000); + } p->skype_callflow = SKYPIAX_STATE_UP; - /**************************/ - - //FIXME switch_core_session_t **new_session; - - //FIXME *new_session=switch_loadable_module_create_interface(skypiax_endpoint_interface, pool); - - if (!global_session) { //FIXME FIXME FIXME - switch_core_session_t *session = NULL; - private_t *tech_pvt = NULL; - switch_channel_t *channel = NULL; - + /**************************/ + //FIXME switch_core_session_t **new_session; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Inbound Channel!\n"); - - if ((session = switch_core_session_request(skypiax_endpoint_interface, NULL)) != 0) { - switch_core_session_add_stream(session, NULL); - if ((tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t))) != 0) { - channel = switch_core_session_get_channel(session); - tech_init(tech_pvt, session, p); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n"); - switch_core_session_destroy(&session); - break; - } - - // if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), NULL, dialplan, cid_name, cid_num, ip, NULL, NULL, NULL, modname, NULL, dest)) != 0) - - if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), - "skypiax", - "XML", - "gmaruzz_from_skype", - "calling_number", - NULL, - "calling_ani", - NULL, - NULL, - (char *) modname, - "default", - "5000")) != 0) { - char name[128]; - switch_snprintf(name, sizeof(name), "skypiax/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff); - switch_channel_set_name(channel, name); - switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); - } - 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); - } + //FIXME *new_session=switch_loadable_module_create_interface(skypiax_endpoint_interface, pool); + if (!global_session) { //FIXME FIXME FIXME + switch_core_session_t *session = NULL; + private_t *tech_pvt = NULL; + switch_channel_t *channel = NULL; + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, + "New Inbound Channel!\n"); + + if ((session = + switch_core_session_request(skypiax_endpoint_interface, + NULL)) != 0) { + switch_core_session_add_stream(session, NULL); + if ((tech_pvt = + (private_t *) switch_core_session_alloc(session, + sizeof(private_t))) != 0) { + channel = switch_core_session_get_channel(session); + tech_init(tech_pvt, session, p); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, + "Hey where is my memory pool?\n"); + switch_core_session_destroy(&session); + break; + } + + // if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session), NULL, dialplan, cid_name, cid_num, ip, NULL, NULL, NULL, modname, NULL, dest)) != 0) + + if ((tech_pvt->caller_profile = + switch_caller_profile_new(switch_core_session_get_pool(session), + "skypiax", "XML", "gmaruzz_from_skype", + "calling_number", NULL, "calling_ani", + NULL, NULL, (char *) modname, "default", + "5000")) != 0) { + char name[128]; + switch_snprintf(name, sizeof(name), "skypiax/%s-%04x", + tech_pvt->caller_profile->destination_number, + rand() & 0xffff); + switch_channel_set_name(channel, name); + switch_channel_set_caller_profile(channel, tech_pvt->caller_profile); + } + 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); + } #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); - } - } + 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; - private_t *tech_pvt = NULL; - switch_channel_t *channel = NULL; - - tech_pvt = p->tech_pvt; - //session = tech_pvt->session; - session = global_session; - channel = switch_core_session_get_channel(session); - switch_channel_mark_pre_answered(channel); - - //switch_channel_set_state(channel, CS_EXECUTE); - - } - /**************************/ - - - + } + } else { + switch_core_session_t *session = NULL; + private_t *tech_pvt = NULL; + switch_channel_t *channel = NULL; + + tech_pvt = p->tech_pvt; + //session = tech_pvt->session; + session = global_session; + channel = switch_core_session_get_channel(session); + switch_channel_mark_pre_answered(channel); + //switch_channel_set_state(channel, CS_EXECUTE); + } + /**************************/ } else { WARNINGA("skype_call: %s, STATUS: %s is not recognized\n", SKYPIAX_P_LOG, @@ -2686,11 +2674,12 @@ if (option_debug > 100) { DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } - //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); + //DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); return 0; } -int skypiax_skype_call(struct skypiax_interface *p, char *idest, int timeout, switch_core_session_t *session) +int skypiax_skype_call(struct skypiax_interface *p, char *idest, int timeout, + switch_core_session_t * session) { char rdest[80]; char msg_to_skype[1024]; @@ -2698,7 +2687,7 @@ if (option_debug > 10) { DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); } -switch_sleep(5000); + switch_sleep(5000); //FIXME strncpy(rdest, idest, sizeof(rdest) - 1); strncpy(rdest, "echo123", sizeof(rdest) - 1); @@ -2736,51 +2725,57 @@ return 0; } -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, *new_session); - - 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; - } +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, + *new_session); + + 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; + return SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER; } @@ -2788,301 +2783,336 @@ * \brief This thread runs during a call, and monitor the interface serial port for signaling, like hangup, caller id, etc * */ -static void *SWITCH_THREAD_FUNC skypiax_do_controldev_thread(switch_thread_t *thread, void *obj) +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; - DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); - - DEBUGA_SKYPE("In skypiax_do_controldev_thread: started, p=%p\n", SKYPIAX_P_LOG, (void *)p); + DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG); + DEBUGA_SKYPE("In skypiax_do_controldev_thread: started, p=%p\n", SKYPIAX_P_LOG, + (void *) p); while (1) { switch_sleep(1000); res = skypiax_skype_read(p); #if 1 - //if (res == CALLFLOW_INCOMING_HANGUP && p->interface_state != SKYPIAX_STATE_DOWN) - if (res == CALLFLOW_INCOMING_HANGUP) { - switch_core_session_t *session = NULL; - private_t *tech_pvt; - switch_channel_t *channel; + //if (res == CALLFLOW_INCOMING_HANGUP && p->interface_state != SKYPIAX_STATE_DOWN) + if (res == CALLFLOW_INCOMING_HANGUP) { + switch_core_session_t *session = NULL; + 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); - //p->interface_state=SKYPIAX_STATE_DOWN; - //if (option_debug) - DEBUGA_SKYPE("skype call ended\n", SKYPIAX_P_LOG); + tech_pvt = p->tech_pvt; + session = tech_pvt->session; - tech_pvt = p->tech_pvt; - session = tech_pvt->session; - - channel = switch_core_session_get_channel(session); - DEBUGA_SKYPE("before channel_on_hangup\n", SKYPIAX_P_LOG); + 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_set_state(channel, CS_HANGUP); - switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); - DEBUGA_SKYPE("after channel_on_hangup\n", SKYPIAX_P_LOG); + switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); + DEBUGA_SKYPE("after channel_on_hangup\n", SKYPIAX_P_LOG); - //DEBUGA_SKYPE("set state to CS_HANGUP\n", SKYPIAX_P_LOG); - } + //DEBUGA_SKYPE("set state to CS_HANGUP\n", SKYPIAX_P_LOG); + } #endif } //if (option_debug > 10) { - DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); //} return NULL; } - #endif // CONTROLDEV_THREAD static switch_status_t load_config(void) { - char *cf = "skypiax.conf"; - switch_xml_t cfg, xml, global_settings, param, interfaces, myinterface; + char *cf = "skypiax.conf"; + switch_xml_t cfg, xml, global_settings, param, interfaces, myinterface; + + switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); + if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); + return SWITCH_STATUS_TERM; + } + + if ((global_settings = switch_xml_child(cfg, "global_settings"))) { + for (param = switch_xml_child(global_settings, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "debug")) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.debug=%d\n", + globals.debug); + globals.debug = atoi(val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.debug=%d\n", + globals.debug); + } else if (!strcasecmp(var, "hold-music")) { + switch_set_string(globals.hold_music, val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.hold_music=%s\n", + globals.hold_music); + } else if (!strcmp(var, "port")) { + globals.port = atoi(val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.port=%d\n", + globals.port); + } else if (!strcmp(var, "ip")) { + set_global_ip(val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.ip=%s\n", + globals.ip); + } else if (!strcmp(var, "codec-master")) { + if (!strcasecmp(val, "us")) { + switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS); + } + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "codec-master globals.debug=%d\n", globals.debug); + } else if (!strcmp(var, "dialplan")) { + set_global_dialplan(val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.dialplan=%s\n", + globals.dialplan); + } else if (!strcmp(var, "codec-prefs")) { + set_global_codec_string(val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "globals.codec_string=%s\n", globals.codec_string); + globals.codec_order_last = + switch_separate_string(globals.codec_string, ',', globals.codec_order, + SWITCH_MAX_CODECS); + } else if (!strcmp(var, "codec-rates")) { + set_global_codec_rates_string(val); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "globals.codec_rates_string=%s\n", globals.codec_rates_string); + globals.codec_rates_last = + switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, + SWITCH_MAX_CODECS); + } + + } + } + + if ((interfaces = switch_xml_child(cfg, "per_interface_settings"))) { + int i = 0; + + for (myinterface = switch_xml_child(interfaces, "interface"); myinterface; + myinterface = myinterface->next) { + char *id = (char *) switch_xml_attr(myinterface, "id"); + char *name = (char *) switch_xml_attr(myinterface, "name"); + char *context = "default"; + char *dialplan = "XML"; + char *tonegroup = NULL; + char *digit_timeout = NULL; + char *max_digits = NULL; + char *hotline = NULL; + char *dial_regex = NULL; + char *hold_music = NULL; + char *fail_dial_regex = NULL; + char *enable_callerid = "true"; + char *X11_display = NULL; + + uint32_t interface_id = 0, to = 0, max = 0; + + for (param = switch_xml_child(myinterface, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcasecmp(var, "tonegroup")) { + tonegroup = val; + } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { + digit_timeout = val; + } else if (!strcasecmp(var, "context")) { + context = val; + } else if (!strcasecmp(var, "dialplan")) { + dialplan = val; + } else if (!strcasecmp(var, "dial-regex")) { + dial_regex = val; + } else if (!strcasecmp(var, "enable-callerid")) { + enable_callerid = val; + } else if (!strcasecmp(var, "fail-dial-regex")) { + fail_dial_regex = val; + } else if (!strcasecmp(var, "hold-music")) { + hold_music = val; + } else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) { + X11_display = val; + } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { + max_digits = val; + } else if (!strcasecmp(var, "hotline")) { + hotline = val; + } - switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, module_pool); - if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf); - return SWITCH_STATUS_TERM; - } - - if ((global_settings = switch_xml_child(cfg, "global_settings"))) { - for (param = switch_xml_child(global_settings, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - - if (!strcasecmp(var, "debug")) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.debug=%d\n", globals.debug); - globals.debug = atoi(val); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.debug=%d\n", globals.debug); - } else if (!strcasecmp(var, "hold-music")) { - switch_set_string(globals.hold_music, val); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.hold_music=%s\n", globals.hold_music); - } else if (!strcmp(var, "port")) { - globals.port = atoi(val); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.port=%d\n", globals.port); - } else if (!strcmp(var, "ip")) { - set_global_ip(val); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.ip=%s\n", globals.ip); - } else if (!strcmp(var, "codec-master")) { - if (!strcasecmp(val, "us")) { - switch_set_flag(&globals, GFLAG_MY_CODEC_PREFS); - } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "codec-master globals.debug=%d\n", globals.debug); - } else if (!strcmp(var, "dialplan")) { - set_global_dialplan(val); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.dialplan=%s\n", globals.dialplan); - } else if (!strcmp(var, "codec-prefs")) { - set_global_codec_string(val); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.codec_string=%s\n", globals.codec_string); - globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS); - } else if (!strcmp(var, "codec-rates")) { - set_global_codec_rates_string(val); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "globals.codec_rates_string=%s\n", globals.codec_rates_string); - globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS); - } - - } - } - - if ((interfaces = switch_xml_child(cfg, "per_interface_settings"))) { - int i=0; - - for (myinterface = switch_xml_child(interfaces, "interface"); myinterface; myinterface = myinterface->next) { - char *id = (char *) switch_xml_attr(myinterface, "id"); - char *name = (char *) switch_xml_attr(myinterface, "name"); - char *context = "default"; - char *dialplan = "XML"; - char *tonegroup = NULL; - char *digit_timeout = NULL; - char *max_digits = NULL; - char *hotline = NULL; - char *dial_regex = NULL; - char *hold_music = NULL; - char *fail_dial_regex = NULL; - char *enable_callerid = "true"; - char *X11_display = NULL; - - uint32_t interface_id = 0, to = 0, max = 0; - - for (param = switch_xml_child(myinterface, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - - if (!strcasecmp(var, "tonegroup")) { - tonegroup = val; - } else if (!strcasecmp(var, "digit_timeout") || !strcasecmp(var, "digit-timeout")) { - digit_timeout = val; - } else if (!strcasecmp(var, "context")) { - context = val; - } else if (!strcasecmp(var, "dialplan")) { - dialplan = val; - } else if (!strcasecmp(var, "dial-regex")) { - dial_regex = val; - } else if (!strcasecmp(var, "enable-callerid")) { - enable_callerid = val; - } else if (!strcasecmp(var, "fail-dial-regex")) { - fail_dial_regex = val; - } else if (!strcasecmp(var, "hold-music")) { - hold_music = val; - } else if (!strcasecmp(var, "X11-display") || !strcasecmp(var, "X11_display")) { - X11_display = val; - } else if (!strcasecmp(var, "max_digits") || !strcasecmp(var, "max-digits")) { - max_digits = val; - } else if (!strcasecmp(var, "hotline")) { - hotline = val; - } - - } - - if (!X11_display) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "interface missing REQUIRED param 'X11_display'\n"); - continue; - } - - if (!id) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "interface missing REQUIRED param 'id'\n"); - continue; - } - if (switch_is_number(id)) { - interface_id = atoi(id); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "interface_id=%d\n", interface_id); - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "interface param 'id' MUST be a number, now id='%s'\n", id); - continue; - } - - - if (!name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "interface missing param 'name', not nice, but works\n"); - } - - if (!tonegroup) { - tonegroup = "us"; - } - - if (digit_timeout) { - to = atoi(digit_timeout); - } - - if (max_digits) { - max = atoi(max_digits); - } - - if (name) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "name=%s\n", name); - } - if(interface_id && interface_id < SKYPIAX_MAX_INTERFACES ) { - struct skypiax_interface newconf; - memset(&newconf, '\0', sizeof(newconf)); - SKYPIAX_INTERFACES[interface_id]=newconf; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CONFIGURING interface_id=%d\n", interface_id); - switch_set_string(SKYPIAX_INTERFACES[interface_id].interface_id, id); - if (name) { - switch_set_string(SKYPIAX_INTERFACES[interface_id].name, name); - } else { - switch_set_string(SKYPIAX_INTERFACES[interface_id].name, "N/A"); - } - switch_set_string(SKYPIAX_INTERFACES[interface_id].X11_display, X11_display); - switch_set_string(SKYPIAX_INTERFACES[interface_id].context, context); - switch_set_string(SKYPIAX_INTERFACES[interface_id].dialplan, dialplan); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "interface_id=%d SKYPIAX_INTERFACES[interface_id].X11_display=%s\n", interface_id, SKYPIAX_INTERFACES[interface_id].X11_display); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "interface_id=%d SKYPIAX_INTERFACES[interface_id].name=%s\n", interface_id, SKYPIAX_INTERFACES[interface_id].name); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "interface_id=%d SKYPIAX_INTERFACES[interface_id].context=%s\n", interface_id, SKYPIAX_INTERFACES[interface_id].context); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "interface_id=%d SKYPIAX_INTERFACES[interface_id].dialplan=%s\n", interface_id, SKYPIAX_INTERFACES[interface_id].dialplan); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "STARTING interface_id=%d\n", interface_id); - - -if(1) -{ - 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(&thread, thd_attr, do_skype_thread, &SKYPIAX_INTERFACES[interface_id], module_pool); -} - -switch_sleep(100000); -if(1) -{ - 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(&thread, thd_attr, skypiax_do_controldev_thread, &SKYPIAX_INTERFACES[interface_id], module_pool); -} - - -switch_sleep(1000000); - -skypiax_skypeaudio_init(&SKYPIAX_INTERFACES[interface_id]); - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "STARTED interface_id=%d\n", interface_id); - - - } else { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "interface id %d is higher than SKYPIAX_MAX_INTERFACES (%d)\n", interface_id, SKYPIAX_MAX_INTERFACES); - continue; - } - - } - - for(i=0; i < SKYPIAX_MAX_INTERFACES; i++) { - if(strlen(SKYPIAX_INTERFACES[i].name)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_INTERFACES[%d].interface_id=%s\n", i, i, SKYPIAX_INTERFACES[i].interface_id); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_INTERFACES[%d].X11_display=%s\n", i, i, SKYPIAX_INTERFACES[i].X11_display); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_INTERFACES[%d].name=%s\n", i, i, SKYPIAX_INTERFACES[i].name); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_INTERFACES[%d].context=%s\n", i, i, SKYPIAX_INTERFACES[i].context); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "i=%d SKYPIAX_INTERFACES[%d].dialplan=%s\n", i, i, SKYPIAX_INTERFACES[i].dialplan); - } - } - } + } + + if (!X11_display) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "interface missing REQUIRED param 'X11_display'\n"); + continue; + } + + if (!id) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "interface missing REQUIRED param 'id'\n"); + continue; + } + if (switch_is_number(id)) { + interface_id = atoi(id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "interface_id=%d\n", + interface_id); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "interface param 'id' MUST be a number, now id='%s'\n", id); + continue; + } + + if (!name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "interface missing param 'name', not nice, but works\n"); + } - switch_xml_free(xml); + if (!tonegroup) { + tonegroup = "us"; + } + + if (digit_timeout) { + to = atoi(digit_timeout); + } - return SWITCH_STATUS_SUCCESS; + if (max_digits) { + max = atoi(max_digits); + } + + if (name) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "name=%s\n", name); + } + if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) { + struct skypiax_interface newconf; + memset(&newconf, '\0', sizeof(newconf)); + SKYPIAX_INTERFACES[interface_id] = newconf; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "CONFIGURING interface_id=%d\n", interface_id); + switch_set_string(SKYPIAX_INTERFACES[interface_id].interface_id, id); + if (name) { + switch_set_string(SKYPIAX_INTERFACES[interface_id].name, name); + } else { + switch_set_string(SKYPIAX_INTERFACES[interface_id].name, "N/A"); + } + switch_set_string(SKYPIAX_INTERFACES[interface_id].X11_display, X11_display); + switch_set_string(SKYPIAX_INTERFACES[interface_id].context, context); + switch_set_string(SKYPIAX_INTERFACES[interface_id].dialplan, dialplan); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "interface_id=%d SKYPIAX_INTERFACES[interface_id].X11_display=%s\n", + interface_id, SKYPIAX_INTERFACES[interface_id].X11_display); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "interface_id=%d SKYPIAX_INTERFACES[interface_id].name=%s\n", + interface_id, SKYPIAX_INTERFACES[interface_id].name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "interface_id=%d SKYPIAX_INTERFACES[interface_id].context=%s\n", + interface_id, SKYPIAX_INTERFACES[interface_id].context); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "interface_id=%d SKYPIAX_INTERFACES[interface_id].dialplan=%s\n", + interface_id, SKYPIAX_INTERFACES[interface_id].dialplan); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, + "STARTING interface_id=%d\n", interface_id); + + if (1) { + 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(&thread, thd_attr, do_skype_thread, + &SKYPIAX_INTERFACES[interface_id], module_pool); + } + + switch_sleep(100000); + if (1) { + 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(&thread, thd_attr, skypiax_do_controldev_thread, + &SKYPIAX_INTERFACES[interface_id], module_pool); + } + + switch_sleep(1000000); + + skypiax_skypeaudio_init(&SKYPIAX_INTERFACES[interface_id]); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, + "STARTED interface_id=%d\n", interface_id); + + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, + "interface id %d is higher than SKYPIAX_MAX_INTERFACES (%d)\n", + interface_id, SKYPIAX_MAX_INTERFACES); + continue; + } + + } + + for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) { + if (strlen(SKYPIAX_INTERFACES[i].name)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "i=%d SKYPIAX_INTERFACES[%d].interface_id=%s\n", i, i, + SKYPIAX_INTERFACES[i].interface_id); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "i=%d SKYPIAX_INTERFACES[%d].X11_display=%s\n", i, i, + SKYPIAX_INTERFACES[i].X11_display); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "i=%d SKYPIAX_INTERFACES[%d].name=%s\n", i, i, + SKYPIAX_INTERFACES[i].name); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "i=%d SKYPIAX_INTERFACES[%d].context=%s\n", i, i, + SKYPIAX_INTERFACES[i].context); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, + "i=%d SKYPIAX_INTERFACES[%d].dialplan=%s\n", i, i, + SKYPIAX_INTERFACES[i].dialplan); + } + } + } + + switch_xml_free(xml); + + return SWITCH_STATUS_SUCCESS; } SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load) { struct skypiax_interface *p = NULL; - module_pool = pool; + module_pool = pool; - memset(&globals, '\0', sizeof(globals)); - memset(SKYPIAX_INTERFACES, '\0', sizeof(SKYPIAX_INTERFACES)); + memset(&globals, '\0', sizeof(globals)); + memset(SKYPIAX_INTERFACES, '\0', sizeof(SKYPIAX_INTERFACES)); -#ifndef _WINDOWS_ //FIXME +#ifndef _WINDOWS_ //FIXME if (!XInitThreads()) { - ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG); + ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG); } else { - DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG); + DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG); } -switch_sleep(10000); //FIXME + switch_sleep(10000); //FIXME #endif /* _WINDOWS_ */ + load_config(); + *module_interface = switch_loadable_module_create_module_interface(pool, modname); + skypiax_endpoint_interface = + switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); + skypiax_endpoint_interface->interface_name = "skypiax"; + skypiax_endpoint_interface->io_routines = &skypiax_io_routines; + skypiax_endpoint_interface->state_handler = &skypiax_state_handlers; - load_config(); - - - *module_interface = switch_loadable_module_create_module_interface(pool, modname); - skypiax_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE); - skypiax_endpoint_interface->interface_name = "skypiax"; - skypiax_endpoint_interface->io_routines = &skypiax_io_routines; - skypiax_endpoint_interface->state_handler = &skypiax_state_handlers; - - /* indicate that the module should continue to be loaded */ - return SWITCH_STATUS_SUCCESS; + /* indicate that the module should continue to be loaded */ + return SWITCH_STATUS_SUCCESS; } /* @@ -3094,64 +3124,64 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skypiax_shutdown) { - int x = 0; + int x = 0; + + running = -1; + + while (running) { + if (x++ > 100) { + break; + } + switch_yield(20000); + } + return SWITCH_STATUS_SUCCESS; +} + +static switch_status_t channel_on_hangup(switch_core_session_t * session) +{ + switch_channel_t *channel = NULL; + private_t *tech_pvt = NULL; + skypiax_interface_t *p; + char msg_to_skype[256]; - running = -1; + channel = switch_core_session_get_channel(session); + assert(channel != NULL); - while (running) { - if (x++ > 100) { - break; - } - switch_yield(20000); - } - return SWITCH_STATUS_SUCCESS; -} - -static switch_status_t channel_on_hangup(switch_core_session_t *session) -{ - switch_channel_t *channel = NULL; - private_t *tech_pvt = NULL; - skypiax_interface_t *p; - char msg_to_skype[256]; - - channel = switch_core_session_get_channel(session); - assert(channel != NULL); - - tech_pvt = switch_core_session_get_private(session); - assert(tech_pvt != NULL); - - p = tech_pvt->p; - - switch_clear_flag_locked(tech_pvt, TFLAG_IO); - switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); - //switch_set_flag_locked(tech_pvt, TFLAG_HANGUP); - - if(strlen(p->skype_call_id)) { - //switch_thread_cond_signal(tech_pvt->cond); - WARNINGA("hanging up skype call: %s\n", SKYPIAX_P_LOG, p->skype_call_id); - //sprintf(msg_to_skype, "SET CALL %s STATUS FINISHED", p->skype_call_id); - sprintf(msg_to_skype, "ALTER CALL %s HANGUP", p->skype_call_id); - skypiax_skype_write(p, msg_to_skype); - } - - if (tech_pvt->read_codec.implementation) { - switch_core_codec_destroy(&tech_pvt->read_codec); - } - - if (tech_pvt->write_codec.implementation) { - switch_core_codec_destroy(&tech_pvt->write_codec); - } - - - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel)); - switch_mutex_lock(globals.mutex); - globals.calls--; - if (globals.calls < 0) { - globals.calls = 0; - } - switch_mutex_unlock(globals.mutex); + tech_pvt = switch_core_session_get_private(session); + assert(tech_pvt != NULL); - return SWITCH_STATUS_SUCCESS; + p = tech_pvt->p; + + switch_clear_flag_locked(tech_pvt, TFLAG_IO); + switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); + //switch_set_flag_locked(tech_pvt, TFLAG_HANGUP); + + if (strlen(p->skype_call_id)) { + //switch_thread_cond_signal(tech_pvt->cond); + WARNINGA("hanging up skype call: %s\n", SKYPIAX_P_LOG, p->skype_call_id); + //sprintf(msg_to_skype, "SET CALL %s STATUS FINISHED", p->skype_call_id); + sprintf(msg_to_skype, "ALTER CALL %s HANGUP", p->skype_call_id); + skypiax_skype_write(p, msg_to_skype); + } + + if (tech_pvt->read_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->read_codec); + } + + if (tech_pvt->write_codec.implementation) { + switch_core_codec_destroy(&tech_pvt->write_codec); + } + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", + switch_channel_get_name(channel)); + switch_mutex_lock(globals.mutex); + globals.calls--; + if (globals.calls < 0) { + globals.calls = 0; + } + switch_mutex_unlock(globals.mutex); + + return SWITCH_STATUS_SUCCESS; } /* For Emacs:
participants (1)
-
FreeSWITCH SVN