[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase2 r306199 - in /team/dvossel/fixthew...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Feb 3 15:31:25 CST 2011
Author: dvossel
Date: Thu Feb 3 15:31:20 2011
New Revision: 306199
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=306199
Log:
load dynamic rtp mime types for formats with attributes
Modified:
team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h
team/dvossel/fixtheworld_phase2/main/rtp_engine.c
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h?view=diff&rev=306199&r1=306198&r2=306199
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h Thu Feb 3 15:31:20 2011
@@ -1798,6 +1798,16 @@
int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy *policy);
struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance);
+/*! \brief Some formats can not have their mime type and payload number initialized
+ * until their format attribute interface is loaded. This function is called with
+ * an ast_format_id as input once one of these formats requiring attributes is loaded.*/
+int ast_rtp_engine_load_format(enum ast_format_id id);
+
+/*! \brief Formats requiring the use of a format attribute interface must have that
+ * interface registered in order for the rtp engine to handle it correctly. If an
+ * attribute interface is unloaded, this function must be called to notify the rtp_engine. */
+int ast_rtp_engine_unload_format(enum ast_format_id id);
+
/*! \brief initializes the rtp engine arrays */
int ast_rtp_engine_init(void);
#if defined(__cplusplus) || defined(c_plusplus)
Modified: team/dvossel/fixtheworld_phase2/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/rtp_engine.c?view=diff&rev=306199&r1=306198&r2=306199
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/rtp_engine.c (original)
+++ team/dvossel/fixtheworld_phase2/main/rtp_engine.c Thu Feb 3 15:31:20 2011
@@ -89,7 +89,7 @@
char *subtype;
unsigned int sample_rate;
} ast_rtp_mime_types[64];
-
+static ast_rwlock_t mime_types_lock;
static int mime_types_len = 0;
@@ -104,6 +104,7 @@
* assigned values
*/
static struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT];
+static ast_rwlock_t static_RTP_PT_lock;
int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module)
{
@@ -423,6 +424,7 @@
{
int i;
+ ast_rwlock_rdlock(&static_RTP_PT_lock);
for (i = 0; i < AST_RTP_MAX_PT; i++) {
if (static_RTP_PT[i].rtp_code || static_RTP_PT[i].asterisk_format) {
@@ -434,6 +436,7 @@
}
}
}
+ ast_rwlock_unlock(&static_RTP_PT_lock);
}
void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
@@ -455,7 +458,10 @@
void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
{
+
+ ast_rwlock_rdlock(&static_RTP_PT_lock);
if (payload < 0 || payload >= AST_RTP_MAX_PT || (!static_RTP_PT[payload].rtp_code && !static_RTP_PT[payload].asterisk_format)) {
+ ast_rwlock_unlock(&static_RTP_PT_lock);
return;
}
@@ -468,6 +474,7 @@
if (instance && instance->engine && instance->engine->payload_set) {
instance->engine->payload_set(instance, payload, codecs->payloads[payload].asterisk_format, &codecs->payloads[payload].format, codecs->payloads[payload].rtp_code);
}
+ ast_rwlock_unlock(&static_RTP_PT_lock);
}
int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
@@ -481,6 +488,7 @@
if (pt < 0 || pt >= AST_RTP_MAX_PT)
return -1; /* bogus payload type */
+ ast_rwlock_rdlock(&mime_types_lock);
for (i = 0; i < mime_types_len; ++i) {
const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[i];
@@ -513,6 +521,7 @@
break;
}
+ ast_rwlock_unlock(&mime_types_lock);
return (found ? 0 : -2);
}
@@ -552,7 +561,9 @@
ast_format_copy(&result.format, &codecs->payloads[payload].format);
if (!result.rtp_code && !result.asterisk_format) {
+ ast_rwlock_rdlock(&static_RTP_PT_lock);
result = static_RTP_PT[payload];
+ ast_rwlock_unlock(&static_RTP_PT_lock);
}
return result;
@@ -580,7 +591,7 @@
int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code)
{
int i;
-
+ int res = -1;
for (i = 0; i < AST_RTP_MAX_PT; i++) {
if (codecs->payloads[i].asterisk_format && asterisk_format && format &&
(ast_format_cmp(format, &codecs->payloads[i].format) != AST_FORMAT_CMP_NOT_EQUAL)) {
@@ -591,56 +602,71 @@
}
}
+ ast_rwlock_rdlock(&static_RTP_PT_lock);
for (i = 0; i < AST_RTP_MAX_PT; i++) {
if (static_RTP_PT[i].asterisk_format && asterisk_format && format &&
(ast_format_cmp(format, &static_RTP_PT[i].format) != AST_FORMAT_CMP_NOT_EQUAL)) {
- return i;
+ res = i;
+ break;
} else if (!static_RTP_PT[i].asterisk_format && !asterisk_format &&
(static_RTP_PT[i].rtp_code == code)) {
- return i;
- }
- }
-
- return -1;
+ res = i;
+ break;
+ }
+ }
+ ast_rwlock_unlock(&static_RTP_PT_lock);
+
+ return res;
}
const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options)
{
int i;
-
+ const char *res = "";
+
+ ast_rwlock_rdlock(&mime_types_lock);
for (i = 0; i < mime_types_len; i++) {
if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
(ast_format_cmp(format, &ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
if ((format->id == AST_FORMAT_G726_AAL2) && (options & AST_RTP_OPT_G726_NONSTANDARD)) {
- return "G726-32";
+ res = "G726-32";
+ break;
} else {
- return ast_rtp_mime_types[i].subtype;
+ res = ast_rtp_mime_types[i].subtype;
+ break;
}
} else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
ast_rtp_mime_types[i].payload_type.rtp_code == code) {
- return ast_rtp_mime_types[i].subtype;
- }
- }
-
- return "";
+ res = ast_rtp_mime_types[i].subtype;
+ break;
+ }
+ }
+ ast_rwlock_unlock(&mime_types_lock);
+
+ return res;
}
unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code)
{
unsigned int i;
-
+ unsigned int res = 0;
+
+ ast_rwlock_rdlock(&mime_types_lock);
for (i = 0; i < mime_types_len; ++i) {
if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
(ast_format_cmp(format, &ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
- return ast_rtp_mime_types[i].sample_rate;
+ res = ast_rtp_mime_types[i].sample_rate;
+ break;
} else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
ast_rtp_mime_types[i].payload_type.rtp_code == code) {
- return ast_rtp_mime_types[i].sample_rate;
- }
- }
-
- return 0;
+ res = ast_rtp_mime_types[i].sample_rate;
+ break;
+ }
+ }
+ ast_rwlock_unlock(&mime_types_lock);
+
+ return res;
}
char *ast_rtp_lookup_mime_multiple2(struct ast_str *buf, struct ast_format_cap *ast_format_capability, int rtp_capability, const int asterisk_format, enum ast_rtp_options options)
@@ -1812,6 +1838,8 @@
if (ARRAY_LEN(ast_rtp_mime_types) == mime_types_len) {
return;
}
+
+ ast_rwlock_wrlock(&mime_types_lock);
if (format) {
ast_rtp_mime_types[x].payload_type.asterisk_format = 1;
ast_format_copy(&ast_rtp_mime_types[x].payload_type.format, format);
@@ -1822,21 +1850,69 @@
ast_rtp_mime_types[x].subtype = subtype;
ast_rtp_mime_types[x].sample_rate = sample_rate;
mime_types_len++;
+ ast_rwlock_unlock(&mime_types_lock);
}
static void add_static_payload(int map, struct ast_format *format, int rtp_code)
{
+ ast_rwlock_wrlock(&static_RTP_PT_lock);
if (format) {
static_RTP_PT[map].asterisk_format = 1;
ast_format_copy(&static_RTP_PT[map].format, format);
} else {
static_RTP_PT[map].rtp_code = rtp_code;
}
+ ast_rwlock_unlock(&static_RTP_PT_lock);
+}
+
+int ast_rtp_engine_load_format(enum ast_format_id id)
+{
+/*
+ switch (id) {
+ case AST_FORMAT_SILK:
+ break;
+ default:
+ break;
+ }
+*/
+ return 0;
+}
+
+int ast_rtp_engine_unload_format(enum ast_format_id id)
+{
+ int x;
+ int y = 0;
+
+ ast_rwlock_wrlock(&static_RTP_PT_lock);
+ /* remove everything pertaining to this format id from the lists */
+ for (x = 0; x < AST_RTP_MAX_PT; x++) {
+ if (static_RTP_PT[x].format.id == id) {
+ memset(&static_RTP_PT[x], 0, sizeof(struct ast_rtp_payload_type));
+ }
+ }
+ ast_rwlock_unlock(&static_RTP_PT_lock);
+
+
+ ast_rwlock_wrlock(&mime_types_lock);
+ /* rebuild the list skipping the items matching this id */
+ for (x = 0; x < mime_types_len; x++) {
+ if (ast_rtp_mime_types[x].payload_type.format.id == id) {
+ continue;
+ }
+ ast_rtp_mime_types[y] = ast_rtp_mime_types[x];
+ y++;
+ }
+ mime_types_len = y;
+ ast_rwlock_unlock(&mime_types_lock);
+ return 0;
}
int ast_rtp_engine_init()
{
struct ast_format tmpfmt;
+
+ ast_rwlock_init(&mime_types_lock);
+ ast_rwlock_init(&static_RTP_PT_lock);
/* Define all the RTP mime types available */
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G723_1, 0), 0, "audio", "G723", 8000);
@@ -1856,9 +1932,7 @@
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX, 0), 0, "audio", "speex", 8000);
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX16, 0), 0, "audio", "speex", 16000);
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ILBC, 0), 0, "audio", "iLBC", 8000);
- /* this is the sample rate listed in the RTP profile for the G.722
- codec, *NOT* the actual sample rate of the media stream
- */
+ /* this is the sample rate listed in the RTP profile for the G.722 codec, *NOT* the actual sample rate of the media stream */
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G722, 0), 0, "audio", "G722", 8000);
set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G726_AAL2, 0), 0, "audio", "AAL2-G726-32", 8000);
set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 8000);
More information about the asterisk-commits
mailing list