Merge branch 'signalwire:master' into master

This commit is contained in:
Talha Asghar 2024-05-01 14:42:49 +05:00 committed by GitHub
commit 52de4ddafc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 21 deletions

View File

@ -1581,7 +1581,6 @@ GCC_DIAG_ON(deprecated-declarations)
} else if (ret == AVERROR(EAGAIN)) {
/* we fully drain all the output in each encode call, so this should not ever happen */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending frame to encoder - BUG, should never happen\n");
ret = AVERROR_BUG;
goto error;
} else if (ret < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error sending frame to encoder\n");

View File

@ -1170,7 +1170,6 @@ GCC_DIAG_ON(deprecated-declarations)
} else if (ret == AVERROR(EAGAIN)) {
/* we fully drain all the output in each encode call, so this should not ever happen */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending frame to encoder on draining AVERROR_BUG - should never happen\n");
ret = AVERROR_BUG;
goto do_break;
} else if (ret < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending frame to encoder on draining\n");
@ -1426,7 +1425,7 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
av_dump_format(context->fc, 0, filename, 0);
for (i = 0; i< context->fc->nb_streams; i++) {
for (i = 0; i < context->fc->nb_streams; i++) {
enum AVMediaType codec_type = av_get_codec_type(context->fc->streams[i]);
if (codec_type == AVMEDIA_TYPE_AUDIO && context->has_audio < 2 && idx < 2) {
@ -1554,7 +1553,9 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
if (context->has_audio) {
AVCodecContext *c[2] = { NULL };
c[0] = av_get_codec_context(&context->audio_st[0]);
if (!(c[0] = av_get_codec_context(&context->audio_st[0]))) {
switch_goto_status(SWITCH_STATUS_FALSE, err);
}
if ((cc = av_get_codec_context(&context->audio_st[1]))) {
c[1] = cc;
@ -1568,9 +1569,7 @@ static switch_status_t open_input_file(av_file_context_t *context, switch_file_h
if (c[1]) {
context->audio_st[1].frame = av_frame_alloc();
switch_assert(context->audio_st[1].frame);
}
if (c[0] && c[1]) {
context->audio_st[0].channels = 1;
context->audio_st[1].channels = 1;
} else {
@ -2016,7 +2015,6 @@ GCC_DIAG_ON(deprecated-declarations)
} else if (dret == AVERROR(EAGAIN)) {
/* we fully drain all the output in each decode call, so this should not ever happen */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending audio packet to decoder - BUG, should never happen\n");
dret = AVERROR_BUG;
goto do_continue;
} else if (dret < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG9, "Error sending audio packet to decoder\n");

View File

@ -2130,9 +2130,7 @@ static enum avmd_detection_mode avmd_process_sample(avmd_session_t *s, circ_buff
sma_buffer_t *sqa_amp_b = &buffer->sqa_amp_b;
if (sample_to_skip_n > 0) {
sample_to_skip_n--;
valid_amplitude = 0;
valid_omega = 0;
return AVMD_DETECT_NONE;
}
@ -2145,12 +2143,12 @@ static enum avmd_detection_mode avmd_process_sample(avmd_session_t *s, circ_buff
RESET_SMA_BUFFER(sma_amp_b);
RESET_SMA_BUFFER(sqa_amp_b);
buffer->samples_streak_amp = s->settings.sample_n_continuous_streak_amp;
sample_to_skip_n = s->settings.sample_n_to_skip;
}
} else {
if (ISINF(amplitude)) {
amplitude = buffer->amplitude_max;
}
if (valid_amplitude == 1) {
APPEND_SMA_VAL(sma_amp_b, amplitude); /* append amplitude */
APPEND_SMA_VAL(sqa_amp_b, amplitude * amplitude);
@ -2161,6 +2159,7 @@ static enum avmd_detection_mode avmd_process_sample(avmd_session_t *s, circ_buff
}
}
}
if (sma_amp_b->sma > buffer->amplitude_max) {
buffer->amplitude_max = sma_amp_b->sma;
}
@ -2176,9 +2175,7 @@ static enum avmd_detection_mode avmd_process_sample(avmd_session_t *s, circ_buff
RESET_SMA_BUFFER(sma_b_fir);
RESET_SMA_BUFFER(sqa_b_fir);
buffer->samples_streak = s->settings.sample_n_continuous_streak;
sample_to_skip_n = s->settings.sample_n_to_skip;
}
sample_to_skip_n = s->settings.sample_n_to_skip;
} else if (omega < -0.99999 || omega > 0.99999) {
valid_omega = 0;
if (s->settings.require_continuous_streak == 1) {
@ -2187,7 +2184,6 @@ static enum avmd_detection_mode avmd_process_sample(avmd_session_t *s, circ_buff
RESET_SMA_BUFFER(sma_b_fir);
RESET_SMA_BUFFER(sqa_b_fir);
buffer->samples_streak = s->settings.sample_n_continuous_streak;
sample_to_skip_n = s->settings.sample_n_to_skip;
}
} else {
if (valid_omega) {
@ -2216,20 +2212,26 @@ static enum avmd_detection_mode avmd_process_sample(avmd_session_t *s, circ_buff
if (((mode == AVMD_DETECT_AMP) || (mode == AVMD_DETECT_BOTH)) && (valid_amplitude == 1)) {
v_amp = sqa_amp_b->sma - (sma_amp_b->sma * sma_amp_b->sma); /* calculate variance of amplitude (biased estimator) */
if ((mode == AVMD_DETECT_AMP) && (avmd_decision_amplitude(s, buffer, v_amp, AVMD_AMPLITUDE_RSD_THRESHOLD) == 1)) {
return AVMD_DETECT_AMP;
}
}
if (((mode == AVMD_DETECT_FREQ) || (mode == AVMD_DETECT_BOTH)) && (valid_omega == 1)) {
v_fir = sqa_b_fir->sma - (sma_b_fir->sma * sma_b_fir->sma); /* calculate variance of filtered samples */
if ((mode == AVMD_DETECT_FREQ) && (avmd_decision_freq(s, buffer, v_fir, AVMD_VARIANCE_RSD_THRESHOLD) == 1)) {
return AVMD_DETECT_FREQ;
}
if (mode == AVMD_DETECT_BOTH) {
if ((avmd_decision_amplitude(s, buffer, v_amp, AVMD_AMPLITUDE_RSD_THRESHOLD) == 1) && (avmd_decision_freq(s, buffer, v_fir, AVMD_VARIANCE_RSD_THRESHOLD) == 1)) {
return AVMD_DETECT_BOTH;
}
}
}
return AVMD_DETECT_NONE;
}

View File

@ -95,23 +95,23 @@ extern switch_bool_t switch_amrwb_pack_be(unsigned char *shift_buf, int n)
extern switch_bool_t switch_amrwb_unpack_be(unsigned char *encoded_buf, uint8_t *tmp, int encoded_len)
{
int framesz, index, ft;
int framesz, index;
uint8_t shift_tocs[2] = {0x00, 0x00};
uint8_t *shift_buf;
memcpy(shift_tocs, encoded_buf, 2);
/* shift for BE */
switch_amr_array_lshift(4, shift_tocs, 2);
ft = shift_tocs[0] >> 3;
ft &= ~(1 << 5); /* Frame Type*/
shift_buf = encoded_buf + 1; /* skip CMR */
/* shift for BE */
switch_amr_array_lshift(2, shift_buf, encoded_len - 1);
/* get frame size */
index = ((shift_tocs[0] >> 3) & 0x0f);
if (index > 10 && index != 0xe && index != 0xf) {
return SWITCH_FALSE;
}
framesz = switch_amrwb_frame_sizes[index];
tmp[0] = shift_tocs[0]; /* save TOC */
memcpy(&tmp[1], shift_buf, framesz);

View File

@ -191,6 +191,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla
if (codec->fmtp_in) {
codec->fmtp_out = switch_core_strdup(codec->memory_pool, codec->fmtp_in);
}
return SWITCH_STATUS_SUCCESS;
#else
struct amrwb_context *context = NULL;
@ -204,6 +205,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct amrwb_context))))) {
return SWITCH_STATUS_FALSE;
} else {
@ -296,6 +298,7 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla
/* re-create mode-set */
fmtptmp_pos = switch_snprintf(fmtptmp, sizeof(fmtptmp), "mode-set=");
for (i = 0; SWITCH_AMRWB_MODES-1 > i; ++i) {
if (context->enc_modes & (1 << i)) {
fmtptmp_pos += switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, fmtptmp_pos > strlen("mode-set=") ? ",%d" : "%d", i);
@ -312,12 +315,13 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla
}
if (!globals.volte) {
fmtptmp_pos += switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, ";octet-align=%d",
switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, ";octet-align=%d",
switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0);
} else {
fmtptmp_pos += switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, ";octet-align=%d;max-red=0;mode-change-capability=2",
switch_snprintf(fmtptmp + fmtptmp_pos, sizeof(fmtptmp) - fmtptmp_pos, ";octet-align=%d;max-red=0;mode-change-capability=2",
switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0);
}
codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
context->encoder_state = NULL;