[asterisk-commits] file: branch file/rtp_engine-mark2 r183248 - in /team/file/rtp_engine-mark2: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 19 13:12:53 CDT 2009


Author: file
Date: Thu Mar 19 13:12:50 2009
New Revision: 183248

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=183248
Log:
Add the sample rate based API calls.

Modified:
    team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h
    team/file/rtp_engine-mark2/main/rtp_engine.c

Modified: team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h?view=diff&rev=183248&r1=183247&r2=183248
==============================================================================
--- team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h (original)
+++ team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h Thu Mar 19 13:12:50 2009
@@ -733,7 +733,29 @@
  *
  * This records that the numerical payload '0' was seen with mime type 'audio' and sub mime type 'PCMU' in the codecs structure.
  */
-int ast_rtp_codecs_payloads_set_rtpmap_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, const char *mimeType, const char *mimeSubtype, enum ast_rtp_options options);
+int ast_rtp_codecs_payloads_set_rtpmap_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, char *mimeType, char *mimeSubtype, enum ast_rtp_options options);
+
+/*! \brief Set payload type to a known MIME media type for a codec with a specific sample rate
+ *
+ * \param rtp RTP structure to modify
+ * \param instance Optionally the instance that the codecs structure belongs to
+ * \param pt Payload type entry to modify
+ * \param mimeType top-level MIME type of media stream (typically "audio", "video", "text", etc.)
+ * \param mimeSubtype MIME subtype of media stream (typically a codec name)
+ * \param options Zero or more flags from the ast_rtp_options enum
+ * \param sample_rate The sample rate of the media stream
+ *
+ * This function 'fills in' an entry in the list of possible formats for
+ * a media stream associated with an RTP structure.
+ *
+ * \retval 0 on success
+ * \retval -1 if the payload type is out of range
+ * \retval -2 if the mimeType/mimeSubtype combination was not found
+ */
+int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
+				  char *mimeType, char *mimeSubtype,
+				  enum ast_rtp_options options,
+				  unsigned int sample_rate);
 
 /*! \brief Remove payload information
  *
@@ -768,6 +790,15 @@
  * This looks up the information for payload '0' from the codecs structure.
  */
 struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload);
+
+/*! \brief Get the sample rate associated with known RTP payload types
+ *
+ * \param isAstFormat True if the value in the 'code' parameter is an AST_FORMAT value
+ * \param code Format code, either from AST_FORMAT list or from AST_RTP list
+ *
+ * \return the sample rate if the format was found, zero if it was not found
+ */
+unsigned int ast_rtp_lookup_sample_rate2(int isAstFormat, int code);
 
 /*! \brief Retrieve all formats that were found
  *

Modified: team/file/rtp_engine-mark2/main/rtp_engine.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/main/rtp_engine.c?view=diff&rev=183248&r1=183247&r2=183248
==============================================================================
--- team/file/rtp_engine-mark2/main/rtp_engine.c (original)
+++ team/file/rtp_engine-mark2/main/rtp_engine.c Thu Mar 19 13:12:50 2009
@@ -462,27 +462,58 @@
 	return;
 }
 
-int ast_rtp_codecs_payloads_set_rtpmap_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, const char *mimeType, const char *mimeSubtype, enum ast_rtp_options options)
-{
-	int i;
-
-	if (payload < 0 || payload > AST_RTP_MAX_PT) {
-		return -1;
-	}
-
-	for (i = 0; i < ARRAY_LEN(mimeTypes); i++) {
-		if (!strcasecmp(mimeTypes[i].subtype, mimeSubtype) && !strcasecmp(mimeTypes[i].type, mimeType)) {
-			ast_debug(1, "Setting payload %d based on rtpmap on %p\n", payload, codecs);
-			codecs->payloads[payload].isAstFormat = mimeTypes[i].payloadType.isAstFormat;
-			codecs->payloads[payload].code = mimeTypes[i].payloadType.code;
-			if (instance && instance->engine && instance->engine->payload_set) {
-				instance->engine->payload_set(instance, payload, codecs->payloads[i].isAstFormat, codecs->payloads[i].code);
-			}
-			return 0;
-		}
-	}
-
-	return -1;
+int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
+				 char *mimeType, char *mimeSubtype,
+				 enum ast_rtp_options options,
+				 unsigned int sample_rate)
+{
+	unsigned int i;
+	int found = 0;
+
+	if (pt < 0 || pt > AST_RTP_MAX_PT)
+		return -1; /* bogus payload type */
+
+	for (i = 0; i < ARRAY_LEN(mimeTypes); ++i) {
+		const struct mimeType *t = &mimeTypes[i];
+
+		if (strcasecmp(mimeSubtype, t->subtype)) {
+			continue;
+		}
+
+		if (strcasecmp(mimeType, t->type)) {
+			continue;
+		}
+
+		/* if both sample rates have been supplied, and they don't match,
+		                      then this not a match; if one has not been supplied, then the
+				      rates are not compared */
+		if (sample_rate && t->sample_rate &&
+		    (sample_rate != t->sample_rate)) {
+			continue;
+		}
+
+		found = 1;
+		codecs->payloads[pt] = t->payloadType;
+
+		if ((t->payloadType.code == AST_FORMAT_G726) &&
+		                        t->payloadType.isAstFormat &&
+		    (options & AST_RTP_OPT_G726_NONSTANDARD)) {
+			codecs->payloads[pt].code = AST_FORMAT_G726_AAL2;
+		}
+
+		if (instance && instance->engine && instance->engine->payload_set) {
+			instance->engine->payload_set(instance, pt, codecs->payloads[i].isAstFormat, codecs->payloads[i].code);
+		}
+
+		break;
+	}
+
+	return (found ? 0 : -2);
+}
+
+int ast_rtp_codecs_payloads_set_rtpmap_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, char *mimeType, char *mimeSubtype, enum ast_rtp_options options)
+{
+	return ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, instance, payload, mimeType, mimeSubtype, options, 0);
 }
 
 void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
@@ -576,6 +607,19 @@
 	}
 
 	return "";
+}
+
+unsigned int ast_rtp_lookup_sample_rate2(int isAstFormat, int code)
+{
+	unsigned int i;
+
+	for (i = 0; i < ARRAY_LEN(mimeTypes); ++i) {
+		if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) {
+			return mimeTypes[i].sample_rate;
+		}
+	}
+
+	return 0;
 }
 
 char *ast_rtp_lookup_mime_multiple2(char *buf, size_t size, const int capability, const int isAstFormat, enum ast_rtp_options options)




More information about the asterisk-commits mailing list