codec tweak

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1957 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-07-18 18:34:42 +00:00
parent 629ee71e8f
commit aee6cc27e1
5 changed files with 51 additions and 30 deletions

View File

@ -202,8 +202,6 @@ static switch_status_t switch_speex_encode(switch_codec_t *codec,
}
speex_bits_pack(&context->encoder_bits, 15, 5);
*encoded_data_len = speex_bits_write(&context->encoder_bits, (char *) encoded_data, context->encoder_frame_size);
speex_bits_reset(&context->encoder_bits);
@ -226,6 +224,7 @@ static switch_status_t switch_speex_decode(switch_codec_t *codec,
return SWITCH_STATUS_FALSE;
}
buf = decoded_data;
if (*flag & SWITCH_CODEC_FLAG_SILENCE) {
speex_decode_int(context->decoder_state, NULL, buf);
@ -276,7 +275,7 @@ static const switch_codec_implementation_t speex_32k_implementation = {
/*.nanoseconds_per_frame */ 20000,
/*.samples_per_frame */ 640,
/*.bytes_per_frame */ 1280,
/*.encoded_bytes_per_frame */ 43,
/*.encoded_bytes_per_frame */ 0,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
@ -295,7 +294,7 @@ static const switch_codec_implementation_t speex_16k_implementation = {
/*.nanoseconds_per_frame */ 20000,
/*.samples_per_frame */ 320,
/*.bytes_per_frame */ 640,
/*.encoded_bytes_per_frame */ 43,
/*.encoded_bytes_per_frame */ 0,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
@ -315,7 +314,7 @@ static const switch_codec_implementation_t speex_8k_implementation = {
/*.nanoseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 29,
/*.encoded_bytes_per_frame */ 0,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,

View File

@ -291,15 +291,15 @@ static int activate_rtp(struct private_object *tech_pvt)
}
if (!(tech_pvt->rtp_session = switch_rtp_new(tech_pvt->profile->ip,
tech_pvt->local_port,
tech_pvt->remote_ip,
tech_pvt->remote_port,
tech_pvt->codec_num,
tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
tech_pvt->read_codec.implementation->microseconds_per_frame,
flags,
NULL,
&err, switch_core_session_get_pool(tech_pvt->session)))) {
tech_pvt->local_port,
tech_pvt->remote_ip,
tech_pvt->remote_port,
tech_pvt->codec_num,
0,
tech_pvt->read_codec.implementation->microseconds_per_frame,
flags,
NULL,
&err, switch_core_session_get_pool(tech_pvt->session)))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "RTP ERROR %s\n", err);
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return -1;
@ -784,8 +784,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
}
if (tech_pvt->read_frame.datalen > 0) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (tech_pvt->read_frame.datalen / bytes);
if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (tech_pvt->read_frame.datalen / bytes);
} else {
frames = 1;
}
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame;
tech_pvt->timestamp_recv += (int32_t) samples;
@ -841,9 +845,13 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
switch_set_flag_locked(tech_pvt, TFLAG_WRITING);
if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = ((int) frame->datalen / bytes);
} else {
frames = 1;
}
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = ((int) frame->datalen / bytes);
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
//printf("%s send %d bytes %d samples in %d frames ts=%d\n", switch_channel_get_name(channel), frame->datalen, samples, frames, tech_pvt->timestamp_send);

View File

@ -562,7 +562,7 @@ static switch_status_t activate_rtp(struct private_object *tech_pvt)
tech_pvt->remote_sdp_audio_ip,
tech_pvt->remote_sdp_audio_port,
tech_pvt->read_codec.implementation->ianacode,
tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
0, //tech_pvt->read_codec.implementation->encoded_bytes_per_frame,
ms,
flags,
key,
@ -718,8 +718,12 @@ static switch_status_t exosip_read_frame(switch_core_session_t *session, switch_
if (tech_pvt->read_frame.datalen > 0) {
tech_pvt->last_read = switch_time_now();
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (tech_pvt->read_frame.datalen / bytes);
if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (tech_pvt->read_frame.datalen / bytes);
} else {
frames = 1;
}
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame;
tech_pvt->timestamp_recv += (int32_t) samples;
@ -776,8 +780,12 @@ static switch_status_t exosip_write_frame(switch_core_session_t *session, switch
switch_set_flag_locked(tech_pvt, TFLAG_WRITING);
if (switch_test_flag(tech_pvt, TFLAG_USING_CODEC)) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = ((int) frame->datalen / bytes);
if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = ((int) frame->datalen / bytes);
} else {
frames = 1;
}
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
} else {
assert(0);

View File

@ -1099,8 +1099,12 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
break;
}
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (int) (tech_pvt->read_frame.datalen / bytes);
if (tech_pvt->read_codec.implementation->encoded_bytes_per_frame) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (int) (tech_pvt->read_frame.datalen / bytes);
} else {
frames = 1;
}
tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;

View File

@ -796,10 +796,11 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
switch_sockaddr_ip_get(&tx_host, rtp_session->from_addr);
switch_sockaddr_ip_get(&old_host, rtp_session->remote_addr);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Auto Changing port from %s:%u to %s:%u\n",
old_host, old, tx_host, rtp_session->from_addr->port);
switch_rtp_set_remote_address(rtp_session, tx_host, rtp_session->from_addr->port, &err);
if (!switch_strlen_zero(tx_host) && rtp_session->from_addr->port > 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Auto Changing port from %s:%u to %s:%u\n",
old_host, old, tx_host, rtp_session->from_addr->port);
switch_rtp_set_remote_address(rtp_session, tx_host, rtp_session->from_addr->port, &err);
}
}
switch_clear_flag(rtp_session, SWITCH_RTP_FLAG_AUTOADJ);
}
@ -1083,7 +1084,8 @@ static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t data
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD) &&
rtp_session->recv_msg.header.pt == rtp_session->vad_data.read_codec->implementation->ianacode &&
datalen == rtp_session->vad_data.read_codec->implementation->encoded_bytes_per_frame) {
((datalen == rtp_session->vad_data.read_codec->implementation->encoded_bytes_per_frame) ||
(datalen > SWITCH_RTP_CNG_PAYLOAD && rtp_session->vad_data.read_codec->implementation->encoded_bytes_per_frame == 0))) {
int16_t decoded[SWITCH_RECCOMMENDED_BUFFER_SIZE/sizeof(int16_t)];
uint32_t rate;
uint32_t flags;