Author: file Date: Fri Dec 12 11:01:42 2014 New Revision: 429498 URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=429498 Log: media: Fix crash when determining sample count of a frame during shutdown.
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 Modified: trunk/ (props changed) trunk/include/asterisk/format.h trunk/main/codec.c trunk/main/format.c Propchange: trunk/ ------------------------------------------------------------------------------ Binary property 'branch-13-merged' - no diff available. Modified: trunk/include/asterisk/format.h URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/format.h?view=diff&rev=429498&r1=429497&r2=429498 ============================================================================== --- trunk/include/asterisk/format.h (original) +++ trunk/include/asterisk/format.h Fri Dec 12 11:01:42 2014 @@ -276,6 +276,17 @@ 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 * * \param format The media format Modified: trunk/main/codec.c URL: http://svnview.digium.com/svn/asterisk/trunk/main/codec.c?view=diff&rev=429498&r1=429497&r2=429498 ============================================================================== --- trunk/main/codec.c (original) +++ trunk/main/codec.c Fri Dec 12 11:01:42 2014 @@ -355,10 +355,7 @@ 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); Modified: trunk/main/format.c URL: http://svnview.digium.com/svn/asterisk/trunk/main/format.c?view=diff&rev=429498&r1=429497&r2=429498 ============================================================================== --- trunk/main/format.c (original) +++ trunk/main/format.c Fri Dec 12 11:01:42 2014 @@ -323,6 +323,11 @@ 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; -- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- svn-commits mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/svn-commits
