alnitak / flutter_soloud

Flutter low-level audio plugin using SoLoud C++ library and FFI
MIT License
221 stars 23 forks source link

VS Code: Lost connection to device. #125

Open FluffyBunniesTasteTheBest opened 2 months ago

FluffyBunniesTasteTheBest commented 2 months ago

Thank you very much for providing flutter_soloud.

Description

When running the app on an Android (12, 13, 14) device, it occassionally happenes that VS Code loses the connection to the device while the app is starting. If the connection gets lost, debug console shows the following:

I/flutter (29412): 2024-09-01 13:06:03.185783: FINEST: flutter_soloud.SoLoud: init() called
D/ven.awesome(29412): PlayerBase::PlayerBase()
D/ven.awesome(29412): TrackPlayerBase::TrackPlayerBase()
I/libOpenSLES(29412): Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
D/AudioTrack(29412): INSP: type=audio,case=1,set=0xb40000706725a230,stream_type=3,sample_rate=44100,format=0x5,channel_mask=0x3,frame_count=0,flags=0x104,notification_frames=-3,session_id=369,transfer_type=0,uid=-1,pid=-1
D/AudioTrack(29412): set(): 0xb40000706725a230, Create AudioTrackThread, tid = 29466
D/AudioTrack(29412): createTrack_l(0): AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 0 -> 1418
D/AudioTrack(29412): createTrack_l(46): 0xb40000706725a230, mCblk = 0x7204554000, mLatency = 74, mAfLatency = 42, frameCount = 1418, mSampleRate = 44100, mFlags = 0, mReqFrameCount = 1418, mNotificationFramesAct = 472
D/AudioTrack(29412): start(46): 0xb40000706725a230, prior state:STATE_STOPPED
D/ven.awesome(29412): PlayerBase::stop() from IPlayer
D/AudioTrack(29412): stop(46): 0xb40000706725a230, prior state:STATE_ACTIVE
D/AudioTrack(29412): stop(46): called with 0 frames delivered
D/AudioTrackShared(29412): this(0xb40000700725ab90), mCblk(0x7204554000), front(0), mIsOut 1, interrupt() FUTEX_WAKE
D/AudioTrack(29412): stop(46): 0xb40000706725a230 stop done
D/AudioTrack(29412): start(46): 0xb40000706725a230, prior state:STATE_STOPPED
I/flutter (29412): 2024-09-01 13:06:03.482217: FINEST: flutter_soloud.SoLoudLoader_io: initialize() called
I/flutter (29412): 2024-09-01 13:06:03.618966: FINEST: flutter_soloud.FlutterSoLoudFfi: STATE CHANGED EVENT state: PlayerStateNotification.started
I/flutter (29412): 2024-09-01 13:06:03.630874: INFO: flutter_soloud.SoLoudLoader_io: Temporary directory initialized at /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files
E/BLASTBufferQueue(29412): [SurfaceView[com.supermega.awesome_app/com.supermega.awesome_app.MainActivity]#1](f:0,a:2) isEGL=1, mPendingRelease.size()=1, mMaxAcquiredBuffers=4, currentMaxAcquiredBufferCount=2
E/BLASTBufferQueue(29412): [SurfaceView[com.supermega.awesome_app/com.supermega.awesome_app.MainActivity]#1](f:0,a:3) isEGL=1, mPendingRelease.size()=2, mMaxAcquiredBuffers=4, currentMaxAcquiredBufferCount=2
I/flutter (29412): 2024-09-01 13:06:10.547654: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 2006529388  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x25ea5d95
I/flutter (29412): 2024-09-01 13:06:13.471286: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 1893300200  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x13f3cb8f
I/flutter (29412): 2024-09-01 13:06:15.805302: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 179615633  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x1c64a24a
I/flutter (29412): 2024-09-01 13:06:18.077289: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 1603303707  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x3a8643a1
Lost connection to device.

Exited.

First time this got noticed was after upgrading from version 2.0.2 to 2.1.1. With the current 2.1.2 version it happens so frequently that it impacts work, hence downgrading to 2.0.2 was necessary.

Expected Behavior

The connection to VS Code's debugger shouldn't be closed.

Additional Context

Another thing, that could be related to it, is that in debug build, it sometimes takes up to half a minute until the app finishes loading the audio files. In release builds it works fine though and the same files are loaded in about a second.

Could this be related to the content of the (ogg) audio files? If the app starts, they are playing just fine though...

Sorry for not being able to provide any more details, but I thought you might be interested in knowing about it anyway.

alnitak commented 2 months ago

Hi @FluffyBunniesTasteTheBest, thanks for reporting your findings.

This issue seems related to the closed #122, but seems something similar is happening here. I have made a new branch and I am asking you to help me see if the problem is gone. Please, could you try replacing this line in your pubspec.yaml

  flutter_soloud: ^2.1.2

with this:

  flutter_soloud:
    git:
      url: https://github.com/alnitak/flutter_soloud
      ref: crash

Another thing, that could be related to it, is that in debug build, it sometimes takes up to half a minute until the app finishes loading the audio files. In release builds it works fine though and the same files are loaded in about a second.

I think this should be fixed too.

Thanks

FluffyBunniesTasteTheBest commented 2 months ago

@alnitak Thank you very much for the fast response!

The connection to the debugger stays now active.

However, during the first start, the app was stuck for longer than a minute at "Installing profile". Here's a log from the first app start on an Android 13 device after updating to the github version:

I/flutter (23129): 2024-09-02 11:23:41.930134: FINEST: flutter_soloud.SoLoud: init() called
I/mali_gralloc(23129): register: id=0x35c00001aa6, importpid=-1
I/mali_gralloc(23129): register: id=0x35c00001aa7, importpid=-1
D/ven.awesome_app(23129): PlayerBase::PlayerBase()
D/ven.awesome_app(23129): TrackPlayerBase::TrackPlayerBase()
I/libOpenSLES(23129): Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
I/AudioTrack(23129): set(): streamType 3, sampleRate 44100, format 0x5, channelMask 0x3, frameCount 0, flags #104, notificationFrames -3, sessionId 3753, transferType 0, uid -1, pid -1
D/AudioTrack(23129): set(): UNISOC add HIFI flags, flags = #2105
W/Parcel  (23129): Expecting binder but got null!
I/AudioTrack(23129): createTrack_l(112): AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 0 -> 1772
2
W/ziparchive(23129): Unable to open '/system_ext/framework/unipnp-framework.dm': No such file or directory
I/AudioTrack(23129): start(304): prior state:STATE_STOPPED
I/mali_gralloc(23129): register: id=0x35c00001aa8, importpid=-1
I/mali_gralloc(23129): register: id=0x35c00001aa9, importpid=-1
D/ven.awesome_app(23129): PlayerBase::stop() from IPlayer
I/AudioTrack(23129): stop(304): prior state:STATE_ACTIVE
D/AudioTrack(23129): stop(304): called with 0 frames delivered
I/AudioTrack(23129): start(304): prior state:STATE_STOPPED
2
W/AidlConversion(23129): aidl2legacy_AudioChannelLayout_audio_channel_mask_t: no legacy output audio_channel_mask_t found for AudioChannelLayout{layoutMask: 16}
I/flutter (23129): 2024-09-02 11:23:42.333837: FINEST: flutter_soloud.SoLoudLoader_io: initialize() called
I/flutter (23129): 2024-09-02 11:23:42.393586: FINEST: flutter_soloud.FlutterSoLoudFfi: STATE CHANGED EVENT state: PlayerStateNotification.started
I/flutter (23129): 2024-09-02 11:23:42.425001: INFO: flutter_soloud.SoLoudLoader_io: Temporary directory initialized at /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files
I/mali_gralloc(23129): register: id=0x35c00001aaa, importpid=-1
D/CompatibilityChangeReporter(23129): Compat change id reported: 78294732; UID 10284; state: ENABLED
D/ProfileInstaller(23129): Installing profile for com.supermega.awesome_app

After about two minutes, I've uninstalled the app and retried again. At the third attempt it finished loading after 79 seconds:

I/flutter (27683): 2024-09-02 11:47:35.256598: FINEST: flutter_soloud.SoLoud: init() called
D/ven.awesome_app(27683): PlayerBase::PlayerBase()
D/ven.awesome_app(27683): TrackPlayerBase::TrackPlayerBase()
I/libOpenSLES(27683): Emulating old channel mask behavior (ignoring positional mask 0x3, using default mask 0x3 based on channel count of 2)
I/AudioTrack(27683): set(): streamType 3, sampleRate 44100, format 0x5, channelMask 0x3, frameCount 0, flags #104, notificationFrames -3, sessionId 3825, transferType 0, uid -1, pid -1
D/AudioTrack(27683): set(): UNISOC add HIFI flags, flags = #2105
I/AudioTrack(27683): createTrack_l(112): AUDIO_OUTPUT_FLAG_FAST denied by server; frameCount 0 -> 1772
I/AudioTrack(27683): start(313): prior state:STATE_STOPPED
D/ven.awesome_app(27683): PlayerBase::stop() from IPlayer
I/AudioTrack(27683): stop(313): prior state:STATE_ACTIVE
D/AudioTrack(27683): stop(313): called with 0 frames delivered
I/AudioTrack(27683): start(313): prior state:STATE_STOPPED
W/AidlConversion(27683): aidl2legacy_AudioChannelLayout_audio_channel_mask_t: no legacy output audio_channel_mask_t found for AudioChannelLayout{layoutMask: 16}
I/flutter (27683): 2024-09-02 11:47:35.366746: FINEST: flutter_soloud.SoLoudLoader_io: initialize() called
I/mali_gralloc(27683): register: id=0x35c00001b67, importpid=-1
I/flutter (27683): 2024-09-02 11:47:35.443502: FINEST: flutter_soloud.FlutterSoLoudFfi: STATE CHANGED EVENT state: PlayerStateNotification.started
I/flutter (27683): 2024-09-02 11:47:35.447625: INFO: flutter_soloud.SoLoudLoader_io: Temporary directory initialized at /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files
I/mali_gralloc(27683): register: id=0x35c00001b68, importpid=-1
D/ProfileInstaller(27683): Installing profile for com.supermega.awesome_app
I/flutter (27683): 2024-09-02 11:48:54.745632: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 2006529388  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x25ea5d95
I/flutter (27683): 2024-09-02 11:48:57.567863: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 1893300200  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x13f3cb8f
I/flutter (27683): 2024-09-02 11:49:00.465546: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 179615633  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x1c64a24a
I/flutter (27683): 2024-09-02 11:49:03.329465: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 1603303707  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x3a8643a1
I/flutter (27683): 2024-09-02 11:49:06.233570: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 1147862653  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x1fa37b1b
I/flutter (27683): 2024-09-02 11:49:09.107898: FINEST: flutter_soloud.FlutterSoLoudFfi: FILE LOADED EVENT error: noError  hash: 744767824  file: /data/user/0/com.supermega.awesome_app/cache/SoLoudLoader-Temp-Files/temp-sound-asset-0x2c952218
I/flutter (27683): 2024-09-02 11:49:09.114917: INFO: SuperMegaAwesomeApp bootup: Audio files loaded

Once the app went through the complete initialization, subsequent starts finished the audio setup in less than two seconds:

I/flutter (22065): 2024-09-02 12:23:56.710325: FINEST: flutter_soloud.SoLoudLoader_io: initialize() called
...
/flutter (22065): 2024-09-02 12:23:58.045086: INFO: SuperMegaAwesomeApp bootup: Audio files loaded

All this happened in debug builds running on Android 12 and 13 devices.

BTW, is there a way to wipe all data from flutter_soloud?

Again, thank you very much for your help.

alnitak commented 2 months ago

Even if I think the delay you are experiencing is a way a lot of time, probably is it due to loading big audio files? Would really help a lot to have a minimal example (ie just the SoLoud.init() and no third-party packages) with the OGGs files you used.

I know that out there there are OGG files with non standard header files that could cause errors when loading, but anyway, my suggestion is to try loading audio with mode: LoadMode.disk parameter. Without that the whole audio is decompressed and stored into memory and this takes its time. If you don't need to use the seek functionality, this is probably the best option for loading a file which is really fast.

BTW, is there a way to wipe all data from flutter_soloud?

The only data that flutter_soloud stores, are the cached audio files. You can pass the automaticCleanup = true parameter to the init() method to clean up cached files.

Please, you are welcome to post any thoughts!

FluffyBunniesTasteTheBest commented 2 months ago

@alnitak Again, thanks for your help. Much appreciated!

The files are all rather short - the longest is about 20 seconds.

I'll try to create a minimum example, but it will take a while - the app uses 50+ packages and they have to be remove one after another, as it could be that another package is related to it. Beside that, I'm on my (very much deserved) vacation this week. ;-)

Please give me some time...

alnitak commented 2 months ago

Sure! Take your time.

I think that if you start a new project from scratch it will be relatively faster! :) Just something like:

1. init SoLoud
2. load all OGGs file synchronously
3. play one of them

Just to be sure it's a flutter_soloud problem and not one of the other 49!