B4J Question jServer hungs during background work

peacemaker

Expert
Licensed User
Longtime User
Hi, All

I'm going on development of RTSP-grabber using simple HTML-form.
When the IP-camera is working stable - all in my server web-app is controlled OK via browser web-page.
But i add checking the camera: ping inside the timer (timer in the Main module) before trying to grab the frame.

B4X:
Sub PingCamera (host As String, timeoutMs As Int) As Boolean
    Private inetaddress As JavaObject
    inetaddress.InitializeStatic("java.net.InetAddress")
    Dim b As Boolean = inetaddress.RunMethodJO("getByName",Array As String(host)).RunMethod("isReachable",Array As Object(timeoutMs))
    Return b
End Sub

Sub tim_tick
    If Grabbing = False Then
        Return
    End If
    Dim H As String = Get_Host(RTSP_URL)
    If PingCamera(h, 500) = False Then
        LastGrabbingError = H & " is not reachable"
        Log(LastGrabbingError)
        Return
    Else
        Log("!")
        Get_Frame
    End If
End Sub

'parse the host to use for Ping
Sub Get_Host(u As String) As String
    Dim m As Matcher = Regex.Matcher("(.*:)//([A-Za-z0-9\-\.]+)(:[0-9]+)?(.*)", u)
    Do While m.Find
        For g = 1 To m.GroupCount
            If g = 2 Then    'host name
                Return m.Group(g)
            End If
        Next
    Loop
    Return ""
End Sub

Web-page from jServer v.4.01 is with refreshing each 10 seconds to update the system state
And the server hangs after each event: if the camera is switched off or switched on: browser at refreshing moment does not stop loading web-page. No any error log messages, just all is hanging (until server restart).

How to understand it and debug ?





Also i remember that i saw such server hanging if to use Sleep(x)...
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
in Get_Frame
Indeed !!! It has turned out that if to call CLI app like "ffmpeg" during trouble with the video source - it needs to kill the process especially, to avoid hunging...
B4X:
Sub Timer1_Tick
    If Main.RTSP_URL = "" Then
        Main.LastGrabbingError = "Camera's RTSP URL is empty."
        Return
    End If
   
    Dim H As String = Get_Host(Main.RTSP_URL)
    If PingCamera(h, 500) = False Then
        Main.isCameraOnline = False
        Main.LastGrabbingError = H & " is not reachable"
        Log(Main.LastGrabbingError)
        Main.Kill_process
        Sleep(100)
        Return
    Else
        Main.LastGrabbingError = ""
        Main.isCameraOnline = True
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…