Merge pull request #796 in FS/freeswitch from ~PIOTRGREGOR/freeswitch:feature/FS-9027-avmd-check-buffer-for-successful to master
* commit 'cc05abc0d4fcc40af68e2e6158256cb655ea3e12': FS-9027: [avmd] Check buffer
This commit is contained in:
commit
5ea78d6da2
|
@ -11,7 +11,6 @@
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#ifndef INT16_MIN
|
#ifndef INT16_MIN
|
||||||
#define INT16_MIN (-32767-1)
|
#define INT16_MIN (-32767-1)
|
||||||
|
@ -95,7 +94,6 @@ extern size_t next_power_of_2(size_t v);
|
||||||
(bf)->buf_len = CALC_BUFF_LEN((fl), (bl)); \
|
(bf)->buf_len = CALC_BUFF_LEN((fl), (bl)); \
|
||||||
(bf)->mask = (bf)->buf_len - 1; \
|
(bf)->mask = (bf)->buf_len - 1; \
|
||||||
(bf)->buf = (BUFF_TYPE *) switch_core_session_alloc(s, (bf)->buf_len * sizeof(BUFF_TYPE)); \
|
(bf)->buf = (BUFF_TYPE *) switch_core_session_alloc(s, (bf)->buf_len * sizeof(BUFF_TYPE)); \
|
||||||
assert((bf)->buf != NULL); \
|
|
||||||
(bf)->pos = 0; \
|
(bf)->pos = 0; \
|
||||||
(bf)->lpos = 0; \
|
(bf)->lpos = 0; \
|
||||||
(bf)->backlog = 0; \
|
(bf)->backlog = 0; \
|
||||||
|
|
|
@ -163,13 +163,18 @@ static void init_avmd_session_data(avmd_session_t *avmd_session,
|
||||||
static void init_avmd_session_data(avmd_session_t *avmd_session,
|
static void init_avmd_session_data(avmd_session_t *avmd_session,
|
||||||
switch_core_session_t *fs_session)
|
switch_core_session_t *fs_session)
|
||||||
{
|
{
|
||||||
/*! This is a worst case sample rate estimate */
|
/*! This is a worst case sample rate estimate */
|
||||||
avmd_session->rate = 48000;
|
avmd_session->rate = 48000;
|
||||||
INIT_CIRC_BUFFER(&avmd_session->b,
|
INIT_CIRC_BUFFER(&avmd_session->b,
|
||||||
(size_t)BEEP_LEN(avmd_session->rate),
|
(size_t)BEEP_LEN(avmd_session->rate),
|
||||||
(size_t)FRAME_LEN(avmd_session->rate),
|
(size_t)FRAME_LEN(avmd_session->rate),
|
||||||
fs_session);
|
fs_session);
|
||||||
|
if (avmd_session->b.buf == NULL) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),
|
||||||
|
SWITCH_LOG_ERROR, "Failed to init avmd session."
|
||||||
|
" Buffer error\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
avmd_session->session = fs_session;
|
avmd_session->session = fs_session;
|
||||||
avmd_session->pos = 0;
|
avmd_session->pos = 0;
|
||||||
avmd_session->f = 0.0;
|
avmd_session->f = 0.0;
|
||||||
|
@ -179,13 +184,11 @@ static void init_avmd_session_data(avmd_session_t *avmd_session,
|
||||||
avmd_session->samples_streak = SAMPLES_CONSECUTIVE_STREAK;
|
avmd_session->samples_streak = SAMPLES_CONSECUTIVE_STREAK;
|
||||||
#endif
|
#endif
|
||||||
avmd_session->sample_count = 0;
|
avmd_session->sample_count = 0;
|
||||||
|
|
||||||
INIT_SMA_BUFFER(
|
INIT_SMA_BUFFER(
|
||||||
&avmd_session->sma_b,
|
&avmd_session->sma_b,
|
||||||
BEEP_LEN(avmd_session->rate) / SINE_LEN(avmd_session->rate),
|
BEEP_LEN(avmd_session->rate) / SINE_LEN(avmd_session->rate),
|
||||||
fs_session
|
fs_session
|
||||||
);
|
);
|
||||||
|
|
||||||
INIT_SMA_BUFFER(
|
INIT_SMA_BUFFER(
|
||||||
&avmd_session->sqa_b,
|
&avmd_session->sqa_b,
|
||||||
BEEP_LEN(avmd_session->rate) / SINE_LEN(avmd_session->rate),
|
BEEP_LEN(avmd_session->rate) / SINE_LEN(avmd_session->rate),
|
||||||
|
@ -269,7 +272,7 @@ static switch_bool_t avmd_callback(switch_media_bug_t * bug,
|
||||||
/* 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,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),SWITCH_LOG_INFO,
|
||||||
"Avmd session started, [%u] samples/s\n", avmd_session->rate);
|
"Avmd session initialized, [%u] samples/s\n", avmd_session->rate);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SWITCH_ABC_TYPE_READ_REPLACE:
|
case SWITCH_ABC_TYPE_READ_REPLACE:
|
||||||
|
@ -411,14 +414,10 @@ SWITCH_STANDARD_APP(avmd_start_function)
|
||||||
switch_core_media_bug_remove(session, &bug);
|
switch_core_media_bug_remove(session, &bug);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have already started */
|
/* We have already started */
|
||||||
switch_log_printf(
|
switch_log_printf(
|
||||||
SWITCH_CHANNEL_SESSION_LOG(session),
|
SWITCH_CHANNEL_SESSION_LOG(session),
|
||||||
SWITCH_LOG_WARNING,
|
SWITCH_LOG_WARNING, "Cannot run 2 at once on the same channel!\n");
|
||||||
"Cannot run 2 at once on the same channel!\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,11 +446,8 @@ SWITCH_STANDARD_APP(avmd_start_function)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (status != SWITCH_STATUS_SUCCESS) {
|
if (status != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session),
|
||||||
SWITCH_CHANNEL_SESSION_LOG(session),
|
SWITCH_LOG_ERROR, "Failure hooking to stream\n");
|
||||||
SWITCH_LOG_ERROR,
|
|
||||||
"Failure hooking to stream\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -558,14 +554,14 @@ SWITCH_STANDARD_API(avmd_api_main)
|
||||||
channel = switch_core_session_get_channel(fs_session);
|
channel = switch_core_session_get_channel(fs_session);
|
||||||
if (channel == NULL) {
|
if (channel == NULL) {
|
||||||
stream->write_function(stream, "-ERR, no channel for FreeSWITCH session [%s]!"
|
stream->write_function(stream, "-ERR, no channel for FreeSWITCH session [%s]!"
|
||||||
"\nPlease report this to the developers.\n\n", uuid);
|
"\nPlease report this to the developers\n\n", uuid);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
#ifdef AVMD_OUTBOUND_CHANNEL
|
#ifdef AVMD_OUTBOUND_CHANNEL
|
||||||
if (SWITCH_CALL_DIRECTION_OUTBOUND != switch_channel_direction(channel)) {
|
if (SWITCH_CALL_DIRECTION_OUTBOUND != switch_channel_direction(channel)) {
|
||||||
stream->write_function(stream, "-ERR, channel for FreeSWITCH session [%s]"
|
stream->write_function(stream, "-ERR, channel for FreeSWITCH session [%s]"
|
||||||
"\nis not outbound.\n\n", uuid);
|
"\nis not outbound\n\n", uuid);
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING,
|
||||||
"Channel [%s] is not outbound!\n", switch_channel_get_name(channel));
|
"Channel [%s] is not outbound!\n", switch_channel_get_name(channel));
|
||||||
} else {
|
} else {
|
||||||
flags |= SMBF_READ_REPLACE;
|
flags |= SMBF_READ_REPLACE;
|
||||||
|
@ -575,7 +571,7 @@ SWITCH_STANDARD_API(avmd_api_main)
|
||||||
if (SWITCH_CALL_DIRECTION_INBOUND != switch_channel_direction(channel)) {
|
if (SWITCH_CALL_DIRECTION_INBOUND != switch_channel_direction(channel)) {
|
||||||
stream->write_function(stream, "-ERR, channel for FreeSWITCH session [%s]"
|
stream->write_function(stream, "-ERR, channel for FreeSWITCH session [%s]"
|
||||||
"\nis not inbound.\n\n", uuid);
|
"\nis not inbound.\n\n", uuid);
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING,
|
||||||
"Channel [%s] is not inbound!\n", switch_channel_get_name(channel));
|
"Channel [%s] is not inbound!\n", switch_channel_get_name(channel));
|
||||||
} else {
|
} else {
|
||||||
flags |= SMBF_WRITE_REPLACE;
|
flags |= SMBF_WRITE_REPLACE;
|
||||||
|
@ -583,9 +579,9 @@ SWITCH_STANDARD_API(avmd_api_main)
|
||||||
#endif
|
#endif
|
||||||
if(flags == 0) {
|
if(flags == 0) {
|
||||||
stream->write_function(stream, "-ERR, can't set direction for channel [%s]\n"
|
stream->write_function(stream, "-ERR, can't set direction for channel [%s]\n"
|
||||||
" for FreeSWITCH session [%s]. Please check avmd configuration.\n\n",
|
" for FreeSWITCH session [%s]. Please check avmd configuration\n\n",
|
||||||
switch_channel_get_name(channel), uuid);
|
switch_channel_get_name(channel), uuid);
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR,
|
||||||
"Can't set direction for channel [%s]\n", switch_channel_get_name(channel));
|
"Can't set direction for channel [%s]\n", switch_channel_get_name(channel));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -594,10 +590,11 @@ SWITCH_STANDARD_API(avmd_api_main)
|
||||||
#ifdef AVMD_OUTBOUND_CHANNEL
|
#ifdef AVMD_OUTBOUND_CHANNEL
|
||||||
if (switch_channel_test_flag(channel, CF_MEDIA_SET) == 0) {
|
if (switch_channel_test_flag(channel, CF_MEDIA_SET) == 0) {
|
||||||
stream->write_function(stream, "-ERR, channel [%s] for FreeSWITCH session [%s]"
|
stream->write_function(stream, "-ERR, channel [%s] for FreeSWITCH session [%s]"
|
||||||
"\nhas no read codec assigned yet. Please try again.\n\n",
|
"\nhas no read codec assigned yet. Please try again\n\n",
|
||||||
switch_channel_get_name(channel), uuid);
|
switch_channel_get_name(channel), uuid);
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_ERROR,
|
||||||
"Failed to start session. Channel [%s] has no codec assigned yet.\n",
|
"Failed to start session. Channel [%s] has no codec assigned yet."
|
||||||
|
" Please try again\n",
|
||||||
switch_channel_get_name(channel));
|
switch_channel_get_name(channel));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -611,12 +608,12 @@ 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[%s] stopped.\n", uuid);
|
stream->write_function(stream, "+OK, [%s] stopped\n", uuid);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have already started */
|
/* We have already started */
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_WARNING,
|
||||||
"Cannot run 2 at once on the same channel!\n");
|
"Cannot run 2 at once on the same channel!\n");
|
||||||
|
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -651,12 +648,8 @@ SWITCH_STANDARD_API(avmd_api_main)
|
||||||
|
|
||||||
/* If adding a media bug fails exit */
|
/* If adding a media bug fails exit */
|
||||||
if (status != SWITCH_STATUS_SUCCESS) {
|
if (status != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session),
|
||||||
switch_log_printf(
|
SWITCH_LOG_ERROR, "Failed to add media bug!\n");
|
||||||
SWITCH_CHANNEL_SESSION_LOG(session),
|
|
||||||
SWITCH_LOG_ERROR,
|
|
||||||
"Failed to add media bug!\n"
|
|
||||||
);
|
|
||||||
stream->write_function(stream,
|
stream->write_function(stream,
|
||||||
"-ERR, [%s] failed to add media bug!\n\n", uuid);
|
"-ERR, [%s] failed to add media bug!\n\n", uuid);
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -665,7 +658,9 @@ SWITCH_STANDARD_API(avmd_api_main)
|
||||||
/* Set the vmd tag to detect an existing vmd media bug */
|
/* Set the vmd tag to detect an existing vmd media bug */
|
||||||
switch_channel_set_private(channel, "_avmd_", bug);
|
switch_channel_set_private(channel, "_avmd_", bug);
|
||||||
|
|
||||||
/* Everything went according to plan! Notify the user */
|
/* OK */
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(fs_session), SWITCH_LOG_INFO,
|
||||||
|
"Avmd session on channel [%s] started\n", switch_channel_get_name(channel));
|
||||||
stream->write_function(stream, "+OK, start\n\n");
|
stream->write_function(stream, "+OK, start\n\n");
|
||||||
|
|
||||||
|
|
||||||
|
@ -845,7 +840,7 @@ static void avmd_process(avmd_session_t *session, switch_frame_t *frame)
|
||||||
switch_event_fire(&event_copy);
|
switch_event_fire(&event_copy);
|
||||||
|
|
||||||
#ifdef AVMD_REPORT_STATUS
|
#ifdef AVMD_REPORT_STATUS
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session->session), SWITCH_LOG_NOTICE,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session->session), SWITCH_LOG_INFO,
|
||||||
"<<< AVMD - Beep Detected: f = [%f], variance = [%f] >>>\n",
|
"<<< AVMD - Beep Detected: f = [%f], variance = [%f] >>>\n",
|
||||||
TO_HZ(session->rate, sma_digital_freq), v);
|
TO_HZ(session->rate, sma_digital_freq), v);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue