This message was deleted.
# helpdesk
s
This message was deleted.
e
hmm I’ll have to look into this, can you file a bug on github?
for your app, are you using the same room every time or recreating a new room?
l
I have one single room which works as factory for audio video tracks. The reason why I'm doing it, it's that I need audio/video data for multiple reasons such as AI or RTSP streaming + app can be in a call or working as a web camera over WebRTC. Also to achieve this I had to modify a little bit sdk to have shared Egl Context, otherwise it was causing crashes. So to sumarize: 1 room which is created once and has while app lifetime and works as audio video tracks factory, and other rooms which are created and destroyed every time when app joins a call or starts/stop working as Web camera over webrtc
@eager-raincoat-52616 I thought there is some problems caused by me, but I see similar behavior on livekit samples where after first join native memory is increased and then after each connect/disconnect it increases by 1 - 2 mb. This chart what I sent it's from livekit compose sample
e
gotcha, that’s helpful to know
l
Hi @eager-raincoat-52616 Tried your changes and don't see any memory leaks. It always returns to 63mb or native usage in debug mode. One think I see what helped with it it's rtcTransport.dispose instead of close. It's working fine when we have only 1 room in application. But when we have a a few rooms simultiniously it's causing crash. I reported it in one of the PR you have created
e
Hey I pushed some changes to fix the crash today, did you test latest?
l
Yes
@eager-raincoat-52616 Maybe it can be related to dagger it still keeps some refs to native object if one room closed but another still exists
e
the crash you reported was before this fix though: https://github.com/livekit/client-sdk-android/pull/307
dagger shouldn’t have anything to do with it, those are self contained within each Room object
l
Yes. This one is fixed
Do you have any ideas why it may happen if we have two active rooms ?
e
multiple rooms should be fine, we have e2e tests running multiple rooms at once on the device and haven’t seen anything there
l
And two rooms can use the same video camera ?
e
no, that’s an android limitation. you’d have to create your own video camera track and share that across rooms
l
Yes. And for this I have separate room which works as factory for audio video tracks. Let me create a repository on GitHub with reproducible error
e
sorry, is this a separate issue from the memory fix, or related to it?
l
I think related, because if use rtc transport close, it still working but I see some small memory leaks as before. Transport destroy fixed it but caused app crashed when we have multiple room
e
ah, the track gets disposed when the room is released
I can add in an option to not dispose the track on release
l
Btw, for this I also have created extra feature with shared egl base as we have track created by one room it cannot be rendered by another
e
would you mind uploading a pr for that?
l
Ok. Let me create a fork from sdk with shared egl base and reproducible error
@eager-raincoat-52616 You mean this code ? > ah, the track gets disposed when the room is released
@eager-raincoat-52616 Was able to reproduce it https://github.com/serrg1994/client-sdk-android/blob/reproducing-crasing-on-dispos[…]common/src/main/java/io/livekit/android/sample/CallViewModel.kt . I created separate room which can be shared and be as audio/video tracks factory. Room which connects to the call publishes tracks created by shared room. If I replace peerConnection.dispose() by peerConnection.close() app is not crashing. But it has memory leaks. Also you can see I created shared EglBase https://github.com/serrg1994/client-sdk-android/blob/reproducing-crasing-on-dispos[…]t-android-sdk/src/main/java/io/livekit/android/EglBaseShared.kt And updated RTCModule to use this EglBase https://github.com/serrg1994/client-sdk-android/blob/reproducing-crasing-on-dispos[…]ndroid-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt Regarding EglBase it still may produce memory leaks if shared room will be always alive and other rooms will be using it for drawing video on the screen. If all rooms are closed then, egl base also will be released. Do you know, maybe there are some other ways to clean memory not to releasing egl base ? For example device can be used as web camera over WebRTC and it will running 24/7, also the same app may connect/disconnect to video calls which means Eglbase will not be released and we still will have memory leaks due to egl base, which means after some certain time app may be crashed
e
ah, gotcha. in that case I’ll add an option in LiveKitOverrides for you to pass in your shared EglBase
you’ll have to manage the memory for that
l
Ok. Thanks. Did you try my example to reproduce a crash ?
e
haven’t had a chance to test it out, but I can see how passing a disposed track to webrtc might cause crashes
Alternatively, instead of having a “factory room”, which is kind of weird, maybe you should just create the camera capturer with
CameraCapturerUtils
and then create tracks based on that shared capturer
l
Hmm. Let me try it
Does it requires EglBase internally?
e
it does not
l
Ok. I did not try it yet, but looks like I have to add some custom track factory to create video tracks with shared EglBase, as only Local participant has public method to create tracks
e
you can pass in your video capturer into
LocalParticipant.createVideoTrack
👍 1
l
@eager-raincoat-52616 Tried on sample project. Yes, I was able to use capture in a single room, and it did not crash when other room existed. But as I see I cannot share capturer across multiple rooms or for example take video frames when no active rooms for AI anaylizer or so. When I tried to create one more track for second room after first published it was giving me an error. Also I don't see any way how to share audio tracks accross rooms
@eager-raincoat-52616 I just played with sample app and created shared video source but for this had to modify LocalVideo track. Also tried to create two rooms which create it's own video tracks based on shared source. Also I see that I don't have to create rooms when I just want to use AI model, when no room is active. Do you see any potential issues with it ?
Unfortunately it still was crashing sometimes, when it was two active rooms and one got disconnected ( When we had our own media server I was working fine. With no limits. Hmmm, what if overlay peer connection factory to have it shared for all room which are active in this period of time
@eager-raincoat-52616 So If working with one room with custom capturer it's working fine, but when I have two rooms active and another is closed, app crashes
Hi. @eager-raincoat-52616. Looks like I found a problem why is was crashing on my scenario. So. Local Video an Audio tracks are storing transceivers created by peerConnection as as peer connection is disposed it was creating a crash. I added a method to clear a transceiver and on unpublish track if does not have to stopped I clear this transceiver. It was working fine when android device was stopping room as I unpublish tracks before disconnect. But it was crashed when call was finished on other side. To solve I put engine.close() in the end to let tracks to be cleared and transcievers also be disposed. and it worked. Now I have to think how to implement in a case if I have two active rooms. Looks like Local Tracks instead of single transceiver should be able to keep multiple from different rooms.
@eager-raincoat-52616 It's working fine for me once I moved transceivers from local tracks to LocalParticipant. It allows me to have multiple connected rooms and stopping one does not cause crash of another. But sometimes randomly app still can crash when last room was released and I cannot find a pattern (. Looks like 10 calls can be fine and 11th will crash app in the end. As I'm using audio in calls can it be related to audio module somehow ? It gives me this error. releasing NetworkRequest [ REQUEST id=366, [ Transports: CELLULAR Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN Uid: 10182 AdministratorUids: [] RequestorUid: 10182 RequestorPackageName: com.company.videostream] ] (release request) 2023-11-09 005645.645 21864-21929 libc com.company.videostream A Pointer tag for 0x6fe0446a30 was truncated. 2023-11-09 005645.646 21864-21929 libc com.company.videostream A Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 21929 (DefaultDispatch), pid 21864 (ert.videostream) 2023-11-09 005645.671 21864-21864 Video Entry 0 com.company.videostream I Stop capture LiveKitCallEnginea8976bf3-ea23-4aec-988f-29163209cc6d 2023-11-09 005645.671 21864-21864 Video Entry 0 com.company.videostream D Stop Local Video track 2023-11-09 005645.672 21864-21864 LocalVideoTrack com.company.videostream I dispose 2023-11-09 005645.672 21864-21864 LocalTrack com.company.videostream I Dispose 2023-11-09 005645.798 25153-25153 DEBUG pid-25153 A pid: 21864, tid: 21929, name: DefaultDispatch >>> com.company.videostream <<< 2023-11-09 005645.800 25153-25153 DEBUG pid-25153 A #02 pc 0000000000412dac /data/app/~~fm3Ye13lV0S6RQoltz6pdw==/com.company.videostream-zRqP6XfMs7VjaYGLCP3UVw==/base.apk!libjingle_peerconnection_so.so (offset 0x3fb2000) (BuildId: c975344a93956e4f) Do you know where can be issue ? Maybe there are left some other webrtc entries, which were not cleared ? Thanks
e
hey, circling back to this, I think I’m going to have to revert some of the memory cleanup changes, there were a lot of side-effects causing crashes. I’m going to aim for a full fix in the coming weeks
👍 1
l
@eager-raincoat-52616 Hi. Is there any updated regarding memory leaks app crashing after changing peerConnection.dispose instead of close ?
e
@loud-jewelry-13301 almost ready to push the fix, need to really make sure it doesn’t cause issues like last time
l
@eager-raincoat-52616 Nice to hear 🔥
e
l
@eager-raincoat-52616 Hi. I see you released 1.6.0 version. You think now I can go and update my app with this version? It should not have to have any issue with peer connection destroy, Right ?
e
@loud-jewelry-13301 yeah, this shouldn’t have any issues with the peer connection destroy
🔥 1