mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-26 03:36:40 +00:00
fuggit
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11351 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
f40e5a06be
commit
38eabef83b
@ -42,8 +42,8 @@
|
|||||||
|
|
||||||
SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load);
|
SWITCH_MODULE_LOAD_FUNCTION(mod_portaudio_load);
|
||||||
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_shutdown);
|
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_shutdown);
|
||||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_portaudio_runtime);
|
//SWITCH_MODULE_RUNTIME_FUNCTION(mod_portaudio_runtime);
|
||||||
SWITCH_MODULE_DEFINITION(mod_portaudio, mod_portaudio_load, mod_portaudio_shutdown, mod_portaudio_runtime);
|
SWITCH_MODULE_DEFINITION(mod_portaudio, mod_portaudio_load, mod_portaudio_shutdown, NULL);
|
||||||
|
|
||||||
static switch_memory_pool_t *module_pool = NULL;
|
static switch_memory_pool_t *module_pool = NULL;
|
||||||
switch_endpoint_interface_t *portaudio_endpoint_interface;
|
switch_endpoint_interface_t *portaudio_endpoint_interface;
|
||||||
@ -200,7 +200,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
|
|||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL INIT %d %d\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL INIT %d %d\n",
|
||||||
switch_channel_get_name(channel), switch_channel_get_state(channel), switch_test_flag(tech_pvt, TFLAG_ANSWER));
|
switch_channel_get_name(channel), switch_channel_get_state(channel), switch_test_flag(tech_pvt, TFLAG_ANSWER));
|
||||||
|
|
||||||
if (engage_device(tech_pvt->sample_rate, tech_pvt->codec_ms) != SWITCH_STATUS_SUCCESS) {
|
if (engage_device(globals.sample_rate, globals.codec_ms) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
@ -243,6 +243,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
|
|||||||
switch_channel_mark_answered(channel);
|
switch_channel_mark_answered(channel);
|
||||||
switch_set_flag(tech_pvt, TFLAG_ANSWER);
|
switch_set_flag(tech_pvt, TFLAG_ANSWER);
|
||||||
switch_mutex_unlock(globals.pvt_lock);
|
switch_mutex_unlock(globals.pvt_lock);
|
||||||
|
switch_yield(1000000);
|
||||||
} else {
|
} else {
|
||||||
switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
|
switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
|
||||||
switch_channel_mark_ring_ready(channel);
|
switch_channel_mark_ring_ready(channel);
|
||||||
@ -334,6 +335,14 @@ static void deactivate_audio_device(void)
|
|||||||
globals.audio_stream = NULL;
|
globals.audio_stream = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* UNLOCKED ************************************************************************************************* */
|
||||||
|
switch_mutex_unlock(globals.device_lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void destroy_codecs(void)
|
||||||
|
{
|
||||||
|
|
||||||
if (globals.read_codec.implementation) {
|
if (globals.read_codec.implementation) {
|
||||||
switch_core_codec_destroy(&globals.read_codec);
|
switch_core_codec_destroy(&globals.read_codec);
|
||||||
}
|
}
|
||||||
@ -350,11 +359,10 @@ static void deactivate_audio_device(void)
|
|||||||
switch_core_timer_destroy(&globals.hold_timer);
|
switch_core_timer_destroy(&globals.hold_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* UNLOCKED ************************************************************************************************* */
|
|
||||||
switch_mutex_unlock(globals.device_lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static void deactivate_ring_device(void)
|
static void deactivate_ring_device(void)
|
||||||
{
|
{
|
||||||
if (!globals.ring_stream) {
|
if (!globals.ring_stream) {
|
||||||
@ -413,6 +421,8 @@ static void add_pvt(private_t *tech_pvt, int master)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
globals.deactivate_timer = 0;
|
||||||
|
|
||||||
switch_mutex_unlock(globals.pvt_lock);
|
switch_mutex_unlock(globals.pvt_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -537,7 +547,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|
|||||||
switch_size_t olen = globals.read_codec.implementation->samples_per_packet;
|
switch_size_t olen = globals.read_codec.implementation->samples_per_packet;
|
||||||
|
|
||||||
if (!tech_pvt->hfh) {
|
if (!tech_pvt->hfh) {
|
||||||
int sample_rate = tech_pvt->sample_rate ? tech_pvt->sample_rate : globals.sample_rate;
|
int sample_rate = globals.sample_rate;
|
||||||
if (switch_core_file_open(&tech_pvt->fh,
|
if (switch_core_file_open(&tech_pvt->fh,
|
||||||
tech_pvt->hold_file,
|
tech_pvt->hold_file,
|
||||||
globals.read_codec.implementation->number_of_channels,
|
globals.read_codec.implementation->number_of_channels,
|
||||||
@ -693,6 +703,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
|
|||||||
switch_caller_profile_t *outbound_profile,
|
switch_caller_profile_t *outbound_profile,
|
||||||
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
|
switch_core_session_t **new_session, switch_memory_pool_t **pool, switch_originate_flag_t flags)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ((*new_session = switch_core_session_request(portaudio_endpoint_interface, pool)) != 0) {
|
if ((*new_session = switch_core_session_request(portaudio_endpoint_interface, pool)) != 0) {
|
||||||
private_t *tech_pvt;
|
private_t *tech_pvt;
|
||||||
switch_channel_t *channel;
|
switch_channel_t *channel;
|
||||||
@ -964,9 +975,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_shutdown)
|
|||||||
|
|
||||||
deactivate_audio_device();
|
deactivate_audio_device();
|
||||||
deactivate_ring_device();
|
deactivate_ring_device();
|
||||||
|
destroy_codecs();
|
||||||
|
|
||||||
switch_core_timer_destroy(&globals.timer);
|
|
||||||
switch_core_timer_destroy(&globals.hold_timer);
|
|
||||||
Pa_Terminate();
|
Pa_Terminate();
|
||||||
switch_core_hash_destroy(&globals.call_hash);
|
switch_core_hash_destroy(&globals.call_hash);
|
||||||
|
|
||||||
@ -975,21 +985,25 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_portaudio_shutdown)
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
SWITCH_MODULE_RUNTIME_FUNCTION(mod_portaudio_runtime)
|
SWITCH_MODULE_RUNTIME_FUNCTION(mod_portaudio_runtime)
|
||||||
{
|
{
|
||||||
globals.monitor_running = 1;
|
globals.monitor_running = 1;
|
||||||
while(globals.monitor_running == 1) {
|
while(globals.monitor_running == 1) {
|
||||||
|
switch_mutex_lock(globals.pvt_lock);
|
||||||
if (!globals.call_list && globals.deactivate_timer > 0) {
|
if (!globals.call_list && globals.deactivate_timer > 0) {
|
||||||
if (!--globals.deactivate_timer) {
|
if (!--globals.deactivate_timer) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No more channels, deactivating audio\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No more channels, deactivating audio\n");
|
||||||
deactivate_audio_device();
|
deactivate_audio_device();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch_mutex_unlock(globals.pvt_lock);
|
||||||
switch_yield(1000000);
|
switch_yield(1000000);
|
||||||
}
|
}
|
||||||
globals.monitor_running = 0;
|
globals.monitor_running = 0;
|
||||||
return SWITCH_STATUS_TERM;
|
return SWITCH_STATUS_TERM;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int get_dev_by_number(char *numstr, int in)
|
static int get_dev_by_number(char *numstr, int in)
|
||||||
{
|
{
|
||||||
@ -1345,6 +1359,14 @@ static switch_status_t engage_device(int sample_rate, int codec_ms)
|
|||||||
err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
|
err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
|
||||||
globals.read_codec.implementation->samples_per_packet, globals.dual_streams);
|
globals.read_codec.implementation->samples_per_packet, globals.dual_streams);
|
||||||
/* UNLOCKED ************************************************************************************************* */
|
/* UNLOCKED ************************************************************************************************* */
|
||||||
|
|
||||||
|
if (err != paNoError) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error opening audio device! retrying\n");
|
||||||
|
switch_yield(1000000);
|
||||||
|
err = OpenAudioStream(&globals.audio_stream, &inputParameters, &outputParameters, sample_rate, paClipOff,
|
||||||
|
globals.read_codec.implementation->samples_per_packet, globals.dual_streams);
|
||||||
|
}
|
||||||
|
|
||||||
switch_mutex_unlock(globals.device_lock);
|
switch_mutex_unlock(globals.device_lock);
|
||||||
|
|
||||||
if (err != paNoError) {
|
if (err != paNoError) {
|
||||||
|
@ -260,15 +260,9 @@ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
|
|||||||
|
|
||||||
/* Allocate PABLIO_Stream structure for caller. */
|
/* Allocate PABLIO_Stream structure for caller. */
|
||||||
aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
|
aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
|
||||||
if (aStream == NULL)
|
switch_assert(aStream);
|
||||||
return paInsufficientMemory;
|
|
||||||
memset(aStream, 0, sizeof(PABLIO_Stream));
|
memset(aStream, 0, sizeof(PABLIO_Stream));
|
||||||
|
|
||||||
/* Initialize PortAudio */
|
|
||||||
err = Pa_Initialize();
|
|
||||||
if (err != paNoError)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (inputParameters) {
|
if (inputParameters) {
|
||||||
channels = inputParameters->channelCount;
|
channels = inputParameters->channelCount;
|
||||||
} else if (outputParameters) {
|
} else if (outputParameters) {
|
||||||
@ -282,32 +276,24 @@ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
|
|||||||
|
|
||||||
if (inputParameters) {
|
if (inputParameters) {
|
||||||
err = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame);
|
err = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame);
|
||||||
if (err != paNoError)
|
if (err != paNoError) {
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
aStream-> has_in = 1;
|
aStream-> has_in = 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputParameters) {
|
if (outputParameters) {
|
||||||
err = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame);
|
err = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame);
|
||||||
if (err != paNoError)
|
if (err != paNoError) {
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
aStream-> has_out = 1;
|
aStream-> has_out = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make Write FIFO appear full initially. */
|
|
||||||
//numBytes = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
|
|
||||||
//PaUtil_AdvanceRingBufferWriteIndex(&aStream->outFIFO, numBytes);
|
|
||||||
|
|
||||||
|
|
||||||
/* Open a PortAudio stream that we will use to communicate with the underlying
|
/* Open a PortAudio stream that we will use to communicate with the underlying
|
||||||
* audio drivers. */
|
* audio drivers. */
|
||||||
|
|
||||||
aStream->do_dual = do_dual;
|
aStream->do_dual = do_dual;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (aStream->do_dual) {
|
if (aStream->do_dual) {
|
||||||
err = Pa_OpenStream(&aStream->istream, inputParameters, NULL, sampleRate, samples_per_packet, streamFlags, iblockingIOCallback, aStream);
|
err = Pa_OpenStream(&aStream->istream, inputParameters, NULL, sampleRate, samples_per_packet, streamFlags, iblockingIOCallback, aStream);
|
||||||
@ -322,8 +308,9 @@ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
|
|||||||
err = Pa_OpenStream(&aStream->iostream, inputParameters, outputParameters, sampleRate, samples_per_packet, streamFlags, ioblockingIOCallback, aStream);
|
err = Pa_OpenStream(&aStream->iostream, inputParameters, outputParameters, sampleRate, samples_per_packet, streamFlags, ioblockingIOCallback, aStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err != paNoError)
|
if (err != paNoError) {
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
if (aStream->do_dual) {
|
if (aStream->do_dual) {
|
||||||
err = Pa_StartStream(aStream->istream);
|
err = Pa_StartStream(aStream->istream);
|
||||||
@ -338,7 +325,6 @@ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
err = Pa_StartStream(aStream->iostream);
|
err = Pa_StartStream(aStream->iostream);
|
||||||
}
|
}
|
||||||
@ -348,13 +334,15 @@ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
|
|||||||
}
|
}
|
||||||
|
|
||||||
*rwblPtr = aStream;
|
*rwblPtr = aStream;
|
||||||
|
|
||||||
switch_yield(500000);
|
|
||||||
|
|
||||||
|
switch_yield(500000);
|
||||||
|
|
||||||
return paNoError;
|
return paNoError;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
|
||||||
CloseAudioStream(aStream);
|
CloseAudioStream(aStream);
|
||||||
|
|
||||||
*rwblPtr = NULL;
|
*rwblPtr = NULL;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -363,14 +351,19 @@ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
|
|||||||
PaError CloseAudioStream(PABLIO_Stream * aStream)
|
PaError CloseAudioStream(PABLIO_Stream * aStream)
|
||||||
{
|
{
|
||||||
int bytesEmpty;
|
int bytesEmpty;
|
||||||
int byteSize = aStream->outFIFO.bufferSize;
|
int byteSize;
|
||||||
|
|
||||||
/* If we are writing data, make sure we play everything written. */
|
|
||||||
if (byteSize > 0) {
|
byteSize = aStream->outFIFO.bufferSize;
|
||||||
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
|
|
||||||
while (bytesEmpty < byteSize) {
|
if (aStream->has_out) {
|
||||||
Pa_Sleep(10);
|
/* If we are writing data, make sure we play everything written. */
|
||||||
|
if (byteSize > 0) {
|
||||||
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
|
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
|
||||||
|
while (bytesEmpty < byteSize) {
|
||||||
|
Pa_Sleep(10);
|
||||||
|
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,10 +397,15 @@ PaError CloseAudioStream(PABLIO_Stream * aStream)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PABLIO_TermFIFO(&aStream->inFIFO);
|
if (aStream->has_in) {
|
||||||
PABLIO_TermFIFO(&aStream->outFIFO);
|
PABLIO_TermFIFO(&aStream->inFIFO);
|
||||||
free(aStream);
|
}
|
||||||
|
|
||||||
|
if (aStream->has_out) {
|
||||||
|
PABLIO_TermFIFO(&aStream->outFIFO);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(aStream);
|
||||||
switch_yield(500000);
|
switch_yield(500000);
|
||||||
|
|
||||||
return paNoError;
|
return paNoError;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user