[Home]

Summary:ASTERISK-28019: Crash in ast_format_get_sample_rate when play an audio
Reporter:Cirillo Ferreira (cirillor@lbv.org.br)Labels:pjsip
Date Opened:2018-08-21 07:58:49Date Closed:2023-01-02 15:45:32.000-0600
Priority:MinorRegression?
Status:Closed/CompleteComponents:Applications/app_playback
Versions:13.22.0 Frequency of
Occurrence
Frequent
Related
Issues:
is related toASTERISK-29040 res_speech: Assertion on format
Environment:> cat /proc/version Linux version 3.10.0-693.2.2.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) ) #1 SMP Tue Sep 12 22:26:13 UTC 2017 > rasterisk -V Asterisk 13.22.0Attachments:( 0) core.ANTIBES-2018-08-21T09-02-21-0300-brief.txt
( 1) core.ANTIBES-2018-08-21T09-02-21-0300-full.txt
( 2) core.ANTIBES-2018-08-21T09-02-21-0300-locks.txt
( 3) core.ANTIBES-2018-08-21T09-02-21-0300-thread1.txt
( 4) encerrar_aguedarmairtarde.wav
( 5) full
Description:Asterisk crashed in ast_format_get_sample_rate when try play an audio.

I already tried use SLIN, GSM, G711 (A-law and mu-law) codecs and in all cases the crash occurs.

Dialplan:

(...)
same => n,Playback(./pt_BR/altrium/felicitacao/encerrar_aguedarmairtarde)
Comments:By: Asterisk Team (asteriskteam) 2018-08-21 07:58:50.604-0500

Thanks for creating a report! The issue has entered the triage process. That means the issue will wait in this status until a Bug Marshal has an opportunity to review the issue. Once the issue has been reviewed you will receive comments regarding the next steps towards resolution.

