FS-7500: add switch_core_session_raw_read to put session into raw read mode without needing a local codec var (WE SHOULD REFACTOR MUCH OF switch_ivr_* to use this...) and add echo_decode_audio option to echo app

This commit is contained in:
Anthony Minessale 2014-11-20 11:28:05 -06:00 committed by Michael Jerris
parent a74b6f62a2
commit 4dc155f164
5 changed files with 29 additions and 23 deletions

View File

@ -194,6 +194,7 @@ struct switch_core_session {
switch_image_write_callback_t image_write_callback; switch_image_write_callback_t image_write_callback;
void *image_write_callback_user_data; void *image_write_callback_user_data;
switch_slin_data_t *sdata;
}; };
struct switch_media_bug { struct switch_media_bug {

View File

@ -861,6 +861,7 @@ SWITCH_DECLARE(switch_digit_action_target_t) switch_ivr_dmachine_get_target(swit
SWITCH_DECLARE(void) switch_ivr_dmachine_set_target(switch_ivr_dmachine_t *dmachine, switch_digit_action_target_t target); SWITCH_DECLARE(void) switch_ivr_dmachine_set_target(switch_ivr_dmachine_t *dmachine, switch_digit_action_target_t target);
SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_terminators(switch_ivr_dmachine_t *dmachine, const char *terminators); SWITCH_DECLARE(switch_status_t) switch_ivr_dmachine_set_terminators(switch_ivr_dmachine_t *dmachine, const char *terminators);
SWITCH_DECLARE(switch_status_t) switch_core_session_set_codec_slin(switch_core_session_t *session, switch_slin_data_t *data); SWITCH_DECLARE(switch_status_t) switch_core_session_set_codec_slin(switch_core_session_t *session, switch_slin_data_t *data);
SWITCH_DECLARE(void) switch_core_session_raw_read(switch_core_session_t *session);
/*! /*!
\brief Retrieve the unique identifier from the core \brief Retrieve the unique identifier from the core

View File

@ -568,7 +568,7 @@ SWITCH_STANDARD_APP(play_yuv_function)
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_frame_t vid_frame = { 0 }; switch_frame_t vid_frame = { 0 };
int fd = -1; int fd = -1;
switch_codec_t read_codec, *codec = NULL; switch_codec_t *codec = NULL;
unsigned char *vid_buffer; unsigned char *vid_buffer;
// switch_timer_t timer = { 0 }; // switch_timer_t timer = { 0 };
switch_dtmf_t dtmf = { 0 }; switch_dtmf_t dtmf = { 0 };
@ -578,7 +578,6 @@ SWITCH_STANDARD_APP(play_yuv_function)
switch_byte_t *yuv = NULL; switch_byte_t *yuv = NULL;
int argc; int argc;
char *argv[3] = { 0 }; char *argv[3] = { 0 };
switch_codec_implementation_t read_impl = { 0 };
char *mydata = switch_core_session_strdup(session, data); char *mydata = switch_core_session_strdup(session, data);
uint32_t loops = 0; uint32_t loops = 0;
@ -591,24 +590,7 @@ SWITCH_STANDARD_APP(play_yuv_function)
} }
switch_channel_audio_sync(channel); switch_channel_audio_sync(channel);
switch_core_session_raw_read(session);
switch_core_session_get_read_impl(session, &read_impl);
if (switch_core_codec_init(&read_codec,
"L16",
NULL,
read_impl.samples_per_second,
read_impl.microseconds_per_packet / 1000,
read_impl.number_of_channels, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Audio Codec Activation Success\n");
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Audio Codec Activation Fail\n");
switch_channel_set_variable(channel, SWITCH_CURRENT_APPLICATION_RESPONSE_VARIABLE, "Audio codec activation failed");
goto done;
}
switch_core_session_set_read_codec(session, &read_codec);
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0]))); argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
@ -716,7 +698,6 @@ SWITCH_STANDARD_APP(play_yuv_function)
done: done:
switch_core_codec_destroy(&read_codec);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE); switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
// switch_channel_clear_flag(channel, CF_VIDEO_PASSIVE); // switch_channel_clear_flag(channel, CF_VIDEO_PASSIVE);

View File

@ -99,7 +99,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_codec_slin(switch_core_s
NULL, NULL,
read_impl.actual_samples_per_second, read_impl.actual_samples_per_second,
interval, interval,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) == SWITCH_STATUS_SUCCESS) { read_impl.number_of_channels, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %dms\n", read_impl.actual_samples_per_second, interval); SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %dms\n", read_impl.actual_samples_per_second, interval);
@ -1298,6 +1298,9 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s
if (reset_read_codec) { if (reset_read_codec) {
switch_core_session_set_read_codec(session, NULL); switch_core_session_set_read_codec(session, NULL);
if (session->sdata && switch_core_codec_ready(&session->sdata->codec)) {
switch_core_codec_destroy(&session->sdata->codec);
}
} }
/* clear resamplers */ /* clear resamplers */
@ -1667,7 +1670,7 @@ static void *SWITCH_THREAD_FUNC switch_core_session_thread_pool_worker(switch_th
switch_memory_pool_t *pool = node->pool; switch_memory_pool_t *pool = node->pool;
void *pop; void *pop;
int check = 0; int check = 0;
switch_mutex_lock(session_manager.mutex); switch_mutex_lock(session_manager.mutex);
session_manager.starting--; session_manager.starting--;
session_manager.running++; session_manager.running++;
@ -3066,6 +3069,21 @@ SWITCH_DECLARE(void) switch_core_session_debug_pool(switch_stream_handle_t *stre
session_manager.running, session_manager.busy, session_manager.popping); session_manager.running, session_manager.busy, session_manager.popping);
} }
SWITCH_DECLARE(void) switch_core_session_raw_read(switch_core_session_t *session)
{
if (session->sdata) {
if (session->sdata && switch_core_codec_ready(&session->sdata->codec)) {
switch_core_codec_destroy(&session->sdata->codec);
}
memset(session->sdata, 0, sizeof(*session->sdata));
} else {
session->sdata = switch_core_session_alloc(session, sizeof(*session->sdata));
}
switch_core_session_set_codec_slin(session, session->sdata);
}
/* For Emacs: /* For Emacs:
* Local Variables: * Local Variables:
* mode:c * mode:c

View File

@ -648,6 +648,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_echo(switch_core_session_t *s
switch_channel_set_flag(channel, CF_VIDEO_DECODED_READ); switch_channel_set_flag(channel, CF_VIDEO_DECODED_READ);
} }
if (switch_true(switch_channel_get_variable(channel, "echo_decode_audio"))) {
switch_core_session_raw_read(session);
}
while (switch_channel_ready(channel)) { while (switch_channel_ready(channel)) {
status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0); status = switch_core_session_read_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
@ -700,6 +704,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_session_echo(switch_core_session_t *s
} }
switch_core_session_video_reset(session); switch_core_session_video_reset(session);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }