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

心已入冬 提交于 2019-12-12 07:49:01

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/13037422/how-can-i-set-up-connection-with-dvr-and-decode-the-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!