Hi all,

I made two little improvements to the sipp:
1.) small delay in RTP echo function
 - first receive some RTP packets (e.g. 30) and only when all are received then 
send it back
2.) play_pcap_audio action
 - add one semaphore to temporary disable RTP echo function when 
play_pcap_audio action is used to play pre-recorded RTP stream
 - with this improvement both the RTP echo function and play_pcap_audio action 
can be used on same script without mixing both audio streams (without this 
audio is distorted).

If anyone is interested to test it I made a patch against snapshots 
sipp.2007-08-08.tar.gz (two files send_packets.c and 
sipp.cpp). Tested only on Linux.

Regards,
         Peter


diff -urp sipp.2007-08-08/send_packets.c sipp.2007-08-08_patch/send_packets.c
--- sipp.2007-08-08/send_packets.c      2007-04-12 15:57:47.000000000 +0200
+++ sipp.2007-08-08_patch/send_packets.c        2007-08-17 16:00:56.000000000 
+0200
@@ -55,10 +55,14 @@
 #include <string.h>
 #include <fcntl.h>
 
+#include <semaphore.h>
+
 #include "send_packets.h"
 #include "prepare_pcap.h"
 #include "screen.hpp"
 
+extern sem_t rtp_echo_sem;
+
 extern volatile unsigned long rtp_pckts_pcap;
 extern volatile unsigned long rtp_bytes_pcap;
 extern int media_ip_is_ipv6;
@@ -135,6 +139,8 @@ send_packets (play_args_t * play_args)
   int fd_flags;
 #endif
 
+       sem_wait(&rtp_echo_sem);
+
   if (media_ip_is_ipv6) {
     sock = socket(PF_INET6, SOCK_RAW, IPPROTO_UDP);
     if (sock < 0) {
@@ -217,6 +223,7 @@ send_packets (play_args_t * play_args)
     }
 #endif
     if (ret < 0) {
+       sem_post(&rtp_echo_sem);
       close(sock);
       WARNING_P1("send_packets.c: sendto failed with error: %s", 
strerror(errno));
       return( -1);
@@ -228,6 +235,7 @@ send_packets (play_args_t * play_args)
     pkt_index++;
        }
 
+  sem_post(&rtp_echo_sem);
   close(sock);
   return 0;
 }
Only in sipp.2007-08-08_patch/: send_packets.o
Only in sipp.2007-08-08_patch/: send_packets_orig.c
Only in sipp.2007-08-08_patch/: sipp
diff -urp sipp.2007-08-08/sipp.cpp sipp.2007-08-08_patch/sipp.cpp
--- sipp.2007-08-08/sipp.cpp    2007-08-01 16:01:37.000000000 +0200
+++ sipp.2007-08-08_patch/sipp.cpp      2007-08-17 16:08:38.000000000 +0200
@@ -33,9 +33,19 @@
 
 #define GLOBALS_FULL_DEFINITION
 
+#include <semaphore.h>
 #include "sipp.hpp"
 #include "assert.h"
 
+#define MAX_DELAY_BUF 30  /* 30 RTP packets delay */
+
+sem_t rtp_echo_sem;
+
+struct rtp_delay_buf {
+  char *msg;
+  size_t nr;
+};
+
 #ifdef _USE_OPENSSL
 SSL_CTX  *sip_trp_ssl_ctx = NULL; /* For SSL cserver context */
 SSL_CTX  *sip_trp_ssl_ctx_client = NULL; /* For SSL cserver context */
@@ -2976,42 +2986,74 @@ void traffic_thread()
 
 void rtp_echo_thread (void * param)
 {
-  char *msg = (char*)alloca(media_bufsize);
-  size_t nr, ns;
+  size_t ns;
   sipp_socklen_t len;
   struct sockaddr_storage remote_rtp_addr;
-
+  rtp_delay_buf rtp_delay[MAX_DELAY_BUF]; 
+  int rtp_index_r = 0;
+  int rtp_index_s = 0;
+  bool delay_done = false;
 
    int                   rc;
    sigset_t              mask;
    sigfillset(&mask); /* Mask all allowed signals */
    rc = pthread_sigmask(SIG_BLOCK, &mask, NULL);
 
+   for (rtp_index_r = 0; rtp_index_r < MAX_DELAY_BUF; rtp_index_r++) {
+        rtp_delay[rtp_index_r].msg = (char *) malloc(media_bufsize); 
+   }
+       
+  rtp_index_r = 0;
   for (;;) {
+    // wait for semafor and just unlock it
+    // if rtp play thread is running wait here and
+    // don't send rtp echo
+    sem_wait(&rtp_echo_sem);
+    sem_post(&rtp_echo_sem);
+       
     len = sizeof(remote_rtp_addr);
-    nr = recvfrom(*(int *)param, 
-                  msg, 
+    rtp_delay[rtp_index_r].nr = recvfrom(*(int *)param, 
+                  rtp_delay[rtp_index_r].msg, 
                   media_bufsize, 0, 
                   (sockaddr *)(void *) &remote_rtp_addr, 
                   &len);
 
-    if (((long)nr) < 0) {
+    if (((long)rtp_delay[rtp_index_r].nr) < 0) {
       WARNING_P2("%s %i", 
                  "Error on RTP echo reception - stopping echo - errno=", 
                  errno);
+               for (rtp_index_r = 0; rtp_index_r < MAX_DELAY_BUF; 
rtp_index_r++) {
+                       free(rtp_delay[rtp_index_r].msg); 
+    }
+    
       return;
     }
-    ns = sendto(*(int *)param, msg, nr, 
+
+    if (++rtp_index_r >= MAX_DELAY_BUF-1) {
+       rtp_index_r = 0;
+       rtp_index_s = 0;
+       delay_done = true;
+    }
+                       
+         if (delay_done == true) {
+      ns = sendto(*(int *)param, rtp_delay[rtp_index_s].msg, 
rtp_delay[rtp_index_s].nr, 
                 0, (sockaddr *)(void *) &remote_rtp_addr, 
                 len);
 
-    if (ns != nr) {
+      if (ns != rtp_delay[rtp_index_s].nr) {
       WARNING_P2("%s %i", 
                  "Error on RTP echo transmission - stopping echo - errno=", 
                  errno);
+                       for (rtp_index_r = 0; rtp_index_r < MAX_DELAY_BUF; 
rtp_index_r++) {
+                               free(rtp_delay[rtp_index_r].msg); 
+                       }
       return;
     }
     
+       if (++rtp_index_s >= MAX_DELAY_BUF-1) {
+               rtp_index_s = 0;
+       }
+       
     if (*(int *)param==media_socket) {    
     rtp_pckts++;
     rtp_bytes += ns;
@@ -3021,6 +3063,11 @@ void rtp_echo_thread (void * param)
       rtp2_pckts++;
       rtp2_bytes += ns;
     }
+         }     /* delay_done == true */
+  }
+
+  for (rtp_index_r = 0; rtp_index_r < MAX_DELAY_BUF; rtp_index_r++) {
+       free(rtp_delay[rtp_index_r].msg); 
   }
 }
 
@@ -3550,6 +3597,8 @@ int main(int argc, char *argv[])
   
   generic[0] = NULL;
 
+  sem_init(&rtp_echo_sem, 0, 1);
+
   /* At least one argument is needed */
   if(argc < 2) {
     help(); 
   



-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Sipp-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sipp-users

Reply via email to