Skip to content

Commit

Permalink
add bitrate adapter to the app example
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroSG94 committed Sep 29, 2024
1 parent 2511dfb commit 67da0bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.pedro.library.generic.GenericStream
import com.pedro.encoder.input.sources.video.Camera1Source
import com.pedro.encoder.input.sources.video.Camera2Source
import com.pedro.extrasources.CameraXSource
import com.pedro.library.util.BitrateAdapter
import com.pedro.streamer.R
import com.pedro.streamer.utils.PathUtils
import com.pedro.streamer.utils.toast
Expand Down Expand Up @@ -90,6 +91,12 @@ class CameraFragment: Fragment(), ConnectChecker {
private val isStereo = true
private val aBitrate = 128 * 1000
private var recordPath = ""
//Bitrate adapter used to change the bitrate on fly depend of the bandwidth.
private val bitrateAdapter = BitrateAdapter {
genericStream.setVideoBitrateOnFly(it)
}.apply {
setMaxBitrate(vBitrate + aBitrate)
}

@SuppressLint("ClickableViewAccessibility")
override fun onCreateView(
Expand Down Expand Up @@ -208,6 +215,7 @@ class CameraFragment: Fragment(), ConnectChecker {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface Listener {
private int oldBitrate;
private int averageBitrate;
private int cont;
private Listener listener;
private final Listener listener;
private float decreaseRange = 0.8f; //20%
private float increaseRange = 1.2f; //20%

Expand Down

0 comments on commit 67da0bb

Please sign in to comment.