Index: rtp.c =================================================================== RCS file: /usr/cvsroot/asterisk/rtp.c,v retrieving revision 1.143 diff -u -r1.143 rtp.c --- rtp.c 30 Aug 2005 02:12:09 -0000 1.143 +++ rtp.c 6 Sep 2005 06:44:14 -0000 @@ -86,6 +86,7 @@ int dtmfcount; unsigned int dtmfduration; int nat; + int natactivated; int flags; struct sockaddr_in us; struct sockaddr_in them; @@ -354,8 +355,8 @@ if ((rtp->rtcp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || (rtp->rtcp->them.sin_port != sin.sin_port)) { memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); - if (option_debug) - ast_log(LOG_DEBUG, "RTP NAT: Using address %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); + if (option_debug || rtpdebug) + ast_log(LOG_DEBUG, "RTCP NAT: Got RTCP from other end. Now sending to address %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); } } if (option_debug) @@ -424,7 +425,9 @@ (rtp->them.sin_port != sin.sin_port)) { memcpy(&rtp->them, &sin, sizeof(rtp->them)); rtp->rxseqno = 0; - ast_log(LOG_DEBUG, "RTP NAT: Using address %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port)); + rtp->natactivated = 1; + if (option_debug || rtpdebug) + ast_log(LOG_DEBUG, "RTP NAT: Got audio from other end. Now sending to address %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port)); } } @@ -646,6 +649,8 @@ void ast_rtp_pt_clear(struct ast_rtp* rtp) { int i; + if (!rtp) + return; for (i = 0; i < MAX_RTP_PT; ++i) { rtp->current_RTP_PT[i].isAstFormat = 0; @@ -1212,8 +1217,17 @@ if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) { res = sendto(rtp->s, (void *)rtpheader, f->datalen + hdrlen, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them)); - if (res <0) - ast_log(LOG_NOTICE, "RTP Transmission error to %s:%d: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno)); + if (res <0) { + if (!rtp->nat || (rtp->nat && rtp->natactivated == 1)) { + ast_log(LOG_DEBUG, "RTP Transmission error of packet %d to %s:%d: %s\n", rtp->seqno, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno)); + } else if (rtp->natactivated == 0 || rtpdebug) { + /* Only give this error message once if we are not RTP debugging */ + if (option_debug || rtpdebug) + ast_log(LOG_DEBUG, "RTP NAT: Can't write RTP to private address %s:%d, waiting for other end to send audio...\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port)); + rtp->natactivated = -1; + } + } + if(rtp_debug_test_addr(&rtp->them)) ast_verbose("Sent RTP packet to %s:%d (type %d, seq %d, ts %d, len %d)\n" , ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), codec, rtp->seqno, rtp->lastts,res - hdrlen);