ok we have 22k chatting with 8k
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@294 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
fabaf64c3c
commit
26e057a32d
|
@ -62,7 +62,7 @@ static switch_status switch_raw_encode(switch_codec *codec,
|
||||||
{
|
{
|
||||||
|
|
||||||
/* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary.*/
|
/* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary.*/
|
||||||
if (decoded_rate != other_codec->implementation->samples_per_second) {
|
if (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
|
||||||
memcpy(encoded_data, decoded_data, decoded_data_len);
|
memcpy(encoded_data, decoded_data, decoded_data_len);
|
||||||
*encoded_data_len = decoded_data_len;
|
*encoded_data_len = decoded_data_len;
|
||||||
return SWITCH_STATUS_RESAMPLE;
|
return SWITCH_STATUS_RESAMPLE;
|
||||||
|
@ -80,7 +80,7 @@ static switch_status switch_raw_decode(switch_codec *codec,
|
||||||
int *decoded_rate,
|
int *decoded_rate,
|
||||||
unsigned int *flag)
|
unsigned int *flag)
|
||||||
{
|
{
|
||||||
if (encoded_rate != other_codec->implementation->samples_per_second) {
|
if (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
|
||||||
memcpy(decoded_data, encoded_data, encoded_data_len);
|
memcpy(decoded_data, encoded_data, encoded_data_len);
|
||||||
*decoded_data_len = encoded_data_len;
|
*decoded_data_len = encoded_data_len;
|
||||||
return SWITCH_STATUS_RESAMPLE;
|
return SWITCH_STATUS_RESAMPLE;
|
||||||
|
|
|
@ -161,13 +161,13 @@ SWITCH_DECLARE(FILE *) switch_core_data_channel(switch_text_channel channel)
|
||||||
FILE *handle = stdout;
|
FILE *handle = stdout;
|
||||||
|
|
||||||
switch (channel) {
|
switch (channel) {
|
||||||
case SWITCH_CHANNEL_ID_CONSOLE:
|
case SWITCH_CHANNEL_ID_CONSOLE:
|
||||||
case SWITCH_CHANNEL_ID_CONSOLE_CLEAN:
|
case SWITCH_CHANNEL_ID_CONSOLE_CLEAN:
|
||||||
handle = runtime.console;
|
handle = runtime.console;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
handle = stdout;
|
handle = stdout;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
|
@ -225,8 +225,8 @@ SWITCH_DECLARE(switch_status) switch_core_codec_init(switch_codec *codec, char *
|
||||||
if ((!rate || rate == iptr->samples_per_second) &&
|
if ((!rate || rate == iptr->samples_per_second) &&
|
||||||
(!ms || ms == (iptr->microseconds_per_frame / 1000)) &&
|
(!ms || ms == (iptr->microseconds_per_frame / 1000)) &&
|
||||||
(!channels || channels == iptr->number_of_channels)) {
|
(!channels || channels == iptr->number_of_channels)) {
|
||||||
implementation = iptr;
|
implementation = iptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +279,17 @@ SWITCH_DECLARE(switch_status) switch_core_codec_encode(switch_codec *codec,
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len, decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
|
*encoded_data_len = decoded_data_len;
|
||||||
|
return codec->implementation->encode(codec,
|
||||||
|
other_codec,
|
||||||
|
decoded_data,
|
||||||
|
decoded_data_len,
|
||||||
|
decoded_rate,
|
||||||
|
encoded_data,
|
||||||
|
encoded_data_len,
|
||||||
|
encoded_rate,
|
||||||
|
flag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec,
|
SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec,
|
||||||
|
@ -306,7 +316,18 @@ SWITCH_DECLARE(switch_status) switch_core_codec_decode(switch_codec *codec,
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate, decoded_data, decoded_data_len, decoded_rate, flag);
|
*decoded_data_len = encoded_data_len;
|
||||||
|
|
||||||
|
return codec->implementation->decode(codec,
|
||||||
|
other_codec,
|
||||||
|
encoded_data,
|
||||||
|
encoded_data_len,
|
||||||
|
encoded_rate,
|
||||||
|
decoded_data,
|
||||||
|
decoded_data_len,
|
||||||
|
decoded_rate,
|
||||||
|
flag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status) switch_core_codec_destroy(switch_codec *codec)
|
SWITCH_DECLARE(switch_status) switch_core_codec_destroy(switch_codec *codec)
|
||||||
|
@ -458,14 +479,14 @@ static void *switch_core_service_thread(switch_thread *thread, void *obj)
|
||||||
|
|
||||||
while(data->running > 0) {
|
while(data->running > 0) {
|
||||||
switch(switch_core_session_read_frame(session, &read_frame, -1)) {
|
switch(switch_core_session_read_frame(session, &read_frame, -1)) {
|
||||||
case SWITCH_STATUS_SUCCESS:
|
case SWITCH_STATUS_SUCCESS:
|
||||||
break;
|
break;
|
||||||
case SWITCH_STATUS_TIMEOUT:
|
case SWITCH_STATUS_TIMEOUT:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
data->running = -1;
|
data->running = -1;
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_yield(100);
|
switch_yield(100);
|
||||||
|
@ -504,7 +525,7 @@ SWITCH_DECLARE(switch_memory_pool *) switch_core_session_get_pool(switch_core_se
|
||||||
}
|
}
|
||||||
|
|
||||||
/* **ONLY** alloc things with this function that **WILL NOT** outlive
|
/* **ONLY** alloc things with this function that **WILL NOT** outlive
|
||||||
the session itself or expect an earth shattering KABOOM!*/
|
the session itself or expect an earth shattering KABOOM!*/
|
||||||
SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, size_t memory)
|
SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, size_t memory)
|
||||||
{
|
{
|
||||||
void *ptr = NULL;
|
void *ptr = NULL;
|
||||||
|
@ -518,7 +539,7 @@ SWITCH_DECLARE(void *)switch_core_session_alloc(switch_core_session *session, si
|
||||||
}
|
}
|
||||||
|
|
||||||
/* **ONLY** alloc things with these functions that **WILL NOT** need
|
/* **ONLY** alloc things with these functions that **WILL NOT** need
|
||||||
to be freed *EVER* ie this is for *PERMENANT* memory allocation */
|
to be freed *EVER* ie this is for *PERMENANT* memory allocation */
|
||||||
|
|
||||||
SWITCH_DECLARE(void *) switch_core_permenant_alloc(size_t memory)
|
SWITCH_DECLARE(void *) switch_core_permenant_alloc(size_t memory)
|
||||||
{
|
{
|
||||||
|
@ -710,35 +731,35 @@ SWITCH_DECLARE(switch_status) switch_core_session_read_frame(switch_core_session
|
||||||
unsigned int flag = 0;
|
unsigned int flag = 0;
|
||||||
session->raw_read_frame.datalen = session->raw_read_frame.buflen;
|
session->raw_read_frame.datalen = session->raw_read_frame.buflen;
|
||||||
status = switch_core_codec_decode(read_frame->codec,
|
status = switch_core_codec_decode(read_frame->codec,
|
||||||
session->read_codec,
|
session->read_codec,
|
||||||
read_frame->data,
|
read_frame->data,
|
||||||
read_frame->datalen,
|
read_frame->datalen,
|
||||||
read_frame->rate,
|
session->read_codec->implementation->samples_per_second,
|
||||||
session->raw_read_frame.data,
|
session->raw_read_frame.data,
|
||||||
&session->raw_read_frame.datalen,
|
&session->raw_read_frame.datalen,
|
||||||
&session->raw_read_frame.rate,
|
&session->raw_read_frame.rate,
|
||||||
&flag);
|
&flag);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case SWITCH_STATUS_RESAMPLE:
|
case SWITCH_STATUS_RESAMPLE:
|
||||||
if (!session->read_resampler) {
|
if (!session->read_resampler) {
|
||||||
switch_resample_create(&session->read_resampler,
|
switch_resample_create(&session->read_resampler,
|
||||||
read_frame->codec->implementation->samples_per_second,
|
read_frame->codec->implementation->samples_per_second,
|
||||||
read_frame->codec->implementation->bytes_per_frame * 10,
|
read_frame->codec->implementation->bytes_per_frame * 10,
|
||||||
session->read_codec->implementation->samples_per_second,
|
session->read_codec->implementation->samples_per_second,
|
||||||
session->read_codec->implementation->bytes_per_frame * 10,
|
session->read_codec->implementation->bytes_per_frame * 10,
|
||||||
session->pool);
|
session->pool);
|
||||||
}
|
}
|
||||||
case SWITCH_STATUS_SUCCESS:
|
case SWITCH_STATUS_SUCCESS:
|
||||||
read_frame = &session->raw_read_frame;
|
read_frame = &session->raw_read_frame;
|
||||||
break;
|
break;
|
||||||
case SWITCH_STATUS_NOOP:
|
case SWITCH_STATUS_NOOP:
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name);
|
||||||
return status;
|
return status;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (session->read_resampler) {
|
if (session->read_resampler) {
|
||||||
|
@ -746,11 +767,11 @@ default:
|
||||||
|
|
||||||
session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int)read_frame->datalen / 2 );
|
session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int)read_frame->datalen / 2 );
|
||||||
session->read_resampler->to_len = switch_resample_process(session->read_resampler,
|
session->read_resampler->to_len = switch_resample_process(session->read_resampler,
|
||||||
session->read_resampler->from,
|
session->read_resampler->from,
|
||||||
session->read_resampler->from_len,
|
session->read_resampler->from_len,
|
||||||
session->read_resampler->to,
|
session->read_resampler->to,
|
||||||
(int)session->read_resampler->to_size,
|
(int)session->read_resampler->to_size,
|
||||||
0);
|
0);
|
||||||
switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
|
switch_float_to_short(session->read_resampler->to, data, read_frame->datalen);
|
||||||
read_frame->samples = session->read_resampler->to_len;
|
read_frame->samples = session->read_resampler->to_len;
|
||||||
read_frame->datalen = session->read_resampler->to_len * 2;
|
read_frame->datalen = session->read_resampler->to_len * 2;
|
||||||
|
@ -776,38 +797,41 @@ default:
|
||||||
|
|
||||||
if (perfect) {
|
if (perfect) {
|
||||||
enc_frame = *frame;
|
enc_frame = *frame;
|
||||||
|
session->raw_read_frame.rate = (*frame)->rate;
|
||||||
} else {
|
} else {
|
||||||
session->raw_read_frame.datalen = switch_buffer_read(session->raw_read_buffer,
|
session->raw_read_frame.datalen = switch_buffer_read(session->raw_read_buffer,
|
||||||
session->raw_read_frame.data,
|
session->raw_read_frame.data,
|
||||||
session->read_codec->implementation->bytes_per_frame);
|
session->read_codec->implementation->bytes_per_frame);
|
||||||
session->raw_read_frame.rate = session->read_codec->implementation->samples_per_second;
|
session->raw_read_frame.rate = session->read_codec->implementation->samples_per_second;
|
||||||
enc_frame = &session->raw_read_frame;
|
enc_frame = &session->raw_read_frame;
|
||||||
}
|
}
|
||||||
session->enc_read_frame.datalen = session->enc_read_frame.buflen;
|
session->enc_read_frame.datalen = session->enc_read_frame.buflen;
|
||||||
status = switch_core_codec_encode(session->read_codec,
|
status = switch_core_codec_encode(session->read_codec,
|
||||||
(*frame)->codec,
|
(*frame)->codec,
|
||||||
session->raw_read_frame.data,
|
session->raw_read_frame.data,
|
||||||
session->raw_read_frame.datalen,
|
session->raw_read_frame.datalen,
|
||||||
session->raw_read_frame.rate,
|
(*frame)->codec->implementation->samples_per_second,
|
||||||
session->enc_read_frame.data,
|
session->enc_read_frame.data,
|
||||||
&session->enc_read_frame.datalen,
|
&session->enc_read_frame.datalen,
|
||||||
&session->enc_read_frame.rate,
|
&session->enc_read_frame.rate,
|
||||||
&flag);
|
&flag);
|
||||||
|
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case SWITCH_STATUS_SUCCESS:
|
case SWITCH_STATUS_RESAMPLE:
|
||||||
*frame = &session->enc_read_frame;
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "fixme 1\n");
|
||||||
break;
|
case SWITCH_STATUS_SUCCESS:
|
||||||
case SWITCH_STATUS_NOOP:
|
*frame = &session->enc_read_frame;
|
||||||
*frame = &session->raw_read_frame;
|
break;
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
case SWITCH_STATUS_NOOP:
|
||||||
break;
|
*frame = &session->raw_read_frame;
|
||||||
default:
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
|
break;
|
||||||
*frame = NULL;
|
default:
|
||||||
status = SWITCH_STATUS_GENERR;
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
|
||||||
break;
|
*frame = NULL;
|
||||||
|
status = SWITCH_STATUS_GENERR;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -857,38 +881,38 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
if (frame->codec) {
|
if (frame->codec) {
|
||||||
session->raw_write_frame.datalen = session->raw_write_frame.buflen;
|
session->raw_write_frame.datalen = session->raw_write_frame.buflen;
|
||||||
status = switch_core_codec_decode(frame->codec,
|
status = switch_core_codec_decode(frame->codec,
|
||||||
session->write_codec,
|
session->write_codec,
|
||||||
frame->data,
|
frame->data,
|
||||||
frame->datalen,
|
frame->datalen,
|
||||||
frame->rate,
|
session->write_codec->implementation->samples_per_second,
|
||||||
session->raw_write_frame.data,
|
session->raw_write_frame.data,
|
||||||
&session->raw_write_frame.datalen,
|
&session->raw_write_frame.datalen,
|
||||||
&session->raw_write_frame.rate,
|
&session->raw_write_frame.rate,
|
||||||
&flag);
|
&flag);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case SWITCH_STATUS_RESAMPLE:
|
case SWITCH_STATUS_RESAMPLE:
|
||||||
write_frame = &session->raw_write_frame;
|
write_frame = &session->raw_write_frame;
|
||||||
if (!session->write_resampler) {
|
if (!session->write_resampler) {
|
||||||
status = switch_resample_create(&session->write_resampler,
|
status = switch_resample_create(&session->write_resampler,
|
||||||
frame->codec->implementation->samples_per_second,
|
frame->codec->implementation->samples_per_second,
|
||||||
frame->codec->implementation->bytes_per_frame * 10,
|
frame->codec->implementation->bytes_per_frame * 10,
|
||||||
session->write_codec->implementation->samples_per_second,
|
session->write_codec->implementation->samples_per_second,
|
||||||
session->write_codec->implementation->bytes_per_frame * 10,
|
session->write_codec->implementation->bytes_per_frame * 10,
|
||||||
session->pool);
|
session->pool);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SWITCH_STATUS_SUCCESS:
|
case SWITCH_STATUS_SUCCESS:
|
||||||
write_frame = &session->raw_write_frame;
|
write_frame = &session->raw_write_frame;
|
||||||
break;
|
break;
|
||||||
case SWITCH_STATUS_NOOP:
|
case SWITCH_STATUS_NOOP:
|
||||||
write_frame = frame;
|
write_frame = frame;
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
|
||||||
return status;
|
return status;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (session->write_resampler) {
|
if (session->write_resampler) {
|
||||||
|
@ -896,12 +920,12 @@ default:
|
||||||
|
|
||||||
session->write_resampler->from_len = switch_short_to_float(data, session->write_resampler->from, (int)write_frame->datalen / 2);
|
session->write_resampler->from_len = switch_short_to_float(data, session->write_resampler->from, (int)write_frame->datalen / 2);
|
||||||
session->write_resampler->to_len = switch_resample_process(session->write_resampler,
|
session->write_resampler->to_len = switch_resample_process(session->write_resampler,
|
||||||
session->write_resampler->from,
|
session->write_resampler->from,
|
||||||
session->write_resampler->from_len,
|
session->write_resampler->from_len,
|
||||||
session->write_resampler->to,
|
session->write_resampler->to,
|
||||||
(int)session->write_resampler->to_size,
|
(int)session->write_resampler->to_size,
|
||||||
0);
|
0);
|
||||||
switch_float_to_short(session->write_resampler->to, data, write_frame->datalen);
|
switch_float_to_short(session->write_resampler->to, data, write_frame->datalen * 2);
|
||||||
write_frame->samples = session->write_resampler->to_len;
|
write_frame->samples = session->write_resampler->to_len;
|
||||||
write_frame->datalen = session->write_resampler->to_len * 2;
|
write_frame->datalen = session->write_resampler->to_len * 2;
|
||||||
write_frame->rate = session->write_resampler->to_rate;
|
write_frame->rate = session->write_resampler->to_rate;
|
||||||
|
@ -913,10 +937,10 @@ default:
|
||||||
if (!session->raw_write_buffer) {
|
if (!session->raw_write_buffer) {
|
||||||
int bytes = session->write_codec->implementation->bytes_per_frame * 10;
|
int bytes = session->write_codec->implementation->bytes_per_frame * 10;
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE,
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE,
|
||||||
"Engaging Write Buffer at %d bytes to accomidate %d->%d\n",
|
"Engaging Write Buffer at %d bytes to accomidate %d->%d\n",
|
||||||
bytes,
|
bytes,
|
||||||
write_frame->datalen,
|
write_frame->datalen,
|
||||||
session->write_codec->implementation->bytes_per_frame);
|
session->write_codec->implementation->bytes_per_frame);
|
||||||
if ((status = switch_buffer_create(session->pool, &session->raw_write_buffer, bytes)) != SWITCH_STATUS_SUCCESS) {
|
if ((status = switch_buffer_create(session->pool, &session->raw_write_buffer, bytes)) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Buffer Failed!\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Buffer Failed!\n");
|
||||||
return status;
|
return status;
|
||||||
|
@ -932,28 +956,30 @@ default:
|
||||||
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
|
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
|
||||||
|
|
||||||
status = switch_core_codec_encode(session->write_codec,
|
status = switch_core_codec_encode(session->write_codec,
|
||||||
frame->codec,
|
frame->codec,
|
||||||
enc_frame->data,
|
enc_frame->data,
|
||||||
enc_frame->datalen,
|
enc_frame->datalen,
|
||||||
enc_frame->rate,
|
session->write_codec->implementation->samples_per_second,
|
||||||
session->enc_write_frame.data,
|
session->enc_write_frame.data,
|
||||||
&session->enc_write_frame.datalen,
|
&session->enc_write_frame.datalen,
|
||||||
&session->enc_write_frame.rate,
|
&session->enc_write_frame.rate,
|
||||||
&flag);
|
&flag);
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case SWITCH_STATUS_SUCCESS:
|
case SWITCH_STATUS_RESAMPLE:
|
||||||
write_frame = &session->enc_write_frame;
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "fixme 2\n");
|
||||||
break;
|
case SWITCH_STATUS_SUCCESS:
|
||||||
case SWITCH_STATUS_NOOP:
|
write_frame = &session->enc_write_frame;
|
||||||
write_frame = enc_frame;
|
break;
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
case SWITCH_STATUS_NOOP:
|
||||||
break;
|
write_frame = enc_frame;
|
||||||
default:
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
|
break;
|
||||||
write_frame = NULL;
|
default:
|
||||||
return status;
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
|
||||||
break;
|
write_frame = NULL;
|
||||||
|
return status;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = perform_write(session, write_frame, timeout, io_flag);
|
status = perform_write(session, write_frame, timeout, io_flag);
|
||||||
|
@ -968,40 +994,69 @@ default:
|
||||||
int x;
|
int x;
|
||||||
for (x = 0; x < frames; x++) {
|
for (x = 0; x < frames; x++) {
|
||||||
if ((session->raw_write_frame.datalen =
|
if ((session->raw_write_frame.datalen =
|
||||||
switch_buffer_read(session->raw_write_buffer,
|
switch_buffer_read(session->raw_write_buffer,
|
||||||
session->raw_write_frame.data,
|
session->raw_write_frame.data,
|
||||||
bytes))) {
|
bytes))) {
|
||||||
|
|
||||||
enc_frame = &session->raw_write_frame;
|
enc_frame = &session->raw_write_frame;
|
||||||
session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second;
|
session->raw_write_frame.rate = session->write_codec->implementation->samples_per_second;
|
||||||
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
|
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
|
||||||
status = switch_core_codec_encode(session->write_codec,
|
status = switch_core_codec_encode(session->write_codec,
|
||||||
frame->codec,
|
frame->codec,
|
||||||
enc_frame->data,
|
enc_frame->data,
|
||||||
enc_frame->datalen,
|
enc_frame->datalen,
|
||||||
enc_frame->rate,
|
frame->codec->implementation->samples_per_second,
|
||||||
session->enc_write_frame.data,
|
session->enc_write_frame.data,
|
||||||
&session->enc_write_frame.datalen,
|
&session->enc_write_frame.datalen,
|
||||||
&session->enc_write_frame.rate,
|
&session->enc_write_frame.rate,
|
||||||
&flag);
|
&flag);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case SWITCH_STATUS_SUCCESS:
|
case SWITCH_STATUS_RESAMPLE:
|
||||||
write_frame = &session->enc_write_frame;
|
write_frame = &session->enc_write_frame;
|
||||||
break;
|
if (!session->read_resampler) {
|
||||||
case SWITCH_STATUS_NOOP:
|
status = switch_resample_create(&session->read_resampler,
|
||||||
write_frame = enc_frame;
|
frame->codec->implementation->samples_per_second,
|
||||||
status = SWITCH_STATUS_SUCCESS;
|
frame->codec->implementation->bytes_per_frame * 10,
|
||||||
break;
|
session->write_codec->implementation->samples_per_second,
|
||||||
default:
|
session->write_codec->implementation->bytes_per_frame * 10,
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
|
session->pool);
|
||||||
write_frame = NULL;
|
|
||||||
return status;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
status = perform_write(session, write_frame, timeout, io_flag);
|
break;
|
||||||
|
case SWITCH_STATUS_SUCCESS:
|
||||||
|
write_frame = &session->enc_write_frame;
|
||||||
|
break;
|
||||||
|
case SWITCH_STATUS_NOOP:
|
||||||
|
write_frame = enc_frame;
|
||||||
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Codec %s encoder error!\n", session->read_codec->codec_interface->interface_name);
|
||||||
|
write_frame = NULL;
|
||||||
|
return status;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (session->read_resampler) {
|
||||||
|
short *data = write_frame->data;
|
||||||
|
|
||||||
|
session->read_resampler->from_len = switch_short_to_float(data,
|
||||||
|
session->read_resampler->from,
|
||||||
|
(int)write_frame->datalen / 2);
|
||||||
|
session->read_resampler->to_len = switch_resample_process(session->read_resampler,
|
||||||
|
session->read_resampler->from,
|
||||||
|
session->read_resampler->from_len,
|
||||||
|
session->read_resampler->to,
|
||||||
|
(int)session->read_resampler->to_size,
|
||||||
|
0);
|
||||||
|
switch_float_to_short(session->read_resampler->to, data, write_frame->datalen * 2);
|
||||||
|
write_frame->samples = session->read_resampler->to_len;
|
||||||
|
write_frame->datalen = session->read_resampler->to_len * 2;
|
||||||
|
write_frame->rate = session->read_resampler->to_rate;
|
||||||
|
}
|
||||||
|
status = perform_write(session, write_frame, timeout, io_flag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
|
@ -1341,7 +1396,7 @@ static void switch_core_standard_on_execute(switch_core_session *session)
|
||||||
|
|
||||||
while (switch_channel_get_state(session->channel) == CS_EXECUTE && extension->current_application) {
|
while (switch_channel_get_state(session->channel) == CS_EXECUTE && extension->current_application) {
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Execute %s(%s)\n", extension->current_application->application_name,
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Execute %s(%s)\n", extension->current_application->application_name,
|
||||||
extension->current_application->application_data);
|
extension->current_application->application_data);
|
||||||
if (!(application_interface = switch_loadable_module_get_application_interface(extension->current_application->application_name))) {
|
if (!(application_interface = switch_loadable_module_get_application_interface(extension->current_application->application_name))) {
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n", extension->current_application->application_name);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Application %s\n", extension->current_application->application_name);
|
||||||
switch_channel_set_state(session->channel, CS_HANGUP);
|
switch_channel_set_state(session->channel, CS_HANGUP);
|
||||||
|
@ -1394,17 +1449,17 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
|
||||||
const switch_event_handler_table *application_event_handlers = NULL;
|
const switch_event_handler_table *application_event_handlers = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Life of the channel. you have channel and pool in your session
|
Life of the channel. you have channel and pool in your session
|
||||||
everywhere you go you use the session to malloc with
|
everywhere you go you use the session to malloc with
|
||||||
switch_core_session_alloc(session, <size>)
|
switch_core_session_alloc(session, <size>)
|
||||||
|
|
||||||
The enpoint module gets the first crack at implementing the state
|
The enpoint module gets the first crack at implementing the state
|
||||||
if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE
|
if it wants to, it can cancel the default behaviour by returning SWITCH_STATUS_FALSE
|
||||||
|
|
||||||
Next comes the channel's event handler table that can be set by an application
|
Next comes the channel's event handler table that can be set by an application
|
||||||
which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE
|
which also can veto the next behaviour in line by returning SWITCH_STATUS_FALSE
|
||||||
|
|
||||||
Finally the default state behaviour is called.
|
Finally the default state behaviour is called.
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
@ -1431,97 +1486,97 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ( state ) {
|
switch ( state ) {
|
||||||
case CS_NEW: /* Just created, Waiting for first instructions */
|
case CS_NEW: /* Just created, Waiting for first instructions */
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State NEW\n");
|
||||||
break;
|
break;
|
||||||
case CS_DONE:
|
case CS_DONE:
|
||||||
continue;
|
continue;
|
||||||
break;
|
break;
|
||||||
case CS_HANGUP: /* Deactivate and end the thread */
|
case CS_HANGUP: /* Deactivate and end the thread */
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State HANGUP\n");
|
||||||
if (!driver_event_handlers->on_hangup ||
|
if (!driver_event_handlers->on_hangup ||
|
||||||
(driver_event_handlers->on_hangup &&
|
(driver_event_handlers->on_hangup &&
|
||||||
driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
|
driver_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
if (!application_event_handlers || !application_event_handlers->on_hangup ||
|
if (!application_event_handlers || !application_event_handlers->on_hangup ||
|
||||||
(application_event_handlers->on_hangup &&
|
(application_event_handlers->on_hangup &&
|
||||||
application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
|
application_event_handlers->on_hangup(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
switch_core_standard_on_hangup(session);
|
switch_core_standard_on_hangup(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch_channel_set_state(session->channel, CS_DONE);
|
switch_channel_set_state(session->channel, CS_DONE);
|
||||||
break;
|
break;
|
||||||
case CS_INIT: /* Basic setup tasks */
|
case CS_INIT: /* Basic setup tasks */
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State INIT\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State INIT\n");
|
||||||
if (!driver_event_handlers->on_init ||
|
if (!driver_event_handlers->on_init ||
|
||||||
(driver_event_handlers->on_init &&
|
(driver_event_handlers->on_init &&
|
||||||
driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
|
driver_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
if (!application_event_handlers || !application_event_handlers->on_init ||
|
if (!application_event_handlers || !application_event_handlers->on_init ||
|
||||||
(application_event_handlers->on_init &&
|
(application_event_handlers->on_init &&
|
||||||
application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
|
application_event_handlers->on_init(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
switch_core_standard_on_init(session);
|
switch_core_standard_on_init(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CS_RING: /* Look for a dialplan and find something to do */
|
case CS_RING: /* Look for a dialplan and find something to do */
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State RING\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State RING\n");
|
||||||
if (!driver_event_handlers->on_ring ||
|
if (!driver_event_handlers->on_ring ||
|
||||||
(driver_event_handlers->on_ring &&
|
(driver_event_handlers->on_ring &&
|
||||||
driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
|
driver_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
if (!application_event_handlers || !application_event_handlers->on_ring ||
|
if (!application_event_handlers || !application_event_handlers->on_ring ||
|
||||||
(application_event_handlers->on_ring &&
|
(application_event_handlers->on_ring &&
|
||||||
application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
|
application_event_handlers->on_ring(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
switch_core_standard_on_ring(session);
|
switch_core_standard_on_ring(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CS_EXECUTE: /* Execute an Operation*/
|
case CS_EXECUTE: /* Execute an Operation*/
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State EXECUTE\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State EXECUTE\n");
|
||||||
if (!driver_event_handlers->on_execute ||
|
if (!driver_event_handlers->on_execute ||
|
||||||
(driver_event_handlers->on_execute &&
|
(driver_event_handlers->on_execute &&
|
||||||
driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
|
driver_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
if (!application_event_handlers || !application_event_handlers->on_execute ||
|
if (!application_event_handlers || !application_event_handlers->on_execute ||
|
||||||
(application_event_handlers->on_execute &&
|
(application_event_handlers->on_execute &&
|
||||||
application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
|
application_event_handlers->on_execute(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
switch_core_standard_on_execute(session);
|
switch_core_standard_on_execute(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CS_LOOPBACK: /* loop all data back to source */
|
case CS_LOOPBACK: /* loop all data back to source */
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State LOOPBACK\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State LOOPBACK\n");
|
||||||
if (!driver_event_handlers->on_loopback ||
|
if (!driver_event_handlers->on_loopback ||
|
||||||
(driver_event_handlers->on_loopback &&
|
(driver_event_handlers->on_loopback &&
|
||||||
driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
|
driver_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
if (!application_event_handlers || !application_event_handlers->on_loopback ||
|
if (!application_event_handlers || !application_event_handlers->on_loopback ||
|
||||||
(application_event_handlers->on_loopback &&
|
(application_event_handlers->on_loopback &&
|
||||||
application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
|
application_event_handlers->on_loopback(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
switch_core_standard_on_loopback(session);
|
switch_core_standard_on_loopback(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CS_TRANSMIT: /* send/recieve data to/from another channel */
|
case CS_TRANSMIT: /* send/recieve data to/from another channel */
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State TRANSMIT\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "State TRANSMIT\n");
|
||||||
if (!driver_event_handlers->on_transmit ||
|
if (!driver_event_handlers->on_transmit ||
|
||||||
(driver_event_handlers->on_transmit &&
|
(driver_event_handlers->on_transmit &&
|
||||||
driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
|
driver_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
if (!application_event_handlers || !application_event_handlers->on_transmit ||
|
if (!application_event_handlers || !application_event_handlers->on_transmit ||
|
||||||
(application_event_handlers->on_transmit &&
|
(application_event_handlers->on_transmit &&
|
||||||
application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
|
application_event_handlers->on_transmit(session) == SWITCH_STATUS_SUCCESS &&
|
||||||
midstate == switch_channel_get_state(session->channel))) {
|
midstate == switch_channel_get_state(session->channel))) {
|
||||||
switch_core_standard_on_transmit(session);
|
switch_core_standard_on_transmit(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
laststate = midstate;
|
laststate = midstate;
|
||||||
|
@ -1581,16 +1636,16 @@ SWITCH_DECLARE(void *) switch_core_hash_find(switch_hash *hash, char *key)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function abstracts the thread creation for modules by allowing you to pass a function ptr and
|
/* This function abstracts the thread creation for modules by allowing you to pass a function ptr and
|
||||||
a void object and trust that that the function will be run in a thread with arg This lets
|
a void object and trust that that the function will be run in a thread with arg This lets
|
||||||
you request and activate a thread without giving up any knowledge about what is in the thread
|
you request and activate a thread without giving up any knowledge about what is in the thread
|
||||||
neither the core nor the calling module know anything about each other.
|
neither the core nor the calling module know anything about each other.
|
||||||
|
|
||||||
This thread is expected to never exit until the application exits so the func is responsible
|
This thread is expected to never exit until the application exits so the func is responsible
|
||||||
to make sure that is the case.
|
to make sure that is the case.
|
||||||
|
|
||||||
The typical use for this is so switch_loadable_module.c can start up a thread for each module
|
The typical use for this is so switch_loadable_module.c can start up a thread for each module
|
||||||
passing the table of module methods as a session obj into the core without actually allowing
|
passing the table of module methods as a session obj into the core without actually allowing
|
||||||
the core to have any clue and keeping switch_loadable_module.c from needing any thread code.
|
the core to have any clue and keeping switch_loadable_module.c from needing any thread code.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -1620,11 +1675,11 @@ SWITCH_DECLARE(void) switch_core_launch_thread(switch_thread_start_t func, void
|
||||||
ts->objs[0] = obj;
|
ts->objs[0] = obj;
|
||||||
|
|
||||||
switch_thread_create(&thread,
|
switch_thread_create(&thread,
|
||||||
thd_attr,
|
thd_attr,
|
||||||
func,
|
func,
|
||||||
ts,
|
ts,
|
||||||
pool
|
pool
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1659,12 +1714,12 @@ SWITCH_DECLARE(void) switch_core_session_thread_launch(switch_core_session *sess
|
||||||
switch_threadattr_detach_set(thd_attr, 1);
|
switch_threadattr_detach_set(thd_attr, 1);
|
||||||
|
|
||||||
if (switch_thread_create(&thread,
|
if (switch_thread_create(&thread,
|
||||||
thd_attr,
|
thd_attr,
|
||||||
switch_core_session_thread,
|
switch_core_session_thread,
|
||||||
session,
|
session,
|
||||||
session->pool
|
session->pool
|
||||||
) != APR_SUCCESS) {
|
) != APR_SUCCESS) {
|
||||||
switch_core_session_destroy(&session);
|
switch_core_session_destroy(&session);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1677,11 +1732,11 @@ SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *sess
|
||||||
switch_threadattr_detach_set(thd_attr, 1);
|
switch_threadattr_detach_set(thd_attr, 1);
|
||||||
|
|
||||||
switch_thread_create(&thread,
|
switch_thread_create(&thread,
|
||||||
thd_attr,
|
thd_attr,
|
||||||
func,
|
func,
|
||||||
obj,
|
obj,
|
||||||
session->pool
|
session->pool
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1727,7 +1782,7 @@ SWITCH_DECLARE(switch_core_session *) switch_core_session_request(const switch_e
|
||||||
switch_channel_init(session->channel, session, CS_NEW, CF_SEND_AUDIO | CF_RECV_AUDIO);
|
switch_channel_init(session->channel, session, CS_NEW, CF_SEND_AUDIO | CF_RECV_AUDIO);
|
||||||
|
|
||||||
/* The session *IS* the pool you may not alter it because you have no idea how
|
/* The session *IS* the pool you may not alter it because you have no idea how
|
||||||
its all private it will be passed to the thread run function */
|
its all private it will be passed to the thread run function */
|
||||||
|
|
||||||
switch_uuid_get(&uuid);
|
switch_uuid_get(&uuid);
|
||||||
switch_uuid_format(session->uuid_str, &uuid);
|
switch_uuid_format(session->uuid_str, &uuid);
|
||||||
|
@ -1770,13 +1825,14 @@ static void core_event_handler (switch_event *event)
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
|
|
||||||
switch(event->event_id) {
|
switch(event->event_id) {
|
||||||
case SWITCH_EVENT_LOG:
|
case SWITCH_EVENT_LOG:
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
switch_event_serialize(event, buf, sizeof(buf), NULL);
|
buf[0] = '\0';
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf);
|
//switch_event_serialize(event, buf, sizeof(buf), NULL);
|
||||||
break;
|
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nCORE EVENT\n--------------------------------\n%s\n", buf);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue