--- /root/svn/chan_sip.c 2005-12-22 19:02:32.000000000 +0000 +++ asterisk/channels/chan_sip.c 2005-12-22 19:21:47.000000000 +0000 @@ -124,7 +124,8 @@ #define CALLERID_UNKNOWN "Unknown" - +#define DEFAULT_MAX_CALL_BITRATE (384) +static int defaultmaxcallbitrate = DEFAULT_MAX_CALL_BITRATE; #define DEFAULT_MAXMS 2000 /* Must be faster than 2 seconds by default */ #define DEFAULT_FREQ_OK 60 * 1000 /* How often to check for the host to be up */ @@ -603,6 +604,7 @@ int peercapability; /*!< Supported peer capability */ int prefcodec; /*!< Preferred codec (outbound only) */ int noncodeccapability; + int maxcallbitrate; /*!< Maximum Call Bitrate for Video Calls */ int callingpres; /*!< Calling presentation */ int authtries; /*!< Times we've tried to authenticate */ int expiry; /*!< How long we take to expire */ @@ -739,6 +741,7 @@ int call_limit; /*!< Limit of concurrent calls */ struct ast_ha *ha; /*!< ACL setting */ struct ast_variable *chanvars; /*!< Variables to set for channel created by user */ + int maxcallbitrate; /*!< Maximum Bitrate for a video call */ }; /* Structure for SIP peer data, we place calls to peers if registered or fixed IP address (host) */ @@ -783,6 +786,7 @@ ast_group_t pickupgroup; /*!< Pickup group */ struct ast_dnsmgr_entry *dnsmgr;/*!< DNS refresh manager for peer */ struct sockaddr_in addr; /*!< IP address of peer */ + int maxcallbitrate; /*!< Maximum Bitrate for a video call */ /* Qualification */ struct sip_pvt *call; /*!< Call pointer */ @@ -1852,6 +1856,10 @@ ast_copy_flags(r, peer, SIP_FLAGS_TO_COPY); r->capability = peer->capability; + if (!ast_test_flag(r, SIP_VIDEOSUPPORT) && r->vrtp) { + ast_rtp_destroy(r->vrtp); + r->vrtp = NULL; + } r->prefs = peer->prefs; if (r->rtp) { ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(r, SIP_NAT) & SIP_NAT_ROUTE)); @@ -1899,6 +1907,7 @@ r->rtpkeepalive = peer->rtpkeepalive; if (peer->call_limit) ast_set_flag(r, SIP_CALL_LIMIT); + r->maxcallbitrate = peer->maxcallbitrate; return 0; } @@ -3038,6 +3047,8 @@ memcpy(&p->ourip, &__ourip, sizeof(p->ourip)); } + ast_copy_flags(p, &global_flags, SIP_FLAGS_TO_COPY); + p->branch = thread_safe_rand(); make_our_tag(p->tag, sizeof(p->tag)); /* Start with 101 instead of 1 */ @@ -3063,6 +3074,7 @@ p->rtptimeout = global_rtptimeout; p->rtpholdtimeout = global_rtpholdtimeout; p->rtpkeepalive = global_rtpkeepalive; + p->maxcallbitrate = defaultmaxcallbitrate; } if (useglobal_nat && sin) { @@ -3082,7 +3094,6 @@ build_callid(p->callid, sizeof(p->callid), p->ourip, p->fromdomain); else ast_copy_string(p->callid, callid, sizeof(p->callid)); - ast_copy_flags(p, &global_flags, SIP_FLAGS_TO_COPY); /* Assign default music on hold class */ strcpy(p->musicclass, global_musicclass); p->capability = global_capability; @@ -4300,6 +4311,7 @@ char o[256]; char c[256]; char t[256]; + char b[256]; char m_audio[256]; char m_video[256]; char a_audio[1024]; @@ -4370,6 +4382,8 @@ snprintf(o, sizeof(o), "o=root %d %d IN IP4 %s\r\n", p->sessionid, p->sessionversion, ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr)); snprintf(s, sizeof(s), "s=session\r\n"); snprintf(c, sizeof(c), "c=IN IP4 %s\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), dest.sin_addr)); + if (p->vrtp) + snprintf(b, sizeof(b), "b=CT:%d\r\n", p->maxcallbitrate); snprintf(t, sizeof(t), "t=0 0\r\n"); ast_build_string(&m_audio_next, &m_audio_left, "m=audio %d RTP/AVP", ntohs(dest.sin_port)); @@ -4462,6 +4476,8 @@ add_line(resp, o); add_line(resp, s); add_line(resp, c); + if (p->vrtp) + add_line(resp, b); add_line(resp, t); add_line(resp, m_audio); add_line(resp, a_audio); @@ -7038,6 +7054,11 @@ p->callingpres = user->callingpres; p->capability = user->capability; p->jointcapability = user->capability; + p->maxcallbitrate = user->maxcallbitrate; + if (!ast_test_flag(p, SIP_VIDEOSUPPORT) && p->vrtp) { + ast_rtp_destroy(p->vrtp); + p->vrtp = NULL; + } if (p->peercapability) p->jointcapability &= p->peercapability; if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_RFC2833) || (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_AUTO)) @@ -7146,6 +7167,11 @@ p->capability = peer->capability; p->prefs = peer->prefs; p->jointcapability = peer->capability; + p->maxcallbitrate = user->maxcallbitrate; + if (!ast_test_flag(p, SIP_VIDEOSUPPORT) && p->vrtp) { + ast_rtp_destroy(p->vrtp); + p->vrtp = NULL; + } if (p->peercapability) p->jointcapability &= p->peercapability; if ((ast_test_flag(p, SIP_DTMF) == SIP_DTMF_RFC2833) || (ast_test_flag(p, SIP_DTMF) == SIP_DTMF_AUTO)) @@ -7903,6 +7929,7 @@ ast_cli(fd, " Call limit : %d\n", peer->call_limit); ast_cli(fd, " Dynamic : %s\n", (ast_test_flag(peer, SIP_DYNAMIC)?"Yes":"No")); ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "")); + ast_cli(fd, " MaxCallBR : %dkbps\n", peer->maxcallbitrate); ast_cli(fd, " Expire : %d\n", peer->expire); ast_cli(fd, " Insecure : %s\n", insecure2str(ast_test_flag(peer, SIP_INSECURE_PORT), ast_test_flag(peer, SIP_INSECURE_INVITE))); ast_cli(fd, " Nat : %s\n", nat2str(ast_test_flag(peer, SIP_NAT))); @@ -7978,6 +8005,7 @@ ast_cli(fd, "VoiceMailbox: %s\r\n", peer->mailbox); ast_cli(fd, "LastMsgsSent: %d\r\n", peer->lastmsgssent); ast_cli(fd, "Call limit: %d\r\n", peer->call_limit); + ast_cli(fd, "MaxCallBR: %dkbps\r\n", peer->maxcallbitrate); ast_cli(fd, "Dynamic: %s\r\n", (ast_test_flag(peer, SIP_DYNAMIC)?"Y":"N")); ast_cli(fd, "Callerid: %s\r\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "")); ast_cli(fd, "RegExpire: %ld seconds\r\n", ast_sched_when(sched,peer->expire)); @@ -8178,6 +8206,7 @@ ast_cli(fd, " Outbound reg. timeout: %d secs\n", global_reg_timeout); ast_cli(fd, " Outbound reg. attempts: %d\n", global_regattempts_max); ast_cli(fd, " Notify ringing state: %s\n", global_notifyringing ? "Yes" : "No"); + ast_cli(fd, " Max Call Bitrate: %dkbps\r\n", defaultmaxcallbitrate); ast_cli(fd, "\nDefault Settings:\n"); ast_cli(fd, "-----------------\n"); ast_cli(fd, " Context: %s\n", default_context); @@ -11869,6 +11898,7 @@ ast_copy_flags(user, &global_flags, SIP_FLAGS_TO_COPY); user->capability = global_capability; user->prefs = prefs; + user->maxcallbitrate = defaultmaxcallbitrate; /* set default context */ strcpy(user->context, default_context); strcpy(user->language, default_language); @@ -11929,7 +11959,11 @@ user->callingpres = ast_parse_caller_presentation(v->value); if (user->callingpres == -1) user->callingpres = atoi(v->value); - } + } else if (!strcasecmp(v->name, "maxcallbitrate")) { + user->maxcallbitrate = atoi(v->value); + if (user->maxcallbitrate < 0) + user->maxcallbitrate = defaultmaxcallbitrate; + } } ast_copy_flags(user, &userflags, mask.flags); ast_free_ha(oldha); @@ -11960,6 +11994,7 @@ peer->addr.sin_port = htons(DEFAULT_SIP_PORT); peer->addr.sin_family = AF_INET; peer->capability = global_capability; + peer->maxcallbitrate = defaultmaxcallbitrate; peer->rtptimeout = global_rtptimeout; peer->rtpholdtimeout = global_rtpholdtimeout; peer->rtpkeepalive = global_rtpkeepalive; @@ -12055,6 +12090,7 @@ peer->capability = global_capability; peer->rtptimeout = global_rtptimeout; peer->rtpholdtimeout = global_rtpholdtimeout; + peer->maxcallbitrate = defaultmaxcallbitrate; while(v) { if (handle_common_options(&peerflags, &mask, v)) { v = v->next; @@ -12213,6 +12249,10 @@ ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno); peer->maxms = 0; } + } else if (!strcasecmp(v->name, "maxcallbitrate")) { + peer->maxcallbitrate = atoi(v->value); + if (peer->maxcallbitrate < 0) + peer->maxcallbitrate = defaultmaxcallbitrate; } /* else if (strcasecmp(v->name,"type")) * ast_log(LOG_WARNING, "Ignoring %s\n", v->name); @@ -12318,6 +12358,7 @@ tos = 0; expiry = DEFAULT_EXPIRY; global_allowguest = 1; + defaultmaxcallbitrate = DEFAULT_MAX_CALL_BITRATE; /* Read the [general] config section of sip.conf (or from realtime config) */ for (v = ast_variable_browse(cfg, "general"); v; v = v->next) { @@ -12502,6 +12543,11 @@ } } else if (!strcasecmp(v->name, "callevents")) { callevents = ast_true(v->value); + } else if (!strcasecmp(v->name, "maxcallbitrate")) { + defaultmaxcallbitrate = atoi(v->value); + if (defaultmaxcallbitrate < 0) + defaultmaxcallbitrate = DEFAULT_MAX_CALL_BITRATE; + ast_log(LOG_NOTICE,"Default Video Bitrate set to %dkbps\n", defaultmaxcallbitrate); } }