[svn-commits] file: branch file/media-attrib-sdp r369165 - /team/file/media-attrib-sdp/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Jun 20 15:07:16 CDT 2012


Author: file
Date: Wed Jun 20 15:07:13 2012
New Revision: 369165

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=369165
Log:
Add parsing and generation for sprop-parameter-sets.

Modified:
    team/file/media-attrib-sdp/res/res_format_attr_h264.c

Modified: team/file/media-attrib-sdp/res/res_format_attr_h264.c
URL: http://svnview.digium.com/svn/asterisk/team/file/media-attrib-sdp/res/res_format_attr_h264.c?view=diff&rev=369165&r1=369164&r2=369165
==============================================================================
--- team/file/media-attrib-sdp/res/res_format_attr_h264.c (original)
+++ team/file/media-attrib-sdp/res/res_format_attr_h264.c Wed Jun 20 15:07:13 2012
@@ -40,6 +40,9 @@
 
 /*! \brief Value that indicates an attribute is actually unset */
 #define H264_ATTR_KEY_UNSET UINT8_MAX
+
+/*! \brief Maximum size for SPS / PPS values in sprop-parameter-sets attribute */
+#define H264_MAX_SPS_PPS_SIZE 32
 
 enum h264_attr_keys {
 	H264_ATTR_KEY_PROFILE_IDC,
@@ -60,7 +63,11 @@
 	H264_ATTR_KEY_SPROP_MAX_DON_DIFF,
 	H264_ATTR_KEY_MAX_RCMD_NALU_SIZE,
 	H264_ATTR_KEY_LEVEL_ASYMMETRY_ALLOWED,
-	H264_ATTR_KEY_END,
+	H264_ATTR_KEY_SPS_LEN,
+	H264_ATTR_KEY_PPS_LEN,
+	H264_ATTR_KEY_SPS,
+	H264_ATTR_KEY_PPS = H264_ATTR_KEY_SPS + H264_MAX_SPS_PPS_SIZE,
+	H264_ATTR_KEY_END = H264_ATTR_KEY_PPS + H264_MAX_SPS_PPS_SIZE,
 };
 
 static enum ast_format_cmp_res h264_format_attr_cmp(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2)
@@ -96,11 +103,32 @@
 	while ((attrib = strsep(&attribs, ";"))) {
 		unsigned int val;
 		unsigned long int val2;
+		char sps[H264_MAX_SPS_PPS_SIZE], pps[H264_MAX_SPS_PPS_SIZE];
 
 		if (sscanf(attrib, "profile-level-id=%lx", &val2) == 1) {
 			format_attr->format_attr[H264_ATTR_KEY_PROFILE_IDC] = ((val2 >> 16) & 0xFF);
 			format_attr->format_attr[H264_ATTR_KEY_PROFILE_IOP] = ((val2 >> 8) & 0xFF);
 			format_attr->format_attr[H264_ATTR_KEY_LEVEL] = (val2 & 0xFF);
+		} else if (sscanf(attrib, "sprop-parameter-sets=%[^','],%s", sps, pps) == 2) {
+			unsigned char spsdecoded[H264_MAX_SPS_PPS_SIZE] = { 0, }, ppsdecoded[H264_MAX_SPS_PPS_SIZE] = { 0, };
+			int i;
+
+			ast_base64decode(spsdecoded, sps, sizeof(spsdecoded));
+			ast_base64decode(ppsdecoded, pps, sizeof(ppsdecoded));
+
+			format_attr->format_attr[H264_ATTR_KEY_SPS_LEN] = 0;
+			format_attr->format_attr[H264_ATTR_KEY_PPS_LEN] = 0;
+
+			for (i = 0; i < H264_MAX_SPS_PPS_SIZE; i++) {
+				if (spsdecoded[i]) {
+					format_attr->format_attr[H264_ATTR_KEY_SPS + i] = spsdecoded[i];
+					format_attr->format_attr[H264_ATTR_KEY_SPS_LEN]++;
+				}
+				if (ppsdecoded[i]) {
+					format_attr->format_attr[H264_ATTR_KEY_PPS + i] = ppsdecoded[i];
+					format_attr->format_attr[H264_ATTR_KEY_PPS_LEN]++;
+				}
+			}
 		} else if (sscanf(attrib, "max-mbps=%30u", &val) == 1) {
 			format_attr->format_attr[H264_ATTR_KEY_MAX_MBPS] = val;
 		} else if (sscanf(attrib, "max-fs=%30u", &val) == 1) {
@@ -201,7 +229,26 @@
         for (i = H264_ATTR_KEY_PROFILE_IDC; i < H264_ATTR_KEY_END; i++) {
                 const char *name;
 
-		if (i == H264_ATTR_KEY_PROFILE_IDC && format_attr->format_attr[H264_ATTR_KEY_PROFILE_IDC] &&
+		if (i == H264_ATTR_KEY_SPS && format_attr->format_attr[H264_ATTR_KEY_SPS] && format_attr->format_attr[H264_ATTR_KEY_PPS]) {
+			unsigned char spsdecoded[H264_MAX_SPS_PPS_SIZE] = { 0, }, ppsdecoded[H264_MAX_SPS_PPS_SIZE] = { 0, };
+			int pos;
+			char sps[H264_MAX_SPS_PPS_SIZE], pps[H264_MAX_SPS_PPS_SIZE];
+
+			for (pos = 0; pos < H264_MAX_SPS_PPS_SIZE; pos++) {
+				spsdecoded[pos] = format_attr->format_attr[H264_ATTR_KEY_SPS + pos];
+				ppsdecoded[pos] = format_attr->format_attr[H264_ATTR_KEY_PPS + pos];
+			}
+
+			ast_base64encode(sps, spsdecoded, format_attr->format_attr[H264_ATTR_KEY_SPS_LEN], H264_MAX_SPS_PPS_SIZE);
+			ast_base64encode(pps, ppsdecoded, format_attr->format_attr[H264_ATTR_KEY_PPS_LEN], H264_MAX_SPS_PPS_SIZE);
+
+			if (!added) {
+				ast_str_append(str, 0, "a=fmtp:%d sprop-parameter-sets=%s,%s", payload, sps, pps);
+				added = 1;
+			} else {
+				ast_str_append(str, 0, ";sprop-parameter-sets=%s,%s", sps, pps);
+			}
+		} else if (i == H264_ATTR_KEY_PROFILE_IDC && format_attr->format_attr[H264_ATTR_KEY_PROFILE_IDC] &&
 		    format_attr->format_attr[H264_ATTR_KEY_PROFILE_IOP] && format_attr->format_attr[H264_ATTR_KEY_LEVEL]) {
 			if (!added) {
 				ast_str_append(str, 0, "a=fmtp:%d profile-level-id=%X%X%X", payload, format_attr->format_attr[H264_ATTR_KEY_PROFILE_IDC],
@@ -220,8 +267,7 @@
 			}
 		}
 	}
-
-
+	
 	if (added) {
 		ast_str_append(str, 0, "\r\n");
 	}




More information about the svn-commits mailing list