[svn-commits] file: branch file/mf-attributes r417749 - /team/file/mf-attributes/res/
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Wed Jul 2 05:41:10 CDT 2014
Author: file
Date: Wed Jul 2 05:41:04 2014
New Revision: 417749
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=417749
Log:
Move res_format_attr_h264 over.
Modified:
team/file/mf-attributes/res/res_format_attr_h264.c
Modified: team/file/mf-attributes/res/res_format_attr_h264.c
URL: http://svnview.digium.com/svn/asterisk/team/file/mf-attributes/res/res_format_attr_h264.c?view=diff&rev=417749&r1=417748&r2=417749
==============================================================================
--- team/file/mf-attributes/res/res_format_attr_h264.c (original)
+++ team/file/mf-attributes/res/res_format_attr_h264.c Wed Jul 2 05:41:04 2014
@@ -231,114 +231,79 @@
return cloned;
}
-/*! \brief Helper function which converts a key enum into a string value for SDP */
-static const char *h264_attr_key_to_str(enum h264_attr_keys key)
-{
- switch (key) {
- case H264_ATTR_KEY_MAX_MBPS:
- return "max-mbps";
- case H264_ATTR_KEY_MAX_FS:
- return "max-fs";
- case H264_ATTR_KEY_MAX_CPB:
- return "max-cpb";
- case H264_ATTR_KEY_MAX_DPB:
- return "max-dpb";
- case H264_ATTR_KEY_MAX_BR:
- return "max-br";
- case H264_ATTR_KEY_MAX_SMBPS:
- return "max-smbps";
- case H264_ATTR_KEY_MAX_FPS:
- return "max-fps";
- case H264_ATTR_KEY_REDUNDANT_PIC_CAP:
- return "redundant-pic-cap";
- case H264_ATTR_KEY_PARAMETER_ADD:
- return "parameter-add";
- case H264_ATTR_KEY_PACKETIZATION_MODE:
- return "packetization-mode";
- case H264_ATTR_KEY_SPROP_INTERLEAVING_DEPTH:
- return "sprop-interleaving-depth";
- case H264_ATTR_KEY_SPROP_DEINT_BUF_REQ:
- return "sprop-deint-buf-req";
- case H264_ATTR_KEY_DEINT_BUF_CAP:
- return "deint-buf-cap";
- case H264_ATTR_KEY_SPROP_INIT_BUF_TIME:
- return "sprop-init-buf-time";
- case H264_ATTR_KEY_SPROP_MAX_DON_DIFF:
- return "sprop-max-don-diff";
- case H264_ATTR_KEY_MAX_RCMD_NALU_SIZE:
- return "max-rcmd-nalu-size";
- case H264_ATTR_KEY_LEVEL_ASYMMETRY_ALLOWED:
- return "level-asymmetry-allowed";
- default:
- return NULL;
- }
-
- return NULL;
-}
-
-/*! \brief Helper function which determines if the value of an attribute can be placed into the SDP */
-static int h264_attr_key_addable(const struct ast_format_attr *format_attr, enum h264_attr_keys key)
-{
- switch (key) {
- case H264_ATTR_KEY_REDUNDANT_PIC_CAP:
- case H264_ATTR_KEY_PARAMETER_ADD:
- case H264_ATTR_KEY_PACKETIZATION_MODE:
- case H264_ATTR_KEY_LEVEL_ASYMMETRY_ALLOWED:
- return (format_attr->format_attr[key] != H264_ATTR_KEY_UNSET) ? 1 : 0;
- default:
- return format_attr->format_attr[key] ? 1 : 0;
- }
-
- return 1;
-}
-
-static void h264_format_attr_sdp_generate(const struct ast_format_attr *format_attr, unsigned int payload, struct ast_str **str)
-{
- int i, added = 0;
-
- for (i = H264_ATTR_KEY_PROFILE_IDC; i < H264_ATTR_KEY_END; i++) {
- const char *name;
-
- 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:%u 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:%u profile-level-id=%02X%02X%02X", payload, 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]);
- added = 1;
- } else {
- ast_str_append(str, 0, ";profile-level-id=%02X%02X%02X", 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]);
- }
- } else if ((name = h264_attr_key_to_str(i)) && h264_attr_key_addable(format_attr, i)) {
- if (!added) {
- ast_str_append(str, 0, "a=fmtp:%u %s=%u", payload, name, format_attr->format_attr[i]);
- added = 1;
- } else {
- ast_str_append(str, 0, ";%s=%u", name, format_attr->format_attr[i]);
- }
+#define APPEND_IF_NOT_H264_UNSET(field, str, name) do { \
+ if (field != H264_ATTR_KEY_UNSET) { \
+ if (added) { \
+ ast_str_append(str, 0, ";"); \
+ } else { \
+ added = 1; \
+ } \
+ ast_str_append(str, 0, "%s=%u", name, field); \
+ } \
+} while (0)
+
+#define APPEND_IF_NONZERO(field, str, name) do { \
+ if (field) { \
+ if (added) { \
+ ast_str_append(str, 0, ";"); \
+ } else { \
+ added = 1; \
+ } \
+ ast_str_append(str, 0, "%s=%u", name, field); \
+ } \
+} while (0)
+
+static void h264_sdp_generate(const struct ast_format *format, unsigned int payload, struct ast_str **str)
+{
+ struct h264_attr *attr = ast_format_get_attribute_data(format);
+ int added = 0;
+
+ if (!attr) {
+ return;
+ }
+
+ ast_str_append(str, 0, "a=fmtp:%u ", payload);
+
+ APPEND_IF_NONZERO(attr->MAX_MBPS, str, "max-mbps");
+ APPEND_IF_NONZERO(attr->MAX_FS, str, "max-fs");
+ APPEND_IF_NONZERO(attr->MAX_CPB, str, "max-cpb");
+ APPEND_IF_NONZERO(attr->MAX_DPB, str, "max-dpb");
+ APPEND_IF_NONZERO(attr->MAX_BR, str, "max-br");
+ APPEND_IF_NONZERO(attr->MAX_SMBPS, str, "max-smbps");
+ APPEND_IF_NONZERO(attr->MAX_FPS, str, "max-fps");
+ APPEND_IF_NONZERO(attr->SPROP_INTERLEAVING_DEPTH, str, "sprop-interleaving-depth");
+ APPEND_IF_NONZERO(attr->SPROP_DEINT_BUF_REQ, str, "sprop-deint-buf-req");
+ APPEND_IF_NONZERO(attr->DEINT_BUF_CAP, str, "deint-buf-cap");
+ APPEND_IF_NONZERO(attr->SPROP_INIT_BUF_TIME, str, "sprop-init-buf-time");
+ APPEND_IF_NONZERO(attr->SPROP_MAX_DON_DIFF, str, "sprop-max-don-diff");
+ APPEND_IF_NONZERO(attr->MAX_RCMD_NALU_SIZE, str, "max-rcmd-nalu-size");
+
+ APPEND_IF_NOT_H264_UNSET(attr->REDUNDANT_PIC_CAP, str, "redundant-pic-cap");
+ APPEND_IF_NOT_H264_UNSET(attr->PARAMETER_ADD, str, "parameter-add");
+ APPEND_IF_NOT_H264_UNSET(attr->PACKETIZATION_MODE, str, "packetization-mode");
+ APPEND_IF_NOT_H264_UNSET(attr->LEVEL_ASYMMETRY_ALLOWED, str, "level-asymmetry-allowed");
+
+ if (attr->PROFILE_IDC && attr->PROFILE_IOP && attr->LEVEL) {
+ if (added) {
+ ast_str_append(str, 0, ";");
+ } else {
+ added = 1;
}
- }
-
- if (added) {
+ ast_str_append(str, 0, "profile-level-id=%02X%02X%02X", attr->PROFILE_IDC, attr->PROFILE_IOP, attr->LEVEL);
+ }
+
+ if (!ast_strlen_zero(attr->SPS) && !ast_strlen_zero(attr->PPS)) {
+ if (added) {
+ ast_str_append(str, 0, ";");
+ } else {
+ added = 1;
+ }
+ ast_str_append(str, 0, ";sprop-parameter-sets=%s,%s", attr->SPS, attr->PPS);
+ }
+
+ if (!added) {
+ ast_str_reset(*str);
+ } else {
ast_str_append(str, 0, "\r\n");
}
More information about the svn-commits
mailing list