Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash on Samsung Galaxy Note 20 #1126

Closed
ashfaq-opn opened this issue Dec 4, 2020 · 6 comments
Closed

Crash on Samsung Galaxy Note 20 #1126

ashfaq-opn opened this issue Dec 4, 2020 · 6 comments
Assignees
Labels
Samsung specific to Samsung devices

Comments

@ashfaq-opn
Copy link

I am getting a crash in Samsung Galaxy Note 20 when closing an output stream. The crash dump is given below.

The stack trace obtained using Address Sanitiser doesn't show any line from my code as source of the crash. The lines specified are from inside oboe code itself.

What can be the reason of this crash? If it is inside oboe, how I can avoid crashing the app?

2020-12-04 18:41:03.687 28404-28404/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2020-12-04 18:41:03.687 28404-28404/? A/DEBUG: Build fingerprint: 'samsung/c1sxxx/c1s:10/QP1A.190711.020/N981BXXU1ATJ1:user/release-keys'
2020-12-04 18:41:03.687 28404-28404/? A/DEBUG: Revision: '23'
2020-12-04 18:41:03.688 28404-28404/? A/DEBUG: ABI: 'arm64'
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: Timestamp: 2020-12-04 18:41:03+0700
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: pid: 26835, tid: 28389, name: Thread-10 >>> com.bluehub.fastmixer <<<
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: uid: 10784
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: x0 0000000000000000 x1 0000000000006ee5 x2 0000000000000006 x3 0000005d1e4dbb20
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: x4 00803d35203e6e45 x5 00803d35203e6e45 x6 00803d35203e6e45 x7 354d5553595dff6a
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: x8 00000000000000f0 x9 20f3cc414ac2e290 x10 0000000000000001 x11 0000000000000000
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: x12 fffffff0fffffbdf x13 0000000000000004 x14 0000000000000001 x15 ffffffffffffffff
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: x16 0000007e1990c8c0 x17 0000007e198e9940 x18 0000005d1238e000 x19 00000000000068d3
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: x20 0000000000006ee5 x21 00000000ffffffff x22 0000007e1d731ef0 x23 0000005d8d5272d5
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: x24 0000005d8d52837b x25 0000005d8d557530 x26 0000000000000001 x27 0000005d8d557c30
2020-12-04 18:41:03.689 28404-28404/? A/DEBUG: x28 0000000000000000 x29 0000005d1e4dbbc0
2020-12-04 18:41:03.690 28404-28404/? A/DEBUG: sp 0000005d1e4dbb00 lr 0000007e1989e108 pc 0000007e1989e134
2020-12-04 18:41:03.693 28404-28404/? A/DEBUG: backtrace:
2020-12-04 18:41:03.693 28404-28404/? A/DEBUG: #00 pc 0000000000083134 /apex/com.android.runtime/lib64/bionic/libc.so (abort+160) (BuildId: f89dc12fdaab6218ce150d0882ab21bc)
2020-12-04 18:41:03.693 28404-28404/? A/DEBUG: #1 pc 000000000001c02c /system/lib64/libaaudio.so (__cfi_check_fail+24) (BuildId: e7bd587284ef213ad2cec523911b4154)
2020-12-04 18:41:03.693 28404-28404/? A/DEBUG: #2 pc 000000000002051c /system/lib64/libaaudio.so (__cfi_check+5404) (BuildId: e7bd587284ef213ad2cec523911b4154)
2020-12-04 18:41:03.693 28404-28404/? A/DEBUG: #3 pc 0000000000046da8 /apex/com.android.runtime/bin/linker64 (_dl__ZN15CFIShadowWriter7CfiFailEmPvS0_S0+124) (BuildId: 15e5a4c71e35e376b9e854697f04e72b)
2020-12-04 18:41:03.693 28404-28404/? A/DEBUG: #4 pc 0000000000001144 /apex/com.android.runtime/lib64/bionic/libdl.so (__cfi_slowpath+64) (BuildId: ee5a54c32874d345e4d2f02a4cbace8a)
2020-12-04 18:41:03.693 28404-28404/? A/DEBUG: #5 pc 0000000000033d90 /system/lib64/libaaudio.so (aaudio::AudioStreamInternalPlay::callbackLoop()+416) (BuildId: e7bd587284ef213ad2cec523911b4154)
2020-12-04 18:41:03.694 28404-28404/? A/DEBUG: #6 pc 000000000001d308 /system/lib64/libaaudio.so (AudioStream_internalThreadProc(void*) [clone .cfi]+224) (BuildId: e7bd587284ef213ad2cec523911b4154)
2020-12-04 18:41:03.694 28404-28404/? A/DEBUG: #7 pc 00000000000e28e0 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: f89dc12fdaab6218ce150d0882ab21bc)
2020-12-04 18:41:03.694 28404-28404/? A/DEBUG: #8 pc 000000000008503c /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: f89dc12fdaab6218ce150d0882ab21bc)

@philburk
Copy link
Collaborator

philburk commented Dec 4, 2020

Here are some questions from our bugreport template. Answering them will help us diagnose the problem.

Android version(s):
Oboe version:

Also, how easily can you reproduce the crash? Is it frequent or rare?

