From ef32d90e91001c39ed261518db423868844a32fd Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 26 Apr 2024 12:41:07 +0000 Subject: [PATCH 1/3] [mod_av] Fix scan-build 14 --- src/mod/applications/mod_av/avcodec.c | 1 - src/mod/applications/mod_av/avformat.c | 10 ++++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/mod/applications/mod_av/avcodec.c b/src/mod/applications/mod_av/avcodec.c index 16d268273b..4f0057264e 100644 --- a/src/mod/applications/mod_av/avcodec.c +++ b/src/mod/applications/mod_av/avcodec.c @@ -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"); diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index 69475c169f..c1e0052530 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -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"); From 597ee613de378c69abfdf4fe5133f29061d8ade7 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 26 Apr 2024 12:58:44 +0000 Subject: [PATCH 2/3] [mod_avmd] Fix scan-build 14 --- src/mod/applications/mod_avmd/mod_avmd.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/mod/applications/mod_avmd/mod_avmd.c b/src/mod/applications/mod_avmd/mod_avmd.c index e5076c1500..713f9158cd 100644 --- a/src/mod/applications/mod_avmd/mod_avmd.c +++ b/src/mod/applications/mod_avmd/mod_avmd.c @@ -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,14 +2143,14 @@ 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(sma_amp_b, amplitude); /* append amplitude */ APPEND_SMA_VAL(sqa_amp_b, amplitude * amplitude); if (s->settings.require_continuous_streak_amp == 1) { if (buffer->samples_streak_amp > 0) { @@ -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)) { + 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; } From 84ab90895ab53cbbf60f0f214f4ca2c025d085e7 Mon Sep 17 00:00:00 2001 From: Jakub Karolczyk Date: Fri, 26 Apr 2024 13:11:54 +0000 Subject: [PATCH 3/3] [mod_amrwb] Fix scan-build 14 --- src/mod/codecs/mod_amrwb/amrwb_be.c | 6 +++--- src/mod/codecs/mod_amrwb/mod_amrwb.c | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mod/codecs/mod_amrwb/amrwb_be.c b/src/mod/codecs/mod_amrwb/amrwb_be.c index 7b43b2b583..e8f45cf7d7 100644 --- a/src/mod/codecs/mod_amrwb/amrwb_be.c +++ b/src/mod/codecs/mod_amrwb/amrwb_be.c @@ -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); diff --git a/src/mod/codecs/mod_amrwb/mod_amrwb.c b/src/mod/codecs/mod_amrwb/mod_amrwb.c index 4ac3f25f37..d89ec5d62b 100644 --- a/src/mod/codecs/mod_amrwb/mod_amrwb.c +++ b/src/mod/codecs/mod_amrwb/mod_amrwb.c @@ -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;