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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jan 5 21:24:22 CST 2009


Author: file
Date: Mon Jan  5 21:24:21 2009
New Revision: 167244

URL: http://svn.digium.com/view/asterisk?view=rev&rev=167244
Log:
Add an API call to find a media format based on parameters.

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=167244&r1=167243&r2=167244
==============================================================================
--- team/file/media/include/asterisk/media.h (original)
+++ team/file/media/include/asterisk/media.h Mon Jan  5 21:24:21 2009
@@ -82,7 +82,7 @@
 		struct ast_media_format_audio audio;                     /*!< Audio specific information */
 		struct ast_media_format_video video;                     /*!< Video specific information */
 		struct ast_media_format_telephone_event telephone_event; /*!< Telephone event specific information */
-	};
+	} parameters;
 };
 
 /*!
@@ -125,6 +125,24 @@
  */
 struct ast_media_format *ast_media_format_find_by_name(const char *name);	
 
+/*! \brief Find a media format based on parameters
+ *
+ * \param media_format_parameters Media format structure containing parameters
+ *
+ * Example usage:
+ *
+ * \code
+ * struct ast_media_format *media_format = ast_media_format_find_by_parameters(&media_format_parameters);
+ * \endcode
+ *
+ * This finds a media format structure based on the parameters present in the media_format_parameters
+ * structure. The reference count of the returned media format structure is 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_parameters(struct ast_media_format *media_format_parameters);	
+	
 /*! \brief Reference a media format
  *
  * \param media_format The media format structure to reference

Modified: team/file/media/main/media.c
URL: http://svn.digium.com/view/asterisk/team/file/media/main/media.c?view=diff&rev=167244&r1=167243&r2=167244
==============================================================================
--- team/file/media/main/media.c (original)
+++ team/file/media/main/media.c Mon Jan  5 21:24:21 2009
@@ -54,11 +54,41 @@
 	return ast_str_hash(media_format->name);
 }
 
-/*! \brief Comparison function used for media formats */
+/*! \brief Comparison function used for media format finding by name */
 static int media_format_cmp_cb(void *obj, void *arg, int flags)
 {
 	const struct ast_media_format *format0 = obj, *format1 = arg;
 	return !strcasecmp(format0->name, format1->name) ? CMP_MATCH | CMP_STOP : 0;
+}
+
+/*! \brief Comparison function used for media format finding by parameters */
+static int media_format_parameters_cmp_cb(void *obj, void *arg, int flags)
+{
+	const struct ast_media_format *format0 = obj, *format1 = arg;
+
+	if (format0->type != format1->type) {
+		return 0;
+	}
+
+	if (strcasecmp(format0->codec, format1->codec)) {
+		return 0;
+	}
+
+	if (format0->channels != format1->channels) {
+		return 0;
+	}
+
+	if (format0->type == AST_MEDIA_FORMAT_AUDIO) {
+		if (format0->parameters.audio.sample_rate != format1->parameters.audio.sample_rate) {
+			return 0;
+		}
+	} else if (format0->type == AST_MEDIA_FORMAT_TELEPHONE_EVENT) {
+		if (format0->parameters.telephone_event.sample_rate != format1->parameters.telephone_event.sample_rate) {
+			return 0;
+		}
+	}
+	
+	return CMP_MATCH | CMP_STOP;
 }
 
 /*! \brief Destroy function used for media formats */
@@ -81,6 +111,11 @@
 	ast_copy_string(tmp.name, name, sizeof(tmp.name));
 
 	return ao2_find(media_formats, &tmp, OBJ_POINTER);
+}
+
+struct ast_media_format *ast_media_format_find_by_parameters(struct ast_media_format *media_format_parameters)
+{
+	return ao2_callback(media_formats, 0, media_format_parameters_cmp_cb, media_format_parameters);
 }
 
 struct ast_media_format *ast_media_format_ref(struct ast_media_format *media_format)
