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

Fix simulcast factory not sending back EncoderInfo #67

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package io.livekit.android.webrtc

import io.livekit.android.util.LKLog
import org.webrtc.*
import java.util.concurrent.*
import java.util.concurrent.Callable
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors

/*
Copyright 2017, Lyo Kato <lyo.kato at gmail.com> (Original Author)
Expand Down Expand Up @@ -49,7 +51,7 @@ internal class SimulcastVideoEncoderFactoryWrapper(
* This results in HardwareVideoEncoderFactory being both the primary and fallback,
* but there aren't any specific problems in doing so.
*/
private class Fallback(private val hardwareVideoEncoderFactory: VideoEncoderFactory) :
private class FallbackFactory(private val hardwareVideoEncoderFactory: VideoEncoderFactory) :
VideoEncoderFactory {

private val softwareVideoEncoderFactory: VideoEncoderFactory = SoftwareVideoEncoderFactory()
Expand Down Expand Up @@ -93,6 +95,7 @@ internal class SimulcastVideoEncoderFactoryWrapper(
val future = executor.submit(Callable {
LKLog.i {
"""initEncode() thread=${Thread.currentThread().name} [${Thread.currentThread().id}]
| encoder=${encoder.implementationName}
| streamSettings:
| numberOfCores=${settings.numberOfCores}
| width=${settings.width}
Expand Down Expand Up @@ -165,6 +168,31 @@ internal class SimulcastVideoEncoderFactoryWrapper(
val future = executor.submit(Callable { return@Callable encoder.implementationName })
return future.get()
}

override fun createNativeVideoEncoder(): Long {
val future = executor.submit(Callable { return@Callable encoder.createNativeVideoEncoder() })
return future.get()
}

override fun isHardwareEncoder(): Boolean {
val future = executor.submit(Callable { return@Callable encoder.isHardwareEncoder })
return future.get()
}

override fun setRates(rcParameters: VideoEncoder.RateControlParameters?): VideoCodecStatus {
val future = executor.submit(Callable { return@Callable encoder.setRates(rcParameters) })
return future.get()
}

override fun getResolutionBitrateLimits(): Array<VideoEncoder.ResolutionBitrateLimits> {
val future = executor.submit(Callable { return@Callable encoder.resolutionBitrateLimits })
return future.get()
}

override fun getEncoderInfo(): VideoEncoder.EncoderInfo {
val future = executor.submit(Callable { return@Callable encoder.encoderInfo })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main thing that was breaking the hardware encoder from working (and preventing H264 from working). EncoderInfo holds onto information needed for resolution alignment, which is used to adjust the resolution (only works on 16x16 aligned frames).

return future.get()
}
}

private class StreamEncoderWrapperFactory(private val factory: VideoEncoderFactory) :
Expand Down Expand Up @@ -195,7 +223,7 @@ internal class SimulcastVideoEncoderFactoryWrapper(
sharedContext, enableIntelVp8Encoder, enableH264HighProfile
)
primary = StreamEncoderWrapperFactory(hardwareVideoEncoderFactory)
fallback = StreamEncoderWrapperFactory(Fallback(primary))
fallback = StreamEncoderWrapperFactory(FallbackFactory(primary))
native = SimulcastVideoEncoderFactory(primary, fallback)
}

Expand Down