Are you using a ManagedStream or a std:shared_ptr when opening the stream?

That crash can be caused by deleting the OboeStream while the callback was still running.
On some versions of Android, in some circumstances, the callback stream could still be running when the close occurred.

We have some simple workarounds in Oboe 1.5.0 to prevent this. Please try oboe 1.5.0 and let us know if they work.

@philburk philburk self-assigned this Dec 4, 2020
@ashfaq-opn
Copy link
Author

ashfaq-opn commented Dec 4, 2020

Thank you for replying :)

I got this crash on Android 10 (One UI), but in other Android 11 phone I got similar crash too.
I pulled the latest master of oboe today. So oboe version is 1.5.0.

The crash is not very frequent but not rare too. It happens for example once in every 4-5 runs.

I am using a managed stream. Creating it in this way,

class BaseStream {
public:
    BaseStream(params...);

    oboe::AudioStream* stream = nullptr;

    virtual void startStream();
    void stopStream();

    // I am taking precaution in the implementation that if the stream has already been closed before closing it
    void closeStream() {
      if (stream &&
        stream->getState() != oboe::StreamState::Closing &&
        stream->getState() != oboe::StreamState::Closed) {
          oboe::Result result = stream->close();
          
          // I am being over-protective here. I got frustrated with the crash and tried many things.
          oboe::StreamState inputState = oboe::StreamState::Closing;
          oboe::StreamState nextState = oboe::StreamState::Uninitialized;
          int64_t nanosecondsPerMillisecond = 1000000;
          int64_t timeoutNanos = 100 * nanosecondsPerMillisecond;
          // May be over protective here as well
          if (!stream) return;

          stream->waitForStateChange(inputState, &nextState, timeoutNanos);

          if (result != oboe::Result::OK) {
            LOGE(TAG, "Error closing stream. %s", oboe::convertToText(result));
          } else {
            stream = nullptr;
          }
      }
    }
};

class PlaybackStream(params): BaseStream(params) {
  void openPlaybackStream() {
    ... Construct the builder
    oboe::Result result = builder.openStream(&stream);
    if (result == oboe::Result::OK && stream) {
        ... Do stuffs
        int32_t mFramesPerBurst = stream->getFramesPerBurst();
        stream->setBufferSizeInFrames(mFramesPerBurst);
    }
  }
}

I am a noob in the area to be honest, trying to learn by implementing a performant application. If this is wrong and any better way is there, please point me. I will remain very grateful.

I tried in 1.5.0 already (latest master - as submodule).

@ashfaq-opn
Copy link
Author

ashfaq-opn commented Dec 4, 2020

Another thing, In my callback I am doing like below,

class PlaybackStream: public BaseStream, public oboe::AudioStreamDataCallback, public oboe::AudioStreamErrorCallback {
  oboe::DataCallbackResult
  PlaybackStream::onAudioReady(oboe::AudioStream *audioStream, void *audioData,
                               int32_t numFrames) {
    return processPlaybackFrame(audioStream, static_cast<float_t *>(audioData), numFrames, audioStream->getChannelCount());
  }

  oboe::DataCallbackResult
  PlaybackStream::processPlaybackFrame(oboe::AudioStream *audioStream, float *audioData,
                                       int32_t numFrames, int32_t channelCount) {
    // Inside read playback I am filling-up the audioData buffer with decoded frames from a wav file
    mRecordingIO->read_playback(audioData, numFrames, channelCount);
    return oboe::DataCallbackResult::Continue;
  }
}

Instead of this, if I do like below, will I get saved?

oboe::DataCallbackResult
PlaybackStream::processPlaybackFrame(oboe::AudioStream *audioStream, float *audioData,
                                       int32_t numFrames, int32_t channelCount) {
    // Check if the stream is not a nullptr and it is already NOT closed
    if (stream && stream->getState() != oboe::StreamState::Closed) {
      mRecordingIO->read_playback(audioData, numFrames, channelCount);
      return oboe::DataCallbackResult::Continue;
    } else {
      // ** what should I return?
    }
  }

@philburk
Copy link
Collaborator

philburk commented Dec 4, 2020

I am using a managed stream.
oboe::AudioStream* stream = nullptr;

That is a raw stream. A ManagedStream is a specific class.
We now recommend using a shared stream. See Issue #820 and #953

    std::shared_ptr<oboe::AudioStream> mStream;

See

std::shared_ptr<oboe::AudioStream> mStream;

There is no point in calling waitForStateChange() after closing the stream. It won't change.

Does this mostly happen when plugging in or unplugging headphones?

@philburk
Copy link
Collaborator

philburk commented Dec 4, 2020

I got this crash on Android 10 (One UI), but in other Android 11 phone I got similar crash too.

Were they both Samsung Note 20? Do you have other phones you could try? This is probably not specific to the Note 20.

@ashfaq-opn
Copy link
Author

@philburk With your kind suggestion I could solve this issue. I followed the code in HelloOboeEngine and also in some places I was setting a shared pointer to null instead of resetting them. Doing these solved the issue. It was for all devices, not for note 20 only. Thank you very much for your kind help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Samsung specific to Samsung devices
Projects
None yet
Development

No branches or pull requests

2 participants