update
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@871 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
bef74390f5
commit
cefb356398
|
@ -57,7 +57,7 @@ static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag fla
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
if (encoding) {
|
if (encoding) {
|
||||||
g729_init_coder(&context->encoder_object, 1);
|
g729_init_coder(&context->encoder_object, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (decoding) {
|
if (decoding) {
|
||||||
|
@ -121,6 +121,7 @@ static switch_status switch_g729_encode(switch_codec *codec,
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +145,6 @@ static switch_status switch_g729_decode(switch_codec *codec,
|
||||||
int plen = 10;
|
int plen = 10;
|
||||||
|
|
||||||
if (!context) {
|
if (!context) {
|
||||||
|
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,7 @@ static switch_status switch_g729_decode(switch_codec *codec,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (encoded_data_len % divisor == 0) {
|
if (encoded_data_len % divisor == 0) {
|
||||||
|
uint8_t *test;
|
||||||
|
|
||||||
int loops = (int) encoded_data_len / divisor;
|
int loops = (int) encoded_data_len / divisor;
|
||||||
|
|
||||||
|
@ -176,6 +177,13 @@ static switch_status switch_g729_decode(switch_codec *codec,
|
||||||
|
|
||||||
unsigned int new_len = 0;
|
unsigned int new_len = 0;
|
||||||
|
|
||||||
|
test = (uint8_t *) encoded_data;
|
||||||
|
if (*test == 0 && *(test+1) == 0) {
|
||||||
|
*decoded_data_len = (encoded_data_len / divisor) * 160;
|
||||||
|
memset(decoded_data, 0, *decoded_data_len);
|
||||||
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
for (x = 0; x < loops && new_len < *decoded_data_len; x++) {
|
for (x = 0; x < loops && new_len < *decoded_data_len; x++) {
|
||||||
g729_decoder(&context->decoder_object, ddp, edp, plen);
|
g729_decoder(&context->decoder_object, ddp, edp, plen);
|
||||||
|
|
||||||
|
@ -191,13 +199,11 @@ static switch_status switch_g729_decode(switch_codec *codec,
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");
|
||||||
|
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -237,7 +243,7 @@ static const switch_codec_implementation g729_8k_implementation = {
|
||||||
/*.encoded_bytes_per_frame */ 20,
|
/*.encoded_bytes_per_frame */ 20,
|
||||||
/*.number_of_channels */ 1,
|
/*.number_of_channels */ 1,
|
||||||
/*.pref_frames_per_packet */ 1,
|
/*.pref_frames_per_packet */ 1,
|
||||||
/*.max_frames_per_packet */ 24,
|
/*.max_frames_per_packet */ 1,
|
||||||
/*.init */ switch_g729_init,
|
/*.init */ switch_g729_init,
|
||||||
/*.encode */ switch_g729_encode,
|
/*.encode */ switch_g729_encode,
|
||||||
/*.decode */ switch_g729_decode,
|
/*.decode */ switch_g729_decode,
|
||||||
|
|
|
@ -59,7 +59,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 (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
|
if (codec && other_codec && 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;
|
||||||
|
@ -75,7 +75,7 @@ static switch_status switch_raw_decode(switch_codec *codec,
|
||||||
void *decoded_data,
|
void *decoded_data,
|
||||||
size_t *decoded_data_len, int *decoded_rate, unsigned int *flag)
|
size_t *decoded_data_len, int *decoded_rate, unsigned int *flag)
|
||||||
{
|
{
|
||||||
if (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
|
if (codec && other_codec && 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;
|
||||||
|
|
|
@ -224,10 +224,11 @@ static switch_status wanpipe_on_init(switch_core_session *session)
|
||||||
{
|
{
|
||||||
struct private_object *tech_pvt;
|
struct private_object *tech_pvt;
|
||||||
switch_channel *channel = NULL;
|
switch_channel *channel = NULL;
|
||||||
wanpipe_tdm_api_t tdm_api;
|
wanpipe_tdm_api_t tdm_api = {};
|
||||||
int err = 0;
|
int err = 0;
|
||||||
int mtu_mru;
|
int mtu_mru;
|
||||||
unsigned int rate = 8000;
|
unsigned int rate = 8000;
|
||||||
|
int new_mtu = ((globals.mtu / 8) / 2);
|
||||||
|
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
assert(channel != NULL);
|
assert(channel != NULL);
|
||||||
|
@ -238,13 +239,20 @@ static switch_status wanpipe_on_init(switch_core_session *session)
|
||||||
tech_pvt->read_frame.data = tech_pvt->databuf;
|
tech_pvt->read_frame.data = tech_pvt->databuf;
|
||||||
|
|
||||||
err = sangoma_tdm_set_codec(tech_pvt->socket, &tdm_api, WP_SLINEAR);
|
err = sangoma_tdm_set_codec(tech_pvt->socket, &tdm_api, WP_SLINEAR);
|
||||||
|
|
||||||
mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->socket, &tdm_api);
|
mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->socket, &tdm_api);
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WANPIPE INIT MTU is %d\n", mtu_mru);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WANPIPE INIT MTU is %d\n", mtu_mru);
|
||||||
|
|
||||||
if (mtu_mru != globals.mtu) {
|
if (mtu_mru != globals.mtu) {
|
||||||
sangoma_tdm_set_usr_period(tech_pvt->socket, &tdm_api, (globals.mtu / 8) / 2);
|
sangoma_tdm_set_usr_period(tech_pvt->socket, &tdm_api, 40);
|
||||||
|
err = sangoma_tdm_set_usr_period(tech_pvt->socket, &tdm_api, new_mtu);
|
||||||
mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->socket, &tdm_api);
|
mtu_mru = sangoma_tdm_get_usr_mtu_mru(tech_pvt->socket, &tdm_api);
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "ADJUSTED MTU is %d\n", mtu_mru);
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "ADJUSTED MTU AFTER SETTING IT TO %d is %d %d [%s]\n", new_mtu, mtu_mru, err, strerror(err));
|
||||||
|
if (mtu_mru != globals.mtu) {
|
||||||
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Failure to adjust MTU\n");
|
||||||
|
switch_channel_hangup(channel);
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_core_codec_init
|
if (switch_core_codec_init
|
||||||
|
@ -287,6 +295,10 @@ static switch_status wanpipe_on_init(switch_core_session *session)
|
||||||
|
|
||||||
teletone_dtmf_detect_init (&tech_pvt->dtmf_detect, rate);
|
teletone_dtmf_detect_init (&tech_pvt->dtmf_detect, rate);
|
||||||
|
|
||||||
|
if (switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
|
||||||
|
switch_channel_answer(channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Move Channel's State Machine to RING */
|
/* Move Channel's State Machine to RING */
|
||||||
switch_channel_set_state(channel, CS_RING);
|
switch_channel_set_state(channel, CS_RING);
|
||||||
|
@ -366,6 +378,17 @@ static switch_status wanpipe_on_loopback(switch_core_session *session)
|
||||||
|
|
||||||
static switch_status wanpipe_on_transmit(switch_core_session *session)
|
static switch_status wanpipe_on_transmit(switch_core_session *session)
|
||||||
{
|
{
|
||||||
|
struct private_object *tech_pvt;
|
||||||
|
switch_channel *channel;
|
||||||
|
|
||||||
|
channel = switch_core_session_get_channel(session);
|
||||||
|
assert(channel != NULL);
|
||||||
|
|
||||||
|
tech_pvt = switch_core_session_get_private(session);
|
||||||
|
assert(tech_pvt != NULL);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WANPIPE TRANSMIT\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WANPIPE TRANSMIT\n");
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -461,7 +484,6 @@ static switch_status wanpipe_outgoing_channel(switch_core_session *session, swit
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
switch_set_flag(tech_pvt, TFLAG_NOSIG);
|
switch_set_flag(tech_pvt, TFLAG_NOSIG);
|
||||||
switch_channel_answer(channel);
|
|
||||||
} else {
|
} else {
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid address\n");
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid address\n");
|
||||||
switch_core_session_destroy(new_session);
|
switch_core_session_destroy(new_session);
|
||||||
|
@ -634,8 +656,8 @@ static switch_status wanpipe_read_frame(switch_core_session *session, switch_fra
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tech_pvt->skip_read_frames) {
|
if (tech_pvt->skip_read_frames > 0) {
|
||||||
memset(tech_pvt->read_frame.data, 255, tech_pvt->read_frame.datalen);
|
memset(tech_pvt->read_frame.data, 0, tech_pvt->read_frame.datalen);
|
||||||
tech_pvt->skip_read_frames--;
|
tech_pvt->skip_read_frames--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -666,8 +688,6 @@ static switch_status wanpipe_write_frame(switch_core_session *session, switch_fr
|
||||||
assert(tech_pvt != NULL);
|
assert(tech_pvt != NULL);
|
||||||
|
|
||||||
|
|
||||||
//printf("write %d\n", frame->datalen);
|
|
||||||
|
|
||||||
while (tech_pvt->dtmf_buffer && bwrote < frame->datalen && bytes > 0 && (inuse = switch_buffer_inuse(tech_pvt->dtmf_buffer)) > 0) {
|
while (tech_pvt->dtmf_buffer && bwrote < frame->datalen && bytes > 0 && (inuse = switch_buffer_inuse(tech_pvt->dtmf_buffer)) > 0) {
|
||||||
if ((bread = switch_buffer_read(tech_pvt->dtmf_buffer, dtmf, globals.mtu)) < globals.mtu) {
|
if ((bread = switch_buffer_read(tech_pvt->dtmf_buffer, dtmf, globals.mtu)) < globals.mtu) {
|
||||||
while (bread < globals.mtu) {
|
while (bread < globals.mtu) {
|
||||||
|
@ -712,7 +732,7 @@ static switch_status wanpipe_write_frame(switch_core_session *session, switch_fr
|
||||||
write(tech_pvt->fd, bp, (int) globals.mtu);
|
write(tech_pvt->fd, bp, (int) globals.mtu);
|
||||||
#endif
|
#endif
|
||||||
towrite = bytes >= globals.mtu ? globals.mtu : bytes;
|
towrite = bytes >= globals.mtu ? globals.mtu : bytes;
|
||||||
//printf("write %d\n", towrite);
|
|
||||||
res = sangoma_sendmsg_socket(tech_pvt->socket,
|
res = sangoma_sendmsg_socket(tech_pvt->socket,
|
||||||
&tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, towrite, 0);
|
&tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, towrite, 0);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
@ -732,6 +752,7 @@ static switch_status wanpipe_write_frame(switch_core_session *session, switch_fr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//printf("write %d %d\n", frame->datalen, status);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1047,6 +1047,9 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
unsigned int flag = 0, need_codec = 0, perfect = 0;
|
unsigned int flag = 0, need_codec = 0, perfect = 0;
|
||||||
switch_io_flag io_flag = SWITCH_IO_FLAG_NOOP;
|
switch_io_flag io_flag = SWITCH_IO_FLAG_NOOP;
|
||||||
|
|
||||||
|
|
||||||
|
assert(frame->codec != NULL);
|
||||||
|
|
||||||
/* if you think this code is redundant.... too bad! I like to understand what I'm doing */
|
/* if you think this code is redundant.... too bad! I like to understand what I'm doing */
|
||||||
if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
|
if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
|
||||||
need_codec = TRUE;
|
need_codec = TRUE;
|
||||||
|
@ -1071,6 +1074,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
session->write_codec->implementation->samples_per_second,
|
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.rate, &flag);
|
&session->raw_write_frame.datalen, &session->raw_write_frame.rate, &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;
|
||||||
|
@ -1114,6 +1119,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (session->write_codec) {
|
if (session->write_codec) {
|
||||||
if (write_frame->datalen == session->write_codec->implementation->bytes_per_frame) {
|
if (write_frame->datalen == session->write_codec->implementation->bytes_per_frame) {
|
||||||
perfect = TRUE;
|
perfect = TRUE;
|
||||||
|
@ -1132,11 +1139,13 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(switch_buffer_write(session->raw_write_buffer, write_frame->data, write_frame->datalen))) {
|
if (!(switch_buffer_write(session->raw_write_buffer, write_frame->data, write_frame->datalen))) {
|
||||||
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Write Buffer Failed!\n");
|
||||||
return SWITCH_STATUS_MEMERR;
|
return SWITCH_STATUS_MEMERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (perfect) {
|
if (perfect) {
|
||||||
|
|
||||||
enc_frame = write_frame;
|
enc_frame = write_frame;
|
||||||
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
|
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
|
||||||
|
|
||||||
|
@ -1175,6 +1184,11 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
size_t frames = (used / bytes);
|
size_t frames = (used / bytes);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
status = SWITCH_STATUS_SUCCESS;
|
||||||
if (frames) {
|
if (frames) {
|
||||||
size_t x;
|
size_t x;
|
||||||
for (x = 0; x < frames; x++) {
|
for (x = 0; x < frames; x++) {
|
||||||
|
@ -1184,6 +1198,8 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
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,
|
||||||
|
@ -1194,7 +1210,6 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
&session->enc_write_frame.rate, &flag);
|
&session->enc_write_frame.rate, &flag);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case SWITCH_STATUS_RESAMPLE:
|
case SWITCH_STATUS_RESAMPLE:
|
||||||
write_frame = &session->enc_write_frame;
|
write_frame = &session->enc_write_frame;
|
||||||
|
@ -1240,16 +1255,16 @@ SWITCH_DECLARE(switch_status) switch_core_session_write_frame(switch_core_sessio
|
||||||
write_frame->datalen = session->read_resampler->to_len * 2;
|
write_frame->datalen = session->read_resampler->to_len * 2;
|
||||||
write_frame->rate = session->read_resampler->to_rate;
|
write_frame->rate = session->read_resampler->to_rate;
|
||||||
}
|
}
|
||||||
status = perform_write(session, write_frame, timeout, io_flag, stream_id);
|
return perform_write(session, write_frame, timeout, io_flag, stream_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
status = perform_write(session, frame, timeout, io_flag, stream_id);
|
return perform_write(session, frame, timeout, io_flag, stream_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -763,7 +763,7 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
|
||||||
if (switch_core_session_read_frame(session_a, &read_frame, -1, stream_id) == SWITCH_STATUS_SUCCESS
|
if (switch_core_session_read_frame(session_a, &read_frame, -1, stream_id) == SWITCH_STATUS_SUCCESS
|
||||||
&& read_frame->datalen) {
|
&& read_frame->datalen) {
|
||||||
if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "write: %s Bad Frame.... Bubye!\n", switch_channel_get_name(chan_b));
|
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "write: %s Bad Frame....[%d] Bubye!\n", switch_channel_get_name(chan_b), read_frame->datalen);
|
||||||
data->running = -1;
|
data->running = -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue