#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) |
struct 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. | |
int | ast_rtp_codec_getformat (int pt) |
struct 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) |
struct 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):. | |
struct 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) |
struct 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) |
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. | |
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. | |
struct 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) |
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(), add_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_codec_getformat(), 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().
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 |
Definition at line 53 of file rtp.h.
00053 { 00054 AST_RTP_OPT_G726_NONSTANDARD = (1 << 0), 00055 };
int ast_rtcp_fd | ( | struct ast_rtp * | rtp | ) |
Definition at line 518 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 826 of file rtp.c.
References ast_rtcp::accumulated_transit, 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_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().
00827 { 00828 socklen_t len; 00829 int position, i, packetwords; 00830 int res; 00831 struct sockaddr_in sin; 00832 unsigned int rtcpdata[8192 + AST_FRIENDLY_OFFSET]; 00833 unsigned int *rtcpheader; 00834 int pt; 00835 struct timeval now; 00836 unsigned int length; 00837 int rc; 00838 double rttsec; 00839 uint64_t rtt = 0; 00840 unsigned int dlsr; 00841 unsigned int lsr; 00842 unsigned int msw; 00843 unsigned int lsw; 00844 unsigned int comp; 00845 struct ast_frame *f = &ast_null_frame; 00846 00847 if (!rtp || !rtp->rtcp) 00848 return &ast_null_frame; 00849 00850 len = sizeof(sin); 00851 00852 res = recvfrom(rtp->rtcp->s, rtcpdata + AST_FRIENDLY_OFFSET, sizeof(rtcpdata) - sizeof(unsigned int) * AST_FRIENDLY_OFFSET, 00853 0, (struct sockaddr *)&sin, &len); 00854 rtcpheader = (unsigned int *)(rtcpdata + AST_FRIENDLY_OFFSET); 00855 00856 if (res < 0) { 00857 ast_assert(errno != EBADF); 00858 if (errno != EAGAIN) { 00859 ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n", strerror(errno)); 00860 return NULL; 00861 } 00862 return &ast_null_frame; 00863 } 00864 00865 packetwords = res / 4; 00866 00867 if (rtp->nat) { 00868 /* Send to whoever sent to us */ 00869 if ((rtp->rtcp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || 00870 (rtp->rtcp->them.sin_port != sin.sin_port)) { 00871 memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); 00872 if (option_debug || rtpdebug) 00873 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)); 00874 } 00875 } 00876 00877 if (option_debug) 00878 ast_log(LOG_DEBUG, "Got RTCP report of %d bytes\n", res); 00879 00880 /* Process a compound packet */ 00881 position = 0; 00882 while (position < packetwords) { 00883 i = position; 00884 length = ntohl(rtcpheader[i]); 00885 pt = (length & 0xff0000) >> 16; 00886 rc = (length & 0x1f000000) >> 24; 00887 length &= 0xffff; 00888 00889 if ((i + length) > packetwords) { 00890 ast_log(LOG_WARNING, "RTCP Read too short\n"); 00891 return &ast_null_frame; 00892 } 00893 00894 if (rtcp_debug_test_addr(&sin)) { 00895 ast_verbose("\n\nGot RTCP from %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 00896 ast_verbose("PT: %d(%s)\n", pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown"); 00897 ast_verbose("Reception reports: %d\n", rc); 00898 ast_verbose("SSRC of sender: %u\n", rtcpheader[i + 1]); 00899 } 00900 00901 i += 2; /* Advance past header and ssrc */ 00902 00903 switch (pt) { 00904 case RTCP_PT_SR: 00905 gettimeofday(&rtp->rtcp->rxlsr,NULL); /* To be able to populate the dlsr */ 00906 rtp->rtcp->spc = ntohl(rtcpheader[i+3]); 00907 rtp->rtcp->soc = ntohl(rtcpheader[i + 4]); 00908 rtp->rtcp->themrxlsr = ((ntohl(rtcpheader[i]) & 0x0000ffff) << 16) | ((ntohl(rtcpheader[i + 1]) & 0xffff0000) >> 16); /* Going to LSR in RR*/ 00909 00910 if (rtcp_debug_test_addr(&sin)) { 00911 ast_verbose("NTP timestamp: %lu.%010lu\n", (unsigned long) ntohl(rtcpheader[i]), (unsigned long) ntohl(rtcpheader[i + 1]) * 4096); 00912 ast_verbose("RTP timestamp: %lu\n", (unsigned long) ntohl(rtcpheader[i + 2])); 00913 ast_verbose("SPC: %lu\tSOC: %lu\n", (unsigned long) ntohl(rtcpheader[i + 3]), (unsigned long) ntohl(rtcpheader[i + 4])); 00914 } 00915 i += 5; 00916 if (rc < 1) 00917 break; 00918 /* Intentional fall through */ 00919 case RTCP_PT_RR: 00920 /* Don't handle multiple reception reports (rc > 1) yet */ 00921 /* Calculate RTT per RFC */ 00922 gettimeofday(&now, NULL); 00923 timeval2ntp(now, &msw, &lsw); 00924 if (ntohl(rtcpheader[i + 4]) && ntohl(rtcpheader[i + 5])) { /* We must have the LSR && DLSR */ 00925 comp = ((msw & 0xffff) << 16) | ((lsw & 0xffff0000) >> 16); 00926 lsr = ntohl(rtcpheader[i + 4]); 00927 dlsr = ntohl(rtcpheader[i + 5]); 00928 rtt = comp - lsr - dlsr; 00929 00930 /* Convert end to end delay to usec (keeping the calculation in 64bit space) 00931 sess->ee_delay = (eedelay * 1000) / 65536; */ 00932 if (rtt < 4294) { 00933 rtt = (rtt * 1000000) >> 16; 00934 } else { 00935 rtt = (rtt * 1000) >> 16; 00936 rtt *= 1000; 00937 } 00938 rtt = rtt / 1000.; 00939 rttsec = rtt / 1000.; 00940 00941 if (comp - dlsr >= lsr) { 00942 rtp->rtcp->accumulated_transit += rttsec; 00943 rtp->rtcp->rtt = rttsec; 00944 if (rtp->rtcp->maxrtt<rttsec) 00945 rtp->rtcp->maxrtt = rttsec; 00946 if (rtp->rtcp->minrtt>rttsec) 00947 rtp->rtcp->minrtt = rttsec; 00948 } else if (rtcp_debug_test_addr(&sin)) { 00949 ast_verbose("Internal RTCP NTP clock skew detected: " 00950 "lsr=%u, now=%u, dlsr=%u (%d:%03dms), " 00951 "diff=%d\n", 00952 lsr, comp, dlsr, dlsr / 65536, 00953 (dlsr % 65536) * 1000 / 65536, 00954 dlsr - (comp - lsr)); 00955 } 00956 } 00957 00958 rtp->rtcp->reported_jitter = ntohl(rtcpheader[i + 3]); 00959 rtp->rtcp->reported_lost = ntohl(rtcpheader[i + 1]) & 0xffffff; 00960 if (rtcp_debug_test_addr(&sin)) { 00961 ast_verbose(" Fraction lost: %ld\n", (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24)); 00962 ast_verbose(" Packets lost so far: %d\n", rtp->rtcp->reported_lost); 00963 ast_verbose(" Highest sequence number: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff)); 00964 ast_verbose(" Sequence number cycles: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16); 00965 ast_verbose(" Interarrival jitter: %u\n", rtp->rtcp->reported_jitter); 00966 ast_verbose(" Last SR(our NTP): %lu.%010lu\n",(unsigned long) ntohl(rtcpheader[i + 4]) >> 16,((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096); 00967 ast_verbose(" DLSR: %4.4f (sec)\n",ntohl(rtcpheader[i + 5])/65536.0); 00968 if (rtt) 00969 ast_verbose(" RTT: %lu(sec)\n", (unsigned long) rtt); 00970 } 00971 break; 00972 case RTCP_PT_FUR: 00973 if (rtcp_debug_test_addr(&sin)) 00974 ast_verbose("Received an RTCP Fast Update Request\n"); 00975 rtp->f.frametype = AST_FRAME_CONTROL; 00976 rtp->f.subclass = AST_CONTROL_VIDUPDATE; 00977 rtp->f.datalen = 0; 00978 rtp->f.samples = 0; 00979 rtp->f.mallocd = 0; 00980 rtp->f.src = "RTP"; 00981 f = &rtp->f; 00982 break; 00983 case RTCP_PT_SDES: 00984 if (rtcp_debug_test_addr(&sin)) 00985 ast_verbose("Received an SDES from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 00986 break; 00987 case RTCP_PT_BYE: 00988 if (rtcp_debug_test_addr(&sin)) 00989 ast_verbose("Received a BYE from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 00990 break; 00991 default: 00992 if (option_debug) 00993 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)); 00994 break; 00995 } 00996 position += (length + 1); 00997 } 00998 00999 return f; 01000 }
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 2340 of file rtp.c.
References ast_rtcp_write(), ast_rtp::rtcp, and ast_rtcp::sendfur.
02341 { 02342 struct ast_rtp *rtp = data; 02343 int res; 02344 02345 rtp->rtcp->sendfur = 1; 02346 res = ast_rtcp_write(data); 02347 02348 return res; 02349 }
size_t ast_rtp_alloc_size | ( | void | ) |
Get the amount of space required to hold an RTP session.
Definition at line 398 of file rtp.c.
Referenced by process_sdp().
00399 { 00400 return sizeof(struct ast_rtp); 00401 }
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 3278 of file rtp.c.
References AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, 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_DEBUG, LOG_WARNING, 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.
03279 { 03280 struct ast_rtp *p0 = NULL, *p1 = NULL; /* Audio RTP Channels */ 03281 struct ast_rtp *vp0 = NULL, *vp1 = NULL; /* Video RTP channels */ 03282 struct ast_rtp_protocol *pr0 = NULL, *pr1 = NULL; 03283 enum ast_rtp_get_result audio_p0_res = AST_RTP_GET_FAILED, video_p0_res = AST_RTP_GET_FAILED; 03284 enum ast_rtp_get_result audio_p1_res = AST_RTP_GET_FAILED, video_p1_res = AST_RTP_GET_FAILED; 03285 enum ast_bridge_result res = AST_BRIDGE_FAILED; 03286 int codec0 = 0, codec1 = 0; 03287 void *pvt0 = NULL, *pvt1 = NULL; 03288 03289 /* Lock channels */ 03290 ast_channel_lock(c0); 03291 while(ast_channel_trylock(c1)) { 03292 ast_channel_unlock(c0); 03293 usleep(1); 03294 ast_channel_lock(c0); 03295 } 03296 03297 /* Ensure neither channel got hungup during lock avoidance */ 03298 if (ast_check_hangup(c0) || ast_check_hangup(c1)) { 03299 ast_log(LOG_WARNING, "Got hangup while attempting to bridge '%s' and '%s'\n", c0->name, c1->name); 03300 ast_channel_unlock(c0); 03301 ast_channel_unlock(c1); 03302 return AST_BRIDGE_FAILED; 03303 } 03304 03305 /* Find channel driver interfaces */ 03306 if (!(pr0 = get_proto(c0))) { 03307 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name); 03308 ast_channel_unlock(c0); 03309 ast_channel_unlock(c1); 03310 return AST_BRIDGE_FAILED; 03311 } 03312 if (!(pr1 = get_proto(c1))) { 03313 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name); 03314 ast_channel_unlock(c0); 03315 ast_channel_unlock(c1); 03316 return AST_BRIDGE_FAILED; 03317 } 03318 03319 /* Get channel specific interface structures */ 03320 pvt0 = c0->tech_pvt; 03321 pvt1 = c1->tech_pvt; 03322 03323 /* Get audio and video interface (if native bridge is possible) */ 03324 audio_p0_res = pr0->get_rtp_info(c0, &p0); 03325 video_p0_res = pr0->get_vrtp_info ? pr0->get_vrtp_info(c0, &vp0) : AST_RTP_GET_FAILED; 03326 audio_p1_res = pr1->get_rtp_info(c1, &p1); 03327 video_p1_res = pr1->get_vrtp_info ? pr1->get_vrtp_info(c1, &vp1) : AST_RTP_GET_FAILED; 03328 03329 /* If we are carrying video, and both sides are not reinviting... then fail the native bridge */ 03330 if (video_p0_res != AST_RTP_GET_FAILED && (audio_p0_res != AST_RTP_TRY_NATIVE || video_p0_res != AST_RTP_TRY_NATIVE)) 03331 audio_p0_res = AST_RTP_GET_FAILED; 03332 if (video_p1_res != AST_RTP_GET_FAILED && (audio_p1_res != AST_RTP_TRY_NATIVE || video_p1_res != AST_RTP_TRY_NATIVE)) 03333 audio_p1_res = AST_RTP_GET_FAILED; 03334 03335 /* Check if a bridge is possible (partial/native) */ 03336 if (audio_p0_res == AST_RTP_GET_FAILED || audio_p1_res == AST_RTP_GET_FAILED) { 03337 /* Somebody doesn't want to play... */ 03338 ast_channel_unlock(c0); 03339 ast_channel_unlock(c1); 03340 return AST_BRIDGE_FAILED_NOWARN; 03341 } 03342 03343 /* If we need to feed DTMF frames into the core then only do a partial native bridge */ 03344 if (ast_test_flag(p0, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) { 03345 ast_set_flag(p0, FLAG_P2P_NEED_DTMF); 03346 audio_p0_res = AST_RTP_TRY_PARTIAL; 03347 } 03348 03349 if (ast_test_flag(p1, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)) { 03350 ast_set_flag(p1, FLAG_P2P_NEED_DTMF); 03351 audio_p1_res = AST_RTP_TRY_PARTIAL; 03352 } 03353 03354 /* If both sides are not using the same method of DTMF transmission 03355 * (ie: one is RFC2833, other is INFO... then we can not do direct media. 03356 * -------------------------------------------------- 03357 * | DTMF Mode | HAS_DTMF | Accepts Begin Frames | 03358 * |-----------|------------|-----------------------| 03359 * | Inband | False | True | 03360 * | RFC2833 | True | True | 03361 * | SIP INFO | False | False | 03362 * -------------------------------------------------- 03363 * However, if DTMF from both channels is being monitored by the core, then 03364 * we can still do packet-to-packet bridging, because passing through the 03365 * core will handle DTMF mode translation. 03366 */ 03367 if ( (ast_test_flag(p0, FLAG_HAS_DTMF) != ast_test_flag(p1, FLAG_HAS_DTMF)) || 03368 (!c0->tech->send_digit_begin != !c1->tech->send_digit_begin)) { 03369 if (!ast_test_flag(p0, FLAG_P2P_NEED_DTMF) || !ast_test_flag(p1, FLAG_P2P_NEED_DTMF)) { 03370 ast_channel_unlock(c0); 03371 ast_channel_unlock(c1); 03372 return AST_BRIDGE_FAILED_NOWARN; 03373 } 03374 audio_p0_res = AST_RTP_TRY_PARTIAL; 03375 audio_p1_res = AST_RTP_TRY_PARTIAL; 03376 } 03377 03378 /* If we need to feed frames into the core don't do a P2P bridge */ 03379 if ((audio_p0_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p0, FLAG_P2P_NEED_DTMF)) || 03380 (audio_p1_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p1, FLAG_P2P_NEED_DTMF))) { 03381 ast_channel_unlock(c0); 03382 ast_channel_unlock(c1); 03383 return AST_BRIDGE_FAILED_NOWARN; 03384 } 03385 03386 /* Get codecs from both sides */ 03387 codec0 = pr0->get_codec ? pr0->get_codec(c0) : 0; 03388 codec1 = pr1->get_codec ? pr1->get_codec(c1) : 0; 03389 if (codec0 && codec1 && !(codec0 & codec1)) { 03390 /* Hey, we can't do native bridging if both parties speak different codecs */ 03391 if (option_debug) 03392 ast_log(LOG_DEBUG, "Channel codec0 = %d is not codec1 = %d, cannot native bridge in RTP.\n", codec0, codec1); 03393 ast_channel_unlock(c0); 03394 ast_channel_unlock(c1); 03395 return AST_BRIDGE_FAILED_NOWARN; 03396 } 03397 03398 /* If either side can only do a partial bridge, then don't try for a true native bridge */ 03399 if (audio_p0_res == AST_RTP_TRY_PARTIAL || audio_p1_res == AST_RTP_TRY_PARTIAL) { 03400 struct ast_format_list fmt0, fmt1; 03401 03402 /* In order to do Packet2Packet bridging both sides must be in the same rawread/rawwrite */ 03403 if (c0->rawreadformat != c1->rawwriteformat || c1->rawreadformat != c0->rawwriteformat) { 03404 if (option_debug) 03405 ast_log(LOG_DEBUG, "Cannot packet2packet bridge - raw formats are incompatible\n"); 03406 ast_channel_unlock(c0); 03407 ast_channel_unlock(c1); 03408 return AST_BRIDGE_FAILED_NOWARN; 03409 } 03410 /* They must also be using the same packetization */ 03411 fmt0 = ast_codec_pref_getsize(&p0->pref, c0->rawreadformat); 03412 fmt1 = ast_codec_pref_getsize(&p1->pref, c1->rawreadformat); 03413 if (fmt0.cur_ms != fmt1.cur_ms) { 03414 if (option_debug) 03415 ast_log(LOG_DEBUG, "Cannot packet2packet bridge - packetization settings prevent it\n"); 03416 ast_channel_unlock(c0); 03417 ast_channel_unlock(c1); 03418 return AST_BRIDGE_FAILED_NOWARN; 03419 } 03420 03421 if (option_verbose > 2) 03422 ast_verbose(VERBOSE_PREFIX_3 "Packet2Packet bridging %s and %s\n", c0->name, c1->name); 03423 res = bridge_p2p_loop(c0, c1, p0, p1, timeoutms, flags, fo, rc, pvt0, pvt1); 03424 } else { 03425 if (option_verbose > 2) 03426 ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s\n", c0->name, c1->name); 03427 res = bridge_native_loop(c0, c1, p0, p1, vp0, vp1, pr0, pr1, codec0, codec1, timeoutms, flags, fo, rc, pvt0, pvt1); 03428 } 03429 03430 return res; 03431 }
int ast_rtp_codec_getformat | ( | int | pt | ) |
Definition at line 2722 of file rtp.c.
References rtpPayloadType::code, and MAX_RTP_PT.
Referenced by process_sdp().
02723 { 02724 if (pt < 0 || pt > MAX_RTP_PT) 02725 return 0; /* bogus payload type */ 02726 02727 if (static_RTP_PT[pt].isAstFormat) 02728 return static_RTP_PT[pt].code; 02729 else 02730 return 0; 02731 }
struct ast_codec_pref* ast_rtp_codec_getpref | ( | struct ast_rtp * | rtp | ) | [read] |
Definition at line 2717 of file rtp.c.
References ast_rtp::pref.
Referenced by add_codec_to_sdp(), and process_sdp().
02718 { 02719 return &rtp->pref; 02720 }
int ast_rtp_codec_setpref | ( | struct ast_rtp * | rtp, | |
struct ast_codec_pref * | prefs | |||
) |
Definition at line 2704 of file rtp.c.
References ast_smoother_free(), ast_codec_pref::framing, ast_codec_pref::order, ast_rtp::pref, and ast_rtp::smoother.
Referenced by __oh323_rtp_create(), check_user_full(), create_addr_from_peer(), process_sdp(), register_verify(), set_peer_capabilities(), sip_alloc(), start_rtp(), and transmit_response_with_sdp().
02705 { 02706 int x; 02707 for (x = 0; x < 32; x++) { /* Ugly way */ 02708 rtp->pref.order[x] = prefs->order[x]; 02709 rtp->pref.framing[x] = prefs->framing[x]; 02710 } 02711 if (rtp->smoother) 02712 ast_smoother_free(rtp->smoother); 02713 rtp->smoother = NULL; 02714 return 0; 02715 }
void ast_rtp_destroy | ( | struct ast_rtp * | rtp | ) |
Definition at line 2123 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(), skinny_hangup(), start_rtp(), and unalloc_sub().
02124 { 02125 if (rtcp_debug_test_addr(&rtp->them) || rtcpstats) { 02126 /*Print some info on the call here */ 02127 ast_verbose(" RTP-stats\n"); 02128 ast_verbose("* Our Receiver:\n"); 02129 ast_verbose(" SSRC: %u\n", rtp->themssrc); 02130 ast_verbose(" Received packets: %u\n", rtp->rxcount); 02131 ast_verbose(" Lost packets: %u\n", rtp->rtcp->expected_prior - rtp->rtcp->received_prior); 02132 ast_verbose(" Jitter: %.4f\n", rtp->rxjitter); 02133 ast_verbose(" Transit: %.4f\n", rtp->rxtransit); 02134 ast_verbose(" RR-count: %u\n", rtp->rtcp->rr_count); 02135 ast_verbose("* Our Sender:\n"); 02136 ast_verbose(" SSRC: %u\n", rtp->ssrc); 02137 ast_verbose(" Sent packets: %u\n", rtp->txcount); 02138 ast_verbose(" Lost packets: %u\n", rtp->rtcp->reported_lost); 02139 ast_verbose(" Jitter: %u\n", rtp->rtcp->reported_jitter / (unsigned int)65536.0); 02140 ast_verbose(" SR-count: %u\n", rtp->rtcp->sr_count); 02141 ast_verbose(" RTT: %f\n", rtp->rtcp->rtt); 02142 } 02143 02144 if (rtp->smoother) 02145 ast_smoother_free(rtp->smoother); 02146 if (rtp->ioid) 02147 ast_io_remove(rtp->io, rtp->ioid); 02148 if (rtp->s > -1) 02149 close(rtp->s); 02150 if (rtp->rtcp) { 02151 AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid); 02152 close(rtp->rtcp->s); 02153 free(rtp->rtcp); 02154 rtp->rtcp=NULL; 02155 } 02156 02157 ast_mutex_destroy(&rtp->bridge_lock); 02158 02159 free(rtp); 02160 }
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 1475 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, option_debug, and ast_rtp_protocol::set_rtp_peer.
Referenced by wait_for_answer().
01476 { 01477 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 01478 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 01479 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 01480 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED; 01481 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED; 01482 int srccodec, destcodec, nat_active = 0; 01483 01484 /* Lock channels */ 01485 ast_channel_lock(dest); 01486 if (src) { 01487 while(ast_channel_trylock(src)) { 01488 ast_channel_unlock(dest); 01489 usleep(1); 01490 ast_channel_lock(dest); 01491 } 01492 } 01493 01494 /* Find channel driver interfaces */ 01495 destpr = get_proto(dest); 01496 if (src) 01497 srcpr = get_proto(src); 01498 if (!destpr) { 01499 if (option_debug) 01500 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name); 01501 ast_channel_unlock(dest); 01502 if (src) 01503 ast_channel_unlock(src); 01504 return 0; 01505 } 01506 if (!srcpr) { 01507 if (option_debug) 01508 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src ? src->name : "<unspecified>"); 01509 ast_channel_unlock(dest); 01510 if (src) 01511 ast_channel_unlock(src); 01512 return 0; 01513 } 01514 01515 /* Get audio and video interface (if native bridge is possible) */ 01516 audio_dest_res = destpr->get_rtp_info(dest, &destp); 01517 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 01518 if (srcpr) { 01519 audio_src_res = srcpr->get_rtp_info(src, &srcp); 01520 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 01521 } 01522 01523 /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */ 01524 if (audio_dest_res != AST_RTP_TRY_NATIVE) { 01525 /* Somebody doesn't want to play... */ 01526 ast_channel_unlock(dest); 01527 if (src) 01528 ast_channel_unlock(src); 01529 return 0; 01530 } 01531 if (audio_src_res == AST_RTP_TRY_NATIVE && srcpr->get_codec) 01532 srccodec = srcpr->get_codec(src); 01533 else 01534 srccodec = 0; 01535 if (audio_dest_res == AST_RTP_TRY_NATIVE && destpr->get_codec) 01536 destcodec = destpr->get_codec(dest); 01537 else 01538 destcodec = 0; 01539 /* Ensure we have at least one matching codec */ 01540 if (!(srccodec & destcodec)) { 01541 ast_channel_unlock(dest); 01542 if (src) 01543 ast_channel_unlock(src); 01544 return 0; 01545 } 01546 /* Consider empty media as non-existant */ 01547 if (audio_src_res == AST_RTP_TRY_NATIVE && !srcp->them.sin_addr.s_addr) 01548 srcp = NULL; 01549 /* If the client has NAT stuff turned on then just safe NAT is active */ 01550 if (srcp && (srcp->nat || ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 01551 nat_active = 1; 01552 /* Bridge media early */ 01553 if (destpr->set_rtp_peer(dest, srcp, vsrcp, srccodec, nat_active)) 01554 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src ? src->name : "<unspecified>"); 01555 ast_channel_unlock(dest); 01556 if (src) 01557 ast_channel_unlock(src); 01558 if (option_debug) 01559 ast_log(LOG_DEBUG, "Setting early bridge SDP of '%s' with that of '%s'\n", dest->name, src ? src->name : "<unspecified>"); 01560 return 1; 01561 }
int ast_rtp_fd | ( | struct ast_rtp * | rtp | ) |
Definition at line 513 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().
00514 { 00515 return rtp->s; 00516 }
Definition at line 2034 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().
02035 { 02036 struct ast_rtp *bridged = NULL; 02037 02038 ast_mutex_lock(&rtp->bridge_lock); 02039 bridged = rtp->bridged; 02040 ast_mutex_unlock(&rtp->bridge_lock); 02041 02042 return bridged; 02043 }
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 1697 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 gtalk_is_answered(), gtalk_newcall(), and process_sdp().
01699 { 01700 int pt; 01701 01702 ast_mutex_lock(&rtp->bridge_lock); 01703 01704 *astFormats = *nonAstFormats = 0; 01705 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01706 if (rtp->current_RTP_PT[pt].isAstFormat) { 01707 *astFormats |= rtp->current_RTP_PT[pt].code; 01708 } else { 01709 *nonAstFormats |= rtp->current_RTP_PT[pt].code; 01710 } 01711 } 01712 01713 ast_mutex_unlock(&rtp->bridge_lock); 01714 01715 return; 01716 }
int ast_rtp_get_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | them | |||
) |
Definition at line 2016 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().
02017 { 02018 if ((them->sin_family != AF_INET) || 02019 (them->sin_port != rtp->them.sin_port) || 02020 (them->sin_addr.s_addr != rtp->them.sin_addr.s_addr)) { 02021 them->sin_family = AF_INET; 02022 them->sin_port = rtp->them.sin_port; 02023 them->sin_addr = rtp->them.sin_addr; 02024 return 1; 02025 } 02026 return 0; 02027 }
char* ast_rtp_get_quality | ( | struct ast_rtp * | rtp, | |
struct ast_rtp_quality * | qual | |||
) |
Return RTCP quality string.
Definition at line 2079 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().
02080 { 02081 /* 02082 *ssrc our ssrc 02083 *themssrc their ssrc 02084 *lp lost packets 02085 *rxjitter our calculated jitter(rx) 02086 *rxcount no. received packets 02087 *txjitter reported jitter of the other end 02088 *txcount transmitted packets 02089 *rlp remote lost packets 02090 *rtt round trip time 02091 */ 02092 02093 if (qual && rtp) { 02094 qual->local_ssrc = rtp->ssrc; 02095 qual->local_jitter = rtp->rxjitter; 02096 qual->local_count = rtp->rxcount; 02097 qual->remote_ssrc = rtp->themssrc; 02098 qual->remote_count = rtp->txcount; 02099 if (rtp->rtcp) { 02100 qual->local_lostpackets = rtp->rtcp->expected_prior - rtp->rtcp->received_prior; 02101 qual->remote_lostpackets = rtp->rtcp->reported_lost; 02102 qual->remote_jitter = rtp->rtcp->reported_jitter / 65536.0; 02103 qual->rtt = rtp->rtcp->rtt; 02104 } 02105 } 02106 if (rtp->rtcp) { 02107 snprintf(rtp->rtcp->quality, sizeof(rtp->rtcp->quality), 02108 "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;txjitter=%f;txcount=%u;rlp=%u;rtt=%f", 02109 rtp->ssrc, 02110 rtp->themssrc, 02111 rtp->rtcp->expected_prior - rtp->rtcp->received_prior, 02112 rtp->rxjitter, 02113 rtp->rxcount, 02114 (double)rtp->rtcp->reported_jitter / 65536.0, 02115 rtp->txcount, 02116 rtp->rtcp->reported_lost, 02117 rtp->rtcp->rtt); 02118 return rtp->rtcp->quality; 02119 } else 02120 return "<Unknown> - RTP/RTCP has already been destroyed"; 02121 }
int ast_rtp_get_rtpholdtimeout | ( | struct ast_rtp * | rtp | ) |
Get rtp hold timeout.
Definition at line 568 of file rtp.c.
References ast_rtp::rtpholdtimeout, and ast_rtp::rtptimeout.
Referenced by do_monitor().
00569 { 00570 if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */ 00571 return 0; 00572 return rtp->rtpholdtimeout; 00573 }
int ast_rtp_get_rtpkeepalive | ( | struct ast_rtp * | rtp | ) |
Get RTP keepalive interval.
Definition at line 576 of file rtp.c.
References ast_rtp::rtpkeepalive.
Referenced by do_monitor().
00577 { 00578 return rtp->rtpkeepalive; 00579 }
int ast_rtp_get_rtptimeout | ( | struct ast_rtp * | rtp | ) |
Get rtp timeout.
Definition at line 560 of file rtp.c.
References ast_rtp::rtptimeout.
Referenced by do_monitor().
00561 { 00562 if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */ 00563 return 0; 00564 return rtp->rtptimeout; 00565 }
void ast_rtp_get_us | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | us | |||
) |
Definition at line 2029 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 596 of file rtp.c.
References ast_test_flag, and FLAG_NAT_ACTIVE.
Referenced by sip_get_rtp_peer().
00597 { 00598 return ast_test_flag(rtp, FLAG_NAT_ACTIVE); 00599 }
void ast_rtp_init | ( | void | ) |
Initialize the RTP system in Asterisk.
Definition at line 3816 of file rtp.c.
References ast_cli_register_multiple(), and ast_rtp_reload().
Referenced by main().
03817 { 03818 ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry)); 03819 ast_rtp_reload(); 03820 }
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 1740 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().
01741 { 01742 int pt = 0; 01743 01744 ast_mutex_lock(&rtp->bridge_lock); 01745 01746 if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && 01747 code == rtp->rtp_lookup_code_cache_code) { 01748 /* Use our cached mapping, to avoid the overhead of the loop below */ 01749 pt = rtp->rtp_lookup_code_cache_result; 01750 ast_mutex_unlock(&rtp->bridge_lock); 01751 return pt; 01752 } 01753 01754 /* Check the dynamic list first */ 01755 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01756 if (rtp->current_RTP_PT[pt].code == code && rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) { 01757 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 01758 rtp->rtp_lookup_code_cache_code = code; 01759 rtp->rtp_lookup_code_cache_result = pt; 01760 ast_mutex_unlock(&rtp->bridge_lock); 01761 return pt; 01762 } 01763 } 01764 01765 /* Then the static list */ 01766 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01767 if (static_RTP_PT[pt].code == code && static_RTP_PT[pt].isAstFormat == isAstFormat) { 01768 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 01769 rtp->rtp_lookup_code_cache_code = code; 01770 rtp->rtp_lookup_code_cache_result = pt; 01771 ast_mutex_unlock(&rtp->bridge_lock); 01772 return pt; 01773 } 01774 } 01775 01776 ast_mutex_unlock(&rtp->bridge_lock); 01777 01778 return -1; 01779 }
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 1800 of file rtp.c.
References ast_rtp_lookup_mime_subtype(), AST_RTP_MAX, format, len, and name.
Referenced by process_sdp().
01802 { 01803 int format; 01804 unsigned len; 01805 char *end = buf; 01806 char *start = buf; 01807 01808 if (!buf || !size) 01809 return NULL; 01810 01811 snprintf(end, size, "0x%x (", capability); 01812 01813 len = strlen(end); 01814 end += len; 01815 size -= len; 01816 start = end; 01817 01818 for (format = 1; format < AST_RTP_MAX; format <<= 1) { 01819 if (capability & format) { 01820 const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format, options); 01821 01822 snprintf(end, size, "%s|", name); 01823 len = strlen(end); 01824 end += len; 01825 size -= len; 01826 } 01827 } 01828 01829 if (start == end) 01830 snprintf(start, size, "nothing)"); 01831 else if (size > 1) 01832 *(end -1) = ')'; 01833 01834 return buf; 01835 }
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 1781 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().
01783 { 01784 unsigned int i; 01785 01786 for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { 01787 if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) { 01788 if (isAstFormat && 01789 (code == AST_FORMAT_G726_AAL2) && 01790 (options & AST_RTP_OPT_G726_NONSTANDARD)) 01791 return "G726-32"; 01792 else 01793 return mimeTypes[i].subtype; 01794 } 01795 } 01796 01797 return ""; 01798 }
struct rtpPayloadType ast_rtp_lookup_pt | ( | struct ast_rtp * | rtp, | |
int | pt | |||
) | [read] |
Mapping between RTP payload format codes and Asterisk codes:.
Definition at line 1718 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), rtpPayloadType::code, rtpPayloadType::isAstFormat, and MAX_RTP_PT.
Referenced by ast_rtp_read(), bridge_p2p_rtp_write(), and setup_rtp_connection().
01719 { 01720 struct rtpPayloadType result; 01721 01722 result.isAstFormat = result.code = 0; 01723 01724 if (pt < 0 || pt > MAX_RTP_PT) 01725 return result; /* bogus payload type */ 01726 01727 /* Start with negotiated codecs */ 01728 ast_mutex_lock(&rtp->bridge_lock); 01729 result = rtp->current_RTP_PT[pt]; 01730 ast_mutex_unlock(&rtp->bridge_lock); 01731 01732 /* If it doesn't exist, check our static RTP type list, just in case */ 01733 if (!result.code) 01734 result = static_RTP_PT[pt]; 01735 01736 return result; 01737 }
int ast_rtp_make_compatible | ( | struct ast_channel * | dest, | |
struct ast_channel * | src, | |||
int | media | |||
) |
Definition at line 1563 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, option_debug, and ast_rtp_protocol::set_rtp_peer.
Referenced by wait_for_answer().
01564 { 01565 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 01566 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 01567 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 01568 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED; 01569 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED; 01570 int srccodec, destcodec; 01571 01572 /* Lock channels */ 01573 ast_channel_lock(dest); 01574 while(ast_channel_trylock(src)) { 01575 ast_channel_unlock(dest); 01576 usleep(1); 01577 ast_channel_lock(dest); 01578 } 01579 01580 /* Find channel driver interfaces */ 01581 if (!(destpr = get_proto(dest))) { 01582 if (option_debug) 01583 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name); 01584 ast_channel_unlock(dest); 01585 ast_channel_unlock(src); 01586 return 0; 01587 } 01588 if (!(srcpr = get_proto(src))) { 01589 if (option_debug) 01590 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src->name); 01591 ast_channel_unlock(dest); 01592 ast_channel_unlock(src); 01593 return 0; 01594 } 01595 01596 /* Get audio and video interface (if native bridge is possible) */ 01597 audio_dest_res = destpr->get_rtp_info(dest, &destp); 01598 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 01599 audio_src_res = srcpr->get_rtp_info(src, &srcp); 01600 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 01601 01602 /* Ensure we have at least one matching codec */ 01603 if (srcpr->get_codec) 01604 srccodec = srcpr->get_codec(src); 01605 else 01606 srccodec = 0; 01607 if (destpr->get_codec) 01608 destcodec = destpr->get_codec(dest); 01609 else 01610 destcodec = 0; 01611 01612 /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */ 01613 if (audio_dest_res != AST_RTP_TRY_NATIVE || audio_src_res != AST_RTP_TRY_NATIVE || !(srccodec & destcodec)) { 01614 /* Somebody doesn't want to play... */ 01615 ast_channel_unlock(dest); 01616 ast_channel_unlock(src); 01617 return 0; 01618 } 01619 ast_rtp_pt_copy(destp, srcp); 01620 if (vdestp && vsrcp) 01621 ast_rtp_pt_copy(vdestp, vsrcp); 01622 if (media) { 01623 /* Bridge early */ 01624 if (destpr->set_rtp_peer(dest, srcp, vsrcp, srccodec, ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 01625 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src->name); 01626 } 01627 ast_channel_unlock(dest); 01628 ast_channel_unlock(src); 01629 if (option_debug) 01630 ast_log(LOG_DEBUG, "Seeded SDP of '%s' with that of '%s'\n", dest->name, src->name); 01631 return 1; 01632 }
struct ast_rtp* ast_rtp_new | ( | struct sched_context * | sched, | |
struct io_context * | io, | |||
int | rtcpenable, | |||
int | callbackmode | |||
) | [read] |
Initializate a RTP session.
sched | ||
io | ||
rtcpenable | ||
callbackmode |
Definition at line 1982 of file rtp.c.
References ast_rtp_new_with_bindaddr().
01983 { 01984 struct in_addr ia; 01985 01986 memset(&ia, 0, sizeof(ia)); 01987 return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia); 01988 }
void ast_rtp_new_init | ( | struct ast_rtp * | rtp | ) |
Initialize a new RTP structure.
Definition at line 1882 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().
01883 { 01884 ast_mutex_init(&rtp->bridge_lock); 01885 01886 rtp->them.sin_family = AF_INET; 01887 rtp->us.sin_family = AF_INET; 01888 rtp->ssrc = ast_random(); 01889 rtp->seqno = ast_random() & 0xffff; 01890 ast_set_flag(rtp, FLAG_HAS_DTMF); 01891 01892 return; 01893 }
void ast_rtp_new_source | ( | struct ast_rtp * | rtp | ) |
Definition at line 1999 of file rtp.c.
References ast_rtp::set_marker_bit.
Referenced by mgcp_indicate(), oh323_indicate(), sip_indicate(), sip_write(), and skinny_indicate().
02000 { 02001 rtp->set_marker_bit = 1; 02002 return; 02003 }
struct ast_rtp* ast_rtp_new_with_bindaddr | ( | struct sched_context * | sched, | |
struct io_context * | io, | |||
int | rtcpenable, | |||
int | callbackmode, | |||
struct in_addr | in | |||
) | [read] |
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 1895 of file rtp.c.
References ast_calloc, ast_io_add(), AST_IO_IN, ast_log(), ast_random(), ast_rtcp_new(), ast_rtp_new_init(), ast_rtp_pt_default(), ast_set_flag, errno, FLAG_CALLBACK_MODE, free, ast_rtp::io, ast_rtp::ioid, LOG_ERROR, ast_rtp::rtcp, rtp_socket(), rtpread(), ast_rtcp::s, ast_rtp::s, ast_rtp::sched, ast_rtcp::us, and ast_rtp::us.
Referenced by __oh323_rtp_create(), ast_rtp_new(), gtalk_alloc(), sip_alloc(), and start_rtp().
01896 { 01897 struct ast_rtp *rtp; 01898 int x; 01899 int first; 01900 int startplace; 01901 01902 if (!(rtp = ast_calloc(1, sizeof(*rtp)))) 01903 return NULL; 01904 01905 ast_rtp_new_init(rtp); 01906 01907 rtp->s = rtp_socket(); 01908 if (rtp->s < 0) { 01909 free(rtp); 01910 ast_log(LOG_ERROR, "Unable to allocate socket: %s\n", strerror(errno)); 01911 return NULL; 01912 } 01913 if (sched && rtcpenable) { 01914 rtp->sched = sched; 01915 rtp->rtcp = ast_rtcp_new(); 01916 } 01917 01918 /* Select a random port number in the range of possible RTP */ 01919 x = (ast_random() % (rtpend-rtpstart)) + rtpstart; 01920 x = x & ~1; 01921 /* Save it for future references. */ 01922 startplace = x; 01923 /* Iterate tring to bind that port and incrementing it otherwise untill a port was found or no ports are available. */ 01924 for (;;) { 01925 /* Must be an even port number by RTP spec */ 01926 rtp->us.sin_port = htons(x); 01927 rtp->us.sin_addr = addr; 01928 /* If there's rtcp, initialize it as well. */ 01929 if (rtp->rtcp) { 01930 rtp->rtcp->us.sin_port = htons(x + 1); 01931 rtp->rtcp->us.sin_addr = addr; 01932 } 01933 /* Try to bind it/them. */ 01934 if (!(first = bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us))) && 01935 (!rtp->rtcp || !bind(rtp->rtcp->s, (struct sockaddr *)&rtp->rtcp->us, sizeof(rtp->rtcp->us)))) 01936 break; 01937 if (!first) { 01938 /* Primary bind succeeded! Gotta recreate it */ 01939 close(rtp->s); 01940 rtp->s = rtp_socket(); 01941 } 01942 if (errno != EADDRINUSE) { 01943 /* We got an error that wasn't expected, abort! */ 01944 ast_log(LOG_ERROR, "Unexpected bind error: %s\n", strerror(errno)); 01945 close(rtp->s); 01946 if (rtp->rtcp) { 01947 close(rtp->rtcp->s); 01948 free(rtp->rtcp); 01949 } 01950 free(rtp); 01951 return NULL; 01952 } 01953 /* The port was used, increment it (by two). */ 01954 x += 2; 01955 /* Did we go over the limit ? */ 01956 if (x > rtpend) 01957 /* then, start from the begingig. */ 01958 x = (rtpstart + 1) & ~1; 01959 /* Check if we reached the place were we started. */ 01960 if (x == startplace) { 01961 /* If so, there's no ports available. */ 01962 ast_log(LOG_ERROR, "No RTP ports remaining. Can't setup media stream for this call.\n"); 01963 close(rtp->s); 01964 if (rtp->rtcp) { 01965 close(rtp->rtcp->s); 01966 free(rtp->rtcp); 01967 } 01968 free(rtp); 01969 return NULL; 01970 } 01971 } 01972 rtp->sched = sched; 01973 rtp->io = io; 01974 if (callbackmode) { 01975 rtp->ioid = ast_io_add(rtp->io, rtp->s, rtpread, AST_IO_IN, rtp); 01976 ast_set_flag(rtp, FLAG_CALLBACK_MODE); 01977 } 01978 ast_rtp_pt_default(rtp); 01979 return rtp; 01980 }
int ast_rtp_proto_register | ( | struct ast_rtp_protocol * | proto | ) |
Register interface to channel driver.
Definition at line 2833 of file rtp.c.
References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), LOG_WARNING, protos, and ast_rtp_protocol::type.
Referenced by load_module().
02834 { 02835 struct ast_rtp_protocol *cur; 02836 02837 AST_LIST_LOCK(&protos); 02838 AST_LIST_TRAVERSE(&protos, cur, list) { 02839 if (!strcmp(cur->type, proto->type)) { 02840 ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type); 02841 AST_LIST_UNLOCK(&protos); 02842 return -1; 02843 } 02844 } 02845 AST_LIST_INSERT_HEAD(&protos, proto, list); 02846 AST_LIST_UNLOCK(&protos); 02847 02848 return 0; 02849 }
void ast_rtp_proto_unregister | ( | struct ast_rtp_protocol * | proto | ) |
Unregister interface to channel driver.
Definition at line 2825 of file rtp.c.
References AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, and protos.
Referenced by load_module(), and unload_module().
02826 { 02827 AST_LIST_LOCK(&protos); 02828 AST_LIST_REMOVE(&protos, proto, list); 02829 AST_LIST_UNLOCK(&protos); 02830 }
void ast_rtp_pt_clear | ( | struct ast_rtp * | rtp | ) |
Setting RTP payload types from lines in a SDP description:.
Definition at line 1399 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().
01400 { 01401 int i; 01402 01403 if (!rtp) 01404 return; 01405 01406 ast_mutex_lock(&rtp->bridge_lock); 01407 01408 for (i = 0; i < MAX_RTP_PT; ++i) { 01409 rtp->current_RTP_PT[i].isAstFormat = 0; 01410 rtp->current_RTP_PT[i].code = 0; 01411 } 01412 01413 rtp->rtp_lookup_code_cache_isAstFormat = 0; 01414 rtp->rtp_lookup_code_cache_code = 0; 01415 rtp->rtp_lookup_code_cache_result = 0; 01416 01417 ast_mutex_unlock(&rtp->bridge_lock); 01418 }
Copy payload types between RTP structures.
Definition at line 1439 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().
01440 { 01441 unsigned int i; 01442 01443 ast_mutex_lock(&dest->bridge_lock); 01444 ast_mutex_lock(&src->bridge_lock); 01445 01446 for (i=0; i < MAX_RTP_PT; ++i) { 01447 dest->current_RTP_PT[i].isAstFormat = 01448 src->current_RTP_PT[i].isAstFormat; 01449 dest->current_RTP_PT[i].code = 01450 src->current_RTP_PT[i].code; 01451 } 01452 dest->rtp_lookup_code_cache_isAstFormat = 0; 01453 dest->rtp_lookup_code_cache_code = 0; 01454 dest->rtp_lookup_code_cache_result = 0; 01455 01456 ast_mutex_unlock(&src->bridge_lock); 01457 ast_mutex_unlock(&dest->bridge_lock); 01458 }
void ast_rtp_pt_default | ( | struct ast_rtp * | rtp | ) |
Set payload types to defaults.
Definition at line 1420 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_new_with_bindaddr().
01421 { 01422 int i; 01423 01424 ast_mutex_lock(&rtp->bridge_lock); 01425 01426 /* Initialize to default payload types */ 01427 for (i = 0; i < MAX_RTP_PT; ++i) { 01428 rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat; 01429 rtp->current_RTP_PT[i].code = static_RTP_PT[i].code; 01430 } 01431 01432 rtp->rtp_lookup_code_cache_isAstFormat = 0; 01433 rtp->rtp_lookup_code_cache_code = 0; 01434 rtp->rtp_lookup_code_cache_result = 0; 01435 01436 ast_mutex_unlock(&rtp->bridge_lock); 01437 }
Definition at line 1104 of file rtp.c.
References ast_assert, ast_codec_get_samples(), AST_FORMAT_MAX_AUDIO, ast_format_rate(), AST_FORMAT_SLINEAR, ast_frame_byteswap_be, AST_FRAME_VIDEO, AST_FRAME_VOICE, AST_FRFLAG_HAS_TIMING_INFO, AST_FRIENDLY_OFFSET, ast_inet_ntoa(), 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_sched_add(), ast_set_flag, ast_verbose(), bridge_p2p_rtp_write(), ast_rtp::bridged, calc_rxstamp(), rtpPayloadType::code, ast_rtp::cycles, ast_frame::data, ast_frame::datalen, ast_frame::delivery, errno, event, ext, ast_rtp::f, f, FLAG_NAT_ACTIVE, 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::rtcp, rtp_debug_test_addr(), RTP_SEQ_MOD, ast_rtp::rxcount, ast_rtp::rxseqno, ast_rtp::rxssrc, 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().
01105 { 01106 int res; 01107 struct sockaddr_in sin; 01108 socklen_t len; 01109 unsigned int seqno; 01110 int version; 01111 int payloadtype; 01112 int hdrlen = 12; 01113 int padding; 01114 int mark; 01115 int ext; 01116 int cc; 01117 unsigned int ssrc; 01118 unsigned int timestamp; 01119 unsigned int *rtpheader; 01120 struct rtpPayloadType rtpPT; 01121 struct ast_rtp *bridged = NULL; 01122 01123 /* If time is up, kill it */ 01124 if (rtp->sending_digit) 01125 ast_rtp_senddigit_continuation(rtp); 01126 01127 len = sizeof(sin); 01128 01129 /* Cache where the header will go */ 01130 res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET, 01131 0, (struct sockaddr *)&sin, &len); 01132 01133 rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET); 01134 if (res < 0) { 01135 ast_assert(errno != EBADF); 01136 if (errno != EAGAIN) { 01137 ast_log(LOG_WARNING, "RTP Read error: %s. Hanging up.\n", strerror(errno)); 01138 return NULL; 01139 } 01140 return &ast_null_frame; 01141 } 01142 01143 if (res < hdrlen) { 01144 ast_log(LOG_WARNING, "RTP Read too short\n"); 01145 return &ast_null_frame; 01146 } 01147 01148 /* Get fields */ 01149 seqno = ntohl(rtpheader[0]); 01150 01151 /* Check RTP version */ 01152 version = (seqno & 0xC0000000) >> 30; 01153 if (!version) { 01154 if ((stun_handle_packet(rtp->s, &sin, rtp->rawdata + AST_FRIENDLY_OFFSET, res) == STUN_ACCEPT) && 01155 (!rtp->them.sin_port && !rtp->them.sin_addr.s_addr)) { 01156 memcpy(&rtp->them, &sin, sizeof(rtp->them)); 01157 } 01158 return &ast_null_frame; 01159 } 01160 01161 #if 0 /* Allow to receive RTP stream with closed transmission path */ 01162 /* If we don't have the other side's address, then ignore this */ 01163 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 01164 return &ast_null_frame; 01165 #endif 01166 01167 /* Send to whoever send to us if NAT is turned on */ 01168 if (rtp->nat) { 01169 if ((rtp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || 01170 (rtp->them.sin_port != sin.sin_port)) { 01171 rtp->them = sin; 01172 if (rtp->rtcp) { 01173 memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); 01174 rtp->rtcp->them.sin_port = htons(ntohs(rtp->them.sin_port)+1); 01175 } 01176 rtp->rxseqno = 0; 01177 ast_set_flag(rtp, FLAG_NAT_ACTIVE); 01178 if (option_debug || rtpdebug) 01179 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)); 01180 } 01181 } 01182 01183 /* If we are bridged to another RTP stream, send direct */ 01184 if ((bridged = ast_rtp_get_bridged(rtp)) && !bridge_p2p_rtp_write(rtp, bridged, rtpheader, res, hdrlen)) 01185 return &ast_null_frame; 01186 01187 if (version != 2) 01188 return &ast_null_frame; 01189 01190 payloadtype = (seqno & 0x7f0000) >> 16; 01191 padding = seqno & (1 << 29); 01192 mark = seqno & (1 << 23); 01193 ext = seqno & (1 << 28); 01194 cc = (seqno & 0xF000000) >> 24; 01195 seqno &= 0xffff; 01196 timestamp = ntohl(rtpheader[1]); 01197 ssrc = ntohl(rtpheader[2]); 01198 01199 if (!mark && rtp->rxssrc && rtp->rxssrc != ssrc) { 01200 if (option_debug || rtpdebug) 01201 ast_log(LOG_DEBUG, "Forcing Marker bit, because SSRC has changed\n"); 01202 mark = 1; 01203 } 01204 01205 rtp->rxssrc = ssrc; 01206 01207 if (padding) { 01208 /* Remove padding bytes */ 01209 res -= rtp->rawdata[AST_FRIENDLY_OFFSET + res - 1]; 01210 } 01211 01212 if (cc) { 01213 /* CSRC fields present */ 01214 hdrlen += cc*4; 01215 } 01216 01217 if (ext) { 01218 /* RTP Extension present */ 01219 hdrlen += (ntohl(rtpheader[hdrlen/4]) & 0xffff) << 2; 01220 hdrlen += 4; 01221 } 01222 01223 if (res < hdrlen) { 01224 ast_log(LOG_WARNING, "RTP Read too short (%d, expecting %d)\n", res, hdrlen); 01225 return &ast_null_frame; 01226 } 01227 01228 rtp->rxcount++; /* Only count reasonably valid packets, this'll make the rtcp stats more accurate */ 01229 01230 if (rtp->rxcount==1) { 01231 /* This is the first RTP packet successfully received from source */ 01232 rtp->seedrxseqno = seqno; 01233 } 01234 01235 /* Do not schedule RR if RTCP isn't run */ 01236 if (rtp->rtcp && rtp->rtcp->them.sin_addr.s_addr && rtp->rtcp->schedid < 1) { 01237 /* Schedule transmission of Receiver Report */ 01238 rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, rtp); 01239 } 01240 if ( (int)rtp->lastrxseqno - (int)seqno > 100) /* if so it would indicate that the sender cycled; allow for misordering */ 01241 rtp->cycles += RTP_SEQ_MOD; 01242 01243 rtp->lastrxseqno = seqno; 01244 01245 if (rtp->themssrc==0) 01246 rtp->themssrc = ntohl(rtpheader[2]); /* Record their SSRC to put in future RR */ 01247 01248 if (rtp_debug_test_addr(&sin)) 01249 ast_verbose("Got RTP packet from %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 01250 ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen); 01251 01252 rtpPT = ast_rtp_lookup_pt(rtp, payloadtype); 01253 if (!rtpPT.isAstFormat) { 01254 struct ast_frame *f = NULL; 01255 01256 /* This is special in-band data that's not one of our codecs */ 01257 if (rtpPT.code == AST_RTP_DTMF) { 01258 /* It's special -- rfc2833 process it */ 01259 if (rtp_debug_test_addr(&sin)) { 01260 unsigned char *data; 01261 unsigned int event; 01262 unsigned int event_end; 01263 unsigned int duration; 01264 data = rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen; 01265 event = ntohl(*((unsigned int *)(data))); 01266 event >>= 24; 01267 event_end = ntohl(*((unsigned int *)(data))); 01268 event_end <<= 8; 01269 event_end >>= 24; 01270 duration = ntohl(*((unsigned int *)(data))); 01271 duration &= 0xFFFF; 01272 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); 01273 } 01274 f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp); 01275 } else if (rtpPT.code == AST_RTP_CISCO_DTMF) { 01276 /* It's really special -- process it the Cisco way */ 01277 if (rtp->lastevent <= seqno || (rtp->lastevent >= 65530 && seqno <= 6)) { 01278 f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01279 rtp->lastevent = seqno; 01280 } 01281 } else if (rtpPT.code == AST_RTP_CN) { 01282 /* Comfort Noise */ 01283 f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01284 } else { 01285 ast_log(LOG_NOTICE, "Unknown RTP codec %d received from '%s'\n", payloadtype, ast_inet_ntoa(rtp->them.sin_addr)); 01286 } 01287 return f ? f : &ast_null_frame; 01288 } 01289 rtp->lastrxformat = rtp->f.subclass = rtpPT.code; 01290 rtp->f.frametype = (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) ? AST_FRAME_VOICE : AST_FRAME_VIDEO; 01291 01292 if (!rtp->lastrxts) 01293 rtp->lastrxts = timestamp; 01294 01295 rtp->rxseqno = seqno; 01296 01297 /* Record received timestamp as last received now */ 01298 rtp->lastrxts = timestamp; 01299 01300 rtp->f.mallocd = 0; 01301 rtp->f.datalen = res - hdrlen; 01302 rtp->f.data = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET; 01303 rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET; 01304 rtp->f.seqno = seqno; 01305 if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) { 01306 rtp->f.samples = ast_codec_get_samples(&rtp->f); 01307 if (rtp->f.subclass == AST_FORMAT_SLINEAR) 01308 ast_frame_byteswap_be(&rtp->f); 01309 calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark); 01310 /* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */ 01311 ast_set_flag(&rtp->f, AST_FRFLAG_HAS_TIMING_INFO); 01312 rtp->f.ts = timestamp / 8; 01313 rtp->f.len = rtp->f.samples / (ast_format_rate(rtp->f.subclass) / 1000); 01314 } else { 01315 /* Video -- samples is # of samples vs. 90000 */ 01316 if (!rtp->lastividtimestamp) 01317 rtp->lastividtimestamp = timestamp; 01318 rtp->f.samples = timestamp - rtp->lastividtimestamp; 01319 rtp->lastividtimestamp = timestamp; 01320 rtp->f.delivery.tv_sec = 0; 01321 rtp->f.delivery.tv_usec = 0; 01322 if (mark) 01323 rtp->f.subclass |= 0x1; 01324 01325 } 01326 rtp->f.src = "RTP"; 01327 return &rtp->f; 01328 }
int ast_rtp_reload | ( | void | ) |
Definition at line 3751 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().
03752 { 03753 struct ast_config *cfg; 03754 const char *s; 03755 03756 rtpstart = 5000; 03757 rtpend = 31000; 03758 dtmftimeout = DEFAULT_DTMF_TIMEOUT; 03759 cfg = ast_config_load("rtp.conf"); 03760 if (cfg) { 03761 if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) { 03762 rtpstart = atoi(s); 03763 if (rtpstart < 1024) 03764 rtpstart = 1024; 03765 if (rtpstart > 65535) 03766 rtpstart = 65535; 03767 } 03768 if ((s = ast_variable_retrieve(cfg, "general", "rtpend"))) { 03769 rtpend = atoi(s); 03770 if (rtpend < 1024) 03771 rtpend = 1024; 03772 if (rtpend > 65535) 03773 rtpend = 65535; 03774 } 03775 if ((s = ast_variable_retrieve(cfg, "general", "rtcpinterval"))) { 03776 rtcpinterval = atoi(s); 03777 if (rtcpinterval == 0) 03778 rtcpinterval = 0; /* Just so we're clear... it's zero */ 03779 if (rtcpinterval < RTCP_MIN_INTERVALMS) 03780 rtcpinterval = RTCP_MIN_INTERVALMS; /* This catches negative numbers too */ 03781 if (rtcpinterval > RTCP_MAX_INTERVALMS) 03782 rtcpinterval = RTCP_MAX_INTERVALMS; 03783 } 03784 if ((s = ast_variable_retrieve(cfg, "general", "rtpchecksums"))) { 03785 #ifdef SO_NO_CHECK 03786 if (ast_false(s)) 03787 nochecksums = 1; 03788 else 03789 nochecksums = 0; 03790 #else 03791 if (ast_false(s)) 03792 ast_log(LOG_WARNING, "Disabling RTP checksums is not supported on this operating system!\n"); 03793 #endif 03794 } 03795 if ((s = ast_variable_retrieve(cfg, "general", "dtmftimeout"))) { 03796 dtmftimeout = atoi(s); 03797 if ((dtmftimeout < 0) || (dtmftimeout > 20000)) { 03798 ast_log(LOG_WARNING, "DTMF timeout of '%d' outside range, using default of '%d' instead\n", 03799 dtmftimeout, DEFAULT_DTMF_TIMEOUT); 03800 dtmftimeout = DEFAULT_DTMF_TIMEOUT; 03801 }; 03802 } 03803 ast_config_destroy(cfg); 03804 } 03805 if (rtpstart >= rtpend) { 03806 ast_log(LOG_WARNING, "Unreasonable values for RTP start/end port in rtp.conf\n"); 03807 rtpstart = 5000; 03808 rtpend = 31000; 03809 } 03810 if (option_verbose > 1) 03811 ast_verbose(VERBOSE_PREFIX_2 "RTP Allocating from port range %d -> %d\n", rtpstart, rtpend); 03812 return 0; 03813 }
void ast_rtp_reset | ( | struct ast_rtp * | rtp | ) |
Definition at line 2059 of file rtp.c.
References ast_rtp::dtmfcount, ast_rtp::dtmfmute, ast_rtp::dtmfsamples, 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.
02060 { 02061 memset(&rtp->rxcore, 0, sizeof(rtp->rxcore)); 02062 memset(&rtp->txcore, 0, sizeof(rtp->txcore)); 02063 memset(&rtp->dtmfmute, 0, sizeof(rtp->dtmfmute)); 02064 rtp->lastts = 0; 02065 rtp->lastdigitts = 0; 02066 rtp->lastrxts = 0; 02067 rtp->lastividtimestamp = 0; 02068 rtp->lastovidtimestamp = 0; 02069 rtp->lasteventseqn = 0; 02070 rtp->lastevent = 0; 02071 rtp->lasttxformat = 0; 02072 rtp->lastrxformat = 0; 02073 rtp->dtmfcount = 0; 02074 rtp->dtmfsamples = 0; 02075 rtp->seqno = 0; 02076 rtp->rxseqno = 0; 02077 }
int ast_rtp_sendcng | ( | struct ast_rtp * | rtp, | |
int | level | |||
) |
generate comfort noice (CNG)
Definition at line 2574 of file rtp.c.
References ast_inet_ntoa(), ast_log(), AST_RTP_CN, ast_rtp_lookup_code(), ast_tvadd(), 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().
02575 { 02576 unsigned int *rtpheader; 02577 int hdrlen = 12; 02578 int res; 02579 int payload; 02580 char data[256]; 02581 level = 127 - (level & 0x7f); 02582 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_CN); 02583 02584 /* If we have no peer, return immediately */ 02585 if (!rtp->them.sin_addr.s_addr) 02586 return 0; 02587 02588 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 02589 02590 /* Get a pointer to the header */ 02591 rtpheader = (unsigned int *)data; 02592 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno++)); 02593 rtpheader[1] = htonl(rtp->lastts); 02594 rtpheader[2] = htonl(rtp->ssrc); 02595 data[12] = level; 02596 if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) { 02597 res = sendto(rtp->s, (void *)rtpheader, hdrlen + 1, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them)); 02598 if (res <0) 02599 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)); 02600 if (rtp_debug_test_addr(&rtp->them)) 02601 ast_verbose("Sent Comfort Noise RTP packet to %s:%u (type %d, seq %u, ts %u, len %d)\n" 02602 , ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen); 02603 02604 } 02605 return 0; 02606 }
int ast_rtp_senddigit_begin | ( | struct ast_rtp * | rtp, | |
char | digit | |||
) |
Send begin frames for DTMF.
Definition at line 2182 of file rtp.c.
References ast_inet_ntoa(), ast_log(), AST_RTP_DTMF, ast_rtp_lookup_code(), ast_tvadd(), ast_verbose(), ast_rtp::dtmfmute, errno, ast_rtp::lastdigitts, 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().
02183 { 02184 unsigned int *rtpheader; 02185 int hdrlen = 12, res = 0, i = 0, payload = 0; 02186 char data[256]; 02187 02188 if ((digit <= '9') && (digit >= '0')) 02189 digit -= '0'; 02190 else if (digit == '*') 02191 digit = 10; 02192 else if (digit == '#') 02193 digit = 11; 02194 else if ((digit >= 'A') && (digit <= 'D')) 02195 digit = digit - 'A' + 12; 02196 else if ((digit >= 'a') && (digit <= 'd')) 02197 digit = digit - 'a' + 12; 02198 else { 02199 ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit); 02200 return 0; 02201 } 02202 02203 /* If we have no peer, return immediately */ 02204 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 02205 return 0; 02206 02207 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF); 02208 02209 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 02210 rtp->send_duration = 160; 02211 02212 /* Get a pointer to the header */ 02213 rtpheader = (unsigned int *)data; 02214 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno)); 02215 rtpheader[1] = htonl(rtp->lastdigitts); 02216 rtpheader[2] = htonl(rtp->ssrc); 02217 02218 for (i = 0; i < 2; i++) { 02219 rtpheader[3] = htonl((digit << 24) | (0xa << 16) | (rtp->send_duration)); 02220 res = sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockaddr *) &rtp->them, sizeof(rtp->them)); 02221 if (res < 0) 02222 ast_log(LOG_ERROR, "RTP Transmission error to %s:%u: %s\n", 02223 ast_inet_ntoa(rtp->them.sin_addr), 02224 ntohs(rtp->them.sin_port), strerror(errno)); 02225 if (rtp_debug_test_addr(&rtp->them)) 02226 ast_verbose("Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 02227 ast_inet_ntoa(rtp->them.sin_addr), 02228 ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen); 02229 /* Increment sequence number */ 02230 rtp->seqno++; 02231 /* Increment duration */ 02232 rtp->send_duration += 160; 02233 /* Clear marker bit and set seqno */ 02234 rtpheader[0] = htonl((2 << 30) | (payload << 16) | (rtp->seqno)); 02235 } 02236 02237 /* Since we received a begin, we can safely store the digit and disable any compensation */ 02238 rtp->sending_digit = 1; 02239 rtp->send_digit = digit; 02240 rtp->send_payload = payload; 02241 02242 return 0; 02243 }
int ast_rtp_senddigit_end | ( | struct ast_rtp * | rtp, | |
char | digit | |||
) |
void ast_rtp_set_callback | ( | struct ast_rtp * | rtp, | |
ast_rtp_callback | callback | |||
) |
Definition at line 586 of file rtp.c.
References ast_rtp::callback.
Referenced by start_rtp().
00587 { 00588 rtp->callback = callback; 00589 }
void ast_rtp_set_data | ( | struct ast_rtp * | rtp, | |
void * | data | |||
) |
Definition at line 581 of file rtp.c.
References ast_rtp::data.
Referenced by start_rtp().
00582 { 00583 rtp->data = data; 00584 }
void ast_rtp_set_m_type | ( | struct ast_rtp * | rtp, | |
int | pt | |||
) |
Activate payload type.
Definition at line 1638 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, ast_rtp::current_RTP_PT, and MAX_RTP_PT.
Referenced by gtalk_is_answered(), gtalk_newcall(), and process_sdp().
01639 { 01640 if (pt < 0 || pt > MAX_RTP_PT || static_RTP_PT[pt].code == 0) 01641 return; /* bogus payload type */ 01642 01643 ast_mutex_lock(&rtp->bridge_lock); 01644 rtp->current_RTP_PT[pt] = static_RTP_PT[pt]; 01645 ast_mutex_unlock(&rtp->bridge_lock); 01646 }
void ast_rtp_set_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | them | |||
) |
Definition at line 2005 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().
02006 { 02007 rtp->them.sin_port = them->sin_port; 02008 rtp->them.sin_addr = them->sin_addr; 02009 if (rtp->rtcp) { 02010 rtp->rtcp->them.sin_port = htons(ntohs(them->sin_port) + 1); 02011 rtp->rtcp->them.sin_addr = them->sin_addr; 02012 } 02013 rtp->rxseqno = 0; 02014 }
void ast_rtp_set_rtpholdtimeout | ( | struct ast_rtp * | rtp, | |
int | timeout | |||
) |
Set rtp hold timeout.
Definition at line 548 of file rtp.c.
References ast_rtp::rtpholdtimeout.
Referenced by create_addr_from_peer(), do_monitor(), and sip_alloc().
00549 { 00550 rtp->rtpholdtimeout = timeout; 00551 }
void ast_rtp_set_rtpkeepalive | ( | struct ast_rtp * | rtp, | |
int | period | |||
) |
set RTP keepalive interval
Definition at line 554 of file rtp.c.
References ast_rtp::rtpkeepalive.
Referenced by create_addr_from_peer(), and sip_alloc().
00555 { 00556 rtp->rtpkeepalive = period; 00557 }
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.
Initiate payload type to a known MIME media type for a codec.
Definition at line 1665 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(), and set_dtmf_payload().
01668 { 01669 unsigned int i; 01670 int found = 0; 01671 01672 if (pt < 0 || pt > MAX_RTP_PT) 01673 return -1; /* bogus payload type */ 01674 01675 ast_mutex_lock(&rtp->bridge_lock); 01676 01677 for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { 01678 if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 && 01679 strcasecmp(mimeType, mimeTypes[i].type) == 0) { 01680 found = 1; 01681 rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType; 01682 if ((mimeTypes[i].payloadType.code == AST_FORMAT_G726) && 01683 mimeTypes[i].payloadType.isAstFormat && 01684 (options & AST_RTP_OPT_G726_NONSTANDARD)) 01685 rtp->current_RTP_PT[pt].code = AST_FORMAT_G726_AAL2; 01686 break; 01687 } 01688 } 01689 01690 ast_mutex_unlock(&rtp->bridge_lock); 01691 01692 return (found ? 0 : -1); 01693 }
void ast_rtp_set_rtptimeout | ( | struct ast_rtp * | rtp, | |
int | timeout | |||
) |
Set rtp timeout.
Definition at line 542 of file rtp.c.
References ast_rtp::rtptimeout.
Referenced by create_addr_from_peer(), do_monitor(), and sip_alloc().
00543 { 00544 rtp->rtptimeout = timeout; 00545 }
void ast_rtp_set_rtptimers_onhold | ( | struct ast_rtp * | rtp | ) |
Definition at line 535 of file rtp.c.
References ast_rtp::rtpholdtimeout, and ast_rtp::rtptimeout.
Referenced by handle_response_invite().
00536 { 00537 rtp->rtptimeout = (-1) * rtp->rtptimeout; 00538 rtp->rtpholdtimeout = (-1) * rtp->rtpholdtimeout; 00539 }
void ast_rtp_setdtmf | ( | struct ast_rtp * | rtp, | |
int | dtmf | |||
) |
Indicate whether this RTP session is carrying DTMF or not.
Definition at line 601 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().
00602 { 00603 ast_set2_flag(rtp, dtmf ? 1 : 0, FLAG_HAS_DTMF); 00604 }
void ast_rtp_setdtmfcompensate | ( | struct ast_rtp * | rtp, | |
int | compensate | |||
) |
Compensate for devices that send RFC2833 packets all at once.
Definition at line 606 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().
00607 { 00608 ast_set2_flag(rtp, compensate ? 1 : 0, FLAG_DTMF_COMPENSATE); 00609 }
void ast_rtp_setnat | ( | struct ast_rtp * | rtp, | |
int | nat | |||
) |
Definition at line 591 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 611 of file rtp.c.
References ast_set2_flag, and FLAG_HAS_STUN.
Referenced by gtalk_new().
00612 { 00613 ast_set2_flag(rtp, stun_enable ? 1 : 0, FLAG_HAS_STUN); 00614 }
int ast_rtp_settos | ( | struct ast_rtp * | rtp, | |
int | tos | |||
) |
Definition at line 1990 of file rtp.c.
References ast_log(), LOG_WARNING, and ast_rtp::s.
Referenced by __oh323_rtp_create(), and sip_alloc().
01991 { 01992 int res; 01993 01994 if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 01995 ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); 01996 return res; 01997 }
void ast_rtp_stop | ( | struct ast_rtp * | rtp | ) |
Definition at line 2045 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().
02046 { 02047 AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid); 02048 02049 memset(&rtp->them.sin_addr, 0, sizeof(rtp->them.sin_addr)); 02050 memset(&rtp->them.sin_port, 0, sizeof(rtp->them.sin_port)); 02051 if (rtp->rtcp) { 02052 memset(&rtp->rtcp->them.sin_addr, 0, sizeof(rtp->rtcp->them.sin_addr)); 02053 memset(&rtp->rtcp->them.sin_port, 0, sizeof(rtp->rtcp->them.sin_port)); 02054 } 02055 02056 ast_clear_flag(rtp, FLAG_P2P_SENT_MARK); 02057 }
void ast_rtp_stun_request | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | suggestion, | |||
const char * | username | |||
) |
Definition at line 403 of file rtp.c.
References append_attr_string(), stun_attr::attr, stun_header::ies, stun_header::msglen, stun_header::msgtype, ast_rtp::s, STUN_BINDREQ, stun_req_id(), stun_send(), and STUN_USERNAME.
Referenced by gtalk_update_stun().
00404 { 00405 struct stun_header *req; 00406 unsigned char reqdata[1024]; 00407 int reqlen, reqleft; 00408 struct stun_attr *attr; 00409 00410 req = (struct stun_header *)reqdata; 00411 stun_req_id(req); 00412 reqlen = 0; 00413 reqleft = sizeof(reqdata) - sizeof(struct stun_header); 00414 req->msgtype = 0; 00415 req->msglen = 0; 00416 attr = (struct stun_attr *)req->ies; 00417 if (username) 00418 append_attr_string(&attr, STUN_USERNAME, username, &reqlen, &reqleft); 00419 req->msglen = htons(reqlen); 00420 req->msgtype = htons(STUN_BINDREQ); 00421 stun_send(rtp->s, suggestion, req); 00422 }
void ast_rtp_unset_m_type | ( | struct ast_rtp * | rtp, | |
int | pt | |||
) |
clear payload type
Definition at line 1650 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().
01651 { 01652 if (pt < 0 || pt > MAX_RTP_PT) 01653 return; /* bogus payload type */ 01654 01655 ast_mutex_lock(&rtp->bridge_lock); 01656 rtp->current_RTP_PT[pt].isAstFormat = 0; 01657 rtp->current_RTP_PT[pt].code = 0; 01658 ast_mutex_unlock(&rtp->bridge_lock); 01659 }
Definition at line 2733 of file rtp.c.
References ast_codec_pref_getsize(), AST_FORMAT_G722, 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::data, 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_frame::samples, ast_rtp::smoother, ast_frame::subclass, and ast_rtp::them.
Referenced by gtalk_write(), mgcp_write(), oh323_write(), sip_write(), and skinny_write().
02734 { 02735 struct ast_frame *f; 02736 int codec; 02737 int hdrlen = 12; 02738 int subclass; 02739 02740 02741 /* If we have no peer, return immediately */ 02742 if (!rtp->them.sin_addr.s_addr) 02743 return 0; 02744 02745 /* If there is no data length, return immediately */ 02746 if (!_f->datalen) 02747 return 0; 02748 02749 /* Make sure we have enough space for RTP header */ 02750 if ((_f->frametype != AST_FRAME_VOICE) && (_f->frametype != AST_FRAME_VIDEO)) { 02751 ast_log(LOG_WARNING, "RTP can only send voice and video\n"); 02752 return -1; 02753 } 02754 02755 subclass = _f->subclass; 02756 if (_f->frametype == AST_FRAME_VIDEO) 02757 subclass &= ~0x1; 02758 02759 codec = ast_rtp_lookup_code(rtp, 1, subclass); 02760 if (codec < 0) { 02761 ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(_f->subclass)); 02762 return -1; 02763 } 02764 02765 if (rtp->lasttxformat != subclass) { 02766 /* New format, reset the smoother */ 02767 if (option_debug) 02768 ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass)); 02769 rtp->lasttxformat = subclass; 02770 if (rtp->smoother) 02771 ast_smoother_free(rtp->smoother); 02772 rtp->smoother = NULL; 02773 } 02774 02775 if (!rtp->smoother && subclass != AST_FORMAT_SPEEX && subclass != AST_FORMAT_G723_1) { 02776 struct ast_format_list fmt = ast_codec_pref_getsize(&rtp->pref, subclass); 02777 if (fmt.inc_ms) { /* if codec parameters is set / avoid division by zero */ 02778 if (!(rtp->smoother = ast_smoother_new((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms))) { 02779 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)); 02780 return -1; 02781 } 02782 if (fmt.flags) 02783 ast_smoother_set_flags(rtp->smoother, fmt.flags); 02784 if (option_debug) 02785 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)); 02786 } 02787 } 02788 if (rtp->smoother) { 02789 if (ast_smoother_test_flag(rtp->smoother, AST_SMOOTHER_FLAG_BE)) { 02790 ast_smoother_feed_be(rtp->smoother, _f); 02791 } else { 02792 ast_smoother_feed(rtp->smoother, _f); 02793 } 02794 02795 while ((f = ast_smoother_read(rtp->smoother)) && (f->data)) { 02796 if (f->subclass == AST_FORMAT_G722) { 02797 /* G.722 is silllllllllllllly */ 02798 f->samples /= 2; 02799 } 02800 02801 ast_rtp_raw_write(rtp, f, codec); 02802 } 02803 } else { 02804 /* Don't buffer outgoing frames; send them one-per-packet: */ 02805 if (_f->offset < hdrlen) { 02806 f = ast_frdup(_f); 02807 } else { 02808 f = _f; 02809 } 02810 if (f->data) { 02811 if (f->subclass == AST_FORMAT_G722) { 02812 /* G.722 is silllllllllllllly */ 02813 f->samples /= 2; 02814 } 02815 ast_rtp_raw_write(rtp, f, codec); 02816 } 02817 if (f != _f) 02818 ast_frfree(f); 02819 } 02820 02821 return 0; 02822 }