RootEncoder icon indicating copy to clipboard operation
RootEncoder copied to clipboard

RTMP connection disconnects when mobile Hotstop with low internet connection(500-1000kpbs)

Open penmatsa opened this issue 5 months ago • 12 comments

Hi,

RTMP connection completely disconnects with low internet conditions.

Video settings: Width : 1280 Height: 720 FPS:30

H264,ACC codecs

library version : 2.5.5

penmatsa avatar Aug 07 '25 17:08 penmatsa

Hello,

How are you doing to limit the bandwidth?

pedroSG94 avatar Aug 11 '25 20:08 pedroSG94

Hi @pedroSG94

we are testing with different distance of hotspot but when network speed reaches(500-1000kpbs) RTMP connection is disconnected.Internet connection is low but not disconnected.

This occurs only with 4g speeds or low internet hotspots.

Thanks

penmatsa avatar Aug 12 '25 18:08 penmatsa

It is really difficult to say because I don't have a way to reproduce it. You can try use java socket to check if you have any change, but normally, if the stream disconnect using RTMP it is because you are losing the connection to the server. Maybe only 1 second but if the library fail to send packets because the connection is lost. The stream is disconnected.

Can you guide me a way to reproduce your case?

pedroSG94 avatar Aug 13 '25 19:08 pedroSG94

Hi @pedroSG94

Getting socket Time out Exception in below method when using low 4g mobile Hotspot (Not Wifi Hotspot)

Class : RtmpSender

override suspend fun onRun() { while (scope.isActive && running) { val error = runCatching { val mediaFrame = runInterruptible { queue.take() } getFlvPacket(mediaFrame) { flvPacket -> var size = 0 if (flvPacket.type == FlvType.VIDEO) { videoFramesSent++ socket?.let { socket -> size = commandsManager.sendVideoPacket(flvPacket, socket) if (isEnableLogs) { Log.i(TAG, "wrote Video packet, size $size") } } } else { audioFramesSent++ socket?.let { socket -> size = commandsManager.sendAudioPacket(flvPacket, socket) if (isEnableLogs) { Log.i(TAG, "wrote Audio packet, size $size") } } } bytesSend += size } }.exceptionOrNull() if (error != null) { onMainThread { connectChecker.onConnectionFailed("Error send packet, ${error.validMessage()}") } Log.e(TAG, "send error: ", error) running = false return } } }

Can we add timeout for RtmpSocket connection???

Thanks.

penmatsa avatar Aug 22 '25 14:08 penmatsa

It is really difficult to say because I don't have a way to reproduce it. You can try use java socket to check if you have any change, but normally, if the stream disconnect using RTMP it is because you are losing the connection to the server. Maybe only 1 second but if the library fail to send packets because the connection is lost. The stream is disconnected.

Can you guide me a way to reproduce your case?

Hi

To Reproduce above issue Please connect 4G phone with SIM internet ON and place at particulat distance when Internet speed reaches with range of (500-1500kpbs).

Cant find any tool to mimic 4g Sim Hotspot.

Thanks.

penmatsa avatar Aug 22 '25 15:08 penmatsa

Hi @pedroSG94,

Please find the github link for RTMP streaming comparison of both library Rootencoder and Simple RTMP.

Link: https://github.com/penmatsa/RTMPSample

When using low networking 4G Hotspot Rootencoder disconnects sharply but Simple RTMP just wait to connection to stabilize.

Thanks

penmatsa avatar Sep 18 '25 13:09 penmatsa

Ok, the problem is that in Simple RTMP you haven't a timeout. In this library the timeout is 5s: https://github.com/pedroSG94/RootEncoder/blob/master/common/src/main/java/com/pedro/common/socket/base/StreamSocket.kt#L31 I can create a method to change the timeout in the socket

pedroSG94 avatar Sep 19 '25 08:09 pedroSG94

Hi @pedroSG94 ,

Comparing socket code for both library we found same timeout(5000),we think its not timeout made the difference.

Please find the attchments below

Simple RTMP Image

RootEncoder Image

Thanks.

penmatsa avatar Sep 19 '25 17:09 penmatsa

It is not the same, only connect method has timeout in simple rtmp In my case I have timeout in write and read commands too

pedroSG94 avatar Sep 19 '25 17:09 pedroSG94

Hi @pedroSG94,

please point to class for custom timeouts in write and read commands.

Adding custom timeout helps use for low internet conditions.

Thanks

penmatsa avatar Sep 22 '25 17:09 penmatsa

Hello,

I already did a commit for it to master. You can do it using this code:

genericStream.getStreamClient().setSocketTimeout(5000L)

pedroSG94 avatar Sep 23 '25 10:09 pedroSG94

Hi @pedroSG94,

Thanks for the support, will try with above code line.

Thank You

penmatsa avatar Sep 23 '25 18:09 penmatsa