pedroSG94 / RootEncoder

RootEncoder for Android (rtmp-rtsp-stream-client-java) is a stream encoder to push video/audio to media servers using protocols RTMP, RTSP, SRT and UDP with all code written in Java/Kotlin
Apache License 2.0
2.53k stars 772 forks source link

Retry issue in case of (multiple RTMP connection - success + failure) #1535

Closed dev-android1 closed 1 month ago

dev-android1 commented 1 month ago

Describe the bug I have an array of RTMP clients with a retry count = 2. I use multiple server e.g. FB, Youtube, ebay Sometime this connection fails for ebay/fb/youtube. I want to retry only for fail connection. First of all I want to know for which URL it was failed and want to reconnect for failed URL only. Please help me how can I resolve this.

To Reproduce

Expected behavior In callbacks I should get URL also when it fails and we should have some property for which I can apply check it is successful or not in retry case.

Screenshots If applicable, add screenshots to help explain your problem.

Smartphone (please complete the following information):

Additional context

dev-android1 commented 1 month ago

I tried to use "isStreaming" property but it is always true even connection failed

pedroSG94 commented 1 month ago

Hello,

You can know which stream throw the callback using a bit of logic. For example:

//Create my own callback to know which stream return the callback
interface ConnectCheckerMultiple {
    fun onConnectionStarted(url: String, index: Int, type: MultiType)
    fun onConnectionSuccess(index: Int, type: MultiType)
    fun onConnectionFailed(reason: String, index: Int, type: MultiType)
    fun onNewBitrate(bitrate: Long, index: Int, type: MultiType)
    fun onDisconnect(index: Int, type: MultiType)
    fun onAuthError(index: Int, type: MultiType)
    fun onAuthSuccess(index: Int, type: MultiType)
}

class test: ConnectCheckerMultiple {

   //create an array of ConnectChecker for each connection type (RTMP, RTSP, SRT, UDP)
    private fun createArray(count: Int, type: MultiType): Array<ConnectChecker> {
        val array = mutableListOf<ConnectChecker>()
        for (i in 0 until count) {
            val connectChecker = object: ConnectChecker {
                override fun onConnectionStarted(url: String) {
                    this@test.onConnectionStarted(url, i, type)
                }

                override fun onNewBitrate(bitrate: Long) {
                    this@test.onNewBitrate(bitrate, i, type)
                }

                override fun onConnectionSuccess() {
                    this@test.onConnectionSuccess(i, type)
                }

                override fun onConnectionFailed(reason: String) {
                    this@test.onConnectionFailed(reason, i, type)
                }

                override fun onDisconnect() {
                    this@test.onDisconnect(i, type)
                }

                override fun onAuthError() {
                    this@test.onAuthError(i, type)
                }

                override fun onAuthSuccess() {
                    this@test.onAuthSuccess(i, type)
                }
            }
            array.add(connectChecker)
        }
        return array.toTypedArray()
    }

   //create arrays to use in for example MultiCamera1 class
    private fun createArrays() {
        val rtmpArray = createArray(3, MultiType.RTMP)
        //Use it in your constructor
    }

    //callbacks of ConnectCheckerMultiple
    override fun onConnectionStarted(url: String, index: Int, type: MultiType) {

    }

    override fun onConnectionSuccess(index: Int, type: MultiType) {

    }

    override fun onConnectionFailed(reason: String, index: Int, type: MultiType) {
      multiCamera1.getStreamClient(type, index).retry(5000, reason, null)
    }

    override fun onNewBitrate(bitrate: Long, index: Int, type: MultiType) {

    }

    override fun onDisconnect(index: Int, type: MultiType) {

    }

    override fun onAuthError(index: Int, type: MultiType) {

    }

    override fun onAuthSuccess(index: Int, type: MultiType) {

    }
}

This code is for the last version of the library

dev-android1 commented 1 month ago

Thanks for response. I will check it.

dev-android1 commented 1 month ago

This worked fine. @pedroSG94 Thanks for your quick support.