<p>Alexander Traud has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15421">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_format_attr_h264: Allow level to be downgraded.<br><br>ASTERISK-29285<br><br>Change-Id: I29a4e1474b0ae1d56ebaa2fe4c9e603fd39c31c6<br>---<br>M res/res_format_attr_h264.c<br>1 file changed, 45 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/21/15421/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_format_attr_h264.c b/res/res_format_attr_h264.c</span><br><span>index c1b538e..209be32 100644</span><br><span>--- a/res/res_format_attr_h264.c</span><br><span>+++ b/res/res_format_attr_h264.c</span><br><span>@@ -35,6 +35,8 @@</span><br><span> </span><br><span> #include "asterisk/module.h"</span><br><span> #include "asterisk/format.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/strings.h" /* for ast_str_append, etc */</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/utils.h" /* for MAX, ast_calloc, ast_free, etc */</span><br><span> </span><br><span> /*! \brief Value that indicates an attribute is actually unset */</span><br><span> #define H264_ATTR_KEY_UNSET UINT8_MAX</span><br><span>@@ -48,6 +50,10 @@</span><br><span> * H264_MAX_SPS_PPS_SIZE */</span><br><span> #define H264_MAX_SPS_PPS_SIZE_SCAN_LIMIT "15"</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define H264_DEFAULT_PROFILE_IDC 66 /* 42 */</span><br><span style="color: hsl(120, 100%, 40%);">+#define H264_DEFAULT_PROFILE_IOP 160 /* a0 */</span><br><span style="color: hsl(120, 100%, 40%);">+#define H264_MIN_LEVEL 10 /* 0a */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct h264_attr {</span><br><span> unsigned int PROFILE_IDC;</span><br><span> unsigned int PROFILE_IOP;</span><br><span>@@ -129,7 +135,6 @@</span><br><span> </span><br><span> DETERMINE_JOINT(attr, attr1, attr2, PROFILE_IDC);</span><br><span> DETERMINE_JOINT(attr, attr1, attr2, PROFILE_IOP);</span><br><span style="color: hsl(0, 100%, 40%);">- DETERMINE_JOINT(attr, attr1, attr2, LEVEL);</span><br><span> DETERMINE_JOINT(attr, attr1, attr2, MAX_MBPS);</span><br><span> DETERMINE_JOINT(attr, attr1, attr2, MAX_FS);</span><br><span> DETERMINE_JOINT(attr, attr1, attr2, MAX_CPB);</span><br><span>@@ -148,6 +153,35 @@</span><br><span> DETERMINE_JOINT(attr, attr1, attr2, LEVEL_ASYMMETRY_ALLOWED);</span><br><span> DETERMINE_JOINT(attr, attr1, attr2, PACKETIZATION_MODE);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* https://mailarchive.ietf.org/arch/msg/avt/o-q0iDkaZXZRg1IQUeD67pd4kAo/ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!attr->LEVEL_ASYMMETRY_ALLOWED) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (attr1 && attr2) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Level 1b is 0x09 sometimes, see RFC 6184 section 8.2.2:</span><br><span style="color: hsl(120, 100%, 40%);">+ * Level 1b is one level higher than Level 1.0 */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (9 == attr1->LEVEL || 9 == attr2->LEVEL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!attr1->LEVEL || 10 == attr1->LEVEL ||</span><br><span style="color: hsl(120, 100%, 40%);">+ !attr2->LEVEL || 10 == attr2->LEVEL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->LEVEL = 10; /* minimum is Level 1.0 */</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->LEVEL = 9; /* minimum is Level 1b */</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ /* otherwise minimum level is 1.0; this is forced here again</span><br><span style="color: hsl(120, 100%, 40%);">+ * because cached formats do not have that as default but 0 */</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->LEVEL = MIN(MAX(attr1->LEVEL,H264_MIN_LEVEL),</span><br><span style="color: hsl(120, 100%, 40%);">+ MAX(attr2->LEVEL,H264_MIN_LEVEL));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ attr1->LEVEL = attr->LEVEL;</span><br><span style="color: hsl(120, 100%, 40%);">+ attr2->LEVEL = attr->LEVEL;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (attr1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->LEVEL = attr1->LEVEL;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (attr2) {</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->LEVEL = attr2->LEVEL;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->LEVEL = H264_MIN_LEVEL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (attr1 && !ast_strlen_zero(attr1->SPS)) {</span><br><span> ast_copy_string(attr->SPS, attr1->SPS, sizeof(attr->SPS));</span><br><span> } else if (attr2 && !ast_strlen_zero(attr2->SPS)) {</span><br><span>@@ -178,7 +212,10 @@</span><br><span> attr->REDUNDANT_PIC_CAP = H264_ATTR_KEY_UNSET;</span><br><span> attr->PARAMETER_ADD = H264_ATTR_KEY_UNSET;</span><br><span> attr->PACKETIZATION_MODE = H264_ATTR_KEY_UNSET;</span><br><span style="color: hsl(0, 100%, 40%);">- attr->LEVEL_ASYMMETRY_ALLOWED = H264_ATTR_KEY_UNSET;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->PROFILE_IDC = H264_DEFAULT_PROFILE_IDC;</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->PROFILE_IOP = H264_DEFAULT_PROFILE_IOP;</span><br><span style="color: hsl(120, 100%, 40%);">+ attr->LEVEL = H264_MIN_LEVEL;</span><br><span> </span><br><span> while ((attrib = strsep(&attribs, ";"))) {</span><br><span> unsigned int val;</span><br><span>@@ -280,9 +317,13 @@</span><br><span> APPEND_IF_NOT_H264_UNSET(attr->REDUNDANT_PIC_CAP, str, "redundant-pic-cap");</span><br><span> APPEND_IF_NOT_H264_UNSET(attr->PARAMETER_ADD, str, "parameter-add");</span><br><span> APPEND_IF_NOT_H264_UNSET(attr->PACKETIZATION_MODE, str, "packetization-mode");</span><br><span style="color: hsl(0, 100%, 40%);">- APPEND_IF_NOT_H264_UNSET(attr->LEVEL_ASYMMETRY_ALLOWED, str, "level-asymmetry-allowed");</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (attr->PROFILE_IDC && attr->LEVEL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ APPEND_IF_NONZERO(attr->LEVEL_ASYMMETRY_ALLOWED, str, "level-asymmetry-allowed");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* cached formats have not the defaults but 0 */</span><br><span style="color: hsl(120, 100%, 40%);">+ if ((attr->PROFILE_IDC && H264_DEFAULT_PROFILE_IDC != attr->PROFILE_IDC) ||</span><br><span style="color: hsl(120, 100%, 40%);">+ (attr->PROFILE_IOP && H264_DEFAULT_PROFILE_IOP != attr->PROFILE_IOP) ||</span><br><span style="color: hsl(120, 100%, 40%);">+ (attr->LEVEL && H264_MIN_LEVEL != attr->LEVEL)) { /* could be 0x09 for Level 1b */</span><br><span> if (added) {</span><br><span> ast_str_append(str, 0, ";");</span><br><span> } else if (0 < ast_str_append(str, 0, "a=fmtp:%u ", payload)) {</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15421">change 15421</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15421"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I29a4e1474b0ae1d56ebaa2fe4c9e603fd39c31c6 </div>
<div style="display:none"> Gerrit-Change-Number: 15421 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexander Traud <pabstraud@compuserve.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>