diff --git a/app/src/main/java/com/pedro/streamer/backgroundexample/BackgroundActivity.kt b/app/src/main/java/com/pedro/streamer/backgroundexample/BackgroundActivity.kt index 6f93e3012..1faedfa21 100644 --- a/app/src/main/java/com/pedro/streamer/backgroundexample/BackgroundActivity.kt +++ b/app/src/main/java/com/pedro/streamer/backgroundexample/BackgroundActivity.kt @@ -44,8 +44,11 @@ class BackgroundActivity : AppCompatActivity(), SurfaceHolder.Callback { binding.bStartStop.setOnClickListener { if (service?.isStreaming() != true) { - if (service?.prepare() == true) { - service?.startStream(binding.etRtpUrl.text.toString()) + service?.stopPreview() + val endpoint = binding.etRtpUrl.text.toString() + if (service?.prepare(endpoint) == true) { + startPreview() + service?.startStream(endpoint) binding.bStartStop.setText(R.string.stop_button) } } else { diff --git a/app/src/main/java/com/pedro/streamer/backgroundexample/ConnectCheckerRtp.kt b/app/src/main/java/com/pedro/streamer/backgroundexample/ConnectCheckerRtp.kt index 4e787cee0..03c4e7d28 100644 --- a/app/src/main/java/com/pedro/streamer/backgroundexample/ConnectCheckerRtp.kt +++ b/app/src/main/java/com/pedro/streamer/backgroundexample/ConnectCheckerRtp.kt @@ -18,12 +18,13 @@ package com.pedro.streamer.backgroundexample import com.pedro.rtmp.utils.ConnectCheckerRtmp import com.pedro.rtsp.utils.ConnectCheckerRtsp +import com.pedro.srt.utils.ConnectCheckerSrt /** * (Only working in kotlin) * Mix both connect interfaces to support RTMP and RTSP in service with same code. */ -interface ConnectCheckerRtp: ConnectCheckerRtmp, ConnectCheckerRtsp { +interface ConnectCheckerRtp: ConnectCheckerRtmp, ConnectCheckerRtsp, ConnectCheckerSrt { /** * Commons @@ -103,4 +104,35 @@ interface ConnectCheckerRtp: ConnectCheckerRtmp, ConnectCheckerRtsp { override fun onAuthSuccessRtsp() { onAuthSuccessRtp() } + + /** + * SRT + */ + override fun onConnectionStartedSrt(srtUrl: String) { + onConnectionStartedRtp(srtUrl) + } + + override fun onConnectionSuccessSrt() { + onConnectionSuccessRtp() + } + + override fun onConnectionFailedSrt(reason: String) { + onConnectionFailedRtp(reason) + } + + override fun onNewBitrateSrt(bitrate: Long) { + onNewBitrateRtp(bitrate) + } + + override fun onDisconnectSrt() { + onDisconnectRtp() + } + + override fun onAuthErrorSrt() { + onAuthErrorRtp() + } + + override fun onAuthSuccessSrt() { + onAuthSuccessRtp() + } } \ No newline at end of file diff --git a/app/src/main/java/com/pedro/streamer/backgroundexample/RtpService.kt b/app/src/main/java/com/pedro/streamer/backgroundexample/RtpService.kt index 84218c95b..c094f2588 100644 --- a/app/src/main/java/com/pedro/streamer/backgroundexample/RtpService.kt +++ b/app/src/main/java/com/pedro/streamer/backgroundexample/RtpService.kt @@ -30,6 +30,8 @@ import androidx.core.app.NotificationCompat import androidx.lifecycle.MutableLiveData import com.pedro.library.base.Camera2Base import com.pedro.library.rtmp.RtmpCamera2 +import com.pedro.library.rtsp.RtspCamera2 +import com.pedro.library.srt.SrtCamera2 import com.pedro.library.view.OpenGlView import com.pedro.streamer.R @@ -101,7 +103,14 @@ class RtpService : Service() { notificationManager?.notify(notifyId, notification) } - fun prepare(): Boolean { + fun prepare(endpoint: String): Boolean { + if (endpoint.startsWith("rtmp")) { + camera2Base = RtmpCamera2(this, true, connectCheckerRtp) + } else if (endpoint.startsWith("rtsp")){ + camera2Base = RtspCamera2(this, true, connectCheckerRtp) + } else { + camera2Base = SrtCamera2(this, true, connectCheckerRtp) + } return camera2Base?.prepareVideo() ?: false && camera2Base?.prepareAudio() ?: false }