Formatting fixes (bug #1951)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3359 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2004-06-29 20:10:57 +00:00
parent 9b32ff1eeb
commit 60ad539878

66
rtp.c
View File

@@ -2,10 +2,12 @@
* Asterisk -- A telephony toolkit for Linux. * Asterisk -- A telephony toolkit for Linux.
* *
* Real-time Protocol Support * Real-time Protocol Support
* Supports RTP and RTCP with Symmetric RTP support for NAT
* traversal
* *
* Copyright (C) 1999, Mark Spencer * Copyright (C) 1999, Mark Spencer
* *
* Mark Spencer <markster@linux-support.net> * Mark Spencer <markster@digium.com>
* *
* This program is free software, distributed under the terms of * This program is free software, distributed under the terms of
* the GNU General Public License * the GNU General Public License
@@ -49,9 +51,9 @@ static int dtmftimeout = 3000; /* 3000 samples */
static int rtpstart = 0; static int rtpstart = 0;
static int rtpend = 0; static int rtpend = 0;
// The value of each payload format mapping: /* The value of each payload format mapping: */
struct rtpPayloadType { struct rtpPayloadType {
int isAstFormat; // whether the following code is an AST_FORMAT int isAstFormat; /* whether the following code is an AST_FORMAT */
int code; int code;
}; };
@@ -89,8 +91,7 @@ struct ast_rtp {
void *data; void *data;
ast_rtp_callback callback; ast_rtp_callback callback;
struct rtpPayloadType current_RTP_PT[MAX_RTP_PT]; struct rtpPayloadType current_RTP_PT[MAX_RTP_PT];
// a cache for the result of rtp_lookup_code(): int rtp_lookup_code_cache_isAstFormat; /* a cache for the result of rtp_lookup_code(): */
int rtp_lookup_code_cache_isAstFormat;
int rtp_lookup_code_cache_code; int rtp_lookup_code_cache_code;
int rtp_lookup_code_cache_result; int rtp_lookup_code_cache_result;
struct ast_rtcp *rtcp; struct ast_rtcp *rtcp;
@@ -457,7 +458,7 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
#endif #endif
rtpPT = ast_rtp_lookup_pt(rtp, payloadtype); rtpPT = ast_rtp_lookup_pt(rtp, payloadtype);
if (!rtpPT.isAstFormat) { if (!rtpPT.isAstFormat) {
// This is special in-band data that's not one of our codecs /* This is special in-band data that's not one of our codecs */
if (rtpPT.code == AST_RTP_DTMF) { if (rtpPT.code == AST_RTP_DTMF) {
/* It's special -- rfc2833 process it */ /* It's special -- rfc2833 process it */
if (rtp->lasteventseqn <= seqno) { if (rtp->lasteventseqn <= seqno) {
@@ -541,7 +542,7 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
break; break;
case AST_FORMAT_SPEEX: case AST_FORMAT_SPEEX:
rtp->f.samples = 160; rtp->f.samples = 160;
// assumes that the RTP packet contained one Speex frame /* assumes that the RTP packet contained one Speex frame */
break; break;
default: default:
ast_log(LOG_NOTICE, "Unable to calculate samples for format %s\n", ast_getformatname(rtp->f.subclass)); ast_log(LOG_NOTICE, "Unable to calculate samples for format %s\n", ast_getformatname(rtp->f.subclass));
@@ -564,8 +565,8 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
return &rtp->f; return &rtp->f;
} }
// The following array defines the MIME type (and subtype) for each /* The following array defines the MIME Media type (and subtype) for each
// of our codecs, or RTP-specific data type. of our codecs, or RTP-specific data type. */
static struct { static struct {
struct rtpPayloadType payloadType; struct rtpPayloadType payloadType;
char* type; char* type;
@@ -596,18 +597,18 @@ static struct {
table for transmission */ table for transmission */
static struct rtpPayloadType static_RTP_PT[MAX_RTP_PT] = { static struct rtpPayloadType static_RTP_PT[MAX_RTP_PT] = {
[0] = {1, AST_FORMAT_ULAW}, [0] = {1, AST_FORMAT_ULAW},
[2] = {1, AST_FORMAT_G726}, // Technically this is G.721, but if Cisco can do it, so can we... [2] = {1, AST_FORMAT_G726}, /* Technically this is G.721, but if Cisco can do it, so can we... */
[3] = {1, AST_FORMAT_GSM}, [3] = {1, AST_FORMAT_GSM},
[4] = {1, AST_FORMAT_G723_1}, [4] = {1, AST_FORMAT_G723_1},
[5] = {1, AST_FORMAT_ADPCM}, // 8 kHz [5] = {1, AST_FORMAT_ADPCM}, /* 8 kHz */
[6] = {1, AST_FORMAT_ADPCM}, // 16 kHz [6] = {1, AST_FORMAT_ADPCM}, /* 16 kHz */
[7] = {1, AST_FORMAT_LPC10}, [7] = {1, AST_FORMAT_LPC10},
[8] = {1, AST_FORMAT_ALAW}, [8] = {1, AST_FORMAT_ALAW},
[10] = {1, AST_FORMAT_SLINEAR}, // 2 channels [10] = {1, AST_FORMAT_SLINEAR}, /* 2 channels */
[11] = {1, AST_FORMAT_SLINEAR}, // 1 channel [11] = {1, AST_FORMAT_SLINEAR}, /* 1 channel */
[13] = {0, AST_RTP_CN}, [13] = {0, AST_RTP_CN},
[16] = {1, AST_FORMAT_ADPCM}, // 11.025 kHz [16] = {1, AST_FORMAT_ADPCM}, /* 11.025 kHz */
[17] = {1, AST_FORMAT_ADPCM}, // 22.050 kHz [17] = {1, AST_FORMAT_ADPCM}, /* 22.050 kHz */
[18] = {1, AST_FORMAT_G729A}, [18] = {1, AST_FORMAT_G729A},
[26] = {1, AST_FORMAT_JPEG}, [26] = {1, AST_FORMAT_JPEG},
[31] = {1, AST_FORMAT_H261}, [31] = {1, AST_FORMAT_H261},
@@ -615,7 +616,7 @@ static struct rtpPayloadType static_RTP_PT[MAX_RTP_PT] = {
[97] = {1, AST_FORMAT_ILBC}, [97] = {1, AST_FORMAT_ILBC},
[101] = {0, AST_RTP_DTMF}, [101] = {0, AST_RTP_DTMF},
[110] = {1, AST_FORMAT_SPEEX}, [110] = {1, AST_FORMAT_SPEEX},
[121] = {0, AST_RTP_CISCO_DTMF}, // Must be type 121 [121] = {0, AST_RTP_CISCO_DTMF}, /* Must be type 121 */
}; };
void ast_rtp_pt_clear(struct ast_rtp* rtp) void ast_rtp_pt_clear(struct ast_rtp* rtp)
@@ -646,24 +647,24 @@ void ast_rtp_pt_default(struct ast_rtp* rtp)
rtp->rtp_lookup_code_cache_result = 0; rtp->rtp_lookup_code_cache_result = 0;
} }
// Make a note of a RTP payload type that was seen in a SDP "m=" line. /* Make a note of a RTP payload type that was seen in a SDP "m=" line. */
// By default, use the well-known value for this type (although it may /* By default, use the well-known value for this type (although it may */
// still be set to a different value by a subsequent "a=rtpmap:" line): /* still be set to a different value by a subsequent "a=rtpmap:" line): */
void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt) { void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt) {
if (pt < 0 || pt > MAX_RTP_PT) return; // bogus payload type if (pt < 0 || pt > MAX_RTP_PT) return; /* bogus payload type */
if (static_RTP_PT[pt].code != 0) { if (static_RTP_PT[pt].code != 0) {
rtp->current_RTP_PT[pt] = static_RTP_PT[pt]; rtp->current_RTP_PT[pt] = static_RTP_PT[pt];
} }
} }
// Make a note of a RTP payload type (with MIME type) that was seen in /* Make a note of a RTP payload type (with MIME type) that was seen in */
// a SDP "a=rtpmap:" line. /* a SDP "a=rtpmap:" line. */
void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt, void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
char* mimeType, char* mimeSubtype) { char* mimeType, char* mimeSubtype) {
int i; int i;
if (pt < 0 || pt > MAX_RTP_PT) return; // bogus payload type if (pt < 0 || pt > MAX_RTP_PT) return; /* bogus payload type */
for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) { for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 && if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 &&
@@ -674,8 +675,8 @@ void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
} }
} }
// Return the union of all of the codecs that were set by rtp_set...() calls /* 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 /* They're returned as two distinct sets: AST_FORMATs, and AST_RTPs */
void ast_rtp_get_current_formats(struct ast_rtp* rtp, void ast_rtp_get_current_formats(struct ast_rtp* rtp,
int* astFormats, int* nonAstFormats) { int* astFormats, int* nonAstFormats) {
int pt; int pt;
@@ -693,9 +694,10 @@ void ast_rtp_get_current_formats(struct ast_rtp* rtp,
struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt)
{ {
struct rtpPayloadType result; struct rtpPayloadType result;
if (pt < 0 || pt > MAX_RTP_PT) { if (pt < 0 || pt > MAX_RTP_PT) {
result.isAstFormat = result.code = 0; result.isAstFormat = result.code = 0;
return result; // bogus payload type return result; /* bogus payload type */
} }
/* Start with the negotiated codecs */ /* Start with the negotiated codecs */
result = rtp->current_RTP_PT[pt]; result = rtp->current_RTP_PT[pt];
@@ -705,14 +707,14 @@ struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt)
return result; return result;
} }
/* Looks up an RTP code out of our *static* outbound list */
int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) { int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) {
int pt; int pt;
/* Looks up an RTP code out of our *static* outbound list */
if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat &&
code == rtp->rtp_lookup_code_cache_code) { code == rtp->rtp_lookup_code_cache_code) {
// Use our cached mapping, to avoid the overhead of the loop below /* Use our cached mapping, to avoid the overhead of the loop below */
return rtp->rtp_lookup_code_cache_result; return rtp->rtp_lookup_code_cache_result;
} }
@@ -1046,7 +1048,7 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec
break; break;
case AST_FORMAT_SPEEX: case AST_FORMAT_SPEEX:
pred = rtp->lastts + 160; pred = rtp->lastts + 160;
// assumes that the RTP packet contains one Speex frame /* assumes that the RTP packet contains one Speex frame */
break; break;
default: default:
ast_log(LOG_WARNING, "Not sure about timestamp format for codec format %s\n", ast_getformatname(f->subclass)); ast_log(LOG_WARNING, "Not sure about timestamp format for codec format %s\n", ast_getformatname(f->subclass));
@@ -1207,12 +1209,12 @@ int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
break; break;
default: default:
ast_log(LOG_WARNING, "Not sure about sending format %s packets\n", ast_getformatname(subclass)); ast_log(LOG_WARNING, "Not sure about sending format %s packets\n", ast_getformatname(subclass));
// fall through to... /* fall through to... */
case AST_FORMAT_H261: case AST_FORMAT_H261:
case AST_FORMAT_H263: case AST_FORMAT_H263:
case AST_FORMAT_G723_1: case AST_FORMAT_G723_1:
case AST_FORMAT_SPEEX: case AST_FORMAT_SPEEX:
// Don't buffer outgoing frames; send them one-per-packet: /* Don't buffer outgoing frames; send them one-per-packet: */
if (_f->offset < hdrlen) { if (_f->offset < hdrlen) {
f = ast_frdup(_f); f = ast_frdup(_f);
} else { } else {