]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
media: Fix crash when determining sample count of a frame during shutdown.
authorJoshua Colp <jcolp@digium.com>
Fri, 12 Dec 2014 17:01:42 +0000 (17:01 +0000)
committerJoshua Colp <jcolp@digium.com>
Fri, 12 Dec 2014 17:01:42 +0000 (17:01 +0000)
When shutting down Asterisk the codecs are cleaned up. As a result anything
attempting to get a codec based on ID or details will find that no codec
exists. This currently occurs when determining the sample count of a frame.
This code did not take this situation into account.

This change fixes this by getting the codec directly from the format and
eliminates the lookup. This is both faster and also provides a guarantee
that the codec will exist and will be valid.

ASTERISK-24604 #close
Reported by: Matt Jordan

Review: https://reviewboard.asterisk.org/r/4260/
........

Merged revisions 429497 from http://svn.asterisk.org/svn/asterisk/branches/13

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@429498 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/format.h
main/codec.c
main/format.c

index 32f9f2b40e2897d710632a638d7e233558f51482..3da2d82368e8cc2070b260482db17ae5ceafa712 100644 (file)
@@ -275,6 +275,17 @@ void ast_format_set_attribute_data(struct ast_format *format, void *attribute_da
  */
 const char *ast_format_get_name(const struct ast_format *format);
 
+/*!
+ * \brief Get the codec associated with a format
+ *
+ * \param format The media format
+ *
+ * \return The codec
+ *
+ * \note The reference count of the returned codec is increased by 1 and must be decremented
+ */
+struct ast_codec *ast_format_get_codec(const struct ast_format *format);
+
 /*!
  * \brief Get the codec identifier associated with a format
  *
index e060efe3ecd3d413a2465ae803f0829627c92a06..19e78fa675a07aa92cde8d2c49bf117f1217498c 100644 (file)
@@ -355,10 +355,7 @@ unsigned int ast_codec_samples_count(struct ast_frame *frame)
                return 0;
        }
 
-       /* BUGBUG - why not just get the codec pointer off the format?
-       This is a bit roundabout
-       */
-       codec = ast_codec_get_by_id(ast_format_get_codec_id(frame->subclass.format));
+       codec = ast_format_get_codec(frame->subclass.format);
 
        if (codec->samples_count) {
                samples = codec->samples_count(frame);
index e54fca01b4af7798b9ee1e64b1f750c79eac4d1b..09d7ef0c507af937c676352851fbc8623a67af07 100644 (file)
@@ -323,6 +323,11 @@ void ast_format_generate_sdp_fmtp(const struct ast_format *format, unsigned int
        format->interface->format_generate_sdp_fmtp(format, payload, str);
 }
 
+struct ast_codec *ast_format_get_codec(const struct ast_format *format)
+{
+       return ao2_bump(format->codec);
+}
+
 unsigned int ast_format_get_codec_id(const struct ast_format *format)
 {
        return format->codec->id;