Browse code

core: add link MTU detection to be used by raw sockets

Raphael Coeffic authored on 17/10/2013 15:14:32
Showing 1 changed files
... ...
@@ -253,8 +253,8 @@ int AmRtpPacket::sendmsg(int sd, unsigned int sys_if_idx)
253 253
 int AmRtpPacket::send(int sd, unsigned int sys_if_idx,
254 254
 		      sockaddr_storage* l_saddr)
255 255
 {
256
-  if(AmConfig::UseRawSockets) {
257
-    return raw_sender::send((char*)buffer,b_size,l_saddr,&addr);
256
+  if(sys_if_idx && AmConfig::UseRawSockets) {
257
+    return raw_sender::send((char*)buffer,b_size,sys_if_idx,l_saddr,&addr);
258 258
   }
259 259
 
260 260
   if(sys_if_idx && AmConfig::ForceOutboundIf) {
Browse code

udp: raw socket support

To use this feature, set following in sems.conf:
use_raw_sockets=yes

Raphael Coeffic authored on 15/10/2013 07:42:43
Showing 1 changed files
... ...
@@ -33,6 +33,7 @@
33 33
 #include "log.h"
34 34
 #include "AmConfig.h"
35 35
 
36
+#include "sip/raw_sender.h"
36 37
 #include "sip/ip_util.h"
37 38
 
38 39
 #include <assert.h>
... ...
@@ -249,8 +250,13 @@ int AmRtpPacket::sendmsg(int sd, unsigned int sys_if_idx)
249 250
   return 0;
250 251
 }
251 252
 
252
-int AmRtpPacket::send(int sd, unsigned int sys_if_idx)
253
+int AmRtpPacket::send(int sd, unsigned int sys_if_idx,
254
+		      sockaddr_storage* l_saddr)
253 255
 {
256
+  if(AmConfig::UseRawSockets) {
257
+    return raw_sender::send((char*)buffer,b_size,l_saddr,&addr);
258
+  }
259
+
254 260
   if(sys_if_idx && AmConfig::ForceOutboundIf) {
255 261
     return sendmsg(sd,sys_if_idx);
256 262
   }
Browse code

core: allow RTP packets with 0 data size.

Raphael Coeffic authored on 29/05/2013 07:31:25
Showing 1 changed files
... ...
@@ -106,7 +106,7 @@ int AmRtpPacket::parse()
106 106
   ssrc = ntohl(hdr->ssrc);
107 107
   version = hdr->version;
108 108
 
109
-  if (data_offset >= b_size) {
109
+  if (data_offset > b_size) {
110 110
     ERROR("bad rtp packet (hdr-size=%u;pkt-size=%u) !\n",
111 111
 	  data_offset,b_size);
112 112
     return -1;
Browse code

added more debug infos for invalid RTP packets

Raphael Coeffic authored on 21/05/2013 15:26:57
Showing 1 changed files
... ...
@@ -107,7 +107,8 @@ int AmRtpPacket::parse()
107 107
   version = hdr->version;
108 108
 
109 109
   if (data_offset >= b_size) {
110
-    ERROR("bad rtp packet (header size too big) !\n");
110
+    ERROR("bad rtp packet (hdr-size=%u;pkt-size=%u) !\n",
111
+	  data_offset,b_size);
111 112
     return -1;
112 113
   }
113 114
   d_size = b_size - data_offset;
Browse code

sbc: support for RTP/RTCP packet logging

Václav Kubart authored on 22/04/2013 10:12:45 • Raphael Coeffic committed on 22/05/2013 19:50:18
Showing 1 changed files
... ...
@@ -42,6 +42,8 @@
42 42
 #include <sys/socket.h>
43 43
 #include <arpa/inet.h>
44 44
 
45
+#include "sip/msg_logger.h"
46
+
45 47
 AmRtpPacket::AmRtpPacket()
46 48
   : data_offset(0)
47 49
 {
... ...
@@ -272,3 +274,16 @@ int AmRtpPacket::recv(int sd)
272 274
     
273 275
   return ret;
274 276
 }
277
+
278
+void AmRtpPacket::logReceived(msg_logger *logger, struct sockaddr_storage *laddr)
279
+{
280
+  static const cstring empty;
281
+  logger->log((const char *)buffer, b_size, &addr, laddr, empty);
282
+}
283
+
284
+void AmRtpPacket::logSent(msg_logger *logger, struct sockaddr_storage *laddr)
285
+{
286
+  static const cstring empty;
287
+  logger->log((const char *)buffer, b_size, laddr, &addr, empty);
288
+}
289
+
Browse code

zrtp: do not buffer ZRTP packets if ZRTP has not been compiled in.

The packets are still relayed if rtp-relay is enabled.

Raphael Coeffic authored on 18/03/2013 15:18:00
Showing 1 changed files
... ...
@@ -102,6 +102,7 @@ int AmRtpPacket::parse()
102 102
   sequence = ntohs(hdr->seq);
103 103
   timestamp = ntohl(hdr->ts);
104 104
   ssrc = ntohl(hdr->ssrc);
105
+  version = hdr->version;
105 106
 
106 107
   if (data_offset >= b_size) {
107 108
     ERROR("bad rtp packet (header size too big) !\n");
Browse code

accept RTP packets with version==0 and extension headers

allows to relay ZRTP packets.

Raphael Coeffic authored on 29/01/2013 16:05:56
Showing 1 changed files
... ...
@@ -70,12 +70,8 @@ int AmRtpPacket::parse()
70 70
   assert(b_size);
71 71
 
72 72
   rtp_hdr_t* hdr = (rtp_hdr_t*)buffer;
73
-  if 
74
-#ifndef WITH_ZRTP
75
-    (hdr->version != RTP_VERSION)
76
-#else 
77
-    ((hdr->version != RTP_VERSION) && (hdr->version != 0))
78
-#endif
73
+  // ZRTP "Hello" packet has version == 0
74
+  if ((hdr->version != RTP_VERSION) && (hdr->version != 0))
79 75
       {
80 76
 	DBG("received RTP packet with unsupported version (%i).\n",
81 77
 	    hdr->version);
... ...
@@ -84,21 +80,21 @@ int AmRtpPacket::parse()
84 80
 
85 81
   data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
86 82
 
87
-  if(hdr->x != 0){
88
-#ifndef WITH_ZRTP 
89
-    if (AmConfig::IgnoreRTPXHdrs) {
90
-      // skip the extension header
91
-#endif
92
-      if (b_size >= data_offset + 4) {
93
-	data_offset +=
94
-	  ntohs(((rtp_xhdr_t*) (buffer + data_offset))->len)*4;
95
-      }
96
-#ifndef WITH_ZRTP
97
-    } else {
98
-      DBG("RTP extension headers not supported.\n");
99
-      return -1;
83
+  if(hdr->x != 0) {
84
+    //#ifndef WITH_ZRTP 
85
+    //if (AmConfig::IgnoreRTPXHdrs) {
86
+    //  skip the extension header
87
+    //#endif
88
+    if (b_size >= data_offset + 4) {
89
+      data_offset +=
90
+	ntohs(((rtp_xhdr_t*) (buffer + data_offset))->len)*4;
100 91
     }
101
-#endif
92
+    // #ifndef WITH_ZRTP
93
+    //   } else {
94
+    //     DBG("RTP extension headers not supported.\n");
95
+    //     return -1;
96
+    //   }
97
+    // #endif
102 98
   }
103 99
 
104 100
   payload = hdr->pt;
Browse code

support for forcing outbound network interface on packets sent (RTP/SIP)

Raphael Coeffic authored on 13/11/2012 13:01:13
Showing 1 changed files
... ...
@@ -25,6 +25,9 @@
25 25
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 26
  */
27 27
 
28
+#define __APPLE_USE_RFC_3542
29
+#include <netinet/in.h>
30
+
28 31
 #include "AmRtpPacket.h"
29 32
 #include "rtp/rtp.h"
30 33
 #include "log.h"
... ...
@@ -37,7 +40,6 @@
37 40
 #include <errno.h>
38 41
 
39 42
 #include <sys/socket.h>
40
-#include <netinet/in.h>
41 43
 #include <arpa/inet.h>
42 44
 
43 45
 AmRtpPacket::AmRtpPacket()
... ...
@@ -180,11 +182,11 @@ int AmRtpPacket::compile_raw(unsigned char* data_buf, unsigned int size)
180 182
   return size;
181 183
 }
182 184
 
183
-int AmRtpPacket::send(int sd)
185
+int AmRtpPacket::sendto(int sd)
184 186
 {
185
-  int err = sendto(sd,buffer,b_size,0,
186
-		   (const struct sockaddr *)&addr,
187
-		   SA_len(&addr));
187
+  int err = ::sendto(sd,buffer,b_size,0,
188
+		     (const struct sockaddr *)&addr,
189
+		     SA_len(&addr));
188 190
 
189 191
   if(err == -1){
190 192
     ERROR("while sending RTP packet: %s\n",strerror(errno));
... ...
@@ -194,6 +196,68 @@ int AmRtpPacket::send(int sd)
194 196
   return 0;
195 197
 }
196 198
 
199
+int AmRtpPacket::sendmsg(int sd, unsigned int sys_if_idx)
200
+{
201
+  struct msghdr hdr;
202
+  struct cmsghdr* cmsg;
203
+    
204
+  union {
205
+    char cmsg4_buf[CMSG_SPACE(sizeof(struct in_pktinfo))];
206
+    char cmsg6_buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
207
+  } cmsg_buf;
208
+
209
+  struct iovec msg_iov[1];
210
+  msg_iov[0].iov_base = (void*)buffer;
211
+  msg_iov[0].iov_len  = b_size;
212
+
213
+  bzero(&hdr,sizeof(hdr));
214
+  hdr.msg_name = (void*)&addr;
215
+  hdr.msg_namelen = SA_len(&addr);
216
+  hdr.msg_iov = msg_iov;
217
+  hdr.msg_iovlen = 1;
218
+
219
+  bzero(&cmsg_buf,sizeof(cmsg_buf));
220
+  hdr.msg_control = &cmsg_buf;
221
+  hdr.msg_controllen = sizeof(cmsg_buf);
222
+
223
+  cmsg = CMSG_FIRSTHDR(&hdr);
224
+  if(addr.ss_family == AF_INET) {
225
+    cmsg->cmsg_level = IPPROTO_IP;
226
+    cmsg->cmsg_type = IP_PKTINFO;
227
+    cmsg->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo));
228
+
229
+    struct in_pktinfo* pktinfo = (struct in_pktinfo*) CMSG_DATA(cmsg);
230
+    pktinfo->ipi_ifindex = sys_if_idx;
231
+  }
232
+  else if(addr.ss_family == AF_INET6) {
233
+    cmsg->cmsg_level = IPPROTO_IPV6;
234
+    cmsg->cmsg_type = IPV6_PKTINFO;
235
+    cmsg->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo));
236
+    
237
+    struct in6_pktinfo* pktinfo = (struct in6_pktinfo*) CMSG_DATA(cmsg);
238
+    pktinfo->ipi6_ifindex = sys_if_idx;
239
+  }
240
+
241
+  hdr.msg_controllen = cmsg->cmsg_len;
242
+  
243
+  // bytes_sent = ;
244
+  if(::sendmsg(sd, &hdr, 0) < 0) {
245
+      ERROR("sendto: %s\n",strerror(errno));
246
+      return -1;
247
+  }
248
+
249
+  return 0;
250
+}
251
+
252
+int AmRtpPacket::send(int sd, unsigned int sys_if_idx)
253
+{
254
+  if(sys_if_idx && AmConfig::ForceOutboundIf) {
255
+    return sendmsg(sd,sys_if_idx);
256
+  }
257
+  
258
+  return sendto(sd);
259
+}
260
+
197 261
 int AmRtpPacket::recv(int sd)
198 262
 {
199 263
   socklen_t recv_addr_len = sizeof(struct sockaddr_storage);
Browse code

fixed IPv6 support

limitations: IPv6 DNS lookups are not supported yet.

Raphael Coeffic authored on 19/11/2012 16:23:06
Showing 1 changed files
... ...
@@ -30,6 +30,8 @@
30 30
 #include "log.h"
31 31
 #include "AmConfig.h"
32 32
 
33
+#include "sip/ip_util.h"
34
+
33 35
 #include <assert.h>
34 36
 #include <string.h>
35 37
 #include <errno.h>
... ...
@@ -50,8 +52,6 @@ AmRtpPacket::~AmRtpPacket()
50 52
 {
51 53
 }
52 54
 
53
-#ifdef SUPPORT_IPV6
54
-
55 55
 void AmRtpPacket::setAddr(struct sockaddr_storage* a)
56 56
 {
57 57
   memcpy(&addr,a,sizeof(sockaddr_storage));
... ...
@@ -62,20 +62,6 @@ void AmRtpPacket::getAddr(struct sockaddr_storage* a)
62 62
   memcpy(a,&addr,sizeof(sockaddr_storage));
63 63
 }
64 64
 
65
-#else
66
-
67
-void AmRtpPacket::setAddr(struct sockaddr_in* a)
68
-{
69
-  memcpy(&addr,a,sizeof(sockaddr_in));
70
-}
71
-
72
-void AmRtpPacket::getAddr(struct sockaddr_in* a)
73
-{
74
-  memcpy(a,&addr,sizeof(sockaddr_in));
75
-}
76
-
77
-#endif
78
-
79 65
 int AmRtpPacket::parse()
80 66
 {
81 67
   assert(buffer);
... ...
@@ -196,17 +182,9 @@ int AmRtpPacket::compile_raw(unsigned char* data_buf, unsigned int size)
196 182
 
197 183
 int AmRtpPacket::send(int sd)
198 184
 {
199
-  int err;
200
-#ifdef SUPPORT_IPV6
201
-  if(addr.ss_family != PF_INET)
202
-    err = sendto(sd,buffer,b_size,0,
203
-		 (const struct sockaddr *)&addr,
204
-		 sizeof(struct sockaddr_in6));
205
-  else 
206
-#endif
207
-    err = sendto(sd,buffer,b_size,0,
208
-		 (const struct sockaddr *)&addr,
209
-		 sizeof(struct sockaddr_in));
185
+  int err = sendto(sd,buffer,b_size,0,
186
+		   (const struct sockaddr *)&addr,
187
+		   SA_len(&addr));
210 188
 
211 189
   if(err == -1){
212 190
     ERROR("while sending RTP packet: %s\n",strerror(errno));
... ...
@@ -218,12 +196,7 @@ int AmRtpPacket::send(int sd)
218 196
 
219 197
 int AmRtpPacket::recv(int sd)
220 198
 {
221
-#ifdef SUPPORT_IPV6
222 199
   socklen_t recv_addr_len = sizeof(struct sockaddr_storage);
223
-#else
224
-  socklen_t recv_addr_len = sizeof(struct sockaddr_in);
225
-#endif
226
-
227 200
   int ret = recvfrom(sd,buffer,sizeof(buffer),0,
228 201
 		     (struct sockaddr*)&addr,
229 202
 		     &recv_addr_len);
Browse code

added OpenSSL linking exception to license

Stefan Sayer authored on 23/09/2010 14:41:49
Showing 1 changed files
... ...
@@ -1,21 +1,21 @@
1 1
 /*
2
- * $Id$
3
- *
4 2
  * Copyright (C) 2002-2003 Fhg Fokus
5 3
  *
6
- * This file is part of sems, a free SIP media server.
4
+ * This file is part of SEMS, a free SIP media server.
7 5
  *
8
- * sems is free software; you can redistribute it and/or modify
6
+ * SEMS is free software; you can redistribute it and/or modify
9 7
  * it under the terms of the GNU General Public License as published by
10 8
  * the Free Software Foundation; either version 2 of the License, or
11
- * (at your option) any later version
9
+ * (at your option) any later version. This program is released under
10
+ * the GPL with the additional exemption that compiling, linking,
11
+ * and/or using OpenSSL is allowed.
12 12
  *
13
- * For a license to use the ser software under conditions
13
+ * For a license to use the SEMS software under conditions
14 14
  * other than those described here, or to purchase support for this
15 15
  * software, please contact iptel.org by e-mail at the following addresses:
16 16
  *    info@iptel.org
17 17
  *
18
- * sems is distributed in the hope that it will be useful,
18
+ * SEMS is distributed in the hope that it will be useful,
19 19
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 20
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 21
  * GNU General Public License for more details.
Browse code

removed some unused function and friends

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1640 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 25/02/2010 15:50:45
Showing 1 changed files
... ...
@@ -238,9 +238,3 @@ int AmRtpPacket::recv(int sd)
238 238
     
239 239
   return ret;
240 240
 }
241
-
242
-void AmRtpPacket::copy(const AmRtpPacket* p)
243
-{
244
-  memcpy(this,p,sizeof(AmRtpPacket));
245
-  memcpy(buffer,p->buffer,b_size);
246
-}
Browse code

functions to access RTP packet (zrtp patch 1)

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@949 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 14/05/2008 12:15:28
Showing 1 changed files
... ...
@@ -82,26 +82,35 @@ int AmRtpPacket::parse()
82 82
   assert(b_size);
83 83
 
84 84
   rtp_hdr_t* hdr = (rtp_hdr_t*)buffer;
85
-
86
-  if(hdr->version != RTP_VERSION){
87
-    DBG("received RTP packet with unsupported version (%i).\n",
88
-	hdr->version);
89
-    return -1;
90
-  }
85
+  if 
86
+#ifndef WITH_ZRTP
87
+    (hdr->version != RTP_VERSION)
88
+#else 
89
+    ((hdr->version != RTP_VERSION) && (hdr->version != 0))
90
+#endif
91
+      {
92
+	DBG("received RTP packet with unsupported version (%i).\n",
93
+	    hdr->version);
94
+	return -1;
95
+      }
91 96
 
92 97
   data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
93 98
 
94 99
   if(hdr->x != 0){
100
+#ifndef WITH_ZRTP 
95 101
     if (AmConfig::IgnoreRTPXHdrs) {
96 102
       // skip the extension header
103
+#endif
97 104
       if (b_size >= data_offset + 4) {
98 105
 	data_offset +=
99 106
 	  ntohs(((rtp_xhdr_t*) (buffer + data_offset))->len)*4;
100 107
       }
108
+#ifndef WITH_ZRTP
101 109
     } else {
102 110
       DBG("RTP extension headers not supported.\n");
103 111
       return -1;
104 112
     }
113
+#endif
105 114
   }
106 115
 
107 116
   payload = hdr->pt;
... ...
@@ -132,6 +141,11 @@ unsigned char *AmRtpPacket::getData()
132 141
   return &buffer[data_offset];
133 142
 }
134 143
 
144
+unsigned char *AmRtpPacket::getBuffer()
145
+{
146
+  return &buffer[0];
147
+}
148
+
135 149
 int AmRtpPacket::compile(unsigned char* data_buf, unsigned int size)
136 150
 {
137 151
   assert(data_buf);
... ...
@@ -163,6 +177,23 @@ int AmRtpPacket::compile(unsigned char* data_buf, unsigned int size)
163 177
   return 0;
164 178
 }
165 179
 
180
+int AmRtpPacket::compile_raw(unsigned char* data_buf, unsigned int size)
181
+{
182
+  if ((!size) || (!data_buf))
183
+    return -1;
184
+
185
+  if(size>sizeof(buffer)){
186
+    ERROR("builtin buffer size (%d) exceeded: %d\n",
187
+	  (int)sizeof(buffer), size);
188
+    return -1;
189
+  }
190
+
191
+  memcpy(&buffer[0], data_buf, size);
192
+  b_size = size;
193
+
194
+  return size;
195
+}
196
+
166 197
 int AmRtpPacket::send(int sd)
167 198
 {
168 199
   int err;
Browse code

fixes o SEMS-7: RTP extension headers may be ignored if ignore_rtpxheaders=yes set in config file o if changing payload type fails, packet will not be processed o minor code beautification and comments added/corrected

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@418 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 01/08/2007 18:44:57
Showing 1 changed files
... ...
@@ -28,6 +28,7 @@
28 28
 #include "AmRtpPacket.h"
29 29
 #include "rtp/rtp.h"
30 30
 #include "log.h"
31
+#include "AmConfig.h"
31 32
 
32 33
 #include <assert.h>
33 34
 #include <string.h>
... ...
@@ -88,9 +89,19 @@ int AmRtpPacket::parse()
88 89
     return -1;
89 90
   }
90 91
 
92
+  data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
93
+
91 94
   if(hdr->x != 0){
92
-    DBG("RTP extension headers not supported.\n");
93
-    return -1;
95
+    if (AmConfig::IgnoreRTPXHdrs) {
96
+      // skip the extension header
97
+      if (b_size >= data_offset + 4) {
98
+	data_offset +=
99
+	  ntohs(((rtp_xhdr_t*) (buffer + data_offset))->len)*4;
100
+      }
101
+    } else {
102
+      DBG("RTP extension headers not supported.\n");
103
+      return -1;
104
+    }
94 105
   }
95 106
 
96 107
   payload = hdr->pt;
... ...
@@ -99,7 +110,6 @@ int AmRtpPacket::parse()
99 110
   timestamp = ntohl(hdr->ts);
100 111
   ssrc = ntohl(hdr->ssrc);
101 112
 
102
-  data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
103 113
   if (data_offset >= b_size) {
104 114
     ERROR("bad rtp packet (header size too big) !\n");
105 115
     return -1;
Browse code

fixes ipv6 compilation problems

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@329 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 14/05/2007 13:01:21
Showing 1 changed files
... ...
@@ -159,7 +159,7 @@ int AmRtpPacket::send(int sd)
159 159
 #ifdef SUPPORT_IPV6
160 160
   if(addr.ss_family != PF_INET)
161 161
     err = sendto(sd,buffer,b_size,0,
162
-		 (const struct sockaddr *)saddr,
162
+		 (const struct sockaddr *)&addr,
163 163
 		 sizeof(struct sockaddr_in6));
164 164
   else 
165 165
 #endif
Browse code

unifies indentation level in all source files to 2 (-i2)

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@261 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 07/03/2007 20:34:39
Showing 1 changed files
... ...
@@ -38,11 +38,11 @@
38 38
 #include <arpa/inet.h>
39 39
 
40 40
 AmRtpPacket::AmRtpPacket()
41
-    : data_offset(0)
41
+  : data_offset(0)
42 42
 {
43
-    // buffer will be overwritten by received packet 
44
-    // of hdr+data - does not need to be set to 0s
45
-    //    memset(buffer,0,4096);
43
+  // buffer will be overwritten by received packet 
44
+  // of hdr+data - does not need to be set to 0s
45
+  //    memset(buffer,0,4096);
46 46
 }
47 47
 
48 48
 AmRtpPacket::~AmRtpPacket()
... ...
@@ -53,153 +53,153 @@ AmRtpPacket::~AmRtpPacket()
53 53
 
54 54
 void AmRtpPacket::setAddr(struct sockaddr_storage* a)
55 55
 {
56
-    memcpy(&addr,a,sizeof(sockaddr_storage));
56
+  memcpy(&addr,a,sizeof(sockaddr_storage));
57 57
 }
58 58
 
59 59
 void AmRtpPacket::getAddr(struct sockaddr_storage* a)
60 60
 {
61
-    memcpy(a,&addr,sizeof(sockaddr_storage));
61
+  memcpy(a,&addr,sizeof(sockaddr_storage));
62 62
 }
63 63
 
64 64
 #else
65 65
 
66 66
 void AmRtpPacket::setAddr(struct sockaddr_in* a)
67 67
 {
68
-    memcpy(&addr,a,sizeof(sockaddr_in));
68
+  memcpy(&addr,a,sizeof(sockaddr_in));
69 69
 }
70 70
 
71 71
 void AmRtpPacket::getAddr(struct sockaddr_in* a)
72 72
 {
73
-    memcpy(a,&addr,sizeof(sockaddr_in));
73
+  memcpy(a,&addr,sizeof(sockaddr_in));
74 74
 }
75 75
 
76 76
 #endif
77 77
 
78 78
 int AmRtpPacket::parse()
79 79
 {
80
-    assert(buffer);
81
-    assert(b_size);
82
-
83
-    rtp_hdr_t* hdr = (rtp_hdr_t*)buffer;
84
-
85
-    if(hdr->version != RTP_VERSION){
86
-	DBG("received RTP packet with unsupported version (%i).\n",
87
-	    hdr->version);
88
-	return -1;
89
-    }
90
-
91
-    if(hdr->x != 0){
92
-	DBG("RTP extension headers not supported.\n");
93
-	return -1;
94
-    }
95
-
96
-    payload = hdr->pt;
97
-    marker = hdr->m;
98
-    sequence = ntohs(hdr->seq);
99
-    timestamp = ntohl(hdr->ts);
100
-    ssrc = ntohl(hdr->ssrc);
101
-
102
-    data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
103
-    if (data_offset >= b_size) {
104
- 	ERROR("bad rtp packet (header size too big) !\n");
105
- 	return -1;
106
-    }
107
-    d_size = b_size - data_offset;
108
-
109
-    if(hdr->p){
110
- 	if (buffer[b_size-1]>=d_size){
111
- 		ERROR("bad rtp packet (invalid padding size) !\n");
112
- 		return -1;
113
- 	}
114
-	d_size -= buffer[b_size-1];
80
+  assert(buffer);
81
+  assert(b_size);
82
+
83
+  rtp_hdr_t* hdr = (rtp_hdr_t*)buffer;
84
+
85
+  if(hdr->version != RTP_VERSION){
86
+    DBG("received RTP packet with unsupported version (%i).\n",
87
+	hdr->version);
88
+    return -1;
89
+  }
90
+
91
+  if(hdr->x != 0){
92
+    DBG("RTP extension headers not supported.\n");
93
+    return -1;
94
+  }
95
+
96
+  payload = hdr->pt;
97
+  marker = hdr->m;
98
+  sequence = ntohs(hdr->seq);
99
+  timestamp = ntohl(hdr->ts);
100
+  ssrc = ntohl(hdr->ssrc);
101
+
102
+  data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
103
+  if (data_offset >= b_size) {
104
+    ERROR("bad rtp packet (header size too big) !\n");
105
+    return -1;
106
+  }
107
+  d_size = b_size - data_offset;
108
+
109
+  if(hdr->p){
110
+    if (buffer[b_size-1]>=d_size){
111
+      ERROR("bad rtp packet (invalid padding size) !\n");
112
+      return -1;
115 113
     }
114
+    d_size -= buffer[b_size-1];
115
+  }
116 116
 
117
-    return 0;
117
+  return 0;
118 118
 }
119 119
 
120 120
 unsigned char *AmRtpPacket::getData()
121 121
 {
122
-    return &buffer[data_offset];
122
+  return &buffer[data_offset];
123 123
 }
124 124
 
125 125
 int AmRtpPacket::compile(unsigned char* data_buf, unsigned int size)
126 126
 {
127
-    assert(data_buf);
128
-    assert(size);
129
-
130
-    d_size = size;
131
-    b_size = d_size + sizeof(rtp_hdr_t);
132
-    assert(b_size <= 4096);
133
-    rtp_hdr_t* hdr = (rtp_hdr_t*)buffer;
134
-
135
-    if(b_size>sizeof(buffer)){
136
- 	ERROR("builtin buffer size (%d) exceeded: %d\n",
137
-	      (int)sizeof(buffer), b_size);
138
-  	return -1;
139
-    }
140
-
141
-    memset(hdr,0,sizeof(rtp_hdr_t));
142
-    hdr->version = RTP_VERSION;
143
-    hdr->m = marker;
144
-    hdr->pt = payload;
127
+  assert(data_buf);
128
+  assert(size);
129
+
130
+  d_size = size;
131
+  b_size = d_size + sizeof(rtp_hdr_t);
132
+  assert(b_size <= 4096);
133
+  rtp_hdr_t* hdr = (rtp_hdr_t*)buffer;
134
+
135
+  if(b_size>sizeof(buffer)){
136
+    ERROR("builtin buffer size (%d) exceeded: %d\n",
137
+	  (int)sizeof(buffer), b_size);
138
+    return -1;
139
+  }
140
+
141
+  memset(hdr,0,sizeof(rtp_hdr_t));
142
+  hdr->version = RTP_VERSION;
143
+  hdr->m = marker;
144
+  hdr->pt = payload;
145 145
     
146
-    hdr->seq = htons(sequence);
147
-    hdr->ts = htonl(timestamp);
148
-    hdr->ssrc = htonl(ssrc);
146
+  hdr->seq = htons(sequence);
147
+  hdr->ts = htonl(timestamp);
148
+  hdr->ssrc = htonl(ssrc);
149 149
     
150
-    data_offset = sizeof(rtp_hdr_t);
151
-    memcpy(&buffer[data_offset],data_buf,d_size);
150
+  data_offset = sizeof(rtp_hdr_t);
151
+  memcpy(&buffer[data_offset],data_buf,d_size);
152 152
 
153
-    return 0;
153
+  return 0;
154 154
 }
155 155
 
156 156
 int AmRtpPacket::send(int sd)
157 157
 {
158
-    int err;
158
+  int err;
159 159
 #ifdef SUPPORT_IPV6
160
-    if(addr.ss_family != PF_INET)
161
-	err = sendto(sd,buffer,b_size,0,
162
-		     (const struct sockaddr *)saddr,
163
-		     sizeof(struct sockaddr_in6));
164
-    else 
160
+  if(addr.ss_family != PF_INET)
161
+    err = sendto(sd,buffer,b_size,0,
162
+		 (const struct sockaddr *)saddr,
163
+		 sizeof(struct sockaddr_in6));
164
+  else 
165 165
 #endif
166
-	err = sendto(sd,buffer,b_size,0,
167
-		     (const struct sockaddr *)&addr,
168
-		     sizeof(struct sockaddr_in));
166
+    err = sendto(sd,buffer,b_size,0,
167
+		 (const struct sockaddr *)&addr,
168
+		 sizeof(struct sockaddr_in));
169 169
 
170
-    if(err == -1){
171
-	ERROR("while sending RTP packet: %s\n",strerror(errno));
172
-	return -1;
173
-    }
170
+  if(err == -1){
171
+    ERROR("while sending RTP packet: %s\n",strerror(errno));
172
+    return -1;
173
+  }
174 174
 
175
-    return 0;
175
+  return 0;
176 176
 }
177 177
 
178 178
 int AmRtpPacket::recv(int sd)
179 179
 {
180 180
 #ifdef SUPPORT_IPV6
181
-    socklen_t recv_addr_len = sizeof(struct sockaddr_storage);
181
+  socklen_t recv_addr_len = sizeof(struct sockaddr_storage);
182 182
 #else
183
-    socklen_t recv_addr_len = sizeof(struct sockaddr_in);
183
+  socklen_t recv_addr_len = sizeof(struct sockaddr_in);
184 184
 #endif
185 185
 
186
-    int ret = recvfrom(sd,buffer,sizeof(buffer),0,
187
-		       (struct sockaddr*)&addr,
188
-		       &recv_addr_len);
186
+  int ret = recvfrom(sd,buffer,sizeof(buffer),0,
187
+		     (struct sockaddr*)&addr,
188
+		     &recv_addr_len);
189 189
 
190
-    if(ret > 0){
190
+  if(ret > 0){
191 191
 
192
-        if(ret > 4096)
193
-	    return -1;
192
+    if(ret > 4096)
193
+      return -1;
194 194
 
195
-	b_size = ret;
196
-    }
195
+    b_size = ret;
196
+  }
197 197
     
198
-    return ret;
198
+  return ret;
199 199
 }
200 200
 
201 201
 void AmRtpPacket::copy(const AmRtpPacket* p)
202 202
 {
203
-    memcpy(this,p,sizeof(AmRtpPacket));
204
-    memcpy(buffer,p->buffer,b_size);
203
+  memcpy(this,p,sizeof(AmRtpPacket));
204
+  memcpy(buffer,p->buffer,b_size);
205 205
 }
Browse code

optimization

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@244 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 26/02/2007 18:32:23
Showing 1 changed files
... ...
@@ -40,12 +40,13 @@
40 40
 AmRtpPacket::AmRtpPacket()
41 41
     : data_offset(0)
42 42
 {
43
-    memset(buffer,0,4096);
43
+    // buffer will be overwritten by received packet 
44
+    // of hdr+data - does not need to be set to 0s
45
+    //    memset(buffer,0,4096);
44 46
 }
45 47
 
46 48
 AmRtpPacket::~AmRtpPacket()
47 49
 {
48
-  //delete [] buffer;
49 50
 }
50 51
 
51 52
 #ifdef SUPPORT_IPV6
Browse code

fixed compilation errors occuring on my desktop ;-) More of them are needed to fix also the py_sems problem.

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@230 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Raphael Coeffic authored on 16/02/2007 10:23:24
Showing 1 changed files
... ...
@@ -106,11 +106,11 @@ int AmRtpPacket::parse()
106 106
     d_size = b_size - data_offset;
107 107
 
108 108
     if(hdr->p){
109
- 	if (buffer[d_size-1]>=d_size){
109
+ 	if (buffer[b_size-1]>=d_size){
110 110
  		ERROR("bad rtp packet (invalid padding size) !\n");
111 111
  		return -1;
112 112
  	}
113
-	d_size -= buffer[data_offset+d_size-1];
113
+	d_size -= buffer[b_size-1];
114 114
     }
115 115
 
116 116
     return 0;
Browse code

r221 patch updated

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@223 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Stefan Sayer authored on 14/02/2007 03:16:03
Showing 1 changed files
... ...
@@ -99,14 +99,14 @@ int AmRtpPacket::parse()
99 99
     ssrc = ntohl(hdr->ssrc);
100 100
 
101 101
     data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
102
-    if (data_offset >= (long)b_size) {
102
+    if (data_offset >= b_size) {
103 103
  	ERROR("bad rtp packet (header size too big) !\n");
104 104
  	return -1;
105 105
     }
106 106
     d_size = b_size - data_offset;
107 107
 
108 108
     if(hdr->p){
109
- 	if (data[d_size-1]>=d_size){
109
+ 	if (buffer[d_size-1]>=d_size){
110 110
  		ERROR("bad rtp packet (invalid padding size) !\n");
111 111
  		return -1;
112 112
  	}
Browse code

- fixes a buffer overflow occuring if an RTP packet...: - ... is too big. - ... has a wrong header length.

Thanks to Andrei for that year-old-yet-not-applied patch!


git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@221 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Raphael Coeffic authored on 09/02/2007 14:07:45
Showing 1 changed files
... ...
@@ -99,9 +99,17 @@ int AmRtpPacket::parse()
99 99
     ssrc = ntohl(hdr->ssrc);
100 100
 
101 101
     data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
102
+    if (data_offset >= (long)b_size) {
103
+ 	ERROR("bad rtp packet (header size too big) !\n");
104
+ 	return -1;
105
+    }
102 106
     d_size = b_size - data_offset;
103 107
 
104 108
     if(hdr->p){
109
+ 	if (data[d_size-1]>=d_size){
110
+ 		ERROR("bad rtp packet (invalid padding size) !\n");
111
+ 		return -1;
112
+ 	}
105 113
 	d_size -= buffer[data_offset+d_size-1];
106 114
     }
107 115
 
... ...
@@ -121,13 +129,13 @@ int AmRtpPacket::compile(unsigned char* data_buf, unsigned int size)
121 129
     d_size = size;
122 130
     b_size = d_size + sizeof(rtp_hdr_t);
123 131
     assert(b_size <= 4096);
124
-//     buffer = new unsigned char [b_size];
125 132
     rtp_hdr_t* hdr = (rtp_hdr_t*)buffer;
126 133
 
127
-//     if(!buffer){
128
-// 	ERROR("not enough memory !\n");
129
-// 	return -1;
130
-//     }
134
+    if(b_size>sizeof(buffer)){
135
+ 	ERROR("builtin buffer size (%d) exceeded: %d\n",
136
+	      (int)sizeof(buffer), b_size);
137
+  	return -1;
138
+    }
131 139
 
132 140
     memset(hdr,0,sizeof(rtp_hdr_t));
133 141
     hdr->version = RTP_VERSION;
... ...
@@ -174,23 +182,16 @@ int AmRtpPacket::recv(int sd)
174 182
     socklen_t recv_addr_len = sizeof(struct sockaddr_in);
175 183
 #endif
176 184
 
177
-    int ret = recvfrom(sd,buffer,4096,
178
-		       MSG_TRUNC | MSG_DONTWAIT,
185
+    int ret = recvfrom(sd,buffer,sizeof(buffer),0,
179 186
 		       (struct sockaddr*)&addr,
180 187
 		       &recv_addr_len);
181 188
 
182 189
     if(ret > 0){
183 190
 
184
-// 	buffer = new unsigned char [ret];
185
-// 	if(!buffer){
186
-// 	    ERROR("not enough memory !\n");
187
-// 	    return -1;
188
-// 	}
189 191
         if(ret > 4096)
190 192
 	    return -1;
191 193
 
192 194
 	b_size = ret;
193
-// 	memcpy(buffer,recv_buffer,b_size);
194 195
     }
195 196
     
196 197
     return ret;
... ...
@@ -199,14 +200,5 @@ int AmRtpPacket::recv(int sd)
199 200
 void AmRtpPacket::copy(const AmRtpPacket* p)
200 201
 {
201 202
     memcpy(this,p,sizeof(AmRtpPacket));
202
-
203
-//     buffer = new unsigned char [b_size];
204
-//     if(!buffer){
205
-// 	ERROR("not enough memory !\n");
206
-// 	data = 0;
207
-// 	b_size = d_size = 0;
208
-// 	return;
209
-//     }
210
-
211 203
     memcpy(buffer,p->buffer,b_size);
212 204
 }
Browse code

Second, much improved revision of adaptive jitter buffering patch.

Changes
-------

1. Make the AmJitterBuffer work with variable size RTP packets. Packet size
can be changed even during session (ex. Cisco in fax passthrough mode). Also
several improvements and fixes have been made to resyncronization logic.

2. Fix made to the AmPlayoutBuffer class to avoid reading chunks of size
larger than requested. This is required in cases when RTP packets contain
more or less data than internal frame size.

3. Small fix to AmRtpPacket class - replace the pointer to internal buffer
with offset in the buffer. This eliminates the nesessity to reparse the
packet each time the packet has been copied.

4. Replace the sample size field in amci_codec_t structure with two
functions - sampes2bytes and bytes2samples as that field did not allow to
specify sample size for LBR codecs (iLBC, gsm). This also brings ability
for codecs to determine the sample size at runtime (ex. iLBC).

5. Remove the sample size from amci_file_desc_t structure as it was used as
internal attribute of WAV files only and doesn't make much sense for other
file formats. Use the codec's ability to calculate sample size instead.

6. Parameter list for amci_inoutfmt_t.on_close() has been changed to give
ability to determine sample size in this file handler (WAV write_header
procedure requires this).

7. Fix gsm, ilbc, wav plugins and AmPlugin.c to reflect changes to amci.
Add corresponding samples2bytes and bytes2samples functions.


Caveats
--------

1. AmAdaptivePlayout class needs additional checking with RTP streams with
packets containing number of samples different from internal frame size
(for example 240 samples per packet in G711). Adaptive playout class
potentially may produce big packets of audio and therefore make the Conference
application work badly. The adaptive playout is used in Conference application
only and the application is working fine now with jitter buffer and without
adaptive playout. So I turned the adaptive playout off in the Conference app
as a workaround.

Developed by: Sippy Software, Inc.
Sponsored by: Digifonica Canada Limited



git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@185 8eb893ce-cfd4-0310-b710-fb5ebe64c474

Maxim Sobolev authored on 21/12/2006 07:52:05
Showing 1 changed files
... ...
@@ -38,7 +38,7 @@
38 38
 #include <arpa/inet.h>
39 39
 
40 40
 AmRtpPacket::AmRtpPacket()
41
-    : data(0)
41
+    : data_offset(0)
42 42
 {
43 43
     memset(buffer,0,4096);
44 44
 }
... ...
@@ -98,16 +98,21 @@ int AmRtpPacket::parse()
98 98
     timestamp = ntohl(hdr->ts);
99 99
     ssrc = ntohl(hdr->ssrc);
100 100
 
101
-    data = buffer + sizeof(rtp_hdr_t) + (hdr->cc*4);
102
-    d_size = b_size - (data - buffer);
101
+    data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4);
102
+    d_size = b_size - data_offset;
103 103
 
104 104
     if(hdr->p){
105
-	d_size -= data[d_size-1];
105
+	d_size -= buffer[data_offset+d_size-1];
106 106
     }
107 107
 
108 108
     return 0;
109 109
 }
110 110
 
111
+unsigned char *AmRtpPacket::getData()
112
+{
113
+    return &buffer[data_offset];
114
+}
115
+
111 116
 int AmRtpPacket::compile(unsigned char* data_buf, unsigned int size)