#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. | |
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) |
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) |
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().
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 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 827 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_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().
00828 { 00829 socklen_t len; 00830 int position, i, packetwords; 00831 int res; 00832 struct sockaddr_in sin; 00833 unsigned int rtcpdata[8192 + AST_FRIENDLY_OFFSET]; 00834 unsigned int *rtcpheader; 00835 int pt; 00836 struct timeval now; 00837 unsigned int length; 00838 int rc; 00839 double rttsec; 00840 uint64_t rtt = 0; 00841 unsigned int dlsr; 00842 unsigned int lsr; 00843 unsigned int msw; 00844 unsigned int lsw; 00845 unsigned int comp; 00846 struct ast_frame *f = &ast_null_frame; 00847 00848 if (!rtp || !rtp->rtcp) 00849 return &ast_null_frame; 00850 00851 len = sizeof(sin); 00852 00853 res = recvfrom(rtp->rtcp->s, rtcpdata + AST_FRIENDLY_OFFSET, sizeof(rtcpdata) - sizeof(unsigned int) * AST_FRIENDLY_OFFSET, 00854 0, (struct sockaddr *)&sin, &len); 00855 if (option_debug) 00856 ast_log(LOG_DEBUG, "socket RTCP read: rtp %i rtcp %i\n", rtp->s, rtp->rtcp->s); 00857 00858 rtcpheader = (unsigned int *)(rtcpdata + AST_FRIENDLY_OFFSET); 00859 00860 if (res < 0) { 00861 ast_assert(errno != EBADF); 00862 if (errno != EAGAIN) { 00863 ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n", strerror(errno)); 00864 ast_log(LOG_WARNING, "socket RTCP read: rtp %i rtcp %i\n", rtp->s, rtp->rtcp->s); 00865 return NULL; 00866 } 00867 return &ast_null_frame; 00868 } 00869 00870 packetwords = res / 4; 00871 00872 if (rtp->nat) { 00873 /* Send to whoever sent to us */ 00874 if ((rtp->rtcp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || 00875 (rtp->rtcp->them.sin_port != sin.sin_port)) { 00876 memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); 00877 if (option_debug || rtpdebug) 00878 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)); 00879 } 00880 } 00881 00882 if (option_debug) 00883 ast_log(LOG_DEBUG, "Got RTCP report of %d bytes\n", res); 00884 00885 /* Process a compound packet */ 00886 position = 0; 00887 while (position < packetwords) { 00888 i = position; 00889 length = ntohl(rtcpheader[i]); 00890 pt = (length & 0xff0000) >> 16; 00891 rc = (length & 0x1f000000) >> 24; 00892 length &= 0xffff; 00893 00894 if ((i + length) > packetwords) { 00895 ast_log(LOG_WARNING, "RTCP Read too short\n"); 00896 return &ast_null_frame; 00897 } 00898 00899 if (rtcp_debug_test_addr(&sin)) { 00900 ast_verbose("\n\nGot RTCP from %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 00901 ast_verbose("PT: %d(%s)\n", pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown"); 00902 ast_verbose("Reception reports: %d\n", rc); 00903 ast_verbose("SSRC of sender: %u\n", rtcpheader[i + 1]); 00904 } 00905 00906 i += 2; /* Advance past header and ssrc */ 00907 00908 switch (pt) { 00909 case RTCP_PT_SR: 00910 gettimeofday(&rtp->rtcp->rxlsr,NULL); /* To be able to populate the dlsr */ 00911 rtp->rtcp->spc = ntohl(rtcpheader[i+3]); 00912 rtp->rtcp->soc = ntohl(rtcpheader[i + 4]); 00913 rtp->rtcp->themrxlsr = ((ntohl(rtcpheader[i]) & 0x0000ffff) << 16) | ((ntohl(rtcpheader[i + 1]) & 0xffff0000) >> 16); /* Going to LSR in RR*/ 00914 00915 if (rtcp_debug_test_addr(&sin)) { 00916 ast_verbose("NTP timestamp: %lu.%010lu\n", (unsigned long) ntohl(rtcpheader[i]), (unsigned long) ntohl(rtcpheader[i + 1]) * 4096); 00917 ast_verbose("RTP timestamp: %lu\n", (unsigned long) ntohl(rtcpheader[i + 2])); 00918 ast_verbose("SPC: %lu\tSOC: %lu\n", (unsigned long) ntohl(rtcpheader[i + 3]), (unsigned long) ntohl(rtcpheader[i + 4])); 00919 } 00920 i += 5; 00921 if (rc < 1) 00922 break; 00923 /* Intentional fall through */ 00924 case RTCP_PT_RR: 00925 /* Don't handle multiple reception reports (rc > 1) yet */ 00926 /* Calculate RTT per RFC */ 00927 gettimeofday(&now, NULL); 00928 timeval2ntp(now, &msw, &lsw); 00929 if (ntohl(rtcpheader[i + 4]) && ntohl(rtcpheader[i + 5])) { /* We must have the LSR && DLSR */ 00930 comp = ((msw & 0xffff) << 16) | ((lsw & 0xffff0000) >> 16); 00931 lsr = ntohl(rtcpheader[i + 4]); 00932 dlsr = ntohl(rtcpheader[i + 5]); 00933 rtt = comp - lsr - dlsr; 00934 00935 /* Convert end to end delay to usec (keeping the calculation in 64bit space) 00936 sess->ee_delay = (eedelay * 1000) / 65536; */ 00937 if (rtt < 4294) { 00938 rtt = (rtt * 1000000) >> 16; 00939 } else { 00940 rtt = (rtt * 1000) >> 16; 00941 rtt *= 1000; 00942 } 00943 rtt = rtt / 1000.; 00944 rttsec = rtt / 1000.; 00945 00946 if (comp - dlsr >= lsr) { 00947 rtp->rtcp->accumulated_transit += rttsec; 00948 rtp->rtcp->rtt = rttsec; 00949 if (rtp->rtcp->maxrtt<rttsec) 00950 rtp->rtcp->maxrtt = rttsec; 00951 if (rtp->rtcp->minrtt>rttsec) 00952 rtp->rtcp->minrtt = rttsec; 00953 } else if (rtcp_debug_test_addr(&sin)) { 00954 ast_verbose("Internal RTCP NTP clock skew detected: " 00955 "lsr=%u, now=%u, dlsr=%u (%d:%03dms), " 00956 "diff=%d\n", 00957 lsr, comp, dlsr, dlsr / 65536, 00958 (dlsr % 65536) * 1000 / 65536, 00959 dlsr - (comp - lsr)); 00960 } 00961 } 00962 00963 rtp->rtcp->reported_jitter = ntohl(rtcpheader[i + 3]); 00964 rtp->rtcp->reported_lost = ntohl(rtcpheader[i + 1]) & 0xffffff; 00965 if (rtcp_debug_test_addr(&sin)) { 00966 ast_verbose(" Fraction lost: %ld\n", (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24)); 00967 ast_verbose(" Packets lost so far: %d\n", rtp->rtcp->reported_lost); 00968 ast_verbose(" Highest sequence number: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff)); 00969 ast_verbose(" Sequence number cycles: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16); 00970 ast_verbose(" Interarrival jitter: %u\n", rtp->rtcp->reported_jitter); 00971 ast_verbose(" Last SR(our NTP): %lu.%010lu\n",(unsigned long) ntohl(rtcpheader[i + 4]) >> 16,((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096); 00972 ast_verbose(" DLSR: %4.4f (sec)\n",ntohl(rtcpheader[i + 5])/65536.0); 00973 if (rtt) 00974 ast_verbose(" RTT: %lu(sec)\n", (unsigned long) rtt); 00975 } 00976 break; 00977 case RTCP_PT_FUR: 00978 if (rtcp_debug_test_addr(&sin)) 00979 ast_verbose("Received an RTCP Fast Update Request\n"); 00980 rtp->f.frametype = AST_FRAME_CONTROL; 00981 rtp->f.subclass = AST_CONTROL_VIDUPDATE; 00982 rtp->f.datalen = 0; 00983 rtp->f.samples = 0; 00984 rtp->f.mallocd = 0; 00985 rtp->f.src = "RTP"; 00986 f = &rtp->f; 00987 break; 00988 case RTCP_PT_SDES: 00989 if (rtcp_debug_test_addr(&sin)) 00990 ast_verbose("Received an SDES from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 00991 break; 00992 case RTCP_PT_BYE: 00993 if (rtcp_debug_test_addr(&sin)) 00994 ast_verbose("Received a BYE from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 00995 break; 00996 default: 00997 if (option_debug) 00998 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)); 00999 break; 01000 } 01001 position += (length + 1); 01002 } 01003 01004 return f; 01005 }
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 2357 of file rtp.c.
References ast_rtcp_write(), ast_rtp::rtcp, and ast_rtcp::sendfur.
02358 { 02359 struct ast_rtp *rtp = data; 02360 int res; 02361 02362 rtp->rtcp->sendfur = 1; 02363 res = ast_rtcp_write(data); 02364 02365 return res; 02366 }
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 3295 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, 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.
03296 { 03297 struct ast_rtp *p0 = NULL, *p1 = NULL; /* Audio RTP Channels */ 03298 struct ast_rtp *vp0 = NULL, *vp1 = NULL; /* Video RTP channels */ 03299 struct ast_rtp_protocol *pr0 = NULL, *pr1 = NULL; 03300 enum ast_rtp_get_result audio_p0_res = AST_RTP_GET_FAILED, video_p0_res = AST_RTP_GET_FAILED; 03301 enum ast_rtp_get_result audio_p1_res = AST_RTP_GET_FAILED, video_p1_res = AST_RTP_GET_FAILED; 03302 enum ast_bridge_result res = AST_BRIDGE_FAILED; 03303 int codec0 = 0, codec1 = 0; 03304 void *pvt0 = NULL, *pvt1 = NULL; 03305 03306 /* Lock channels */ 03307 ast_channel_lock(c0); 03308 while(ast_channel_trylock(c1)) { 03309 ast_channel_unlock(c0); 03310 usleep(1); 03311 ast_channel_lock(c0); 03312 } 03313 03314 /* Ensure neither channel got hungup during lock avoidance */ 03315 if (ast_check_hangup(c0) || ast_check_hangup(c1)) { 03316 ast_log(LOG_WARNING, "Got hangup while attempting to bridge '%s' and '%s'\n", c0->name, c1->name); 03317 ast_channel_unlock(c0); 03318 ast_channel_unlock(c1); 03319 return AST_BRIDGE_FAILED; 03320 } 03321 03322 /* Find channel driver interfaces */ 03323 if (!(pr0 = get_proto(c0))) { 03324 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name); 03325 ast_channel_unlock(c0); 03326 ast_channel_unlock(c1); 03327 return AST_BRIDGE_FAILED; 03328 } 03329 if (!(pr1 = get_proto(c1))) { 03330 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name); 03331 ast_channel_unlock(c0); 03332 ast_channel_unlock(c1); 03333 return AST_BRIDGE_FAILED; 03334 } 03335 03336 /* Get channel specific interface structures */ 03337 pvt0 = c0->tech_pvt; 03338 pvt1 = c1->tech_pvt; 03339 03340 /* Get audio and video interface (if native bridge is possible) */ 03341 audio_p0_res = pr0->get_rtp_info(c0, &p0); 03342 video_p0_res = pr0->get_vrtp_info ? pr0->get_vrtp_info(c0, &vp0) : AST_RTP_GET_FAILED; 03343 audio_p1_res = pr1->get_rtp_info(c1, &p1); 03344 video_p1_res = pr1->get_vrtp_info ? pr1->get_vrtp_info(c1, &vp1) : AST_RTP_GET_FAILED; 03345 03346 /* If we are carrying video, and both sides are not reinviting... then fail the native bridge */ 03347 if (video_p0_res != AST_RTP_GET_FAILED && (audio_p0_res != AST_RTP_TRY_NATIVE || video_p0_res != AST_RTP_TRY_NATIVE)) 03348 audio_p0_res = AST_RTP_GET_FAILED; 03349 if (video_p1_res != AST_RTP_GET_FAILED && (audio_p1_res != AST_RTP_TRY_NATIVE || video_p1_res != AST_RTP_TRY_NATIVE)) 03350 audio_p1_res = AST_RTP_GET_FAILED; 03351 03352 /* Check if a bridge is possible (partial/native) */ 03353 if (audio_p0_res == AST_RTP_GET_FAILED || audio_p1_res == AST_RTP_GET_FAILED) { 03354 /* Somebody doesn't want to play... */ 03355 ast_channel_unlock(c0); 03356 ast_channel_unlock(c1); 03357 return AST_BRIDGE_FAILED_NOWARN; 03358 } 03359 03360 /* If we need to feed DTMF frames into the core then only do a partial native bridge */ 03361 if (ast_test_flag(p0, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) { 03362 ast_set_flag(p0, FLAG_P2P_NEED_DTMF); 03363 audio_p0_res = AST_RTP_TRY_PARTIAL; 03364 } 03365 03366 if (ast_test_flag(p1, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)) { 03367 ast_set_flag(p1, FLAG_P2P_NEED_DTMF); 03368 audio_p1_res = AST_RTP_TRY_PARTIAL; 03369 } 03370 03371 /* If both sides are not using the same method of DTMF transmission 03372 * (ie: one is RFC2833, other is INFO... then we can not do direct media. 03373 * -------------------------------------------------- 03374 * | DTMF Mode | HAS_DTMF | Accepts Begin Frames | 03375 * |-----------|------------|-----------------------| 03376 * | Inband | False | True | 03377 * | RFC2833 | True | True | 03378 * | SIP INFO | False | False | 03379 * -------------------------------------------------- 03380 * However, if DTMF from both channels is being monitored by the core, then 03381 * we can still do packet-to-packet bridging, because passing through the 03382 * core will handle DTMF mode translation. 03383 */ 03384 if ( (ast_test_flag(p0, FLAG_HAS_DTMF) != ast_test_flag(p1, FLAG_HAS_DTMF)) || 03385 (!c0->tech->send_digit_begin != !c1->tech->send_digit_begin)) { 03386 if (!ast_test_flag(p0, FLAG_P2P_NEED_DTMF) || !ast_test_flag(p1, FLAG_P2P_NEED_DTMF)) { 03387 ast_channel_unlock(c0); 03388 ast_channel_unlock(c1); 03389 return AST_BRIDGE_FAILED_NOWARN; 03390 } 03391 audio_p0_res = AST_RTP_TRY_PARTIAL; 03392 audio_p1_res = AST_RTP_TRY_PARTIAL; 03393 } 03394 03395 /* If we need to feed frames into the core don't do a P2P bridge */ 03396 if ((audio_p0_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p0, FLAG_P2P_NEED_DTMF)) || 03397 (audio_p1_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p1, FLAG_P2P_NEED_DTMF))) { 03398 ast_channel_unlock(c0); 03399 ast_channel_unlock(c1); 03400 return AST_BRIDGE_FAILED_NOWARN; 03401 } 03402 03403 /* Get codecs from both sides */ 03404 codec0 = pr0->get_codec ? pr0->get_codec(c0) : 0; 03405 codec1 = pr1->get_codec ? pr1->get_codec(c1) : 0; 03406 if (codec0 && codec1 && !(codec0 & codec1)) { 03407 /* Hey, we can't do native bridging if both parties speak different codecs */ 03408 if (option_debug) 03409 ast_log(LOG_DEBUG, "Channel codec0 = %d is not codec1 = %d, cannot native bridge in RTP.\n", codec0, codec1); 03410 ast_channel_unlock(c0); 03411 ast_channel_unlock(c1); 03412 return AST_BRIDGE_FAILED_NOWARN; 03413 } 03414 03415 /* If either side can only do a partial bridge, then don't try for a true native bridge */ 03416 if (audio_p0_res == AST_RTP_TRY_PARTIAL || audio_p1_res == AST_RTP_TRY_PARTIAL) { 03417 struct ast_format_list fmt0, fmt1; 03418 03419 /* In order to do Packet2Packet bridging both sides must be in the same rawread/rawwrite */ 03420 if (c0->rawreadformat != c1->rawwriteformat || c1->rawreadformat != c0->rawwriteformat) { 03421 if (option_debug) 03422 ast_log(LOG_DEBUG, "Cannot packet2packet bridge - raw formats are incompatible\n"); 03423 ast_channel_unlock(c0); 03424 ast_channel_unlock(c1); 03425 return AST_BRIDGE_FAILED_NOWARN; 03426 } 03427 /* They must also be using the same packetization */ 03428 fmt0 = ast_codec_pref_getsize(&p0->pref, c0->rawreadformat); 03429 fmt1 = ast_codec_pref_getsize(&p1->pref, c1->rawreadformat); 03430 if (fmt0.cur_ms != fmt1.cur_ms) { 03431 if (option_debug) 03432 ast_log(LOG_DEBUG, "Cannot packet2packet bridge - packetization settings prevent it\n"); 03433 ast_channel_unlock(c0); 03434 ast_channel_unlock(c1); 03435 return AST_BRIDGE_FAILED_NOWARN; 03436 } 03437 03438 if (option_verbose > 2) 03439 ast_verbose(VERBOSE_PREFIX_3 "Packet2Packet bridging %s and %s\n", c0->name, c1->name); 03440 res = bridge_p2p_loop(c0, c1, p0, p1, timeoutms, flags, fo, rc, pvt0, pvt1); 03441 } else { 03442 if (option_verbose > 2) 03443 ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s\n", c0->name, c1->name); 03444 res = bridge_native_loop(c0, c1, p0, p1, vp0, vp1, pr0, pr1, codec0, codec1, timeoutms, flags, fo, rc, pvt0, pvt1); 03445 } 03446 03447 return res; 03448 }
int ast_rtp_codec_getformat | ( | int | pt | ) |
Definition at line 2739 of file rtp.c.
References rtpPayloadType::code, and static_RTP_PT.
Referenced by process_sdp().
02740 { 02741 if (pt < 0 || pt > MAX_RTP_PT) 02742 return 0; /* bogus payload type */ 02743 02744 if (static_RTP_PT[pt].isAstFormat) 02745 return static_RTP_PT[pt].code; 02746 else 02747 return 0; 02748 }
struct ast_codec_pref* ast_rtp_codec_getpref | ( | struct ast_rtp * | rtp | ) |
Definition at line 2734 of file rtp.c.
References ast_rtp::pref.
Referenced by add_codec_to_sdp(), and process_sdp().
02735 { 02736 return &rtp->pref; 02737 }
int ast_rtp_codec_setpref | ( | struct ast_rtp * | rtp, | |
struct ast_codec_pref * | prefs | |||
) |
Definition at line 2721 of file rtp.c.
References ast_smoother_free(), ast_codec_pref::framing, ast_codec_pref::order, ast_rtp::pref, prefs, 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().
02722 { 02723 int x; 02724 for (x = 0; x < 32; x++) { /* Ugly way */ 02725 rtp->pref.order[x] = prefs->order[x]; 02726 rtp->pref.framing[x] = prefs->framing[x]; 02727 } 02728 if (rtp->smoother) 02729 ast_smoother_free(rtp->smoother); 02730 rtp->smoother = NULL; 02731 return 0; 02732 }
void ast_rtp_destroy | ( | struct ast_rtp * | rtp | ) |
Definition at line 2140 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().
02141 { 02142 if (rtcp_debug_test_addr(&rtp->them) || rtcpstats) { 02143 /*Print some info on the call here */ 02144 ast_verbose(" RTP-stats\n"); 02145 ast_verbose("* Our Receiver:\n"); 02146 ast_verbose(" SSRC: %u\n", rtp->themssrc); 02147 ast_verbose(" Received packets: %u\n", rtp->rxcount); 02148 ast_verbose(" Lost packets: %u\n", rtp->rtcp->expected_prior - rtp->rtcp->received_prior); 02149 ast_verbose(" Jitter: %.4f\n", rtp->rxjitter); 02150 ast_verbose(" Transit: %.4f\n", rtp->rxtransit); 02151 ast_verbose(" RR-count: %u\n", rtp->rtcp->rr_count); 02152 ast_verbose("* Our Sender:\n"); 02153 ast_verbose(" SSRC: %u\n", rtp->ssrc); 02154 ast_verbose(" Sent packets: %u\n", rtp->txcount); 02155 ast_verbose(" Lost packets: %u\n", rtp->rtcp->reported_lost); 02156 ast_verbose(" Jitter: %u\n", rtp->rtcp->reported_jitter / (unsigned int)65536.0); 02157 ast_verbose(" SR-count: %u\n", rtp->rtcp->sr_count); 02158 ast_verbose(" RTT: %f\n", rtp->rtcp->rtt); 02159 } 02160 02161 if (rtp->smoother) 02162 ast_smoother_free(rtp->smoother); 02163 if (rtp->ioid) 02164 ast_io_remove(rtp->io, rtp->ioid); 02165 if (rtp->s > -1) 02166 close(rtp->s); 02167 if (rtp->rtcp) { 02168 AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid); 02169 close(rtp->rtcp->s); 02170 free(rtp->rtcp); 02171 rtp->rtcp=NULL; 02172 } 02173 02174 ast_mutex_destroy(&rtp->bridge_lock); 02175 02176 free(rtp); 02177 }
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 1484 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().
01485 { 01486 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 01487 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 01488 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 01489 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED; 01490 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED; 01491 int srccodec, destcodec, nat_active = 0; 01492 01493 /* Lock channels */ 01494 ast_channel_lock(dest); 01495 if (src) { 01496 while(ast_channel_trylock(src)) { 01497 ast_channel_unlock(dest); 01498 usleep(1); 01499 ast_channel_lock(dest); 01500 } 01501 } 01502 01503 /* Find channel driver interfaces */ 01504 destpr = get_proto(dest); 01505 if (src) 01506 srcpr = get_proto(src); 01507 if (!destpr) { 01508 if (option_debug) 01509 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name); 01510 ast_channel_unlock(dest); 01511 if (src) 01512 ast_channel_unlock(src); 01513 return 0; 01514 } 01515 if (!srcpr) { 01516 if (option_debug) 01517 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src ? src->name : "<unspecified>"); 01518 ast_channel_unlock(dest); 01519 if (src) 01520 ast_channel_unlock(src); 01521 return 0; 01522 } 01523 01524 /* Get audio and video interface (if native bridge is possible) */ 01525 audio_dest_res = destpr->get_rtp_info(dest, &destp); 01526 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 01527 if (srcpr) { 01528 audio_src_res = srcpr->get_rtp_info(src, &srcp); 01529 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 01530 } 01531 01532 /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */ 01533 if (audio_dest_res != AST_RTP_TRY_NATIVE) { 01534 /* Somebody doesn't want to play... */ 01535 ast_channel_unlock(dest); 01536 if (src) 01537 ast_channel_unlock(src); 01538 return 0; 01539 } 01540 if (audio_src_res == AST_RTP_TRY_NATIVE && srcpr->get_codec) 01541 srccodec = srcpr->get_codec(src); 01542 else 01543 srccodec = 0; 01544 if (audio_dest_res == AST_RTP_TRY_NATIVE && destpr->get_codec) 01545 destcodec = destpr->get_codec(dest); 01546 else 01547 destcodec = 0; 01548 /* Ensure we have at least one matching codec */ 01549 if (!(srccodec & destcodec)) { 01550 ast_channel_unlock(dest); 01551 if (src) 01552 ast_channel_unlock(src); 01553 return 0; 01554 } 01555 /* Consider empty media as non-existant */ 01556 if (audio_src_res == AST_RTP_TRY_NATIVE && !srcp->them.sin_addr.s_addr) 01557 srcp = NULL; 01558 /* If the client has NAT stuff turned on then just safe NAT is active */ 01559 if (srcp && (srcp->nat || ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 01560 nat_active = 1; 01561 /* Bridge media early */ 01562 if (destpr->set_rtp_peer(dest, srcp, vsrcp, srccodec, nat_active)) 01563 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src ? src->name : "<unspecified>"); 01564 ast_channel_unlock(dest); 01565 if (src) 01566 ast_channel_unlock(src); 01567 if (option_debug) 01568 ast_log(LOG_DEBUG, "Setting early bridge SDP of '%s' with that of '%s'\n", dest->name, src ? src->name : "<unspecified>"); 01569 return 1; 01570 }
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 2049 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().
02050 { 02051 struct ast_rtp *bridged = NULL; 02052 02053 ast_mutex_lock(&rtp->bridge_lock); 02054 bridged = rtp->bridged; 02055 ast_mutex_unlock(&rtp->bridge_lock); 02056 02057 return bridged; 02058 }
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 1706 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().
01708 { 01709 int pt; 01710 01711 ast_mutex_lock(&rtp->bridge_lock); 01712 01713 *astFormats = *nonAstFormats = 0; 01714 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01715 if (rtp->current_RTP_PT[pt].isAstFormat) { 01716 *astFormats |= rtp->current_RTP_PT[pt].code; 01717 } else { 01718 *nonAstFormats |= rtp->current_RTP_PT[pt].code; 01719 } 01720 } 01721 01722 ast_mutex_unlock(&rtp->bridge_lock); 01723 01724 return; 01725 }
int ast_rtp_get_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | them | |||
) |
Definition at line 2031 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().
02032 { 02033 if ((them->sin_family != AF_INET) || 02034 (them->sin_port != rtp->them.sin_port) || 02035 (them->sin_addr.s_addr != rtp->them.sin_addr.s_addr)) { 02036 them->sin_family = AF_INET; 02037 them->sin_port = rtp->them.sin_port; 02038 them->sin_addr = rtp->them.sin_addr; 02039 return 1; 02040 } 02041 return 0; 02042 }
char* ast_rtp_get_quality | ( | struct ast_rtp * | rtp, | |
struct ast_rtp_quality * | qual | |||
) |
Return RTCP quality string.
Definition at line 2096 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().
02097 { 02098 /* 02099 *ssrc our ssrc 02100 *themssrc their ssrc 02101 *lp lost packets 02102 *rxjitter our calculated jitter(rx) 02103 *rxcount no. received packets 02104 *txjitter reported jitter of the other end 02105 *txcount transmitted packets 02106 *rlp remote lost packets 02107 *rtt round trip time 02108 */ 02109 02110 if (qual && rtp) { 02111 qual->local_ssrc = rtp->ssrc; 02112 qual->local_jitter = rtp->rxjitter; 02113 qual->local_count = rtp->rxcount; 02114 qual->remote_ssrc = rtp->themssrc; 02115 qual->remote_count = rtp->txcount; 02116 if (rtp->rtcp) { 02117 qual->local_lostpackets = rtp->rtcp->expected_prior - rtp->rtcp->received_prior; 02118 qual->remote_lostpackets = rtp->rtcp->reported_lost; 02119 qual->remote_jitter = rtp->rtcp->reported_jitter / 65536.0; 02120 qual->rtt = rtp->rtcp->rtt; 02121 } 02122 } 02123 if (rtp->rtcp) { 02124 snprintf(rtp->rtcp->quality, sizeof(rtp->rtcp->quality), 02125 "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;txjitter=%f;txcount=%u;rlp=%u;rtt=%f", 02126 rtp->ssrc, 02127 rtp->themssrc, 02128 rtp->rtcp->expected_prior - rtp->rtcp->received_prior, 02129 rtp->rxjitter, 02130 rtp->rxcount, 02131 (double)rtp->rtcp->reported_jitter / 65536.0, 02132 rtp->txcount, 02133 rtp->rtcp->reported_lost, 02134 rtp->rtcp->rtt); 02135 return rtp->rtcp->quality; 02136 } else 02137 return "<Unknown> - RTP/RTCP has already been destroyed"; 02138 }
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 2044 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 3833 of file rtp.c.
References ast_cli_register_multiple(), ast_rtp_reload(), and cli_rtp.
Referenced by main().
03834 { 03835 ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry)); 03836 ast_rtp_reload(); 03837 }
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 1749 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().
01750 { 01751 int pt = 0; 01752 01753 ast_mutex_lock(&rtp->bridge_lock); 01754 01755 if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && 01756 code == rtp->rtp_lookup_code_cache_code) { 01757 /* Use our cached mapping, to avoid the overhead of the loop below */ 01758 pt = rtp->rtp_lookup_code_cache_result; 01759 ast_mutex_unlock(&rtp->bridge_lock); 01760 return pt; 01761 } 01762 01763 /* Check the dynamic list first */ 01764 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01765 if (rtp->current_RTP_PT[pt].code == code && rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) { 01766 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 01767 rtp->rtp_lookup_code_cache_code = code; 01768 rtp->rtp_lookup_code_cache_result = pt; 01769 ast_mutex_unlock(&rtp->bridge_lock); 01770 return pt; 01771 } 01772 } 01773 01774 /* Then the static list */ 01775 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01776 if (static_RTP_PT[pt].code == code && static_RTP_PT[pt].isAstFormat == isAstFormat) { 01777 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 01778 rtp->rtp_lookup_code_cache_code = code; 01779 rtp->rtp_lookup_code_cache_result = pt; 01780 ast_mutex_unlock(&rtp->bridge_lock); 01781 return pt; 01782 } 01783 } 01784 01785 ast_mutex_unlock(&rtp->bridge_lock); 01786 01787 return -1; 01788 }
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 1809 of file rtp.c.
References ast_rtp_lookup_mime_subtype(), AST_RTP_MAX, format, len, and name.
Referenced by process_sdp().
01811 { 01812 int format; 01813 unsigned len; 01814 char *end = buf; 01815 char *start = buf; 01816 01817 if (!buf || !size) 01818 return NULL; 01819 01820 snprintf(end, size, "0x%x (", capability); 01821 01822 len = strlen(end); 01823 end += len; 01824 size -= len; 01825 start = end; 01826 01827 for (format = 1; format < AST_RTP_MAX; format <<= 1) { 01828 if (capability & format) { 01829 const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format, options); 01830 01831 snprintf(end, size, "%s|", name); 01832 len = strlen(end); 01833 end += len; 01834 size -= len; 01835 } 01836 } 01837 01838 if (start == end) 01839 snprintf(start, size, "nothing)"); 01840 else if (size > 1) 01841 *(end -1) = ')'; 01842 01843 return buf; 01844 }
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 1790 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().
01792 { 01793 unsigned int i; 01794 01795 for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { 01796 if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) { 01797 if (isAstFormat && 01798 (code == AST_FORMAT_G726_AAL2) && 01799 (options & AST_RTP_OPT_G726_NONSTANDARD)) 01800 return "G726-32"; 01801 else 01802 return mimeTypes[i].subtype; 01803 } 01804 } 01805 01806 return ""; 01807 }
struct rtpPayloadType ast_rtp_lookup_pt | ( | struct ast_rtp * | rtp, | |
int | pt | |||
) |
Mapping between RTP payload format codes and Asterisk codes:.
Definition at line 1727 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().
01728 { 01729 struct rtpPayloadType result; 01730 01731 result.isAstFormat = result.code = 0; 01732 01733 if (pt < 0 || pt > MAX_RTP_PT) 01734 return result; /* bogus payload type */ 01735 01736 /* Start with negotiated codecs */ 01737 ast_mutex_lock(&rtp->bridge_lock); 01738 result = rtp->current_RTP_PT[pt]; 01739 ast_mutex_unlock(&rtp->bridge_lock); 01740 01741 /* If it doesn't exist, check our static RTP type list, just in case */ 01742 if (!result.code) 01743 result = static_RTP_PT[pt]; 01744 01745 return result; 01746 }
int ast_rtp_make_compatible | ( | struct ast_channel * | dest, | |
struct ast_channel * | src, | |||
int | media | |||
) |
Definition at line 1572 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().
01573 { 01574 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 01575 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 01576 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 01577 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED; 01578 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED; 01579 int srccodec, destcodec; 01580 01581 /* Lock channels */ 01582 ast_channel_lock(dest); 01583 while(ast_channel_trylock(src)) { 01584 ast_channel_unlock(dest); 01585 usleep(1); 01586 ast_channel_lock(dest); 01587 } 01588 01589 /* Find channel driver interfaces */ 01590 if (!(destpr = get_proto(dest))) { 01591 if (option_debug) 01592 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name); 01593 ast_channel_unlock(dest); 01594 ast_channel_unlock(src); 01595 return 0; 01596 } 01597 if (!(srcpr = get_proto(src))) { 01598 if (option_debug) 01599 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src->name); 01600 ast_channel_unlock(dest); 01601 ast_channel_unlock(src); 01602 return 0; 01603 } 01604 01605 /* Get audio and video interface (if native bridge is possible) */ 01606 audio_dest_res = destpr->get_rtp_info(dest, &destp); 01607 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 01608 audio_src_res = srcpr->get_rtp_info(src, &srcp); 01609 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 01610 01611 /* Ensure we have at least one matching codec */ 01612 if (srcpr->get_codec) 01613 srccodec = srcpr->get_codec(src); 01614 else 01615 srccodec = 0; 01616 if (destpr->get_codec) 01617 destcodec = destpr->get_codec(dest); 01618 else 01619 destcodec = 0; 01620 01621 /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */ 01622 if (audio_dest_res != AST_RTP_TRY_NATIVE || audio_src_res != AST_RTP_TRY_NATIVE || !(srccodec & destcodec)) { 01623 /* Somebody doesn't want to play... */ 01624 ast_channel_unlock(dest); 01625 ast_channel_unlock(src); 01626 return 0; 01627 } 01628 ast_rtp_pt_copy(destp, srcp); 01629 if (vdestp && vsrcp) 01630 ast_rtp_pt_copy(vdestp, vsrcp); 01631 if (media) { 01632 /* Bridge early */ 01633 if (destpr->set_rtp_peer(dest, srcp, vsrcp, srccodec, ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 01634 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src->name); 01635 } 01636 ast_channel_unlock(dest); 01637 ast_channel_unlock(src); 01638 if (option_debug) 01639 ast_log(LOG_DEBUG, "Seeded SDP of '%s' with that of '%s'\n", dest->name, src->name); 01640 return 1; 01641 }
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 1995 of file rtp.c.
References ast_rtp_new_with_bindaddr(), io, and sched.
01996 { 01997 struct in_addr ia; 01998 01999 memset(&ia, 0, sizeof(ia)); 02000 return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia); 02001 }
void ast_rtp_new_init | ( | struct ast_rtp * | rtp | ) |
Initialize a new RTP structure.
Definition at line 1892 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().
01893 { 01894 ast_mutex_init(&rtp->bridge_lock); 01895 01896 rtp->them.sin_family = AF_INET; 01897 rtp->us.sin_family = AF_INET; 01898 rtp->ssrc = ast_random(); 01899 rtp->seqno = ast_random() & 0xffff; 01900 ast_set_flag(rtp, FLAG_HAS_DTMF); 01901 01902 return; 01903 }
void ast_rtp_new_source | ( | struct ast_rtp * | rtp | ) |
Definition at line 2012 of file rtp.c.
References ast_rtp::set_marker_bit.
Referenced by mgcp_indicate(), oh323_indicate(), sip_indicate(), sip_write(), and skinny_indicate().
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 1905 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, io, LOG_ERROR, LOG_NOTICE, rtp_socket(), rtpread(), and sched.
Referenced by __oh323_rtp_create(), ast_rtp_new(), gtalk_alloc(), sip_alloc(), and start_rtp().
01906 { 01907 struct ast_rtp *rtp; 01908 int x; 01909 int first; 01910 int startplace; 01911 01912 if (!(rtp = ast_calloc(1, sizeof(*rtp)))) 01913 return NULL; 01914 01915 ast_rtp_new_init(rtp); 01916 01917 rtp->s = rtp_socket(); 01918 ast_log(LOG_NOTICE, "socket RTP fd: %i\n", rtp->s); 01919 if (rtp->s < 0) { 01920 free(rtp); 01921 ast_log(LOG_ERROR, "Unable to allocate socket: %s\n", strerror(errno)); 01922 return NULL; 01923 } 01924 if (sched && rtcpenable) { 01925 rtp->sched = sched; 01926 rtp->rtcp = ast_rtcp_new(); 01927 ast_log(LOG_NOTICE, "socket RTCP fd: %i\n", rtp->rtcp->s); 01928 } 01929 01930 /* Select a random port number in the range of possible RTP */ 01931 x = (ast_random() % (rtpend-rtpstart)) + rtpstart; 01932 x = x & ~1; 01933 /* Save it for future references. */ 01934 startplace = x; 01935 /* Iterate tring to bind that port and incrementing it otherwise untill a port was found or no ports are available. */ 01936 for (;;) { 01937 /* Must be an even port number by RTP spec */ 01938 rtp->us.sin_port = htons(x); 01939 rtp->us.sin_addr = addr; 01940 /* If there's rtcp, initialize it as well. */ 01941 if (rtp->rtcp) { 01942 rtp->rtcp->us.sin_port = htons(x + 1); 01943 rtp->rtcp->us.sin_addr = addr; 01944 } 01945 /* Try to bind it/them. */ 01946 if (!(first = bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us))) && 01947 (!rtp->rtcp || !bind(rtp->rtcp->s, (struct sockaddr *)&rtp->rtcp->us, sizeof(rtp->rtcp->us)))) 01948 break; 01949 if (!first) { 01950 /* Primary bind succeeded! Gotta recreate it */ 01951 close(rtp->s); 01952 rtp->s = rtp_socket(); 01953 ast_log(LOG_NOTICE, "socket RTP2 fd: %i\n", rtp->s); 01954 } 01955 if (errno != EADDRINUSE) { 01956 /* We got an error that wasn't expected, abort! */ 01957 ast_log(LOG_ERROR, "Unexpected bind error: %s\n", strerror(errno)); 01958 close(rtp->s); 01959 if (rtp->rtcp) { 01960 close(rtp->rtcp->s); 01961 free(rtp->rtcp); 01962 } 01963 free(rtp); 01964 return NULL; 01965 } 01966 /* The port was used, increment it (by two). */ 01967 x += 2; 01968 /* Did we go over the limit ? */ 01969 if (x > rtpend) 01970 /* then, start from the begingig. */ 01971 x = (rtpstart + 1) & ~1; 01972 /* Check if we reached the place were we started. */ 01973 if (x == startplace) { 01974 /* If so, there's no ports available. */ 01975 ast_log(LOG_ERROR, "No RTP ports remaining. Can't setup media stream for this call.\n"); 01976 close(rtp->s); 01977 if (rtp->rtcp) { 01978 close(rtp->rtcp->s); 01979 free(rtp->rtcp); 01980 } 01981 free(rtp); 01982 return NULL; 01983 } 01984 } 01985 rtp->sched = sched; 01986 rtp->io = io; 01987 if (callbackmode) { 01988 rtp->ioid = ast_io_add(rtp->io, rtp->s, rtpread, AST_IO_IN, rtp); 01989 ast_set_flag(rtp, FLAG_CALLBACK_MODE); 01990 } 01991 ast_rtp_pt_default(rtp); 01992 return rtp; 01993 }
int ast_rtp_proto_register | ( | struct ast_rtp_protocol * | proto | ) |
Register interface to channel driver.
Definition at line 2850 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().
02851 { 02852 struct ast_rtp_protocol *cur; 02853 02854 AST_LIST_LOCK(&protos); 02855 AST_LIST_TRAVERSE(&protos, cur, list) { 02856 if (!strcmp(cur->type, proto->type)) { 02857 ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type); 02858 AST_LIST_UNLOCK(&protos); 02859 return -1; 02860 } 02861 } 02862 AST_LIST_INSERT_HEAD(&protos, proto, list); 02863 AST_LIST_UNLOCK(&protos); 02864 02865 return 0; 02866 }
void ast_rtp_proto_unregister | ( | struct ast_rtp_protocol * | proto | ) |
Unregister interface to channel driver.
Definition at line 2842 of file rtp.c.
References AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, and protos.
Referenced by load_module(), and unload_module().
02843 { 02844 AST_LIST_LOCK(&protos); 02845 AST_LIST_REMOVE(&protos, proto, list); 02846 AST_LIST_UNLOCK(&protos); 02847 }
void ast_rtp_pt_clear | ( | struct ast_rtp * | rtp | ) |
Setting RTP payload types from lines in a SDP description:.
Definition at line 1408 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().
01409 { 01410 int i; 01411 01412 if (!rtp) 01413 return; 01414 01415 ast_mutex_lock(&rtp->bridge_lock); 01416 01417 for (i = 0; i < MAX_RTP_PT; ++i) { 01418 rtp->current_RTP_PT[i].isAstFormat = 0; 01419 rtp->current_RTP_PT[i].code = 0; 01420 } 01421 01422 rtp->rtp_lookup_code_cache_isAstFormat = 0; 01423 rtp->rtp_lookup_code_cache_code = 0; 01424 rtp->rtp_lookup_code_cache_result = 0; 01425 01426 ast_mutex_unlock(&rtp->bridge_lock); 01427 }
Copy payload types between RTP structures.
Definition at line 1448 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().
01449 { 01450 unsigned int i; 01451 01452 ast_mutex_lock(&dest->bridge_lock); 01453 ast_mutex_lock(&src->bridge_lock); 01454 01455 for (i=0; i < MAX_RTP_PT; ++i) { 01456 dest->current_RTP_PT[i].isAstFormat = 01457 src->current_RTP_PT[i].isAstFormat; 01458 dest->current_RTP_PT[i].code = 01459 src->current_RTP_PT[i].code; 01460 } 01461 dest->rtp_lookup_code_cache_isAstFormat = 0; 01462 dest->rtp_lookup_code_cache_code = 0; 01463 dest->rtp_lookup_code_cache_result = 0; 01464 01465 ast_mutex_unlock(&src->bridge_lock); 01466 ast_mutex_unlock(&dest->bridge_lock); 01467 }
void ast_rtp_pt_default | ( | struct ast_rtp * | rtp | ) |
Set payload types to defaults.
Definition at line 1429 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.
Referenced by ast_rtp_new_with_bindaddr().
01430 { 01431 int i; 01432 01433 ast_mutex_lock(&rtp->bridge_lock); 01434 01435 /* Initialize to default payload types */ 01436 for (i = 0; i < MAX_RTP_PT; ++i) { 01437 rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat; 01438 rtp->current_RTP_PT[i].code = static_RTP_PT[i].code; 01439 } 01440 01441 rtp->rtp_lookup_code_cache_isAstFormat = 0; 01442 rtp->rtp_lookup_code_cache_code = 0; 01443 rtp->rtp_lookup_code_cache_result = 0; 01444 01445 ast_mutex_unlock(&rtp->bridge_lock); 01446 }
Definition at line 1110 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_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().
01111 { 01112 int res; 01113 struct sockaddr_in sin; 01114 socklen_t len; 01115 unsigned int seqno; 01116 int version; 01117 int payloadtype; 01118 int hdrlen = 12; 01119 int padding; 01120 int mark; 01121 int ext; 01122 int cc; 01123 unsigned int ssrc; 01124 unsigned int timestamp; 01125 unsigned int *rtpheader; 01126 struct rtpPayloadType rtpPT; 01127 struct ast_rtp *bridged = NULL; 01128 01129 /* If time is up, kill it */ 01130 if (rtp->sending_digit) 01131 ast_rtp_senddigit_continuation(rtp); 01132 01133 len = sizeof(sin); 01134 01135 /* Cache where the header will go */ 01136 res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET, 01137 0, (struct sockaddr *)&sin, &len); 01138 if (option_debug > 3) 01139 ast_log(LOG_DEBUG, "socket RTP read: rtp %i rtcp %i\n", rtp->s, rtp->rtcp->s); 01140 01141 rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET); 01142 if (res < 0) { 01143 ast_assert(errno != EBADF); 01144 if (errno != EAGAIN) { 01145 ast_log(LOG_WARNING, "RTP Read error: %s. Hanging up.\n", strerror(errno)); 01146 ast_log(LOG_WARNING, "socket RTP read: rtp %i rtcp %i\n", rtp->s, rtp->rtcp->s); 01147 return NULL; 01148 } 01149 return &ast_null_frame; 01150 } 01151 01152 if (res < hdrlen) { 01153 ast_log(LOG_WARNING, "RTP Read too short\n"); 01154 return &ast_null_frame; 01155 } 01156 01157 /* Get fields */ 01158 seqno = ntohl(rtpheader[0]); 01159 01160 /* Check RTP version */ 01161 version = (seqno & 0xC0000000) >> 30; 01162 if (!version) { 01163 if ((stun_handle_packet(rtp->s, &sin, rtp->rawdata + AST_FRIENDLY_OFFSET, res) == STUN_ACCEPT) && 01164 (!rtp->them.sin_port && !rtp->them.sin_addr.s_addr)) { 01165 memcpy(&rtp->them, &sin, sizeof(rtp->them)); 01166 } 01167 return &ast_null_frame; 01168 } 01169 01170 #if 0 /* Allow to receive RTP stream with closed transmission path */ 01171 /* If we don't have the other side's address, then ignore this */ 01172 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 01173 return &ast_null_frame; 01174 #endif 01175 01176 /* Send to whoever send to us if NAT is turned on */ 01177 if (rtp->nat) { 01178 if ((rtp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || 01179 (rtp->them.sin_port != sin.sin_port)) { 01180 rtp->them = sin; 01181 if (rtp->rtcp) { 01182 memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); 01183 rtp->rtcp->them.sin_port = htons(ntohs(rtp->them.sin_port)+1); 01184 } 01185 rtp->rxseqno = 0; 01186 ast_set_flag(rtp, FLAG_NAT_ACTIVE); 01187 if (option_debug || rtpdebug) 01188 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)); 01189 } 01190 } 01191 01192 /* If we are bridged to another RTP stream, send direct */ 01193 if ((bridged = ast_rtp_get_bridged(rtp)) && !bridge_p2p_rtp_write(rtp, bridged, rtpheader, res, hdrlen)) 01194 return &ast_null_frame; 01195 01196 if (version != 2) 01197 return &ast_null_frame; 01198 01199 payloadtype = (seqno & 0x7f0000) >> 16; 01200 padding = seqno & (1 << 29); 01201 mark = seqno & (1 << 23); 01202 ext = seqno & (1 << 28); 01203 cc = (seqno & 0xF000000) >> 24; 01204 seqno &= 0xffff; 01205 timestamp = ntohl(rtpheader[1]); 01206 ssrc = ntohl(rtpheader[2]); 01207 01208 if (!mark && rtp->rxssrc && rtp->rxssrc != ssrc) { 01209 if (option_debug || rtpdebug) 01210 ast_log(LOG_DEBUG, "Forcing Marker bit, because SSRC has changed\n"); 01211 mark = 1; 01212 } 01213 01214 rtp->rxssrc = ssrc; 01215 01216 if (padding) { 01217 /* Remove padding bytes */ 01218 res -= rtp->rawdata[AST_FRIENDLY_OFFSET + res - 1]; 01219 } 01220 01221 if (cc) { 01222 /* CSRC fields present */ 01223 hdrlen += cc*4; 01224 } 01225 01226 if (ext) { 01227 /* RTP Extension present */ 01228 hdrlen += (ntohl(rtpheader[hdrlen/4]) & 0xffff) << 2; 01229 hdrlen += 4; 01230 } 01231 01232 if (res < hdrlen) { 01233 ast_log(LOG_WARNING, "RTP Read too short (%d, expecting %d)\n", res, hdrlen); 01234 return &ast_null_frame; 01235 } 01236 01237 rtp->rxcount++; /* Only count reasonably valid packets, this'll make the rtcp stats more accurate */ 01238 01239 if (rtp->rxcount==1) { 01240 /* This is the first RTP packet successfully received from source */ 01241 rtp->seedrxseqno = seqno; 01242 } 01243 01244 /* Do not schedule RR if RTCP isn't run */ 01245 if (rtp->rtcp && rtp->rtcp->them.sin_addr.s_addr && rtp->rtcp->schedid < 1) { 01246 /* Schedule transmission of Receiver Report */ 01247 rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, rtp); 01248 } 01249 if ( (int)rtp->lastrxseqno - (int)seqno > 100) /* if so it would indicate that the sender cycled; allow for misordering */ 01250 rtp->cycles += RTP_SEQ_MOD; 01251 01252 rtp->lastrxseqno = seqno; 01253 01254 if (rtp->themssrc==0) 01255 rtp->themssrc = ntohl(rtpheader[2]); /* Record their SSRC to put in future RR */ 01256 01257 if (rtp_debug_test_addr(&sin)) 01258 ast_verbose("Got RTP packet from %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 01259 ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen); 01260 01261 rtpPT = ast_rtp_lookup_pt(rtp, payloadtype); 01262 if (!rtpPT.isAstFormat) { 01263 struct ast_frame *f = NULL; 01264 01265 /* This is special in-band data that's not one of our codecs */ 01266 if (rtpPT.code == AST_RTP_DTMF) { 01267 /* It's special -- rfc2833 process it */ 01268 if (rtp_debug_test_addr(&sin)) { 01269 unsigned char *data; 01270 unsigned int event; 01271 unsigned int event_end; 01272 unsigned int duration; 01273 data = rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen; 01274 event = ntohl(*((unsigned int *)(data))); 01275 event >>= 24; 01276 event_end = ntohl(*((unsigned int *)(data))); 01277 event_end <<= 8; 01278 event_end >>= 24; 01279 duration = ntohl(*((unsigned int *)(data))); 01280 duration &= 0xFFFF; 01281 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); 01282 } 01283 f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp); 01284 } else if (rtpPT.code == AST_RTP_CISCO_DTMF) { 01285 /* It's really special -- process it the Cisco way */ 01286 if (rtp->lastevent <= seqno || (rtp->lastevent >= 65530 && seqno <= 6)) { 01287 f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01288 rtp->lastevent = seqno; 01289 } 01290 } else if (rtpPT.code == AST_RTP_CN) { 01291 /* Comfort Noise */ 01292 f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01293 } else { 01294 ast_log(LOG_NOTICE, "Unknown RTP codec %d received from '%s'\n", payloadtype, ast_inet_ntoa(rtp->them.sin_addr)); 01295 } 01296 return f ? f : &ast_null_frame; 01297 } 01298 rtp->lastrxformat = rtp->f.subclass = rtpPT.code; 01299 rtp->f.frametype = (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) ? AST_FRAME_VOICE : AST_FRAME_VIDEO; 01300 01301 if (!rtp->lastrxts) 01302 rtp->lastrxts = timestamp; 01303 01304 rtp->rxseqno = seqno; 01305 01306 /* Record received timestamp as last received now */ 01307 rtp->lastrxts = timestamp; 01308 01309 rtp->f.mallocd = 0; 01310 rtp->f.datalen = res - hdrlen; 01311 rtp->f.data = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET; 01312 rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET; 01313 rtp->f.seqno = seqno; 01314 if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) { 01315 rtp->f.samples = ast_codec_get_samples(&rtp->f); 01316 if (rtp->f.subclass == AST_FORMAT_SLINEAR) 01317 ast_frame_byteswap_be(&rtp->f); 01318 calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark); 01319 /* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */ 01320 ast_set_flag(&rtp->f, AST_FRFLAG_HAS_TIMING_INFO); 01321 rtp->f.ts = timestamp / 8; 01322 rtp->f.len = rtp->f.samples / (ast_format_rate(rtp->f.subclass) / 1000); 01323 } else { 01324 /* Video -- samples is # of samples vs. 90000 */ 01325 if (!rtp->lastividtimestamp) 01326 rtp->lastividtimestamp = timestamp; 01327 rtp->f.samples = timestamp - rtp->lastividtimestamp; 01328 rtp->lastividtimestamp = timestamp; 01329 rtp->f.delivery.tv_sec = 0; 01330 rtp->f.delivery.tv_usec = 0; 01331 if (mark) 01332 rtp->f.subclass |= 0x1; 01333 01334 } 01335 rtp->f.src = "RTP"; 01336 return &rtp->f; 01337 }
int ast_rtp_reload | ( | void | ) |
Definition at line 3768 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().
03769 { 03770 struct ast_config *cfg; 03771 const char *s; 03772 03773 rtpstart = 5000; 03774 rtpend = 31000; 03775 dtmftimeout = DEFAULT_DTMF_TIMEOUT; 03776 cfg = ast_config_load("rtp.conf"); 03777 if (cfg) { 03778 if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) { 03779 rtpstart = atoi(s); 03780 if (rtpstart < 1024) 03781 rtpstart = 1024; 03782 if (rtpstart > 65535) 03783 rtpstart = 65535; 03784 } 03785 if ((s = ast_variable_retrieve(cfg, "general", "rtpend"))) { 03786 rtpend = atoi(s); 03787 if (rtpend < 1024) 03788 rtpend = 1024; 03789 if (rtpend > 65535) 03790 rtpend = 65535; 03791 } 03792 if ((s = ast_variable_retrieve(cfg, "general", "rtcpinterval"))) { 03793 rtcpinterval = atoi(s); 03794 if (rtcpinterval == 0) 03795 rtcpinterval = 0; /* Just so we're clear... it's zero */ 03796 if (rtcpinterval < RTCP_MIN_INTERVALMS) 03797 rtcpinterval = RTCP_MIN_INTERVALMS; /* This catches negative numbers too */ 03798 if (rtcpinterval > RTCP_MAX_INTERVALMS) 03799 rtcpinterval = RTCP_MAX_INTERVALMS; 03800 } 03801 if ((s = ast_variable_retrieve(cfg, "general", "rtpchecksums"))) { 03802 #ifdef SO_NO_CHECK 03803 if (ast_false(s)) 03804 nochecksums = 1; 03805 else 03806 nochecksums = 0; 03807 #else 03808 if (ast_false(s)) 03809 ast_log(LOG_WARNING, "Disabling RTP checksums is not supported on this operating system!\n"); 03810 #endif 03811 } 03812 if ((s = ast_variable_retrieve(cfg, "general", "dtmftimeout"))) { 03813 dtmftimeout = atoi(s); 03814 if ((dtmftimeout < 0) || (dtmftimeout > 20000)) { 03815 ast_log(LOG_WARNING, "DTMF timeout of '%d' outside range, using default of '%d' instead\n", 03816 dtmftimeout, DEFAULT_DTMF_TIMEOUT); 03817 dtmftimeout = DEFAULT_DTMF_TIMEOUT; 03818 }; 03819 } 03820 ast_config_destroy(cfg); 03821 } 03822 if (rtpstart >= rtpend) { 03823 ast_log(LOG_WARNING, "Unreasonable values for RTP start/end port in rtp.conf\n"); 03824 rtpstart = 5000; 03825 rtpend = 31000; 03826 } 03827 if (option_verbose > 1) 03828 ast_verbose(VERBOSE_PREFIX_2 "RTP Allocating from port range %d -> %d\n", rtpstart, rtpend); 03829 return 0; 03830 }
void ast_rtp_reset | ( | struct ast_rtp * | rtp | ) |
Definition at line 2076 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.
02077 { 02078 memset(&rtp->rxcore, 0, sizeof(rtp->rxcore)); 02079 memset(&rtp->txcore, 0, sizeof(rtp->txcore)); 02080 memset(&rtp->dtmfmute, 0, sizeof(rtp->dtmfmute)); 02081 rtp->lastts = 0; 02082 rtp->lastdigitts = 0; 02083 rtp->lastrxts = 0; 02084 rtp->lastividtimestamp = 0; 02085 rtp->lastovidtimestamp = 0; 02086 rtp->lasteventseqn = 0; 02087 rtp->lastevent = 0; 02088 rtp->lasttxformat = 0; 02089 rtp->lastrxformat = 0; 02090 rtp->dtmfcount = 0; 02091 rtp->dtmfsamples = 0; 02092 rtp->seqno = 0; 02093 rtp->rxseqno = 0; 02094 }
int ast_rtp_sendcng | ( | struct ast_rtp * | rtp, | |
int | level | |||
) |
generate comfort noice (CNG)
Definition at line 2591 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().
02592 { 02593 unsigned int *rtpheader; 02594 int hdrlen = 12; 02595 int res; 02596 int payload; 02597 char data[256]; 02598 level = 127 - (level & 0x7f); 02599 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_CN); 02600 02601 /* If we have no peer, return immediately */ 02602 if (!rtp->them.sin_addr.s_addr) 02603 return 0; 02604 02605 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 02606 02607 /* Get a pointer to the header */ 02608 rtpheader = (unsigned int *)data; 02609 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno++)); 02610 rtpheader[1] = htonl(rtp->lastts); 02611 rtpheader[2] = htonl(rtp->ssrc); 02612 data[12] = level; 02613 if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) { 02614 res = sendto(rtp->s, (void *)rtpheader, hdrlen + 1, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them)); 02615 if (res <0) 02616 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)); 02617 if (rtp_debug_test_addr(&rtp->them)) 02618 ast_verbose("Sent Comfort Noise RTP packet to %s:%u (type %d, seq %u, ts %u, len %d)\n" 02619 , ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen); 02620 02621 } 02622 return 0; 02623 }
int ast_rtp_senddigit_begin | ( | struct ast_rtp * | rtp, | |
char | digit | |||
) |
Send begin frames for DTMF.
Definition at line 2199 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().
02200 { 02201 unsigned int *rtpheader; 02202 int hdrlen = 12, res = 0, i = 0, payload = 0; 02203 char data[256]; 02204 02205 if ((digit <= '9') && (digit >= '0')) 02206 digit -= '0'; 02207 else if (digit == '*') 02208 digit = 10; 02209 else if (digit == '#') 02210 digit = 11; 02211 else if ((digit >= 'A') && (digit <= 'D')) 02212 digit = digit - 'A' + 12; 02213 else if ((digit >= 'a') && (digit <= 'd')) 02214 digit = digit - 'a' + 12; 02215 else { 02216 ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit); 02217 return 0; 02218 } 02219 02220 /* If we have no peer, return immediately */ 02221 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 02222 return 0; 02223 02224 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF); 02225 02226 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 02227 rtp->send_duration = 160; 02228 02229 /* Get a pointer to the header */ 02230 rtpheader = (unsigned int *)data; 02231 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno)); 02232 rtpheader[1] = htonl(rtp->lastdigitts); 02233 rtpheader[2] = htonl(rtp->ssrc); 02234 02235 for (i = 0; i < 2; i++) { 02236 rtpheader[3] = htonl((digit << 24) | (0xa << 16) | (rtp->send_duration)); 02237 res = sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockaddr *) &rtp->them, sizeof(rtp->them)); 02238 if (res < 0) 02239 ast_log(LOG_ERROR, "RTP Transmission error to %s:%u: %s\n", 02240 ast_inet_ntoa(rtp->them.sin_addr), 02241 ntohs(rtp->them.sin_port), strerror(errno)); 02242 if (rtp_debug_test_addr(&rtp->them)) 02243 ast_verbose("Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 02244 ast_inet_ntoa(rtp->them.sin_addr), 02245 ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen); 02246 /* Increment sequence number */ 02247 rtp->seqno++; 02248 /* Increment duration */ 02249 rtp->send_duration += 160; 02250 /* Clear marker bit and set seqno */ 02251 rtpheader[0] = htonl((2 << 30) | (payload << 16) | (rtp->seqno)); 02252 } 02253 02254 /* Since we received a begin, we can safely store the digit and disable any compensation */ 02255 rtp->sending_digit = 1; 02256 rtp->send_digit = digit; 02257 rtp->send_payload = payload; 02258 02259 return 0; 02260 }
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 1647 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().
01648 { 01649 if (pt < 0 || pt > MAX_RTP_PT || static_RTP_PT[pt].code == 0) 01650 return; /* bogus payload type */ 01651 01652 ast_mutex_lock(&rtp->bridge_lock); 01653 rtp->current_RTP_PT[pt] = static_RTP_PT[pt]; 01654 ast_mutex_unlock(&rtp->bridge_lock); 01655 }
void ast_rtp_set_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | them | |||
) |
Definition at line 2020 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().
02021 { 02022 rtp->them.sin_port = them->sin_port; 02023 rtp->them.sin_addr = them->sin_addr; 02024 if (rtp->rtcp) { 02025 rtp->rtcp->them.sin_port = htons(ntohs(them->sin_port) + 1); 02026 rtp->rtcp->them.sin_addr = them->sin_addr; 02027 } 02028 rtp->rxseqno = 0; 02029 }
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.
Definition at line 1674 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().
01677 { 01678 unsigned int i; 01679 int found = 0; 01680 01681 if (pt < 0 || pt > MAX_RTP_PT) 01682 return -1; /* bogus payload type */ 01683 01684 ast_mutex_lock(&rtp->bridge_lock); 01685 01686 for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { 01687 if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 && 01688 strcasecmp(mimeType, mimeTypes[i].type) == 0) { 01689 found = 1; 01690 rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType; 01691 if ((mimeTypes[i].payloadType.code == AST_FORMAT_G726) && 01692 mimeTypes[i].payloadType.isAstFormat && 01693 (options & AST_RTP_OPT_G726_NONSTANDARD)) 01694 rtp->current_RTP_PT[pt].code = AST_FORMAT_G726_AAL2; 01695 break; 01696 } 01697 } 01698 01699 ast_mutex_unlock(&rtp->bridge_lock); 01700 01701 return (found ? 0 : -1); 01702 }
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 2003 of file rtp.c.
References ast_log(), LOG_WARNING, and ast_rtp::s.
Referenced by __oh323_rtp_create(), and sip_alloc().
02004 { 02005 int res; 02006 02007 if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 02008 ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); 02009 return res; 02010 }
void ast_rtp_stop | ( | struct ast_rtp * | rtp | ) |
Definition at line 2060 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().
02061 { 02062 if (rtp->rtcp) { 02063 AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid); 02064 } 02065 02066 memset(&rtp->them.sin_addr, 0, sizeof(rtp->them.sin_addr)); 02067 memset(&rtp->them.sin_port, 0, sizeof(rtp->them.sin_port)); 02068 if (rtp->rtcp) { 02069 memset(&rtp->rtcp->them.sin_addr, 0, sizeof(rtp->rtcp->them.sin_addr)); 02070 memset(&rtp->rtcp->them.sin_port, 0, sizeof(rtp->rtcp->them.sin_port)); 02071 } 02072 02073 ast_clear_flag(rtp, FLAG_P2P_SENT_MARK); 02074 }
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, 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 1659 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().
01660 { 01661 if (pt < 0 || pt > MAX_RTP_PT) 01662 return; /* bogus payload type */ 01663 01664 ast_mutex_lock(&rtp->bridge_lock); 01665 rtp->current_RTP_PT[pt].isAstFormat = 0; 01666 rtp->current_RTP_PT[pt].code = 0; 01667 ast_mutex_unlock(&rtp->bridge_lock); 01668 }
Definition at line 2750 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_frame::datalen, f, fmt, ast_frame::frametype, 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().
02751 { 02752 struct ast_frame *f; 02753 int codec; 02754 int hdrlen = 12; 02755 int subclass; 02756 02757 02758 /* If we have no peer, return immediately */ 02759 if (!rtp->them.sin_addr.s_addr) 02760 return 0; 02761 02762 /* If there is no data length, return immediately */ 02763 if (!_f->datalen) 02764 return 0; 02765 02766 /* Make sure we have enough space for RTP header */ 02767 if ((_f->frametype != AST_FRAME_VOICE) && (_f->frametype != AST_FRAME_VIDEO)) { 02768 ast_log(LOG_WARNING, "RTP can only send voice and video\n"); 02769 return -1; 02770 } 02771 02772 subclass = _f->subclass; 02773 if (_f->frametype == AST_FRAME_VIDEO) 02774 subclass &= ~0x1; 02775 02776 codec = ast_rtp_lookup_code(rtp, 1, subclass); 02777 if (codec < 0) { 02778 ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(_f->subclass)); 02779 return -1; 02780 } 02781 02782 if (rtp->lasttxformat != subclass) { 02783 /* New format, reset the smoother */ 02784 if (option_debug) 02785 ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass)); 02786 rtp->lasttxformat = subclass; 02787 if (rtp->smoother) 02788 ast_smoother_free(rtp->smoother); 02789 rtp->smoother = NULL; 02790 } 02791 02792 if (!rtp->smoother && subclass != AST_FORMAT_SPEEX && subclass != AST_FORMAT_G723_1) { 02793 struct ast_format_list fmt = ast_codec_pref_getsize(&rtp->pref, subclass); 02794 if (fmt.inc_ms) { /* if codec parameters is set / avoid division by zero */ 02795 if (!(rtp->smoother = ast_smoother_new((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms))) { 02796 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)); 02797 return -1; 02798 } 02799 if (fmt.flags) 02800 ast_smoother_set_flags(rtp->smoother, fmt.flags); 02801 if (option_debug) 02802 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)); 02803 } 02804 } 02805 if (rtp->smoother) { 02806 if (ast_smoother_test_flag(rtp->smoother, AST_SMOOTHER_FLAG_BE)) { 02807 ast_smoother_feed_be(rtp->smoother, _f); 02808 } else { 02809 ast_smoother_feed(rtp->smoother, _f); 02810 } 02811 02812 while ((f = ast_smoother_read(rtp->smoother)) && (f->data)) { 02813 if (f->subclass == AST_FORMAT_G722) { 02814 /* G.722 is silllllllllllllly */ 02815 f->samples /= 2; 02816 } 02817 02818 ast_rtp_raw_write(rtp, f, codec); 02819 } 02820 } else { 02821 /* Don't buffer outgoing frames; send them one-per-packet: */ 02822 if (_f->offset < hdrlen) { 02823 f = ast_frdup(_f); 02824 } else { 02825 f = _f; 02826 } 02827 if (f->data) { 02828 if (f->subclass == AST_FORMAT_G722) { 02829 /* G.722 is silllllllllllllly */ 02830 f->samples /= 2; 02831 } 02832 ast_rtp_raw_write(rtp, f, codec); 02833 } 02834 if (f != _f) 02835 ast_frfree(f); 02836 } 02837 02838 return 0; 02839 }