*/
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 */
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;
+}
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);