#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. | |
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) |
Make a note of a RTP payload type that was seen in a SDP "m=" line. By default, use the well-known value for this type (although it may still be set to a different value by a subsequent "a=rtpmap:" line). | |
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 | |
void | ast_rtp_set_rtpmap_type (struct ast_rtp *rtp, int pt, char *mimeType, char *mimeSubtype, enum ast_rtp_options options) |
Make a note of a RTP payload type (with MIME type) that was seen in an SDP "a=rtpmap:" line. | |
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) |
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(), and ast_rtp_set_rtpmap_type().
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 822 of file rtp.c.
References ast_rtcp::accumulated_transit, AST_CONTROL_VIDUPDATE, AST_FRAME_CONTROL, AST_FRIENDLY_OFFSET, ast_inet_ntoa(), ast_log(), ast_null_frame, ast_verbose(), CRASH, ast_frame::datalen, 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().
00823 { 00824 socklen_t len; 00825 int position, i, packetwords; 00826 int res; 00827 struct sockaddr_in sin; 00828 unsigned int rtcpdata[8192 + AST_FRIENDLY_OFFSET]; 00829 unsigned int *rtcpheader; 00830 int pt; 00831 struct timeval now; 00832 unsigned int length; 00833 int rc; 00834 double rttsec; 00835 uint64_t rtt = 0; 00836 unsigned int dlsr; 00837 unsigned int lsr; 00838 unsigned int msw; 00839 unsigned int lsw; 00840 unsigned int comp; 00841 struct ast_frame *f = &ast_null_frame; 00842 00843 if (!rtp || !rtp->rtcp) 00844 return &ast_null_frame; 00845 00846 len = sizeof(sin); 00847 00848 res = recvfrom(rtp->rtcp->s, rtcpdata + AST_FRIENDLY_OFFSET, sizeof(rtcpdata) - sizeof(unsigned int) * AST_FRIENDLY_OFFSET, 00849 0, (struct sockaddr *)&sin, &len); 00850 rtcpheader = (unsigned int *)(rtcpdata + AST_FRIENDLY_OFFSET); 00851 00852 if (res < 0) { 00853 if (errno == EBADF) 00854 CRASH; 00855 if (errno != EAGAIN) { 00856 ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n", strerror(errno)); 00857 return NULL; 00858 } 00859 return &ast_null_frame; 00860 } 00861 00862 packetwords = res / 4; 00863 00864 if (rtp->nat) { 00865 /* Send to whoever sent to us */ 00866 if ((rtp->rtcp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || 00867 (rtp->rtcp->them.sin_port != sin.sin_port)) { 00868 memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); 00869 if (option_debug || rtpdebug) 00870 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)); 00871 } 00872 } 00873 00874 if (option_debug) 00875 ast_log(LOG_DEBUG, "Got RTCP report of %d bytes\n", res); 00876 00877 /* Process a compound packet */ 00878 position = 0; 00879 while (position < packetwords) { 00880 i = position; 00881 length = ntohl(rtcpheader[i]); 00882 pt = (length & 0xff0000) >> 16; 00883 rc = (length & 0x1f000000) >> 24; 00884 length &= 0xffff; 00885 00886 if ((i + length) > packetwords) { 00887 ast_log(LOG_WARNING, "RTCP Read too short\n"); 00888 return &ast_null_frame; 00889 } 00890 00891 if (rtcp_debug_test_addr(&sin)) { 00892 ast_verbose("\n\nGot RTCP from %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 00893 ast_verbose("PT: %d(%s)\n", pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown"); 00894 ast_verbose("Reception reports: %d\n", rc); 00895 ast_verbose("SSRC of sender: %u\n", rtcpheader[i + 1]); 00896 } 00897 00898 i += 2; /* Advance past header and ssrc */ 00899 00900 switch (pt) { 00901 case RTCP_PT_SR: 00902 gettimeofday(&rtp->rtcp->rxlsr,NULL); /* To be able to populate the dlsr */ 00903 rtp->rtcp->spc = ntohl(rtcpheader[i+3]); 00904 rtp->rtcp->soc = ntohl(rtcpheader[i + 4]); 00905 rtp->rtcp->themrxlsr = ((ntohl(rtcpheader[i]) & 0x0000ffff) << 16) | ((ntohl(rtcpheader[i + 1]) & 0xffff0000) >> 16); /* Going to LSR in RR*/ 00906 00907 if (rtcp_debug_test_addr(&sin)) { 00908 ast_verbose("NTP timestamp: %lu.%010lu\n", (unsigned long) ntohl(rtcpheader[i]), (unsigned long) ntohl(rtcpheader[i + 1]) * 4096); 00909 ast_verbose("RTP timestamp: %lu\n", (unsigned long) ntohl(rtcpheader[i + 2])); 00910 ast_verbose("SPC: %lu\tSOC: %lu\n", (unsigned long) ntohl(rtcpheader[i + 3]), (unsigned long) ntohl(rtcpheader[i + 4])); 00911 } 00912 i += 5; 00913 if (rc < 1) 00914 break; 00915 /* Intentional fall through */ 00916 case RTCP_PT_RR: 00917 /* Don't handle multiple reception reports (rc > 1) yet */ 00918 /* Calculate RTT per RFC */ 00919 gettimeofday(&now, NULL); 00920 timeval2ntp(now, &msw, &lsw); 00921 if (ntohl(rtcpheader[i + 4]) && ntohl(rtcpheader[i + 5])) { /* We must have the LSR && DLSR */ 00922 comp = ((msw & 0xffff) << 16) | ((lsw & 0xffff0000) >> 16); 00923 lsr = ntohl(rtcpheader[i + 4]); 00924 dlsr = ntohl(rtcpheader[i + 5]); 00925 rtt = comp - lsr - dlsr; 00926 00927 /* Convert end to end delay to usec (keeping the calculation in 64bit space) 00928 sess->ee_delay = (eedelay * 1000) / 65536; */ 00929 if (rtt < 4294) { 00930 rtt = (rtt * 1000000) >> 16; 00931 } else { 00932 rtt = (rtt * 1000) >> 16; 00933 rtt *= 1000; 00934 } 00935 rtt = rtt / 1000.; 00936 rttsec = rtt / 1000.; 00937 00938 if (comp - dlsr >= lsr) { 00939 rtp->rtcp->accumulated_transit += rttsec; 00940 rtp->rtcp->rtt = rttsec; 00941 if (rtp->rtcp->maxrtt<rttsec) 00942 rtp->rtcp->maxrtt = rttsec; 00943 if (rtp->rtcp->minrtt>rttsec) 00944 rtp->rtcp->minrtt = rttsec; 00945 } else if (rtcp_debug_test_addr(&sin)) { 00946 ast_verbose("Internal RTCP NTP clock skew detected: " 00947 "lsr=%u, now=%u, dlsr=%u (%d:%03dms), " 00948 "diff=%d\n", 00949 lsr, comp, dlsr, dlsr / 65536, 00950 (dlsr % 65536) * 1000 / 65536, 00951 dlsr - (comp - lsr)); 00952 } 00953 } 00954 00955 rtp->rtcp->reported_jitter = ntohl(rtcpheader[i + 3]); 00956 rtp->rtcp->reported_lost = ntohl(rtcpheader[i + 1]) & 0xffffff; 00957 if (rtcp_debug_test_addr(&sin)) { 00958 ast_verbose(" Fraction lost: %ld\n", (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24)); 00959 ast_verbose(" Packets lost so far: %d\n", rtp->rtcp->reported_lost); 00960 ast_verbose(" Highest sequence number: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff)); 00961 ast_verbose(" Sequence number cycles: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16); 00962 ast_verbose(" Interarrival jitter: %u\n", rtp->rtcp->reported_jitter); 00963 ast_verbose(" Last SR(our NTP): %lu.%010lu\n",(unsigned long) ntohl(rtcpheader[i + 4]) >> 16,((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096); 00964 ast_verbose(" DLSR: %4.4f (sec)\n",ntohl(rtcpheader[i + 5])/65536.0); 00965 if (rtt) 00966 ast_verbose(" RTT: %lu(sec)\n", (unsigned long) rtt); 00967 } 00968 break; 00969 case RTCP_PT_FUR: 00970 if (rtcp_debug_test_addr(&sin)) 00971 ast_verbose("Received an RTCP Fast Update Request\n"); 00972 rtp->f.frametype = AST_FRAME_CONTROL; 00973 rtp->f.subclass = AST_CONTROL_VIDUPDATE; 00974 rtp->f.datalen = 0; 00975 rtp->f.samples = 0; 00976 rtp->f.mallocd = 0; 00977 rtp->f.src = "RTP"; 00978 f = &rtp->f; 00979 break; 00980 case RTCP_PT_SDES: 00981 if (rtcp_debug_test_addr(&sin)) 00982 ast_verbose("Received an SDES from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 00983 break; 00984 case RTCP_PT_BYE: 00985 if (rtcp_debug_test_addr(&sin)) 00986 ast_verbose("Received a BYE from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 00987 break; 00988 default: 00989 if (option_debug) 00990 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)); 00991 break; 00992 } 00993 position += (length + 1); 00994 } 00995 00996 return f; 00997 }
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 2298 of file rtp.c.
References ast_rtcp_write(), ast_rtp::rtcp, and ast_rtcp::sendfur.
02299 { 02300 struct ast_rtp *rtp = data; 02301 int res; 02302 02303 rtp->rtcp->sendfur = 1; 02304 res = ast_rtcp_write(data); 02305 02306 return res; 02307 }
size_t ast_rtp_alloc_size | ( | void | ) |
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 3206 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_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_DTMF_COMPENSATE, 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.
03207 { 03208 struct ast_rtp *p0 = NULL, *p1 = NULL; /* Audio RTP Channels */ 03209 struct ast_rtp *vp0 = NULL, *vp1 = NULL; /* Video RTP channels */ 03210 struct ast_rtp_protocol *pr0 = NULL, *pr1 = NULL; 03211 enum ast_rtp_get_result audio_p0_res = AST_RTP_GET_FAILED, video_p0_res = AST_RTP_GET_FAILED; 03212 enum ast_rtp_get_result audio_p1_res = AST_RTP_GET_FAILED, video_p1_res = AST_RTP_GET_FAILED; 03213 enum ast_bridge_result res = AST_BRIDGE_FAILED; 03214 int codec0 = 0, codec1 = 0; 03215 void *pvt0 = NULL, *pvt1 = NULL; 03216 03217 /* Lock channels */ 03218 ast_channel_lock(c0); 03219 while(ast_channel_trylock(c1)) { 03220 ast_channel_unlock(c0); 03221 usleep(1); 03222 ast_channel_lock(c0); 03223 } 03224 03225 /* Find channel driver interfaces */ 03226 if (!(pr0 = get_proto(c0))) { 03227 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name); 03228 ast_channel_unlock(c0); 03229 ast_channel_unlock(c1); 03230 return AST_BRIDGE_FAILED; 03231 } 03232 if (!(pr1 = get_proto(c1))) { 03233 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name); 03234 ast_channel_unlock(c0); 03235 ast_channel_unlock(c1); 03236 return AST_BRIDGE_FAILED; 03237 } 03238 03239 /* Get channel specific interface structures */ 03240 pvt0 = c0->tech_pvt; 03241 pvt1 = c1->tech_pvt; 03242 03243 /* Get audio and video interface (if native bridge is possible) */ 03244 audio_p0_res = pr0->get_rtp_info(c0, &p0); 03245 video_p0_res = pr0->get_vrtp_info ? pr0->get_vrtp_info(c0, &vp0) : AST_RTP_GET_FAILED; 03246 audio_p1_res = pr1->get_rtp_info(c1, &p1); 03247 video_p1_res = pr1->get_vrtp_info ? pr1->get_vrtp_info(c1, &vp1) : AST_RTP_GET_FAILED; 03248 03249 /* If we are carrying video, and both sides are not reinviting... then fail the native bridge */ 03250 if (video_p0_res != AST_RTP_GET_FAILED && (audio_p0_res != AST_RTP_TRY_NATIVE || video_p0_res != AST_RTP_TRY_NATIVE)) 03251 audio_p0_res = AST_RTP_GET_FAILED; 03252 if (video_p1_res != AST_RTP_GET_FAILED && (audio_p1_res != AST_RTP_TRY_NATIVE || video_p1_res != AST_RTP_TRY_NATIVE)) 03253 audio_p1_res = AST_RTP_GET_FAILED; 03254 03255 /* Check if a bridge is possible (partial/native) */ 03256 if (audio_p0_res == AST_RTP_GET_FAILED || audio_p1_res == AST_RTP_GET_FAILED) { 03257 /* Somebody doesn't want to play... */ 03258 ast_channel_unlock(c0); 03259 ast_channel_unlock(c1); 03260 return AST_BRIDGE_FAILED_NOWARN; 03261 } 03262 03263 /* If we need to feed DTMF frames into the core then only do a partial native bridge */ 03264 if (ast_test_flag(p0, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) { 03265 ast_set_flag(p0, FLAG_P2P_NEED_DTMF); 03266 audio_p0_res = AST_RTP_TRY_PARTIAL; 03267 } 03268 03269 if (ast_test_flag(p1, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)) { 03270 ast_set_flag(p1, FLAG_P2P_NEED_DTMF); 03271 audio_p1_res = AST_RTP_TRY_PARTIAL; 03272 } 03273 03274 /* If both sides are not using the same method of DTMF transmission 03275 * (ie: one is RFC2833, other is INFO... then we can not do direct media. 03276 * -------------------------------------------------- 03277 * | DTMF Mode | HAS_DTMF | Accepts Begin Frames | 03278 * |-----------|------------|-----------------------| 03279 * | Inband | False | True | 03280 * | RFC2833 | True | True | 03281 * | SIP INFO | False | False | 03282 * -------------------------------------------------- 03283 * However, if DTMF from both channels is being monitored by the core, then 03284 * we can still do packet-to-packet bridging, because passing through the 03285 * core will handle DTMF mode translation. 03286 */ 03287 if ( (ast_test_flag(p0, FLAG_HAS_DTMF) != ast_test_flag(p1, FLAG_HAS_DTMF)) || 03288 (!c0->tech->send_digit_begin != !c1->tech->send_digit_begin)) { 03289 if (!ast_test_flag(p0, FLAG_P2P_NEED_DTMF) || !ast_test_flag(p1, FLAG_P2P_NEED_DTMF)) { 03290 ast_channel_unlock(c0); 03291 ast_channel_unlock(c1); 03292 return AST_BRIDGE_FAILED_NOWARN; 03293 } 03294 audio_p0_res = AST_RTP_TRY_PARTIAL; 03295 audio_p1_res = AST_RTP_TRY_PARTIAL; 03296 } 03297 03298 /* If the core will need to compensate and the P2P bridge will need to feed up DTMF frames then we can not reliably do so yet, so do not P2P bridge */ 03299 if ((audio_p0_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p0, FLAG_P2P_NEED_DTMF) && ast_test_flag(p0, FLAG_DTMF_COMPENSATE)) || 03300 (audio_p1_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p1, FLAG_P2P_NEED_DTMF) && ast_test_flag(p1, FLAG_DTMF_COMPENSATE))) { 03301 ast_channel_unlock(c0); 03302 ast_channel_unlock(c1); 03303 return AST_BRIDGE_FAILED_NOWARN; 03304 } 03305 03306 /* Get codecs from both sides */ 03307 codec0 = pr0->get_codec ? pr0->get_codec(c0) : 0; 03308 codec1 = pr1->get_codec ? pr1->get_codec(c1) : 0; 03309 if (codec0 && codec1 && !(codec0 & codec1)) { 03310 /* Hey, we can't do native bridging if both parties speak different codecs */ 03311 if (option_debug) 03312 ast_log(LOG_DEBUG, "Channel codec0 = %d is not codec1 = %d, cannot native bridge in RTP.\n", codec0, codec1); 03313 ast_channel_unlock(c0); 03314 ast_channel_unlock(c1); 03315 return AST_BRIDGE_FAILED_NOWARN; 03316 } 03317 03318 /* If either side can only do a partial bridge, then don't try for a true native bridge */ 03319 if (audio_p0_res == AST_RTP_TRY_PARTIAL || audio_p1_res == AST_RTP_TRY_PARTIAL) { 03320 struct ast_format_list fmt0, fmt1; 03321 03322 /* In order to do Packet2Packet bridging both sides must be in the same rawread/rawwrite */ 03323 if (c0->rawreadformat != c1->rawwriteformat || c1->rawreadformat != c0->rawwriteformat) { 03324 if (option_debug) 03325 ast_log(LOG_DEBUG, "Cannot packet2packet bridge - raw formats are incompatible\n"); 03326 ast_channel_unlock(c0); 03327 ast_channel_unlock(c1); 03328 return AST_BRIDGE_FAILED_NOWARN; 03329 } 03330 /* They must also be using the same packetization */ 03331 fmt0 = ast_codec_pref_getsize(&p0->pref, c0->rawreadformat); 03332 fmt1 = ast_codec_pref_getsize(&p1->pref, c1->rawreadformat); 03333 if (fmt0.cur_ms != fmt1.cur_ms) { 03334 if (option_debug) 03335 ast_log(LOG_DEBUG, "Cannot packet2packet bridge - packetization settings prevent it\n"); 03336 ast_channel_unlock(c0); 03337 ast_channel_unlock(c1); 03338 return AST_BRIDGE_FAILED_NOWARN; 03339 } 03340 03341 if (option_verbose > 2) 03342 ast_verbose(VERBOSE_PREFIX_3 "Packet2Packet bridging %s and %s\n", c0->name, c1->name); 03343 res = bridge_p2p_loop(c0, c1, p0, p1, timeoutms, flags, fo, rc, pvt0, pvt1); 03344 } else { 03345 if (option_verbose > 2) 03346 ast_verbose(VERBOSE_PREFIX_3 "Native bridging %s and %s\n", c0->name, c1->name); 03347 res = bridge_native_loop(c0, c1, p0, p1, vp0, vp1, pr0, pr1, codec0, codec1, timeoutms, flags, fo, rc, pvt0, pvt1); 03348 } 03349 03350 return res; 03351 }
int ast_rtp_codec_getformat | ( | int | pt | ) |
Definition at line 2681 of file rtp.c.
References rtpPayloadType::code, and MAX_RTP_PT.
02682 { 02683 if (pt < 0 || pt > MAX_RTP_PT) 02684 return 0; /* bogus payload type */ 02685 02686 if (static_RTP_PT[pt].isAstFormat) 02687 return static_RTP_PT[pt].code; 02688 else 02689 return 0; 02690 }
struct ast_codec_pref* ast_rtp_codec_getpref | ( | struct ast_rtp * | rtp | ) | [read] |
Definition at line 2676 of file rtp.c.
References ast_rtp::pref.
02677 { 02678 return &rtp->pref; 02679 }
int ast_rtp_codec_setpref | ( | struct ast_rtp * | rtp, | |
struct ast_codec_pref * | prefs | |||
) |
Definition at line 2663 of file rtp.c.
References ast_smoother_free(), ast_codec_pref::framing, ast_codec_pref::order, ast_rtp::pref, and ast_rtp::smoother.
02664 { 02665 int x; 02666 for (x = 0; x < 32; x++) { /* Ugly way */ 02667 rtp->pref.order[x] = prefs->order[x]; 02668 rtp->pref.framing[x] = prefs->framing[x]; 02669 } 02670 if (rtp->smoother) 02671 ast_smoother_free(rtp->smoother); 02672 rtp->smoother = NULL; 02673 return 0; 02674 }
void ast_rtp_destroy | ( | struct ast_rtp * | rtp | ) |
Definition at line 2080 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.
02081 { 02082 if (rtcp_debug_test_addr(&rtp->them) || rtcpstats) { 02083 /*Print some info on the call here */ 02084 ast_verbose(" RTP-stats\n"); 02085 ast_verbose("* Our Receiver:\n"); 02086 ast_verbose(" SSRC: %u\n", rtp->themssrc); 02087 ast_verbose(" Received packets: %u\n", rtp->rxcount); 02088 ast_verbose(" Lost packets: %u\n", rtp->rtcp->expected_prior - rtp->rtcp->received_prior); 02089 ast_verbose(" Jitter: %.4f\n", rtp->rxjitter); 02090 ast_verbose(" Transit: %.4f\n", rtp->rxtransit); 02091 ast_verbose(" RR-count: %u\n", rtp->rtcp->rr_count); 02092 ast_verbose("* Our Sender:\n"); 02093 ast_verbose(" SSRC: %u\n", rtp->ssrc); 02094 ast_verbose(" Sent packets: %u\n", rtp->txcount); 02095 ast_verbose(" Lost packets: %u\n", rtp->rtcp->reported_lost); 02096 ast_verbose(" Jitter: %u\n", rtp->rtcp->reported_jitter); 02097 ast_verbose(" SR-count: %u\n", rtp->rtcp->sr_count); 02098 ast_verbose(" RTT: %f\n", rtp->rtcp->rtt); 02099 } 02100 02101 if (rtp->smoother) 02102 ast_smoother_free(rtp->smoother); 02103 if (rtp->ioid) 02104 ast_io_remove(rtp->io, rtp->ioid); 02105 if (rtp->s > -1) 02106 close(rtp->s); 02107 if (rtp->rtcp) { 02108 if (rtp->rtcp->schedid > 0) 02109 ast_sched_del(rtp->sched, rtp->rtcp->schedid); 02110 close(rtp->rtcp->s); 02111 free(rtp->rtcp); 02112 rtp->rtcp=NULL; 02113 } 02114 02115 ast_mutex_destroy(&rtp->bridge_lock); 02116 02117 free(rtp); 02118 }
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 1466 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.
01467 { 01468 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 01469 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 01470 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 01471 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED; 01472 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED; 01473 int srccodec, destcodec, nat_active = 0; 01474 01475 /* Lock channels */ 01476 ast_channel_lock(dest); 01477 if (src) { 01478 while(ast_channel_trylock(src)) { 01479 ast_channel_unlock(dest); 01480 usleep(1); 01481 ast_channel_lock(dest); 01482 } 01483 } 01484 01485 /* Find channel driver interfaces */ 01486 destpr = get_proto(dest); 01487 if (src) 01488 srcpr = get_proto(src); 01489 if (!destpr) { 01490 if (option_debug) 01491 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name); 01492 ast_channel_unlock(dest); 01493 if (src) 01494 ast_channel_unlock(src); 01495 return 0; 01496 } 01497 if (!srcpr) { 01498 if (option_debug) 01499 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src ? src->name : "<unspecified>"); 01500 ast_channel_unlock(dest); 01501 if (src) 01502 ast_channel_unlock(src); 01503 return 0; 01504 } 01505 01506 /* Get audio and video interface (if native bridge is possible) */ 01507 audio_dest_res = destpr->get_rtp_info(dest, &destp); 01508 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 01509 if (srcpr) { 01510 audio_src_res = srcpr->get_rtp_info(src, &srcp); 01511 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 01512 } 01513 01514 /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */ 01515 if (audio_dest_res != AST_RTP_TRY_NATIVE) { 01516 /* Somebody doesn't want to play... */ 01517 ast_channel_unlock(dest); 01518 if (src) 01519 ast_channel_unlock(src); 01520 return 0; 01521 } 01522 if (audio_src_res == AST_RTP_TRY_NATIVE && srcpr->get_codec) 01523 srccodec = srcpr->get_codec(src); 01524 else 01525 srccodec = 0; 01526 if (audio_dest_res == AST_RTP_TRY_NATIVE && destpr->get_codec) 01527 destcodec = destpr->get_codec(dest); 01528 else 01529 destcodec = 0; 01530 /* Ensure we have at least one matching codec */ 01531 if (!(srccodec & destcodec)) { 01532 ast_channel_unlock(dest); 01533 if (src) 01534 ast_channel_unlock(src); 01535 return 0; 01536 } 01537 /* Consider empty media as non-existant */ 01538 if (audio_src_res == AST_RTP_TRY_NATIVE && !srcp->them.sin_addr.s_addr) 01539 srcp = NULL; 01540 /* If the client has NAT stuff turned on then just safe NAT is active */ 01541 if (srcp && (srcp->nat || ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 01542 nat_active = 1; 01543 /* Bridge media early */ 01544 if (destpr->set_rtp_peer(dest, srcp, vsrcp, srccodec, nat_active)) 01545 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src ? src->name : "<unspecified>"); 01546 ast_channel_unlock(dest); 01547 if (src) 01548 ast_channel_unlock(src); 01549 if (option_debug) 01550 ast_log(LOG_DEBUG, "Setting early bridge SDP of '%s' with that of '%s'\n", dest->name, src ? src->name : "<unspecified>"); 01551 return 1; 01552 }
int ast_rtp_fd | ( | struct ast_rtp * | rtp | ) |
Definition at line 2002 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, and ast_rtp::bridged.
02003 { 02004 struct ast_rtp *bridged = NULL; 02005 02006 ast_mutex_lock(&rtp->bridge_lock); 02007 bridged = rtp->bridged; 02008 ast_mutex_unlock(&rtp->bridge_lock); 02009 02010 return bridged; 02011 }
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 1672 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.
01674 { 01675 int pt; 01676 01677 ast_mutex_lock(&rtp->bridge_lock); 01678 01679 *astFormats = *nonAstFormats = 0; 01680 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01681 if (rtp->current_RTP_PT[pt].isAstFormat) { 01682 *astFormats |= rtp->current_RTP_PT[pt].code; 01683 } else { 01684 *nonAstFormats |= rtp->current_RTP_PT[pt].code; 01685 } 01686 } 01687 01688 ast_mutex_unlock(&rtp->bridge_lock); 01689 01690 return; 01691 }
int ast_rtp_get_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | them | |||
) |
Definition at line 1984 of file rtp.c.
References ast_rtp::them.
01985 { 01986 if ((them->sin_family != AF_INET) || 01987 (them->sin_port != rtp->them.sin_port) || 01988 (them->sin_addr.s_addr != rtp->them.sin_addr.s_addr)) { 01989 them->sin_family = AF_INET; 01990 them->sin_port = rtp->them.sin_port; 01991 them->sin_addr = rtp->them.sin_addr; 01992 return 1; 01993 } 01994 return 0; 01995 }
char* ast_rtp_get_quality | ( | struct ast_rtp * | rtp, | |
struct ast_rtp_quality * | qual | |||
) |
Return RTCP quality string.
Definition at line 2050 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.
02051 { 02052 /* 02053 *ssrc our ssrc 02054 *themssrc their ssrc 02055 *lp lost packets 02056 *rxjitter our calculated jitter(rx) 02057 *rxcount no. received packets 02058 *txjitter reported jitter of the other end 02059 *txcount transmitted packets 02060 *rlp remote lost packets 02061 *rtt round trip time 02062 */ 02063 02064 if (qual) { 02065 qual->local_ssrc = rtp->ssrc; 02066 qual->local_lostpackets = rtp->rtcp->expected_prior - rtp->rtcp->received_prior; 02067 qual->local_jitter = rtp->rxjitter; 02068 qual->local_count = rtp->rxcount; 02069 qual->remote_ssrc = rtp->themssrc; 02070 qual->remote_lostpackets = rtp->rtcp->reported_lost; 02071 qual->remote_jitter = rtp->rtcp->reported_jitter / 65536.0; 02072 qual->remote_count = rtp->txcount; 02073 qual->rtt = rtp->rtcp->rtt; 02074 } 02075 snprintf(rtp->rtcp->quality, sizeof(rtp->rtcp->quality), "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;txjitter=%f;txcount=%u;rlp=%u;rtt=%f", rtp->ssrc, rtp->themssrc, rtp->rtcp->expected_prior - rtp->rtcp->received_prior, rtp->rxjitter, rtp->rxcount, (double)rtp->rtcp->reported_jitter/65536., rtp->txcount, rtp->rtcp->reported_lost, rtp->rtcp->rtt); 02076 02077 return rtp->rtcp->quality; 02078 }
int ast_rtp_get_rtpholdtimeout | ( | struct ast_rtp * | rtp | ) |
Get rtp hold timeout.
Definition at line 567 of file rtp.c.
References ast_rtp::rtpholdtimeout, and ast_rtp::rtptimeout.
00568 { 00569 if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */ 00570 return 0; 00571 return rtp->rtpholdtimeout; 00572 }
int ast_rtp_get_rtpkeepalive | ( | struct ast_rtp * | rtp | ) |
Get RTP keepalive interval.
Definition at line 575 of file rtp.c.
References ast_rtp::rtpkeepalive.
00576 { 00577 return rtp->rtpkeepalive; 00578 }
int ast_rtp_get_rtptimeout | ( | struct ast_rtp * | rtp | ) |
Get rtp timeout.
Definition at line 559 of file rtp.c.
References ast_rtp::rtptimeout.
00560 { 00561 if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */ 00562 return 0; 00563 return rtp->rtptimeout; 00564 }
void ast_rtp_get_us | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | us | |||
) |
int ast_rtp_getnat | ( | struct ast_rtp * | rtp | ) |
Definition at line 595 of file rtp.c.
References ast_test_flag, and FLAG_NAT_ACTIVE.
00596 { 00597 return ast_test_flag(rtp, FLAG_NAT_ACTIVE); 00598 }
void ast_rtp_init | ( | void | ) |
Initialize the RTP system in Asterisk.
Definition at line 3736 of file rtp.c.
References ast_cli_register_multiple(), and ast_rtp_reload().
03737 { 03738 ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry)); 03739 ast_rtp_reload(); 03740 }
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 1715 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.
01716 { 01717 int pt = 0; 01718 01719 ast_mutex_lock(&rtp->bridge_lock); 01720 01721 if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && 01722 code == rtp->rtp_lookup_code_cache_code) { 01723 /* Use our cached mapping, to avoid the overhead of the loop below */ 01724 pt = rtp->rtp_lookup_code_cache_result; 01725 ast_mutex_unlock(&rtp->bridge_lock); 01726 return pt; 01727 } 01728 01729 /* Check the dynamic list first */ 01730 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01731 if (rtp->current_RTP_PT[pt].code == code && rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) { 01732 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 01733 rtp->rtp_lookup_code_cache_code = code; 01734 rtp->rtp_lookup_code_cache_result = pt; 01735 ast_mutex_unlock(&rtp->bridge_lock); 01736 return pt; 01737 } 01738 } 01739 01740 /* Then the static list */ 01741 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 01742 if (static_RTP_PT[pt].code == code && static_RTP_PT[pt].isAstFormat == isAstFormat) { 01743 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 01744 rtp->rtp_lookup_code_cache_code = code; 01745 rtp->rtp_lookup_code_cache_result = pt; 01746 ast_mutex_unlock(&rtp->bridge_lock); 01747 return pt; 01748 } 01749 } 01750 01751 ast_mutex_unlock(&rtp->bridge_lock); 01752 01753 return -1; 01754 }
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 1775 of file rtp.c.
References ast_rtp_lookup_mime_subtype(), AST_RTP_MAX, format, len, and name.
01777 { 01778 int format; 01779 unsigned len; 01780 char *end = buf; 01781 char *start = buf; 01782 01783 if (!buf || !size) 01784 return NULL; 01785 01786 snprintf(end, size, "0x%x (", capability); 01787 01788 len = strlen(end); 01789 end += len; 01790 size -= len; 01791 start = end; 01792 01793 for (format = 1; format < AST_RTP_MAX; format <<= 1) { 01794 if (capability & format) { 01795 const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format, options); 01796 01797 snprintf(end, size, "%s|", name); 01798 len = strlen(end); 01799 end += len; 01800 size -= len; 01801 } 01802 } 01803 01804 if (start == end) 01805 snprintf(start, size, "nothing)"); 01806 else if (size > 1) 01807 *(end -1) = ')'; 01808 01809 return buf; 01810 }
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 1756 of file rtp.c.
References AST_FORMAT_G726_AAL2, AST_RTP_OPT_G726_NONSTANDARD, rtpPayloadType::code, mimeTypes, and payloadType.
01758 { 01759 unsigned int i; 01760 01761 for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { 01762 if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) { 01763 if (isAstFormat && 01764 (code == AST_FORMAT_G726_AAL2) && 01765 (options & AST_RTP_OPT_G726_NONSTANDARD)) 01766 return "G726-32"; 01767 else 01768 return mimeTypes[i].subtype; 01769 } 01770 } 01771 01772 return ""; 01773 }
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 1693 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), rtpPayloadType::code, rtpPayloadType::isAstFormat, and MAX_RTP_PT.
01694 { 01695 struct rtpPayloadType result; 01696 01697 result.isAstFormat = result.code = 0; 01698 01699 if (pt < 0 || pt > MAX_RTP_PT) 01700 return result; /* bogus payload type */ 01701 01702 /* Start with negotiated codecs */ 01703 ast_mutex_lock(&rtp->bridge_lock); 01704 result = rtp->current_RTP_PT[pt]; 01705 ast_mutex_unlock(&rtp->bridge_lock); 01706 01707 /* If it doesn't exist, check our static RTP type list, just in case */ 01708 if (!result.code) 01709 result = static_RTP_PT[pt]; 01710 01711 return result; 01712 }
int ast_rtp_make_compatible | ( | struct ast_channel * | dest, | |
struct ast_channel * | src, | |||
int | media | |||
) |
Definition at line 1554 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.
01555 { 01556 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 01557 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 01558 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 01559 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED; 01560 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED; 01561 int srccodec, destcodec; 01562 01563 /* Lock channels */ 01564 ast_channel_lock(dest); 01565 while(ast_channel_trylock(src)) { 01566 ast_channel_unlock(dest); 01567 usleep(1); 01568 ast_channel_lock(dest); 01569 } 01570 01571 /* Find channel driver interfaces */ 01572 if (!(destpr = get_proto(dest))) { 01573 if (option_debug) 01574 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name); 01575 ast_channel_unlock(dest); 01576 ast_channel_unlock(src); 01577 return 0; 01578 } 01579 if (!(srcpr = get_proto(src))) { 01580 if (option_debug) 01581 ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src->name); 01582 ast_channel_unlock(dest); 01583 ast_channel_unlock(src); 01584 return 0; 01585 } 01586 01587 /* Get audio and video interface (if native bridge is possible) */ 01588 audio_dest_res = destpr->get_rtp_info(dest, &destp); 01589 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 01590 audio_src_res = srcpr->get_rtp_info(src, &srcp); 01591 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 01592 01593 /* Ensure we have at least one matching codec */ 01594 if (srcpr->get_codec) 01595 srccodec = srcpr->get_codec(src); 01596 else 01597 srccodec = 0; 01598 if (destpr->get_codec) 01599 destcodec = destpr->get_codec(dest); 01600 else 01601 destcodec = 0; 01602 01603 /* Check if bridge is still possible (In SIP canreinvite=no stops this, like NAT) */ 01604 if (audio_dest_res != AST_RTP_TRY_NATIVE || audio_src_res != AST_RTP_TRY_NATIVE || !(srccodec & destcodec)) { 01605 /* Somebody doesn't want to play... */ 01606 ast_channel_unlock(dest); 01607 ast_channel_unlock(src); 01608 return 0; 01609 } 01610 ast_rtp_pt_copy(destp, srcp); 01611 if (vdestp && vsrcp) 01612 ast_rtp_pt_copy(vdestp, vsrcp); 01613 if (media) { 01614 /* Bridge early */ 01615 if (destpr->set_rtp_peer(dest, srcp, vsrcp, srccodec, ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 01616 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src->name); 01617 } 01618 ast_channel_unlock(dest); 01619 ast_channel_unlock(src); 01620 if (option_debug) 01621 ast_log(LOG_DEBUG, "Seeded SDP of '%s' with that of '%s'\n", dest->name, src->name); 01622 return 1; 01623 }
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 1956 of file rtp.c.
References ast_rtp_new_with_bindaddr().
01957 { 01958 struct in_addr ia; 01959 01960 memset(&ia, 0, sizeof(ia)); 01961 return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia); 01962 }
void ast_rtp_new_init | ( | struct ast_rtp * | rtp | ) |
Initialize a new RTP structure.
Definition at line 1856 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.
01857 { 01858 ast_mutex_init(&rtp->bridge_lock); 01859 01860 rtp->them.sin_family = AF_INET; 01861 rtp->us.sin_family = AF_INET; 01862 rtp->ssrc = ast_random(); 01863 rtp->seqno = ast_random() & 0xffff; 01864 ast_set_flag(rtp, FLAG_HAS_DTMF); 01865 01866 return; 01867 }
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 1869 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, 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.
01870 { 01871 struct ast_rtp *rtp; 01872 int x; 01873 int first; 01874 int startplace; 01875 01876 if (!(rtp = ast_calloc(1, sizeof(*rtp)))) 01877 return NULL; 01878 01879 ast_rtp_new_init(rtp); 01880 01881 rtp->s = rtp_socket(); 01882 if (rtp->s < 0) { 01883 free(rtp); 01884 ast_log(LOG_ERROR, "Unable to allocate socket: %s\n", strerror(errno)); 01885 return NULL; 01886 } 01887 if (sched && rtcpenable) { 01888 rtp->sched = sched; 01889 rtp->rtcp = ast_rtcp_new(); 01890 } 01891 01892 /* Select a random port number in the range of possible RTP */ 01893 x = (ast_random() % (rtpend-rtpstart)) + rtpstart; 01894 x = x & ~1; 01895 /* Save it for future references. */ 01896 startplace = x; 01897 /* Iterate tring to bind that port and incrementing it otherwise untill a port was found or no ports are available. */ 01898 for (;;) { 01899 /* Must be an even port number by RTP spec */ 01900 rtp->us.sin_port = htons(x); 01901 rtp->us.sin_addr = addr; 01902 /* If there's rtcp, initialize it as well. */ 01903 if (rtp->rtcp) { 01904 rtp->rtcp->us.sin_port = htons(x + 1); 01905 rtp->rtcp->us.sin_addr = addr; 01906 } 01907 /* Try to bind it/them. */ 01908 if (!(first = bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us))) && 01909 (!rtp->rtcp || !bind(rtp->rtcp->s, (struct sockaddr *)&rtp->rtcp->us, sizeof(rtp->rtcp->us)))) 01910 break; 01911 if (!first) { 01912 /* Primary bind succeeded! Gotta recreate it */ 01913 close(rtp->s); 01914 rtp->s = rtp_socket(); 01915 } 01916 if (errno != EADDRINUSE) { 01917 /* We got an error that wasn't expected, abort! */ 01918 ast_log(LOG_ERROR, "Unexpected bind error: %s\n", strerror(errno)); 01919 close(rtp->s); 01920 if (rtp->rtcp) { 01921 close(rtp->rtcp->s); 01922 free(rtp->rtcp); 01923 } 01924 free(rtp); 01925 return NULL; 01926 } 01927 /* The port was used, increment it (by two). */ 01928 x += 2; 01929 /* Did we go over the limit ? */ 01930 if (x > rtpend) 01931 /* then, start from the begingig. */ 01932 x = (rtpstart + 1) & ~1; 01933 /* Check if we reached the place were we started. */ 01934 if (x == startplace) { 01935 /* If so, there's no ports available. */ 01936 ast_log(LOG_ERROR, "No RTP ports remaining. Can't setup media stream for this call.\n"); 01937 close(rtp->s); 01938 if (rtp->rtcp) { 01939 close(rtp->rtcp->s); 01940 free(rtp->rtcp); 01941 } 01942 free(rtp); 01943 return NULL; 01944 } 01945 } 01946 rtp->sched = sched; 01947 rtp->io = io; 01948 if (callbackmode) { 01949 rtp->ioid = ast_io_add(rtp->io, rtp->s, rtpread, AST_IO_IN, rtp); 01950 ast_set_flag(rtp, FLAG_CALLBACK_MODE); 01951 } 01952 ast_rtp_pt_default(rtp); 01953 return rtp; 01954 }
int ast_rtp_proto_register | ( | struct ast_rtp_protocol * | proto | ) |
Register interface to channel driver.
Definition at line 2781 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.
02782 { 02783 struct ast_rtp_protocol *cur; 02784 02785 AST_LIST_LOCK(&protos); 02786 AST_LIST_TRAVERSE(&protos, cur, list) { 02787 if (!strcmp(cur->type, proto->type)) { 02788 ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type); 02789 AST_LIST_UNLOCK(&protos); 02790 return -1; 02791 } 02792 } 02793 AST_LIST_INSERT_HEAD(&protos, proto, list); 02794 AST_LIST_UNLOCK(&protos); 02795 02796 return 0; 02797 }
void ast_rtp_proto_unregister | ( | struct ast_rtp_protocol * | proto | ) |
Unregister interface to channel driver.
Definition at line 2773 of file rtp.c.
References AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, and protos.
02774 { 02775 AST_LIST_LOCK(&protos); 02776 AST_LIST_REMOVE(&protos, proto, list); 02777 AST_LIST_UNLOCK(&protos); 02778 }
void ast_rtp_pt_clear | ( | struct ast_rtp * | rtp | ) |
Setting RTP payload types from lines in a SDP description:.
Definition at line 1390 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.
01391 { 01392 int i; 01393 01394 if (!rtp) 01395 return; 01396 01397 ast_mutex_lock(&rtp->bridge_lock); 01398 01399 for (i = 0; i < MAX_RTP_PT; ++i) { 01400 rtp->current_RTP_PT[i].isAstFormat = 0; 01401 rtp->current_RTP_PT[i].code = 0; 01402 } 01403 01404 rtp->rtp_lookup_code_cache_isAstFormat = 0; 01405 rtp->rtp_lookup_code_cache_code = 0; 01406 rtp->rtp_lookup_code_cache_result = 0; 01407 01408 ast_mutex_unlock(&rtp->bridge_lock); 01409 }
Copy payload types between RTP structures.
Definition at line 1430 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.
01431 { 01432 unsigned int i; 01433 01434 ast_mutex_lock(&dest->bridge_lock); 01435 ast_mutex_lock(&src->bridge_lock); 01436 01437 for (i=0; i < MAX_RTP_PT; ++i) { 01438 dest->current_RTP_PT[i].isAstFormat = 01439 src->current_RTP_PT[i].isAstFormat; 01440 dest->current_RTP_PT[i].code = 01441 src->current_RTP_PT[i].code; 01442 } 01443 dest->rtp_lookup_code_cache_isAstFormat = 0; 01444 dest->rtp_lookup_code_cache_code = 0; 01445 dest->rtp_lookup_code_cache_result = 0; 01446 01447 ast_mutex_unlock(&src->bridge_lock); 01448 ast_mutex_unlock(&dest->bridge_lock); 01449 }
void ast_rtp_pt_default | ( | struct ast_rtp * | rtp | ) |
Set payload types to defaults.
Definition at line 1411 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.
01412 { 01413 int i; 01414 01415 ast_mutex_lock(&rtp->bridge_lock); 01416 01417 /* Initialize to default payload types */ 01418 for (i = 0; i < MAX_RTP_PT; ++i) { 01419 rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat; 01420 rtp->current_RTP_PT[i].code = static_RTP_PT[i].code; 01421 } 01422 01423 rtp->rtp_lookup_code_cache_isAstFormat = 0; 01424 rtp->rtp_lookup_code_cache_code = 0; 01425 rtp->rtp_lookup_code_cache_result = 0; 01426 01427 ast_mutex_unlock(&rtp->bridge_lock); 01428 }
Definition at line 1097 of file rtp.c.
References ast_codec_get_samples(), AST_FORMAT_MAX_AUDIO, AST_FORMAT_SLINEAR, ast_frame_byteswap_be, AST_FRAME_VIDEO, AST_FRAME_VOICE, 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, CRASH, ast_rtp::cycles, ast_frame::data, ast_frame::datalen, ast_frame::delivery, event, ext, ast_rtp::f, f, FLAG_NAT_ACTIVE, ast_frame::frametype, ast_frame::has_timing_info, 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.
01098 { 01099 int res; 01100 struct sockaddr_in sin; 01101 socklen_t len; 01102 unsigned int seqno; 01103 int version; 01104 int payloadtype; 01105 int hdrlen = 12; 01106 int padding; 01107 int mark; 01108 int ext; 01109 int cc; 01110 unsigned int ssrc; 01111 unsigned int timestamp; 01112 unsigned int *rtpheader; 01113 struct rtpPayloadType rtpPT; 01114 struct ast_rtp *bridged = NULL; 01115 01116 /* If time is up, kill it */ 01117 if (rtp->sending_digit) 01118 ast_rtp_senddigit_continuation(rtp); 01119 01120 len = sizeof(sin); 01121 01122 /* Cache where the header will go */ 01123 res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET, 01124 0, (struct sockaddr *)&sin, &len); 01125 01126 rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET); 01127 if (res < 0) { 01128 if (errno == EBADF) 01129 CRASH; 01130 if (errno != EAGAIN) { 01131 ast_log(LOG_WARNING, "RTP Read error: %s. Hanging up.\n", strerror(errno)); 01132 return NULL; 01133 } 01134 return &ast_null_frame; 01135 } 01136 01137 if (res < hdrlen) { 01138 ast_log(LOG_WARNING, "RTP Read too short\n"); 01139 return &ast_null_frame; 01140 } 01141 01142 /* Get fields */ 01143 seqno = ntohl(rtpheader[0]); 01144 01145 /* Check RTP version */ 01146 version = (seqno & 0xC0000000) >> 30; 01147 if (!version) { 01148 if ((stun_handle_packet(rtp->s, &sin, rtp->rawdata + AST_FRIENDLY_OFFSET, res) == STUN_ACCEPT) && 01149 (!rtp->them.sin_port && !rtp->them.sin_addr.s_addr)) { 01150 memcpy(&rtp->them, &sin, sizeof(rtp->them)); 01151 } 01152 return &ast_null_frame; 01153 } 01154 01155 #if 0 /* Allow to receive RTP stream with closed transmission path */ 01156 /* If we don't have the other side's address, then ignore this */ 01157 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 01158 return &ast_null_frame; 01159 #endif 01160 01161 /* Send to whoever send to us if NAT is turned on */ 01162 if (rtp->nat) { 01163 if ((rtp->them.sin_addr.s_addr != sin.sin_addr.s_addr) || 01164 (rtp->them.sin_port != sin.sin_port)) { 01165 rtp->them = sin; 01166 if (rtp->rtcp) { 01167 memcpy(&rtp->rtcp->them, &sin, sizeof(rtp->rtcp->them)); 01168 rtp->rtcp->them.sin_port = htons(ntohs(rtp->them.sin_port)+1); 01169 } 01170 rtp->rxseqno = 0; 01171 ast_set_flag(rtp, FLAG_NAT_ACTIVE); 01172 if (option_debug || rtpdebug) 01173 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)); 01174 } 01175 } 01176 01177 /* If we are bridged to another RTP stream, send direct */ 01178 if ((bridged = ast_rtp_get_bridged(rtp)) && !bridge_p2p_rtp_write(rtp, bridged, rtpheader, res, hdrlen)) 01179 return &ast_null_frame; 01180 01181 if (version != 2) 01182 return &ast_null_frame; 01183 01184 payloadtype = (seqno & 0x7f0000) >> 16; 01185 padding = seqno & (1 << 29); 01186 mark = seqno & (1 << 23); 01187 ext = seqno & (1 << 28); 01188 cc = (seqno & 0xF000000) >> 24; 01189 seqno &= 0xffff; 01190 timestamp = ntohl(rtpheader[1]); 01191 ssrc = ntohl(rtpheader[2]); 01192 01193 if (!mark && rtp->rxssrc && rtp->rxssrc != ssrc) { 01194 if (option_debug || rtpdebug) 01195 ast_log(LOG_DEBUG, "Forcing Marker bit, because SSRC has changed\n"); 01196 mark = 1; 01197 } 01198 01199 rtp->rxssrc = ssrc; 01200 01201 if (padding) { 01202 /* Remove padding bytes */ 01203 res -= rtp->rawdata[AST_FRIENDLY_OFFSET + res - 1]; 01204 } 01205 01206 if (cc) { 01207 /* CSRC fields present */ 01208 hdrlen += cc*4; 01209 } 01210 01211 if (ext) { 01212 /* RTP Extension present */ 01213 hdrlen += (ntohl(rtpheader[hdrlen/4]) & 0xffff) << 2; 01214 hdrlen += 4; 01215 } 01216 01217 if (res < hdrlen) { 01218 ast_log(LOG_WARNING, "RTP Read too short (%d, expecting %d)\n", res, hdrlen); 01219 return &ast_null_frame; 01220 } 01221 01222 rtp->rxcount++; /* Only count reasonably valid packets, this'll make the rtcp stats more accurate */ 01223 01224 if (rtp->rxcount==1) { 01225 /* This is the first RTP packet successfully received from source */ 01226 rtp->seedrxseqno = seqno; 01227 } 01228 01229 /* Do not schedule RR if RTCP isn't run */ 01230 if (rtp->rtcp && rtp->rtcp->them.sin_addr.s_addr && rtp->rtcp->schedid < 1) { 01231 /* Schedule transmission of Receiver Report */ 01232 rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, rtp); 01233 } 01234 if ( (int)rtp->lastrxseqno - (int)seqno > 100) /* if so it would indicate that the sender cycled; allow for misordering */ 01235 rtp->cycles += RTP_SEQ_MOD; 01236 01237 rtp->lastrxseqno = seqno; 01238 01239 if (rtp->themssrc==0) 01240 rtp->themssrc = ntohl(rtpheader[2]); /* Record their SSRC to put in future RR */ 01241 01242 if (rtp_debug_test_addr(&sin)) 01243 ast_verbose("Got RTP packet from %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 01244 ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen); 01245 01246 rtpPT = ast_rtp_lookup_pt(rtp, payloadtype); 01247 if (!rtpPT.isAstFormat) { 01248 struct ast_frame *f = NULL; 01249 01250 /* This is special in-band data that's not one of our codecs */ 01251 if (rtpPT.code == AST_RTP_DTMF) { 01252 /* It's special -- rfc2833 process it */ 01253 if (rtp_debug_test_addr(&sin)) { 01254 unsigned char *data; 01255 unsigned int event; 01256 unsigned int event_end; 01257 unsigned int duration; 01258 data = rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen; 01259 event = ntohl(*((unsigned int *)(data))); 01260 event >>= 24; 01261 event_end = ntohl(*((unsigned int *)(data))); 01262 event_end <<= 8; 01263 event_end >>= 24; 01264 duration = ntohl(*((unsigned int *)(data))); 01265 duration &= 0xFFFF; 01266 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); 01267 } 01268 f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp); 01269 } else if (rtpPT.code == AST_RTP_CISCO_DTMF) { 01270 /* It's really special -- process it the Cisco way */ 01271 if (rtp->lastevent <= seqno || (rtp->lastevent >= 65530 && seqno <= 6)) { 01272 f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01273 rtp->lastevent = seqno; 01274 } 01275 } else if (rtpPT.code == AST_RTP_CN) { 01276 /* Comfort Noise */ 01277 f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01278 } else { 01279 ast_log(LOG_NOTICE, "Unknown RTP codec %d received from '%s'\n", payloadtype, ast_inet_ntoa(rtp->them.sin_addr)); 01280 } 01281 return f ? f : &ast_null_frame; 01282 } 01283 rtp->lastrxformat = rtp->f.subclass = rtpPT.code; 01284 rtp->f.frametype = (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) ? AST_FRAME_VOICE : AST_FRAME_VIDEO; 01285 01286 if (!rtp->lastrxts) 01287 rtp->lastrxts = timestamp; 01288 01289 rtp->rxseqno = seqno; 01290 01291 /* Record received timestamp as last received now */ 01292 rtp->lastrxts = timestamp; 01293 01294 rtp->f.mallocd = 0; 01295 rtp->f.datalen = res - hdrlen; 01296 rtp->f.data = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET; 01297 rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET; 01298 rtp->f.seqno = seqno; 01299 if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) { 01300 rtp->f.samples = ast_codec_get_samples(&rtp->f); 01301 if (rtp->f.subclass == AST_FORMAT_SLINEAR) 01302 ast_frame_byteswap_be(&rtp->f); 01303 calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark); 01304 /* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */ 01305 rtp->f.has_timing_info = 1; 01306 rtp->f.ts = timestamp / 8; 01307 rtp->f.len = rtp->f.samples / 8; 01308 } else { 01309 /* Video -- samples is # of samples vs. 90000 */ 01310 if (!rtp->lastividtimestamp) 01311 rtp->lastividtimestamp = timestamp; 01312 rtp->f.samples = timestamp - rtp->lastividtimestamp; 01313 rtp->lastividtimestamp = timestamp; 01314 rtp->f.delivery.tv_sec = 0; 01315 rtp->f.delivery.tv_usec = 0; 01316 if (mark) 01317 rtp->f.subclass |= 0x1; 01318 01319 } 01320 rtp->f.src = "RTP"; 01321 return &rtp->f; 01322 }
int ast_rtp_reload | ( | void | ) |
Definition at line 3671 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.
03672 { 03673 struct ast_config *cfg; 03674 const char *s; 03675 03676 rtpstart = 5000; 03677 rtpend = 31000; 03678 dtmftimeout = DEFAULT_DTMF_TIMEOUT; 03679 cfg = ast_config_load("rtp.conf"); 03680 if (cfg) { 03681 if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) { 03682 rtpstart = atoi(s); 03683 if (rtpstart < 1024) 03684 rtpstart = 1024; 03685 if (rtpstart > 65535) 03686 rtpstart = 65535; 03687 } 03688 if ((s = ast_variable_retrieve(cfg, "general", "rtpend"))) { 03689 rtpend = atoi(s); 03690 if (rtpend < 1024) 03691 rtpend = 1024; 03692 if (rtpend > 65535) 03693 rtpend = 65535; 03694 } 03695 if ((s = ast_variable_retrieve(cfg, "general", "rtcpinterval"))) { 03696 rtcpinterval = atoi(s); 03697 if (rtcpinterval == 0) 03698 rtcpinterval = 0; /* Just so we're clear... it's zero */ 03699 if (rtcpinterval < RTCP_MIN_INTERVALMS) 03700 rtcpinterval = RTCP_MIN_INTERVALMS; /* This catches negative numbers too */ 03701 if (rtcpinterval > RTCP_MAX_INTERVALMS) 03702 rtcpinterval = RTCP_MAX_INTERVALMS; 03703 } 03704 if ((s = ast_variable_retrieve(cfg, "general", "rtpchecksums"))) { 03705 #ifdef SO_NO_CHECK 03706 if (ast_false(s)) 03707 nochecksums = 1; 03708 else 03709 nochecksums = 0; 03710 #else 03711 if (ast_false(s)) 03712 ast_log(LOG_WARNING, "Disabling RTP checksums is not supported on this operating system!\n"); 03713 #endif 03714 } 03715 if ((s = ast_variable_retrieve(cfg, "general", "dtmftimeout"))) { 03716 dtmftimeout = atoi(s); 03717 if ((dtmftimeout < 0) || (dtmftimeout > 20000)) { 03718 ast_log(LOG_WARNING, "DTMF timeout of '%d' outside range, using default of '%d' instead\n", 03719 dtmftimeout, DEFAULT_DTMF_TIMEOUT); 03720 dtmftimeout = DEFAULT_DTMF_TIMEOUT; 03721 }; 03722 } 03723 ast_config_destroy(cfg); 03724 } 03725 if (rtpstart >= rtpend) { 03726 ast_log(LOG_WARNING, "Unreasonable values for RTP start/end port in rtp.conf\n"); 03727 rtpstart = 5000; 03728 rtpend = 31000; 03729 } 03730 if (option_verbose > 1) 03731 ast_verbose(VERBOSE_PREFIX_2 "RTP Allocating from port range %d -> %d\n", rtpstart, rtpend); 03732 return 0; 03733 }
void ast_rtp_reset | ( | struct ast_rtp * | rtp | ) |
Definition at line 2030 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.
02031 { 02032 memset(&rtp->rxcore, 0, sizeof(rtp->rxcore)); 02033 memset(&rtp->txcore, 0, sizeof(rtp->txcore)); 02034 memset(&rtp->dtmfmute, 0, sizeof(rtp->dtmfmute)); 02035 rtp->lastts = 0; 02036 rtp->lastdigitts = 0; 02037 rtp->lastrxts = 0; 02038 rtp->lastividtimestamp = 0; 02039 rtp->lastovidtimestamp = 0; 02040 rtp->lasteventseqn = 0; 02041 rtp->lastevent = 0; 02042 rtp->lasttxformat = 0; 02043 rtp->lastrxformat = 0; 02044 rtp->dtmfcount = 0; 02045 rtp->dtmfsamples = 0; 02046 rtp->seqno = 0; 02047 rtp->rxseqno = 0; 02048 }
int ast_rtp_sendcng | ( | struct ast_rtp * | rtp, | |
int | level | |||
) |
generate comfort noice (CNG)
Definition at line 2540 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, ast_rtp::lastts, LOG_ERROR, rtp_debug_test_addr(), ast_rtp::s, ast_rtp::seqno, ast_rtp::ssrc, and ast_rtp::them.
02541 { 02542 unsigned int *rtpheader; 02543 int hdrlen = 12; 02544 int res; 02545 int payload; 02546 char data[256]; 02547 level = 127 - (level & 0x7f); 02548 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_CN); 02549 02550 /* If we have no peer, return immediately */ 02551 if (!rtp->them.sin_addr.s_addr) 02552 return 0; 02553 02554 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 02555 02556 /* Get a pointer to the header */ 02557 rtpheader = (unsigned int *)data; 02558 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno++)); 02559 rtpheader[1] = htonl(rtp->lastts); 02560 rtpheader[2] = htonl(rtp->ssrc); 02561 data[12] = level; 02562 if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) { 02563 res = sendto(rtp->s, (void *)rtpheader, hdrlen + 1, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them)); 02564 if (res <0) 02565 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)); 02566 if (rtp_debug_test_addr(&rtp->them)) 02567 ast_verbose("Sent Comfort Noise RTP packet to %s:%u (type %d, seq %u, ts %u, len %d)\n" 02568 , ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen); 02569 02570 } 02571 return 0; 02572 }
int ast_rtp_senddigit_begin | ( | struct ast_rtp * | rtp, | |
char | digit | |||
) |
Send begin frames for DTMF.
Definition at line 2140 of file rtp.c.
References ast_inet_ntoa(), ast_log(), AST_RTP_DTMF, ast_rtp_lookup_code(), ast_tvadd(), ast_verbose(), ast_rtp::dtmfmute, 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.
02141 { 02142 unsigned int *rtpheader; 02143 int hdrlen = 12, res = 0, i = 0, payload = 0; 02144 char data[256]; 02145 02146 if ((digit <= '9') && (digit >= '0')) 02147 digit -= '0'; 02148 else if (digit == '*') 02149 digit = 10; 02150 else if (digit == '#') 02151 digit = 11; 02152 else if ((digit >= 'A') && (digit <= 'D')) 02153 digit = digit - 'A' + 12; 02154 else if ((digit >= 'a') && (digit <= 'd')) 02155 digit = digit - 'a' + 12; 02156 else { 02157 ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit); 02158 return 0; 02159 } 02160 02161 /* If we have no peer, return immediately */ 02162 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 02163 return 0; 02164 02165 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF); 02166 02167 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 02168 rtp->send_duration = 160; 02169 02170 /* Get a pointer to the header */ 02171 rtpheader = (unsigned int *)data; 02172 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno)); 02173 rtpheader[1] = htonl(rtp->lastdigitts); 02174 rtpheader[2] = htonl(rtp->ssrc); 02175 02176 for (i = 0; i < 2; i++) { 02177 rtpheader[3] = htonl((digit << 24) | (0xa << 16) | (rtp->send_duration)); 02178 res = sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockaddr *) &rtp->them, sizeof(rtp->them)); 02179 if (res < 0) 02180 ast_log(LOG_ERROR, "RTP Transmission error to %s:%u: %s\n", 02181 ast_inet_ntoa(rtp->them.sin_addr), 02182 ntohs(rtp->them.sin_port), strerror(errno)); 02183 if (rtp_debug_test_addr(&rtp->them)) 02184 ast_verbose("Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 02185 ast_inet_ntoa(rtp->them.sin_addr), 02186 ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen); 02187 /* Increment sequence number */ 02188 rtp->seqno++; 02189 /* Increment duration */ 02190 rtp->send_duration += 160; 02191 /* Clear marker bit and set seqno */ 02192 rtpheader[0] = htonl((2 << 30) | (payload << 16) | (rtp->seqno)); 02193 } 02194 02195 /* Since we received a begin, we can safely store the digit and disable any compensation */ 02196 rtp->sending_digit = 1; 02197 rtp->send_digit = digit; 02198 rtp->send_payload = payload; 02199 02200 return 0; 02201 }
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 585 of file rtp.c.
References ast_rtp::callback.
00586 { 00587 rtp->callback = callback; 00588 }
void ast_rtp_set_data | ( | struct ast_rtp * | rtp, | |
void * | data | |||
) |
Definition at line 580 of file rtp.c.
References ast_rtp::data.
00581 { 00582 rtp->data = data; 00583 }
void ast_rtp_set_m_type | ( | struct ast_rtp * | rtp, | |
int | pt | |||
) |
Make a note of a RTP payload type that was seen in a SDP "m=" line. By default, use the well-known value for this type (although it may still be set to a different value by a subsequent "a=rtpmap:" line).
Definition at line 1629 of file rtp.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_rtp::bridge_lock, ast_rtp::current_RTP_PT, and MAX_RTP_PT.
01630 { 01631 if (pt < 0 || pt > MAX_RTP_PT || static_RTP_PT[pt].code == 0) 01632 return; /* bogus payload type */ 01633 01634 ast_mutex_lock(&rtp->bridge_lock); 01635 rtp->current_RTP_PT[pt] = static_RTP_PT[pt]; 01636 ast_mutex_unlock(&rtp->bridge_lock); 01637 }
void ast_rtp_set_peer | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | them | |||
) |
Definition at line 1973 of file rtp.c.
References ast_rtp::rtcp, ast_rtp::rxseqno, ast_rtcp::them, and ast_rtp::them.
01974 { 01975 rtp->them.sin_port = them->sin_port; 01976 rtp->them.sin_addr = them->sin_addr; 01977 if (rtp->rtcp) { 01978 rtp->rtcp->them.sin_port = htons(ntohs(them->sin_port) + 1); 01979 rtp->rtcp->them.sin_addr = them->sin_addr; 01980 } 01981 rtp->rxseqno = 0; 01982 }
void ast_rtp_set_rtpholdtimeout | ( | struct ast_rtp * | rtp, | |
int | timeout | |||
) |
Set rtp hold timeout.
Definition at line 547 of file rtp.c.
References ast_rtp::rtpholdtimeout.
00548 { 00549 rtp->rtpholdtimeout = timeout; 00550 }
void ast_rtp_set_rtpkeepalive | ( | struct ast_rtp * | rtp, | |
int | period | |||
) |
set RTP keepalive interval
Definition at line 553 of file rtp.c.
References ast_rtp::rtpkeepalive.
00554 { 00555 rtp->rtpkeepalive = period; 00556 }
void ast_rtp_set_rtpmap_type | ( | struct ast_rtp * | rtp, | |
int | pt, | |||
char * | mimeType, | |||
char * | mimeSubtype, | |||
enum ast_rtp_options | options | |||
) |
Make a note of a RTP payload type (with MIME type) that was seen in an SDP "a=rtpmap:" line.
Definition at line 1642 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.
01645 { 01646 unsigned int i; 01647 01648 if (pt < 0 || pt > MAX_RTP_PT) 01649 return; /* bogus payload type */ 01650 01651 ast_mutex_lock(&rtp->bridge_lock); 01652 01653 for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) { 01654 if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 && 01655 strcasecmp(mimeType, mimeTypes[i].type) == 0) { 01656 rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType; 01657 if ((mimeTypes[i].payloadType.code == AST_FORMAT_G726) && 01658 mimeTypes[i].payloadType.isAstFormat && 01659 (options & AST_RTP_OPT_G726_NONSTANDARD)) 01660 rtp->current_RTP_PT[pt].code = AST_FORMAT_G726_AAL2; 01661 break; 01662 } 01663 } 01664 01665 ast_mutex_unlock(&rtp->bridge_lock); 01666 01667 return; 01668 }
void ast_rtp_set_rtptimeout | ( | struct ast_rtp * | rtp, | |
int | timeout | |||
) |
Set rtp timeout.
Definition at line 541 of file rtp.c.
References ast_rtp::rtptimeout.
00542 { 00543 rtp->rtptimeout = timeout; 00544 }
void ast_rtp_set_rtptimers_onhold | ( | struct ast_rtp * | rtp | ) |
Definition at line 534 of file rtp.c.
References ast_rtp::rtpholdtimeout, and ast_rtp::rtptimeout.
00535 { 00536 rtp->rtptimeout = (-1) * rtp->rtptimeout; 00537 rtp->rtpholdtimeout = (-1) * rtp->rtpholdtimeout; 00538 }
void ast_rtp_setdtmf | ( | struct ast_rtp * | rtp, | |
int | dtmf | |||
) |
Indicate whether this RTP session is carrying DTMF or not.
Definition at line 600 of file rtp.c.
References ast_set2_flag, and FLAG_HAS_DTMF.
00601 { 00602 ast_set2_flag(rtp, dtmf ? 1 : 0, FLAG_HAS_DTMF); 00603 }
void ast_rtp_setdtmfcompensate | ( | struct ast_rtp * | rtp, | |
int | compensate | |||
) |
Compensate for devices that send RFC2833 packets all at once.
Definition at line 605 of file rtp.c.
References ast_set2_flag, and FLAG_DTMF_COMPENSATE.
00606 { 00607 ast_set2_flag(rtp, compensate ? 1 : 0, FLAG_DTMF_COMPENSATE); 00608 }
void ast_rtp_setnat | ( | struct ast_rtp * | rtp, | |
int | nat | |||
) |
void ast_rtp_setstun | ( | struct ast_rtp * | rtp, | |
int | stun_enable | |||
) |
Enable STUN capability.
Definition at line 610 of file rtp.c.
References ast_set2_flag, and FLAG_HAS_STUN.
00611 { 00612 ast_set2_flag(rtp, stun_enable ? 1 : 0, FLAG_HAS_STUN); 00613 }
int ast_rtp_settos | ( | struct ast_rtp * | rtp, | |
int | tos | |||
) |
Definition at line 1964 of file rtp.c.
References ast_log(), LOG_WARNING, and ast_rtp::s.
01965 { 01966 int res; 01967 01968 if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) 01969 ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); 01970 return res; 01971 }
void ast_rtp_stop | ( | struct ast_rtp * | rtp | ) |
Definition at line 2013 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.
02014 { 02015 if (rtp->rtcp && rtp->rtcp->schedid > 0) { 02016 ast_sched_del(rtp->sched, rtp->rtcp->schedid); 02017 rtp->rtcp->schedid = -1; 02018 } 02019 02020 memset(&rtp->them.sin_addr, 0, sizeof(rtp->them.sin_addr)); 02021 memset(&rtp->them.sin_port, 0, sizeof(rtp->them.sin_port)); 02022 if (rtp->rtcp) { 02023 memset(&rtp->rtcp->them.sin_addr, 0, sizeof(rtp->rtcp->them.sin_addr)); 02024 memset(&rtp->rtcp->them.sin_port, 0, sizeof(rtp->rtcp->them.sin_port)); 02025 } 02026 02027 ast_clear_flag(rtp, FLAG_P2P_SENT_MARK); 02028 }
void ast_rtp_stun_request | ( | struct ast_rtp * | rtp, | |
struct sockaddr_in * | suggestion, | |||
const char * | username | |||
) |
Definition at line 402 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.
00403 { 00404 struct stun_header *req; 00405 unsigned char reqdata[1024]; 00406 int reqlen, reqleft; 00407 struct stun_attr *attr; 00408 00409 req = (struct stun_header *)reqdata; 00410 stun_req_id(req); 00411 reqlen = 0; 00412 reqleft = sizeof(reqdata) - sizeof(struct stun_header); 00413 req->msgtype = 0; 00414 req->msglen = 0; 00415 attr = (struct stun_attr *)req->ies; 00416 if (username) 00417 append_attr_string(&attr, STUN_USERNAME, username, &reqlen, &reqleft); 00418 req->msglen = htons(reqlen); 00419 req->msgtype = htons(STUN_BINDREQ); 00420 stun_send(rtp->s, suggestion, req); 00421 }
Definition at line 2692 of file rtp.c.
References ast_codec_pref_getsize(), 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_rtp::smoother, ast_frame::subclass, and ast_rtp::them.
02693 { 02694 struct ast_frame *f; 02695 int codec; 02696 int hdrlen = 12; 02697 int subclass; 02698 02699 02700 /* If we have no peer, return immediately */ 02701 if (!rtp->them.sin_addr.s_addr) 02702 return 0; 02703 02704 /* If there is no data length, return immediately */ 02705 if (!_f->datalen) 02706 return 0; 02707 02708 /* Make sure we have enough space for RTP header */ 02709 if ((_f->frametype != AST_FRAME_VOICE) && (_f->frametype != AST_FRAME_VIDEO)) { 02710 ast_log(LOG_WARNING, "RTP can only send voice and video\n"); 02711 return -1; 02712 } 02713 02714 subclass = _f->subclass; 02715 if (_f->frametype == AST_FRAME_VIDEO) 02716 subclass &= ~0x1; 02717 02718 codec = ast_rtp_lookup_code(rtp, 1, subclass); 02719 if (codec < 0) { 02720 ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(_f->subclass)); 02721 return -1; 02722 } 02723 02724 if (rtp->lasttxformat != subclass) { 02725 /* New format, reset the smoother */ 02726 if (option_debug) 02727 ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass)); 02728 rtp->lasttxformat = subclass; 02729 if (rtp->smoother) 02730 ast_smoother_free(rtp->smoother); 02731 rtp->smoother = NULL; 02732 } 02733 02734 if (!rtp->smoother && subclass != AST_FORMAT_SPEEX) { 02735 struct ast_format_list fmt = ast_codec_pref_getsize(&rtp->pref, subclass); 02736 if (fmt.inc_ms) { /* if codec parameters is set / avoid division by zero */ 02737 if (!(rtp->smoother = ast_smoother_new((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms))) { 02738 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)); 02739 return -1; 02740 } 02741 if (fmt.flags) 02742 ast_smoother_set_flags(rtp->smoother, fmt.flags); 02743 if (option_debug) 02744 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)); 02745 } 02746 } 02747 if (rtp->smoother) { 02748 if (ast_smoother_test_flag(rtp->smoother, AST_SMOOTHER_FLAG_BE)) { 02749 ast_smoother_feed_be(rtp->smoother, _f); 02750 } else { 02751 ast_smoother_feed(rtp->smoother, _f); 02752 } 02753 02754 while((f = ast_smoother_read(rtp->smoother)) && (f->data)) 02755 ast_rtp_raw_write(rtp, f, codec); 02756 } else { 02757 /* Don't buffer outgoing frames; send them one-per-packet: */ 02758 if (_f->offset < hdrlen) { 02759 f = ast_frdup(_f); 02760 } else { 02761 f = _f; 02762 } 02763 if (f->data) 02764 ast_rtp_raw_write(rtp, f, codec); 02765 if (f != _f) 02766 ast_frfree(f); 02767 } 02768 02769 return 0; 02770 }