diff --git a/app/src/main/java/com/pedro/streamer/rotation/CameraFragment.kt b/app/src/main/java/com/pedro/streamer/rotation/CameraFragment.kt index 45345c24d..c32d311fb 100644 --- a/app/src/main/java/com/pedro/streamer/rotation/CameraFragment.kt +++ b/app/src/main/java/com/pedro/streamer/rotation/CameraFragment.kt @@ -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 @@ -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( @@ -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) } diff --git a/library/src/main/java/com/pedro/library/util/BitrateAdapter.java b/library/src/main/java/com/pedro/library/util/BitrateAdapter.java index 0e4a6d86e..a1f34d940 100644 --- a/library/src/main/java/com/pedro/library/util/BitrateAdapter.java +++ b/library/src/main/java/com/pedro/library/util/BitrateAdapter.java @@ -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%