]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
codec tweak
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 18 Jul 2006 18:34:42 +0000 (18:34 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 18 Jul 2006 18:34:42 +0000 (18:34 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1957 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/codecs/mod_speex/mod_speex.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_exosip/mod_exosip.c
src/mod/endpoints/mod_iax/mod_iax.c
src/switch_rtp.c

index 24c1eebd729c6d33ef193978ce97efa1a7b6cf6c..42ad6d5f83bb5f59280928d30c5f216483ab2792 100644 (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,
index 49f0ace23b99240cc399e7524b81ba01db41170a..872dbb9f844890bd6c1c9d1fb56ebc5dfedb6643 100644 (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);
index da31f25950c5ea53c081d6e3ce33ea2433eddc4b..e60969d480b7d4198fec52acbbe3b67e872fffc7 100644 (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);
index ac5c8f0658a946c4ab7546b2efeafca950d5a503..931c182ab4493031830e5d51f9e80c77ab10d619 100644 (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;
index f1d190b85029922f782558be8ab1951851ec74e5..7832db0589057245ae7fef750a65cd350dd43718 100644 (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;