mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-18 09:32:34 +00:00
Merge pull request #790 in FS/freeswitch from ~PIOTRGREGOR/freeswitch:bugfix/FS-9016-avmd-segfault-on-null-read_codec to master
* commit '0a893bac2f26a66b18ebb2e08ee05eafc3db47c5': FS-9016 Avmd segfaults on NULL read codec
This commit is contained in:
commit
61fda5727d
@ -20,8 +20,7 @@
|
|||||||
|
|
||||||
|
|
||||||
double
|
double
|
||||||
avmd_desa2_tweaked(circ_buffer_t *b, size_t i,
|
avmd_desa2_tweaked(circ_buffer_t *b, size_t i)
|
||||||
switch_core_session_t *session)
|
|
||||||
{
|
{
|
||||||
double d;
|
double d;
|
||||||
double n;
|
double n;
|
||||||
|
@ -35,8 +35,7 @@
|
|||||||
* from this partial result using
|
* from this partial result using
|
||||||
* 0.5 * acos(n/d)
|
* 0.5 * acos(n/d)
|
||||||
*/
|
*/
|
||||||
double avmd_desa2_tweaked(circ_buffer_t *b, size_t i,
|
double avmd_desa2_tweaked(circ_buffer_t *b, size_t i);
|
||||||
switch_core_session_t *session);
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __AVMD_DESA2_TWEAKED_H__ */
|
#endif /* __AVMD_DESA2_TWEAKED_H__ */
|
||||||
|
@ -211,21 +211,59 @@ static switch_bool_t avmd_callback(switch_media_bug_t * bug,
|
|||||||
avmd_session_t *avmd_session;
|
avmd_session_t *avmd_session;
|
||||||
switch_codec_t *read_codec;
|
switch_codec_t *read_codec;
|
||||||
switch_frame_t *frame;
|
switch_frame_t *frame;
|
||||||
|
switch_core_session_t *fs_session;
|
||||||
|
|
||||||
|
|
||||||
avmd_session = (avmd_session_t *) user_data;
|
avmd_session = (avmd_session_t *) user_data;
|
||||||
if (avmd_session == NULL) {
|
if (avmd_session == NULL) {
|
||||||
|
switch_log_printf(
|
||||||
|
SWITCH_CHANNEL_LOG,
|
||||||
|
SWITCH_LOG_ERROR,
|
||||||
|
"No avmd session assigned!\n"
|
||||||
|
);
|
||||||
|
return SWITCH_FALSE;
|
||||||
|
}
|
||||||
|
fs_session = avmd_session->session;
|
||||||
|
if (fs_session == NULL) {
|
||||||
|
switch_log_printf(
|
||||||
|
SWITCH_CHANNEL_LOG,
|
||||||
|
SWITCH_LOG_ERROR,
|
||||||
|
"No FreeSWITCH session assigned!\n"
|
||||||
|
);
|
||||||
return SWITCH_FALSE;
|
return SWITCH_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case SWITCH_ABC_TYPE_INIT:
|
case SWITCH_ABC_TYPE_INIT:
|
||||||
read_codec = switch_core_session_get_read_codec(avmd_session->session);
|
read_codec = switch_core_session_get_read_codec(fs_session);
|
||||||
|
if (read_codec == NULL) {
|
||||||
|
switch_log_printf(
|
||||||
|
SWITCH_CHANNEL_SESSION_LOG(fs_session),
|
||||||
|
SWITCH_LOG_WARNING,
|
||||||
|
"No codec assigned, default session rate to 8000 samples/s\n"
|
||||||
|
);
|
||||||
|
avmd_session->rate = 8000;
|
||||||
|
} else {
|
||||||
|
if (read_codec->implementation == NULL) {
|
||||||
|
switch_log_printf(
|
||||||
|
SWITCH_CHANNEL_SESSION_LOG(fs_session),
|
||||||
|
SWITCH_LOG_WARNING,
|
||||||
|
"No codec implementation assigned, default session rate to 8000 samples/s\n"
|
||||||
|
);
|
||||||
|
avmd_session->rate = 8000;
|
||||||
|
} else {
|
||||||
avmd_session->rate = read_codec->implementation->samples_per_second;
|
avmd_session->rate = read_codec->implementation->samples_per_second;
|
||||||
|
}
|
||||||
|
}
|
||||||
avmd_session->start_time = switch_micro_time_now();
|
avmd_session->start_time = switch_micro_time_now();
|
||||||
/* avmd_session->vmd_codec.channels =
|
/* avmd_session->vmd_codec.channels =
|
||||||
* read_codec->implementation->number_of_channels; */
|
* read_codec->implementation->number_of_channels; */
|
||||||
|
switch_log_printf(
|
||||||
|
SWITCH_CHANNEL_SESSION_LOG(fs_session),
|
||||||
|
SWITCH_LOG_INFO,
|
||||||
|
"Avmd session started, [%u] samples/s\n", avmd_session->rate
|
||||||
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SWITCH_ABC_TYPE_READ_REPLACE:
|
case SWITCH_ABC_TYPE_READ_REPLACE:
|
||||||
@ -368,8 +406,14 @@ SWITCH_STANDARD_APP(avmd_start_function)
|
|||||||
avmd_session_t *avmd_session;
|
avmd_session_t *avmd_session;
|
||||||
switch_media_bug_flag_t flags = 0;
|
switch_media_bug_flag_t flags = 0;
|
||||||
|
|
||||||
if (session == NULL)
|
if (session == NULL) {
|
||||||
|
switch_log_printf(
|
||||||
|
SWITCH_CHANNEL_LOG,
|
||||||
|
SWITCH_LOG_ERROR,
|
||||||
|
"No FreeSWITCH session assigned!\n"
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
|
|
||||||
@ -500,7 +544,8 @@ SWITCH_STANDARD_API(avmd_api_main)
|
|||||||
|
|
||||||
/* No command? Display usage */
|
/* No command? Display usage */
|
||||||
if (zstr(cmd)) {
|
if (zstr(cmd)) {
|
||||||
stream->write_function(stream, "-USAGE: %s\n", AVMD_SYNTAX);
|
stream->write_function(stream, "-ERR, bad command!\n"
|
||||||
|
"-USAGE: %s\n\n", AVMD_SYNTAX);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,7 +557,8 @@ SWITCH_STANDARD_API(avmd_api_main)
|
|||||||
/* If we don't have the expected number of parameters
|
/* If we don't have the expected number of parameters
|
||||||
* display usage */
|
* display usage */
|
||||||
if (argc != AVMD_PARAMS) {
|
if (argc != AVMD_PARAMS) {
|
||||||
stream->write_function(stream, "-USAGE: %s\n", AVMD_SYNTAX);
|
stream->write_function(stream, "-ERR, avmd takes [%u] parameters!\n"
|
||||||
|
"-USAGE: %s\n\n", AVMD_PARAMS, AVMD_SYNTAX);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,7 +570,8 @@ SWITCH_STANDARD_API(avmd_api_main)
|
|||||||
|
|
||||||
/* If the session was not found exit */
|
/* If the session was not found exit */
|
||||||
if (fs_session == NULL) {
|
if (fs_session == NULL) {
|
||||||
stream->write_function(stream, "-USAGE: %s\n", AVMD_SYNTAX);
|
stream->write_function(stream, "-ERR, no FreeSWITCH session for uuid [%s]!"
|
||||||
|
"\n-USAGE: %s\n\n", uuid, AVMD_SYNTAX);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,7 +588,7 @@ SWITCH_STANDARD_API(avmd_api_main)
|
|||||||
switch_channel_set_private(channel, "_avmd_", NULL);
|
switch_channel_set_private(channel, "_avmd_", NULL);
|
||||||
switch_core_media_bug_remove(fs_session, &bug);
|
switch_core_media_bug_remove(fs_session, &bug);
|
||||||
switch_safe_free(ccmd);
|
switch_safe_free(ccmd);
|
||||||
stream->write_function(stream, "+OK\n");
|
stream->write_function(stream, "+OK\n[%s] stopped.\n", uuid);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,7 +604,8 @@ SWITCH_STANDARD_API(avmd_api_main)
|
|||||||
|
|
||||||
/* If we don't see the expected start exit */
|
/* If we don't see the expected start exit */
|
||||||
if (strcasecmp(command, "start") != 0) {
|
if (strcasecmp(command, "start") != 0) {
|
||||||
stream->write_function(stream, "-USAGE: %s\n", AVMD_SYNTAX);
|
stream->write_function(stream, "-ERR, did you mean\n"
|
||||||
|
"api avmd %s start ?\n-USAGE: %s\n\n", uuid, AVMD_SYNTAX);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -595,9 +643,10 @@ SWITCH_STANDARD_API(avmd_api_main)
|
|||||||
switch_log_printf(
|
switch_log_printf(
|
||||||
SWITCH_CHANNEL_SESSION_LOG(session),
|
SWITCH_CHANNEL_SESSION_LOG(session),
|
||||||
SWITCH_LOG_ERROR,
|
SWITCH_LOG_ERROR,
|
||||||
"Failure hooking to stream\n"
|
"Failed to add media bug!\n"
|
||||||
);
|
);
|
||||||
|
stream->write_function(stream,
|
||||||
|
"-ERR, [%s] failed to add media bug!\n\n", uuid);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,7 +654,7 @@ SWITCH_STANDARD_API(avmd_api_main)
|
|||||||
switch_channel_set_private(channel, "_avmd_", bug);
|
switch_channel_set_private(channel, "_avmd_", bug);
|
||||||
|
|
||||||
/* Everything went according to plan! Notify the user */
|
/* Everything went according to plan! Notify the user */
|
||||||
stream->write_function(stream, "+OK\n");
|
stream->write_function(stream, "+OK, start\n\n");
|
||||||
|
|
||||||
|
|
||||||
end:
|
end:
|
||||||
@ -667,7 +716,7 @@ static void avmd_process(avmd_session_t *session, switch_frame_t *frame)
|
|||||||
/*for (pos = session->pos; pos < (GET_CURRENT_POS(b) - P); pos++) { */
|
/*for (pos = session->pos; pos < (GET_CURRENT_POS(b) - P); pos++) { */
|
||||||
if ((sample_n % sine_len_i) == 0) {
|
if ((sample_n % sine_len_i) == 0) {
|
||||||
/* Get a desa2 frequency estimate every sine len */
|
/* Get a desa2 frequency estimate every sine len */
|
||||||
omega = avmd_desa2_tweaked(b, pos + sample_n, session->session);
|
omega = avmd_desa2_tweaked(b, pos + sample_n);
|
||||||
|
|
||||||
if (omega < -0.999999 || omega > 0.999999) {
|
if (omega < -0.999999 || omega > 0.999999) {
|
||||||
#ifdef AVMD_DEBUG
|
#ifdef AVMD_DEBUG
|
||||||
|
Loading…
x
Reference in New Issue
Block a user