Author Topic: Crash Android  (Read 335 times)

Egor

  • Guest
Crash Android
« on: 11 Sep '23 - 23:23 »
Thanks for your work!
I'm using Bass android in ndk
I have a certain function..

Code: [Select]
bool Record::Init(const uint32_t bitrate) noexcept
{
    if(Record::initStatus)
        return false;

    if(BASS_IsStarted() == 0)
        return false;

    Log("[sv:dbg:record:init] : module initializing...");

    {
        int opusErrorCode { -1 };

        Record::encoder = opus_encoder_create(SV::kFrequency, 1,OPUS_APPLICATION_VOIP, &opusErrorCode);

        if(Record::encoder == nullptr || opusErrorCode < 0)
        {
            Log("[sv:err:record:init] : failed to create encoder (code:%d)", opusErrorCode);
            return false;
        }
    }

   // opus_encoder_destroy(Record::encoder);

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_BITRATE(bitrate)); error < 0)
    {
        Log("[sv:err:record:init] : failed to "
            "set bitrate for encoder (code:%d)", error);
        return false;
    }

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_SIGNAL(OPUS_SIGNAL_VOICE)); error < 0)
    {
        Log("[sv:err:record:init] : failed to "
            "set audiosignal type for encoder (code:%d)", error);
        return false;
    }

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_COMPLEXITY(10)); error < 0)
    {
        Log("[sv:err:record:init] : failed to "
            "set complexity for encoder (code:%d)", error);
        return false;
    }

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_PREDICTION_DISABLED(0)); error < 0)
    {
        Log("[sv:err:record:init] : failed to "
            "enable prediction for encoder (code:%d)", error);
        return false;
    }

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_LSB_DEPTH(16)); error < 0)
    {
        Log("[sv:err:record:init] : failed to "
            "set lsb depth for encoder (code:%d)", error);
        return false;
    }

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_FORCE_CHANNELS(1)); error < 0)
    {
        Log("[sv:err:record:init] : failed to "
            "set count channels for encoder (code:%d)", error);
        return false;
    }

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_DTX(0)); error < 0)
    {
        Log("[sv:err:record:init] : failed to "
            "set dtx for encoder (code:%d)", error);
        return false;
    }

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_INBAND_FEC(1)); error < 0)
    {
        Log("[sv:err:record:init] : failed to "
            "set inband fec for encoder (code:%d)", error);
        return false;
    }

    if(const auto error = opus_encoder_ctl(Record::encoder,
        OPUS_SET_PACKET_LOSS_PERC(10)); error < 0)
    {
        Log("[sv:err:record:init] : failed to set "
            "packet loss percent for encoder (code:%d)", error);
        return false;
    }

    bool initRecordStatus = BASS_RecordInit(-1);

    if(!initRecordStatus)
    {
        Log("[sv:err:record:init] : failed to "
            "init device (code:%d)", BASS_ErrorGetCode());
        return false;
    }


    Log("[sv:dbg:record:startrecording] : channel recording starting...");
    Record::recordChannel = BASS_RecordStart(SV::kFrequency, 1, BASS_RECORD_PAUSE, nullptr, nullptr);

    if(Record::recordChannel == NULL)
    {
        Log("[sv:err:record:init] : failed to create record "
            "stream (code:%d)", BASS_ErrorGetCode());
        return false;
    }
    BASS_ChannelPause(Record::recordChannel);

    Record::checkChannel = BASS_StreamCreate(SV::kFrequency, 1, NULL, STREAMPROC_PUSH, nullptr);

    if(Record::checkChannel == NULL)
    {
        Log("[sv:err:record:init] : failed to create "
            "check stream (code:%d)", BASS_ErrorGetCode());
        return false;
    }

    BASS_ChannelSetAttribute(Record::checkChannel, BASS_ATTRIB_VOL, 4.f);

    if(!Voice::PluginConfig::IsRecordLoaded())
    {
        Voice::PluginConfig::SetRecordLoaded(true);
        Record::ResetConfigs();
    }

//    deviceListsResetScope.Release();
//    encoderResetScope.Release();
//    recordResetScope.Release();
//    channelResetScope.Release();

    Log("[sv:dbg:record:init] : module initialized");

    Record::initStatus = true;
    Record::SyncConfigs();

    return true;
}

It causes a crash:
Code: [Select]
_ZN10soundtouch16FIFOSampleBuffer14receiveSamplesEPsjThis is all that is in my log, I use NDK and it is not very inclined to provide a detailed trace. I also can’t use debugging because I can’t repeat this crash on my device.
By disabling parts of the code, we managed to find out that the function affects the crash
Code: [Select]
BASS_RecordStart
I will be glad to any ideas

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Crash Android
« Reply #1 on: 12 Sep '23 - 14:02 »
It causes a crash:
Code: [Select]
_ZN10soundtouch16FIFOSampleBuffer14receiveSamplesEPsj

I don't see it mentioned in the posted code, but that crash location looks like you're also using the SoundTouch library? If so, does removing/disabling that stuff provent the crash happening? If it does, the next thing to check is your SoundTouch function call parameters, in particular the "putSamples" function calls.

You could also try using the BASS_FX add-on instead of the SoundTouch library directly. Its tempo functions (eg. BASS_FX_TempoCreate) are based on the SoundTouch library.

egor

  • Guest
Re: Crash Android
« Reply #2 on: 12 Sep '23 - 14:09 »
no, I don’t use soundtouch, and I don’t even know what it is. Perhaps it is used by the device firmware? If so, is there a way to disable it?
The problem went away when I changed the frequency to 44100 (it was 48000, I thought I needed the same frequency as the opus). But I'm not sure that this is the right decision and it won't entail anything

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Crash Android
« Reply #3 on: 12 Sep '23 - 14:53 »
The SoundTouch library is for changing the tempo/pitch (also BPM detection).

Where exactly are you seeing the "_ZN10soundtouch16FIFOSampleBuffer14receiveSamplesEPsj" symbol? If it's in a crash backtrace/callstack then that should also show what library the symbol is in. Please post the entire crash report from logcat to have a look at. If you can't reproduce the crash yourself then perhaps the affected user can provide that info using "adb logcat -b crash". If they don't already have adb, they can get it from here:

   https://developer.android.com/tools/releases/platform-tools

egor

  • Guest
Re: Crash Android
« Reply #4 on: 12 Sep '23 - 19:37 »
I see an error in firebase, custom stack trace. It's not very informative... But I'm 1000% sure that I don't have soundtouch.



I can also attach the native stacktrace crashlytics, but personally I’m not familiar with it at all
https://pastebin.com/T3Ardj01

Ian @ un4seen

  • Administrator
  • Posts: 25626
Re: Crash Android
« Reply #5 on: 13 Sep '23 - 12:25 »
The library paths aren't included but that native stacktrace does suggest that libsoundtouch.so is called by libaudioclient.so, which is a system library, so perhaps libsoundtouch.so is too. I don't think I've seen that before (not that I've been looking for it), so perhaps it's a custom firmware? Are you in contact with the affected user to be able to confirm what they have?