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

srtdroid on API 19+ #30

Closed
yoobi opened this issue Jan 11, 2023 · 6 comments
Closed

srtdroid on API 19+ #30

yoobi opened this issue Jan 11, 2023 · 6 comments

Comments

@yoobi
Copy link
Contributor

yoobi commented Jan 11, 2023

Hello,

I'm trying to use your library with minSdk 19 to do that I've cloned the repo change the minSdk of the lib to 19. Everythings works great for API 21+ but it crashs on API 19 with the following stacktrace:

Unexpected error loading stream
java.lang.UnsatisfiedLinkError: dlopen failed: could not load library "libsrt.so" needed by "libsrtdroid.so"; caused by cannot locate symbol "epoll_create1" referenced by "libsrt.so"...
  at java.lang.Runtime.loadLibrary(Runtime.java:365)
  at java.lang.System.loadLibrary(System.java:526)
  at io.github.thibaultbee.srtdroid.Srt.<clinit>(Srt.kt:23)
  at io.github.thibaultbee.srtdroid.models.Socket.<clinit>(Socket.kt:41)
  at io.yoobi.srt.test.SrtLiveStreamDataSource.open(SrtLiveStreamDataSourceFactory.kt:39)
  at com.google.android.exoplayer2.upstream.StatsDataSource.open(StatsDataSource.java:84)
  at com.google.android.exoplayer2.source.ProgressiveMediaPeriod$ExtractingLoadable.load(ProgressiveMediaPeriod.java:1005)
  at com.google.android.exoplayer2.upstream.Loader$LoadTask.run(Loader.java:412)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at java.lang.Thread.run(Thread.java:841)

with SrtLiveStreamDataSourceFactory being:

class SrtLiveStreamDataSourceFactory(
    private val srtUrl: String,
    private val port: Int,
    private val passPhrase: String? = null
): DataSource.Factory {
    override fun createDataSource(): DataSource {
        return SrtLiveStreamDataSource(srtUrl, port, passPhrase)
    }
}

const val PAYLOAD_SIZE = 1316


class SrtLiveStreamDataSource(
    private val srtUrl: String,
    private val port: Int,
    private val passPhrase: String?

): BaseDataSource(true) {

    private var socket: Socket? = null
    private val byteQueue: Queue<Byte> = LinkedList()


    override fun open(dataSpec: DataSpec): Long {
        socket = Socket() // <---- THIS IS LINE 39 
        socket?.setSockFlag(SockOpt.TRANSTYPE, Transtype.LIVE)
        socket?.setSockFlag(SockOpt.PAYLOADSIZE, PAYLOAD_SIZE)
        if(passPhrase != null){
            socket?.setSockFlag(SockOpt.PASSPHRASE, passPhrase)
        }
        socket?.connect(srtUrl, port)
        return C.LENGTH_UNSET.toLong()
    }


    /**
     * Receives from SRT socket and feeds into a queue. Depending on the length requested
     * from exoplayer, that amount of bytes is polled from queue and onto the buffer with the given offset.
     *
     * You cannot directly receive at the given length from the socket, because SRT uses a
     * predetermined payload size that cannot be dynamic
     */
    override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
        if (length == 0) {
            return 0
        }
        var bytesReceived = 0
        if (socket != null) {
            val received = socket!!.recv(PAYLOAD_SIZE)
            for (byte in received.second /*received byte array*/) {
                byteQueue.offer(byte)
            }
            repeat(length) { index ->
                val byte = byteQueue.poll()
                if (byte != null) {
                    buffer[index + offset] = byte
                    bytesReceived++
                }
            }
            return bytesReceived
        }
        throw IOException("Couldn't read bytes at offset: $offset")
    }

    override fun getUri(): Uri = Uri.parse("srt://$srtUrl:$port")

    override fun close() {
        socket?.close()
        socket = null
    }
}

Do you have any idea how I could fix this ?

@ThibaultBee
Copy link
Owner

Hi,

Yes, the minimal SDK version is set to 21 for srtdroid.
Could you upgrade your application minimal SDK version to 21?
I am not really interested to extend the minimal SDK version of srtdroid as I don't have any device to test that and the number of devices is < 1%.

@yoobi
Copy link
Contributor Author

yoobi commented Jan 14, 2023

I can't upgrade my minSdk, my app is being used in countries where my users (~300 000) are still using KitKat (API 19)
Without extending srtdroid to 19 maybe with a new branch or something that could help me figure out how to make this work, I don't really know C o C++ so it's quite hard for me to debug

Thanks in advance

@ThibaultBee
Copy link
Owner

Hum, not sure anymore.

I truied with branch https://github.com/ThibaultBee/srtdroid/tree/feat/android-19-support but unfortunatly, it seems that libsrt itself does not build for Android < 21. (See https://github.com/ThibaultBee/srtdroid/actions/runs/3918612479/jobs/6699102675)

The compile failed with issue:

 srtcore/sync_posix.cpp:306:5: error: use of undeclared identifier 'pthread_condattr_setclock'; did you mean 'pthread_condattr_setpshared'?
      pthread_condattr_setclock(&CondAttribs, CLOCK_MONOTONIC);
      ^~~~~~~~~~~~~~~~~~~~~~~~~
      pthread_condattr_setpshared

I can't do anything on srtdroid side. Please contact directly libsrt.

@yoobi
Copy link
Contributor Author

yoobi commented Jan 14, 2023

Okay thank you ! I'll do that and link this issue to their repo

@yoobi
Copy link
Contributor Author

yoobi commented Jan 31, 2023

Turns out I need to recompile srt lib with a special argument for Android 19. Thanks for your help

@yoobi yoobi closed this as completed Feb 1, 2023
@ThibaultBee
Copy link
Owner

I can add the flag in the project. Could you make a PR about it?

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

No branches or pull requests

2 participants