2 * Asterisk -- A telephony toolkit for Linux.
4 * Real-time Protocol Support
6 * Copyright (C) 1999, Mark Spencer
8 * Mark Spencer <markster@linux-support.net>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
22 #include <netinet/in.h>
24 #include <sys/socket.h>
25 #include <arpa/inet.h>
28 #include <asterisk/rtp.h>
29 #include <asterisk/frame.h>
30 #include <asterisk/logger.h>
31 #include <asterisk/options.h>
32 #include <asterisk/channel.h>
33 #include <asterisk/acl.h>
34 #include <asterisk/channel.h>
35 #include <asterisk/channel_pvt.h>
36 #include <asterisk/config.h>
42 #define TYPE_SILENCE 0x2
43 #define TYPE_DONTSEND 0x3
46 static int dtmftimeout = 3000; /* 3000 samples */
48 static int rtpstart = 0;
49 static int rtpend = 0;
51 // The value of each payload format mapping:
52 struct rtpPayloadType {
53 int isAstFormat; // whether the following code is an AST_FORMAT
57 #define MAX_RTP_PT 256
59 #define FLAG_3389_WARNING (1 << 0)
65 unsigned char rawdata[8192 + AST_FRIENDLY_OFFSET];
68 unsigned int lastrxts;
69 unsigned int lastividtimestamp;
70 unsigned int lastovidtimestamp;
71 unsigned int lasteventseqn;
75 unsigned int dtmfduration;
78 struct sockaddr_in us;
79 struct sockaddr_in them;
80 struct timeval rxcore;
81 struct timeval txcore;
82 struct timeval dtmfmute;
83 struct ast_smoother *smoother;
86 struct sched_context *sched;
87 struct io_context *io;
89 ast_rtp_callback callback;
90 struct rtpPayloadType current_RTP_PT[MAX_RTP_PT];
91 // a cache for the result of rtp_lookup_code():
92 int rtp_lookup_code_cache_isAstFormat;
93 int rtp_lookup_code_cache_code;
94 int rtp_lookup_code_cache_result;
95 struct ast_rtcp *rtcp;
100 struct sockaddr_in us;
101 struct sockaddr_in them;
104 static struct ast_rtp_protocol *protos = NULL;
106 int ast_rtp_fd(struct ast_rtp *rtp)
111 int ast_rtcp_fd(struct ast_rtp *rtp)
118 static int g723_len(unsigned char buf)
120 switch(buf & TYPE_MASK) {
134 ast_log(LOG_WARNING, "Badly encoded frame (%d)\n", buf & TYPE_MASK);
139 static int g723_samples(unsigned char *buf, int maxlen)
144 while(pos < maxlen) {
145 res = g723_len(buf[pos]);
154 void ast_rtp_set_data(struct ast_rtp *rtp, void *data)
159 void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback)
161 rtp->callback = callback;
164 void ast_rtp_setnat(struct ast_rtp *rtp, int nat)
169 static struct ast_frame *send_dtmf(struct ast_rtp *rtp)
172 static struct ast_frame null_frame = { AST_FRAME_NULL, };
173 gettimeofday(&tv, NULL);
174 if ((tv.tv_sec < rtp->dtmfmute.tv_sec) ||
175 ((tv.tv_sec == rtp->dtmfmute.tv_sec) && (tv.tv_usec < rtp->dtmfmute.tv_usec))) {
176 ast_log(LOG_DEBUG, "Ignore potential DTMF echo from '%s'\n", inet_ntoa(rtp->them.sin_addr));
178 rtp->dtmfduration = 0;
181 ast_log(LOG_DEBUG, "Sending dtmf: %d (%c), at %s\n", rtp->resp, rtp->resp, inet_ntoa(rtp->them.sin_addr));
182 rtp->f.frametype = AST_FRAME_DTMF;
183 rtp->f.subclass = rtp->resp;
189 rtp->dtmfduration = 0;
194 static struct ast_frame *process_cisco_dtmf(struct ast_rtp *rtp, unsigned char *data, int len)
198 struct ast_frame *f = NULL;
199 event = ntohl(*((unsigned int *)(data)));
202 printf("Cisco Digit: %08x (len = %d)\n", event, len);
206 } else if (event < 11) {
208 } else if (event < 12) {
210 } else if (event < 16) {
211 resp = 'A' + (event - 12);
213 if (rtp->resp && (rtp->resp != resp)) {
217 rtp->dtmfcount = dtmftimeout;
221 static struct ast_frame *process_rfc2833(struct ast_rtp *rtp, unsigned char *data, int len)
224 unsigned int event_end;
225 unsigned int duration;
227 struct ast_frame *f = NULL;
228 event = ntohl(*((unsigned int *)(data)));
230 event_end = ntohl(*((unsigned int *)(data)));
233 duration = ntohl(*((unsigned int *)(data)));
236 printf("Event: %08x (len = %d)\n", event, len);
240 } else if (event < 11) {
242 } else if (event < 12) {
244 } else if (event < 16) {
245 resp = 'A' + (event - 12);
247 if (rtp->resp && (rtp->resp != resp)) {
250 else if(event_end & 0x80)
259 else if(rtp->dtmfduration && (duration < rtp->dtmfduration))
263 if (!(event_end & 0x80))
265 rtp->dtmfcount = dtmftimeout;
266 rtp->dtmfduration = duration;
270 static struct ast_frame *process_rfc3389(struct ast_rtp *rtp, unsigned char *data, int len)
272 struct ast_frame *f = NULL;
273 /* Convert comfort noise into audio with various codecs. Unfortunately this doesn't
274 totally help us out becuase we don't have an engine to keep it going and we are not
275 guaranteed to have it every 20ms or anything */
277 printf("RFC3389: %d bytes, format is %d\n", len, rtp->lastrxformat);
279 if (!(rtp->flags & FLAG_3389_WARNING)) {
280 ast_log(LOG_NOTICE, "RFC3389 support incomplete. Turn off on client if possible\n");
281 rtp->flags |= FLAG_3389_WARNING;
283 if (!rtp->lastrxformat)
285 switch(rtp->lastrxformat) {
286 case AST_FORMAT_ULAW:
287 rtp->f.frametype = AST_FRAME_VOICE;
288 rtp->f.subclass = AST_FORMAT_ULAW;
289 rtp->f.datalen = 160;
290 rtp->f.samples = 160;
291 memset(rtp->f.data, 0x7f, rtp->f.datalen);
294 case AST_FORMAT_ALAW:
295 rtp->f.frametype = AST_FRAME_VOICE;
296 rtp->f.subclass = AST_FORMAT_ALAW;
297 rtp->f.datalen = 160;
298 rtp->f.samples = 160;
299 memset(rtp->f.data, 0x7e, rtp->f.datalen); /* XXX Is this right? XXX */
302 case AST_FORMAT_SLINEAR:
303 rtp->f.frametype = AST_FRAME_VOICE;
304 rtp->f.subclass = AST_FORMAT_SLINEAR;
305 rtp->f.datalen = 320;
306 rtp->f.samples = 160;
307 memset(rtp->f.data, 0x00, rtp->f.datalen);
311 ast_log(LOG_NOTICE, "Don't know how to handle RFC3389 for receive codec %d\n", rtp->lastrxformat);
316 static int rtpread(int *id, int fd, short events, void *cbdata)
318 struct ast_rtp *rtp = cbdata;
320 f = ast_rtp_read(rtp);
323 rtp->callback(rtp, f, rtp->data);
328 struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp)
330 static struct ast_frame null_frame = { AST_FRAME_NULL, };
334 struct sockaddr_in sin;
335 unsigned int rtcpdata[1024];
342 res = recvfrom(rtp->rtcp->s, rtcpdata, sizeof(rtcpdata),
343 0, (struct sockaddr *)&sin, &len);
346 ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno));
353 ast_log(LOG_WARNING, "RTP Read too short\n");
358 /* Send to whoever sent to us */
359 if ((rtp->rtcp->them.sin_addr.s_addr != sin.sin_addr.s_addr) ||
360 (rtp->rtcp->them.sin_port != sin.sin_port)) {
361 memcpy(&rtp->them, &sin, sizeof(rtp->them));
362 ast_log(LOG_DEBUG, "RTP NAT: Using address %s:%d\n", inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
366 ast_log(LOG_DEBUG, "Got RTCP report of %d bytes\n", res);
370 static void calc_rxstamp(struct timeval *tv, struct ast_rtp *rtp, unsigned int timestamp, int mark)
372 if ((!rtp->rxcore.tv_sec && !rtp->rxcore.tv_usec) || mark) {
373 gettimeofday(&rtp->rxcore, NULL);
374 rtp->rxcore.tv_sec -= timestamp / 8000;
375 rtp->rxcore.tv_usec -= (timestamp % 8000) * 125;
376 rtp->rxcore.tv_usec -= rtp->rxcore.tv_usec % 20000;
377 if (rtp->rxcore.tv_usec < 0) {
378 /* Adjust appropriately if necessary */
379 rtp->rxcore.tv_usec += 1000000;
380 rtp->rxcore.tv_sec -= 1;
383 tv->tv_sec = rtp->rxcore.tv_sec + timestamp / 8000;
384 tv->tv_usec = rtp->rxcore.tv_usec + (timestamp % 8000) * 125;
385 if (tv->tv_usec >= 1000000) {
386 tv->tv_usec -= 1000000;
391 struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
394 struct sockaddr_in sin;
400 unsigned int timestamp;
401 unsigned int *rtpheader;
402 static struct ast_frame *f, null_frame = { AST_FRAME_NULL, };
403 struct rtpPayloadType rtpPT;
407 /* Cache where the header will go */
408 res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET,
409 0, (struct sockaddr *)&sin, &len);
412 rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET);
415 ast_log(LOG_NOTICE, "RTP: Received packet with bad UDP checksum\n");
417 ast_log(LOG_WARNING, "RTP Read error: %s\n", strerror(errno));
423 ast_log(LOG_WARNING, "RTP Read too short\n");
427 /* Ignore if the other side hasn't been given an address
429 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port)
433 /* Send to whoever sent to us */
434 if ((rtp->them.sin_addr.s_addr != sin.sin_addr.s_addr) ||
435 (rtp->them.sin_port != sin.sin_port)) {
436 memcpy(&rtp->them, &sin, sizeof(rtp->them));
437 ast_log(LOG_DEBUG, "RTP NAT: Using address %s:%d\n", inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port));
442 seqno = ntohl(rtpheader[0]);
443 payloadtype = (seqno & 0x7f0000) >> 16;
444 mark = seqno & (1 << 23);
446 timestamp = ntohl(rtpheader[1]);
449 printf("Got RTP packet from %s:%d (type %d, seq %d, ts %d, len = %d)\n", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen);
451 rtpPT = ast_rtp_lookup_pt(rtp, payloadtype);
452 if (!rtpPT.isAstFormat) {
453 // This is special in-band data that's not one of our codecs
454 if (rtpPT.code == AST_RTP_DTMF) {
455 /* It's special -- rfc2833 process it */
456 if (rtp->lasteventseqn <= seqno) {
457 f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
458 rtp->lasteventseqn = seqno;
460 if (f) return f; else return &null_frame;
461 } else if (rtpPT.code == AST_RTP_CISCO_DTMF) {
462 /* It's really special -- process it the Cisco way */
463 if (rtp->lasteventseqn <= seqno) {
464 f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
465 rtp->lasteventseqn = seqno;
467 if (f) return f; else return &null_frame;
468 } else if (rtpPT.code == AST_RTP_CN) {
470 f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
471 if (f) return f; else return &null_frame;
473 ast_log(LOG_NOTICE, "Unknown RTP codec %d received\n", payloadtype);
477 rtp->f.subclass = rtpPT.code;
478 if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO)
479 rtp->f.frametype = AST_FRAME_VOICE;
481 rtp->f.frametype = AST_FRAME_VIDEO;
482 rtp->lastrxformat = rtp->f.subclass;
485 rtp->lastrxts = timestamp;
487 if (rtp->dtmfcount) {
489 printf("dtmfcount was %d\n", rtp->dtmfcount);
491 rtp->dtmfcount -= (timestamp - rtp->lastrxts);
492 if (rtp->dtmfcount < 0)
495 if (dtmftimeout != rtp->dtmfcount)
496 printf("dtmfcount is %d\n", rtp->dtmfcount);
499 rtp->lastrxts = timestamp;
501 /* Send any pending DTMF */
502 if (rtp->resp && !rtp->dtmfcount) {
503 ast_log(LOG_DEBUG, "Sending pending DTMF\n");
504 return send_dtmf(rtp);
507 rtp->f.datalen = res - hdrlen;
508 rtp->f.data = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET;
509 rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET;
510 if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) {
511 switch(rtp->f.subclass) {
512 case AST_FORMAT_ULAW:
513 case AST_FORMAT_ALAW:
514 rtp->f.samples = rtp->f.datalen;
516 case AST_FORMAT_SLINEAR:
517 rtp->f.samples = rtp->f.datalen / 2;
520 rtp->f.samples = 160 * (rtp->f.datalen / 33);
522 case AST_FORMAT_ILBC:
523 rtp->f.samples = 240 * (rtp->f.datalen / 50);
525 case AST_FORMAT_ADPCM:
526 case AST_FORMAT_G726:
527 rtp->f.samples = rtp->f.datalen * 2;
529 case AST_FORMAT_G729A:
530 rtp->f.samples = rtp->f.datalen * 8;
532 case AST_FORMAT_G723_1:
533 rtp->f.samples = g723_samples(rtp->f.data, rtp->f.datalen);
535 case AST_FORMAT_SPEEX:
536 rtp->f.samples = 160;
537 // assumes that the RTP packet contained one Speex frame
540 ast_log(LOG_NOTICE, "Unable to calculate samples for format %s\n", ast_getformatname(rtp->f.subclass));
543 calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark);
545 /* Video -- samples is # of samples vs. 90000 */
546 if (!rtp->lastividtimestamp)
547 rtp->lastividtimestamp = timestamp;
548 rtp->f.samples = timestamp - rtp->lastividtimestamp;
549 rtp->lastividtimestamp = timestamp;
550 rtp->f.delivery.tv_sec = 0;
551 rtp->f.delivery.tv_usec = 0;
553 rtp->f.subclass |= 0x1;
560 // The following array defines the MIME type (and subtype) for each
561 // of our codecs, or RTP-specific data type.
563 struct rtpPayloadType payloadType;
567 {{1, AST_FORMAT_G723_1}, "audio", "G723"},
568 {{1, AST_FORMAT_GSM}, "audio", "GSM"},
569 {{1, AST_FORMAT_ULAW}, "audio", "PCMU"},
570 {{1, AST_FORMAT_ALAW}, "audio", "PCMA"},
571 {{1, AST_FORMAT_G726}, "audio", "G726-32"},
572 {{1, AST_FORMAT_ADPCM}, "audio", "DVI4"},
573 {{1, AST_FORMAT_SLINEAR}, "audio", "L16"},
574 {{1, AST_FORMAT_LPC10}, "audio", "LPC"},
575 {{1, AST_FORMAT_G729A}, "audio", "G729"},
576 {{1, AST_FORMAT_SPEEX}, "audio", "SPEEX"},
577 {{1, AST_FORMAT_ILBC}, "audio", "iLBC"},
578 {{0, AST_RTP_DTMF}, "audio", "telephone-event"},
579 {{0, AST_RTP_CISCO_DTMF}, "audio", "cisco-telephone-event"},
580 {{0, AST_RTP_CN}, "audio", "CN"},
581 {{1, AST_FORMAT_JPEG}, "video", "JPEG"},
582 {{1, AST_FORMAT_PNG}, "video", "PNG"},
583 {{1, AST_FORMAT_H261}, "video", "H261"},
584 {{1, AST_FORMAT_H263}, "video", "H263"},
587 /* Static (i.e., well-known) RTP payload types for our "AST_FORMAT..."s:
588 also, our own choices for dynamic payload types. This is our master
589 table for transmission */
590 static struct rtpPayloadType static_RTP_PT[MAX_RTP_PT] = {
591 [0] = {1, AST_FORMAT_ULAW},
592 [2] = {1, AST_FORMAT_G726}, // Technically this is G.721, but if Cisco can do it, so can we...
593 [3] = {1, AST_FORMAT_GSM},
594 [4] = {1, AST_FORMAT_G723_1},
595 [5] = {1, AST_FORMAT_ADPCM}, // 8 kHz
596 [6] = {1, AST_FORMAT_ADPCM}, // 16 kHz
597 [7] = {1, AST_FORMAT_LPC10},
598 [8] = {1, AST_FORMAT_ALAW},
599 [10] = {1, AST_FORMAT_SLINEAR}, // 2 channels
600 [11] = {1, AST_FORMAT_SLINEAR}, // 1 channel
601 [13] = {0, AST_RTP_CN},
602 [16] = {1, AST_FORMAT_ADPCM}, // 11.025 kHz
603 [17] = {1, AST_FORMAT_ADPCM}, // 22.050 kHz
604 [18] = {1, AST_FORMAT_G729A},
605 [26] = {1, AST_FORMAT_JPEG},
606 [31] = {1, AST_FORMAT_H261},
607 [34] = {1, AST_FORMAT_H263},
608 [97] = {1, AST_FORMAT_ILBC},
609 [101] = {0, AST_RTP_DTMF},
610 [110] = {1, AST_FORMAT_SPEEX},
611 [121] = {0, AST_RTP_CISCO_DTMF}, // Must be type 121
614 void ast_rtp_pt_clear(struct ast_rtp* rtp)
618 for (i = 0; i < MAX_RTP_PT; ++i) {
619 rtp->current_RTP_PT[i].isAstFormat = 0;
620 rtp->current_RTP_PT[i].code = 0;
623 rtp->rtp_lookup_code_cache_isAstFormat = 0;
624 rtp->rtp_lookup_code_cache_code = 0;
625 rtp->rtp_lookup_code_cache_result = 0;
628 void ast_rtp_pt_default(struct ast_rtp* rtp)
631 /* Initialize to default payload types */
632 for (i = 0; i < MAX_RTP_PT; ++i) {
633 rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat;
634 rtp->current_RTP_PT[i].code = static_RTP_PT[i].code;
637 rtp->rtp_lookup_code_cache_isAstFormat = 0;
638 rtp->rtp_lookup_code_cache_code = 0;
639 rtp->rtp_lookup_code_cache_result = 0;
642 // Make a note of a RTP payload type that was seen in a SDP "m=" line.
643 // By default, use the well-known value for this type (although it may
644 // still be set to a different value by a subsequent "a=rtpmap:" line):
645 void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt) {
646 if (pt < 0 || pt > MAX_RTP_PT) return; // bogus payload type
648 if (static_RTP_PT[pt].code != 0) {
649 rtp->current_RTP_PT[pt] = static_RTP_PT[pt];
653 // Make a note of a RTP payload type (with MIME type) that was seen in
654 // a SDP "a=rtpmap:" line.
655 void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
656 char* mimeType, char* mimeSubtype) {
659 if (pt < 0 || pt > MAX_RTP_PT) return; // bogus payload type
661 for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
662 if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 &&
663 strcasecmp(mimeType, mimeTypes[i].type) == 0) {
664 rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType;
670 // Return the union of all of the codecs that were set by rtp_set...() calls
671 // They're returned as two distinct sets: AST_FORMATs, and AST_RTPs
672 void ast_rtp_get_current_formats(struct ast_rtp* rtp,
673 int* astFormats, int* nonAstFormats) {
676 *astFormats = *nonAstFormats = 0;
677 for (pt = 0; pt < MAX_RTP_PT; ++pt) {
678 if (rtp->current_RTP_PT[pt].isAstFormat) {
679 *astFormats |= rtp->current_RTP_PT[pt].code;
681 *nonAstFormats |= rtp->current_RTP_PT[pt].code;
686 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt)
688 struct rtpPayloadType result;
689 if (pt < 0 || pt > MAX_RTP_PT) {
690 result.isAstFormat = result.code = 0;
691 return result; // bogus payload type
693 /* Start with the negotiated codecs */
694 result = rtp->current_RTP_PT[pt];
695 /* If it doesn't exist, check our static RTP type list, just in case */
697 result = static_RTP_PT[pt];
701 int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) {
704 /* Looks up an RTP code out of our *static* outbound list */
706 if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat &&
707 code == rtp->rtp_lookup_code_cache_code) {
708 // Use our cached mapping, to avoid the overhead of the loop below
709 return rtp->rtp_lookup_code_cache_result;
712 /* Check the dynamic list first */
713 for (pt = 0; pt < MAX_RTP_PT; ++pt) {
714 if (rtp->current_RTP_PT[pt].code == code &&
715 rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) {
716 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
717 rtp->rtp_lookup_code_cache_code = code;
718 rtp->rtp_lookup_code_cache_result = pt;
723 /* Then the static list */
724 for (pt = 0; pt < MAX_RTP_PT; ++pt) {
725 if (static_RTP_PT[pt].code == code &&
726 static_RTP_PT[pt].isAstFormat == isAstFormat) {
727 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
728 rtp->rtp_lookup_code_cache_code = code;
729 rtp->rtp_lookup_code_cache_result = pt;
736 char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code) {
739 for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
740 if (mimeTypes[i].payloadType.code == code &&
741 mimeTypes[i].payloadType.isAstFormat == isAstFormat) {
742 return mimeTypes[i].subtype;
748 static struct ast_rtcp *ast_rtcp_new(void)
750 struct ast_rtcp *rtcp;
752 rtcp = malloc(sizeof(struct ast_rtcp));
755 memset(rtcp, 0, sizeof(struct ast_rtcp));
756 rtcp->s = socket(AF_INET, SOCK_DGRAM, 0);
757 rtcp->us.sin_family = AF_INET;
760 ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
763 flags = fcntl(rtcp->s, F_GETFL);
764 fcntl(rtcp->s, F_SETFL, flags | O_NONBLOCK);
768 struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode)
774 rtp = malloc(sizeof(struct ast_rtp));
777 memset(rtp, 0, sizeof(struct ast_rtp));
778 rtp->them.sin_family = AF_INET;
779 rtp->us.sin_family = AF_INET;
780 rtp->s = socket(AF_INET, SOCK_DGRAM, 0);
782 rtp->seqno = rand() & 0xffff;
785 ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
788 if (sched && rtcpenable) {
790 rtp->rtcp = ast_rtcp_new();
792 flags = fcntl(rtp->s, F_GETFL);
793 fcntl(rtp->s, F_SETFL, flags | O_NONBLOCK);
794 /* Find us a place */
795 x = (rand() % (rtpend-rtpstart)) + rtpstart;
799 /* Must be an even port number by RTP spec */
800 rtp->us.sin_port = htons(x);
802 rtp->rtcp->us.sin_port = htons(x + 1);
803 if (!bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us)) &&
804 (!rtp->rtcp || !bind(rtp->rtcp->s, (struct sockaddr *)&rtp->rtcp->us, sizeof(rtp->rtcp->us))))
806 if (errno != EADDRINUSE) {
807 ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno));
818 x = (rtpstart + 1) & ~1;
819 if (x == startplace) {
820 ast_log(LOG_WARNING, "No RTP ports remaining\n");
830 if (io && sched && callbackmode) {
831 /* Operate this one in a callback mode */
834 rtp->ioid = ast_io_add(rtp->io, rtp->s, rtpread, AST_IO_IN, rtp);
836 ast_rtp_pt_default(rtp);
840 int ast_rtp_settos(struct ast_rtp *rtp, int tos)
843 if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))))
844 ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
848 void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them)
850 rtp->them.sin_port = them->sin_port;
851 rtp->them.sin_addr = them->sin_addr;
853 rtp->rtcp->them.sin_port = htons(ntohs(them->sin_port) + 1);
854 rtp->rtcp->them.sin_addr = them->sin_addr;
858 void ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them)
860 them->sin_family = AF_INET;
861 them->sin_port = rtp->them.sin_port;
862 them->sin_addr = rtp->them.sin_addr;
865 void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us)
867 memcpy(us, &rtp->us, sizeof(rtp->us));
870 void ast_rtp_stop(struct ast_rtp *rtp)
872 memset(&rtp->them.sin_addr, 0, sizeof(rtp->them.sin_addr));
873 memset(&rtp->them.sin_port, 0, sizeof(rtp->them.sin_port));
875 memset(&rtp->rtcp->them.sin_addr, 0, sizeof(rtp->them.sin_addr));
876 memset(&rtp->rtcp->them.sin_port, 0, sizeof(rtp->them.sin_port));
880 void ast_rtp_destroy(struct ast_rtp *rtp)
883 ast_smoother_free(rtp->smoother);
885 ast_io_remove(rtp->io, rtp->ioid);
895 static unsigned int calc_txstamp(struct ast_rtp *rtp, struct timeval *delivery)
899 if (!rtp->txcore.tv_sec && !rtp->txcore.tv_usec) {
900 gettimeofday(&rtp->txcore, NULL);
901 rtp->txcore.tv_usec -= rtp->txcore.tv_usec % 20000;
903 if (delivery && (delivery->tv_sec || delivery->tv_usec)) {
904 /* Use previous txcore */
905 ms = (delivery->tv_sec - rtp->txcore.tv_sec) * 1000;
906 ms += (delivery->tv_usec - rtp->txcore.tv_usec) / 1000;
907 rtp->txcore.tv_sec = delivery->tv_sec;
908 rtp->txcore.tv_usec = delivery->tv_usec;
910 gettimeofday(&now, NULL);
911 ms = (now.tv_sec - rtp->txcore.tv_sec) * 1000;
912 ms += (now.tv_usec - rtp->txcore.tv_usec) / 1000;
913 /* Use what we just got for next time */
914 rtp->txcore.tv_sec = now.tv_sec;
915 rtp->txcore.tv_usec = now.tv_usec;
920 int ast_rtp_senddigit(struct ast_rtp *rtp, char digit)
922 unsigned int *rtpheader;
929 if ((digit <= '9') && (digit >= '0'))
931 else if (digit == '*')
933 else if (digit == '#')
935 else if ((digit >= 'A') && (digit <= 'D'))
936 digit = digit - 'A' + 12;
937 else if ((digit >= 'a') && (digit <= 'd'))
938 digit = digit - 'a' + 12;
940 ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit);
945 /* If we have no peer, return immediately */
946 if (!rtp->them.sin_addr.s_addr)
949 gettimeofday(&rtp->dtmfmute, NULL);
950 rtp->dtmfmute.tv_usec += (500 * 1000);
951 if (rtp->dtmfmute.tv_usec > 1000000) {
952 rtp->dtmfmute.tv_usec -= 1000000;
953 rtp->dtmfmute.tv_sec += 1;
956 ms = calc_txstamp(rtp, NULL);
957 /* Default prediction */
958 rtp->lastts = rtp->lastts + ms * 8;
960 /* Get a pointer to the header */
961 rtpheader = (unsigned int *)data;
962 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (101 << 16) | (rtp->seqno++));
963 rtpheader[1] = htonl(rtp->lastts);
964 rtpheader[2] = htonl(rtp->ssrc);
965 rtpheader[3] = htonl((digit << 24) | (0xa << 16) | (0));
967 if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) {
968 res = sendto(rtp->s, (void *)rtpheader, hdrlen + 4, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them));
970 ast_log(LOG_NOTICE, "RTP Transmission error to %s:%d: %s\n", inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno));
972 printf("Sent %d bytes of RTP data to %s:%d\n", res, inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port));
976 /* Clear marker bit and increment seqno */
977 rtpheader[0] = htonl((2 << 30) | (101 << 16) | (rtp->seqno++));
978 /* Make duration 800 (100ms) */
979 rtpheader[3] |= htonl((800));
980 /* Set the End bit for the last 3 */
981 rtpheader[3] |= htonl((1 << 23));
987 static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec)
989 unsigned int *rtpheader;
996 ms = calc_txstamp(rtp, &f->delivery);
997 /* Default prediction */
998 if (f->subclass < AST_FORMAT_MAX_AUDIO) {
999 pred = rtp->lastts + ms * 8;
1001 switch(f->subclass) {
1002 case AST_FORMAT_ULAW:
1003 case AST_FORMAT_ALAW:
1004 /* If we're within +/- 20ms from when where we
1005 predict we should be, use that */
1006 pred = rtp->lastts + f->datalen;
1008 case AST_FORMAT_ADPCM:
1009 case AST_FORMAT_G726:
1010 /* If we're within +/- 20ms from when where we
1011 predict we should be, use that */
1012 pred = rtp->lastts + f->datalen * 2;
1014 case AST_FORMAT_G729A:
1015 pred = rtp->lastts + f->datalen * 8;
1017 case AST_FORMAT_GSM:
1018 pred = rtp->lastts + (f->datalen * 160 / 33);
1020 case AST_FORMAT_ILBC:
1021 pred = rtp->lastts + (f->datalen * 240 / 50);
1023 case AST_FORMAT_G723_1:
1024 pred = rtp->lastts + g723_samples(f->data, f->datalen);
1026 case AST_FORMAT_SPEEX:
1027 pred = rtp->lastts + 160;
1028 // assumes that the RTP packet contains one Speex frame
1031 ast_log(LOG_WARNING, "Not sure about timestamp format for codec format %s\n", ast_getformatname(f->subclass));
1033 /* Re-calculate last TS */
1034 rtp->lastts = rtp->lastts + ms * 8;
1035 if (!f->delivery.tv_sec && !f->delivery.tv_usec) {
1036 /* If this isn't an absolute delivery time, Check if it is close to our prediction,
1037 and if so, go with our prediction */
1038 if (abs(rtp->lastts - pred) < 640)
1041 ast_log(LOG_DEBUG, "Difference is %d, ms is %d\n", abs(rtp->lastts - pred), ms);
1046 mark = f->subclass & 0x1;
1047 pred = rtp->lastovidtimestamp + f->samples;
1048 /* Re-calculate last TS */
1049 rtp->lastts = rtp->lastts + ms * 90;
1050 /* If it's close to our prediction, go for it */
1051 if (!f->delivery.tv_sec && !f->delivery.tv_usec) {
1052 if (abs(rtp->lastts - pred) < 7200) {
1054 rtp->lastovidtimestamp += f->samples;
1056 ast_log(LOG_DEBUG, "Difference is %d, ms is %d (%d), pred/ts/samples %d/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, f->samples);
1057 rtp->lastovidtimestamp = rtp->lastts;
1061 /* Get a pointer to the header */
1062 rtpheader = (unsigned int *)(f->data - hdrlen);
1063 rtpheader[0] = htonl((2 << 30) | (codec << 16) | (rtp->seqno++) | (mark << 23));
1064 rtpheader[1] = htonl(rtp->lastts);
1065 rtpheader[2] = htonl(rtp->ssrc);
1066 if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) {
1067 res = sendto(rtp->s, (void *)rtpheader, f->datalen + hdrlen, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them));
1069 ast_log(LOG_NOTICE, "RTP Transmission error to %s:%d: %s\n", inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno));
1071 printf("Sent %d bytes of RTP data to %s:%d\n", res, inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port));
1077 int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
1079 struct ast_frame *f;
1085 /* If we have no peer, return immediately */
1086 if (!rtp->them.sin_addr.s_addr)
1089 /* If there is no data length, return immediately */
1093 /* Make sure we have enough space for RTP header */
1094 if ((_f->frametype != AST_FRAME_VOICE) && (_f->frametype != AST_FRAME_VIDEO)) {
1095 ast_log(LOG_WARNING, "RTP can only send voice\n");
1099 subclass = _f->subclass;
1100 if (_f->frametype == AST_FRAME_VIDEO)
1103 codec = ast_rtp_lookup_code(rtp, 1, subclass);
1105 ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(_f->subclass));
1109 if (rtp->lasttxformat != subclass) {
1110 /* New format, reset the smoother */
1111 ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass));
1112 rtp->lasttxformat = subclass;
1114 ast_smoother_free(rtp->smoother);
1115 rtp->smoother = NULL;
1120 case AST_FORMAT_ULAW:
1121 case AST_FORMAT_ALAW:
1122 if (!rtp->smoother) {
1123 rtp->smoother = ast_smoother_new(160);
1125 if (!rtp->smoother) {
1126 ast_log(LOG_WARNING, "Unable to create smoother :(\n");
1129 ast_smoother_feed(rtp->smoother, _f);
1131 while((f = ast_smoother_read(rtp->smoother)))
1132 ast_rtp_raw_write(rtp, f, codec);
1134 case AST_FORMAT_ADPCM:
1135 case AST_FORMAT_G726:
1136 if (!rtp->smoother) {
1137 rtp->smoother = ast_smoother_new(80);
1139 if (!rtp->smoother) {
1140 ast_log(LOG_WARNING, "Unable to create smoother :(\n");
1143 ast_smoother_feed(rtp->smoother, _f);
1145 while((f = ast_smoother_read(rtp->smoother)))
1146 ast_rtp_raw_write(rtp, f, codec);
1148 case AST_FORMAT_G729A:
1149 if (!rtp->smoother) {
1150 rtp->smoother = ast_smoother_new(20);
1152 ast_smoother_set_flags(rtp->smoother, AST_SMOOTHER_FLAG_G729);
1154 if (!rtp->smoother) {
1155 ast_log(LOG_WARNING, "Unable to create g729 smoother :(\n");
1158 ast_smoother_feed(rtp->smoother, _f);
1160 while((f = ast_smoother_read(rtp->smoother)))
1161 ast_rtp_raw_write(rtp, f, codec);
1163 case AST_FORMAT_GSM:
1164 if (!rtp->smoother) {
1165 rtp->smoother = ast_smoother_new(33);
1167 if (!rtp->smoother) {
1168 ast_log(LOG_WARNING, "Unable to create GSM smoother :(\n");
1171 ast_smoother_feed(rtp->smoother, _f);
1172 while((f = ast_smoother_read(rtp->smoother)))
1173 ast_rtp_raw_write(rtp, f, codec);
1175 case AST_FORMAT_ILBC:
1176 if (!rtp->smoother) {
1177 rtp->smoother = ast_smoother_new(50);
1179 if (!rtp->smoother) {
1180 ast_log(LOG_WARNING, "Unable to create ILBC smoother :(\n");
1183 ast_smoother_feed(rtp->smoother, _f);
1184 while((f = ast_smoother_read(rtp->smoother)))
1185 ast_rtp_raw_write(rtp, f, codec);
1188 ast_log(LOG_WARNING, "Not sure about sending format %s packets\n", ast_getformatname(subclass));
1189 // fall through to...
1190 case AST_FORMAT_H261:
1191 case AST_FORMAT_H263:
1192 case AST_FORMAT_G723_1:
1193 case AST_FORMAT_SPEEX:
1194 // Don't buffer outgoing frames; send them one-per-packet:
1195 if (_f->offset < hdrlen) {
1200 ast_rtp_raw_write(rtp, f, codec);
1206 void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto)
1208 struct ast_rtp_protocol *cur, *prev;
1214 prev->next = proto->next;
1216 protos = proto->next;
1224 int ast_rtp_proto_register(struct ast_rtp_protocol *proto)
1226 struct ast_rtp_protocol *cur;
1229 if (cur->type == proto->type) {
1230 ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type);
1235 proto->next = protos;
1240 static struct ast_rtp_protocol *get_proto(struct ast_channel *chan)
1242 struct ast_rtp_protocol *cur;
1245 if (cur->type == chan->type) {
1253 int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc)
1255 struct ast_frame *f;
1256 struct ast_channel *who, *cs[3];
1257 struct ast_rtp *p0, *p1;
1258 struct ast_rtp *vp0, *vp1;
1259 struct ast_rtp_protocol *pr0, *pr1;
1260 struct sockaddr_in ac0, ac1;
1261 struct sockaddr_in vac0, vac1;
1262 struct sockaddr_in t0, t1;
1263 struct sockaddr_in vt0, vt1;
1267 int codec0,codec1, oldcodec0, oldcodec1;
1269 memset(&vt0, 0, sizeof(vt0));
1270 memset(&vt1, 0, sizeof(vt1));
1271 memset(&vac0, 0, sizeof(vac0));
1272 memset(&vac1, 0, sizeof(vac1));
1274 /* if need DTMF, cant native bridge */
1275 if (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1))
1277 ast_mutex_lock(&c0->lock);
1278 ast_mutex_lock(&c1->lock);
1279 pr0 = get_proto(c0);
1280 pr1 = get_proto(c1);
1282 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name);
1283 ast_mutex_unlock(&c0->lock);
1284 ast_mutex_unlock(&c1->lock);
1288 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name);
1289 ast_mutex_unlock(&c0->lock);
1290 ast_mutex_unlock(&c1->lock);
1293 pvt0 = c0->pvt->pvt;
1294 pvt1 = c1->pvt->pvt;
1295 p0 = pr0->get_rtp_info(c0);
1296 if (pr0->get_vrtp_info)
1297 vp0 = pr0->get_vrtp_info(c0);
1300 p1 = pr1->get_rtp_info(c1);
1301 if (pr1->get_vrtp_info)
1302 vp1 = pr1->get_vrtp_info(c1);
1306 /* Somebody doesn't want to play... */
1307 ast_mutex_unlock(&c0->lock);
1308 ast_mutex_unlock(&c1->lock);
1312 codec0 = pr0->get_codec(c0);
1316 codec1 = pr1->get_codec(c1);
1319 if (pr0->get_codec && pr1->get_codec) {
1320 /* Hey, we can't do reinvite if both parties speak diffrent codecs */
1321 if (!(codec0 & codec1)) {
1322 ast_log(LOG_WARNING, "codec0 = %d is not codec1 = %d, cannot native bridge.\n",codec0,codec1);
1323 ast_mutex_unlock(&c0->lock);
1324 ast_mutex_unlock(&c1->lock);
1328 if (pr0->set_rtp_peer(c0, p1, vp1, codec1))
1329 ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
1331 /* Store RTP peer */
1332 ast_rtp_get_peer(p1, &ac1);
1334 ast_rtp_get_peer(vp1, &vac1);
1336 if (pr1->set_rtp_peer(c1, p0, vp0, codec0))
1337 ast_log(LOG_WARNING, "Channel '%s' failed to talk back to '%s'\n", c1->name, c0->name);
1339 /* Store RTP peer */
1340 ast_rtp_get_peer(p0, &ac0);
1342 ast_rtp_get_peer(vp0, &vac0);
1344 ast_mutex_unlock(&c0->lock);
1345 ast_mutex_unlock(&c1->lock);
1352 if ((c0->pvt->pvt != pvt0) ||
1353 (c1->pvt->pvt != pvt1) ||
1354 (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
1355 ast_log(LOG_DEBUG, "Oooh, something is weird, backing out\n");
1356 if (c0->pvt->pvt == pvt0) {
1357 if (pr0->set_rtp_peer(c0, NULL, NULL, 0))
1358 ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
1360 if (c1->pvt->pvt == pvt1) {
1361 if (pr1->set_rtp_peer(c1, NULL, NULL, 0))
1362 ast_log(LOG_WARNING, "Channel '%s' failed to revert back\n", c1->name);
1364 /* Tell it to try again later */
1368 ast_rtp_get_peer(p1, &t1);
1369 ast_rtp_get_peer(p0, &t0);
1371 codec0 = pr0->get_codec(c0);
1373 codec1 = pr1->get_codec(c1);
1375 ast_rtp_get_peer(vp1, &vt1);
1377 ast_rtp_get_peer(vp0, &vt0);
1378 if (inaddrcmp(&t1, &ac1) || (vp1 && inaddrcmp(&vt1, &vac1)) || (codec1 != oldcodec1)) {
1379 ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
1380 c1->name, inet_ntoa(t1.sin_addr), ntohs(t1.sin_port), codec1);
1381 ast_log(LOG_DEBUG, "Oooh, '%s' changed end vaddress to %s:%d (format %d)\n",
1382 c1->name, inet_ntoa(vt1.sin_addr), ntohs(vt1.sin_port), codec1);
1383 ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
1384 c1->name, inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port), oldcodec1);
1385 ast_log(LOG_DEBUG, "Oooh, '%s' wasv %s:%d/(format %d)\n",
1386 c1->name, inet_ntoa(vac1.sin_addr), ntohs(vac1.sin_port), oldcodec1);
1387 if (pr0->set_rtp_peer(c0, t1.sin_addr.s_addr ? p1 : NULL, vt1.sin_addr.s_addr ? vp1 : NULL, codec1))
1388 ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c0->name, c1->name);
1389 memcpy(&ac1, &t1, sizeof(ac1));
1390 memcpy(&vac1, &vt1, sizeof(vac1));
1393 if (inaddrcmp(&t0, &ac0) || (vp0 && inaddrcmp(&vt0, &vac0))) {
1394 ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
1395 c0->name, inet_ntoa(t0.sin_addr), ntohs(t0.sin_port), codec0);
1396 ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
1397 c0->name, inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port), oldcodec0);
1398 if (pr1->set_rtp_peer(c1, t0.sin_addr.s_addr ? p0 : NULL, vt0.sin_addr.s_addr ? vp0 : NULL, codec0))
1399 ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c1->name, c0->name);
1400 memcpy(&ac0, &t0, sizeof(ac0));
1401 memcpy(&vac0, &vt0, sizeof(vac0));
1404 who = ast_waitfor_n(cs, 2, &to);
1406 ast_log(LOG_DEBUG, "Ooh, empty read...\n");
1407 /* check for hagnup / whentohangup */
1408 if (ast_check_hangup(c0) || ast_check_hangup(c1))
1413 if (!f || ((f->frametype == AST_FRAME_DTMF) &&
1414 (((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) ||
1415 ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) {
1418 ast_log(LOG_DEBUG, "Oooh, got a %s\n", f ? "digit" : "hangup");
1419 if ((c0->pvt->pvt == pvt0) && (!c0->_softhangup)) {
1420 if (pr0->set_rtp_peer(c0, NULL, NULL, 0))
1421 ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
1423 if ((c1->pvt->pvt == pvt1) && (!c1->_softhangup)) {
1424 if (pr1->set_rtp_peer(c1, NULL, NULL, 0))
1425 ast_log(LOG_WARNING, "Channel '%s' failed to revert back\n", c1->name);
1427 /* That's all we needed */
1430 if ((f->frametype == AST_FRAME_DTMF) ||
1431 (f->frametype == AST_FRAME_VOICE) ||
1432 (f->frametype == AST_FRAME_VIDEO)) {
1433 /* Forward voice or DTMF frames if they happen upon us */
1436 } else if (who == c1) {
1442 /* Swap priority not that it's a big deal at this point */
1451 void ast_rtp_reload(void)
1453 struct ast_config *cfg;
1457 cfg = ast_load("rtp.conf");
1459 if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) {
1461 if (rtpstart < 1024)
1463 if (rtpstart > 65535)
1466 if ((s = ast_variable_retrieve(cfg, "general", "rtpend"))) {
1475 if (rtpstart >= rtpend) {
1476 ast_log(LOG_WARNING, "Unreasonable values for RTP start/end\n");
1480 if (option_verbose > 1)
1481 ast_verbose(VERBOSE_PREFIX_2 "RTP Allocating from port range %d -> %d\n", rtpstart, rtpend);
1484 void ast_rtp_init(void)