<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14943">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
George Joseph: Looks good to me, but someone else must approve; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">format_cap: Perform codec lookups by pointer instead of name<br><br>ASTERISK-28416 #close<br><br>Change-Id: I069420875ebdbcaada52d92599a5f7de3cb2cdf4<br>---<br>M include/asterisk/format_cache.h<br>M main/format_cache.c<br>M main/format_cap.c<br>3 files changed, 35 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/format_cache.h b/include/asterisk/format_cache.h</span><br><span>index 5a2add6..7dc0276 100644</span><br><span>--- a/include/asterisk/format_cache.h</span><br><span>+++ b/include/asterisk/format_cache.h</span><br><span>@@ -314,4 +314,17 @@</span><br><span> */</span><br><span> int ast_format_cache_is_slinear(struct ast_format *format);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Retrieve a format from the cache by its codec</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param codec The codec to search by</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non-NULL if found</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval NULL if not found</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \note The returned format has its reference count incremented. It must be</span><br><span style="color: hsl(120, 100%, 40%);">+ * dropped using ao2_ref or ao2_cleanup.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_format *ast_format_cache_get_by_codec(const struct ast_codec *codec);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif /* _AST_FORMAT_CACHE_H */</span><br><span>diff --git a/main/format_cache.c b/main/format_cache.c</span><br><span>index fbe659f..3ce8ee0 100644</span><br><span>--- a/main/format_cache.c</span><br><span>+++ b/main/format_cache.c</span><br><span>@@ -555,3 +555,24 @@</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct ast_format *ast_format_cache_get_by_codec(const struct ast_codec *codec)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_format *format;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ao2_iterator it;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (it = ao2_iterator_init(formats, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+ (format = ao2_iterator_next(&it));</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(format, -1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_codec *candidate = ast_format_get_codec(format);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (codec == candidate) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(candidate);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_iterator_destroy(&it);</span><br><span style="color: hsl(120, 100%, 40%);">+ return format;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(candidate);</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%);">+ ao2_iterator_destroy(&it);</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/main/format_cap.c b/main/format_cap.c</span><br><span>index a97fd6d..4dc8e49 100644</span><br><span>--- a/main/format_cap.c</span><br><span>+++ b/main/format_cap.c</span><br><span>@@ -232,7 +232,7 @@</span><br><span> continue;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- format = ast_format_cache_get(codec->name);</span><br><span style="color: hsl(120, 100%, 40%);">+ format = ast_format_cache_get_by_codec(codec);</span><br><span> </span><br><span> if (format == ast_format_none) {</span><br><span> ao2_ref(format, -1);</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14943">change 14943</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/+/14943"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I069420875ebdbcaada52d92599a5f7de3cb2cdf4 </div>
<div style="display:none"> Gerrit-Change-Number: 14943 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>