Skip to content

Commit

Permalink
add setBitrateExponentialFactor and getBitrateExponentialFactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Jul 9, 2024
1 parent 74a781f commit bd37da9
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class CameraFragment: Fragment(), ConnectChecker {
val genericStream: GenericStream by lazy {
GenericStream(requireContext(), this).apply {
getGlInterface().autoHandleOrientation = true
getStreamClient().setBitrateExponentialFactor(0.5f)
}
}
private lateinit var surfaceView: SurfaceView
Expand All @@ -100,7 +101,6 @@ class CameraFragment: Fragment(), ConnectChecker {
val etUrl = view.findViewById<EditText>(R.id.et_rtp_url)

txtBitrate = view.findViewById(R.id.txt_bitrate)

surfaceView = view.findViewById(R.id.surfaceView)
(activity as? RotationActivity)?.let {
surfaceView.setOnTouchListener(it)
Expand Down Expand Up @@ -207,7 +207,7 @@ class CameraFragment: Fragment(), ConnectChecker {
}

override fun onNewBitrate(bitrate: Long) {
txtBitrate.text = String.format("%.1f mb/s", bitrate / 1000f / 1000f)
txtBitrate.text = String.format(Locale.getDefault(), "%.1f mb/s", bitrate / 1000_000f)
}

override fun onDisconnect() {
Expand Down
3 changes: 1 addition & 2 deletions common/src/main/java/com/pedro/common/BitrateManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ open class BitrateManager(private val bitrateChecker: BitrateChecker) {

private var bitrate = 0L
private var bitrateOld = 0L
private val exponentialFactor: Float = 0.5f
var exponentialFactor: Float = 1f
private var timeStamp = TimeUtils.getCurrentTimeMillis()

suspend fun calculateBitrate(size: Long) {
Expand All @@ -47,5 +47,4 @@ open class BitrateManager(private val bitrateChecker: BitrateChecker) {
bitrate = 0
bitrateOld = 0
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,20 @@ class GenericStreamClient(
udpClient
} else null
}

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
override fun setBitrateExponentialFactor(factor: Float) {
rtmpClient.setBitrateExponentialFactor(factor)
rtspClient.setBitrateExponentialFactor(factor)
srtClient.setBitrateExponentialFactor(factor)
udpClient.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
override fun getBitrateExponentialFactor() = connectedStreamClient?.getBitrateExponentialFactor() ?: 1f
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,17 @@ class RtmpStreamClient(
override fun setOnlyVideo(onlyVideo: Boolean) {
rtmpClient.setOnlyVideo(onlyVideo)
}

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
override fun setBitrateExponentialFactor(factor: Float) {
rtmpClient.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
override fun getBitrateExponentialFactor() = rtmpClient.getBitrateExponentialFactor()
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,17 @@ class RtspStreamClient(
override fun setOnlyVideo(onlyVideo: Boolean) {
rtspClient.setOnlyVideo(onlyVideo)
}

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
override fun setBitrateExponentialFactor(factor: Float) {
rtspClient.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
override fun getBitrateExponentialFactor() = rtspClient.getBitrateExponentialFactor()
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,17 @@ class SrtStreamClient(
override fun setOnlyVideo(onlyVideo: Boolean) {
srtClient.setOnlyVideo(onlyVideo)
}

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
override fun setBitrateExponentialFactor(factor: Float) {
srtClient.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
override fun getBitrateExponentialFactor() = srtClient.getBitrateExponentialFactor()
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,15 @@ abstract class StreamBaseClient {
abstract fun resetDroppedVideoFrames()
abstract fun setOnlyAudio(onlyAudio: Boolean)
abstract fun setOnlyVideo(onlyVideo: Boolean)

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
abstract fun setBitrateExponentialFactor(factor: Float)

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
abstract fun getBitrateExponentialFactor(): Float
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,17 @@ class UdpStreamClient(
override fun setOnlyVideo(onlyVideo: Boolean) {
udpClient.setOnlyVideo(onlyVideo)
}

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
override fun setBitrateExponentialFactor(factor: Float) {
udpClient.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
override fun getBitrateExponentialFactor() = udpClient.getBitrateExponentialFactor()
}
13 changes: 13 additions & 0 deletions rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -602,4 +602,17 @@ class RtmpClient(private val connectChecker: ConnectChecker) {
}

fun getItemsInCache(): Int = rtmpSender.getItemsInCache()

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
fun setBitrateExponentialFactor(factor: Float) {
rtmpSender.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
fun getBitrateExponentialFactor() = rtmpSender.getBitrateExponentialFactor()
}
6 changes: 6 additions & 0 deletions rtmp/src/main/java/com/pedro/rtmp/rtmp/RtmpSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,10 @@ class RtmpSender(
fun setLogs(enable: Boolean) {
isEnableLogs = enable
}

fun setBitrateExponentialFactor(factor: Float) {
bitrateManager.exponentialFactor = factor
}

fun getBitrateExponentialFactor() = bitrateManager.exponentialFactor
}
13 changes: 13 additions & 0 deletions rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,17 @@ class RtspClient(private val connectChecker: ConnectChecker) {
}

fun getItemsInCache(): Int = rtspSender.getItemsInCache()

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
fun setBitrateExponentialFactor(factor: Float) {
rtspSender.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
fun getBitrateExponentialFactor() = rtspSender.getBitrateExponentialFactor()
}
6 changes: 6 additions & 0 deletions rtsp/src/main/java/com/pedro/rtsp/rtsp/RtspSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,10 @@ class RtspSender(
fun setLogs(enable: Boolean) {
isEnableLogs = enable
}

fun setBitrateExponentialFactor(factor: Float) {
bitrateManager.exponentialFactor = factor
}

fun getBitrateExponentialFactor() = bitrateManager.exponentialFactor
}
13 changes: 13 additions & 0 deletions srt/src/main/java/com/pedro/srt/srt/SrtClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -429,4 +429,17 @@ class SrtClient(private val connectChecker: ConnectChecker) {
}

fun getItemsInCache(): Int = srtSender.getItemsInCache()

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
fun setBitrateExponentialFactor(factor: Float) {
srtSender.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
fun getBitrateExponentialFactor() = srtSender.getBitrateExponentialFactor()
}
6 changes: 6 additions & 0 deletions srt/src/main/java/com/pedro/srt/srt/SrtSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,10 @@ class SrtSender(
fun setLogs(enable: Boolean) {
isEnableLogs = enable
}

fun setBitrateExponentialFactor(factor: Float) {
bitrateManager.exponentialFactor = factor
}

fun getBitrateExponentialFactor() = bitrateManager.exponentialFactor
}
13 changes: 13 additions & 0 deletions udp/src/main/java/com/pedro/udp/UdpClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,17 @@ class UdpClient(private val connectChecker: ConnectChecker) {
}

fun getItemsInCache(): Int = udpSender.getItemsInCache()

/**
* @param factor values from 0.1f to 1f
* Set an exponential factor to the bitrate calculation to avoid bitrate spikes
*/
fun setBitrateExponentialFactor(factor: Float) {
udpSender.setBitrateExponentialFactor(factor)
}

/**
* Get the exponential factor used to calculate the bitrate. Default 1f
*/
fun getBitrateExponentialFactor() = udpSender.getBitrateExponentialFactor()
}
6 changes: 6 additions & 0 deletions udp/src/main/java/com/pedro/udp/UdpSender.kt
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,10 @@ class UdpSender(
fun setLogs(enable: Boolean) {
isEnableLogs = enable
}

fun setBitrateExponentialFactor(factor: Float) {
bitrateManager.exponentialFactor = factor
}

fun getBitrateExponentialFactor() = bitrateManager.exponentialFactor
}

0 comments on commit bd37da9

Please sign in to comment.