@@ -216,29 +251,29 @@
 {
 	for (; v; v = v->next) {
 		CV_START(v->name, v->value);
-		CV_F("sample_rate", media_format->audio.sample_rate = atoi(__val));
-		CV_F("frame_size", media_format->audio.frame_size = atoi(__val));
-		CV_F("maximum_frame_size", media_format->audio.maximum_frame_size = atoi(__val));
-		CV_F("minimum_frame_size", media_format->audio.minimum_frame_size = atoi(__val));
+		CV_F("sample_rate", media_format->parameters.audio.sample_rate = atoi(__val));
+		CV_F("frame_size", media_format->parameters.audio.frame_size = atoi(__val));
+		CV_F("maximum_frame_size", media_format->parameters.audio.maximum_frame_size = atoi(__val));
+		CV_F("minimum_frame_size", media_format->parameters.audio.minimum_frame_size = atoi(__val));
 		CV_END;
 	}
 
-	if (!media_format->audio.sample_rate || !media_format->audio.frame_size) {
+	if (!media_format->parameters.audio.sample_rate || !media_format->parameters.audio.frame_size) {
 		ast_log(LOG_ERROR, "Audio media format '%s' did not pass configuration check.\n", media_format->name);
 		return -1;
 	}
 
-	if (!media_format->audio.maximum_frame_size) {
-		media_format->audio.maximum_frame_size = media_format->audio.frame_size;
-	}
-
-	if (!media_format->audio.minimum_frame_size) {
-		media_format->audio.minimum_frame_size = media_format->audio.frame_size;
+	if (!media_format->parameters.audio.maximum_frame_size) {
+		media_format->parameters.audio.maximum_frame_size = media_format->parameters.audio.frame_size;
+	}
+
+	if (!media_format->parameters.audio.minimum_frame_size) {
+		media_format->parameters.audio.minimum_frame_size = media_format->parameters.audio.frame_size;
 	}
 
 	if (VERBOSITY_ATLEAST(2)) {
 		ast_verbose(VERBOSE_PREFIX_3 "Configured audio media format '%s' with codec '%s', sample rate '%d', and frame size '%d'\n", 
-			    media_format->name, media_format->codec, media_format->audio.sample_rate, media_format->audio.frame_size);
+			    media_format->name, media_format->codec, media_format->parameters.audio.sample_rate, media_format->parameters.audio.frame_size);
 	}
 
 	return 0;
@@ -249,8 +284,8 @@
 {
 	for (; v; v = v->next) {
 		CV_START(v->name, v->value);
-		CV_F("maximum_bandwidth", media_format->video.maximum_bandwidth = atoi(__val));
-		CV_F("maximum_bitrate", media_format->video.maximum_bitrate = atoi(__val));
+		CV_F("maximum_bandwidth", media_format->parameters.video.maximum_bandwidth = atoi(__val));
+		CV_F("maximum_bitrate", media_format->parameters.video.maximum_bitrate = atoi(__val));
 		CV_END;
 	}
 
@@ -296,11 +331,11 @@
 {
 	for (; v; v = v->next) {
 		CV_START(v->name, v->value);
-		CV_F("sample_rate", media_format->telephone_event.sample_rate = atoi(__val));
+		CV_F("sample_rate", media_format->parameters.telephone_event.sample_rate = atoi(__val));
 		CV_END;
 	}
 
-	if (!media_format->telephone_event.sample_rate) {
+	if (!media_format->parameters.telephone_event.sample_rate) {
 		ast_log(LOG_ERROR, "Telephone event media format '%s' did not pass configuration check.\n",
 			media_format->name);
 		return -1;
@@ -308,7 +343,7 @@
 
 	if (VERBOSITY_ATLEAST(2)) {
 		ast_verbose(VERBOSE_PREFIX_3 "Configured telephone event media format '%s' with sample rate '%d'\n",
-			    media_format->name, media_format->telephone_event.sample_rate);
+			    media_format->name, media_format->parameters.telephone_event.sample_rate);
 	}
 
 	return 0;




More information about the svn-commits mailing list