[commit] r10342 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax
Author: gmaruzz Date: Wed Nov 12 05:32:02 2008 New Revision: 10342 Log: skypiax: accept a call and sends you the audioPA_ALSA_PLUGHW=1 /usr/local/freeswitch/bin/freeswitch PA_ALSA_PLUGHW=1 /usr/local/freeswitch/bin/freeswitch 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 Wed Nov 12 05:32:02 2008 @@ -220,6 +220,134 @@ int option_debug = 100; +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; + + + 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; + +} +#undef PORTAUDIO_ENGAGE +#ifdef PORTAUDIO_ENGAGE +static switch_status_t engage_device(int sample_rate, int codec_ms) +{ + PaStreamParameters inputParameters, outputParameters; + PaError err; + + if (!globals.audio_stream) { + if (!sample_rate) { + sample_rate = globals.sample_rate; + } + if (!codec_ms) { + codec_ms = globals.codec_ms; + } + + if (!globals.read_codec.implementation) { + if (switch_core_codec_init(&globals.read_codec, + "L16", + NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, + NULL) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); + return SWITCH_STATUS_FALSE; + } + } + + switch_assert(globals.read_codec.implementation); + + if (!globals.write_codec.implementation) { + if (switch_core_codec_init(&globals.write_codec, + "L16", + NULL, + sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, + NULL) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); + switch_core_codec_destroy(&globals.read_codec); + return SWITCH_STATUS_FALSE; + } + } + + if (!globals.timer.timer_interface) { + if (switch_core_timer_init(&globals.timer, + globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_packet, + module_pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup timer failed!\n"); + switch_core_codec_destroy(&globals.read_codec); + switch_core_codec_destroy(&globals.write_codec); + return SWITCH_STATUS_FALSE; + } + } + + if (!globals.hold_timer.timer_interface) { + if (switch_core_timer_init(&globals.hold_timer, + globals.timer_name, codec_ms, globals.read_codec.implementation->samples_per_packet, + module_pool) != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "setup hold timer failed!\n"); + switch_core_codec_destroy(&globals.read_codec); + switch_core_codec_destroy(&globals.write_codec); + switch_core_timer_destroy(&globals.timer); + return SWITCH_STATUS_FALSE; + } + } + + globals.read_frame.rate = sample_rate; + globals.read_frame.codec = &globals.read_codec; + + switch_mutex_lock(globals.device_lock); + /* LOCKED ************************************************************************************************** */ + inputParameters.device = globals.indev; + inputParameters.channelCount = 1; + inputParameters.sampleFormat = SAMPLE_TYPE; + inputParameters.suggestedLatency = Pa_GetDeviceInfo(inputParameters.device)->defaultLowInputLatency; + inputParameters.hostApiSpecificStreamInfo = NULL; + + outputParameters.device = globals.outdev; + outputParameters.channelCount = 1; + outputParameters.sampleFormat = SAMPLE_TYPE; + outputParameters.suggestedLatency = Pa_GetDeviceInfo(outputParameters.device)->defaultLowOutputLatency; + outputParameters.hostApiSpecificStreamInfo = NULL; + err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff, + globals.read_codec.implementation->samples_per_packet); + /* UNLOCKED ************************************************************************************************* */ + switch_mutex_unlock(globals.device_lock); + + if (err != paNoError) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't open audio device!\n"); + switch_core_codec_destroy(&globals.read_codec); + switch_core_codec_destroy(&globals.write_codec); + switch_core_timer_destroy(&globals.timer); + switch_core_timer_destroy(&globals.hold_timer); + return SWITCH_STATUS_FALSE; + } + } + + return SWITCH_STATUS_SUCCESS; +} +#endif // PORTAUDIO_ENGAGE + + #define SKYPE_AUDIO #ifdef SKYPE_AUDIO @@ -519,6 +647,13 @@ tech_pvt->session = session; if(p) tech_pvt->p=p; +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_ERROR, "skypiax_docec SUCCESS\n"); +} + DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG); } @@ -719,7 +854,7 @@ #endif - //switch_set_flag_locked(tech_pvt, TFLAG_VOICE); //FIXME + switch_set_flag_locked(tech_pvt, TFLAG_VOICE); //FIXME if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) { switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
participants (1)
-
FreeSWITCH SVN