[asterisk-commits] file: branch file/media r167123 - in /team/file/media: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 2 14:37:54 CST 2009


Author: file
Date: Fri Jan  2 14:37:54 2009
New Revision: 167123

URL: http://svn.digium.com/view/asterisk?view=rev&rev=167123
Log:
Add API calls to find a media format based on name and to unreference one. This also changes reload logic so that media format reloading only adds new media formats. It is extremely complex to have it remove and modify existing media formats for the little benefit gained.

Modified:
    team/file/media/include/asterisk/media.h
    team/file/media/main/media.c

Modified: team/file/media/include/asterisk/media.h
URL: http://svn.digium.com/view/asterisk/team/file/media/include/asterisk/media.h?view=diff&rev=167123&r1=167122&r2=167123
==============================================================================
--- team/file/media/include/asterisk/media.h (original)
+++ team/file/media/include/asterisk/media.h Fri Jan  2 14:37:54 2009
@@ -97,6 +97,39 @@
  * and registers CLI commands which can be used to examine the media formats themselves.
  */
 void ast_media_load(void);
+
+/*! \brief Find a media format based on name
+ *
+ * \param name The name of the media format
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_media_format *media_format = ast_media_format_find_by_name("ulaw8 at 20");
+ * \endcode
+ *
+ * This finds a media format structure named ulaw8 at 20 and returns a pointer to it
+ * with the reference count incremented.
+ *
+ * \note Since this returns with a reference you must call ast_media_format_unref on it
+ *       to decrement the reference count.
+ */
+struct ast_media_format *ast_media_format_find_by_name(const char *name);	
+
+/*! \brief Unreference a media format
+ *
+ * \param media_format The media format structure to unreference
+ *
+ * Example usage:
+ *
+ * \code
+ * media_format = ast_media_format_unref(media_format);
+ * \endcode
+ *
+ * This decrements the reference count on the media format structure pointed to
+ * by media_format.
+ */
+struct ast_media_format *ast_media_format_unref(struct ast_media_format *media_format);	
 	
 #if defined(__cplusplus) || defined(c_plusplus)
 }

Modified: team/file/media/main/media.c
URL: http://svn.digium.com/view/asterisk/team/file/media/main/media.c?view=diff&rev=167123&r1=167122&r2=167123
==============================================================================
--- team/file/media/main/media.c (original)
+++ team/file/media/main/media.c Fri Jan  2 14:37:54 2009
@@ -69,6 +69,21 @@
 	}
 
 	return;
+}
+
+struct ast_media_format *ast_media_format_find_by_name(const char *name)
+{
+	struct ast_media_format tmp;
+
+	ast_copy_string(tmp.name, name, sizeof(tmp.name));
+
+	return ao2_find(media_formats, &tmp, OBJ_POINTER);
+}
+
+struct ast_media_format *ast_media_format_unref(struct ast_media_format *media_format)
+{
+	ao2_ref(media_format, -1);
+	return NULL;
 }
 
 /*! \brief Conversion function which takes a media format enum and turns it into a string */
@@ -248,12 +263,6 @@
 	return;
 }
 
-/*! \brief Function used for unlinking all the media formats */
-static int media_format_unlinker(void *obj, void *arg, int flags)
-{
-	return CMP_MATCH;
-}
-
 /*! \brief Function which parses and configures user defined media formats */
 static int load_config(int reload)
 {
@@ -268,20 +277,18 @@
 		return 0;
 	}
 
-	ao2_lock(media_formats);
-
-	/* For reloads we actually want to drop all of the existing media formats since they may change */
-	if (reload) {
-		ao2_callback(media_formats, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE , media_format_unlinker, NULL);
-
-		if (VERBOSITY_ATLEAST(1)) {
-			ast_verbose(VERBOSE_PREFIX_2 "Removed existing media formats\n");
-		}
-	}
-
 	while ((name = ast_category_browse(cfg, name))) {
 		const char *type = ast_variable_retrieve(cfg, name, "type");
-
+		struct ast_media_format *media_format = ast_media_format_find_by_name(name);
+
+		if (media_format) {
+			if (VERBOSITY_ATLEAST(1)) {
+				ast_verbose(VERBOSE_PREFIX_2 "Skipped media format '%s' since it is already configured\n", name);
+			}
+			ast_media_format_unref(media_format);
+			continue;
+		}
+		
 		if (!strcasecmp(type, "audio")) {
 			media_format_create(name, AST_MEDIA_FORMAT_AUDIO, ast_variable_browse(cfg, name));
 		} else if (!strcasecmp(type, "video")) {
@@ -299,8 +306,6 @@
 		}
 	}
 
-	ao2_unlock(media_formats);
-
 	if (VERBOSITY_ATLEAST(1)) {
 		ast_verbose(VERBOSE_PREFIX_2 "%d media formats configured\n", ao2_container_count(media_formats));
 	}




More information about the asterisk-commits mailing list