[Asterisk-code-review] format_cap: Perform codec lookups by pointer instead of name (asterisk[17])
George Joseph
asteriskteam at digium.com
Tue Sep 15 14:36:47 CDT 2020
George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14941 )
Change subject: format_cap: Perform codec lookups by pointer instead of name
......................................................................
format_cap: Perform codec lookups by pointer instead of name
ASTERISK-28416 #close
Change-Id: I069420875ebdbcaada52d92599a5f7de3cb2cdf4
---
M include/asterisk/format_cache.h
M main/format_cache.c
M main/format_cap.c
3 files changed, 35 insertions(+), 1 deletion(-)
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
diff --git a/include/asterisk/format_cache.h b/include/asterisk/format_cache.h
index 5a2add6..7dc0276 100644
--- a/include/asterisk/format_cache.h
+++ b/include/asterisk/format_cache.h
@@ -314,4 +314,17 @@
*/
int ast_format_cache_is_slinear(struct ast_format *format);
+/*!
+ * \brief Retrieve a format from the cache by its codec
+ *
+ * \param codec The codec to search by
+ *
+ * \retval non-NULL if found
+ * \retval NULL if not found
+ *
+ * \note The returned format has its reference count incremented. It must be
+ * dropped using ao2_ref or ao2_cleanup.
+ */
+struct ast_format *ast_format_cache_get_by_codec(const struct ast_codec *codec);
+
#endif /* _AST_FORMAT_CACHE_H */
diff --git a/main/format_cache.c b/main/format_cache.c
index fbe659f..3ce8ee0 100644
--- a/main/format_cache.c
+++ b/main/format_cache.c
@@ -555,3 +555,24 @@
return 0;
}
+
+struct ast_format *ast_format_cache_get_by_codec(const struct ast_codec *codec)
+{
+ struct ast_format *format;
+ struct ao2_iterator it;
+
+ for (it = ao2_iterator_init(formats, 0);
+ (format = ao2_iterator_next(&it));
+ ao2_ref(format, -1)) {
+ struct ast_codec *candidate = ast_format_get_codec(format);
+ if (codec == candidate) {
+ ao2_cleanup(candidate);
+ ao2_iterator_destroy(&it);
+ return format;
+ }
+ ao2_cleanup(candidate);
+ }
+
+ ao2_iterator_destroy(&it);
+ return NULL;
+}
diff --git a/main/format_cap.c b/main/format_cap.c
index a97fd6d..4dc8e49 100644
--- a/main/format_cap.c
+++ b/main/format_cap.c
@@ -232,7 +232,7 @@
continue;
}
- format = ast_format_cache_get(codec->name);
+ format = ast_format_cache_get_by_codec(codec);
if (format == ast_format_none) {
ao2_ref(format, -1);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14941
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 17
Gerrit-Change-Id: I069420875ebdbcaada52d92599a5f7de3cb2cdf4
Gerrit-Change-Number: 14941
Gerrit-PatchSet: 3
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200915/c5ca1bc4/attachment.html>
More information about the asterisk-code-review
mailing list