#include "asterisk/network.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 |
| This is the structure that binds a channel (SIP/Jingle/H.323) to the RTP subsystem. More... | |
| struct | ast_rtp_quality |
| RTCP quality report storage. More... | |
| struct | rtpPayloadType |
| The value of each payload format mapping:. More... | |
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 |
| #define | RED_MAX_GENERATION 5 |
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) } |
| enum | ast_rtp_qos_vars { AST_RTP_TXCOUNT, AST_RTP_RXCOUNT, AST_RTP_TXJITTER, AST_RTP_RXJITTER, AST_RTP_RXPLOSS, AST_RTP_TXPLOSS, AST_RTP_RTT } |
| Variables used in ast_rtcp_get function. More... | |
| enum | ast_rtp_quality_type { RTPQOS_SUMMARY = 0, RTPQOS_JITTER, RTPQOS_LOSS, RTPQOS_RTT } |
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) |
| The RTP bridge. | |
| void | ast_rtp_change_source (struct ast_rtp *rtp) |
| Indicate that we need to set the marker bit and change the ssrc. | |
| int | ast_rtp_codec_getformat (int pt) |
| get format from predefined dynamic payload format | |
| struct ast_codec_pref * | ast_rtp_codec_getpref (struct ast_rtp *rtp) |
| Get codec preference. | |
| void | ast_rtp_codec_setpref (struct ast_rtp *rtp, struct ast_codec_pref *prefs) |
| Set codec preference. | |
| void | ast_rtp_destroy (struct ast_rtp *rtp) |
| int | ast_rtp_early_bridge (struct ast_channel *c0, struct ast_channel *c1) |
| 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) |
| int | ast_rtp_get_qos (struct ast_rtp *rtp, const char *qos, char *buf, unsigned int buflen) |
| Get QOS stats on a RTP channel. | |
| unsigned int | ast_rtp_get_qosvalue (struct ast_rtp *rtp, enum ast_rtp_qos_vars value) |
| Return RTP and RTCP QoS values. | |
| char * | ast_rtp_get_quality (struct ast_rtp *rtp, struct ast_rtp_quality *qual, enum ast_rtp_quality_type qtype) |
| 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:. | |
| unsigned int | ast_rtp_lookup_sample_rate (int isAstFormat, int code) |
| Get the sample rate associated with known RTP payload types. | |
| int | ast_rtp_make_compatible (struct ast_channel *dest, struct ast_channel *src, int media) |
| struct ast_rtp * | ast_rtp_new (struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode) |
| Initializate a RTP session. | |
| void | ast_rtp_new_init (struct ast_rtp *rtp) |
| Initialize a new RTP structure. | |
| void | ast_rtp_new_source (struct ast_rtp *rtp) |
| Indicate that we need to set the marker bit. | |
| 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 an RTP channel client. | |
| void | ast_rtp_proto_unregister (struct ast_rtp_protocol *proto) |
| Unregister an RTP channel client. | |
| 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) |
| Send end packets for DTMF. | |
| void | ast_rtp_set_alt_peer (struct ast_rtp *rtp, struct sockaddr_in *alt) |
| set potential alternate source for RTP media | |
| void | ast_rtp_set_callback (struct ast_rtp *rtp, ast_rtp_callback callback) |
| void | ast_rtp_set_data (struct ast_rtp *rtp, void *data) |
| void | ast_rtp_set_m_type (struct ast_rtp *rtp, int pt) |
| Activate payload type. | |
| void | ast_rtp_set_peer (struct ast_rtp *rtp, struct sockaddr_in *them) |
| void | ast_rtp_set_rtpholdtimeout (struct ast_rtp *rtp, int timeout) |
| Set rtp hold timeout. | |
| void | ast_rtp_set_rtpkeepalive (struct ast_rtp *rtp, int period) |
| set RTP keepalive interval | |
| int | ast_rtp_set_rtpmap_type (struct ast_rtp *rtp, int pt, char *mimeType, char *mimeSubtype, enum ast_rtp_options options) |
| Set payload type to a known MIME media type for a codec. | |
| int | ast_rtp_set_rtpmap_type_rate (struct ast_rtp *rtp, int pt, char *mimeType, char *mimeSubtype, enum ast_rtp_options options, unsigned int sample_rate) |
| Set payload type to a known MIME media type for a codec with a specific sample rate. | |
| 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_set_vars (struct ast_channel *chan, struct ast_rtp *rtp) |
| Set RTPAUDIOQOS(...) variables on a channel when it is being hung up. | |
| 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) |
| int | ast_rtp_setqos (struct ast_rtp *rtp, int tos, int cos, char *desc) |
| void | ast_rtp_setstun (struct ast_rtp *rtp, int stun_enable) |
| Enable STUN capability. | |
| void | ast_rtp_stop (struct ast_rtp *rtp) |
| void | ast_rtp_stun_request (struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username) |
| Send STUN request for an RTP socket Deprecated, this is just a wrapper for ast_rtp_stun_request(). | |
| 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) |
| int | ast_stun_request (int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer) |
| Generic STUN request send a generic stun request to the server specified. | |
| void | red_buffer_t140 (struct ast_rtp *rtp, struct ast_frame *f) |
| Buffer t.140 data. | |
| int | rtp_red_init (struct ast_rtp *rtp, int ti, int *pt, int num_gen) |
| Initalize t.140 redudancy. | |
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_peer_ok(), 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 FLAG_3389_WARNING (1 << 0) |
| #define MAX_RTP_PT 256 |
Maxmum number of payload defintions for a RTP session
Definition at line 52 of file rtp.h.
Referenced by ast_rtp_codec_getformat(), ast_rtp_get_current_formats(), ast_rtp_lookup_code(), ast_rtp_lookup_pt(), ast_rtp_pt_clear(), ast_rtp_pt_copy(), ast_rtp_pt_default(), ast_rtp_set_m_type(), ast_rtp_set_rtpmap_type_rate(), ast_rtp_unset_m_type(), and process_sdp_a_audio().
| #define RED_MAX_GENERATION 5 |
T.140 Redundancy Maxium number of generations
Definition at line 55 of file rtp.h.
Referenced by process_sdp_a_text().
| typedef int(* ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data) |
| enum ast_rtp_get_result |
Definition at line 63 of file rtp.h.
00063 { 00064 /*! Failed to find the RTP structure */ 00065 AST_RTP_GET_FAILED = 0, 00066 /*! RTP structure exists but true native bridge can not occur so try partial */ 00067 AST_RTP_TRY_PARTIAL, 00068 /*! RTP structure exists and native bridge can occur */ 00069 AST_RTP_TRY_NATIVE, 00070 };
| enum ast_rtp_options |
Definition at line 59 of file rtp.h.
00059 { 00060 AST_RTP_OPT_G726_NONSTANDARD = (1 << 0), 00061 };
| enum ast_rtp_qos_vars |
Variables used in ast_rtcp_get function.
| AST_RTP_TXCOUNT | |
| AST_RTP_RXCOUNT | |
| AST_RTP_TXJITTER | |
| AST_RTP_RXJITTER | |
| AST_RTP_RXPLOSS | |
| AST_RTP_TXPLOSS | |
| AST_RTP_RTT |
Definition at line 73 of file rtp.h.
00073 { 00074 AST_RTP_TXCOUNT, 00075 AST_RTP_RXCOUNT, 00076 AST_RTP_TXJITTER, 00077 AST_RTP_RXJITTER, 00078 AST_RTP_RXPLOSS, 00079 AST_RTP_TXPLOSS, 00080 AST_RTP_RTT 00081 };
| enum ast_rtp_quality_type |
Definition at line 109 of file rtp.h.
00109 { 00110 RTPQOS_SUMMARY = 0, 00111 RTPQOS_JITTER, 00112 RTPQOS_LOSS, 00113 RTPQOS_RTT 00114 };
| int ast_rtcp_fd | ( | struct ast_rtp * | rtp | ) |
Definition at line 724 of file rtp.c.
References ast_rtp::rtcp, and ast_rtcp::s.
Referenced by __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), gtalk_new(), jingle_new(), sip_new(), start_rtp(), and unistim_new().
Definition at line 1184 of file rtp.c.
References ast_rtcp::accumulated_transit, ast_rtcp::altthem, ast_assert, AST_CONTROL_VIDUPDATE, ast_debug, AST_FRAME_CONTROL, AST_FRIENDLY_OFFSET, ast_inet_ntoa(), ast_log(), ast_null_frame, ast_verbose, ast_frame::datalen, errno, EVENT_FLAG_REPORTING, ast_rtp::f, f, ast_frame::frametype, len(), LOG_DEBUG, LOG_WARNING, ast_frame::mallocd, manager_event, ast_rtcp::maxrtt, ast_rtcp::minrtt, ast_rtp::nat, normdev_compute(), ast_rtcp::normdevrtt, option_debug, ast_rtcp::reported_jitter, ast_rtcp::reported_jitter_count, ast_rtcp::reported_lost, ast_rtcp::reported_maxjitter, ast_rtcp::reported_maxlost, ast_rtcp::reported_minjitter, ast_rtcp::reported_minlost, ast_rtcp::reported_normdev_jitter, ast_rtcp::reported_normdev_lost, ast_rtcp::reported_stdev_jitter, ast_rtcp::reported_stdev_lost, ast_rtp::rtcp, rtcp_debug_test_addr(), ast_rtcp::rtcp_info, RTCP_PT_BYE, RTCP_PT_FUR, RTCP_PT_RR, RTCP_PT_SDES, RTCP_PT_SR, ast_rtcp::rtt, ast_rtcp::rtt_count, ast_rtcp::rxlsr, ast_rtcp::s, ast_frame::samples, ast_rtcp::soc, ast_rtcp::spc, ast_frame::src, stddev_compute(), ast_rtcp::stdevrtt, ast_frame::subclass, ast_rtcp::them, ast_rtcp::themrxlsr, and timeval2ntp().
Referenced by oh323_read(), sip_rtp_read(), skinny_rtp_read(), and unistim_rtp_read().
01185 { 01186 socklen_t len; 01187 int position, i, packetwords; 01188 int res; 01189 struct sockaddr_in sock_in; 01190 unsigned int rtcpdata[8192 + AST_FRIENDLY_OFFSET]; 01191 unsigned int *rtcpheader; 01192 int pt; 01193 struct timeval now; 01194 unsigned int length; 01195 int rc; 01196 double rttsec; 01197 uint64_t rtt = 0; 01198 unsigned int dlsr; 01199 unsigned int lsr; 01200 unsigned int msw; 01201 unsigned int lsw; 01202 unsigned int comp; 01203 struct ast_frame *f = &ast_null_frame; 01204 01205 double reported_jitter; 01206 double reported_normdev_jitter_current; 01207 double normdevrtt_current; 01208 double reported_lost; 01209 double reported_normdev_lost_current; 01210 01211 if (!rtp || !rtp->rtcp) 01212 return &ast_null_frame; 01213 01214 len = sizeof(sock_in); 01215 01216 res = recvfrom(rtp->rtcp->s, rtcpdata + AST_FRIENDLY_OFFSET, sizeof(rtcpdata) - sizeof(unsigned int) * AST_FRIENDLY_OFFSET, 01217 0, (struct sockaddr *)&sock_in, &len); 01218 rtcpheader = (unsigned int *)(rtcpdata + AST_FRIENDLY_OFFSET); 01219 01220 if (res < 0) { 01221 ast_assert(errno != EBADF); 01222 if (errno != EAGAIN) { 01223 ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n", strerror(errno)); 01224 return NULL; 01225 } 01226 return &ast_null_frame; 01227 } 01228 01229 packetwords = res / 4; 01230 01231 if (rtp->nat) { 01232 /* Send to whoever sent to us */ 01233 if (((rtp->rtcp->them.sin_addr.s_addr != sock_in.sin_addr.s_addr) || 01234 (rtp->rtcp->them.sin_port != sock_in.sin_port)) && 01235 ((rtp->rtcp->altthem.sin_addr.s_addr != sock_in.sin_addr.s_addr) || 01236 (rtp->rtcp->altthem.sin_port != sock_in.sin_port))) { 01237 memcpy(&rtp->rtcp->them, &sock_in, sizeof(rtp->rtcp->them)); 01238 if (option_debug || rtpdebug) 01239 ast_debug(0, "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)); 01240 } 01241 } 01242 01243 ast_debug(1, "Got RTCP report of %d bytes\n", res); 01244 01245 /* Process a compound packet */ 01246 position = 0; 01247 while (position < packetwords) { 01248 i = position; 01249 length = ntohl(rtcpheader[i]); 01250 pt = (length & 0xff0000) >> 16; 01251 rc = (length & 0x1f000000) >> 24; 01252 length &= 0xffff; 01253 01254 if ((i + length) > packetwords) { 01255 if (option_debug || rtpdebug) 01256 ast_log(LOG_DEBUG, "RTCP Read too short\n"); 01257 return &ast_null_frame; 01258 } 01259 01260 if (rtcp_debug_test_addr(&sock_in)) { 01261 ast_verbose("\n\nGot RTCP from %s:%d\n", ast_inet_ntoa(sock_in.sin_addr), ntohs(sock_in.sin_port)); 01262 ast_verbose("PT: %d(%s)\n", pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown"); 01263 ast_verbose("Reception reports: %d\n", rc); 01264 ast_verbose("SSRC of sender: %u\n", rtcpheader[i + 1]); 01265 } 01266 01267 i += 2; /* Advance past header and ssrc */ 01268 01269 switch (pt) { 01270 case RTCP_PT_SR: 01271 gettimeofday(&rtp->rtcp->rxlsr,NULL); /* To be able to populate the dlsr */ 01272 rtp->rtcp->spc = ntohl(rtcpheader[i+3]); 01273 rtp->rtcp->soc = ntohl(rtcpheader[i + 4]); 01274 rtp->rtcp->themrxlsr = ((ntohl(rtcpheader[i]) & 0x0000ffff) << 16) | ((ntohl(rtcpheader[i + 1]) & 0xffff0000) >> 16); /* Going to LSR in RR*/ 01275 01276 if (rtcp_debug_test_addr(&sock_in)) { 01277 ast_verbose("NTP timestamp: %lu.%010lu\n", (unsigned long) ntohl(rtcpheader[i]), (unsigned long) ntohl(rtcpheader[i + 1]) * 4096); 01278 ast_verbose("RTP timestamp: %lu\n", (unsigned long) ntohl(rtcpheader[i + 2])); 01279 ast_verbose("SPC: %lu\tSOC: %lu\n", (unsigned long) ntohl(rtcpheader[i + 3]), (unsigned long) ntohl(rtcpheader[i + 4])); 01280 } 01281 i += 5; 01282 if (rc < 1) 01283 break; 01284 /* Intentional fall through */ 01285 case RTCP_PT_RR: 01286 /* Don't handle multiple reception reports (rc > 1) yet */ 01287 /* Calculate RTT per RFC */ 01288 gettimeofday(&now, NULL); 01289 timeval2ntp(now, &msw, &lsw); 01290 if (ntohl(rtcpheader[i + 4]) && ntohl(rtcpheader[i + 5])) { /* We must have the LSR && DLSR */ 01291 comp = ((msw & 0xffff) << 16) | ((lsw & 0xffff0000) >> 16); 01292 lsr = ntohl(rtcpheader[i + 4]); 01293 dlsr = ntohl(rtcpheader[i + 5]); 01294 rtt = comp - lsr - dlsr; 01295 01296 /* Convert end to end delay to usec (keeping the calculation in 64bit space) 01297 sess->ee_delay = (eedelay * 1000) / 65536; */ 01298 if (rtt < 4294) { 01299 rtt = (rtt * 1000000) >> 16; 01300 } else { 01301 rtt = (rtt * 1000) >> 16; 01302 rtt *= 1000; 01303 } 01304 rtt = rtt / 1000.; 01305 rttsec = rtt / 1000.; 01306 rtp->rtcp->rtt = rttsec; 01307 01308 if (comp - dlsr >= lsr) { 01309 rtp->rtcp->accumulated_transit += rttsec; 01310 01311 if (rtp->rtcp->rtt_count == 0) 01312 rtp->rtcp->minrtt = rttsec; 01313 01314 if (rtp->rtcp->maxrtt<rttsec) 01315 rtp->rtcp->maxrtt = rttsec; 01316 01317 if (rtp->rtcp->minrtt>rttsec) 01318 rtp->rtcp->minrtt = rttsec; 01319 01320 normdevrtt_current = normdev_compute(rtp->rtcp->normdevrtt, rttsec, rtp->rtcp->rtt_count); 01321 01322 rtp->rtcp->stdevrtt = stddev_compute(rtp->rtcp->stdevrtt, rttsec, rtp->rtcp->normdevrtt, normdevrtt_current, rtp->rtcp->rtt_count); 01323 01324 rtp->rtcp->normdevrtt = normdevrtt_current; 01325 01326 rtp->rtcp->rtt_count++; 01327 } else if (rtcp_debug_test_addr(&sock_in)) { 01328 ast_verbose("Internal RTCP NTP clock skew detected: " 01329 "lsr=%u, now=%u, dlsr=%u (%d:%03dms), " 01330 "diff=%d\n", 01331 lsr, comp, dlsr, dlsr / 65536, 01332 (dlsr % 65536) * 1000 / 65536, 01333 dlsr - (comp - lsr)); 01334 } 01335 } 01336 01337 rtp->rtcp->reported_jitter = ntohl(rtcpheader[i + 3]); 01338 reported_jitter = (double) rtp->rtcp->reported_jitter; 01339 01340 if (rtp->rtcp->reported_jitter_count == 0) 01341 rtp->rtcp->reported_minjitter = reported_jitter; 01342 01343 if (reported_jitter < rtp->rtcp->reported_minjitter) 01344 rtp->rtcp->reported_minjitter = reported_jitter; 01345 01346 if (reported_jitter > rtp->rtcp->reported_maxjitter) 01347 rtp->rtcp->reported_maxjitter = reported_jitter; 01348 01349 reported_normdev_jitter_current = normdev_compute(rtp->rtcp->reported_normdev_jitter, reported_jitter, rtp->rtcp->reported_jitter_count); 01350 01351 rtp->rtcp->reported_stdev_jitter = stddev_compute(rtp->rtcp->reported_stdev_jitter, reported_jitter, rtp->rtcp->reported_normdev_jitter, reported_normdev_jitter_current, rtp->rtcp->reported_jitter_count); 01352 01353 rtp->rtcp->reported_normdev_jitter = reported_normdev_jitter_current; 01354 01355 rtp->rtcp->reported_lost = ntohl(rtcpheader[i + 1]) & 0xffffff; 01356 01357 reported_lost = (double) rtp->rtcp->reported_lost; 01358 01359 /* using same counter as for jitter */ 01360 if (rtp->rtcp->reported_jitter_count == 0) 01361 rtp->rtcp->reported_minlost = reported_lost; 01362 01363 if (reported_lost < rtp->rtcp->reported_minlost) 01364 rtp->rtcp->reported_minlost = reported_lost; 01365 01366 if (reported_lost > rtp->rtcp->reported_maxlost) 01367 rtp->rtcp->reported_maxlost = reported_lost; 01368 01369 reported_normdev_lost_current = normdev_compute(rtp->rtcp->reported_normdev_lost, reported_lost, rtp->rtcp->reported_jitter_count); 01370 01371 rtp->rtcp->reported_stdev_lost = stddev_compute(rtp->rtcp->reported_stdev_lost, reported_lost, rtp->rtcp->reported_normdev_lost, reported_normdev_lost_current, rtp->rtcp->reported_jitter_count); 01372 01373 rtp->rtcp->reported_normdev_lost = reported_normdev_lost_current; 01374 01375 rtp->rtcp->reported_jitter_count++; 01376 01377 if (rtcp_debug_test_addr(&sock_in)) { 01378 ast_verbose(" Fraction lost: %ld\n", (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24)); 01379 ast_verbose(" Packets lost so far: %d\n", rtp->rtcp->reported_lost); 01380 ast_verbose(" Highest sequence number: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff)); 01381 ast_verbose(" Sequence number cycles: %ld\n", (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16); 01382 ast_verbose(" Interarrival jitter: %u\n", rtp->rtcp->reported_jitter); 01383 ast_verbose(" Last SR(our NTP): %lu.%010lu\n",(unsigned long) ntohl(rtcpheader[i + 4]) >> 16,((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096); 01384 ast_verbose(" DLSR: %4.4f (sec)\n",ntohl(rtcpheader[i + 5])/65536.0); 01385 if (rtt) 01386 ast_verbose(" RTT: %lu(sec)\n", (unsigned long) rtt); 01387 } 01388 01389 if (rtt) { 01390 manager_event(EVENT_FLAG_REPORTING, "RTCPReceived", "From: %s:%d\r\n" 01391 "PT: %d(%s)\r\n" 01392 "ReceptionReports: %d\r\n" 01393 "SenderSSRC: %u\r\n" 01394 "FractionLost: %ld\r\n" 01395 "PacketsLost: %d\r\n" 01396 "HighestSequence: %ld\r\n" 01397 "SequenceNumberCycles: %ld\r\n" 01398 "IAJitter: %u\r\n" 01399 "LastSR: %lu.%010lu\r\n" 01400 "DLSR: %4.4f(sec)\r\n" 01401 "RTT: %llu(sec)\r\n", 01402 ast_inet_ntoa(sock_in.sin_addr), ntohs(sock_in.sin_port), 01403 pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown", 01404 rc, 01405 rtcpheader[i + 1], 01406 (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24), 01407 rtp->rtcp->reported_lost, 01408 (long) (ntohl(rtcpheader[i + 2]) & 0xffff), 01409 (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16, 01410 rtp->rtcp->reported_jitter, 01411 (unsigned long) ntohl(rtcpheader[i + 4]) >> 16, ((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096, 01412 ntohl(rtcpheader[i + 5])/65536.0, 01413 (unsigned long long)rtt); 01414 } else { 01415 manager_event(EVENT_FLAG_REPORTING, "RTCPReceived", "From: %s:%d\r\n" 01416 "PT: %d(%s)\r\n" 01417 "ReceptionReports: %d\r\n" 01418 "SenderSSRC: %u\r\n" 01419 "FractionLost: %ld\r\n" 01420 "PacketsLost: %d\r\n" 01421 "HighestSequence: %ld\r\n" 01422 "SequenceNumberCycles: %ld\r\n" 01423 "IAJitter: %u\r\n" 01424 "LastSR: %lu.%010lu\r\n" 01425 "DLSR: %4.4f(sec)\r\n", 01426 ast_inet_ntoa(sock_in.sin_addr), ntohs(sock_in.sin_port), 01427 pt, (pt == 200) ? "Sender Report" : (pt == 201) ? "Receiver Report" : (pt == 192) ? "H.261 FUR" : "Unknown", 01428 rc, 01429 rtcpheader[i + 1], 01430 (((long) ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24), 01431 rtp->rtcp->reported_lost, 01432 (long) (ntohl(rtcpheader[i + 2]) & 0xffff), 01433 (long) (ntohl(rtcpheader[i + 2]) & 0xffff) >> 16, 01434 rtp->rtcp->reported_jitter, 01435 (unsigned long) ntohl(rtcpheader[i + 4]) >> 16, 01436 ((unsigned long) ntohl(rtcpheader[i + 4]) << 16) * 4096, 01437 ntohl(rtcpheader[i + 5])/65536.0); 01438 } 01439 break; 01440 case RTCP_PT_FUR: 01441 if (rtcp_debug_test_addr(&sock_in)) 01442 ast_verbose("Received an RTCP Fast Update Request\n"); 01443 rtp->f.frametype = AST_FRAME_CONTROL; 01444 rtp->f.subclass = AST_CONTROL_VIDUPDATE; 01445 rtp->f.datalen = 0; 01446 rtp->f.samples = 0; 01447 rtp->f.mallocd = 0; 01448 rtp->f.src = "RTP"; 01449 f = &rtp->f; 01450 break; 01451 case RTCP_PT_SDES: 01452 if (rtcp_debug_test_addr(&sock_in)) 01453 ast_verbose("Received an SDES from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 01454 break; 01455 case RTCP_PT_BYE: 01456 if (rtcp_debug_test_addr(&sock_in)) 01457 ast_verbose("Received a BYE from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); 01458 break; 01459 default: 01460 ast_debug(1, "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)); 01461 break; 01462 } 01463 position += (length + 1); 01464 } 01465 rtp->rtcp->rtcp_info = 1; 01466 return f; 01467 }
| 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 3348 of file rtp.c.
References ast_rtcp_write(), ast_rtp::rtcp, and ast_rtcp::sendfur.
03349 { 03350 struct ast_rtp *rtp = data; 03351 int res; 03352 03353 rtp->rtcp->sendfur = 1; 03354 res = ast_rtcp_write(data); 03355 03356 return res; 03357 }
| size_t ast_rtp_alloc_size | ( | void | ) |
Get the amount of space required to hold an RTP session.
Definition at line 495 of file rtp.c.
Referenced by process_sdp().
00496 { 00497 return sizeof(struct ast_rtp); 00498 }
| int ast_rtp_bridge | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1, | |||
| int | flags, | |||
| struct ast_frame ** | fo, | |||
| struct ast_channel ** | rc, | |||
| int | timeoutms | |||
| ) |
The RTP bridge.
Definition at line 4447 of file rtp.c.
References AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_codec_pref_getsize(), ast_debug, ast_log(), AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, AST_RTP_TRY_PARTIAL, ast_set_flag, ast_test_flag, ast_verb, 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_trtp_info, ast_rtp_protocol::get_vrtp_info, LOG_WARNING, ast_channel::name, ast_rtp::pref, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel_tech::send_digit_begin, ast_channel::tech, and ast_channel::tech_pvt.
04448 { 04449 struct ast_rtp *p0 = NULL, *p1 = NULL; /* Audio RTP Channels */ 04450 struct ast_rtp *vp0 = NULL, *vp1 = NULL; /* Video RTP channels */ 04451 struct ast_rtp *tp0 = NULL, *tp1 = NULL; /* Text RTP channels */ 04452 struct ast_rtp_protocol *pr0 = NULL, *pr1 = NULL; 04453 enum ast_rtp_get_result audio_p0_res = AST_RTP_GET_FAILED, video_p0_res = AST_RTP_GET_FAILED, text_p0_res = AST_RTP_GET_FAILED; 04454 enum ast_rtp_get_result audio_p1_res = AST_RTP_GET_FAILED, video_p1_res = AST_RTP_GET_FAILED, text_p1_res = AST_RTP_GET_FAILED; 04455 enum ast_bridge_result res = AST_BRIDGE_FAILED; 04456 int codec0 = 0, codec1 = 0; 04457 void *pvt0 = NULL, *pvt1 = NULL; 04458 04459 /* Lock channels */ 04460 ast_channel_lock(c0); 04461 while (ast_channel_trylock(c1)) { 04462 ast_channel_unlock(c0); 04463 usleep(1); 04464 ast_channel_lock(c0); 04465 } 04466 04467 /* Ensure neither channel got hungup during lock avoidance */ 04468 if (ast_check_hangup(c0) || ast_check_hangup(c1)) { 04469 ast_log(LOG_WARNING, "Got hangup while attempting to bridge '%s' and '%s'\n", c0->name, c1->name); 04470 ast_channel_unlock(c0); 04471 ast_channel_unlock(c1); 04472 return AST_BRIDGE_FAILED; 04473 } 04474 04475 /* Find channel driver interfaces */ 04476 if (!(pr0 = get_proto(c0))) { 04477 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c0->name); 04478 ast_channel_unlock(c0); 04479 ast_channel_unlock(c1); 04480 return AST_BRIDGE_FAILED; 04481 } 04482 if (!(pr1 = get_proto(c1))) { 04483 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", c1->name); 04484 ast_channel_unlock(c0); 04485 ast_channel_unlock(c1); 04486 return AST_BRIDGE_FAILED; 04487 } 04488 04489 /* Get channel specific interface structures */ 04490 pvt0 = c0->tech_pvt; 04491 pvt1 = c1->tech_pvt; 04492 04493 /* Get audio and video interface (if native bridge is possible) */ 04494 audio_p0_res = pr0->get_rtp_info(c0, &p0); 04495 video_p0_res = pr0->get_vrtp_info ? pr0->get_vrtp_info(c0, &vp0) : AST_RTP_GET_FAILED; 04496 text_p0_res = pr0->get_trtp_info ? pr0->get_trtp_info(c0, &vp0) : AST_RTP_GET_FAILED; 04497 audio_p1_res = pr1->get_rtp_info(c1, &p1); 04498 video_p1_res = pr1->get_vrtp_info ? pr1->get_vrtp_info(c1, &vp1) : AST_RTP_GET_FAILED; 04499 text_p1_res = pr1->get_trtp_info ? pr1->get_trtp_info(c1, &vp1) : AST_RTP_GET_FAILED; 04500 04501 /* If we are carrying video, and both sides are not reinviting... then fail the native bridge */ 04502 if (video_p0_res != AST_RTP_GET_FAILED && (audio_p0_res != AST_RTP_TRY_NATIVE || video_p0_res != AST_RTP_TRY_NATIVE)) 04503 audio_p0_res = AST_RTP_GET_FAILED; 04504 if (video_p1_res != AST_RTP_GET_FAILED && (audio_p1_res != AST_RTP_TRY_NATIVE || video_p1_res != AST_RTP_TRY_NATIVE)) 04505 audio_p1_res = AST_RTP_GET_FAILED; 04506 04507 /* Check if a bridge is possible (partial/native) */ 04508 if (audio_p0_res == AST_RTP_GET_FAILED || audio_p1_res == AST_RTP_GET_FAILED) { 04509 /* Somebody doesn't want to play... */ 04510 ast_channel_unlock(c0); 04511 ast_channel_unlock(c1); 04512 return AST_BRIDGE_FAILED_NOWARN; 04513 } 04514 04515 /* If we need to feed DTMF frames into the core then only do a partial native bridge */ 04516 if (ast_test_flag(p0, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) { 04517 ast_set_flag(p0, FLAG_P2P_NEED_DTMF); 04518 audio_p0_res = AST_RTP_TRY_PARTIAL; 04519 } 04520 04521 if (ast_test_flag(p1, FLAG_HAS_DTMF) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)) { 04522 ast_set_flag(p1, FLAG_P2P_NEED_DTMF); 04523 audio_p1_res = AST_RTP_TRY_PARTIAL; 04524 } 04525 04526 /* If both sides are not using the same method of DTMF transmission 04527 * (ie: one is RFC2833, other is INFO... then we can not do direct media. 04528 * -------------------------------------------------- 04529 * | DTMF Mode | HAS_DTMF | Accepts Begin Frames | 04530 * |-----------|------------|-----------------------| 04531 * | Inband | False | True | 04532 * | RFC2833 | True | True | 04533 * | SIP INFO | False | False | 04534 * -------------------------------------------------- 04535 * However, if DTMF from both channels is being monitored by the core, then 04536 * we can still do packet-to-packet bridging, because passing through the 04537 * core will handle DTMF mode translation. 04538 */ 04539 if ((ast_test_flag(p0, FLAG_HAS_DTMF) != ast_test_flag(p1, FLAG_HAS_DTMF)) || 04540 (!c0->tech->send_digit_begin != !c1->tech->send_digit_begin)) { 04541 if (!ast_test_flag(p0, FLAG_P2P_NEED_DTMF) || !ast_test_flag(p1, FLAG_P2P_NEED_DTMF)) { 04542 ast_channel_unlock(c0); 04543 ast_channel_unlock(c1); 04544 return AST_BRIDGE_FAILED_NOWARN; 04545 } 04546 audio_p0_res = AST_RTP_TRY_PARTIAL; 04547 audio_p1_res = AST_RTP_TRY_PARTIAL; 04548 } 04549 04550 /* If we need to feed frames into the core don't do a P2P bridge */ 04551 if ((audio_p0_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p0, FLAG_P2P_NEED_DTMF)) || 04552 (audio_p1_res == AST_RTP_TRY_PARTIAL && ast_test_flag(p1, FLAG_P2P_NEED_DTMF))) { 04553 ast_channel_unlock(c0); 04554 ast_channel_unlock(c1); 04555 return AST_BRIDGE_FAILED_NOWARN; 04556 } 04557 04558 /* Get codecs from both sides */ 04559 codec0 = pr0->get_codec ? pr0->get_codec(c0) : 0; 04560 codec1 = pr1->get_codec ? pr1->get_codec(c1) : 0; 04561 if (codec0 && codec1 && !(codec0 & codec1)) { 04562 /* Hey, we can't do native bridging if both parties speak different codecs */ 04563 ast_debug(3, "Channel codec0 = %d is not codec1 = %d, cannot native bridge in RTP.\n", codec0, codec1); 04564 ast_channel_unlock(c0); 04565 ast_channel_unlock(c1); 04566 return AST_BRIDGE_FAILED_NOWARN; 04567 } 04568 04569 /* If either side can only do a partial bridge, then don't try for a true native bridge */ 04570 if (audio_p0_res == AST_RTP_TRY_PARTIAL || audio_p1_res == AST_RTP_TRY_PARTIAL) { 04571 struct ast_format_list fmt0, fmt1; 04572 04573 /* In order to do Packet2Packet bridging both sides must be in the same rawread/rawwrite */ 04574 if (c0->rawreadformat != c1->rawwriteformat || c1->rawreadformat != c0->rawwriteformat) { 04575 ast_debug(1, "Cannot packet2packet bridge - raw formats are incompatible\n"); 04576 ast_channel_unlock(c0); 04577 ast_channel_unlock(c1); 04578 return AST_BRIDGE_FAILED_NOWARN; 04579 } 04580 /* They must also be using the same packetization */ 04581 fmt0 = ast_codec_pref_getsize(&p0->pref, c0->rawreadformat); 04582 fmt1 = ast_codec_pref_getsize(&p1->pref, c1->rawreadformat); 04583 if (fmt0.cur_ms != fmt1.cur_ms) { 04584 ast_debug(1, "Cannot packet2packet bridge - packetization settings prevent it\n"); 04585 ast_channel_unlock(c0); 04586 ast_channel_unlock(c1); 04587 return AST_BRIDGE_FAILED_NOWARN; 04588 } 04589 04590 ast_verb(3, "Packet2Packet bridging %s and %s\n", c0->name, c1->name); 04591 res = bridge_p2p_loop(c0, c1, p0, p1, timeoutms, flags, fo, rc, pvt0, pvt1); 04592 } else { 04593 ast_verb(3, "Native bridging %s and %s\n", c0->name, c1->name); 04594 res = bridge_native_loop(c0, c1, p0, p1, vp0, vp1, tp0, tp1, pr0, pr1, codec0, codec1, timeoutms, flags, fo, rc, pvt0, pvt1); 04595 } 04596 04597 return res; 04598 }
| void ast_rtp_change_source | ( | struct ast_rtp * | rtp | ) |
Indicate that we need to set the marker bit and change the ssrc.
Definition at line 2694 of file rtp.c.
References ast_debug, ast_random(), ast_rtp::set_marker_bit, and ast_rtp::ssrc.
Referenced by mgcp_indicate(), oh323_indicate(), sip_indicate(), and skinny_indicate().
02695 { 02696 if (rtp) { 02697 unsigned int ssrc = ast_random(); 02698 02699 rtp->set_marker_bit = 1; 02700 ast_debug(3, "Changing ssrc from %u to %u due to a source change\n", rtp->ssrc, ssrc); 02701 rtp->ssrc = ssrc; 02702 } 02703 }
| int ast_rtp_codec_getformat | ( | int | pt | ) |
get format from predefined dynamic payload format
Definition at line 3828 of file rtp.c.
References rtpPayloadType::code, and MAX_RTP_PT.
Referenced by process_sdp_a_audio().
03829 { 03830 if (pt < 0 || pt >= MAX_RTP_PT) 03831 return 0; /* bogus payload type */ 03832 03833 if (static_RTP_PT[pt].isAstFormat) 03834 return static_RTP_PT[pt].code; 03835 else 03836 return 0; 03837 }
| struct ast_codec_pref* ast_rtp_codec_getpref | ( | struct ast_rtp * | rtp | ) | [read] |
Get codec preference.
Definition at line 3823 of file rtp.c.
References ast_rtp::pref.
Referenced by add_codec_to_sdp(), and process_sdp_a_audio().
03824 { 03825 return &rtp->pref; 03826 }
| void ast_rtp_codec_setpref | ( | struct ast_rtp * | rtp, | |
| struct ast_codec_pref * | prefs | |||
| ) |
Set codec preference.
Definition at line 3777 of file rtp.c.
References ast_codec_pref_getsize(), ast_log(), ast_smoother_new(), ast_smoother_reconfigure(), ast_smoother_set_flags(), ast_format_list::cur_ms, ast_format_list::flags, ast_format_list::fr_len, ast_format_list::inc_ms, ast_rtp::lasttxformat, LOG_DEBUG, LOG_WARNING, option_debug, ast_rtp::pref, and ast_rtp::smoother.
Referenced by __oh323_rtp_create(), check_peer_ok(), create_addr_from_peer(), gtalk_new(), jingle_new(), process_sdp_a_audio(), register_verify(), set_peer_capabilities(), sip_alloc(), start_rtp(), and transmit_response_with_sdp().
03778 { 03779 struct ast_format_list current_format_old, current_format_new; 03780 03781 /* if no packets have been sent through this session yet, then 03782 * changing preferences does not require any extra work 03783 */ 03784 if (rtp->lasttxformat == 0) { 03785 rtp->pref = *prefs; 03786 return; 03787 } 03788 03789 current_format_old = ast_codec_pref_getsize(&rtp->pref, rtp->lasttxformat); 03790 03791 rtp->pref = *prefs; 03792 03793 current_format_new = ast_codec_pref_getsize(&rtp->pref, rtp->lasttxformat); 03794 03795 /* if the framing desired for the current format has changed, we may have to create 03796 * or adjust the smoother for this session 03797 */ 03798 if ((current_format_new.inc_ms != 0) && 03799 (current_format_new.cur_ms != current_format_old.cur_ms)) { 03800 int new_size = (current_format_new.cur_ms * current_format_new.fr_len) / current_format_new.inc_ms; 03801 03802 if (rtp->smoother) { 03803 ast_smoother_reconfigure(rtp->smoother, new_size); 03804 if (option_debug) { 03805 ast_log(LOG_DEBUG, "Adjusted smoother to %d ms and %d bytes\n", current_format_new.cur_ms, new_size); 03806 } 03807 } else { 03808 if (!(rtp->smoother = ast_smoother_new(new_size))) { 03809 ast_log(LOG_WARNING, "Unable to create smoother: format: %d ms: %d len: %d\n", rtp->lasttxformat, current_format_new.cur_ms, new_size); 03810 return; 03811 } 03812 if (current_format_new.flags) { 03813 ast_smoother_set_flags(rtp->smoother, current_format_new.flags); 03814 } 03815 if (option_debug) { 03816 ast_log(LOG_DEBUG, "Created smoother: format: %d ms: %d len: %d\n", rtp->lasttxformat, current_format_new.cur_ms, new_size); 03817 } 03818 } 03819 } 03820 03821 }
| void ast_rtp_destroy | ( | struct ast_rtp * | rtp | ) |
Destroy RTP session
Definition at line 3107 of file rtp.c.
References ast_free, ast_io_remove(), ast_mutex_destroy(), AST_SCHED_DEL, ast_smoother_free(), ast_verbose, EVENT_FLAG_REPORTING, ast_rtcp::expected_prior, ast_rtp::io, ast_rtp::ioid, manager_event, 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_peer_ok(), cleanup_connection(), create_addr_from_peer(), destroy_endpoint(), gtalk_free_pvt(), jingle_free_pvt(), mgcp_hangup(), oh323_alloc(), skinny_hangup(), start_rtp(), unalloc_sub(), and unistim_hangup().
03108 { 03109 if (rtcp_debug_test_addr(&rtp->them) || rtcpstats) { 03110 /*Print some info on the call here */ 03111 ast_verbose(" RTP-stats\n"); 03112 ast_verbose("* Our Receiver:\n"); 03113 ast_verbose(" SSRC: %u\n", rtp->themssrc); 03114 ast_verbose(" Received packets: %u\n", rtp->rxcount); 03115 ast_verbose(" Lost packets: %u\n", rtp->rtcp ? (rtp->rtcp->expected_prior - rtp->rtcp->received_prior) : 0); 03116 ast_verbose(" Jitter: %.4f\n", rtp->rxjitter); 03117 ast_verbose(" Transit: %.4f\n", rtp->rxtransit); 03118 ast_verbose(" RR-count: %u\n", rtp->rtcp ? rtp->rtcp->rr_count : 0); 03119 ast_verbose("* Our Sender:\n"); 03120 ast_verbose(" SSRC: %u\n", rtp->ssrc); 03121 ast_verbose(" Sent packets: %u\n", rtp->txcount); 03122 ast_verbose(" Lost packets: %u\n", rtp->rtcp ? rtp->rtcp->reported_lost : 0); 03123 ast_verbose(" Jitter: %u\n", rtp->rtcp ? (rtp->rtcp->reported_jitter / (unsigned int)65536.0) : 0); 03124 ast_verbose(" SR-count: %u\n", rtp->rtcp ? rtp->rtcp->sr_count : 0); 03125 ast_verbose(" RTT: %f\n", rtp->rtcp ? rtp->rtcp->rtt : 0); 03126 } 03127 03128 manager_event(EVENT_FLAG_REPORTING, "RTPReceiverStat", "SSRC: %u\r\n" 03129 "ReceivedPackets: %u\r\n" 03130 "LostPackets: %u\r\n" 03131 "Jitter: %.4f\r\n" 03132 "Transit: %.4f\r\n" 03133 "RRCount: %u\r\n", 03134 rtp->themssrc, 03135 rtp->rxcount, 03136 rtp->rtcp ? (rtp->rtcp->expected_prior - rtp->rtcp->received_prior) : 0, 03137 rtp->rxjitter, 03138 rtp->rxtransit, 03139 rtp->rtcp ? rtp->rtcp->rr_count : 0); 03140 manager_event(EVENT_FLAG_REPORTING, "RTPSenderStat", "SSRC: %u\r\n" 03141 "SentPackets: %u\r\n" 03142 "LostPackets: %u\r\n" 03143 "Jitter: %u\r\n" 03144 "SRCount: %u\r\n" 03145 "RTT: %f\r\n", 03146 rtp->ssrc, 03147 rtp->txcount, 03148 rtp->rtcp ? rtp->rtcp->reported_lost : 0, 03149 rtp->rtcp ? rtp->rtcp->reported_jitter : 0, 03150 rtp->rtcp ? rtp->rtcp->sr_count : 0, 03151 rtp->rtcp ? rtp->rtcp->rtt : 0); 03152 if (rtp->smoother) 03153 ast_smoother_free(rtp->smoother); 03154 if (rtp->ioid) 03155 ast_io_remove(rtp->io, rtp->ioid); 03156 if (rtp->s > -1) 03157 close(rtp->s); 03158 if (rtp->rtcp) { 03159 AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid); 03160 close(rtp->rtcp->s); 03161 ast_free(rtp->rtcp); 03162 rtp->rtcp=NULL; 03163 } 03164 #ifdef P2P_INTENSE 03165 ast_mutex_destroy(&rtp->bridge_lock); 03166 #endif 03167 ast_free(rtp); 03168 }
| int ast_rtp_early_bridge | ( | struct ast_channel * | c0, | |
| struct ast_channel * | c1 | |||
| ) |
If possible, create an early bridge directly between the devices without having to send a re-invite later.
Definition at line 2116 of file rtp.c.
References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, 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_trtp_info, ast_rtp_protocol::get_vrtp_info, LOG_WARNING, ast_channel::name, and ast_rtp_protocol::set_rtp_peer.
02117 { 02118 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 02119 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 02120 struct ast_rtp *tdestp = NULL, *tsrcp = NULL; /* Text RTP channels */ 02121 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 02122 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED, text_dest_res = AST_RTP_GET_FAILED; 02123 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED, text_src_res = AST_RTP_GET_FAILED; 02124 int srccodec, destcodec, nat_active = 0; 02125 02126 /* Lock channels */ 02127 ast_channel_lock(c0); 02128 if (c1) { 02129 while (ast_channel_trylock(c1)) { 02130 ast_channel_unlock(c0); 02131 usleep(1); 02132 ast_channel_lock(c0); 02133 } 02134 } 02135 02136 /* Find channel driver interfaces */ 02137 destpr = get_proto(c0); 02138 if (c1) 02139 srcpr = get_proto(c1); 02140 if (!destpr) { 02141 ast_debug(1, "Channel '%s' has no RTP, not doing anything\n", c0->name); 02142 ast_channel_unlock(c0); 02143 if (c1) 02144 ast_channel_unlock(c1); 02145 return -1; 02146 } 02147 if (!srcpr) { 02148 ast_debug(1, "Channel '%s' has no RTP, not doing anything\n", c1 ? c1->name : "<unspecified>"); 02149 ast_channel_unlock(c0); 02150 if (c1) 02151 ast_channel_unlock(c1); 02152 return -1; 02153 } 02154 02155 /* Get audio, video and text interface (if native bridge is possible) */ 02156 audio_dest_res = destpr->get_rtp_info(c0, &destp); 02157 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(c0, &vdestp) : AST_RTP_GET_FAILED; 02158 text_dest_res = destpr->get_trtp_info ? destpr->get_trtp_info(c0, &tdestp) : AST_RTP_GET_FAILED; 02159 if (srcpr) { 02160 audio_src_res = srcpr->get_rtp_info(c1, &srcp); 02161 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(c1, &vsrcp) : AST_RTP_GET_FAILED; 02162 text_src_res = srcpr->get_trtp_info ? srcpr->get_trtp_info(c1, &tsrcp) : AST_RTP_GET_FAILED; 02163 } 02164 02165 /* Check if bridge is still possible (In SIP directmedia=no stops this, like NAT) */ 02166 if (audio_dest_res != AST_RTP_TRY_NATIVE || (video_dest_res != AST_RTP_GET_FAILED && video_dest_res != AST_RTP_TRY_NATIVE)) { 02167 /* Somebody doesn't want to play... */ 02168 ast_channel_unlock(c0); 02169 if (c1) 02170 ast_channel_unlock(c1); 02171 return -1; 02172 } 02173 if (audio_src_res == AST_RTP_TRY_NATIVE && (video_src_res == AST_RTP_GET_FAILED || video_src_res == AST_RTP_TRY_NATIVE) && srcpr->get_codec) 02174 srccodec = srcpr->get_codec(c1); 02175 else 02176 srccodec = 0; 02177 if (audio_dest_res == AST_RTP_TRY_NATIVE && (video_dest_res == AST_RTP_GET_FAILED || video_dest_res == AST_RTP_TRY_NATIVE) && destpr->get_codec) 02178 destcodec = destpr->get_codec(c0); 02179 else 02180 destcodec = 0; 02181 /* Ensure we have at least one matching codec */ 02182 if (srcp && !(srccodec & destcodec)) { 02183 ast_channel_unlock(c0); 02184 ast_channel_unlock(c1); 02185 return 0; 02186 } 02187 /* Consider empty media as non-existent */ 02188 if (audio_src_res == AST_RTP_TRY_NATIVE && !srcp->them.sin_addr.s_addr) 02189 srcp = NULL; 02190 if (srcp && (srcp->nat || ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 02191 nat_active = 1; 02192 /* Bridge media early */ 02193 if (destpr->set_rtp_peer(c0, srcp, vsrcp, tsrcp, srccodec, nat_active)) 02194 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", c0->name, c1 ? c1->name : "<unspecified>"); 02195 ast_channel_unlock(c0); 02196 if (c1) 02197 ast_channel_unlock(c1); 02198 ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", c0->name, c1 ? c1->name : "<unspecified>"); 02199 return 0; 02200 }
| int ast_rtp_fd | ( | struct ast_rtp * | rtp | ) |
Definition at line 719 of file rtp.c.
References ast_rtp::s.
Referenced by __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), gtalk_new(), jingle_new(), mgcp_new(), p2p_callback_disable(), sip_new(), skinny_new(), start_rtp(), and unistim_new().
00720 { 00721 return rtp->s; 00722 }
Definition at line 2748 of file rtp.c.
References ast_rtp::bridged, rtp_bridge_lock(), and rtp_bridge_unlock().
Referenced by __sip_destroy(), ast_rtp_read(), and dialog_needdestroy().
02749 { 02750 struct ast_rtp *bridged = NULL; 02751 02752 rtp_bridge_lock(rtp); 02753 bridged = rtp->bridged; 02754 rtp_bridge_unlock(rtp); 02755 02756 return bridged; 02757 }
| 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 2364 of file rtp.c.
References rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, rtp_bridge_lock(), and rtp_bridge_unlock().
Referenced by gtalk_is_answered(), gtalk_newcall(), and process_sdp().
02366 { 02367 int pt; 02368 02369 rtp_bridge_lock(rtp); 02370 02371 *astFormats = *nonAstFormats = 0; 02372 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 02373 if (rtp->current_RTP_PT[pt].isAstFormat) { 02374 *astFormats |= rtp->current_RTP_PT[pt].code; 02375 } else { 02376 *nonAstFormats |= rtp->current_RTP_PT[pt].code; 02377 } 02378 } 02379 02380 rtp_bridge_unlock(rtp); 02381 }
| int ast_rtp_get_peer | ( | struct ast_rtp * | rtp, | |
| struct sockaddr_in * | them | |||
| ) |
Definition at line 2730 of file rtp.c.
References ast_rtp::them.
Referenced by acf_channel_read(), add_sdp(), bridge_native_loop(), check_rtp_timeout(), gtalk_update_stun(), oh323_set_rtp_peer(), process_sdp(), sip_set_rtp_peer(), skinny_set_rtp_peer(), and transmit_modify_with_sdp().
02731 { 02732 if ((them->sin_family != AF_INET) || 02733 (them->sin_port != rtp->them.sin_port) || 02734 (them->sin_addr.s_addr != rtp->them.sin_addr.s_addr)) { 02735 them->sin_family = AF_INET; 02736 them->sin_port = rtp->them.sin_port; 02737 them->sin_addr = rtp->them.sin_addr; 02738 return 1; 02739 } 02740 return 0; 02741 }
| int ast_rtp_get_qos | ( | struct ast_rtp * | rtp, | |
| const char * | qos, | |||
| char * | buf, | |||
| unsigned int | buflen | |||
| ) |
Get QOS stats on a RTP channel.
Definition at line 2869 of file rtp.c.
References __ast_rtp_get_qos().
Referenced by acf_channel_read().
02870 { 02871 double value; 02872 int found; 02873 02874 value = __ast_rtp_get_qos(rtp, qos, &found); 02875 02876 if (!found) 02877 return -1; 02878 02879 snprintf(buf, buflen, "%.0lf", value); 02880 02881 return 0; 02882 }
| unsigned int ast_rtp_get_qosvalue | ( | struct ast_rtp * | rtp, | |
| enum ast_rtp_qos_vars | value | |||
| ) |
Return RTP and RTCP QoS values.
Definition at line 2803 of file rtp.c.
References ast_log(), AST_RTP_RTT, AST_RTP_RXCOUNT, AST_RTP_RXJITTER, AST_RTP_RXPLOSS, AST_RTP_TXCOUNT, AST_RTP_TXJITTER, AST_RTP_TXPLOSS, ast_rtcp::expected_prior, LOG_DEBUG, option_debug, ast_rtcp::received_prior, ast_rtcp::reported_jitter, ast_rtcp::reported_lost, ast_rtp::rtcp, ast_rtcp::rtt, ast_rtp::rxcount, ast_rtp::rxjitter, and ast_rtp::txcount.
Referenced by show_chanstats_cb().
02804 { 02805 if (rtp == NULL) { 02806 if (option_debug > 1) 02807 ast_log(LOG_DEBUG, "NO RTP Structure? Kidding me? \n"); 02808 return 0; 02809 } 02810 if (option_debug > 1 && rtp->rtcp == NULL) { 02811 ast_log(LOG_DEBUG, "NO RTCP structure. Maybe in RTP p2p bridging mode? \n"); 02812 } 02813 02814 switch (value) { 02815 case AST_RTP_TXCOUNT: 02816 return (unsigned int) rtp->txcount; 02817 case AST_RTP_RXCOUNT: 02818 return (unsigned int) rtp->rxcount; 02819 case AST_RTP_TXJITTER: 02820 return (unsigned int) (rtp->rxjitter * 1000.0); 02821 case AST_RTP_RXJITTER: 02822 return (unsigned int) (rtp->rtcp ? (rtp->rtcp->reported_jitter / (unsigned int) 65536.0) : 0); 02823 case AST_RTP_RXPLOSS: 02824 return rtp->rtcp ? (rtp->rtcp->expected_prior - rtp->rtcp->received_prior) : 0; 02825 case AST_RTP_TXPLOSS: 02826 return rtp->rtcp ? rtp->rtcp->reported_lost : 0; 02827 case AST_RTP_RTT: 02828 return (unsigned int) (rtp->rtcp ? (rtp->rtcp->rtt * 100) : 0); 02829 } 02830 return 0; /* To make the compiler happy */ 02831 }
| char* ast_rtp_get_quality | ( | struct ast_rtp * | rtp, | |
| struct ast_rtp_quality * | qual, | |||
| enum ast_rtp_quality_type | qtype | |||
| ) |
Return RTCP quality string.
| rtp | An rtp structure to get qos information about. | |
| qual | An (optional) rtp quality structure that will be filled with the quality information described in the ast_rtp_quality structure. This structure is not dependent on any qtype, so a call for any type of information would yield the same results because ast_rtp_quality is not a data type specific to any qos type. | |
| qtype | The quality type you'd like, default should be RTPQOS_SUMMARY which returns basic information about the call. The return from RTPQOS_SUMMARY is basically ast_rtp_quality in a string. The other types are RTPQOS_JITTER, RTPQOS_LOSS and RTPQOS_RTT which will return more specific statistics. |
Definition at line 3076 of file rtp.c.
References __ast_rtp_get_quality(), __ast_rtp_get_quality_jitter(), __ast_rtp_get_quality_loss(), __ast_rtp_get_quality_rtt(), 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::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, RTPQOS_JITTER, RTPQOS_LOSS, RTPQOS_RTT, RTPQOS_SUMMARY, 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(), ast_rtp_set_vars(), handle_request_bye(), and sip_hangup().
03077 { 03078 if (qual && rtp) { 03079 qual->local_ssrc = rtp->ssrc; 03080 qual->local_jitter = rtp->rxjitter; 03081 qual->local_count = rtp->rxcount; 03082 qual->remote_ssrc = rtp->themssrc; 03083 qual->remote_count = rtp->txcount; 03084 03085 if (rtp->rtcp) { 03086 qual->local_lostpackets = rtp->rtcp->expected_prior - rtp->rtcp->received_prior; 03087 qual->remote_lostpackets = rtp->rtcp->reported_lost; 03088 qual->remote_jitter = rtp->rtcp->reported_jitter / 65536.0; 03089 qual->rtt = rtp->rtcp->rtt; 03090 } 03091 } 03092 03093 switch (qtype) { 03094 case RTPQOS_SUMMARY: 03095 return __ast_rtp_get_quality(rtp); 03096 case RTPQOS_JITTER: 03097 return __ast_rtp_get_quality_jitter(rtp); 03098 case RTPQOS_LOSS: 03099 return __ast_rtp_get_quality_loss(rtp); 03100 case RTPQOS_RTT: 03101 return __ast_rtp_get_quality_rtt(rtp); 03102 } 03103 03104 return NULL; 03105 }
| int ast_rtp_get_rtpholdtimeout | ( | struct ast_rtp * | rtp | ) |
Get rtp hold timeout.
Definition at line 779 of file rtp.c.
References ast_rtp::rtpholdtimeout, and ast_rtp::rtptimeout.
Referenced by check_rtp_timeout().
00780 { 00781 if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */ 00782 return 0; 00783 return rtp->rtpholdtimeout; 00784 }
| int ast_rtp_get_rtpkeepalive | ( | struct ast_rtp * | rtp | ) |
Get RTP keepalive interval.
Definition at line 787 of file rtp.c.
References ast_rtp::rtpkeepalive.
Referenced by check_rtp_timeout().
00788 { 00789 return rtp->rtpkeepalive; 00790 }
| int ast_rtp_get_rtptimeout | ( | struct ast_rtp * | rtp | ) |
Get rtp timeout.
Definition at line 771 of file rtp.c.
References ast_rtp::rtptimeout.
Referenced by check_rtp_timeout().
00772 { 00773 if (rtp->rtptimeout < 0) /* We're not checking, but remembering the setting (during T.38 transmission) */ 00774 return 0; 00775 return rtp->rtptimeout; 00776 }
| void ast_rtp_get_us | ( | struct ast_rtp * | rtp, | |
| struct sockaddr_in * | us | |||
| ) |
Definition at line 2743 of file rtp.c.
References ast_rtp::us.
Referenced by add_sdp(), external_rtp_create(), get_our_media_address(), gtalk_create_candidates(), handle_open_receive_channel_ack_message(), jingle_create_candidates(), oh323_set_rtp_peer(), skinny_set_rtp_peer(), and start_rtp().
| int ast_rtp_getnat | ( | struct ast_rtp * | rtp | ) |
Definition at line 807 of file rtp.c.
References ast_test_flag, and FLAG_NAT_ACTIVE.
Referenced by sip_get_rtp_peer().
00808 { 00809 return ast_test_flag(rtp, FLAG_NAT_ACTIVE); 00810 }
| void ast_rtp_init | ( | void | ) |
Initialize the RTP system in Asterisk.
Definition at line 4868 of file rtp.c.
References __ast_rtp_reload(), and ast_cli_register_multiple().
Referenced by main().
04869 { 04870 ast_cli_register_multiple(cli_rtp, sizeof(cli_rtp) / sizeof(struct ast_cli_entry)); 04871 __ast_rtp_reload(0); 04872 }
| 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 2405 of file rtp.c.
References rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, rtp_bridge_lock(), rtp_bridge_unlock(), 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(), add_tcodec_to_sdp(), add_vcodec_to_sdp(), ast_rtp_sendcng(), ast_rtp_senddigit_begin(), ast_rtp_write(), bridge_p2p_rtp_write(), and start_rtp().
02406 { 02407 int pt = 0; 02408 02409 rtp_bridge_lock(rtp); 02410 02411 if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && 02412 code == rtp->rtp_lookup_code_cache_code) { 02413 /* Use our cached mapping, to avoid the overhead of the loop below */ 02414 pt = rtp->rtp_lookup_code_cache_result; 02415 rtp_bridge_unlock(rtp); 02416 return pt; 02417 } 02418 02419 /* Check the dynamic list first */ 02420 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 02421 if (rtp->current_RTP_PT[pt].code == code && rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) { 02422 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 02423 rtp->rtp_lookup_code_cache_code = code; 02424 rtp->rtp_lookup_code_cache_result = pt; 02425 rtp_bridge_unlock(rtp); 02426 return pt; 02427 } 02428 } 02429 02430 /* Then the static list */ 02431 for (pt = 0; pt < MAX_RTP_PT; ++pt) { 02432 if (static_RTP_PT[pt].code == code && static_RTP_PT[pt].isAstFormat == isAstFormat) { 02433 rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; 02434 rtp->rtp_lookup_code_cache_code = code; 02435 rtp->rtp_lookup_code_cache_result = pt; 02436 rtp_bridge_unlock(rtp); 02437 return pt; 02438 } 02439 } 02440 02441 rtp_bridge_unlock(rtp); 02442 02443 return -1; 02444 }
| 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 2478 of file rtp.c.
References ast_copy_string(), ast_rtp_lookup_mime_subtype(), AST_RTP_MAX, format, len(), and name.
Referenced by process_sdp().
02480 { 02481 int format; 02482 unsigned len; 02483 char *end = buf; 02484 char *start = buf; 02485 02486 if (!buf || !size) 02487 return NULL; 02488 02489 snprintf(end, size, "0x%x (", capability); 02490 02491 len = strlen(end); 02492 end += len; 02493 size -= len; 02494 start = end; 02495 02496 for (format = 1; format < AST_RTP_MAX; format <<= 1) { 02497 if (capability & format) { 02498 const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format, options); 02499 02500 snprintf(end, size, "%s|", name); 02501 len = strlen(end); 02502 end += len; 02503 size -= len; 02504 } 02505 } 02506 02507 if (start == end) 02508 ast_copy_string(start, "nothing)", size); 02509 else if (size > 1) 02510 *(end -1) = ')'; 02511 02512 return buf; 02513 }
| 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 2446 of file rtp.c.
References ARRAY_LEN, AST_FORMAT_G726_AAL2, AST_RTP_OPT_G726_NONSTANDARD, rtpPayloadType::isAstFormat, mimeTypes, mimeType::payloadType, and mimeType::subtype.
Referenced by add_codec_to_sdp(), add_noncodec_to_sdp(), add_sdp(), add_tcodec_to_sdp(), add_vcodec_to_sdp(), ast_rtp_lookup_mime_multiple(), transmit_connect_with_sdp(), and transmit_modify_with_sdp().
02448 { 02449 unsigned int i; 02450 02451 for (i = 0; i < ARRAY_LEN(mimeTypes); ++i) { 02452 if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) { 02453 if (isAstFormat && 02454 (code == AST_FORMAT_G726_AAL2) && 02455 (options & AST_RTP_OPT_G726_NONSTANDARD)) 02456 return "G726-32"; 02457 else 02458 return mimeTypes[i].subtype; 02459 } 02460 } 02461 02462 return ""; 02463 }
| 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 2383 of file rtp.c.
References rtpPayloadType::code, rtpPayloadType::isAstFormat, MAX_RTP_PT, rtp_bridge_lock(), and rtp_bridge_unlock().
Referenced by ast_rtp_read(), bridge_p2p_rtp_write(), process_sdp_a_audio(), and setup_rtp_connection().
02384 { 02385 struct rtpPayloadType result; 02386 02387 result.isAstFormat = result.code = 0; 02388 02389 if (pt < 0 || pt >= MAX_RTP_PT) 02390 return result; /* bogus payload type */ 02391 02392 /* Start with negotiated codecs */ 02393 rtp_bridge_lock(rtp); 02394 result = rtp->current_RTP_PT[pt]; 02395 rtp_bridge_unlock(rtp); 02396 02397 /* If it doesn't exist, check our static RTP type list, just in case */ 02398 if (!result.code) 02399 result = static_RTP_PT[pt]; 02400 02401 return result; 02402 }
| unsigned int ast_rtp_lookup_sample_rate | ( | int | isAstFormat, | |
| int | code | |||
| ) |
Get the sample rate associated with known RTP payload types.
| isAstFormat | True if the value in the 'code' parameter is an AST_FORMAT value | |
| code | Format code, either from AST_FORMAT list or from AST_RTP list |
Definition at line 2465 of file rtp.c.
References ARRAY_LEN, rtpPayloadType::isAstFormat, mimeTypes, mimeType::payloadType, and mimeType::sample_rate.
Referenced by add_codec_to_sdp(), add_noncodec_to_sdp(), add_tcodec_to_sdp(), and add_vcodec_to_sdp().
02466 { 02467 unsigned int i; 02468 02469 for (i = 0; i < ARRAY_LEN(mimeTypes); ++i) { 02470 if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) { 02471 return mimeTypes[i].sample_rate; 02472 } 02473 } 02474 02475 return 0; 02476 }
| int ast_rtp_make_compatible | ( | struct ast_channel * | dest, | |
| struct ast_channel * | src, | |||
| int | media | |||
| ) |
Definition at line 2202 of file rtp.c.
References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, 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_trtp_info, ast_rtp_protocol::get_vrtp_info, LOG_WARNING, ast_channel::name, and ast_rtp_protocol::set_rtp_peer.
Referenced by dial_exec_full(), and do_forward().
02203 { 02204 struct ast_rtp *destp = NULL, *srcp = NULL; /* Audio RTP Channels */ 02205 struct ast_rtp *vdestp = NULL, *vsrcp = NULL; /* Video RTP channels */ 02206 struct ast_rtp *tdestp = NULL, *tsrcp = NULL; /* Text RTP channels */ 02207 struct ast_rtp_protocol *destpr = NULL, *srcpr = NULL; 02208 enum ast_rtp_get_result audio_dest_res = AST_RTP_GET_FAILED, video_dest_res = AST_RTP_GET_FAILED, text_dest_res = AST_RTP_GET_FAILED; 02209 enum ast_rtp_get_result audio_src_res = AST_RTP_GET_FAILED, video_src_res = AST_RTP_GET_FAILED, text_src_res = AST_RTP_GET_FAILED; 02210 int srccodec, destcodec; 02211 02212 /* Lock channels */ 02213 ast_channel_lock(dest); 02214 while (ast_channel_trylock(src)) { 02215 ast_channel_unlock(dest); 02216 usleep(1); 02217 ast_channel_lock(dest); 02218 } 02219 02220 /* Find channel driver interfaces */ 02221 if (!(destpr = get_proto(dest))) { 02222 ast_debug(1, "Channel '%s' has no RTP, not doing anything\n", dest->name); 02223 ast_channel_unlock(dest); 02224 ast_channel_unlock(src); 02225 return 0; 02226 } 02227 if (!(srcpr = get_proto(src))) { 02228 ast_debug(1, "Channel '%s' has no RTP, not doing anything\n", src->name); 02229 ast_channel_unlock(dest); 02230 ast_channel_unlock(src); 02231 return 0; 02232 } 02233 02234 /* Get audio and video interface (if native bridge is possible) */ 02235 audio_dest_res = destpr->get_rtp_info(dest, &destp); 02236 video_dest_res = destpr->get_vrtp_info ? destpr->get_vrtp_info(dest, &vdestp) : AST_RTP_GET_FAILED; 02237 text_dest_res = destpr->get_trtp_info ? destpr->get_trtp_info(dest, &tdestp) : AST_RTP_GET_FAILED; 02238 audio_src_res = srcpr->get_rtp_info(src, &srcp); 02239 video_src_res = srcpr->get_vrtp_info ? srcpr->get_vrtp_info(src, &vsrcp) : AST_RTP_GET_FAILED; 02240 text_src_res = srcpr->get_trtp_info ? srcpr->get_trtp_info(src, &tsrcp) : AST_RTP_GET_FAILED; 02241 02242 /* Ensure we have at least one matching codec */ 02243 if (srcpr->get_codec) 02244 srccodec = srcpr->get_codec(src); 02245 else 02246 srccodec = 0; 02247 if (destpr->get_codec) 02248 destcodec = destpr->get_codec(dest); 02249 else 02250 destcodec = 0; 02251 02252 /* Check if bridge is still possible (In SIP directmedia=no stops this, like NAT) */ 02253 if (audio_dest_res != AST_RTP_TRY_NATIVE || (video_dest_res != AST_RTP_GET_FAILED && video_dest_res != AST_RTP_TRY_NATIVE) || audio_src_res != AST_RTP_TRY_NATIVE || (video_src_res != AST_RTP_GET_FAILED && video_src_res != AST_RTP_TRY_NATIVE) || !(srccodec & destcodec)) { 02254 /* Somebody doesn't want to play... */ 02255 ast_channel_unlock(dest); 02256 ast_channel_unlock(src); 02257 return 0; 02258 } 02259 ast_rtp_pt_copy(destp, srcp); 02260 if (vdestp && vsrcp) 02261 ast_rtp_pt_copy(vdestp, vsrcp); 02262 if (tdestp && tsrcp) 02263 ast_rtp_pt_copy(tdestp, tsrcp); 02264 if (media) { 02265 /* Bridge early */ 02266 if (destpr->set_rtp_peer(dest, srcp, vsrcp, tsrcp, srccodec, ast_test_flag(srcp, FLAG_NAT_ACTIVE))) 02267 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", dest->name, src->name); 02268 } 02269 ast_channel_unlock(dest); 02270 ast_channel_unlock(src); 02271 ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n", dest->name, src->name); 02272 return 1; 02273 }
| 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 2673 of file rtp.c.
References ast_rtp_new_with_bindaddr().
02674 { 02675 struct in_addr ia; 02676 02677 memset(&ia, 0, sizeof(ia)); 02678 return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia); 02679 }
| void ast_rtp_new_init | ( | struct ast_rtp * | rtp | ) |
Initialize a new RTP structure.
reload rtp configuration
Definition at line 2564 of file rtp.c.
References ast_mutex_init(), ast_random(), ast_set_flag, FLAG_HAS_DTMF, ast_rtp::seqno, ast_rtp::ssrc, STRICT_RTP_LEARN, STRICT_RTP_OPEN, ast_rtp::strict_rtp_state, ast_rtp::them, and ast_rtp::us.
Referenced by ast_rtp_new_with_bindaddr(), and process_sdp().
02565 { 02566 #ifdef P2P_INTENSE 02567 ast_mutex_init(&rtp->bridge_lock); 02568 #endif 02569 02570 rtp->them.sin_family = AF_INET; 02571 rtp->us.sin_family = AF_INET; 02572 rtp->ssrc = ast_random(); 02573 rtp->seqno = ast_random() & 0xffff; 02574 ast_set_flag(rtp, FLAG_HAS_DTMF); 02575 rtp->strict_rtp_state = (strictrtp ? STRICT_RTP_LEARN : STRICT_RTP_OPEN); 02576 }
| void ast_rtp_new_source | ( | struct ast_rtp * | rtp | ) |
Indicate that we need to set the marker bit.
Definition at line 2686 of file rtp.c.
References ast_debug, and ast_rtp::set_marker_bit.
Referenced by mgcp_indicate(), oh323_indicate(), sip_answer(), sip_indicate(), sip_write(), and skinny_indicate().
02687 { 02688 if (rtp) { 02689 rtp->set_marker_bit = 1; 02690 ast_debug(3, "Setting the marker bit due to a source update\n"); 02691 } 02692 }
| 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 2578 of file rtp.c.
References ast_calloc, ast_free, 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, ast_rtp::io, ast_rtp::ioid, LOG_ERROR, ast_rtp::rtcp, rtp_socket(), rtpread(), ast_rtcp::s, ast_rtp::s, ast_rtp::sched, ast_rtcp::us, and ast_rtp::us.
Referenced by __oh323_rtp_create(), ast_rtp_new(), gtalk_alloc(), jingle_alloc(), sip_alloc(), and start_rtp().
02579 { 02580 struct ast_rtp *rtp; 02581 int x; 02582 int startplace; 02583 02584 if (!(rtp = ast_calloc(1, sizeof(*rtp)))) 02585 return NULL; 02586 02587 ast_rtp_new_init(rtp); 02588 02589 rtp->s = rtp_socket("RTP"); 02590 if (rtp->s < 0) 02591 goto fail; 02592 if (sched && rtcpenable) { 02593 rtp->sched = sched; 02594 rtp->rtcp = ast_rtcp_new(); 02595 } 02596 02597 /* 02598 * Try to bind the RTP port, x, and possibly the RTCP port, x+1 as well. 02599 * Start from a random (even, by RTP spec) port number, and 02600 * iterate until success or no ports are available. 02601 * Note that the requirement of RTP port being even, or RTCP being the 02602 * next one, cannot be enforced in presence of a NAT box because the 02603 * mapping is not under our control. 02604 */ 02605 x = (rtpend == rtpstart) ? rtpstart : (ast_random() % (rtpend - rtpstart)) + rtpstart; 02606 x = x & ~1; /* make it an even number */ 02607 startplace = x; /* remember the starting point */ 02608 /* this is constant across the loop */ 02609 rtp->us.sin_addr = addr; 02610 if (rtp->rtcp) 02611 rtp->rtcp->us.sin_addr = addr; 02612 for (;;) { 02613 rtp->us.sin_port = htons(x); 02614 if (!bind(rtp->s, (struct sockaddr *)&rtp->us, sizeof(rtp->us))) { 02615 /* bind succeeded, if no rtcp then we are done */ 02616 if (!rtp->rtcp) 02617 break; 02618 /* have rtcp, try to bind it */ 02619 rtp->rtcp->us.sin_port = htons(x + 1); 02620 if (!bind(rtp->rtcp->s, (struct sockaddr *)&rtp->rtcp->us, sizeof(rtp->rtcp->us))) 02621 break; /* success again, we are really done */ 02622 /* 02623 * RTCP bind failed, so close and recreate the 02624 * already bound RTP socket for the next round. 02625 */ 02626 close(rtp->s); 02627 rtp->s = rtp_socket("RTP"); 02628 if (rtp->s < 0) 02629 goto fail; 02630 } 02631 /* 02632 * If we get here, there was an error in one of the bind() 02633 * calls, so make sure it is nothing unexpected. 02634 */ 02635 if (errno != EADDRINUSE) { 02636 /* We got an error that wasn't expected, abort! */ 02637 ast_log(LOG_ERROR, "Unexpected bind error: %s\n", strerror(errno)); 02638 goto fail; 02639 } 02640 /* 02641 * One of the ports is in use. For the next iteration, 02642 * increment by two and handle wraparound. 02643 * If we reach the starting point, then declare failure. 02644 */ 02645 x += 2; 02646 if (x > rtpend) 02647 x = (rtpstart + 1) & ~1; 02648 if (x == startplace) { 02649 ast_log(LOG_ERROR, "No RTP ports remaining. Can't setup media stream for this call.\n"); 02650 goto fail; 02651 } 02652 } 02653 rtp->sched = sched; 02654 rtp->io = io; 02655 if (callbackmode) { 02656 rtp->ioid = ast_io_add(rtp->io, rtp->s, rtpread, AST_IO_IN, rtp); 02657 ast_set_flag(rtp, FLAG_CALLBACK_MODE); 02658 } 02659 ast_rtp_pt_default(rtp); 02660 return rtp; 02661 02662 fail: 02663 if (rtp->s >= 0) 02664 close(rtp->s); 02665 if (rtp->rtcp) { 02666 close(rtp->rtcp->s); 02667 ast_free(rtp->rtcp); 02668 } 02669 ast_free(rtp); 02670 return NULL; 02671 }
| int ast_rtp_proto_register | ( | struct ast_rtp_protocol * | proto | ) |
Register an RTP channel client.
Definition at line 3945 of file rtp.c.
References ast_log(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_rtp_protocol::list, LOG_WARNING, and ast_rtp_protocol::type.
Referenced by load_module().
03946 { 03947 struct ast_rtp_protocol *cur; 03948 03949 AST_RWLIST_WRLOCK(&protos); 03950 AST_RWLIST_TRAVERSE(&protos, cur, list) { 03951 if (!strcmp(cur->type, proto->type)) { 03952 ast_log(LOG_WARNING, "Tried to register same protocol '%s' twice\n", cur->type); 03953 AST_RWLIST_UNLOCK(&protos); 03954 return -1; 03955 } 03956 } 03957 AST_RWLIST_INSERT_HEAD(&protos, proto, list); 03958 AST_RWLIST_UNLOCK(&protos); 03959 03960 return 0; 03961 }
| void ast_rtp_proto_unregister | ( | struct ast_rtp_protocol * | proto | ) |
Unregister an RTP channel client.
Definition at line 3937 of file rtp.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by load_module(), and unload_module().
03938 { 03939 AST_RWLIST_WRLOCK(&protos); 03940 AST_RWLIST_REMOVE(&protos, proto, list); 03941 AST_RWLIST_UNLOCK(&protos); 03942 }
| void ast_rtp_pt_clear | ( | struct ast_rtp * | rtp | ) |
Setting RTP payload types from lines in a SDP description:.
Definition at line 2040 of file rtp.c.
References rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, rtp_bridge_lock(), rtp_bridge_unlock(), 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().
02041 { 02042 int i; 02043 02044 if (!rtp) 02045 return; 02046 02047 rtp_bridge_lock(rtp); 02048 02049 for (i = 0; i < MAX_RTP_PT; ++i) { 02050 rtp->current_RTP_PT[i].isAstFormat = 0; 02051 rtp->current_RTP_PT[i].code = 0; 02052 } 02053 02054 rtp->rtp_lookup_code_cache_isAstFormat = 0; 02055 rtp->rtp_lookup_code_cache_code = 0; 02056 rtp->rtp_lookup_code_cache_result = 0; 02057 02058 rtp_bridge_unlock(rtp); 02059 }
Copy payload types between RTP structures.
Definition at line 2080 of file rtp.c.
References rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, rtp_bridge_lock(), rtp_bridge_unlock(), 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().
02081 { 02082 unsigned int i; 02083 02084 rtp_bridge_lock(dest); 02085 rtp_bridge_lock(src); 02086 02087 for (i = 0; i < MAX_RTP_PT; ++i) { 02088 dest->current_RTP_PT[i].isAstFormat = 02089 src->current_RTP_PT[i].isAstFormat; 02090 dest->current_RTP_PT[i].code = 02091 src->current_RTP_PT[i].code; 02092 } 02093 dest->rtp_lookup_code_cache_isAstFormat = 0; 02094 dest->rtp_lookup_code_cache_code = 0; 02095 dest->rtp_lookup_code_cache_result = 0; 02096 02097 rtp_bridge_unlock(src); 02098 rtp_bridge_unlock(dest); 02099 }
| void ast_rtp_pt_default | ( | struct ast_rtp * | rtp | ) |
Set payload types to defaults.
Definition at line 2061 of file rtp.c.
References rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, rtp_bridge_lock(), rtp_bridge_unlock(), ast_rtp::rtp_lookup_code_cache_code, ast_rtp::rtp_lookup_code_cache_isAstFormat, and ast_rtp::rtp_lookup_code_cache_result.
Referenced by ast_rtp_new_with_bindaddr().
02062 { 02063 int i; 02064 02065 rtp_bridge_lock(rtp); 02066 02067 /* Initialize to default payload types */ 02068 for (i = 0; i < MAX_RTP_PT; ++i) { 02069 rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat; 02070 rtp->current_RTP_PT[i].code = static_RTP_PT[i].code; 02071 } 02072 02073 rtp->rtp_lookup_code_cache_isAstFormat = 0; 02074 rtp->rtp_lookup_code_cache_code = 0; 02075 rtp->rtp_lookup_code_cache_result = 0; 02076 02077 rtp_bridge_unlock(rtp); 02078 }
Definition at line 1578 of file rtp.c.
References ast_rtp::altthem, ast_assert, ast_codec_get_samples(), AST_CONTROL_SRCCHANGE, ast_debug, AST_FORMAT_AUDIO_MASK, ast_format_rate(), AST_FORMAT_SLINEAR, AST_FORMAT_T140, AST_FORMAT_T140RED, AST_FORMAT_VIDEO_MASK, ast_frame_byteswap_be, AST_FRAME_CONTROL, AST_FRAME_DTMF_END, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, AST_FRFLAG_HAS_TIMING_INFO, AST_FRIENDLY_OFFSET, ast_frisolate(), ast_inet_ntoa(), AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_HEAD_INIT_NOLOCK, AST_LIST_INSERT_TAIL, ast_log(), ast_null_frame, ast_rtcp_calc_interval(), ast_rtcp_write(), AST_RTP_CISCO_DTMF, AST_RTP_CN, AST_RTP_DTMF, ast_rtp_get_bridged(), ast_rtp_lookup_pt(), ast_rtp_senddigit_continuation(), ast_samp2tv(), ast_sched_add(), ast_set_flag, ast_tv(), ast_tvdiff_ms(), ast_verbose, bridge_p2p_rtp_write(), ast_rtp::bridged, calc_rxstamp(), rtpPayloadType::code, create_dtmf_frame(), ast_rtp::cycles, ast_frame::data, ast_frame::datalen, ast_frame::delivery, ast_rtp::dtmf_duration, ast_rtp::dtmf_timeout, errno, ext, ast_rtp::f, f, FLAG_NAT_ACTIVE, ast_frame::frametype, rtpPayloadType::isAstFormat, ast_rtp::lastevent, ast_rtp::lastitexttimestamp, ast_rtp::lastividtimestamp, ast_rtp::lastrxformat, ast_rtp::lastrxseqno, ast_rtp::lastrxts, ast_frame::len, len(), LOG_NOTICE, LOG_WARNING, ast_frame::mallocd, ast_rtp::nat, ast_frame::offset, option_debug, process_cisco_dtmf(), process_rfc2833(), process_rfc3389(), ast_frame::ptr, ast_rtp::rawdata, ast_rtp::resp, ast_rtp::rtcp, rtp_debug_test_addr(), rtp_get_rate(), RTP_SEQ_MOD, ast_rtp::rxcount, ast_rtp::rxseqno, ast_rtp::rxssrc, ast_rtp::s, ast_frame::samples, ast_rtp::sched, ast_rtcp::schedid, ast_rtp::seedrxseqno, ast_rtp::sending_digit, ast_frame::seqno, ast_frame::src, ast_rtp::strict_rtp_address, STRICT_RTP_CLOSED, STRICT_RTP_LEARN, ast_rtp::strict_rtp_state, STUN_ACCEPT, stun_handle_packet(), ast_frame::subclass, ast_rtcp::them, ast_rtp::them, ast_rtp::themssrc, ast_frame::ts, and version.
Referenced by gtalk_rtp_read(), jingle_rtp_read(), mgcp_rtp_read(), oh323_rtp_read(), rtpread(), sip_rtp_read(), skinny_rtp_read(), and unistim_rtp_read().
01579 { 01580 int res; 01581 struct sockaddr_in sock_in; 01582 socklen_t len; 01583 unsigned int seqno; 01584 int version; 01585 int payloadtype; 01586 int hdrlen = 12; 01587 int padding; 01588 int mark; 01589 int ext; 01590 int cc; 01591 unsigned int ssrc; 01592 unsigned int timestamp; 01593 unsigned int *rtpheader; 01594 struct rtpPayloadType rtpPT; 01595 struct ast_rtp *bridged = NULL; 01596 int prev_seqno; 01597 struct frame_list frames; 01598 01599 /* If time is up, kill it */ 01600 if (rtp->sending_digit) 01601 ast_rtp_senddigit_continuation(rtp); 01602 01603 len = sizeof(sock_in); 01604 01605 /* Cache where the header will go */ 01606 res = recvfrom(rtp->s, rtp->rawdata + AST_FRIENDLY_OFFSET, sizeof(rtp->rawdata) - AST_FRIENDLY_OFFSET, 01607 0, (struct sockaddr *)&sock_in, &len); 01608 01609 /* If strict RTP protection is enabled see if we need to learn this address or if the packet should be dropped */ 01610 if (rtp->strict_rtp_state == STRICT_RTP_LEARN) { 01611 /* Copy over address that this packet was received on */ 01612 memcpy(&rtp->strict_rtp_address, &sock_in, sizeof(rtp->strict_rtp_address)); 01613 /* Now move over to actually protecting the RTP port */ 01614 rtp->strict_rtp_state = STRICT_RTP_CLOSED; 01615 ast_debug(1, "Learned remote address is %s:%d for strict RTP purposes, now protecting the port.\n", ast_inet_ntoa(rtp->strict_rtp_address.sin_addr), ntohs(rtp->strict_rtp_address.sin_port)); 01616 } else if (rtp->strict_rtp_state == STRICT_RTP_CLOSED) { 01617 /* If the address we previously learned doesn't match the address this packet came in on simply drop it */ 01618 if ((rtp->strict_rtp_address.sin_addr.s_addr != sock_in.sin_addr.s_addr) || (rtp->strict_rtp_address.sin_port != sock_in.sin_port)) { 01619 ast_debug(1, "Received RTP packet from %s:%d, dropping due to strict RTP protection. Expected it to be from %s:%d\n", ast_inet_ntoa(sock_in.sin_addr), ntohs(sock_in.sin_port), ast_inet_ntoa(rtp->strict_rtp_address.sin_addr), ntohs(rtp->strict_rtp_address.sin_port)); 01620 return &ast_null_frame; 01621 } 01622 } 01623 01624 rtpheader = (unsigned int *)(rtp->rawdata + AST_FRIENDLY_OFFSET); 01625 if (res < 0) { 01626 ast_assert(errno != EBADF); 01627 if (errno != EAGAIN) { 01628 ast_log(LOG_WARNING, "RTP Read error: %s. Hanging up.\n", strerror(errno)); 01629 return NULL; 01630 } 01631 return &ast_null_frame; 01632 } 01633 01634 if (res < hdrlen) { 01635 ast_log(LOG_WARNING, "RTP Read too short\n"); 01636 return &ast_null_frame; 01637 } 01638 01639 /* Get fields */ 01640 seqno = ntohl(rtpheader[0]); 01641 01642 /* Check RTP version */ 01643 version = (seqno & 0xC0000000) >> 30; 01644 if (!version) { 01645 /* If the two high bits are 0, this might be a 01646 * STUN message, so process it. stun_handle_packet() 01647 * answers to requests, and it returns STUN_ACCEPT 01648 * if the request is valid. 01649 */ 01650 if ((stun_handle_packet(rtp->s, &sock_in, rtp->rawdata + AST_FRIENDLY_OFFSET, res, NULL, NULL) == STUN_ACCEPT) && 01651 (!rtp->them.sin_port && !rtp->them.sin_addr.s_addr)) { 01652 memcpy(&rtp->them, &sock_in, sizeof(rtp->them)); 01653 } 01654 return &ast_null_frame; 01655 } 01656 01657 #if 0 /* Allow to receive RTP stream with closed transmission path */ 01658 /* If we don't have the other side's address, then ignore this */ 01659 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 01660 return &ast_null_frame; 01661 #endif 01662 01663 /* Send to whoever send to us if NAT is turned on */ 01664 if (rtp->nat) { 01665 if (((rtp->them.sin_addr.s_addr != sock_in.sin_addr.s_addr) || 01666 (rtp->them.sin_port != sock_in.sin_port)) && 01667 ((rtp->altthem.sin_addr.s_addr != sock_in.sin_addr.s_addr) || 01668 (rtp->altthem.sin_port != sock_in.sin_port))) { 01669 rtp->them = sock_in; 01670 if (rtp->rtcp) { 01671 int h = 0; 01672 memcpy(&rtp->rtcp->them, &sock_in, sizeof(rtp->rtcp->them)); 01673 h = ntohs(rtp->them.sin_port); 01674 rtp->rtcp->them.sin_port = htons(h + 1); 01675 } 01676 rtp->rxseqno = 0; 01677 ast_set_flag(rtp, FLAG_NAT_ACTIVE); 01678 if (option_debug || rtpdebug) 01679 ast_debug(0, "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)); 01680 } 01681 } 01682 01683 /* If we are bridged to another RTP stream, send direct */ 01684 if ((bridged = ast_rtp_get_bridged(rtp)) && !bridge_p2p_rtp_write(rtp, bridged, rtpheader, res, hdrlen)) 01685 return &ast_null_frame; 01686 01687 if (version != 2) 01688 return &ast_null_frame; 01689 01690 payloadtype = (seqno & 0x7f0000) >> 16; 01691 padding = seqno & (1 << 29); 01692 mark = seqno & (1 << 23); 01693 ext = seqno & (1 << 28); 01694 cc = (seqno & 0xF000000) >> 24; 01695 seqno &= 0xffff; 01696 timestamp = ntohl(rtpheader[1]); 01697 ssrc = ntohl(rtpheader[2]); 01698 01699 AST_LIST_HEAD_INIT_NOLOCK(&frames); 01700 /* Force a marker bit and change SSRC if the SSRC changes */ 01701 if (rtp->rxssrc && rtp->rxssrc != ssrc) { 01702 struct ast_frame *f, srcupdate = { 01703 AST_FRAME_CONTROL, 01704 .subclass = AST_CONTROL_SRCCHANGE, 01705 }; 01706 01707 if (!mark) { 01708 if (option_debug || rtpdebug) { 01709 ast_debug(0, "Forcing Marker bit, because SSRC has changed\n"); 01710 } 01711 mark = 1; 01712 } 01713 f = ast_frisolate(&srcupdate); 01714 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01715 } 01716 01717 rtp->rxssrc = ssrc; 01718 01719 if (padding) { 01720 /* Remove padding bytes */ 01721 res -= rtp->rawdata[AST_FRIENDLY_OFFSET + res - 1]; 01722 } 01723 01724 if (cc) { 01725 /* CSRC fields present */ 01726 hdrlen += cc*4; 01727 } 01728 01729 if (ext) { 01730 /* RTP Extension present */ 01731 hdrlen += (ntohl(rtpheader[hdrlen/4]) & 0xffff) << 2; 01732 hdrlen += 4; 01733 if (option_debug) { 01734 int profile; 01735 profile = (ntohl(rtpheader[3]) & 0xffff0000) >> 16; 01736 if (profile == 0x505a) 01737 ast_debug(1, "Found Zfone extension in RTP stream - zrtp - not supported.\n"); 01738 else 01739 ast_debug(1, "Found unknown RTP Extensions %x\n", profile); 01740 } 01741 } 01742 01743 if (res < hdrlen) { 01744 ast_log(LOG_WARNING, "RTP Read too short (%d, expecting %d)\n", res, hdrlen); 01745 return AST_LIST_FIRST(&frames) ? AST_LIST_FIRST(&frames) : &ast_null_frame; 01746 } 01747 01748 rtp->rxcount++; /* Only count reasonably valid packets, this'll make the rtcp stats more accurate */ 01749 01750 if (rtp->rxcount==1) { 01751 /* This is the first RTP packet successfully received from source */ 01752 rtp->seedrxseqno = seqno; 01753 } 01754 01755 /* Do not schedule RR if RTCP isn't run */ 01756 if (rtp->rtcp && rtp->rtcp->them.sin_addr.s_addr && rtp->rtcp->schedid < 1) { 01757 /* Schedule transmission of Receiver Report */ 01758 rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, rtp); 01759 } 01760 if ((int)rtp->lastrxseqno - (int)seqno > 100) /* if so it would indicate that the sender cycled; allow for misordering */ 01761 rtp->cycles += RTP_SEQ_MOD; 01762 01763 prev_seqno = rtp->lastrxseqno; 01764 01765 rtp->lastrxseqno = seqno; 01766 01767 if (!rtp->themssrc) 01768 rtp->themssrc = ntohl(rtpheader[2]); /* Record their SSRC to put in future RR */ 01769 01770 if (rtp_debug_test_addr(&sock_in)) 01771 ast_verbose("Got RTP packet from %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 01772 ast_inet_ntoa(sock_in.sin_addr), ntohs(sock_in.sin_port), payloadtype, seqno, timestamp,res - hdrlen); 01773 01774 rtpPT = ast_rtp_lookup_pt(rtp, payloadtype); 01775 if (!rtpPT.isAstFormat) { 01776 struct ast_frame *f = NULL; 01777 01778 /* This is special in-band data that's not one of our codecs */ 01779 if (rtpPT.code == AST_RTP_DTMF) { 01780 /* It's special -- rfc2833 process it */ 01781 if (rtp_debug_test_addr(&sock_in)) { 01782 unsigned char *data; 01783 unsigned int event; 01784 unsigned int event_end; 01785 unsigned int duration; 01786 data = rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen; 01787 event = ntohl(*((unsigned int *)(data))); 01788 event >>= 24; 01789 event_end = ntohl(*((unsigned int *)(data))); 01790 event_end <<= 8; 01791 event_end >>= 24; 01792 duration = ntohl(*((unsigned int *)(data))); 01793 duration &= 0xFFFF; 01794 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(sock_in.sin_addr), ntohs(sock_in.sin_port), payloadtype, seqno, timestamp, res - hdrlen, (mark?1:0), event, ((event_end & 0x80)?1:0), duration); 01795 } 01796 /* process_rfc2833 may need to return multiple frames. We do this 01797 * by passing the pointer to the frame list to it so that the method 01798 * can append frames to the list as needed 01799 */ 01800 process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen, seqno, timestamp, &frames); 01801 } else if (rtpPT.code == AST_RTP_CISCO_DTMF) { 01802 /* It's really special -- process it the Cisco way */ 01803 if (rtp->lastevent <= seqno || (rtp->lastevent >= 65530 && seqno <= 6)) { 01804 f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01805 rtp->lastevent = seqno; 01806 } 01807 } else if (rtpPT.code == AST_RTP_CN) { 01808 /* Comfort Noise */ 01809 f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); 01810 } else { 01811 ast_log(LOG_NOTICE, "Unknown RTP codec %d received from '%s'\n", payloadtype, ast_inet_ntoa(rtp->them.sin_addr)); 01812 } 01813 if (f) { 01814 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01815 } 01816 /* Even if no frame was returned by one of the above methods, 01817 * we may have a frame to return in our frame list 01818 */ 01819 if (!AST_LIST_EMPTY(&frames)) { 01820 return AST_LIST_FIRST(&frames); 01821 } 01822 return &ast_null_frame; 01823 } 01824 rtp->lastrxformat = rtp->f.subclass = rtpPT.code; 01825 rtp->f.frametype = (rtp->f.subclass & AST_FORMAT_AUDIO_MASK) ? AST_FRAME_VOICE : (rtp->f.subclass & AST_FORMAT_VIDEO_MASK) ? AST_FRAME_VIDEO : AST_FRAME_TEXT; 01826 01827 rtp->rxseqno = seqno; 01828 01829 if (rtp->dtmf_timeout && rtp->dtmf_timeout < timestamp) { 01830 rtp->dtmf_timeout = 0; 01831 01832 if (rtp->resp) { 01833 struct ast_frame *f; 01834 f = create_dtmf_frame(rtp, AST_FRAME_DTMF_END); 01835 f->len = ast_tvdiff_ms(ast_samp2tv(rtp->dtmf_duration, rtp_get_rate(f->subclass)), ast_tv(0, 0)); 01836 rtp->resp = 0; 01837 rtp->dtmf_timeout = rtp->dtmf_duration = 0; 01838 AST_LIST_INSERT_TAIL(&frames, f, frame_list); 01839 return AST_LIST_FIRST(&frames); 01840 } 01841 } 01842 01843 /* Record received timestamp as last received now */ 01844 rtp->lastrxts = timestamp; 01845 01846 rtp->f.mallocd = 0; 01847 rtp->f.datalen = res - hdrlen; 01848 rtp->f.data.ptr = rtp->rawdata + hdrlen + AST_FRIENDLY_OFFSET; 01849 rtp->f.offset = hdrlen + AST_FRIENDLY_OFFSET; 01850 rtp->f.seqno = seqno; 01851 01852 if (rtp->f.subclass == AST_FORMAT_T140 && (int)seqno - (prev_seqno+1) > 0 && (int)seqno - (prev_seqno+1) < 10) { 01853 unsigned char *data = rtp->f.data.ptr; 01854 01855 memmove(rtp->f.data.ptr+3, rtp->f.data.ptr, rtp->f.datalen); 01856 rtp->f.datalen +=3; 01857 *data++ = 0xEF; 01858 *data++ = 0xBF; 01859 *data = 0xBD; 01860 } 01861 01862 if (rtp->f.subclass == AST_FORMAT_T140RED) { 01863 unsigned char *data = rtp->f.data.ptr; 01864 unsigned char *header_end; 01865 int num_generations; 01866 int header_length; 01867 int length; 01868 int diff =(int)seqno - (prev_seqno+1); /* if diff = 0, no drop*/ 01869 int x; 01870 01871 rtp->f.subclass = AST_FORMAT_T140; 01872 header_end = memchr(data, ((*data) & 0x7f), rtp->f.datalen); 01873 if (header_end == NULL) { 01874 return &ast_null_frame; 01875 } 01876 header_end++; 01877 01878 header_length = header_end - data; 01879 num_generations = header_length / 4; 01880 length = header_length; 01881 01882 if (!diff) { 01883 for (x = 0; x < num_generations; x++) 01884 length += data[x * 4 + 3]; 01885 01886 if (!(rtp->f.datalen - length)) 01887 return &ast_null_frame; 01888 01889 rtp->f.data.ptr += length; 01890 rtp->f.datalen -= length; 01891 } else if (diff > num_generations && diff < 10) { 01892 length -= 3; 01893 rtp->f.data.ptr += length; 01894 rtp->f.datalen -= length; 01895 01896 data = rtp->f.data.ptr; 01897 *data++ = 0xEF; 01898 *data++ = 0xBF; 01899 *data = 0xBD; 01900 } else { 01901 for ( x = 0; x < num_generations - diff; x++) 01902 length += data[x * 4 + 3]; 01903 01904 rtp->f.data.ptr += length; 01905 rtp->f.datalen -= length; 01906 } 01907 } 01908 01909 if (rtp->f.subclass & AST_FORMAT_AUDIO_MASK) { 01910 rtp->f.samples = ast_codec_get_samples(&rtp->f); 01911 if (rtp->f.subclass == AST_FORMAT_SLINEAR) 01912 ast_frame_byteswap_be(&rtp->f); 01913 calc_rxstamp(&rtp->f.delivery, rtp, timestamp, mark); 01914 /* Add timing data to let ast_generic_bridge() put the frame into a jitterbuf */ 01915 ast_set_flag(&rtp->f, AST_FRFLAG_HAS_TIMING_INFO); 01916 rtp->f.ts = timestamp / (rtp_get_rate(rtp->f.subclass) / 1000); 01917 rtp->f.len = rtp->f.samples / ((ast_format_rate(rtp->f.subclass) / 1000)); 01918 } else if (rtp->f.subclass & AST_FORMAT_VIDEO_MASK) { 01919 /* Video -- samples is # of samples vs. 90000 */ 01920 if (!rtp->lastividtimestamp) 01921 rtp->lastividtimestamp = timestamp; 01922 rtp->f.samples = timestamp - rtp->lastividtimestamp; 01923 rtp->lastividtimestamp = timestamp; 01924 rtp->f.delivery.tv_sec = 0; 01925 rtp->f.delivery.tv_usec = 0; 01926 /* Pass the RTP marker bit as bit 0 in the subclass field. 01927 * This is ok because subclass is actually a bitmask, and 01928 * the low bits represent audio formats, that are not 01929 * involved here since we deal with video. 01930 */ 01931 if (mark) 01932 rtp->f.subclass |= 0x1; 01933 } else { 01934 /* TEXT -- samples is # of samples vs. 1000 */ 01935 if (!rtp->lastitexttimestamp) 01936 rtp->lastitexttimestamp = timestamp; 01937 rtp->f.samples = timestamp - rtp->lastitexttimestamp; 01938 rtp->lastitexttimestamp = timestamp; 01939 rtp->f.delivery.tv_sec = 0; 01940 rtp->f.delivery.tv_usec = 0; 01941 } 01942 rtp->f.src = "RTP"; 01943 01944 AST_LIST_INSERT_TAIL(&frames, &rtp->f, frame_list); 01945 return AST_LIST_FIRST(&frames); 01946 }
| int ast_rtp_reload | ( | void | ) |
Initialize RTP subsystem
Definition at line 4862 of file rtp.c.
References __ast_rtp_reload().
04863 { 04864 return __ast_rtp_reload(1); 04865 }
| void ast_rtp_reset | ( | struct ast_rtp * | rtp | ) |
Definition at line 2780 of file rtp.c.
References ast_rtp::dtmf_timeout, ast_rtp::dtmfmute, ast_rtp::dtmfsamples, ast_rtp::lastdigitts, ast_rtp::lastevent, ast_rtp::lasteventseqn, ast_rtp::lastitexttimestamp, ast_rtp::lastividtimestamp, ast_rtp::lastotexttimestamp, 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.
02781 { 02782 memset(&rtp->rxcore, 0, sizeof(rtp->rxcore)); 02783 memset(&rtp->txcore, 0, sizeof(rtp->txcore)); 02784 memset(&rtp->dtmfmute, 0, sizeof(rtp->dtmfmute)); 02785 rtp->lastts = 0; 02786 rtp->lastdigitts = 0; 02787 rtp->lastrxts = 0; 02788 rtp->lastividtimestamp = 0; 02789 rtp->lastovidtimestamp = 0; 02790 rtp->lastitexttimestamp = 0; 02791 rtp->lastotexttimestamp = 0; 02792 rtp->lasteventseqn = 0; 02793 rtp->lastevent = 0; 02794 rtp->lasttxformat = 0; 02795 rtp->lastrxformat = 0; 02796 rtp->dtmf_timeout = 0; 02797 rtp->dtmfsamples = 0; 02798 rtp->seqno = 0; 02799 rtp->rxseqno = 0; 02800 }
| int ast_rtp_sendcng | ( | struct ast_rtp * | rtp, | |
| int | level | |||
| ) |
generate comfort noice (CNG)
Definition at line 3623 of file rtp.c.
References ast_inet_ntoa(), ast_log(), AST_RTP_CN, ast_rtp_lookup_code(), ast_tv(), ast_tvadd(), ast_tvnow(), ast_verbose, ast_rtp::data, ast_rtp::dtmfmute, errno, ast_rtp::lastts, LOG_ERROR, rtp_debug_test_addr(), ast_rtp::s, ast_rtp::seqno, ast_rtp::ssrc, and ast_rtp::them.
Referenced by check_rtp_timeout().
03624 { 03625 unsigned int *rtpheader; 03626 int hdrlen = 12; 03627 int res; 03628 int payload; 03629 char data[256]; 03630 level = 127 - (level & 0x7f); 03631 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_CN); 03632 03633 /* If we have no peer, return immediately */ 03634 if (!rtp->them.sin_addr.s_addr) 03635 return 0; 03636 03637 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 03638 03639 /* Get a pointer to the header */ 03640 rtpheader = (unsigned int *)data; 03641 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno++)); 03642 rtpheader[1] = htonl(rtp->lastts); 03643 rtpheader[2] = htonl(rtp->ssrc); 03644 data[12] = level; 03645 if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) { 03646 res = sendto(rtp->s, (void *)rtpheader, hdrlen + 1, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them)); 03647 if (res <0) 03648 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)); 03649 if (rtp_debug_test_addr(&rtp->them)) 03650 ast_verbose("Sent Comfort Noise RTP packet to %s:%u (type %d, seq %u, ts %u, len %d)\n" 03651 , ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen); 03652 03653 } 03654 return 0; 03655 }
| int ast_rtp_senddigit_begin | ( | struct ast_rtp * | rtp, | |
| char | digit | |||
| ) |
Send begin frames for DTMF.
Definition at line 3190 of file rtp.c.
References ast_inet_ntoa(), ast_log(), AST_RTP_DTMF, ast_rtp_lookup_code(), ast_tv(), ast_tvadd(), ast_tvnow(), ast_verbose, ast_rtp::dtmfmute, errno, ast_rtp::lastdigitts, ast_rtp::lastts, LOG_ERROR, LOG_WARNING, rtp_debug_test_addr(), ast_rtp::s, ast_rtp::send_digit, ast_rtp::send_duration, ast_rtp::send_payload, ast_rtp::sending_digit, ast_rtp::seqno, ast_rtp::ssrc, and ast_rtp::them.
Referenced by mgcp_senddigit_begin(), oh323_digit_begin(), and sip_senddigit_begin().
03191 { 03192 unsigned int *rtpheader; 03193 int hdrlen = 12, res = 0, i = 0, payload = 0; 03194 char data[256]; 03195 03196 if ((digit <= '9') && (digit >= '0')) 03197 digit -= '0'; 03198 else if (digit == '*') 03199 digit = 10; 03200 else if (digit == '#') 03201 digit = 11; 03202 else if ((digit >= 'A') && (digit <= 'D')) 03203 digit = digit - 'A' + 12; 03204 else if ((digit >= 'a') && (digit <= 'd')) 03205 digit = digit - 'a' + 12; 03206 else { 03207 ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit); 03208 return 0; 03209 } 03210 03211 /* If we have no peer, return immediately */ 03212 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 03213 return 0; 03214 03215 payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF); 03216 03217 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 03218 rtp->send_duration = 160; 03219 rtp->lastdigitts = rtp->lastts + rtp->send_duration; 03220 03221 /* Get a pointer to the header */ 03222 rtpheader = (unsigned int *)data; 03223 rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno)); 03224 rtpheader[1] = htonl(rtp->lastdigitts); 03225 rtpheader[2] = htonl(rtp->ssrc); 03226 03227 for (i = 0; i < 2; i++) { 03228 rtpheader[3] = htonl((digit << 24) | (0xa << 16) | (rtp->send_duration)); 03229 res = sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockaddr *) &rtp->them, sizeof(rtp->them)); 03230 if (res < 0) 03231 ast_log(LOG_ERROR, "RTP Transmission error to %s:%u: %s\n", 03232 ast_inet_ntoa(rtp->them.sin_addr), 03233 ntohs(rtp->them.sin_port), strerror(errno)); 03234 if (rtp_debug_test_addr(&rtp->them)) 03235 ast_verbose("Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 03236 ast_inet_ntoa(rtp->them.sin_addr), 03237 ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastdigitts, res - hdrlen); 03238 /* Increment sequence number */ 03239 rtp->seqno++; 03240 /* Increment duration */ 03241 rtp->send_duration += 160; 03242 /* Clear marker bit and set seqno */ 03243 rtpheader[0] = htonl((2 << 30) | (payload << 16) | (rtp->seqno)); 03244 } 03245 03246 /* Since we received a begin, we can safely store the digit and disable any compensation */ 03247 rtp->sending_digit = 1; 03248 rtp->send_digit = digit; 03249 rtp->send_payload = payload; 03250 03251 return 0; 03252 }
| int ast_rtp_senddigit_end | ( | struct ast_rtp * | rtp, | |
| char | digit | |||
| ) |
Send end packets for DTMF.
Definition at line 3292 of file rtp.c.
References ast_inet_ntoa(), ast_log(), ast_tv(), ast_tvadd(), ast_tvnow(), ast_verbose, ast_rtp::dtmfmute, errno, ast_rtp::lastdigitts, ast_rtp::lastts, LOG_ERROR, LOG_WARNING, rtp_debug_test_addr(), ast_rtp::s, ast_rtp::send_digit, ast_rtp::send_duration, ast_rtp::send_payload, ast_rtp::sending_digit, ast_rtp::seqno, ast_rtp::ssrc, and ast_rtp::them.
Referenced by mgcp_senddigit_end(), oh323_digit_end(), and sip_senddigit_end().
03293 { 03294 unsigned int *rtpheader; 03295 int hdrlen = 12, res = 0, i = 0; 03296 char data[256]; 03297 03298 /* If no address, then bail out */ 03299 if (!rtp->them.sin_addr.s_addr || !rtp->them.sin_port) 03300 return 0; 03301 03302 if ((digit <= '9') && (digit >= '0')) 03303 digit -= '0'; 03304 else if (digit == '*') 03305 digit = 10; 03306 else if (digit == '#') 03307 digit = 11; 03308 else if ((digit >= 'A') && (digit <= 'D')) 03309 digit = digit - 'A' + 12; 03310 else if ((digit >= 'a') && (digit <= 'd')) 03311 digit = digit - 'a' + 12; 03312 else { 03313 ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit); 03314 return 0; 03315 } 03316 03317 rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000)); 03318 03319 rtpheader = (unsigned int *)data; 03320 rtpheader[1] = htonl(rtp->lastdigitts); 03321 rtpheader[2] = htonl(rtp->ssrc); 03322 rtpheader[3] = htonl((digit << 24) | (0xa << 16) | (rtp->send_duration)); 03323 /* Set end bit */ 03324 rtpheader[3] |= htonl((1 << 23)); 03325 03326 /* Send 3 termination packets */ 03327 for (i = 0; i < 3; i++) { 03328 rtpheader[0] = htonl((2 << 30) | (rtp->send_payload << 16) | (rtp->seqno)); 03329 res = sendto(rtp->s, (void *) rtpheader, hdrlen + 4, 0, (struct sockaddr *) &rtp->them, sizeof(rtp->them)); 03330 rtp->seqno++; 03331 if (res < 0) 03332 ast_log(LOG_ERROR, "RTP Transmission error to %s:%d: %s\n", 03333 ast_inet_ntoa(rtp->them.sin_addr), 03334 ntohs(rtp->them.sin_port), strerror(errno)); 03335 if (rtp_debug_test_addr(&rtp->them)) 03336 ast_verbose("Sent RTP DTMF packet to %s:%u (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n", 03337 ast_inet_ntoa(rtp->them.sin_addr), 03338 ntohs(rtp->them.sin_port), rtp->send_payload, rtp->seqno, rtp->lastdigitts, res - hdrlen); 03339 } 03340 rtp->lastts += rtp->send_duration; 03341 rtp->sending_digit = 0; 03342 rtp->send_digit = 0; 03343 03344 return res; 03345 }
| void ast_rtp_set_alt_peer | ( | struct ast_rtp * | rtp, | |
| struct sockaddr_in * | alt | |||
| ) |
set potential alternate source for RTP media
| rtp | The RTP structure we wish to set up an alternate host/port on | |
| alt | The address information for the alternate media source |
| void |
Definition at line 2720 of file rtp.c.
References ast_rtcp::altthem, ast_rtp::altthem, and ast_rtp::rtcp.
Referenced by handle_request_invite().
02721 { 02722 rtp->altthem.sin_port = alt->sin_port; 02723 rtp->altthem.sin_addr = alt->sin_addr; 02724 if (rtp->rtcp) { 02725 rtp->rtcp->altthem.sin_port = htons(ntohs(alt->sin_port) + 1); 02726 rtp->rtcp->altthem.sin_addr = alt->sin_addr; 02727 } 02728 }
| void ast_rtp_set_callback | ( | struct ast_rtp * | rtp, | |
| ast_rtp_callback | callback | |||
| ) |
Definition at line 797 of file rtp.c.
References ast_rtp::callback.
Referenced by start_rtp().
00798 { 00799 rtp->callback = callback; 00800 }
| 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.
Definition at line 2279 of file rtp.c.
References ast_rtp::current_RTP_PT, MAX_RTP_PT, rtp_bridge_lock(), and rtp_bridge_unlock().
Referenced by gtalk_is_answered(), gtalk_newcall(), jingle_newcall(), and process_sdp().
02280 { 02281 if (pt < 0 || pt >= MAX_RTP_PT || static_RTP_PT[pt].code == 0) 02282 return; /* bogus payload type */ 02283 02284 rtp_bridge_lock(rtp); 02285 rtp->current_RTP_PT[pt] = static_RTP_PT[pt]; 02286 rtp_bridge_unlock(rtp); 02287 }
| void ast_rtp_set_peer | ( | struct ast_rtp * | rtp, | |
| struct sockaddr_in * | them | |||
| ) |
Definition at line 2705 of file rtp.c.
References ast_rtp::rtcp, ast_rtp::rxseqno, STRICT_RTP_LEARN, ast_rtp::strict_rtp_state, ast_rtcp::them, and ast_rtp::them.
Referenced by handle_open_receive_channel_ack_message(), process_sdp(), setup_rtp_connection(), and start_rtp().
02706 { 02707 rtp->them.sin_port = them->sin_port; 02708 rtp->them.sin_addr = them->sin_addr; 02709 if (rtp->rtcp) { 02710 int h = ntohs(them->sin_port); 02711 rtp->rtcp->them.sin_port = htons(h + 1); 02712 rtp->rtcp->them.sin_addr = them->sin_addr; 02713 } 02714 rtp->rxseqno = 0; 02715 /* If strict RTP protection is enabled switch back to the learn state so we don't drop packets from above */ 02716 if (strictrtp) 02717 rtp->strict_rtp_state = STRICT_RTP_LEARN; 02718 }
| void ast_rtp_set_rtpholdtimeout | ( | struct ast_rtp * | rtp, | |
| int | timeout | |||
| ) |
Set rtp hold timeout.
Definition at line 759 of file rtp.c.
References ast_rtp::rtpholdtimeout.
Referenced by check_rtp_timeout(), create_addr_from_peer(), and sip_alloc().
00760 { 00761 rtp->rtpholdtimeout = timeout; 00762 }
| void ast_rtp_set_rtpkeepalive | ( | struct ast_rtp * | rtp, | |
| int | period | |||
| ) |
set RTP keepalive interval
Definition at line 765 of file rtp.c.
References ast_rtp::rtpkeepalive.
Referenced by create_addr_from_peer(), and sip_alloc().
00766 { 00767 rtp->rtpkeepalive = period; 00768 }
| int ast_rtp_set_rtpmap_type | ( | struct ast_rtp * | rtp, | |
| int | pt, | |||
| char * | mimeType, | |||
| char * | mimeSubtype, | |||
| enum ast_rtp_options | options | |||
| ) |
Set payload type to a known MIME media type for a codec.
| rtp | RTP structure to modify | |
| pt | Payload type entry to modify | |
| mimeType | top-level MIME type of media stream (typically "audio", "video", "text", etc.) | |
| mimeSubtype | MIME subtype of media stream (typically a codec name) | |
| options | Zero or more flags from the ast_rtp_options enum |
| 0 | on success | |
| -1 | if the payload type is out of range | |
| -2 | if the mimeType/mimeSubtype combination was not found |
Definition at line 2355 of file rtp.c.
References ast_rtp_set_rtpmap_type_rate().
Referenced by __oh323_rtp_create(), gtalk_is_answered(), gtalk_newcall(), jingle_newcall(), process_sdp(), process_sdp_a_text(), set_dtmf_payload(), and setup_rtp_connection().
02358 { 02359 return ast_rtp_set_rtpmap_type_rate(rtp, pt, mimeType, mimeSubtype, options, 0); 02360 }
| int ast_rtp_set_rtpmap_type_rate | ( | struct ast_rtp * | rtp, | |
| int | pt, | |||
| char * | mimeType, | |||
| char * | mimeSubtype, | |||
| enum ast_rtp_options | options, | |||
| unsigned int | sample_rate | |||
| ) |
Set payload type to a known MIME media type for a codec with a specific sample rate.
| rtp | RTP structure to modify | |
| pt | Payload type entry to modify | |
| mimeType | top-level MIME type of media stream (typically "audio", "video", "text", etc.) | |
| mimeSubtype | MIME subtype of media stream (typically a codec name) | |
| options | Zero or more flags from the ast_rtp_options enum | |
| sample_rate | The sample rate of the media stream |
| 0 | on success | |
| -1 | if the payload type is out of range | |
| -2 | if the mimeType/mimeSubtype combination was not found |
Definition at line 2306 of file rtp.c.
References ARRAY_LEN, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_RTP_OPT_G726_NONSTANDARD, rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, mimeTypes, mimeType::payloadType, rtp_bridge_lock(), rtp_bridge_unlock(), mimeType::sample_rate, mimeType::subtype, and mimeType::type.
Referenced by ast_rtp_set_rtpmap_type(), process_sdp_a_audio(), and process_sdp_a_video().
02310 { 02311 unsigned int i; 02312 int found = 0; 02313 02314 if (pt < 0 || pt >= MAX_RTP_PT) 02315 return -1; /* bogus payload type */ 02316 02317 rtp_bridge_lock(rtp); 02318 02319 for (i = 0; i < ARRAY_LEN(mimeTypes); ++i) { 02320 const struct mimeType *t = &mimeTypes[i]; 02321 02322 if (strcasecmp(mimeSubtype, t->subtype)) { 02323 continue; 02324 } 02325 02326 if (strcasecmp(mimeType, t->type)) { 02327 continue; 02328 } 02329 02330 /* if both sample rates have been supplied, and they don't match, 02331 then this not a match; if one has not been supplied, then the 02332 rates are not compared */ 02333 if (sample_rate && t->sample_rate && 02334 (sample_rate != t->sample_rate)) { 02335 continue; 02336 } 02337 02338 found = 1; 02339 rtp->current_RTP_PT[pt] = t->payloadType; 02340 02341 if ((t->payloadType.code == AST_FORMAT_G726) && 02342 t->payloadType.isAstFormat && 02343 (options & AST_RTP_OPT_G726_NONSTANDARD)) { 02344 rtp->current_RTP_PT[pt].code = AST_FORMAT_G726_AAL2; 02345 } 02346 02347 break; 02348 } 02349 02350 rtp_bridge_unlock(rtp); 02351 02352 return (found ? 0 : -2); 02353 }
| void ast_rtp_set_rtptimeout | ( | struct ast_rtp * | rtp, | |
| int | timeout | |||
| ) |
Set rtp timeout.
Definition at line 753 of file rtp.c.
References ast_rtp::rtptimeout.
Referenced by check_rtp_timeout(), create_addr_from_peer(), and sip_alloc().
00754 { 00755 rtp->rtptimeout = timeout; 00756 }
| void ast_rtp_set_rtptimers_onhold | ( | struct ast_rtp * | rtp | ) |
Definition at line 746 of file rtp.c.
References ast_rtp::rtpholdtimeout, and ast_rtp::rtptimeout.
Referenced by handle_response_invite().
00747 { 00748 rtp->rtptimeout = (-1) * rtp->rtptimeout; 00749 rtp->rtpholdtimeout = (-1) * rtp->rtpholdtimeout; 00750 }
| void ast_rtp_set_vars | ( | struct ast_channel * | chan, | |
| struct ast_rtp * | rtp | |||
| ) |
Set RTPAUDIOQOS(...) variables on a channel when it is being hung up.
Definition at line 2884 of file rtp.c.
References ast_bridged_channel(), ast_rtp_get_quality(), ast_channel::bridge, pbx_builtin_setvar_helper(), RTPQOS_JITTER, RTPQOS_LOSS, RTPQOS_RTT, and RTPQOS_SUMMARY.
Referenced by handle_request_bye(), and sip_hangup().
02884 { 02885 char *audioqos; 02886 char *audioqos_jitter; 02887 char *audioqos_loss; 02888 char *audioqos_rtt; 02889 struct ast_channel *bridge; 02890 02891 if (!rtp || !chan) 02892 return; 02893 02894 bridge = ast_bridged_channel(chan); 02895 02896 audioqos = ast_rtp_get_quality(rtp, NULL, RTPQOS_SUMMARY); 02897 audioqos_jitter = ast_rtp_get_quality(rtp, NULL, RTPQOS_JITTER); 02898 audioqos_loss = ast_rtp_get_quality(rtp, NULL, RTPQOS_LOSS); 02899 audioqos_rtt = ast_rtp_get_quality(rtp, NULL, RTPQOS_RTT); 02900 02901 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOS", audioqos); 02902 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSJITTER", audioqos_jitter); 02903 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSLOSS", audioqos_loss); 02904 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSRTT", audioqos_rtt); 02905 02906 if (!bridge) 02907 return; 02908 02909 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", audioqos); 02910 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", audioqos_jitter); 02911 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", audioqos_loss); 02912 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", audioqos_rtt); 02913 }
| void ast_rtp_setdtmf | ( | struct ast_rtp * | rtp, | |
| int | dtmf | |||
| ) |
Indicate whether this RTP session is carrying DTMF or not.
Definition at line 812 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().
00813 { 00814 ast_set2_flag(rtp, dtmf ? 1 : 0, FLAG_HAS_DTMF); 00815 }
| void ast_rtp_setdtmfcompensate | ( | struct ast_rtp * | rtp, | |
| int | compensate | |||
| ) |
Compensate for devices that send RFC2833 packets all at once.
Definition at line 817 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().
00818 { 00819 ast_set2_flag(rtp, compensate ? 1 : 0, FLAG_DTMF_COMPENSATE); 00820 }
| void ast_rtp_setnat | ( | struct ast_rtp * | rtp, | |
| int | nat | |||
| ) |
Definition at line 802 of file rtp.c.
References ast_rtp::nat.
Referenced by __oh323_rtp_create(), do_setnat(), oh323_rtp_read(), and start_rtp().
| int ast_rtp_setqos | ( | struct ast_rtp * | rtp, | |
| int | tos, | |||
| int | cos, | |||
| char * | desc | |||
| ) |
Definition at line 2681 of file rtp.c.
References ast_netsock_set_qos(), and ast_rtp::s.
Referenced by __oh323_rtp_create(), sip_alloc(), and start_rtp().
02682 { 02683 return ast_netsock_set_qos(rtp->s, type_of_service, class_of_service, desc); 02684 }
| void ast_rtp_setstun | ( | struct ast_rtp * | rtp, | |
| int | stun_enable | |||
| ) |
Enable STUN capability.
Definition at line 822 of file rtp.c.
References ast_set2_flag, and FLAG_HAS_STUN.
Referenced by gtalk_new().
00823 { 00824 ast_set2_flag(rtp, stun_enable ? 1 : 0, FLAG_HAS_STUN); 00825 }
| void ast_rtp_stop | ( | struct ast_rtp * | rtp | ) |
Stop RTP session, do not destroy structure
Definition at line 2759 of file rtp.c.
References ast_clear_flag, AST_SCHED_DEL, FLAG_P2P_SENT_MARK, free, ast_rtp::red, ast_rtp::rtcp, ast_rtp::sched, rtp_red::schedid, ast_rtcp::schedid, ast_rtcp::them, and ast_rtp::them.
Referenced by process_sdp(), setup_rtp_connection(), and stop_media_flows().
02760 { 02761 if (rtp->rtcp) { 02762 AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid); 02763 } 02764 if (rtp->red) { 02765 AST_SCHED_DEL(rtp->sched, rtp->red->schedid); 02766 free(rtp->red); 02767 rtp->red = NULL; 02768 } 02769 02770 memset(&rtp->them.sin_addr, 0, sizeof(rtp->them.sin_addr)); 02771 memset(&rtp->them.sin_port, 0, sizeof(rtp->them.sin_port)); 02772 if (rtp->rtcp) { 02773 memset(&rtp->rtcp->them.sin_addr, 0, sizeof(rtp->rtcp->them.sin_addr)); 02774 memset(&rtp->rtcp->them.sin_port, 0, sizeof(rtp->rtcp->them.sin_port)); 02775 } 02776 02777 ast_clear_flag(rtp, FLAG_P2P_SENT_MARK); 02778 }
| void ast_rtp_stun_request | ( | struct ast_rtp * | rtp, | |
| struct sockaddr_in * | suggestion, | |||
| const char * | username | |||
| ) |
Send STUN request for an RTP socket Deprecated, this is just a wrapper for ast_rtp_stun_request().
Definition at line 701 of file rtp.c.
References ast_stun_request(), and ast_rtp::s.
Referenced by gtalk_update_stun(), and jingle_update_stun().
00702 { 00703 ast_stun_request(rtp->s, suggestion, username, NULL); 00704 }
| void ast_rtp_unset_m_type | ( | struct ast_rtp * | rtp, | |
| int | pt | |||
| ) |
clear payload type
Definition at line 2291 of file rtp.c.
References rtpPayloadType::code, ast_rtp::current_RTP_PT, rtpPayloadType::isAstFormat, MAX_RTP_PT, rtp_bridge_lock(), and rtp_bridge_unlock().
Referenced by process_sdp_a_audio(), and process_sdp_a_video().
02292 { 02293 if (pt < 0 || pt >= MAX_RTP_PT) 02294 return; /* bogus payload type */ 02295 02296 rtp_bridge_lock(rtp); 02297 rtp->current_RTP_PT[pt].isAstFormat = 0; 02298 rtp->current_RTP_PT[pt].code = 0; 02299 rtp_bridge_unlock(rtp); 02300 }
Definition at line 3839 of file rtp.c.
References ast_codec_pref_getsize(), ast_debug, AST_FORMAT_G723_1, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, AST_FORMAT_SPEEX, AST_FRAME_TEXT, 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_WARNING, ast_frame::offset, ast_rtp::pref, ast_frame::ptr, ast_rtp::red, red_t140_to_red(), ast_rtp::smoother, ast_frame::subclass, and ast_rtp::them.
Referenced by gtalk_write(), jingle_write(), mgcp_write(), oh323_write(), red_write(), sip_write(), skinny_write(), and unistim_write().
03840 { 03841 struct ast_frame *f; 03842 int codec; 03843 int hdrlen = 12; 03844 int subclass; 03845 03846 03847 /* If we have no peer, return immediately */ 03848 if (!rtp->them.sin_addr.s_addr) 03849 return 0; 03850 03851 /* If there is no data length, return immediately */ 03852 if (!_f->datalen && !rtp->red) 03853 return 0; 03854 03855 /* Make sure we have enough space for RTP header */ 03856 if ((_f->frametype != AST_FRAME_VOICE) && (_f->frametype != AST_FRAME_VIDEO) && (_f->frametype != AST_FRAME_TEXT)) { 03857 ast_log(LOG_WARNING, "RTP can only send voice, video and text\n"); 03858 return -1; 03859 } 03860 03861 if (rtp->red) { 03862 /* return 0; */ 03863 /* no primary data or generations to send */ 03864 if ((_f = red_t140_to_red(rtp->red)) == NULL) 03865 return 0; 03866 } 03867 03868 /* The bottom bit of a video subclass contains the marker bit */ 03869 subclass = _f->subclass; 03870 if (_f->frametype == AST_FRAME_VIDEO) 03871 subclass &= ~0x1; 03872 03873 codec = ast_rtp_lookup_code(rtp, 1, subclass); 03874 if (codec < 0) { 03875 ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(_f->subclass)); 03876 return -1; 03877 } 03878 03879 if (rtp->lasttxformat != subclass) { 03880 /* New format, reset the smoother */ 03881 ast_debug(1, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass)); 03882 rtp->lasttxformat = subclass; 03883 if (rtp->smoother) 03884 ast_smoother_free(rtp->smoother); 03885 rtp->smoother = NULL; 03886 } 03887 03888 if (!rtp->smoother) { 03889 struct ast_format_list fmt = ast_codec_pref_getsize(&rtp->pref, subclass); 03890 03891 switch (subclass) { 03892 case AST_FORMAT_SPEEX: 03893 case AST_FORMAT_G723_1: 03894 case AST_FORMAT_SIREN7: 03895 case AST_FORMAT_SIREN14: 03896 /* these are all frame-based codecs and cannot be safely run through 03897 a smoother */ 03898 break; 03899 default: 03900 if (fmt.inc_ms) { /* if codec parameters is set / avoid division by zero */ 03901 if (!(rtp->smoother = ast_smoother_new((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms))) { 03902 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)); 03903 return -1; 03904 } 03905 if (fmt.flags) 03906 ast_smoother_set_flags(rtp->smoother, fmt.flags); 03907 ast_debug(1, "Created smoother: format: %d ms: %d len: %d\n", subclass, fmt.cur_ms, ((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms)); 03908 } 03909 } 03910 } 03911 if (rtp->smoother) { 03912 if (ast_smoother_test_flag(rtp->smoother, AST_SMOOTHER_FLAG_BE)) { 03913 ast_smoother_feed_be(rtp->smoother, _f); 03914 } else { 03915 ast_smoother_feed(rtp->smoother, _f); 03916 } 03917 03918 while ((f = ast_smoother_read(rtp->smoother)) && (f->data.ptr)) { 03919 ast_rtp_raw_write(rtp, f, codec); 03920 } 03921 } else { 03922 /* Don't buffer outgoing frames; send them one-per-packet: */ 03923 if (_f->offset < hdrlen) 03924 f = ast_frdup(_f); /*! \bug XXX this might never be free'd. Why do we do this? */ 03925 else 03926 f = _f; 03927 if (f->data.ptr) 03928 ast_rtp_raw_write(rtp, f, codec); 03929 if (f != _f) 03930 ast_frfree(f); 03931 } 03932 03933 return 0; 03934 }
| int ast_stun_request | ( | int | s, | |
| struct sockaddr_in * | dst, | |||
| const char * | username, | |||
| struct sockaddr_in * | answer | |||
| ) |
Generic STUN request send a generic stun request to the server specified.
| s | the socket used to send the request | |
| dst | the address of the STUN server | |
| username | if non null, add the username in the request | |
| answer | if non null, the function waits for a response and puts here the externally visible address. |
| s | the socket used to send the request | |
| dst | the address of the STUN server | |
| username | if non null, add the username in the request | |
| answer | if non null, the function waits for a response and puts here the externally visible address. |
Definition at line 635 of file rtp.c.
References append_attr_string(), ast_log(), ast_select(), stun_header::ies, LOG_WARNING, stun_header::msglen, stun_header::msgtype, STUN_BINDREQ, stun_get_mapped(), stun_handle_packet(), stun_req_id(), stun_send(), and STUN_USERNAME.
Referenced by ast_rtp_stun_request(), ast_sip_ouraddrfor(), and reload_config().
00637 { 00638 struct stun_header *req; 00639 unsigned char reqdata[1024]; 00640 int reqlen, reqleft; 00641 struct stun_attr *attr; 00642 int res = 0; 00643 int retry; 00644 00645 req = (struct stun_header *)reqdata; 00646 stun_req_id(req); 00647 reqlen = 0; 00648 reqleft = sizeof(reqdata) - sizeof(struct stun_header); 00649 req->msgtype = 0; 00650 req->msglen = 0; 00651 attr = (struct stun_attr *)req->ies; 00652 if (username) 00653 append_attr_string(&attr, STUN_USERNAME, username, &reqlen, &reqleft); 00654 req->msglen = htons(reqlen); 00655 req->msgtype = htons(STUN_BINDREQ); 00656 for (retry = 0; retry < 3; retry++) { /* XXX make retries configurable */ 00657 /* send request, possibly wait for reply */ 00658 unsigned char reply_buf[1024]; 00659 fd_set rfds; 00660 struct timeval to = { 3, 0 }; /* timeout, make it configurable */ 00661 struct sockaddr_in src; 00662 socklen_t srclen; 00663 00664 res = stun_send(s, dst, req); 00665 if (res < 0) { 00666 ast_log(LOG_WARNING, "ast_stun_request send #%d failed error %d, retry\n", 00667 retry, res); 00668 continue; 00669 } 00670 if (answer == NULL) 00671 break; 00672 FD_ZERO(&rfds); 00673 FD_SET(s, &rfds); 00674 res = ast_select(s + 1, &rfds, NULL, NULL, &to); 00675 if (res <= 0) /* timeout or error */ 00676 continue; 00677 memset(&src, '\0', sizeof(src)); 00678 srclen = sizeof(src); 00679 /* XXX pass -1 in the size, because stun_handle_packet might 00680 * write past the end of the buffer. 00681 */ 00682 res = recvfrom(s, reply_buf, sizeof(reply_buf) - 1, 00683 0, (struct sockaddr *)&src, &srclen); 00684 if (res < 0) { 00685 ast_log(LOG_WARNING, "ast_stun_request recvfrom #%d failed error %d, retry\n", 00686 retry, res); 00687 continue; 00688 } 00689 memset(answer, '\0', sizeof(struct sockaddr_in)); 00690 stun_handle_packet(s, &src, reply_buf, res, 00691 stun_get_mapped, answer); 00692 res = 0; /* signal regular exit */ 00693 break; 00694 } 00695 return res; 00696 }
Buffer t.140 data.
Buffer t.140 data.
| rtp | ||
| f | frame |
Definition at line 4972 of file rtp.c.
References rtp_red::buf_data, ast_frame::data, ast_frame::datalen, ast_frame::ptr, ast_rtp::red, rtp_red::t140, and ast_frame::ts.
Referenced by sip_write().
04973 { 04974 if (f->datalen > -1) { 04975 struct rtp_red *red = rtp->red; 04976 memcpy(&red->buf_data[red->t140.datalen], f->data.ptr, f->datalen); 04977 red->t140.datalen += f->datalen; 04978 red->t140.ts = f->ts; 04979 } 04980 }
| int rtp_red_init | ( | struct ast_rtp * | rtp, | |
| int | ti, | |||
| int * | red_data_pt, | |||
| int | num_gen | |||
| ) |
Initalize t.140 redudancy.
| ti | time between each t140red frame is sent | |
| red_pt | payloadtype for RTP packet | |
| pt | payloadtype numbers for each generation including primary data | |
| num_gen | number of redundant generations, primary data excluded |
| rtp | ||
| ti | buffer t140 for ti (msecs) before sending redundant frame | |
| red_data_pt | Payloadtypes for primary- and generation-data | |
| num_gen | numbers of generations (primary generation not encounted) |
Definition at line 4933 of file rtp.c.
References ast_calloc, AST_FORMAT_T140RED, AST_FRAME_TEXT, ast_sched_add(), rtp_red::buf_data, ast_frame::data, ast_frame::datalen, ast_frame::frametype, rtp_red::hdrlen, rtp_red::num_gen, rtp_red::prev_ts, rtp_red::pt, ast_frame::ptr, ast_rtp::red, red_write(), ast_rtp::sched, rtp_red::schedid, ast_frame::subclass, rtp_red::t140, rtp_red::t140red, rtp_red::t140red_data, rtp_red::ti, and ast_frame::ts.
Referenced by process_sdp().
04934 { 04935 struct rtp_red *r; 04936 int x; 04937 04938 if (!(r = ast_calloc(1, sizeof(struct rtp_red)))) 04939 return -1; 04940 04941 r->t140.frametype = AST_FRAME_TEXT; 04942 r->t140.subclass = AST_FORMAT_T140RED; 04943 r->t140.data.ptr = &r->buf_data; 04944 04945 r->t140.ts = 0; 04946 r->t140red = r->t140; 04947 r->t140red.data.ptr = &r->t140red_data; 04948 r->t140red.datalen = 0; 04949 r->ti = ti; 04950 r->num_gen = num_gen; 04951 r->hdrlen = num_gen * 4 + 1; 04952 r->prev_ts = 0; 04953 04954 for (x = 0; x < num_gen; x++) { 04955 r->pt[x] = red_data_pt[x]; 04956 r->pt[x] |= 1 << 7; /* mark redundant generations pt */ 04957 r->t140red_data[x*4] = r->pt[x]; 04958 } 04959 r->t140red_data[x*4] = r->pt[x] = red_data_pt[x]; /* primary pt */ 04960 r->schedid = ast_sched_add(rtp->sched, ti, red_write, rtp); 04961 rtp->red = r; 04962 04963 r->t140.datalen = 0; 04964 04965 return 0; 04966 }
1.5.9