summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/asterisk/format_cap.h9
-rw-r--r--main/channel.c5
-rw-r--r--main/format_cap.c15
-rw-r--r--main/translate.c5
4 files changed, 34 insertions, 0 deletions
diff --git a/include/asterisk/format_cap.h b/include/asterisk/format_cap.h
index f7d33fccd..94e81f869 100644
--- a/include/asterisk/format_cap.h
+++ b/include/asterisk/format_cap.h
@@ -321,4 +321,13 @@ int ast_format_cap_has_type(const struct ast_format_cap *cap, enum ast_media_typ
*/
const char *ast_format_cap_get_names(struct ast_format_cap *cap, struct ast_str **buf);
+/*!
+ * \brief Determine if a format cap has no formats in it.
+ *
+ * \param cap The format cap to check for emptiness
+ * \retval 1 The format cap has zero formats or only ast_format_none
+ * \retval 0 The format cap has at least one format
+ */
+int ast_format_cap_empty(struct ast_format_cap *cap);
+
#endif /* _AST_FORMAT_CAP_H */
diff --git a/main/channel.c b/main/channel.c
index 4595b5944..477bc815b 100644
--- a/main/channel.c
+++ b/main/channel.c
@@ -5327,6 +5327,11 @@ static int set_format(struct ast_channel *chan, struct ast_format_cap *cap_set,
ast_assert(rawformat != NULL);
cap_native = ast_channel_nativeformats(chan);
+ if (ast_format_cap_empty(cap_native)) {
+ ast_log(LOG_ERROR, "Unable to set format because channel %s supports no formats\n",
+ ast_channel_name(chan));
+ return -1;
+ }
/* Find a translation path from the native format to one of the desired formats */
if (!direction) {
diff --git a/main/format_cap.c b/main/format_cap.c
index 65e469fc1..364c924bf 100644
--- a/main/format_cap.c
+++ b/main/format_cap.c
@@ -700,3 +700,18 @@ const char *ast_format_cap_get_names(struct ast_format_cap *cap, struct ast_str
return ast_str_buffer(*buf);
}
+
+int ast_format_cap_empty(struct ast_format_cap *cap)
+{
+ int count = ast_format_cap_count(cap);
+
+ if (count > 1) {
+ return 0;
+ }
+
+ if (count == 0 || AST_VECTOR_GET(&cap->preference_order, 0)->format == ast_format_none) {
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/main/translate.c b/main/translate.c
index 0696f5d83..2778ebccf 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -1276,6 +1276,11 @@ int ast_translator_best_choice(struct ast_format_cap *dst_cap,
int i;
int j;
+ if (ast_format_cap_empty(dst_cap) || ast_format_cap_empty(src_cap)) {
+ ast_log(LOG_ERROR, "Cannot determine best translation path since one capability supports no formats\n");
+ return -1;
+ }
+
if (!(joint_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT))) {
return -1;
}