r3581 - in trunk/libminisip: include/libminisip/media/rtp source/subsystem_media/rtp
erik at minisip.org
erik at minisip.org
Thu May 22 15:09:09 CEST 2008
Author: erik
Date: 2008-05-22 15:09:08 +0200 (Thu, 22 May 2008)
New Revision: 3581
Modified:
trunk/libminisip/include/libminisip/media/rtp/SRtpPacket.h
trunk/libminisip/source/subsystem_media/rtp/SRtpPacket.cxx
Log:
* Added a method to read a SRTP packet from a memory buffer.
Modified: trunk/libminisip/include/libminisip/media/rtp/SRtpPacket.h
===================================================================
--- trunk/libminisip/include/libminisip/media/rtp/SRtpPacket.h 2008-05-21 11:16:49 UTC (rev 3580)
+++ trunk/libminisip/include/libminisip/media/rtp/SRtpPacket.h 2008-05-22 13:09:08 UTC (rev 3581)
@@ -51,9 +51,16 @@
unsigned ssrc);
virtual ~SRtpPacket();
+ /**
+ * Reads a (S)RTP packet from a socket.
+ */
static SRtpPacket *readPacket( UDPSocket &udp_sock, MRef<IPAddress *>&from, int timeout=-1);
- // static????
+ /**
+ * Reads a (S)RTP packet from a memory buffer.
+ */
+ static SRtpPacket *readPacket( byte_t *buf, unsigned buflen);
+
void protect( MRef<CryptoContext *> scontext );
int unprotect( MRef<CryptoContext *> scontext );
Modified: trunk/libminisip/source/subsystem_media/rtp/SRtpPacket.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/rtp/SRtpPacket.cxx 2008-05-21 11:16:49 UTC (rev 3580)
+++ trunk/libminisip/source/subsystem_media/rtp/SRtpPacket.cxx 2008-05-22 13:09:08 UTC (rev 3581)
@@ -197,29 +197,31 @@
SRtpPacket *SRtpPacket::readPacket(UDPSocket &srtp_socket, MRef<IPAddress *> &from, int timeout) {
#define UDP_SIZE 65536
- int i;
- uint8_t buf[UDP_SIZE];
+ int i;
+ uint8_t buf[UDP_SIZE];
+ int32_t port;
+ i = srtp_socket.recvFrom((char*)buf, UDP_SIZE, from, port);
+ if( i < 0 ){
+#ifdef DEBUG_OUTPUT
+ merror("recvfrom:");
+#endif
+ return NULL;
+ }
+ return readPacket(buf, i);
+}
+
+SRtpPacket *SRtpPacket::readPacket(byte_t *buf, unsigned buflen) {
+#define UDP_SIZE 65536
uint8_t j;
uint8_t cc;
- //memset( buf, '\0', UDP_SIZE );
- int32_t port;
- i = srtp_socket.recvFrom((char*)buf, UDP_SIZE, from, port);
-
- if( i < 0 ){
-#ifdef DEBUG_OUTPUT
- merror("recvfrom:");
-#endif
- return NULL;
- }
-
- if( i < 12 ){
+ if( buflen < 12 ){
/* too small to contain an RTP header */
return NULL;
}
cc = buf[0] & 0x0F;
- if( i < 12 + cc * 4 ){
+ if( buflen < 12 + cc * 4 ){
/* too small to contain an RTP header with cc CCSRC */
return NULL;
}
@@ -238,7 +240,7 @@
for( j = 0 ; j < cc ; j++ )
hdr.addCSRC( U32_AT( buf + 12 + j*4 ) );
- int datalen = i - 12 - cc*4;
+ int datalen = buflen - 12 - cc*4;
unsigned char *data = (unsigned char *)&buf[ 12 + 4*cc ];
More information about the Minisip-devel
mailing list