codecs: Fix ABI incompatibility created by adding format_name to ast_codec

Adding format_name even to the end of ast_codec caused issued with
binary codec modules because the pointer would be garbage in asterisk
when they registered.  So, the ast_codec structure was reverted and an
internal_ast_codec structure was created just for use in codec.c.  A new
internal-only API was also added (__ast_codec_register_with_format) so
that codec_builtin could register codecs with the format_name in a
separate parameter rather than in the ast_codec structure.

ASTERISK-26144 #close
Reported-by: Alexei Gradinari

Change-Id: I6df1b08f6a6ae089db23adfe1ebc8636330265ba
This commit is contained in:
George Joseph
2016-06-28 08:00:32 -06:00
parent 541f038694
commit 4045e6d8ba
3 changed files with 52 additions and 21 deletions

View File

@@ -38,6 +38,9 @@ ASTERISK_REGISTER_FILE()
#include "asterisk/format_cache.h"
#include "asterisk/frame.h"
int __ast_codec_register_with_format(struct ast_codec *codec, const char *format_name,
struct ast_module *mod);
enum frame_type {
TYPE_HIGH, /* 0x0 */
TYPE_LOW, /* 0x1 */
@@ -774,8 +777,7 @@ static struct ast_codec t140 = {
int __res_ ## __LINE__ = 0; \
struct ast_format *__fmt_ ## __LINE__; \
struct ast_codec *__codec_ ## __LINE__; \
codec.format_name = (codec).name; \
res |= __ast_codec_register(&(codec), NULL); \
res |= __ast_codec_register_with_format(&(codec), (codec).name, NULL); \
__codec_ ## __LINE__ = ast_codec_get((codec).name, (codec).type, (codec).sample_rate); \
__fmt_ ## __LINE__ = __codec_ ## __LINE__ ? ast_format_create(__codec_ ## __LINE__) : NULL; \
res |= ast_format_cache_set(__fmt_ ## __LINE__); \
@@ -789,8 +791,7 @@ static struct ast_codec t140 = {
int __res_ ## __LINE__ = 0; \
struct ast_format *__fmt_ ## __LINE__; \
struct ast_codec *__codec_ ## __LINE__; \
codec.format_name = fmt_name; \
res |= __ast_codec_register(&(codec), NULL); \
res |= __ast_codec_register_with_format(&(codec), fmt_name, NULL); \
__codec_ ## __LINE__ = ast_codec_get((codec).name, (codec).type, (codec).sample_rate); \
__fmt_ ## __LINE__ = ast_format_create_named((fmt_name), __codec_ ## __LINE__); \
res |= ast_format_cache_set(__fmt_ ## __LINE__); \