#include <netinet/in.h>
#include "asterisk/frame.h"
#include "asterisk/io.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/linkedlists.h"
Go to the source code of this file.
Data Structures | |
struct | ast_rtp_protocol |
struct | ast_rtp_quality |
Defines | |
#define | AST_RTP_CISCO_DTMF (1 << 2) |
#define | AST_RTP_CN (1 << 1) |
#define | AST_RTP_DTMF (1 << 0) |
#define | AST_RTP_MAX AST_RTP_CISCO_DTMF |
#define | FLAG_3389_WARNING (1 << 0) |
#define | MAX_RTP_PT 256 |
Typedefs | |
typedef int(*) | ast_rtp_callback (struct ast_rtp *rtp, struct ast_frame *f, void *data) |
Enumerations | |
enum | ast_rtp_get_result { AST_RTP_GET_FAILED = 0, AST_RTP_TRY_PARTIAL, AST_RTP_TRY_NATIVE } |
enum | ast_rtp_options { AST_RTP_OPT_G726_NONSTANDARD = (1 << 0) } |
Functions | |
int | ast_rtcp_fd (struct ast_rtp *rtp) |
ast_frame * | ast_rtcp_read (struct ast_rtp *rtp) |
int | ast_rtcp_send_h261fur (void *data) |
Send an H.261 fast update request. Some devices need this rather than the XML message in SIP. | |
size_t | ast_rtp_alloc_size (void) |
Get the amount of space required to hold an RTP session. | |
int | ast_rtp_bridge (struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms) |
Bridge calls. If possible and allowed, initiate re-invite so the peers exchange media directly outside of Asterisk. | |
void | ast_rtp_change_source (struct ast_rtp *rtp) |
Indicate that we need to set the marker bit and change the ssrc. | |
int | ast_rtp_codec_getformat (int pt) |
ast_codec_pref * | ast_rtp_codec_getpref (struct ast_rtp *rtp) |
int | ast_rtp_codec_setpref (struct ast_rtp *rtp, struct ast_codec_pref *prefs) |
void | ast_rtp_destroy (struct ast_rtp *rtp) |
int | ast_rtp_early_bridge (struct ast_channel *dest, struct ast_channel *src) |
If possible, create an early bridge directly between the devices without having to send a re-invite later. | |
int | ast_rtp_fd (struct ast_rtp *rtp) |
ast_rtp * | ast_rtp_get_bridged (struct ast_rtp *rtp) |
void | ast_rtp_get_current_formats (struct ast_rtp *rtp, int *astFormats, int *nonAstFormats) |
Return the union of all of the codecs that were set by rtp_set...() calls They're returned as two distinct sets: AST_FORMATs, and AST_RTPs. | |
int | ast_rtp_get_peer (struct ast_rtp *rtp, struct sockaddr_in *them) |
char * | ast_rtp_get_quality (struct ast_rtp *rtp, struct ast_rtp_quality *qual) |
Return RTCP quality string. | |
int | ast_rtp_get_rtpholdtimeout (struct ast_rtp *rtp) |
Get rtp hold timeout. | |
int | ast_rtp_get_rtpkeepalive (struct ast_rtp *rtp) |
Get RTP keepalive interval. | |
int | ast_rtp_get_rtptimeout (struct ast_rtp *rtp) |
Get rtp timeout. | |
void | ast_rtp_get_us (struct ast_rtp *rtp, struct sockaddr_in *us) |
int | ast_rtp_getnat (struct ast_rtp *rtp) |
void | ast_rtp_init (void) |
Initialize the RTP system in Asterisk. | |
int | ast_rtp_lookup_code (struct ast_rtp *rtp, int isAstFormat, int code) |
Looks up an RTP code out of our *static* outbound list. | |
char * | ast_rtp_lookup_mime_multiple (char *buf, size_t size, const int capability, const int isAstFormat, enum ast_rtp_options options) |
Build a string of MIME subtype names from a capability list. | |
const char * | ast_rtp_lookup_mime_subtype (int isAstFormat, int code, enum ast_rtp_options options) |
Mapping an Asterisk code into a MIME subtype (string):. | |
rtpPayloadType | ast_rtp_lookup_pt (struct ast_rtp *rtp, int pt) |
Mapping between RTP payload format codes and Asterisk codes:. | |
int | ast_rtp_make_compatible (struct ast_channel *dest, struct ast_channel *src, int media) |
ast_rtp * | ast_rtp_new (struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode) |
Initializate a RTP session. | |
void | ast_rtp_new_init (struct ast_rtp *rtp) |
Initialize a new RTP structure. | |
void | ast_rtp_new_source (struct ast_rtp *rtp) |
Indicate that we need to set the marker bit. | |
ast_rtp * | ast_rtp_new_with_bindaddr (struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in) |
Initializate a RTP session using an in_addr structure. | |
int | ast_rtp_proto_register (struct ast_rtp_protocol *proto) |
Register interface to channel driver. | |
void | ast_rtp_proto_unregister (struct ast_rtp_protocol *proto) |
Unregister interface to channel driver. | |
void | ast_rtp_pt_clear (struct ast_rtp *rtp) |
Setting RTP payload types from lines in a SDP description:. | |
void | ast_rtp_pt_copy (struct ast_rtp *dest, struct ast_rtp *src) |
Copy payload types between RTP structures. | |
void | ast_rtp_pt_default (struct ast_rtp *rtp) |
Set payload types to defaults. | |
ast_frame * | ast_rtp_read (struct ast_rtp *rtp) |
int | ast_rtp_reload (void) |
void | ast_rtp_reset (struct ast_rtp *rtp) |
int | ast_rtp_sendcng (struct ast_rtp *rtp, int level) |
generate comfort noice (CNG) | |
int | ast_rtp_senddigit_begin (struct ast_rtp *rtp, char digit) |
Send begin frames for DTMF. | |
int | ast_rtp_senddigit_end (struct ast_rtp *rtp, char digit) |
int | ast_rtp_senddigit_end_with_duration (struct ast_rtp *rtp, char digit, unsigned int duration) |
void | ast_rtp_set_alt_peer (struct ast_rtp *rtp, struct sockaddr_in *alt) |
set potential alternate source for RTP media | |
void | ast_rtp_set_callback (struct ast_rtp *rtp, ast_rtp_callback callback) |
void | ast_rtp_set_data (struct ast_rtp *rtp, void *data) |
void | ast_rtp_set_m_type (struct ast_rtp *rtp, int pt) |
Activate payload type. | |
void | ast_rtp_set_peer (struct ast_rtp *rtp, struct sockaddr_in *them) |
void | ast_rtp_set_rtpholdtimeout (struct ast_rtp *rtp, int timeout) |
Set rtp hold timeout. | |
void | ast_rtp_set_rtpkeepalive (struct ast_rtp *rtp, int period) |
set RTP keepalive interval | |
int | ast_rtp_set_rtpmap_type (struct ast_rtp *rtp, int pt, char *mimeType, char *mimeSubtype, enum ast_rtp_options options) |
Initiate payload type to a known MIME media type for a codec. | |
void | ast_rtp_set_rtptimeout (struct ast_rtp *rtp, int timeout) |
Set rtp timeout. | |
void | ast_rtp_set_rtptimers_onhold (struct ast_rtp *rtp) |
void | ast_rtp_setdtmf (struct ast_rtp *rtp, int dtmf) |
Indicate whether this RTP session is carrying DTMF or not. | |
void | ast_rtp_setdtmfcompensate (struct ast_rtp *rtp, int compensate) |
Compensate for devices that send RFC2833 packets all at once. | |
void | ast_rtp_setnat (struct ast_rtp *rtp, int nat) |
void | ast_rtp_setstun (struct ast_rtp *rtp, int stun_enable) |
Enable STUN capability. | |
int | ast_rtp_settos (struct ast_rtp *rtp, int tos) |
void | ast_rtp_stop (struct ast_rtp *rtp) |
void | ast_rtp_stun_request (struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username) |
void | ast_rtp_unset_m_type (struct ast_rtp *rtp, int pt) |
clear payload type | |
int | ast_rtp_write (struct ast_rtp *rtp, struct ast_frame *f) |
RTP is defined in RFC 3550.
Definition in file rtp.h.
#define AST_RTP_CISCO_DTMF (1 << 2) |
#define AST_RTP_CN (1 << 1) |
'Comfort Noise' (RFC3389)
Definition at line 45 of file rtp.h.
Referenced by ast_rtp_read(), and ast_rtp_sendcng().
#define AST_RTP_DTMF (1 << 0) |
DTMF (RFC2833)
Definition at line 43 of file rtp.h.
Referenced by add_noncodec_to_sdp(), ast_rtp_read(), ast_rtp_senddigit_begin(), bridge_p2p_rtp_write(), check_user_full(), create_addr(), create_addr_from_peer(), oh323_alloc(), oh323_request(), process_sdp(), sip_alloc(), and sip_dtmfmode().
#define AST_RTP_MAX AST_RTP_CISCO_DTMF |
Maximum RTP-specific code
Definition at line 49 of file rtp.h.
Referenced by add_sdp(), and ast_rtp_lookup_mime_multiple().
#define MAX_RTP_PT 256 |
Definition at line 51 of file rtp.h.
Referenced by ast_rtp_get_current_formats(), ast_rtp_lookup_code(), ast_rtp_lookup_pt(), ast_rtp_pt_clear(), ast_rtp_pt_copy(), ast_rtp_pt_default(), ast_rtp_set_m_type(), ast_rtp_set_rtpmap_type(), ast_rtp_unset_m_type(), and process_sdp_a_audio().
typedef int(*) ast_rtp_callback(struct ast_rtp *rtp, struct ast_frame *f, void *data) |
enum ast_rtp_get_result |
Definition at line 57 of file rtp.h.
00057 { 00058 /*! Failed to find the RTP structure */ 00059 AST_RTP_GET_FAILED = 0, 00060 /*! RTP structure exists but true native bridge can not occur so try partial */ 00061 AST_RTP_TRY_PARTIAL, 00062 /*! RTP structure exists and native bridge can occur */ 00063 AST_RTP_TRY_NATIVE, 00064 };
enum ast_rtp_options |
int ast_rtcp_fd | ( | struct ast_rtp * | rtp | ) |
Definition at line 523 of file rtp.c.
References ast_rtp::rtcp, and ast_rtcp::s.
Referenced by __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), gtalk_new(), sip_new(), and start_rtp().
Definition at line 887 of file rtp.c.
References ast_rtcp::accumulated_transit, ast_rtcp::altthem, ast_assert, AST_CONTROL_VIDUPDATE, AST_FRAME_CONTROL, AST_FRIENDLY_OFFSET, ast_inet_ntoa(), ast_log(), ast_null_frame, ast_verbose(), ast_frame::datalen, errno, ast_rtp::f, f, ast_frame::frametype, len(), LOG_DEBUG, LOG_WARNING, ast_frame::mallocd, ast_rtcp::maxrtt, ast_rtcp::minrtt, ast_rtp::nat, option_debug, ast_rtcp::reported_jitter, ast_rtcp::reported_lost, ast_rtp::rtcp, rtcp_debug_test_addr(), RTCP_PT_BYE, RTCP_PT_FUR, RTCP_PT_RR, RTCP_PT_SDES, RTCP_PT_SR, ast_rtcp::rtt, ast_rtcp::rxlsr, ast_rtp::s, ast_rtcp::s, ast_frame::samples, ast_rtcp::soc, ast_rtcp::spc, ast_frame::src, ast_frame::subclass, ast_rtcp::them, ast_rtcp::themrxlsr, and timeval2ntp().
Referenced by oh323_read(), sip_rtp_read(), and skinny_rtp_read().
00888 { 00889 socklen_t len; 00890 int position, i, packetwords; 00891 int res; 00892 struct sockaddr_in sin; 00893 unsigned int rtcpdata[8192 + AST_FRIENDLY_OFFSET]; 00894 unsigned int *rtcpheader; 00895 int pt; 00896 struct timeval now; 00897 unsigned int length; 00898 int rc; 00899 double rttsec; 00900 uint64_t rtt = 0; 00901 unsigned int dlsr; 00902 unsigned int lsr; 00903 unsigned int msw; 00904 unsigned int lsw; 00905 unsigned int comp; 00906 struct ast_frame *f = &ast_null_frame; 00907 00908 if (!rtp || !rtp->rtcp) 00909 return &ast_null_frame; 00910 00911 len = sizeof(sin); 00912 00913 res = recvfrom(rtp->rtcp->s, rtcpdata + AST_FRIENDLY_OFFSET, sizeof(rtcpdata) - sizeof(unsigned int) * AST_FRIENDLY_OFFSET, 00914 0, (struct sockaddr *)&sin, &len); 00915 if (option_debug > 2) 00916 ast_log(LOG_DEBUG, "socket RTCP read: rtp %i rtcp %i\n", rtp->s, rtp->rtcp->s); 00917 00918 rtcpheader = (unsigned int *)(rtcpdata + AST_FRIENDLY_OFFSET); 00919 00920 if (res < 0) { 00921 ast_assert(errno != EBADF); 00922 if (errno != EAGAIN) { 00923 ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n", strerror(errno)); 00924 ast_log(LOG_WARNING, "socket RTCP read: rtp %i rtcp %i\n", rtp->s, rtp->rtcp->s); 00925 return NULL; 00926 } 00927 return &ast_null_frame; 00928 } 00929 00930 packetwords = res / 4; 00931 00932 if (rtp->nat) { 00933 /* Send to whoever sent to us */ 00934 if (((rtp->rtcp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || 00935 (rtp->rtcp->them.sin_port != sin.sin_port)) && 00936 ((rtp->rtcp->altthem.sin_addr.s_addr != sin.sin_addr.s_addr) || 00937 (rtp->rtcp->altthem.sin_port != sin.sin_port))) { 00938 memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); 00939 if (option_debug || rtpdebug) 00940 ast_log(LOG_DEBUG, "RTCP NAT: Got RTCP from other end. Now sending to address %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 00941 } 00942 } 00943 00944 if (option_debug) 00945 ast_log(LOG_DEBUG, "Got RTCP report of %d bytes\n", res); 00946 00947 /* Process a compound packet */ 00948 position = 0; 00949 while (position < packetwords) { 00950 i = position; 00951 length = ntohl(rtcpheader[i]); 00952 pt = (length & 0xff0000) >> 16; 00953 rc = (length & 0x1f000000) >> 24; 00954 length &= 0xffff; 00955 00956 if ((i + length) > packetwords) { 00957 ast_log(LOG_WARNING, "RTCP Read too short\n"); 00958 return &ast_null_frame; 00959 } 00960 00961 if (rtcp_debug_test_addr(&sin)) { 00962 ast_verbose("\n\nGot RTCP from %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 00963 ast_verbose("PT: %d(%s)\n", pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown"); 00964 ast_verbose("Reception reports: %d\n", rc); 00965 ast_verbose("SSRC of sender: %u\n", rtcpheader[i + 1]); 00966 } 00967 00968 i += 2; /* Advance past header and ssrc */ 00969 if (rc == 0 && pt == RTCP_PT_RR) { /* We're receiving a receiver report with no reports, which is ok */ 00970 position += (length + 1); 00971 continue; 00972 } 00973 00974 switch (pt) { 00975 case RTCP_PT_SR: 00976 gettimeofday(&rtp->rtcp->rxlsr,NULL); /* To be able to populate the dlsr */ 00977 rtp->rtcp->spc = ntohl(rtcpheader[i+3]); 00978 rtp->rtcp->soc = ntohl(rtcpheader[i + 4]); 00979 rtp->rtcp->themrxlsr = ((ntohl(rtcpheader[i]) & 0x0000ffff) << 16) | ((ntohl(rtcpheader[i + 1]) & 0xffff0000) >> 16); /* Going to LSR in RR*/ 00980 00981 if (rtcp_debug_test_addr(&sin)) { 00982 ast_verbose("NTP timestamp: %lu.%010lu\n", (unsigned long) ntohl(rtcpheader[i]), (unsigned long) ntohl(rtcpheader[i + 1]) * 4096); 00983 ast_verbose("RTP timestamp: %lu\n", (unsigned long) ntohl(rtcpheader[i + 2])); 00984 ast_verbose("SPC: %lu\tSOC: %lu\n", (unsigned long) ntohl(rtcpheader[i + 3]), (unsigned long) ntohl(rtcpheader[i + 4])); 00985 } 00986 i += 5; 00987 if (rc < 1) 00988 break; 00989 /* Intentional fall through */ 00990 case RTCP_PT_RR: 00991 /* Don't handle multiple reception reports (rc > 1) yet */ 00992 /* Calculate RTT per RFC */ 00993 gettimeofday(&now, NULL); 00994 timeval2ntp(now, &msw, &lsw); 00995 if (ntohl(rtcpheader[i + 4]) && ntohl(rtcpheader[i + 5])) { /* We must have the LSR && DLSR */ 00996 comp = ((msw & 0xffff) << 16) | ((lsw & 0xffff0000) >> 16); 00997 lsr = ntohl(rtcpheader[i + 4]); 00998 dlsr = ntohl(rtcpheader[i + 5]); 00999 rtt = comp - lsr - dlsr; 01000 01001 /* Convert end to end delay to usec (keeping the calculation in 64bit space) 01002 sess->ee_delay = (eedelay * 1000) / 65536; */ 01003 if (rtt < 4294) { 01004 rtt = (rtt * 1000000) >> 16; 01005 } else { 01006 rtt = (rtt * 1000) >> 16; 01007 rtt *= 1000; 01008 } 01009 rtt = rtt / 1000.; 01010 rttsec = rtt / 1000.; 01011 01012 if (comp - dlsr >= lsr) { 01013 rtp->rtcp->accumulated_transit += rttsec; 01014 rtp->rtcp->rtt = rttsec; 01015 if (rtp->rtcp->maxrtt<rttsec) 01016 rtp->rtcp->maxrtt = rttsec; 01017 if (rtp->rtcp->minrtt>rttsec) 01018 rtp->rtcp->minrtt = rttsec; 01019 } else if (rtcp_debug_test_addr(&sin)) { 01020 ast_verbose("Internal RTCP NTP clock skew detected: " 01021 "lsr=%u, now=%u, dlsr=%u (%d:%03dms), " 01022 "diff=%d\n", 01023 lsr, comp, dlsr, dlsr / 65536, 01024 (dlsr % 65536) * 1000 / 65536, 01025 dlsr - (comp - lsr)); 01026 } 01027 } 01028 01029 rtp->rtcp->reported_jitter = ntohl(rtcpheader[i + 3]); 01030 rtp->rtcp->reported_lost = ntohl(rtcpheader[i + 1]) & 0xffffff; 01031 if (rtcp_debug_test_addr(&sin)) { 01032 ast_verbose(" Fraction lost: %ld\n", (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24)); 01033 ast_verbose(" Packets lost so far: %d\n", rtp->rtcp->reported_lost); 01034 ast_verbose(" Highest sequence number: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff)); 01035 ast_verbose(" Sequence number cycles: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16); 01036 ast_verbose(" Interarrival jitter: %u\n", rtp->rtcp->reported_jitter); 01037 ast_verbose(" Last SR(our NTP): %lu.%010lu\n",(unsigned long) ntohl(rtcpheader[i + 4]) >> 16,((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096); 01038 ast_verbose(" DLSR: %4.4f (sec)\n",ntohl(rtcpheader[i + 5])/65536.0); 01039 if (rtt) 01040 ast_verbose(" RTT: %lu(sec)\n", (unsigned long) rtt); 01041 } 01042 break; 01043 case RTCP_PT_FUR: 01044 if (rtcp_debug_test_addr(&sin)) 01045 ast_verbose("Received an RTCP Fast Update Request\n"); 01046 rtp->f.frametype = AST_FRAME_CONTROL; 01047 rtp->f.subclass = AST_CONTROL_VIDUPDATE; 01048 rtp->f.datalen = 0; 01049 rtp->f.samples = 0; 01050 rtp->f.mallocd = 0; 01051 rtp->f.src = "RTP"; 01052 f = &rtp->f; 01053 break; 01054 case RTCP_PT_SDES: 01055 if (rtcp_debug_test_addr(&sin)) 01056 ast_verbose("Received an SDES from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 01057 break; 01058 case RTCP_PT_BYE: 01059 if (rtcp_debug_test_addr(&sin)) 01060 ast_verbose("Received a BYE from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 01061 break; 01062 default: 01063 if (option_debug) 01064 ast_log(LOG_DEBUG, "Unknown RTCP packet (pt=%d) received from %s:%d\n", pt, ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 01065 break; 01066 } 01067 position += (length + 1); 01068 } 01069 01070 return f; 01071 }
int ast_rtcp_send_h261fur | ( | void * | data | ) |
Send an H.261 fast update request. Some devices need this rather than the XML message in SIP.
Definition at line 2510 of file rtp.c.
References ast_rtcp_write(), ast_rtp::rtcp, and ast_rtcp::sendfur.
02511 { 02512 struct ast_rtp *rtp = data; 02513 int res; 02514 02515 rtp->rtcp->sendfur = 1; 02516 res = ast_rtcp_write(data); 02517 02518 return res; 02519 }
size_t ast_rtp_alloc_size | ( | void | ) |
Get the amount of space required to hold an RTP session.
Definition at line 403 of file rtp.c.
Referenced by process_sdp().
00404 { 00405 return sizeof(struct ast_rtp); 00406 }
int ast_rtp_bridge | ( | struct ast_channel * | c0, | |
struct ast_channel * | c1, | |||
int | flags, | |||
struct ast_frame ** | fo, | |||
struct ast_channel ** | rc, | |||
int | timeoutms | |||
) |
Bridge calls. If possible and allowed, initiate re-invite so the peers exchange media directly outside of Asterisk.
Definition at line 3486 of file rtp.c.
References AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_codec_pref_getsize(), ast_log(), AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, AST_RTP_TRY_PARTIAL, ast_set_flag, ast_test_flag, ast_verbose(), bridge_native_loop(), bridge_p2p_loop(), ast_format_list::cur_ms, FLAG_HAS_DTMF, FLAG_P2P_NEED_DTMF, ast_rtp_protocol::get_codec, get_proto(), ast_rtp_protocol::get_rtp_info, ast_rtp_protocol::get_vrtp_info, LOG_WARNING, ast_channel::name, option_debug, option_verbose, ast_rtp::pref, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel_tech::send_digit_begin, ast_channel::tech, ast_channel::tech_pvt, and VERBOSE_PREFIX_3.
03487 { 03488 struct ast_rtp *p0 = NULL, *p1 = NULL; /* Audio RTP Channels */ 03489 struct ast_rtp *vp0 = NULL, *vp1 = NULL; /* Video RTP channels */ 03490 struct ast_rtp_protocol *pr0 = NULL, *pr1 = NULL; 03491 enum ast_rtp_get_result audio_p0_res = AST_RTP_GET_FAILED, video_p0_res = AST_RTP_GET_FAILED; 03492 enum ast_rtp_get_result audio_p1_res = AST_RTP_GET_FAILED, video_p1_res = AST_RTP_GET_FAILED; 03493 enum ast_bridge_result res = AST_BRIDGE_FAILED; 03494 int codec0 = 0, codec1 = 0; 03495 void *pvt0 = NULL, *pvt1 = NULL; 03496 03497 /* Lock channels */ 03498 ast_channel_lock(c0); 03499 while(ast_channel_trylock(c1)) { 03500 ast_channel_unlock(c0); 03501 usleep(1); 03502 ast_channel_lock(c0); 03503 } 03504 03505 /* Ensure neither channel got hungup during lock avoidance */ 03506 if (ast_check_hangup(c0) || ast_check_hangup(c1)) { 03507 ast_log(LOG_WARNING, "Got hangup while attempting to bridge '%s' and '%s'\n", c0->name, c1->name); 03508 ast_channel_unlock(c0); 03509 ast_channel_unlock(c1); 03510 return AST_BRIDGE_FAILED; 03511 } 03512 03513 /* Find channel driver interfaces */ 03514 if (!(pr0 = get_proto(c0))) { 03515 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name); 03516 ast_channel_unlock(c0); 03517 ast_channel_unlock(c1); 03518 return AST_BRIDGE_FAILED; 03519 } 03520 if (!(pr1 = get_proto(c1))) { 03521 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name); 03522 ast_channel_unlock(c0); 03523 ast_channel_unlock(c1); 03524 return AST_BRIDGE_FAILED; 03525 } 03526 03527 /* Get channel specific interface structures */ 03528 pvt0 = c0->tech_pvt; 03529 pvt1 = c1->tech_pvt; 03530 03531 /* Get audio and video interface (if native bridge is possible) */ 03532 audio_p0_res = pr0->get_rtp_info(c0, &p0); 03533 video_p0_res = pr0->get_vrtp_info ? pr0->get_vrtp_info(c0, &vp0) : AST_RTP_GET_FAILED; 03534 audio_p1_res = pr1->get_rtp_info(c1, &p1); 03535 video_p1_res = pr1->get_vrtp_info ? pr1->get_vrtp_info(c1, &vp1) : AST_RTP_GET_FAILED; 03536 03537 /* If we are carrying video, and both sides are not reinviting... then fail the native bridge */ 03538 if (video_p0_res != AST_RTP_GET_FAILED && (audio_p0_res != AST_RTP_TRY_NATIVE || video_p0_res != AST_RTP_TRY_NATIVE)) 03539 audio_p0_res = AST_RTP_GET_FAILED; 03540 if (video_p1_res != AST_RTP_GET_FAILED && (audio_p1_res != AST_RTP_TRY_NATIVE || video_p1_res != AST_RTP_TRY_NATIVE)) 03541 audio_p1_res = AST_RTP_GET_FAILED; 03542 03543 /* Check if a bridge is possible (partial/native) */ 03544 if (audio_p0_res == AST_RTP_GET_FAILED || audio_p1_res == AST_RTP_GET_FAILED) { 03545 /* Somebody doesn't want to play... */ 03546 ast_channel_unlock(c0); 03547 ast_channel_unlock(c1); 03548 return AST_BRIDGE_FAILED_NOWARN; 03549 } 03550 03551 /* If we need to feed DTMF frames into the core then only do a partial native bridge */ 03552 if (ast_test_flag(p0, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) { 03553 ast_set_flag(p0, FLAG_P2P_NEED_DTMF); 03554 audio_p0_res = AST_RTP_TRY_PARTIAL; 03555 } 03556 03557 if (ast_test_flag(p1, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)) { 03558 ast_set_flag(p1, FLAG_P2P_NEED_DTMF); 03559 audio_p1_res = AST_RTP_TRY_PARTIAL; 03560 } 03561 03562 /* If both sides are not using the same method of DTMF transmission 03563 * (ie: one is RFC2833, other is INFO... then we can not do direct media. 03564 * -------------------------------------------------- 03565 * | DTMF Mode | HAS_DTMF | Accepts Begin Frames | 03566 * |-----------|------------|-----------------------| 03567 * | Inband | False | True | 03568 * | RFC2833 | True | True | 03569 * | SIP INFO | False | False | 03570 * -------------------------------------------------- 03571 * However, if DTMF from both channels is being monitored by the core, then 03572 * we can still do packet-to-packet bridging, because passing through the 03573 * core will handle DTMF mode translation. 03574 */ 03575 if ( (ast_test_flag(p0, FLAG_HAS_DTMF) != ast_test_flag(p1, FLAG_HAS_DTMF)) || 03576 (!c0->tech->send_digit_begin != !c1->tech->send_digit_begin)) { 03577 if (!ast_test_flag(p0, FLAG_P2P_NEED_DTMF) || !ast_test_flag(p1, FLAG_P2P_NEED_DTMF)) { 03578 ast_channel_unlock(c0); 03579 ast_channel_unlock(c1); 03580 return AST_BRIDGE_FAILED_NOWARN; 03581 } 03582 audio_p0_res = AST_RTP_TRY_PARTIAL; 03583 audio_p1_res = AST_RTP_TRY_PARTIAL; 03584 } 03585 03586 /* If we need to feed frames into the core don't do a P2P bridge */ 03587 if ((audio_p0_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p0, FLAG_P2P_NEED_DTMF)) || 03588 (audio_p1_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p1, FLAG_P2P_NEED_DTMF))) { 03589 ast_channel_unlock(c0); 03590 ast_channel_unlock(c1); 03591 return AST_BRIDGE_FAILED_NOWARN; 03592 } 03593 03594 /* Get codecs from both sides */ 03595 codec0 = pr0->get_codec ? pr0->get_codec(c0) : 0; 03596 codec1 = pr1->get_codec ? pr1->get_codec(c1) : 0; 03597 if (codec0 && codec1 && !(codec0 & codec1)) { 03598 /* Hey, we can't do native bridging if both parties speak different codecs */ 03599 if (option_debug) 03600 ast_log(LOG_DEBUG, "Channel codec0 = %d is not codec1 = %d, cannot native bridge in RTP.\n", codec0, codec1); 03601 ast_channel_unlock(c0); 03602 ast_channel_unlock(c1); 03603 return AST_BRIDGE_FAILED_NOWARN; 03604 } 03605 03606 /* If either side can only do a partial bridge, then don't try for a true native bridge */ 03607 if (audio_p0_res == AST_RTP_TRY_PARTIAL || audio_p1_res == AST_RTP_TRY_PARTIAL) { 03608 struct ast_format_list fmt0, fmt1; 03609 03610 /* In order to do Packet2Packet bridging both sides must be in the same rawread/rawwrite */ 03611 if (c0->rawreadformat != c1->rawwriteformat || c1->rawreadformat != c0->rawwriteformat) { 03612 if (option_debug) 03613 ast_log(LOG_DEBUG, "Cannot packet2packet bridge - raw formats are incompatible\n"); 03614 ast_channel_unlock(c0); 03615 ast_channel_unlock(c1); 03616 return AST_BRIDGE_FAILED_NOWARN; 03617 } 03618 /* They must also be using the same packetization */ 03619 fmt0 = ast_codec_pref_getsize(&p0->pref, c0->rawreadformat); 03620 fmt1 = ast_codec_pref_getsize(&p1->pref, c1->rawreadformat); 03621 if (fmt0.cur_ms != fmt1.cur_ms) { 03622 if (option_debug) 03623 ast_log(LOG_DEBUG, "Cannot packet2packet bridge - packetization settings prevent it\n"); 03624 ast_channel_unlock(c0); 03625 ast_channel_unlock(c1); 03626 return AST_BRIDGE_FAILED_NOWARN; 03627 } 03628 03629 if (option_verbose > 2) 03630 ast_verbose(VERBOSE_PREFIX_3 "Packet2Packet bridging %s and %s\n", c0->name, c1->name); 03631 res = bridge_p2p_loop(c0, c1, p0, p1, timeoutms, flags, fo, rc, pvt0, pvt1); 03632 } else { 03633 if (option_verbose > 2) 03634 ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s\n", c0->name, c1->name); 03635 res = bridge_native_loop(c0, c1, p0, p1, vp0, vp1, pr0, pr1, codec0, codec1, timeoutms, flags, fo, rc, pvt0, pvt1); 03636 } 03637 03638 return res; 03639 }
void ast_rtp_change_source | ( | struct ast_rtp * | rtp | ) |
Indicate that we need to set the marker bit and change the ssrc.
Definition at line 2138 of file rtp.c.
References ast_log(), ast_random(), LOG_DEBUG, option_debug, ast_rtp::set_marker_bit, and ast_rtp::ssrc.
Referenced by mgcp_indicate(), oh323_indicate(), sip_indicate(), and skinny_indicate().
02139 { 02140 if (rtp) { 02141 unsigned int ssrc = ast_random(); 02142 02143 rtp->set_marker_bit = 1; 02144 if (option_debug > 2) { 02145 ast_log(LOG_DEBUG, "Changing ssrc from %u to %u due to a source change\n", rtp->ssrc, ssrc); 02146 } 02147 rtp->ssrc = ssrc; 02148 } 02149 }
int ast_rtp_codec_getformat | ( | int | pt | ) |
Definition at line 2938 of file rtp.c.
References rtpPayloadType::code, and static_RTP_PT.
Referenced by process_sdp_a_audio().
02939 { 02940 if (pt < 0 || pt >= MAX_RTP_PT) 02941 return 0; /* bogus payload type */ 02942 02943 if (static_RTP_PT[pt].isAstFormat) 02944 return static_RTP_PT[pt].code; 02945 else 02946 return 0; 02947 }
struct ast_codec_pref* ast_rtp_codec_getpref | ( | struct ast_rtp * | rtp | ) |
Definition at line 2933 of file rtp.c.
References ast_rtp::pref.
Referenced by add_codec_to_sdp(), and process_sdp_a_audio().
02934 { 02935 return &rtp->pref; 02936 }
int ast_rtp_codec_setpref | ( | struct ast_rtp * | rtp, | |
struct ast_codec_pref * | prefs | |||
) |
Definition at line 2886 of file rtp.c.
References ast_codec_pref_getsize(), ast_log(), ast_smoother_new(), ast_smoother_reconfigure(), ast_smoother_set_flags(), ast_format_list::cur_ms, ast_format_list::flags, ast_format_list::fr_len, ast_format_list::inc_ms, ast_rtp::lasttxformat, LOG_DEBUG, LOG_WARNING, option_debug, ast_rtp::pref, prefs, and ast_rtp::smoother.
Referenced by __oh323_rtp_create(), check_user_full(), create_addr_from_peer(), process_sdp_a_audio(), register_verify(), set_peer_capabilities(), sip_alloc(), start_rtp(), and transmit_response_with_sdp().
02887 { 02888 struct ast_format_list current_format_old, current_format_new; 02889 02890 /* if no packets have been sent through this session yet, then 02891 * changing preferences does not require any extra work 02892 */ 02893 if (rtp->lasttxformat == 0) { 02894 rtp->pref = *prefs; 02895 return 0; 02896 } 02897 02898 current_format_old = ast_codec_pref_getsize(&rtp->pref, rtp->lasttxformat); 02899 02900 rtp->pref = *prefs; 02901 02902 current_format_new = ast_codec_pref_getsize(&rtp->pref, rtp->lasttxformat); 02903 02904 /* if the framing desired for the current format has changed, we may have to create 02905 * or adjust the smoother for this session 02906 */ 02907 if ((current_format_new.inc_ms != 0) && 02908 (current_format_new.cur_ms != current_format_old.cur_ms)) { 02909 int new_size = (current_format_new.cur_ms * current_format_new.fr_len) / current_format_new.inc_ms; 02910 02911 if (rtp->smoother) { 02912 ast_smoother_reconfigure(rtp->smoother, new_size); 02913 if (option_debug) { 02914 ast_log(LOG_DEBUG, "Adjusted smoother to %d ms and %d bytes\n", current_format_new.cur_ms, new_size); 02915 } 02916 } else { 02917 if (!(rtp->smoother = ast_smoother_new(new_size))) { 02918 ast_log(LOG_WARNING, "Unable to create smoother: format: %d ms: %d len: %d\n", rtp->lasttxformat, current_format_new.cur_ms, new_size); 02919 return -1; 02920 } 02921 if (current_format_new.flags) { 02922 ast_smoother_set_flags(rtp->smoother, current_format_new.flags); 02923 } 02924 if (option_debug) { 02925 ast_log(LOG_DEBUG, "Created smoother: format: %d ms: %d len: %d\n", rtp->lasttxformat, current_format_new.cur_ms, new_size); 02926 } 02927 } 02928 } 02929 02930 return 0; 02931 }
void ast_rtp_destroy | ( | struct ast_rtp * | rtp | ) |
Definition at line 2280 of file rtp.c.
References ast_io_remove(), ast_mutex_destroy(), AST_SCHED_DEL, ast_smoother_free(), ast_verbose(), ast_rtp::bridge_lock, ast_rtcp::expected_prior, free, ast_rtp::io, ast_rtp::ioid, ast_rtcp::received_prior, ast_rtcp::reported_jitter, ast_rtcp::reported_lost, ast_rtcp::rr_count, ast_rtp::rtcp, rtcp_debug_test_addr(), ast_rtcp::rtt, ast_rtp::rxcount, ast_rtp::rxjitter, ast_rtp::rxtransit, ast_rtcp::s, ast_rtp::s, ast_rtp::sched, ast_rtcp::schedid, ast_rtp::smoother, ast_rtcp::sr_count, ast_rtp::ssrc, ast_rtp::them, ast_rtp::themssrc, and ast_rtp::txcount.
Referenced by __oh323_destroy(), __sip_destroy(), check_user_full(), cleanup_connection(), create_addr_from_peer(), destroy_endpoint(), gtalk_free_pvt(), mgcp_hangup(), oh323_alloc(), sip_alloc(), skinny_hangup(), start_rtp(), and unalloc_sub().
02281 { 02282 if (rtcp_debug_test_addr(&rtp->them) || rtcpstats) { 02283 /*Print some info on the call here */ 02284 ast_verbose(" RTP-stats\n"); 02285 ast_verbose("* Our Receiver:\n"); 02286 ast_verbose(" SSRC: %u\n", rtp->themssrc); 02287 ast_verbose(" Received packets: %u\n", rtp->rxcount); 02288 ast_verbose(" Lost packets: %u\n", rtp->rtcp ? (rtp->rtcp->expected_prior - rtp->rtcp->received_prior) : 0); 02289 ast_verbose(" Jitter: %.4f\n", rtp->rxjitter); 02290 ast_verbose(" Transit: %.4f\n", rtp->rxtransit); 02291 ast_verbose(" RR-count: %u\n", rtp->rtcp ? rtp->rtcp->rr_count : 0); 02292 ast_verbose("* Our Sender:\n"); 02293 ast_verbose(" SSRC: %u\n", rtp->ssrc); 02294 ast_verbose(" Sent packets: %u\n", rtp->txcount); 02295 ast_verbose(" Lost packets: %u\n", rtp->rtcp ? rtp->rtcp->reported_lost : 0); 02296 ast_verbose(" Jitter: %u\n", rtp->rtcp ? (rtp->rtcp->reported_jitter / (unsigned int)65536.0) : 0); 02297 ast_verbose(" SR-count: %u\n", rtp->rtcp ? rtp->rtcp->sr_count : 0); 02298 ast_verbose(" RTT: %f\n", rtp->rtcp ? rtp->rtcp->rtt : 0); 02299 } 02300 02301 if (rtp->smoother) 02302 ast_smoother_free(rtp->smoother); 02303 if (rtp->ioid) 02304 ast_io_remove(rtp->io, rtp->ioid); 02305 if (rtp->s > -1) 02306 close(rtp->s); 02307 if (rtp->rtcp) { 02308 AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid); 02309 close(rtp->rtcp->s); 02310 free(rtp->rtcp); 02311 rtp->rtcp=NULL; 02312 } 02313 02314 ast_mutex_destroy(&rtp->bridge_lock); 02315 02316 free(rtp); 02317 }
int ast_rtp_early_bridge | ( | struct ast_channel * | dest, | |
struct ast_channel * | src | |||
) |
If possible, create an early bridge directly between the devices without having to send a re-invite later.
Definition at line 1597 of file rtp.c.
References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_log(), AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, ast_test_flag, FLAG_NAT_ACTIVE, ast_rtp_protocol::get_codec, get_proto(), ast_rtp_protocol::get_rtp_info, ast_rtp_protocol::get_vrtp_info, LOG_DEBUG, LOG_WARNING, ast_channel::name, option_debug, and ast_rtp_protocol::set_rtp_peer.
Referenced by wait_for_answer().
01598 { 01599 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 01600 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 01601 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 01602 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED; 01603 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED; 01604 int srccodec, destcodec, nat_active = 0; 01605 01606 /* Lock channels */ 01607 ast_channel_lock(dest); 01608 if (src) { 01609 while(ast_channel_trylock(src)) { 01610 ast_channel_unlock(dest); 01611 usleep(1); 01612 ast_channel_lock(dest); 01613 } 01614 } 01615 01616 /* Find channel driver interfaces */ 01617 destpr = get_proto(dest); 01618 if (src) 01619 srcpr = get_proto(src); 01620 if (!destpr) { 01621 if (option_debug) 01622 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name); 01623 ast_channel_unlock(dest); 01624 if (src) 01625 ast_channel_unlock(src); 01626 return 0; 01627 } 01628 if (!srcpr) { 01629 if (option_debug) 01630 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src ? src->name : "<unspecified>"); 01631 ast_channel_unlock(dest); 01632 if (src) 01633 ast_channel_unlock(src); 01634 return 0; 01635 } 01636 01637 /* Get audio and video interface (if native bridge is possible) */ 01638 audio_dest_res = destpr->get_rtp_info(dest, &destp); 01639 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 01640 if (srcpr) { 01641 audio_src_res = srcpr->get_rtp_info(src, &srcp); 01642 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 01643 } 01644 01645 /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */ 01646 if (audio_dest_res != AST_RTP_TRY_NATIVE || (video_dest_res != AST_RTP_GET_FAILED && video_dest_res != AST_RTP_TRY_NATIVE)) { 01647 /* Somebody doesn't want to play... */ 01648 ast_channel_unlock(dest); 01649 if (src) 01650 ast_channel_unlock(src); 01651 return 0; 01652 } 01653 if (audio_src_res == AST_RTP_TRY_NATIVE && (video_src_res == AST_RTP_GET_FAILED || video_src_res == AST_RTP_TRY_NATIVE) && srcpr->get_codec) 01654 srccodec = srcpr->get_codec(src); 01655 else 01656 srccodec = 0; 01657 if (audio_dest_res == AST_RTP_TRY_NATIVE && (video_dest_res == AST_RTP_GET_FAILED || video_dest_res == AST_RTP_TRY_NATIVE) && destpr->get_codec) 01658 destcodec = destpr->get_codec(dest); 01659 else 01660 destcodec = 0; 01661 /* Ensure we have at least one matching codec */ 01662 if (srcp && !(srccodec & destcodec)) { 01663 ast_channel_unlock(dest); 01664 ast_channel_unlock(src); 01665 return 0; 01666 } 01667 /* Consider empty media as non-existant */ 01668 if (audio_src_res == AST_RTP_TRY_NATIVE && !srcp->them.sin_addr.s_addr) 01669 srcp = NULL; 01670 /* If the client has NAT stuff turned on then just safe NAT is active */ 01671 if (srcp && (srcp->nat || ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 01672 nat_active = 1; 01673 /* Bridge media early */ 01674 if (destpr->set_rtp_peer(dest, srcp, vsrcp, srccodec, nat_active)) 01675 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src ? src->name : "<unspecified>"); 01676 ast_channel_unlock(dest); 01677 if (src) 01678 ast_channel_unlock(src); 01679 if (option_debug) 01680 ast_log(LOG_DEBUG, "Setting early bridge SDP of '%s' with that of '%s'\n", dest->name, src ? src->name : "<unspecified>"); 01681 return 1; 01682 }
int ast_rtp_fd | ( | struct ast_rtp * | rtp | ) |
Definition at line 518 of file rtp.c.
References ast_rtp::s.
Referenced by __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), gtalk_new(), mgcp_new(), sip_new(), skinny_new(), and start_rtp().
00519 { 00520 return rtp->s; 00521 }
Definition at line 2190 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, and ast_rtp::bridged.
Referenced by __sip_destroy(), and ast_rtp_read().
02191 { 02192 struct ast_rtp *bridged = NULL; 02193 02194 ast_mutex_lock(&rtp->bridge_lock); 02195 bridged = rtp->bridged; 02196 ast_mutex_unlock(&rtp->bridge_lock); 02197 02198 return bridged; 02199 }
void ast_rtp_get_current_formats | ( | struct ast_rtp * | rtp, | |
int * | astFormats, | |||
int * | nonAstFormats | |||
) |
Return the union of all of the codecs that were set by rtp_set...() calls They're returned as two distinct sets: AST_FORMATs, and AST_RTPs.
Definition at line 1818 of file rtp.c.
References ast_mutex_lock(), ast_rtp::bridge_lock, rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, and MAX_RTP_PT.
Referenced by gtalk_is_answered(), gtalk_newcall(), and process_sdp().
01820 { 01821 int pt; 01822 01823 ast_mutex_lock(&rtp->bridge_lock); 01824 01825 *astFormats = *nonAstFormats = 0; 01826 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01827 if (rtp->current_RTP_PT[pt].isAstFormat) { 01828 *astFormats |= rtp->current_RTP_PT[pt].code; 01829 } else { 01830 *nonAstFormats |= rtp->current_RTP_PT[pt].code; 01831 } 01832 } 01833 01834 ast_mutex_unlock(&rtp->bridge_lock); 01835 01836 return; 01837 }
int ast_rtp_get_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | them | |||
) |
Definition at line 2172 of file rtp.c.
References ast_rtp::them.
Referenced by add_sdp(), bridge_native_loop(), do_monitor(), gtalk_update_stun(), oh323_set_rtp_peer(), process_sdp(), sip_set_rtp_peer(), and transmit_modify_with_sdp().
02173 { 02174 if ((them->sin_family != AF_INET) || 02175 (them->sin_port != rtp->them.sin_port) || 02176 (them->sin_addr.s_addr != rtp->them.sin_addr.s_addr)) { 02177 them->sin_family = AF_INET; 02178 them->sin_port = rtp->them.sin_port; 02179 them->sin_addr = rtp->them.sin_addr; 02180 return 1; 02181 } 02182 return 0; 02183 }
char* ast_rtp_get_quality | ( | struct ast_rtp * | rtp, | |
struct ast_rtp_quality * | qual | |||
) |
Return RTCP quality string.
Definition at line 2236 of file rtp.c.
References ast_rtcp::expected_prior, ast_rtp_quality::local_count, ast_rtp_quality::local_jitter, ast_rtp_quality::local_lostpackets, ast_rtp_quality::local_ssrc, ast_rtcp::quality, ast_rtcp::received_prior, ast_rtp_quality::remote_count, ast_rtp_quality::remote_jitter, ast_rtp_quality::remote_lostpackets, ast_rtp_quality::remote_ssrc, ast_rtcp::reported_jitter, ast_rtcp::reported_lost, ast_rtp::rtcp, ast_rtcp::rtt, ast_rtp_quality::rtt, ast_rtp::rxcount, ast_rtp::rxjitter, ast_rtp::ssrc, ast_rtp::themssrc, and ast_rtp::txcount.
Referenced by acf_channel_read(), handle_request_bye(), and sip_hangup().
02237 { 02238 /* 02239 *ssrc our ssrc 02240 *themssrc their ssrc 02241 *lp lost packets 02242 *rxjitter our calculated jitter(rx) 02243 *rxcount no. received packets 02244 *txjitter reported jitter of the other end 02245 *txcount transmitted packets 02246 *rlp remote lost packets 02247 *rtt round trip time 02248 */ 02249 02250 if (qual && rtp) { 02251 qual->local_ssrc = rtp->ssrc; 02252 qual->local_jitter = rtp->rxjitter; 02253 qual->local_count = rtp->rxcount; 02254 qual->remote_ssrc = rtp->themssrc; 02255 qual->remote_count = rtp->txcount; 02256 if (rtp->rtcp) { 02257 qual->local_lostpackets = rtp->rtcp->expected_prior - rtp->rtcp->received_prior; 02258 qual->remote_lostpackets = rtp->rtcp->reported_lost; 02259 qual->remote_jitter = rtp->rtcp->reported_jitter / 65536.0; 02260 qual->rtt = rtp->rtcp->rtt; 02261 } 02262 } 02263 if (rtp->rtcp) { 02264 snprintf(rtp->rtcp->quality, sizeof(rtp->rtcp->quality), 02265 "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;txjitter=%f;txcount=%u;rlp=%u;rtt=%f", 02266 rtp->ssrc, 02267 rtp->themssrc, 02268 rtp->rtcp->expected_prior - rtp->rtcp->received_prior, 02269 rtp->rxjitter, 02270 rtp->rxcount, 02271 (double)rtp->rtcp->reported_jitter / 65536.0, 02272 rtp->txcount, 02273 rtp->rtcp->reported_lost, 02274 rtp->rtcp->rtt); 02275 return rtp->rtcp->quality; 02276 } else 02277 return "<Unknown> - RTP/RTCP has already been destroyed"; 02278 }
int ast_rtp_get_rtpholdtimeout | ( | struct ast_rtp * | rtp | ) |
Get rtp hold timeout.
Definition at line 578 of file rtp.c.
References ast_rtp::rtpholdtimeout, and ast_rtp::rtptimeout.
Referenced by do_monitor().
00579 { 00580 if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */ 00581 return 0; 00582 return rtp->rtpholdtimeout; 00583 }
int ast_rtp_get_rtpkeepalive | ( | struct ast_rtp * | rtp | ) |
Get RTP keepalive interval.
Definition at line 586 of file rtp.c.
References ast_rtp::rtpkeepalive.
Referenced by do_monitor().
00587 { 00588 return rtp->rtpkeepalive; 00589 }
int ast_rtp_get_rtptimeout | ( | struct ast_rtp * | rtp | ) |
Get rtp timeout.
Definition at line 570 of file rtp.c.
References ast_rtp::rtptimeout.
Referenced by do_monitor().
00571 { 00572 if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */ 00573 return 0; 00574 return rtp->rtptimeout; 00575 }
void ast_rtp_get_us | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | us | |||
) |
Definition at line 2185 of file rtp.c.
References ast_rtp::us.
Referenced by add_sdp(), external_rtp_create(), gtalk_create_candidates(), handle_open_receive_channel_ack_message(), and oh323_set_rtp_peer().
int ast_rtp_getnat | ( | struct ast_rtp * | rtp | ) |
Definition at line 606 of file rtp.c.
References ast_test_flag, and FLAG_NAT_ACTIVE.
Referenced by sip_get_rtp_peer().
00607 { 00608 return ast_test_flag(rtp, FLAG_NAT_ACTIVE); 00609 }
void ast_rtp_init | ( | void | ) |
Initialize the RTP system in Asterisk.
Definition at line 4024 of file rtp.c.
References ast_cli_register_multiple(), ast_rtp_reload(), and cli_rtp.
Referenced by main().
04025 { 04026 ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry)); 04027 ast_rtp_reload(); 04028 }
int ast_rtp_lookup_code | ( | struct ast_rtp * | rtp, | |
int | isAstFormat, | |||
int | code | |||
) |
Looks up an RTP code out of our *static* outbound list.
Definition at line 1861 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, ast_rtp::rtp_lookup_code_cache_code, ast_rtp::rtp_lookup_code_cache_isAstFormat, and ast_rtp::rtp_lookup_code_cache_result.
Referenced by add_codec_to_answer(), add_codec_to_sdp(), add_noncodec_to_sdp(), add_sdp(), ast_rtp_sendcng(), ast_rtp_senddigit_begin(), ast_rtp_write(), and bridge_p2p_rtp_write().
01862 { 01863 int pt = 0; 01864 01865 ast_mutex_lock(&rtp->bridge_lock); 01866 01867 if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && 01868 code == rtp->rtp_lookup_code_cache_code) { 01869 /* Use our cached mapping, to avoid the overhead of the loop below */ 01870 pt = rtp->rtp_lookup_code_cache_result; 01871 ast_mutex_unlock(&rtp->bridge_lock); 01872 return pt; 01873 } 01874 01875 /* Check the dynamic list first */ 01876 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01877 if (rtp->current_RTP_PT[pt].code == code && rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) { 01878 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 01879 rtp->rtp_lookup_code_cache_code = code; 01880 rtp->rtp_lookup_code_cache_result = pt; 01881 ast_mutex_unlock(&rtp->bridge_lock); 01882 return pt; 01883 } 01884 } 01885 01886 /* Then the static list */ 01887 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01888 if (static_RTP_PT[pt].code == code && static_RTP_PT[pt].isAstFormat == isAstFormat) { 01889 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 01890 rtp->rtp_lookup_code_cache_code = code; 01891 rtp->rtp_lookup_code_cache_result = pt; 01892 ast_mutex_unlock(&rtp->bridge_lock); 01893 return pt; 01894 } 01895 } 01896 01897 ast_mutex_unlock(&rtp->bridge_lock); 01898 01899 return -1; 01900 }
char* ast_rtp_lookup_mime_multiple | ( | char * | buf, | |
size_t | size, | |||
const int | capability, | |||
const int | isAstFormat, | |||
enum ast_rtp_options | options | |||
) |
Build a string of MIME subtype names from a capability list.
Definition at line 1921 of file rtp.c.
References ast_rtp_lookup_mime_subtype(), AST_RTP_MAX, format, len(), and name.
Referenced by process_sdp().
01923 { 01924 int format; 01925 unsigned len; 01926 char *end = buf; 01927 char *start = buf; 01928 01929 if (!buf || !size) 01930 return NULL; 01931 01932 snprintf(end, size, "0x%x (", capability); 01933 01934 len = strlen(end); 01935 end += len; 01936 size -= len; 01937 start = end; 01938 01939 for (format = 1; format < AST_RTP_MAX; format <<= 1) { 01940 if (capability & format) { 01941 const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format, options); 01942 01943 snprintf(end, size, "%s|", name); 01944 len = strlen(end); 01945 end += len; 01946 size -= len; 01947 } 01948 } 01949 01950 if (start == end) 01951 snprintf(start, size, "nothing)"); 01952 else if (size > 1) 01953 *(end -1) = ')'; 01954 01955 return buf; 01956 }
const char* ast_rtp_lookup_mime_subtype | ( | int | isAstFormat, | |
int | code, | |||
enum ast_rtp_options | options | |||
) |
Mapping an Asterisk code into a MIME subtype (string):.
Definition at line 1902 of file rtp.c.
References AST_FORMAT_G726_AAL2, AST_RTP_OPT_G726_NONSTANDARD, rtpPayloadType::code, mimeTypes, and payloadType.
Referenced by add_codec_to_sdp(), add_noncodec_to_sdp(), add_sdp(), ast_rtp_lookup_mime_multiple(), transmit_connect_with_sdp(), and transmit_modify_with_sdp().
01904 { 01905 unsigned int i; 01906 01907 for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { 01908 if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) { 01909 if (isAstFormat && 01910 (code == AST_FORMAT_G726_AAL2) && 01911 (options & AST_RTP_OPT_G726_NONSTANDARD)) 01912 return "G726-32"; 01913 else 01914 return mimeTypes[i].subtype; 01915 } 01916 } 01917 01918 return ""; 01919 }
struct rtpPayloadType ast_rtp_lookup_pt | ( | struct ast_rtp * | rtp, | |
int | pt | |||
) |
Mapping between RTP payload format codes and Asterisk codes:.
Definition at line 1839 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), rtpPayloadType::isAstFormat, MAX_RTP_PT, and static_RTP_PT.
Referenced by ast_rtp_read(), bridge_p2p_rtp_write(), and setup_rtp_connection().
01840 { 01841 struct rtpPayloadType result; 01842 01843 result.isAstFormat = result.code = 0; 01844 01845 if (pt < 0 || pt >= MAX_RTP_PT) 01846 return result; /* bogus payload type */ 01847 01848 /* Start with negotiated codecs */ 01849 ast_mutex_lock(&rtp->bridge_lock); 01850 result = rtp->current_RTP_PT[pt]; 01851 ast_mutex_unlock(&rtp->bridge_lock); 01852 01853 /* If it doesn't exist, check our static RTP type list, just in case */ 01854 if (!result.code) 01855 result = static_RTP_PT[pt]; 01856 01857 return result; 01858 }
int ast_rtp_make_compatible | ( | struct ast_channel * | dest, | |
struct ast_channel * | src, | |||
int | media | |||
) |
Definition at line 1684 of file rtp.c.
References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_log(), AST_RTP_GET_FAILED, ast_rtp_pt_copy(), AST_RTP_TRY_NATIVE, ast_test_flag, FLAG_NAT_ACTIVE, ast_rtp_protocol::get_codec, get_proto(), ast_rtp_protocol::get_rtp_info, ast_rtp_protocol::get_vrtp_info, LOG_DEBUG, LOG_WARNING, ast_channel::name, option_debug, and ast_rtp_protocol::set_rtp_peer.
Referenced by wait_for_answer().
01685 { 01686 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 01687 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 01688 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 01689 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED; 01690 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED; 01691 int srccodec, destcodec; 01692 01693 /* Lock channels */ 01694 ast_channel_lock(dest); 01695 while(ast_channel_trylock(src)) { 01696 ast_channel_unlock(dest); 01697 usleep(1); 01698 ast_channel_lock(dest); 01699 } 01700 01701 /* Find channel driver interfaces */ 01702 if (!(destpr = get_proto(dest))) { 01703 if (option_debug) 01704 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name); 01705 ast_channel_unlock(dest); 01706 ast_channel_unlock(src); 01707 return 0; 01708 } 01709 if (!(srcpr = get_proto(src))) { 01710 if (option_debug) 01711 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src->name); 01712 ast_channel_unlock(dest); 01713 ast_channel_unlock(src); 01714 return 0; 01715 } 01716 01717 /* Get audio and video interface (if native bridge is possible) */ 01718 audio_dest_res = destpr->get_rtp_info(dest, &destp); 01719 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 01720 audio_src_res = srcpr->get_rtp_info(src, &srcp); 01721 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 01722 01723 /* Ensure we have at least one matching codec */ 01724 if (srcpr->get_codec) 01725 srccodec = srcpr->get_codec(src); 01726 else 01727 srccodec = 0; 01728 if (destpr->get_codec) 01729 destcodec = destpr->get_codec(dest); 01730 else 01731 destcodec = 0; 01732 01733 /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */ 01734 if (audio_dest_res != AST_RTP_TRY_NATIVE || (video_dest_res != AST_RTP_GET_FAILED && video_dest_res != AST_RTP_TRY_NATIVE) || audio_src_res != AST_RTP_TRY_NATIVE || (video_src_res != AST_RTP_GET_FAILED && video_src_res != AST_RTP_TRY_NATIVE) || !(srccodec & destcodec)) { 01735 /* Somebody doesn't want to play... */ 01736 ast_channel_unlock(dest); 01737 ast_channel_unlock(src); 01738 return 0; 01739 } 01740 ast_rtp_pt_copy(destp, srcp); 01741 if (vdestp && vsrcp) 01742 ast_rtp_pt_copy(vdestp, vsrcp); 01743 if (media) { 01744 /* Bridge early */ 01745 if (destpr->set_rtp_peer(dest, srcp, vsrcp, srccodec, ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 01746 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src->name); 01747 } 01748 ast_channel_unlock(dest); 01749 ast_channel_unlock(src); 01750 if (option_debug) 01751 ast_log(LOG_DEBUG, "Seeded SDP of '%s' with that of '%s'\n", dest->name, src->name); 01752 return 1; 01753 }
struct ast_rtp* ast_rtp_new | ( | struct sched_context * | sched, | |
struct io_context * | io, | |||
int | rtcpenable, | |||
int | callbackmode | |||
) |
Initializate a RTP session.
sched | ||
io | ||
rtcpenable | ||
callbackmode |
Definition at line 2111 of file rtp.c.
References ast_rtp_new_with_bindaddr(), io, and sched.
02112 { 02113 struct in_addr ia; 02114 02115 memset(&ia, 0, sizeof(ia)); 02116 return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia); 02117 }
void ast_rtp_new_init | ( | struct ast_rtp * | rtp | ) |
Initialize a new RTP structure.
Definition at line 2005 of file rtp.c.
References ast_mutex_init(), ast_random(), ast_set_flag, ast_rtp::bridge_lock, FLAG_HAS_DTMF, ast_rtp::seqno, ast_rtp::ssrc, ast_rtp::them, and ast_rtp::us.
Referenced by ast_rtp_new_with_bindaddr(), and process_sdp().
02006 { 02007 ast_mutex_init(&rtp->bridge_lock); 02008 02009 rtp->them.sin_family = AF_INET; 02010 rtp->us.sin_family = AF_INET; 02011 rtp->ssrc = ast_random(); 02012 rtp->seqno = ast_random() & 0xffff; 02013 ast_set_flag(rtp, FLAG_HAS_DTMF); 02014 02015 return; 02016 }
void ast_rtp_new_source | ( | struct ast_rtp * | rtp | ) |
Indicate that we need to set the marker bit.
Definition at line 2128 of file rtp.c.
References ast_log(), LOG_DEBUG, option_debug, and ast_rtp::set_marker_bit.
Referenced by mgcp_indicate(), oh323_indicate(), sip_answer(), sip_indicate(), sip_write(), and skinny_indicate().
02129 { 02130 if (rtp) { 02131 rtp->set_marker_bit = 1; 02132 if (option_debug > 2) { 02133 ast_log(LOG_DEBUG, "Setting the marker bit due to a source update\n"); 02134 } 02135 } 02136 }
struct ast_rtp* ast_rtp_new_with_bindaddr | ( | struct sched_context * | sched, | |
struct io_context * | io, | |||
int | rtcpenable, | |||
int | callbackmode, | |||
struct in_addr | in | |||
) |
Initializate a RTP session using an in_addr structure.
This fuction gets called by ast_rtp_new().
sched | ||
io | ||
rtcpenable | ||
callbackmode | ||
in |
Definition at line 2018 of file rtp.c.
References ast_calloc, ast_log(), ast_random(), ast_rtcp_new(), ast_rtp_new_init(), errno, first, free, LOG_DEBUG, LOG_ERROR, option_debug, rtp_socket(), and sched.
Referenced by __oh323_rtp_create(), ast_rtp_new(), gtalk_alloc(), sip_alloc(), and start_rtp().
02019 { 02020 struct ast_rtp *rtp; 02021 int x; 02022 int first; 02023 int startplace; 02024 02025 if (!(rtp = ast_calloc(1, sizeof(*rtp)))) 02026 return NULL; 02027 02028 ast_rtp_new_init(rtp); 02029 02030 rtp->s = rtp_socket(); 02031 if (option_debug > 2) 02032 ast_log(LOG_DEBUG, "socket RTP fd: %i\n", rtp->s); 02033 if (rtp->s < 0) { 02034 free(rtp); 02035 ast_log(LOG_ERROR, "Unable to allocate socket: %s\n", strerror(errno)); 02036 return NULL; 02037 } 02038 if (sched && rtcpenable) { 02039 rtp->sched = sched; 02040 rtp->rtcp = ast_rtcp_new(); 02041 if (option_debug > 2) 02042 ast_log(LOG_DEBUG, "socket RTCP fd: %i\n", rtp->rtcp->s); 02043 } 02044 02045 /* Select a random port number in the range of possible RTP */ 02046 x = (rtpend == rtpstart) ? rtpstart : (ast_random() % (rtpend - rtpstart)) + rtpstart; 02047 x = x & ~1; 02048 /* Save it for future references. */ 02049 startplace = x; 02050 /* Iterate tring to bind that port and incrementing it otherwise untill a port was found or no ports are available. */ 02051 for (;;) { 02052 /* Must be an even port number by RTP spec */ 02053 rtp->us.sin_port = htons(x); 02054 rtp->us.sin_addr = addr; 02055 /* If there's rtcp, initialize it as well. */ 02056 if (rtp->rtcp) { 02057 rtp->rtcp->us.sin_port = htons(x + 1); 02058 rtp->rtcp->us.sin_addr = addr; 02059 } 02060 /* Try to bind it/them. */ 02061 if (!(first = bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us))) && 02062 (!rtp->rtcp || !bind(rtp->rtcp->s, (struct sockaddr *)&rtp->rtcp->us, sizeof(rtp->rtcp->us)))) 02063 break; 02064 if (!first) { 02065 /* Primary bind succeeded! Gotta recreate it */ 02066 close(rtp->s); 02067 rtp->s = rtp_socket(); 02068 if (option_debug > 2) 02069 ast_log(LOG_DEBUG, "socket RTP2 fd: %i\n", rtp->s); 02070 } 02071 if (errno != EADDRINUSE) { 02072 /* We got an error that wasn't expected, abort! */ 02073 ast_log(LOG_ERROR, "Unexpected bind error: %s\n", strerror(errno)); 02074 close(rtp->s); 02075 if (rtp->rtcp) { 02076 close(rtp->rtcp->s); 02077 free(rtp->rtcp); 02078 } 02079 free(rtp); 02080 return NULL; 02081 } 02082 /* The port was used, increment it (by two). */ 02083 x += 2; 02084 /* Did we go over the limit ? */ 02085 if (x > rtpend) 02086 /* then, start from the begingig. */ 02087 x = (rtpstart + 1) & ~1; 02088 /* Check if we reached the place were we started. */ 02089 if (x == startplace) { 02090 /* If so, there's no ports available. */ 02091 ast_log(LOG_ERROR, "No RTP ports remaining. Can't setup media stream for this call.\n"); 02092 close(rtp->s); 02093 if (rtp->rtcp) { 02094 close(rtp->rtcp->s); 02095 free(rtp->rtcp); 02096 } 02097 free(rtp); 02098 return NULL; 02099 } 02100 } 02101 rtp->sched = sched; 02102 rtp->io = io; 02103 if (callbackmode) { 02104 rtp->ioid = ast_io_add(rtp->io, rtp->s, rtpread, AST_IO_IN, rtp); 02105 ast_set_flag(rtp, FLAG_CALLBACK_MODE); 02106 } 02107 ast_rtp_pt_default(rtp); 02108 return rtp; 02109 }
int ast_rtp_proto_register | ( | struct ast_rtp_protocol * | proto | ) |
Register interface to channel driver.
Definition at line 3040 of file rtp.c.
References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), ast_rtp_protocol::list, LOG_WARNING, and ast_rtp_protocol::type.
Referenced by load_module().
03041 { 03042 struct ast_rtp_protocol *cur; 03043 03044 AST_LIST_LOCK(&protos); 03045 AST_LIST_TRAVERSE(&protos, cur, list) { 03046 if (!strcmp(cur->type, proto->type)) { 03047 ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type); 03048 AST_LIST_UNLOCK(&protos); 03049 return -1; 03050 } 03051 } 03052 AST_LIST_INSERT_HEAD(&protos, proto, list); 03053 AST_LIST_UNLOCK(&protos); 03054 03055 return 0; 03056 }
void ast_rtp_proto_unregister | ( | struct ast_rtp_protocol * | proto | ) |
Unregister interface to channel driver.
Definition at line 3032 of file rtp.c.
References AST_LIST_LOCK, AST_LIST_REMOVE, and AST_LIST_UNLOCK.
Referenced by load_module(), and unload_module().
03033 { 03034 AST_LIST_LOCK(&protos); 03035 AST_LIST_REMOVE(&protos, proto, list); 03036 AST_LIST_UNLOCK(&protos); 03037 }
void ast_rtp_pt_clear | ( | struct ast_rtp * | rtp | ) |
Setting RTP payload types from lines in a SDP description:.
Definition at line 1521 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, ast_rtp::rtp_lookup_code_cache_code, ast_rtp::rtp_lookup_code_cache_isAstFormat, and ast_rtp::rtp_lookup_code_cache_result.
Referenced by gtalk_alloc(), and process_sdp().
01522 { 01523 int i; 01524 01525 if (!rtp) 01526 return; 01527 01528 ast_mutex_lock(&rtp->bridge_lock); 01529 01530 for (i = 0; i < MAX_RTP_PT; ++i) { 01531 rtp->current_RTP_PT[i].isAstFormat = 0; 01532 rtp->current_RTP_PT[i].code = 0; 01533 } 01534 01535 rtp->rtp_lookup_code_cache_isAstFormat = 0; 01536 rtp->rtp_lookup_code_cache_code = 0; 01537 rtp->rtp_lookup_code_cache_result = 0; 01538 01539 ast_mutex_unlock(&rtp->bridge_lock); 01540 }
Copy payload types between RTP structures.
Definition at line 1561 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, ast_rtp::rtp_lookup_code_cache_code, ast_rtp::rtp_lookup_code_cache_isAstFormat, and ast_rtp::rtp_lookup_code_cache_result.
Referenced by ast_rtp_make_compatible(), and process_sdp().
01562 { 01563 unsigned int i; 01564 01565 ast_mutex_lock(&dest->bridge_lock); 01566 ast_mutex_lock(&src->bridge_lock); 01567 01568 for (i=0; i < MAX_RTP_PT; ++i) { 01569 dest->current_RTP_PT[i].isAstFormat = 01570 src->current_RTP_PT[i].isAstFormat; 01571 dest->current_RTP_PT[i].code = 01572 src->current_RTP_PT[i].code; 01573 } 01574 dest->rtp_lookup_code_cache_isAstFormat = 0; 01575 dest->rtp_lookup_code_cache_code = 0; 01576 dest->rtp_lookup_code_cache_result = 0; 01577 01578 ast_mutex_unlock(&src->bridge_lock); 01579 ast_mutex_unlock(&dest->bridge_lock); 01580 }
void ast_rtp_pt_default | ( | struct ast_rtp * | rtp | ) |
Set payload types to defaults.
Definition at line 1542 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, ast_rtp::rtp_lookup_code_cache_code, ast_rtp::rtp_lookup_code_cache_isAstFormat, ast_rtp::rtp_lookup_code_cache_result, and static_RTP_PT.
01543 { 01544 int i; 01545 01546 ast_mutex_lock(&rtp->bridge_lock); 01547 01548 /* Initialize to default payload types */ 01549 for (i = 0; i < MAX_RTP_PT; ++i) { 01550 rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat; 01551 rtp->current_RTP_PT[i].code = static_RTP_PT[i].code; 01552 } 01553 01554 rtp->rtp_lookup_code_cache_isAstFormat = 0; 01555 rtp->rtp_lookup_code_cache_code = 0; 01556 rtp->rtp_lookup_code_cache_result = 0; 01557 01558 ast_mutex_unlock(&rtp->bridge_lock); 01559 }
Definition at line 1182 of file rtp.c.
References ast_rtp::altthem, ast_assert, ast_codec_get_samples(), AST_CONTROL_SRCCHANGE, AST_FORMAT_MAX_AUDIO, ast_format_rate(), AST_FORMAT_SLINEAR, ast_frame_byteswap_be, AST_FRAME_CONTROL, AST_FRAME_DTMF_END, AST_FRAME_VIDEO, AST_FRAME_VOICE, AST_FRFLAG_HAS_TIMING_INFO, AST_FRIENDLY_OFFSET, ast_frisolate(), ast_inet_ntoa(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, ast_log(), ast_null_frame, ast_rtcp_calc_interval(), ast_rtcp_write(), AST_RTP_CISCO_DTMF, AST_RTP_CN, AST_RTP_DTMF, ast_rtp_get_bridged(), ast_rtp_lookup_pt(), ast_rtp_senddigit_continuation(), ast_samp2tv(), ast_sched_add(), ast_set_flag, ast_tv(), ast_tvdiff_ms(), ast_verbose(), bridge_p2p_rtp_write(), ast_rtp::bridged, calc_rxstamp(), rtpPayloadType::code, create_dtmf_frame(), ast_rtp::cycles, ast_frame::data, ast_frame::datalen, ast_frame::delivery, ast_rtp::dtmf_duration, ast_rtp::dtmf_timeout, errno, ext, ast_rtp::f, f, FLAG_NAT_ACTIVE, frames, ast_frame::frametype, rtpPayloadType::isAstFormat, ast_rtp::lastevent, ast_rtp::lastividtimestamp, ast_rtp::lastrxformat, ast_rtp::lastrxseqno, ast_rtp::lastrxts, ast_frame::len, len(), LOG_DEBUG, LOG_NOTICE, LOG_WARNING, ast_frame::mallocd, ast_rtp::nat, ast_frame::offset, option_debug, process_cisco_dtmf(), process_rfc2833(), process_rfc3389(), ast_rtp::rawdata, ast_rtp::resp, ast_rtp::rtcp, rtp_debug_test_addr(), rtp_get_rate(), RTP_SEQ_MOD, ast_rtp::rxcount, ast_rtp::rxseqno, ast_rtp::rxssrc, ast_rtcp::s, ast_rtp::s, ast_frame::samples, ast_rtp::sched, ast_rtcp::schedid, ast_rtp::seedrxseqno, ast_rtp::sending_digit, ast_frame::seqno, ast_frame::src, STUN_ACCEPT, stun_handle_packet(), ast_frame::subclass, ast_rtcp::them, ast_rtp::them, ast_rtp::themssrc, and ast_frame::ts.
Referenced by gtalk_rtp_read(), mgcp_rtp_read(), oh323_rtp_read(), rtpread(), sip_rtp_read(), and skinny_rtp_read().
01183 { 01184 int res; 01185 struct sockaddr_in sin; 01186 socklen_t len; 01187 unsigned int seqno; 01188 int version; 01189 int payloadtype; 01190 int hdrlen = 12; 01191 int padding; 01192 int mark; 01193 int ext; 01194 int cc; 01195 unsigned int ssrc; 01196 unsigned int timestamp; 01197 unsigned int *rtpheader; 01198 struct rtpPayloadType rtpPT; 01199 struct ast_rtp *bridged = NULL; 01200 struct frame_list frames; 01201 01202 /* If time is up, kill it */ 01203 if (rtp->sending_digit) 01204 ast_rtp_senddigit_continuation(rtp); 01205 01206 len = sizeof(sin); 01207 01208 /* Cache where the header will go */ 01209 res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET, 01210 0, (struct sockaddr *)&sin, &len); 01211 if (option_debug > 3) 01212 ast_log(LOG_DEBUG, "socket RTP read: rtp %i rtcp %i\n", rtp->s, rtp->rtcp->s); 01213 01214 rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET); 01215 if (res < 0) { 01216 ast_assert(errno != EBADF); 01217 if (errno != EAGAIN) { 01218 ast_log(LOG_WARNING, "RTP Read error: %s. Hanging up.\n", strerror(errno)); 01219 ast_log(LOG_WARNING, "socket RTP read: rtp %i rtcp %i\n", rtp->s, rtp->rtcp->s); 01220 return NULL; 01221 } 01222 return &ast_null_frame; 01223 } 01224 01225 if (res < hdrlen) { 01226 ast_log(LOG_WARNING, "RTP Read too short\n"); 01227 return &ast_null_frame; 01228 } 01229 01230 /* Get fields */ 01231 seqno = ntohl(rtpheader[0]); 01232 01233 /* Check RTP version */ 01234 version = (seqno & 0xC0000000) >> 30; 01235 if (!version) { 01236 if ((stun_handle_packet(rtp->s, &sin, rtp->rawdata + AST_FRIENDLY_OFFSET, res) == STUN_ACCEPT) && 01237 (!rtp->them.sin_port && !rtp->them.sin_addr.s_addr)) { 01238 memcpy(&rtp->them, &sin, sizeof(rtp->them)); 01239 } 01240 return &ast_null_frame; 01241 } 01242 01243 #if 0 /* Allow to receive RTP stream with closed transmission path */ 01244 /* If we don't have the other side's address, then ignore this */ 01245 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 01246 return &ast_null_frame; 01247 #endif 01248 01249 /* Send to whoever send to us if NAT is turned on */ 01250 if (rtp->nat) { 01251 if (((rtp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || 01252 (rtp->them.sin_port != sin.sin_port)) && 01253 ((rtp->altthem.sin_addr.s_addr != sin.sin_addr.s_addr) || 01254 (rtp->altthem.sin_port != sin.sin_port))) { 01255 rtp->them = sin; 01256 if (rtp->rtcp) { 01257 memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); 01258 rtp->rtcp->them.sin_port = htons(ntohs(rtp->them.sin_port)+1); 01259 } 01260 rtp->rxseqno = 0; 01261 ast_set_flag(rtp, FLAG_NAT_ACTIVE); 01262 if (option_debug || rtpdebug) 01263 ast_log(LOG_DEBUG, "RTP NAT: Got audio from other end. Now sending to address %s:%d\n", ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port)); 01264 } 01265 } 01266 01267 /* If we are bridged to another RTP stream, send direct */ 01268 if ((bridged = ast_rtp_get_bridged(rtp)) && !bridge_p2p_rtp_write(rtp, bridged, rtpheader, res, hdrlen)) 01269 return &ast_null_frame; 01270 01271 if (version != 2) 01272 return &ast_null_frame; 01273 01274 payloadtype = (seqno & 0x7f0000) >> 16; 01275 padding = seqno & (1 << 29); 01276 mark = seqno & (1 << 23); 01277 ext = seqno & (1 << 28); 01278 cc = (seqno & 0xF000000) >> 24; 01279 seqno &= 0xffff; 01280 timestamp = ntohl(rtpheader[1]); 01281 ssrc = ntohl(rtpheader[2]); 01282 01283 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01284 /* Force a marker bit and change SSRC if the SSRC changes */ 01285 if (rtp->rxssrc && rtp->rxssrc != ssrc) { 01286 struct ast_frame *f, srcupdate = { 01287 AST_FRAME_CONTROL, 01288 .subclass = AST_CONTROL_SRCCHANGE, 01289 }; 01290 01291 if (!mark) { 01292 if (option_debug || rtpdebug) { 01293 ast_log(LOG_DEBUG, "Forcing Marker bit, because SSRC has changed\n"); 01294 } 01295 mark = 1; 01296 } 01297 f = ast_frisolate(&srcupdate); 01298 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01299 } 01300 01301 rtp->rxssrc = ssrc; 01302 01303 if (padding) { 01304 /* Remove padding bytes */ 01305 res -= rtp->rawdata[AST_FRIENDLY_OFFSET + res - 1]; 01306 } 01307 01308 if (cc) { 01309 /* CSRC fields present */ 01310 hdrlen += cc*4; 01311 } 01312 01313 if (ext) { 01314 /* RTP Extension present */ 01315 hdrlen += (ntohl(rtpheader[hdrlen/4]) & 0xffff) << 2; 01316 hdrlen += 4; 01317 } 01318 01319 if (res < hdrlen) { 01320 ast_log(LOG_WARNING, "RTP Read too short (%d, expecting %d)\n", res, hdrlen); 01321 return AST_LIST_FIRST(&frames) ? AST_LIST_FIRST(&frames) : &ast_null_frame; 01322 } 01323 01324 rtp->rxcount++; /* Only count reasonably valid packets, this'll make the rtcp stats more accurate */ 01325 01326 if (rtp->rxcount==1) { 01327 /* This is the first RTP packet successfully received from source */ 01328 rtp->seedrxseqno = seqno; 01329 } 01330 01331 /* Do not schedule RR if RTCP isn't run */ 01332 if (rtp->rtcp && rtp->rtcp->them.sin_addr.s_addr && rtp->rtcp->schedid < 1) { 01333 /* Schedule transmission of Receiver Report */ 01334 rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, rtp); 01335 } 01336 if ( (int)rtp->lastrxseqno - (int)seqno > 100) /* if so it would indicate that the sender cycled; allow for misordering */ 01337 rtp->cycles += RTP_SEQ_MOD; 01338 01339 rtp->lastrxseqno = seqno; 01340 01341 if (rtp->themssrc==0) 01342 rtp->themssrc = ntohl(rtpheader[2]); /* Record their SSRC to put in future RR */ 01343 01344 if (rtp_debug_test_addr(&sin)) 01345 ast_verbose("Got RTP packet from %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 01346 ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen); 01347 01348 rtpPT = ast_rtp_lookup_pt(rtp, payloadtype); 01349 if (!rtpPT.isAstFormat) { 01350 struct ast_frame *f = NULL; 01351 01352 /* This is special in-band data that's not one of our codecs */ 01353 if (rtpPT.code == AST_RTP_DTMF) { 01354 /* It's special -- rfc2833 process it */ 01355 if (rtp_debug_test_addr(&sin)) { 01356 unsigned char *data; 01357 unsigned int event; 01358 unsigned int event_end; 01359 unsigned int duration; 01360 data = rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen; 01361 event = ntohl(*((unsigned int *)(data))); 01362 event >>= 24; 01363 event_end = ntohl(*((unsigned int *)(data))); 01364 event_end <<= 8; 01365 event_end >>= 24; 01366 duration = ntohl(*((unsigned int *)(data))); 01367 duration &= 0xFFFF; 01368 ast_verbose("Got RTP RFC2833 from %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u, mark %d, event %08x, end %d, duration %-5.5d) \n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp, res - hdrlen, (mark?1:0), event, ((event_end & 0x80)?1:0), duration); 01369 } 01370 /* process_rfc2833 may need to return multiple frames. We do this 01371 * by passing the pointer to the frame list to it so that the method 01372 * can append frames to the list as needed 01373 */ 01374 process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp, &frames); 01375 } else if (rtpPT.code == AST_RTP_CISCO_DTMF) { 01376 /* It's really special -- process it the Cisco way */ 01377 if (rtp->lastevent <= seqno || (rtp->lastevent >= 65530 && seqno <= 6)) { 01378 f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01379 rtp->lastevent = seqno; 01380 } 01381 } else if (rtpPT.code == AST_RTP_CN) { 01382 /* Comfort Noise */ 01383 f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01384 } else { 01385 ast_log(LOG_NOTICE, "Unknown RTP codec %d received from '%s'\n", payloadtype, ast_inet_ntoa(rtp->them.sin_addr)); 01386 } 01387 if (f) { 01388 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01389 } 01390 /* Even if no frame was returned by one of the above methods, 01391 * we may have a frame to return in our frame list 01392 */ 01393 if (!AST_LIST_EMPTY(&frames)) { 01394 return AST_LIST_FIRST(&frames); 01395 } 01396 return &ast_null_frame; 01397 } 01398 rtp->lastrxformat = rtp->f.subclass = rtpPT.code; 01399 rtp->f.frametype = (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) ? AST_FRAME_VOICE : AST_FRAME_VIDEO; 01400 01401 rtp->rxseqno = seqno; 01402 01403 if (rtp->dtmf_timeout && rtp->dtmf_timeout < timestamp) { 01404 rtp->dtmf_timeout = 0; 01405 01406 if (rtp->resp) { 01407 struct ast_frame *f; 01408 f = create_dtmf_frame(rtp, AST_FRAME_DTMF_END); 01409 f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, rtp_get_rate(f->subclass)), ast_tv(0, 0)); 01410 rtp->resp = 0; 01411 rtp->dtmf_timeout = rtp->dtmf_duration = 0; 01412 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01413 return AST_LIST_FIRST(&frames); 01414 } 01415 } 01416 01417 /* Record received timestamp as last received now */ 01418 rtp->lastrxts = timestamp; 01419 01420 rtp->f.mallocd = 0; 01421 rtp->f.datalen = res - hdrlen; 01422 rtp->f.data = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET; 01423 rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET; 01424 rtp->f.seqno = seqno; 01425 if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) { 01426 rtp->f.samples = ast_codec_get_samples(&rtp->f); 01427 if (rtp->f.subclass == AST_FORMAT_SLINEAR) 01428 ast_frame_byteswap_be(&rtp->f); 01429 calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark); 01430 /* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */ 01431 ast_set_flag(&rtp->f, AST_FRFLAG_HAS_TIMING_INFO); 01432 rtp->f.ts = timestamp / (rtp_get_rate(rtp->f.subclass) / 1000); 01433 rtp->f.len = rtp->f.samples / (ast_format_rate(rtp->f.subclass) / 1000); 01434 } else { 01435 /* Video -- samples is # of samples vs. 90000 */ 01436 if (!rtp->lastividtimestamp) 01437 rtp->lastividtimestamp = timestamp; 01438 rtp->f.samples = timestamp - rtp->lastividtimestamp; 01439 rtp->lastividtimestamp = timestamp; 01440 rtp->f.delivery.tv_sec = 0; 01441 rtp->f.delivery.tv_usec = 0; 01442 if (mark) 01443 rtp->f.subclass |= 0x1; 01444 } 01445 rtp->f.src = "RTP"; 01446 01447 AST_LIST_INSERT_TAIL(&frames, &rtp->f, frame_list); 01448 return AST_LIST_FIRST(&frames); 01449 }
int ast_rtp_reload | ( | void | ) |
Definition at line 3959 of file rtp.c.
References ast_config_destroy(), ast_config_load(), ast_false(), ast_log(), ast_variable_retrieve(), ast_verbose(), DEFAULT_DTMF_TIMEOUT, LOG_WARNING, option_verbose, RTCP_MAX_INTERVALMS, RTCP_MIN_INTERVALMS, s, and VERBOSE_PREFIX_2.
Referenced by ast_rtp_init().
03960 { 03961 struct ast_config *cfg; 03962 const char *s; 03963 03964 rtpstart = 5000; 03965 rtpend = 31000; 03966 dtmftimeout = DEFAULT_DTMF_TIMEOUT; 03967 cfg = ast_config_load("rtp.conf"); 03968 if (cfg) { 03969 if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) { 03970 rtpstart = atoi(s); 03971 if (rtpstart < 1024) 03972 rtpstart = 1024; 03973 if (rtpstart > 65535) 03974 rtpstart = 65535; 03975 } 03976 if ((s = ast_variable_retrieve(cfg, "general", "rtpend"))) { 03977 rtpend = atoi(s); 03978 if (rtpend < 1024) 03979 rtpend = 1024; 03980 if (rtpend > 65535) 03981 rtpend = 65535; 03982 } 03983 if ((s = ast_variable_retrieve(cfg, "general", "rtcpinterval"))) { 03984 rtcpinterval = atoi(s); 03985 if (rtcpinterval == 0) 03986 rtcpinterval = 0; /* Just so we're clear... it's zero */ 03987 if (rtcpinterval < RTCP_MIN_INTERVALMS) 03988 rtcpinterval = RTCP_MIN_INTERVALMS; /* This catches negative numbers too */ 03989 if (rtcpinterval > RTCP_MAX_INTERVALMS) 03990 rtcpinterval = RTCP_MAX_INTERVALMS; 03991 } 03992 if ((s = ast_variable_retrieve(cfg, "general", "rtpchecksums"))) { 03993 #ifdef SO_NO_CHECK 03994 if (ast_false(s)) 03995 nochecksums = 1; 03996 else 03997 nochecksums = 0; 03998 #else 03999 if (ast_false(s)) 04000 ast_log(LOG_WARNING, "Disabling RTP checksums is not supported on this operating system!\n"); 04001 #endif 04002 } 04003 if ((s = ast_variable_retrieve(cfg, "general", "dtmftimeout"))) { 04004 dtmftimeout = atoi(s); 04005 if ((dtmftimeout < 0) || (dtmftimeout > 64000)) { 04006 ast_log(LOG_WARNING, "DTMF timeout of '%d' outside range, using default of '%d' instead\n", 04007 dtmftimeout, DEFAULT_DTMF_TIMEOUT); 04008 dtmftimeout = DEFAULT_DTMF_TIMEOUT; 04009 }; 04010 } 04011 ast_config_destroy(cfg); 04012 } 04013 if (rtpstart >= rtpend) { 04014 ast_log(LOG_WARNING, "Unreasonable values for RTP start/end port in rtp.conf\n"); 04015 rtpstart = 5000; 04016 rtpend = 31000; 04017 } 04018 if (option_verbose > 1) 04019 ast_verbose(VERBOSE_PREFIX_2 "RTP Allocating from port range %d -> %d\n", rtpstart, rtpend); 04020 return 0; 04021 }
void ast_rtp_reset | ( | struct ast_rtp * | rtp | ) |
Definition at line 2217 of file rtp.c.
References ast_rtp::dtmf_timeout, ast_rtp::dtmfmute, ast_rtp::lastdigitts, ast_rtp::lastevent, ast_rtp::lasteventseqn, ast_rtp::lastividtimestamp, ast_rtp::lastovidtimestamp, ast_rtp::lastrxformat, ast_rtp::lastrxts, ast_rtp::lastts, ast_rtp::lasttxformat, ast_rtp::rxcore, ast_rtp::rxseqno, ast_rtp::seqno, and ast_rtp::txcore.
02218 { 02219 memset(&rtp->rxcore, 0, sizeof(rtp->rxcore)); 02220 memset(&rtp->txcore, 0, sizeof(rtp->txcore)); 02221 memset(&rtp->dtmfmute, 0, sizeof(rtp->dtmfmute)); 02222 rtp->lastts = 0; 02223 rtp->lastdigitts = 0; 02224 rtp->lastrxts = 0; 02225 rtp->lastividtimestamp = 0; 02226 rtp->lastovidtimestamp = 0; 02227 rtp->lasteventseqn = 0; 02228 rtp->lastevent = 0; 02229 rtp->lasttxformat = 0; 02230 rtp->lastrxformat = 0; 02231 rtp->dtmf_timeout = 0; 02232 rtp->seqno = 0; 02233 rtp->rxseqno = 0; 02234 }
int ast_rtp_sendcng | ( | struct ast_rtp * | rtp, | |
int | level | |||
) |
generate comfort noice (CNG)
Definition at line 2744 of file rtp.c.
References ast_inet_ntoa(), ast_log(), AST_RTP_CN, ast_rtp_lookup_code(), ast_tv(), ast_tvadd(), ast_tvnow(), ast_verbose(), ast_rtp::data, ast_rtp::dtmfmute, errno, ast_rtp::lastts, LOG_ERROR, rtp_debug_test_addr(), ast_rtp::s, ast_rtp::seqno, ast_rtp::ssrc, and ast_rtp::them.
Referenced by do_monitor().
02745 { 02746 unsigned int *rtpheader; 02747 int hdrlen = 12; 02748 int res; 02749 int payload; 02750 char data[256]; 02751 level = 127 - (level & 0x7f); 02752 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_CN); 02753 02754 /* If we have no peer, return immediately */ 02755 if (!rtp->them.sin_addr.s_addr) 02756 return 0; 02757 02758 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 02759 02760 /* Get a pointer to the header */ 02761 rtpheader = (unsigned int *)data; 02762 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno++)); 02763 rtpheader[1] = htonl(rtp->lastts); 02764 rtpheader[2] = htonl(rtp->ssrc); 02765 data[12] = level; 02766 if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) { 02767 res = sendto(rtp->s, (void *)rtpheader, hdrlen + 1, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them)); 02768 if (res <0) 02769 ast_log(LOG_ERROR, "RTP Comfort Noise Transmission error to %s:%d: %s\n", ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno)); 02770 if (rtp_debug_test_addr(&rtp->them)) 02771 ast_verbose("Sent Comfort Noise RTP packet to %s:%u (type %d, seq %u, ts %u, len %d)\n" 02772 , ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen); 02773 02774 } 02775 return 0; 02776 }
int ast_rtp_senddigit_begin | ( | struct ast_rtp * | rtp, | |
char | digit | |||
) |
Send begin frames for DTMF.
Definition at line 2339 of file rtp.c.
References ast_inet_ntoa(), ast_log(), AST_RTP_DTMF, ast_rtp_lookup_code(), ast_tv(), ast_tvadd(), ast_tvnow(), ast_verbose(), ast_rtp::dtmfmute, errno, ast_rtp::lastdigitts, ast_rtp::lastts, LOG_ERROR, LOG_WARNING, rtp_debug_test_addr(), ast_rtp::s, ast_rtp::send_digit, ast_rtp::send_duration, ast_rtp::send_payload, ast_rtp::sending_digit, ast_rtp::seqno, ast_rtp::ssrc, and ast_rtp::them.
Referenced by mgcp_senddigit_begin(), oh323_digit_begin(), and sip_senddigit_begin().
02340 { 02341 unsigned int *rtpheader; 02342 int hdrlen = 12, res = 0, i = 0, payload = 0; 02343 char data[256]; 02344 02345 if ((digit <= '9') && (digit >= '0')) 02346 digit -= '0'; 02347 else if (digit == '*') 02348 digit = 10; 02349 else if (digit == '#') 02350 digit = 11; 02351 else if ((digit >= 'A') && (digit <= 'D')) 02352 digit = digit - 'A' + 12; 02353 else if ((digit >= 'a') && (digit <= 'd')) 02354 digit = digit - 'a' + 12; 02355 else { 02356 ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit); 02357 return 0; 02358 } 02359 02360 /* If we have no peer, return immediately */ 02361 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 02362 return 0; 02363 02364 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF); 02365 02366 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 02367 rtp->send_duration = 160; 02368 rtp->lastdigitts = rtp->lastts + rtp->send_duration; 02369 02370 /* Get a pointer to the header */ 02371 rtpheader = (unsigned int *)data; 02372 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno)); 02373 rtpheader[1] = htonl(rtp->lastdigitts); 02374 rtpheader[2] = htonl(rtp->ssrc); 02375 02376 for (i = 0; i < 2; i++) { 02377 rtpheader[3] = htonl((digit << 24) | (0xa << 16) | (rtp->send_duration)); 02378 res = sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockaddr *) &rtp->them, sizeof(rtp->them)); 02379 if (res < 0) 02380 ast_log(LOG_ERROR, "RTP Transmission error to %s:%u: %s\n", 02381 ast_inet_ntoa(rtp->them.sin_addr), 02382 ntohs(rtp->them.sin_port), strerror(errno)); 02383 if (rtp_debug_test_addr(&rtp->them)) 02384 ast_verbose("Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 02385 ast_inet_ntoa(rtp->them.sin_addr), 02386 ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen); 02387 /* Increment sequence number */ 02388 rtp->seqno++; 02389 /* Increment duration */ 02390 rtp->send_duration += 160; 02391 /* Clear marker bit and set seqno */ 02392 rtpheader[0] = htonl((2 << 30) | (payload << 16) | (rtp->seqno)); 02393 } 02394 02395 /* Since we received a begin, we can safely store the digit and disable any compensation */ 02396 rtp->sending_digit = 1; 02397 rtp->send_digit = digit; 02398 rtp->send_payload = payload; 02399 02400 return 0; 02401 }
int ast_rtp_senddigit_end | ( | struct ast_rtp * | rtp, | |
char | digit | |||
) |
int ast_rtp_senddigit_end_with_duration | ( | struct ast_rtp * | rtp, | |
char | digit, | |||
unsigned int | duration | |||
) |
void ast_rtp_set_alt_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | alt | |||
) |
set potential alternate source for RTP media
rtp | The RTP structure we wish to set up an alternate host/port on | |
alt | The address information for the alternate media source |
void |
Definition at line 2162 of file rtp.c.
References ast_rtcp::altthem, ast_rtp::altthem, and ast_rtp::rtcp.
Referenced by handle_request_invite().
02163 { 02164 rtp->altthem.sin_port = alt->sin_port; 02165 rtp->altthem.sin_addr = alt->sin_addr; 02166 if (rtp->rtcp) { 02167 rtp->rtcp->altthem.sin_port = htons(ntohs(alt->sin_port) + 1); 02168 rtp->rtcp->altthem.sin_addr = alt->sin_addr; 02169 } 02170 }
void ast_rtp_set_callback | ( | struct ast_rtp * | rtp, | |
ast_rtp_callback | callback | |||
) |
Definition at line 596 of file rtp.c.
References ast_rtp::callback.
Referenced by start_rtp().
00597 { 00598 rtp->callback = callback; 00599 }
void ast_rtp_set_data | ( | struct ast_rtp * | rtp, | |
void * | data | |||
) |
Definition at line 591 of file rtp.c.
References ast_rtp::data.
Referenced by start_rtp().
00592 { 00593 rtp->data = data; 00594 }
void ast_rtp_set_m_type | ( | struct ast_rtp * | rtp, | |
int | pt | |||
) |
Activate payload type.
Definition at line 1759 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, ast_rtp::current_RTP_PT, MAX_RTP_PT, and static_RTP_PT.
Referenced by gtalk_is_answered(), gtalk_newcall(), and process_sdp().
01760 { 01761 if (pt < 0 || pt >= MAX_RTP_PT || static_RTP_PT[pt].code == 0) 01762 return; /* bogus payload type */ 01763 01764 ast_mutex_lock(&rtp->bridge_lock); 01765 rtp->current_RTP_PT[pt] = static_RTP_PT[pt]; 01766 ast_mutex_unlock(&rtp->bridge_lock); 01767 }
void ast_rtp_set_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | them | |||
) |
Definition at line 2151 of file rtp.c.
References ast_rtp::rtcp, ast_rtp::rxseqno, ast_rtcp::them, and ast_rtp::them.
Referenced by handle_open_receive_channel_ack_message(), process_sdp(), and setup_rtp_connection().
02152 { 02153 rtp->them.sin_port = them->sin_port; 02154 rtp->them.sin_addr = them->sin_addr; 02155 if (rtp->rtcp) { 02156 rtp->rtcp->them.sin_port = htons(ntohs(them->sin_port) + 1); 02157 rtp->rtcp->them.sin_addr = them->sin_addr; 02158 } 02159 rtp->rxseqno = 0; 02160 }
void ast_rtp_set_rtpholdtimeout | ( | struct ast_rtp * | rtp, | |
int | timeout | |||
) |
Set rtp hold timeout.
Definition at line 558 of file rtp.c.
References ast_rtp::rtpholdtimeout.
Referenced by create_addr_from_peer(), do_monitor(), and sip_alloc().
00559 { 00560 rtp->rtpholdtimeout = timeout; 00561 }
void ast_rtp_set_rtpkeepalive | ( | struct ast_rtp * | rtp, | |
int | period | |||
) |
set RTP keepalive interval
Definition at line 564 of file rtp.c.
References ast_rtp::rtpkeepalive.
Referenced by create_addr_from_peer(), and sip_alloc().
00565 { 00566 rtp->rtpkeepalive = period; 00567 }
int ast_rtp_set_rtpmap_type | ( | struct ast_rtp * | rtp, | |
int | pt, | |||
char * | mimeType, | |||
char * | mimeSubtype, | |||
enum ast_rtp_options | options | |||
) |
Initiate payload type to a known MIME media type for a codec.
Definition at line 1786 of file rtp.c.
References AST_FORMAT_G726, AST_FORMAT_G726_AAL2, ast_mutex_lock(), ast_mutex_unlock(), AST_RTP_OPT_G726_NONSTANDARD, ast_rtp::bridge_lock, rtpPayloadType::code, ast_rtp::current_RTP_PT, MAX_RTP_PT, mimeTypes, payloadType, subtype, and type.
Referenced by __oh323_rtp_create(), gtalk_is_answered(), gtalk_newcall(), process_sdp(), process_sdp_a_audio(), process_sdp_a_video(), and set_dtmf_payload().
01789 { 01790 unsigned int i; 01791 int found = 0; 01792 01793 if (pt < 0 || pt >= MAX_RTP_PT) 01794 return -1; /* bogus payload type */ 01795 01796 ast_mutex_lock(&rtp->bridge_lock); 01797 01798 for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { 01799 if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 && 01800 strcasecmp(mimeType, mimeTypes[i].type) == 0) { 01801 found = 1; 01802 rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType; 01803 if ((mimeTypes[i].payloadType.code == AST_FORMAT_G726) && 01804 mimeTypes[i].payloadType.isAstFormat && 01805 (options & AST_RTP_OPT_G726_NONSTANDARD)) 01806 rtp->current_RTP_PT[pt].code = AST_FORMAT_G726_AAL2; 01807 break; 01808 } 01809 } 01810 01811 ast_mutex_unlock(&rtp->bridge_lock); 01812 01813 return (found ? 0 : -1); 01814 }
void ast_rtp_set_rtptimeout | ( | struct ast_rtp * | rtp, | |
int | timeout | |||
) |
Set rtp timeout.
Definition at line 552 of file rtp.c.
References ast_rtp::rtptimeout.
Referenced by create_addr_from_peer(), do_monitor(), and sip_alloc().
00553 { 00554 rtp->rtptimeout = timeout; 00555 }
void ast_rtp_set_rtptimers_onhold | ( | struct ast_rtp * | rtp | ) |
Definition at line 545 of file rtp.c.
References ast_rtp::rtpholdtimeout, and ast_rtp::rtptimeout.
Referenced by handle_response_invite().
00546 { 00547 rtp->rtptimeout = (-1) * rtp->rtptimeout; 00548 rtp->rtpholdtimeout = (-1) * rtp->rtpholdtimeout; 00549 }
void ast_rtp_setdtmf | ( | struct ast_rtp * | rtp, | |
int | dtmf | |||
) |
Indicate whether this RTP session is carrying DTMF or not.
Definition at line 611 of file rtp.c.
References ast_set2_flag, and FLAG_HAS_DTMF.
Referenced by create_addr_from_peer(), handle_request_invite(), process_sdp(), sip_alloc(), and sip_dtmfmode().
00612 { 00613 ast_set2_flag(rtp, dtmf ? 1 : 0, FLAG_HAS_DTMF); 00614 }
void ast_rtp_setdtmfcompensate | ( | struct ast_rtp * | rtp, | |
int | compensate | |||
) |
Compensate for devices that send RFC2833 packets all at once.
Definition at line 616 of file rtp.c.
References ast_set2_flag, and FLAG_DTMF_COMPENSATE.
Referenced by create_addr_from_peer(), handle_request_invite(), process_sdp(), and sip_alloc().
00617 { 00618 ast_set2_flag(rtp, compensate ? 1 : 0, FLAG_DTMF_COMPENSATE); 00619 }
void ast_rtp_setnat | ( | struct ast_rtp * | rtp, | |
int | nat | |||
) |
Definition at line 601 of file rtp.c.
References ast_rtp::nat.
Referenced by __oh323_rtp_create(), do_setnat(), oh323_rtp_read(), and start_rtp().
void ast_rtp_setstun | ( | struct ast_rtp * | rtp, | |
int | stun_enable | |||
) |
Enable STUN capability.
Definition at line 621 of file rtp.c.
References ast_set2_flag, and FLAG_HAS_STUN.
Referenced by gtalk_new().
00622 { 00623 ast_set2_flag(rtp, stun_enable ? 1 : 0, FLAG_HAS_STUN); 00624 }
int ast_rtp_settos | ( | struct ast_rtp * | rtp, | |
int | tos | |||
) |
Definition at line 2119 of file rtp.c.
References ast_log(), LOG_WARNING, and ast_rtp::s.
Referenced by __oh323_rtp_create(), and sip_alloc().
02120 { 02121 int res; 02122 02123 if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 02124 ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); 02125 return res; 02126 }
void ast_rtp_stop | ( | struct ast_rtp * | rtp | ) |
Definition at line 2201 of file rtp.c.
References ast_clear_flag, AST_SCHED_DEL, FLAG_P2P_SENT_MARK, ast_rtp::rtcp, ast_rtp::sched, ast_rtcp::schedid, ast_rtcp::them, and ast_rtp::them.
Referenced by process_sdp(), setup_rtp_connection(), and stop_media_flows().
02202 { 02203 if (rtp->rtcp) { 02204 AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid); 02205 } 02206 02207 memset(&rtp->them.sin_addr, 0, sizeof(rtp->them.sin_addr)); 02208 memset(&rtp->them.sin_port, 0, sizeof(rtp->them.sin_port)); 02209 if (rtp->rtcp) { 02210 memset(&rtp->rtcp->them.sin_addr, 0, sizeof(rtp->rtcp->them.sin_addr)); 02211 memset(&rtp->rtcp->them.sin_port, 0, sizeof(rtp->rtcp->them.sin_port)); 02212 } 02213 02214 ast_clear_flag(rtp, FLAG_P2P_SENT_MARK); 02215 }
void ast_rtp_stun_request | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | suggestion, | |||
const char * | username | |||
) |
Definition at line 408 of file rtp.c.
References append_attr_string(), stun_attr::attr, ast_rtp::s, STUN_BINDREQ, stun_req_id(), stun_send(), and STUN_USERNAME.
Referenced by gtalk_update_stun().
00409 { 00410 struct stun_header *req; 00411 unsigned char reqdata[1024]; 00412 int reqlen, reqleft; 00413 struct stun_attr *attr; 00414 00415 req = (struct stun_header *)reqdata; 00416 stun_req_id(req); 00417 reqlen = 0; 00418 reqleft = sizeof(reqdata) - sizeof(struct stun_header); 00419 req->msgtype = 0; 00420 req->msglen = 0; 00421 attr = (struct stun_attr *)req->ies; 00422 if (username) 00423 append_attr_string(&attr, STUN_USERNAME, username, &reqlen, &reqleft); 00424 req->msglen = htons(reqlen); 00425 req->msgtype = htons(STUN_BINDREQ); 00426 stun_send(rtp->s, suggestion, req); 00427 }
void ast_rtp_unset_m_type | ( | struct ast_rtp * | rtp, | |
int | pt | |||
) |
clear payload type
Definition at line 1771 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, and MAX_RTP_PT.
Referenced by process_sdp_a_audio(), and process_sdp_a_video().
01772 { 01773 if (pt < 0 || pt >= MAX_RTP_PT) 01774 return; /* bogus payload type */ 01775 01776 ast_mutex_lock(&rtp->bridge_lock); 01777 rtp->current_RTP_PT[pt].isAstFormat = 0; 01778 rtp->current_RTP_PT[pt].code = 0; 01779 ast_mutex_unlock(&rtp->bridge_lock); 01780 }
Definition at line 2949 of file rtp.c.
References ast_codec_pref_getsize(), AST_FORMAT_G723_1, AST_FORMAT_SPEEX, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frdup(), ast_frfree, ast_getformatname(), ast_log(), ast_rtp_lookup_code(), ast_rtp_raw_write(), ast_smoother_feed, ast_smoother_feed_be, AST_SMOOTHER_FLAG_BE, ast_smoother_free(), ast_smoother_new(), ast_smoother_read(), ast_smoother_set_flags(), ast_smoother_test_flag(), ast_format_list::cur_ms, ast_frame::datalen, f, ast_format_list::flags, ast_format_list::fr_len, ast_frame::frametype, ast_format_list::inc_ms, ast_rtp::lasttxformat, LOG_DEBUG, LOG_WARNING, ast_frame::offset, option_debug, ast_rtp::pref, ast_rtp::smoother, ast_frame::subclass, and ast_rtp::them.
Referenced by gtalk_write(), mgcp_write(), oh323_write(), sip_write(), and skinny_write().
02950 { 02951 struct ast_frame *f; 02952 int codec; 02953 int hdrlen = 12; 02954 int subclass; 02955 02956 02957 /* If we have no peer, return immediately */ 02958 if (!rtp->them.sin_addr.s_addr) 02959 return 0; 02960 02961 /* If there is no data length, return immediately */ 02962 if (!_f->datalen) 02963 return 0; 02964 02965 /* Make sure we have enough space for RTP header */ 02966 if ((_f->frametype != AST_FRAME_VOICE) && (_f->frametype != AST_FRAME_VIDEO)) { 02967 ast_log(LOG_WARNING, "RTP can only send voice and video\n"); 02968 return -1; 02969 } 02970 02971 subclass = _f->subclass; 02972 if (_f->frametype == AST_FRAME_VIDEO) 02973 subclass &= ~0x1; 02974 02975 codec = ast_rtp_lookup_code(rtp, 1, subclass); 02976 if (codec < 0) { 02977 ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(_f->subclass)); 02978 return -1; 02979 } 02980 02981 if (rtp->lasttxformat != subclass) { 02982 /* New format, reset the smoother */ 02983 if (option_debug) 02984 ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass)); 02985 rtp->lasttxformat = subclass; 02986 if (rtp->smoother) 02987 ast_smoother_free(rtp->smoother); 02988 rtp->smoother = NULL; 02989 } 02990 02991 if (!rtp->smoother && subclass != AST_FORMAT_SPEEX && subclass != AST_FORMAT_G723_1) { 02992 struct ast_format_list fmt = ast_codec_pref_getsize(&rtp->pref, subclass); 02993 if (fmt.inc_ms) { /* if codec parameters is set / avoid division by zero */ 02994 if (!(rtp->smoother = ast_smoother_new((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms))) { 02995 ast_log(LOG_WARNING, "Unable to create smoother: format: %d ms: %d len: %d\n", subclass, fmt.cur_ms, ((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms)); 02996 return -1; 02997 } 02998 if (fmt.flags) 02999 ast_smoother_set_flags(rtp->smoother, fmt.flags); 03000 if (option_debug) 03001 ast_log(LOG_DEBUG, "Created smoother: format: %d ms: %d len: %d\n", subclass, fmt.cur_ms, ((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms)); 03002 } 03003 } 03004 if (rtp->smoother) { 03005 if (ast_smoother_test_flag(rtp->smoother, AST_SMOOTHER_FLAG_BE)) { 03006 ast_smoother_feed_be(rtp->smoother, _f); 03007 } else { 03008 ast_smoother_feed(rtp->smoother, _f); 03009 } 03010 03011 while ((f = ast_smoother_read(rtp->smoother)) && (f->data)) { 03012 ast_rtp_raw_write(rtp, f, codec); 03013 } 03014 } else { 03015 /* Don't buffer outgoing frames; send them one-per-packet: */ 03016 if (_f->offset < hdrlen) { 03017 f = ast_frdup(_f); 03018 } else { 03019 f = _f; 03020 } 03021 if (f->data) { 03022 ast_rtp_raw_write(rtp, f, codec); 03023 } 03024 if (f != _f) 03025 ast_frfree(f); 03026 } 03027 03028 return 0; 03029 }