]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
drop rtp frame that was already replaced with a cng frame
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 23 Dec 2010 02:38:57 +0000 (20:38 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 23 Dec 2010 02:38:57 +0000 (20:38 -0600)
src/include/switch_types.h
src/mod/applications/mod_dptools/mod_dptools.c
src/switch_core_io.c
src/switch_rtp.c

index 76af5a40edda25e70e8cc900a5197a81d8ee250d..830ea409e85b08069bef4d6c62acfeba863abaf2 100644 (file)
@@ -1097,6 +1097,7 @@ typedef enum {
        CF_JITTERBUFFER,
        CF_DIALPLAN,
        CF_BLOCK_BROADCAST_UNTIL_MEDIA,
+       CF_CNG_PLC,
        /* WARNING: DO NOT ADD ANY FLAGS BELOW THIS LINE */
        CF_FLAG_MAX
 } switch_channel_flag_t;
index e508486380522770c0758272b21ebe8857d01d5c..d5d0cb7576f153f0f40bea0c50352b53add465e7 100755 (executable)
@@ -3112,6 +3112,11 @@ SWITCH_STANDARD_APP(verbose_events_function)
        switch_channel_set_flag(switch_core_session_get_channel(session), CF_VERBOSE_EVENTS);
 }
 
+SWITCH_STANDARD_APP(cng_plc_function)
+{
+       switch_channel_set_flag(switch_core_session_get_channel(session), CF_CNG_PLC);
+}
+
 SWITCH_STANDARD_APP(early_hangup_function)
 {
        switch_channel_set_flag(switch_core_session_get_channel(session), CF_EARLY_HANGUP);
@@ -3497,6 +3502,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
                                   "<ip> <acl | cidr> [<hangup_cause>]", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
        SWITCH_ADD_APP(app_interface, "verbose_events", "Make ALL Events verbose.", "Make ALL Events verbose.", verbose_events_function, "",
                                   SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
+       SWITCH_ADD_APP(app_interface, "cng_plc", "Do PLC on CNG frames", "", cng_plc_function, "",
+                                  SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
        SWITCH_ADD_APP(app_interface, "early_hangup", "Enable early hangup", "", early_hangup_function, "", SAF_SUPPORT_NOMEDIA | SAF_ROUTING_EXEC);
        SWITCH_ADD_APP(app_interface, "sleep", "Pause a channel", SLEEP_LONG_DESC, sleep_function, "<pausemilliseconds>", SAF_SUPPORT_NOMEDIA);
        SWITCH_ADD_APP(app_interface, "delay_echo", "echo audio at a specified delay", "Delay n ms", delay_function, "<delay ms>", SAF_NONE);
index c3113e96801af868af53751bd87027137b561378..49956b317277eb22b583b8638b1ce917b9cbc839 100644 (file)
@@ -341,7 +341,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                                }
                                
                                if (status == SWITCH_STATUS_SUCCESS) {
-                                       if (switch_channel_test_flag(session->channel, CF_JITTERBUFFER) && !session->plc) {
+                                       if ((switch_channel_test_flag(session->channel, CF_JITTERBUFFER) || switch_channel_test_flag(session->channel, CF_CNG_PLC)) 
+                                               && !session->plc) {
                                                session->plc = plc_init(NULL);
                                        }
                                
index 1600e2858f51f3a31935bd8248061e179ccfed81..60c0bae9736b4193a0982145a625a0d9b583e087 100644 (file)
@@ -175,6 +175,7 @@ struct switch_rtp {
        uint32_t ts;
        uint32_t last_write_ts;
        uint32_t last_read_ts;
+       uint32_t last_cng_ts;
        uint32_t last_write_samplecount;
        uint32_t next_write_samplecount;
        switch_time_t last_write_timestamp;
@@ -2164,11 +2165,19 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
 {
        switch_status_t status = SWITCH_STATUS_FALSE;
        stfu_frame_t *jb_frame;
+       uint32_t ts;
 
        switch_assert(bytes);
 
        *bytes = sizeof(rtp_msg_t);
        status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock_input, 0, (void *) &rtp_session->recv_msg, bytes);
+       ts = ntohl(rtp_session->recv_msg.header.ts);
+
+       if (ts && !rtp_session->jb && ts <= rtp_session->last_cng_ts) {
+               /* we already sent this frame..... */
+               *bytes = 0;
+               return SWITCH_STATUS_SUCCESS;
+       }
 
        if (*bytes) {
                rtp_session->stats.inbound.raw_bytes += *bytes;
@@ -2192,7 +2201,7 @@ static switch_status_t read_rtp_packet(switch_rtp_t *rtp_session, switch_size_t
        }
 
 
-       rtp_session->last_read_ts = ntohl(rtp_session->recv_msg.header.ts);
+       rtp_session->last_read_ts = ts;
 
        if (rtp_session->jb && rtp_session->recv_msg.header.version == 2 && *bytes) {
                if (rtp_session->recv_msg.header.m && rtp_session->recv_msg.header.pt != rtp_session->recv_te && 
@@ -2920,7 +2929,8 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_
 
                if (do_cng) {
                        uint8_t *data = (uint8_t *) rtp_session->recv_msg.body;
-
+                       rtp_session->last_cng_ts = rtp_session->last_read_ts + rtp_session->samples_per_interval;
+                       
                        memset(data, 0, 2);
                        data[0] = 65;
                        rtp_session->recv_msg.header.pt = (uint32_t) rtp_session->cng_pt ? rtp_session->cng_pt : SWITCH_RTP_CNG_PAYLOAD;