add function to help set session read codec to slinear

This commit is contained in:
Anthony Minessale 2011-01-06 17:41:17 -06:00
parent 85c22d10e2
commit 1a08df9b20
4 changed files with 44 additions and 1 deletions

View File

@ -116,7 +116,6 @@ struct switch_core_session;
struct switch_core_runtime;
struct switch_core_port_allocator;
/*!
\defgroup core1 Core Library
\ingroup FREESWITCH
@ -713,6 +712,7 @@ SWITCH_DECLARE(void) switch_core_session_soft_lock(switch_core_session_t *sessio
SWITCH_DECLARE(void) switch_core_session_soft_unlock(switch_core_session_t *session);
SWITCH_DECLARE(void) switch_core_session_set_dmachine(switch_core_session_t *session, switch_ivr_dmachine_t *dmachine);
SWITCH_DECLARE(switch_ivr_dmachine_t *) switch_core_session_get_dmachine(switch_core_session_t *session);
SWITCH_DECLARE(switch_status_t) switch_core_session_set_codec_slin(switch_core_session_t *session, switch_slin_data_t *data);
/*!
\brief Retrieve the unique identifier from the core

View File

@ -711,6 +711,14 @@ struct switch_api_interface {
#define PROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_rdlock(_it->parent->rwlock); switch_thread_rwlock_rdlock(_it->rwlock); _it->refs++; _it->parent->refs++; switch_mutex_unlock(_it->reflock);} //if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "+++++++++++LOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
#define UNPROTECT_INTERFACE(_it) if (_it) {switch_mutex_lock(_it->reflock); switch_thread_rwlock_unlock(_it->rwlock); switch_thread_rwlock_unlock(_it->parent->rwlock); _it->refs--; _it->parent->refs--; switch_mutex_unlock(_it->reflock);} //if (!strcmp(_it->interface_name, "user")) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "---------UNLOCK %s %d/%d\n", _it->interface_name, _it->refs, _it->parent->refs);
#include "switch_frame.h"
struct switch_slin_data {
switch_core_session_t *session;
switch_frame_t write_frame;
switch_codec_t codec;
char frame_data[SWITCH_RECOMMENDED_BUFFER_SIZE];
};
SWITCH_END_EXTERN_C
#endif

View File

@ -1817,6 +1817,8 @@ typedef struct switch_loadable_module_function_table {
typedef int (*switch_modulename_callback_func_t) (void *user_data, const char *module_name);
typedef struct switch_slin_data switch_slin_data_t;
#define SWITCH_MODULE_DEFINITION_EX(name, load, shutdown, runtime, flags) \
static const char modname[] = #name ; \
SWITCH_MOD_DECLARE_DATA switch_loadable_module_function_table_t name##_module_interface = { \

View File

@ -58,6 +58,39 @@ SWITCH_DECLARE(void) switch_core_session_soft_unlock(switch_core_session_t *sess
session->soft_lock = 0;
}
SWITCH_DECLARE(switch_status_t) switch_core_session_set_codec_slin(switch_core_session_t *session, switch_slin_data_t *data)
{
switch_codec_implementation_t read_impl = { 0 };
int interval;
switch_core_session_get_read_impl(session, &read_impl);
interval = read_impl.microseconds_per_packet / 1000;
data->session = session;
if (switch_core_codec_init(&data->codec,
"L16",
NULL,
read_impl.actual_samples_per_second,
interval,
1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, NULL) == SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
SWITCH_LOG_DEBUG, "Codec Activated L16@%uhz %dms\n", read_impl.actual_samples_per_second, interval);
memset(&data->write_frame, 0, sizeof(data->write_frame));
data->write_frame.codec = &data->codec;
data->write_frame.data = data->frame_data;
data->write_frame.buflen = sizeof(data->frame_data);
data->write_frame.datalen = 0;
switch_core_session_set_read_codec(session, &data->codec);
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
}
#ifdef SWITCH_DEBUG_RWLOCKS
SWITCH_DECLARE(switch_core_session_t *) switch_core_session_perform_locate(const char *uuid_str, const char *file, const char *func, int line)
#else