A good first step is for you to review the [Asterisk Issue Guidelines|https://wiki.asterisk.org/wiki/display/AST/Asterisk+Issue+Guidelines] if you haven't already. The guidelines detail what is expected from an Asterisk issue report.

Then, if you are submitting a patch, please review the [Patch Contribution Process|https://wiki.asterisk.org/wiki/display/AST/Patch+Contribution+Process].

By: Joshua C. Colp (jcolp) 2018-08-21 08:54:38.367-0500

The problem actually seems to be occurring in audiohooks which are used by MixMonitor and ChanSpy. Can you please also provide the console output and a complete dialplan which demonstrates the problem.

By: Cirillo Ferreira (cirillor@lbv.org.br) 2018-08-21 09:51:27.266-0500

My dialplan is basically this:

{code}
[ivr-felicitacao-avulso]
exten => 4012,1,Answer()
same => n,Set(CHANNEL(hangup_handler_push)=handler-free-speech,s,1(args))

;; Inicia a gravação da ligação
same => n,Macro(iniciar-gravacao,voise-${cctTelefone},F)

same => n,SpeechCreate(voise)

(...)

same => n(agendarparamaistarde),Log(DEBUG, ==> Processo AgendarParaMaisTarde)
same => n,Macro(agendar-ligacao2,RL,3,123,2073,Sem resposta ou não foi possível entender a pessoa)
same => n,Playback(./pt_BR/altrium/felicitacao/encerrar_aguedarmairtarde)
same => n,Hangup()

(...)


[macro-iniciar-gravacao]
exten => s,1,Set(MONITOR_PATH=altriumrecorder/${STRFTIME(${EPOCH},,%Y)}/${STRFTIME(${EPOCH},,%m)}/${STRFTIME(${EPOCH},,%d)})
same => n,Set(MONITOR_FILENAME=${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${ARG1}-${ARG2})
same => n,MixMonitor(${MONITOR_PATH}/${MONITOR_FILENAME}.wav,)
same => n,MacroExit

[handler-free-speech]
exten => s,1,GotoIf($["${IVRRESULT}" = ""]?2:3)
same => 2,Macro(agendar-ligacao2,RL,3,123,2072,Ligação abandonada ${IVRSTEPNAME})
same => 3,SpeechDestroy()
same => 4,Return()
{code}

Ps: I also made a call using the local channel

By: Cirillo Ferreira (cirillor@lbv.org.br) 2018-08-21 09:51:55.278-0500

Log full at moment of crash

By: Joshua C. Colp (jcolp) 2018-08-23 07:46:24.704-0500

I am unable to reproduce this problem on Asterisk 13.22.0 using a PJSIP channel or an originated Local channel. No crash occurs and a recording still occurs.

Looking at your console log I see that you are using at least one external module for the Khomp channels and potentially a second one for Speech recognition. Can you please try an environment that does NOT use this to ensure they are not the real source of the problem?

By: Cirillo Ferreira (cirillor@lbv.org.br) 2018-08-30 16:49:16.994-0500

Joshua,

I created a simple environment that reproduces the crash.

Apparently the error only occurs when I try playback an audio with speech engine created.

Because this I did a simple speech engine (res_speech_mock) to demonstrate the problem.

{code:title=test.conf}
[origmock]
exten => s,1,Answer()
same => n,Set(CHANNEL(hangup_handler_push)=handler-free,s,1(args))
same => n,SpeechCreate(mock)
same => n,Playback(encerrar_aguedarmairtarde)
same => n,Wait(1)
same => n,Hangup()

[destmock]
exten => _1111,1,Answer()
same => n,Wait(${RAND(20,600)})
same => n,Hangup()

[handler-free]
exten => s,1,SpeechDestroy()
same => n,Return()
{code}

{code:title=run.sh}
#!/bin/bash

CONT=1
CALLS=40000000

while [ $CONT -lt $CALLS ]; do

   rasterisk -rx "originate Local/1111@destmock extension s@origmock";
   sleep 0.1

   echo "CALL $CONT";
   let CONT=CONT+1;
done
{code}

{code:title=res_speech_mock.c}

#include "asterisk.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

#include "asterisk/channel.h"
#include "asterisk/frame.h"
#include "asterisk/dsp.h"
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/config.h"
#include "asterisk/speech.h"

#include "asterisk/ast_version.h"
#include <asterisk/format_cache.h>

static const char *MOCK_CFG = "mock_speech.conf";

static struct ast_speech_engine mock_engine;

static struct ast_config* mock_load_asterisk_config(void)
{
  struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS };
  return ast_config_load(MOCK_CFG, config_flags);
}

static int mock_create(struct ast_speech *speech, int format)
{
   ast_speech_change_state(speech, AST_SPEECH_STATE_NOT_READY);
   return 0;
}

static int mock_destroy(struct ast_speech *speech)
{
   return 0;
}

static int mock_load_grammar(struct ast_speech *speech, char *grammar_name, char *grammar)
{
   return 0;
}

static int mock_unload_grammar(struct ast_speech *speech, char *grammar_name)
{
   return 0;
}

static int mock_activate_grammar(struct ast_speech *speech, char *grammar_name)
{
   return 0;
}

static int mock_deactivate_grammar(struct ast_speech *speech, char *grammar_name)
{
   return 0;
}

static int mock_write(struct ast_speech *speech, void *data, int len)
{
   return 0;
}

static int mock_dtmf(struct ast_speech *speech, const char *dtmf)
{
   return 0;
}

static int mock_start(struct ast_speech *speech)
{
   ast_speech_change_state(speech, AST_SPEECH_STATE_READY);

   return 0;
}

static int mock_change(struct ast_speech *speech, char *name, const char *value)
{
   return 0;
}

static int mock_change_results_type(struct ast_speech *speech, enum ast_speech_results_type results_type)
{
   return 0;
}

static struct ast_speech_result* mock_get(struct ast_speech *speech)
{
   return speech->results;
}

static struct ast_speech_engine mock_engine = {
   .name = "mock",
   .create = mock_create,
   .destroy = mock_destroy,
   .load = mock_load_grammar,
   .unload = mock_unload_grammar,
   .activate = mock_activate_grammar,
   .deactivate = mock_deactivate_grammar,
   .write = mock_write,
   .dtmf = mock_dtmf,
   .start = mock_start,
   .change = mock_change,
   .change_results_type = mock_change_results_type,
   .get = mock_get,
};

static int load_module(void)
{
   ast_log(LOG_NOTICE, "Loading resourse module\n");

   mock_engine.formats = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);

   if (!mock_engine.formats)
   {
       ast_log(LOG_ERROR, "Failed to alloc media format capabilities\n");
       return AST_MODULE_LOAD_FAILURE;
   }

   ast_format_cap_append(mock_engine.formats, ast_format_slin, 0);

   if (ast_speech_register(&mock_engine))
   {
       ast_log(LOG_ERROR, "Failed to register resource module\n");
       return -1;
   }

   return 0;
}

static int unload_module(void)
{
   ast_log(LOG_NOTICE, "Unloading resourse speech\n");

   return ast_speech_unregister(mock_engine.name);
}

AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Mock engine");
{code}

By: Benjamin Keith Ford (bford) 2018-08-31 09:18:42.879-0500

There is a patch attached to ASTERISK-27986 but it was never submitted to Gerrit. You could try applying it and see if it resolves the problem for you.

By: Cirillo Ferreira (cirillor@lbv.org.br) 2018-09-10 14:02:27.787-0500

Benjamin,

Since I applied the patch my operation is running without crash (~1 week), so apparently it fixed the problem.

But I didn't understand why occurs the crash when Asterisk try uses the native formats.

The register of my speech engine always forces to use SLIN format. Can it be a problem in choosing the best format

By: Benjamin Keith Ford (bford) 2018-09-10 16:34:50.201-0500

That patch was just a test to help get started with what may be going on in Asterisk. The fact that it does not crash with the patch applied helps narrow down the problem, but it's still a mystery why the crash is happening. It could have something to do with a format having a "none" type instead of NULL, which could be causing issues further down in audiohooks, since NULL would / should create issues sooner than that. The patch also has a memory leak (the cap is never freed), so it is not the end solution, just a good place for us to start. I believe we have enough information here to go ahead and open the issue up.

By: Sean Bright (seanbright) 2023-01-02 15:45:33.068-0600

This should have been resolved by ASTERISK-29040. If it still occurs feel free to re-open by responding.