Android: Detecting stream disconnect from LiveVideo

Currently when testing our server and Android app the live video stream is disconnecting for some reason after ~2-3 minutes. This occurs with the Milestone XProtect app also, however the XProtect app detects the stream stopped and reconnects.

The SDK LiveVideo class catches and consumes an exception that the stream has disconnected but provides no way to notify the containing app.

I discovered in the SDK ‘ConnectivityStateReceiver’ however this only fires changes on network state, in our case the video stops even though network connectivity has not changed.

Exception when stream stops is as follows:

2019-12-06 16:29:01.530 26465-26568/app.plugin.milestone D/VideoChannelThread: Exception in vStream.receiveResponse()
    java.net.SocketException: Connection reset
        at java.net.SocketInputStream.read(SocketInputStream.java:215)
        at java.net.SocketInputStream.read(SocketInputStream.java:144)
        at com.android.okhttp.okio.Okio$2.read(Okio.java:145)
        at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:213)
        at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:317)
        at com.android.okhttp.okio.RealBufferedSource.indexOf(RealBufferedSource.java:311)
        at com.android.okhttp.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:207)
        at com.android.okhttp.internal.http.Http1xStream.readResponse(Http1xStream.java:388)
        at com.android.okhttp.internal.http.Http1xStream.readResponseHeaders(Http1xStream.java:146)
        at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:900)
        at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:772)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:493)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:429)
        at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseMessage(HttpURLConnectionImpl.java:556)
        at com.milestonesys.xpmobilesdk.communication.HTTPConnection.getResponseInputStream(HTTPConnection.java:284)
        at com.milestonesys.xpmobilesdk.communication.HTTPConnection.receiveResponse(HTTPConnection.java:273)
        at com.milestonesys.xpmobilesdk.communication.VideoChannelThread.pullVideo(VideoChannelThread.java:393)
        at com.milestonesys.xpmobilesdk.communication.VideoChannelThread.access$1200(VideoChannelThread.java:23)
        at com.milestonesys.xpmobilesdk.communication.VideoChannelThread$1.run(VideoChannelThread.java:239)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)
2019-12-06 16:29:01.530 26465-26568/cs.android.milestone D/VideoChannelThread: Thread for VideoStream '0235dec0-aaee-4805-b6a3-c04bb0b344ae' will be closed.
2019-12-06 16:29:01.530 26465-26568/cs.android.milestone D/VideoChannelThread: Thread for VideoStream '0235dec0-aaee-4805-b6a3-c04bb0b344ae' has been closed!

Even after this the server connection is still OK as I’m getting keep alive live messages:

2019-12-06 16:29:37.557 26465-26547/app.plugin.milestone D/SdkWrapper: LiveMessage: Command { seq: 0, name: LiveMessage, type: Response, result: OK, outputParams: { {Timeout=30} } }

I suspect the disconnect is firewall related, however as this is a possible problem for users I would like to ensure they are never left looking at a stream that is actually stopped.

This is using 2019 R3 SDK and Server.

Hello,

If I understood it correctly, only the video stream seems to be closed, while the connection to the server is still alive?

Is the Milestone XProtect app showing the ‘connection lost/reconnecting’ message in this case (not inside the camera, but over the app)?

Then, probably you could set up some kind of watchdog timer, to be reset every time a new frame has been received. Then, if you don’t receive a new frame in, say, 3 seconds, you will know that the stream is broken and can show error message or reconnect

Hope this helps,

Plamen Parvanov

Yes, that is a solution for now.

I think its a reasonable request for a future SDK version: the exception the LiveVideo class consumes fires an event to notify the implementing app that the video has stopped/or an error has occured.

Yes, it’s a reasonable request to provide some kind of information to the app that a streaming error has occurred.

We will try to add such a functionality in one of the next releases

Thanks for your feedback!
Plamen Parvanov

Good afternoon Jon,

Could you help me with the lines of code that you implemented to solve this problem?

Thank you very much!