Home » Android » java – How can I set up connection with DVR and decode the data?

java – How can I set up connection with DVR and decode the data?

Posted by: admin June 15, 2020 Leave a comment

Questions:

My system consists of a digital video recorder (dvr) and two cameras, which are connected with dvr. The dvr works as server also (connected to LAN). To the system was included an android application, where I put info about server, port, user name and password (I can add accounts using server software). The application streams video from cameras. I can also connect with dvr via http (only IE), then it show activeX application.

What I’m to do is write similar application, but I stuck into a problem – how can I fetch the video stream from dvr? I’m no expert with Java and tried connect with dvr, unsuccessfully.

Here is my code:

import java.net.*;
import java.io.*;

public class VideoStream
{

final static int BUFFER_SIZE = 1024000;
public static void main(String[] args) throws Exception 
{
    Authenticator.setDefault(new Authenticator()
    {
        protected  PasswordAuthentication  getPasswordAuthentication()
        {
            System.out.println("Authenticatting...");
            PasswordAuthentication p=new PasswordAuthentication("login", "password".toCharArray());
        return p;       
        }
    });
    Socket s = new Socket();
    String host = "192.168.80.107"; //192.168.80.107
    PrintWriter s_out = null;
    BufferedReader s_in = null;
    BufferedInputStream bufferedInputStream = null;

    try
    {
        s.connect(new InetSocketAddress(host, 34599));
        System.out.println("Is connected? : " + s.isConnected());

        s_out = new PrintWriter(s.getOutputStream(), true);
        s_in = new BufferedReader(new InputStreamReader(s.getInputStream()));
        //bufferedInputStream = new BufferedInputStream(s.getInputStream());
    }
    catch(UnknownHostException e)
    {
        e.printStackTrace();
        System.exit(1);
    }
    catch(Exception e)
    {
        e.printStackTrace();
        System.exit(1);
    }

    byte[] b = new byte[BUFFER_SIZE];
    //bufferedInputStream.read(b);

    int bytesRead = 0;
    System.out.println("Reading... \n");
    while((bytesRead = s_in.read()) > 0)
    {
        System.out.println(s_in.readLine());
    }
    System.out.println("Done");
}

I tried different port (TCP and for included android app). The socket connect with the server, but it “hangs” when I try to use read() method (even out of while loop). Authenticator don’t work too.

Some info about dvr:

  1. Protocol support: TCP/IP, UDP, SMTP, NTP, DHCP, DDNS
  2. Video compression: H.264
  3. Operating system: linux

I will much appreciate any advices.

How to&Answers:

As others noted in the comments, the advice is to know how the existing Android application works.

It may be worth trying to inspect packets and replies (captured with a sniffer like Shark for Droid) concerning the communications between the Android client and the DVR.