Skip to content

Commit

Permalink
Fixed calling onRtspStatusFailed() when host or port is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyvasilyev committed Oct 4, 2024
1 parent 98252e6 commit e61a3e6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ val uri = Uri.parse("rtsps://10.0.1.3/test.sdp")
val username = "admin"
val password = "secret"
val stopped = new AtomicBoolean(false)
val sslSocket = NetUtils.createSslSocketAndConnect(uri.getHost(), uri.getPort(), 10000)
val sslSocket = NetUtils.createSslSocketAndConnect(uri.getHost(), uri.getPort(), 5000)

val rtspClient = RtspClient.Builder(sslSocket, uri.toString(), stopped, rtspClientListener)
.requestVideo(true)
Expand Down
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
apply from: '../constants.gradle'
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

Expand Down Expand Up @@ -46,7 +45,7 @@ dependencies {
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
def androidXNavigationVersion = '2.8.1'
def androidXNavigationVersion = '2.8.2'
implementation "androidx.navigation:navigation-fragment-ktx:$androidXNavigationVersion"
implementation "androidx.navigation:navigation-ui-ktx:$androidXNavigationVersion"
implementation "androidx.navigation:navigation-fragment-ktx:$androidXNavigationVersion"
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/com/alexvas/rtsp/demo/live/RawFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.alexvas.rtsp.demo.databinding.FragmentRawBinding
import com.alexvas.rtsp.widget.toHexString
import com.alexvas.utils.NetUtils
import kotlinx.coroutines.Runnable
import java.net.Socket
import java.util.Timer
import java.util.TimerTask
import java.util.concurrent.atomic.AtomicBoolean
Expand Down Expand Up @@ -146,10 +147,11 @@ class RawFragment : Fragment() {

private val threadRunnable = Runnable {
Log.i(TAG, "Thread started")
var socket: Socket? = null
try {
val uri = Uri.parse(liveViewModel.rtspRequest.value)
val port = if (uri.port == -1) DEFAULT_RTSP_PORT else uri.port
val socket = NetUtils.createSocketAndConnect(uri.host!!, port, 10000)
socket = NetUtils.createSocketAndConnect(uri.host!!, port, 5000)

val rtspClient =
RtspClient.Builder(
Expand All @@ -169,9 +171,11 @@ class RawFragment : Fragment() {
.build()

rtspClient.execute()
NetUtils.closeSocket(socket)
} catch (e: Exception) {
e.printStackTrace()
binding.root.post { rtspClientListener.onRtspFailed(e.message) }
} finally {
NetUtils.closeSocket(socket)
}
Log.i(TAG, "Thread stopped")
}
Expand Down
5 changes: 0 additions & 5 deletions constants.gradle

This file was deleted.

7 changes: 3 additions & 4 deletions library-client-rtsp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
id 'maven-publish'
}

apply from: '../constants.gradle'
apply plugin: 'com.android.library'

project.afterEvaluate {
Expand Down Expand Up @@ -39,7 +38,7 @@ android {
}

dependencies {
implementation "androidx.annotation:annotation:$androidXAnnotationVersion"
implementation "androidx.media3:media3-exoplayer:$androidXMedia3Version"
implementation "androidx.camera:camera-core:$androidXCameraCoreVersion"
implementation 'androidx.annotation:annotation:1.8.2'
implementation 'androidx.media3:media3-exoplayer:1.4.1'
implementation 'androidx.camera:camera-core:1.4.0-rc03'
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,11 @@ class RtspProcessor(
override fun run() {
onRtspClientStarted()
val port = if (uri.port == -1) DEFAULT_RTSP_PORT else uri.port
var socket: Socket? = null
try {
if (DEBUG) Log.d(TAG, "Connecting to ${uri.host.toString()}:$port...")

val socket: Socket = if (uri.scheme?.lowercase() == "rtsps")
socket = if (uri.scheme?.lowercase() == "rtsps")
NetUtils.createSslSocketAndConnect(uri.host.toString(), port, 5000)
else
NetUtils.createSocketAndConnect(uri.host.toString(), port, 5000)
Expand All @@ -325,10 +326,11 @@ class RtspProcessor(
.withCredentials(username, password)
.build()
rtspClient.execute()

NetUtils.closeSocket(socket)
} catch (e: Exception) {
e.printStackTrace()
uiHandler.post { proxyClientListener.onRtspFailed(e.message) }
} finally {
NetUtils.closeSocket(socket)
}
onRtspClientStopped()
}
Expand Down

0 comments on commit e61a3e6

Please sign in to comment.