[Android] - IPCapture library problem

[Android] - ipcapture library problem

hello. Nice to meet you.

step-7
run-1
run-2
run-3
(HTTPLog)-Static: isSBSettingEnabled false
(HTTPLog)-Static: isSBSettingEnabled false
Unable to open I/O streams (app): http://20....

An error occurs as above.

abc

    try {
      conn = (HttpURLConnection)url.openConnection();
      String user = "admin";   String pass = "jusung_123";
      conn.setRequestProperty("Authorization", "Basic " + base64.encode(user + ":" + pass));
    }
    catch (IOException e) {
      System.err.println("Unable to connect: " + e.getMessage());
      return;
    }
    System.out.println("run-3");
    
    try {
      // int p_value = 8192;   //  p_value = 8192;
      httpIn = new BufferedInputStream(conn.getInputStream(), p_value);
      jpgOut = new ByteArrayOutputStream(p_value);      
    }
    catch (IOException e) {
      
      System.err.println("Unable to open I/O streams(app): " + e.getMessage());
      return;
    }
    System.out.println("run-4");

Does anyone know the cause of the error?

help me~.

  1. It works fine on PC.
  2. It doesn’t work in the app.
    Why?
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package=""><uses-sdk android:minSdkVersion="15" android:targetSdkVersion="29"/><application android:debuggable="true" android:icon="@drawable/icon" android:label="CCTV" android:requestLegacyExternalStorage="true" android:targetSandboxVersion="2" android:usesCleartextTraffic="true">
<activity android:name=".MainActivity">android:theme="@android:style/Theme.NoTitleBar"&gt;<intent-filter><action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/></intent-filter></activity></application><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"/><uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/><uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/><uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/></manifest>

link : Android 9 파이에서 http 사용시 에러 발생 해결

android android:networksecurityconfig
I would like to add the above,
It is not added in ‘Processing’.

I tried to work on it today, but I didn’t succeed.
Why is that?
The current phenomenon is as follows.

  1. CCTV Hikvision Model
  • PC(JAVA Mode) : Work
  • SmartPhone(Android Mode) : Work
  1. CCTV H Model
  • PC(JAVA Mode) : Work
  • Smartphone(Android Mode) : not Work

I don’t understand this part too much.
Also, ‘H Model CCTV’ is not visible even when ‘network streaming’ is performed through VLC media.

Both PC and Android have the same source code, but why does the operation differ depending on the ‘CCTV Model’?

       conn = (HttpURLConnection)url.openConnection();
       // conn.setRequestProperty("Authorization", authorizationHeaderValue);
       
        System.out.println("run-2-1");        
       //conn.setRequestMethod("GET");
       //conn.setRequestProperty("Origin", "http://211.104.181.146:10111");   
       //conn.setRequestProperty("Accept", "application/xml");
       //conn.setRequestProperty("Content-Type", "text/html");      //
       
       // conn.setDoOutput(true);
       // conn.setDoInput(true);           
        System.out.println("Status code: " + conn.getResponseCode());
        System.out.println("Message: " + conn.getResponseMessage());

Error MSG(println)

Status code: 401
Message: Unauthorized

Are there any seniors? help me~.

 conn = null;
 conn = (HttpURLConnection)url.openConnection();
 System.out.println("---------------------------------------------------");
 System.out.println(" conn : " + conn.toString());
 System.out.println("---------------------------------------------------");

What I’ve experienced so far
It seems to prevent it when requesting from CCTV to Android. (This is my opinion.)

// JAVA(PC)
conn: sun.net.www.protocol.http.HttpURLConnection:http://ip/stw-cgi/video.cgi?msubmenu=stream&action=view&Profile=10

// Android (Smartphone)
conn: com.android.okhttp.internal.huc.HttpURLConnectionImpl:http://ip/stw-cgi/video.cgi?msubmenu=stream&action=view&Profile=10

The result is as above.
By any chance, while running on Android
Can I send a PC request to CCTV?
Can’t I force CCTV to send the information that I am a computer, not a smartphone?

The results of what I have done so far are as follows.
CCTV Model No. 2

  • It must be ‘Digest authentication processing’ using ‘md5’.

It’s pretty tough.

DESCRIBE rtsp://192.168.9.100:554/profile2/media.smp RTSP/1.0
CSeq: 2
Authorization: Digest
username="admin",realm="iPOLiS",nonce="C9AB5CEC50A78C07C25704A9675B171E",uri
="rtsp://192.168.9.100:554/profile2/media.smp",cnonce="814ae708b84f4f0f9f2e5
1fe1624166d",nc=00000001,response="40899fab43a5df53c72f8b3683f023e2",qop="au
th"
User-Agent: oscar-rtsp-client
Require: Bestshot

Hi!

I don’t know if posting credentials is good practice, but at least they take to a private ip not reachable from outside.

About your question, chances are there is a different android version on the non-working machine. Different android versions imply different APIs.

Another possible source of conflict are permissions. Make sure the app is requesting permissions to user, user is granting them and “Google Play Protection” is not removing permissions. It tends to revoke permissions even when instructed not to do so.

1 Like

Both urls may be opened on an Android device if they are opened by a browser. The failure occurs when the urls are opened in a java app (only one will open on my system in Android mode; neither will open in Java mode on my system). According to this reference (second answer) that is a feature of java apps: https://stackoverflow.com/questions/32306509/server-returned-http-response-code-401-for-url-when-using-shopify-api .

1 Like

@JoseMY / @svan

  • It must be ‘Digest authentication processing’ using ‘md5’.

The reason is as above. If you do it with an internet browser, the authentication is said to be automatic.
However, in order to weave with Android or a separate WEB code
It must be ‘Digest authentication processing’ using ‘md5’.
The above protocol must be followed.

Because ‘IPCaputure library’ has Basic authentication system, ‘corresponding CCTV’ does not operate.
However, as a result of contacting CCTV, it is automatically authenticated when connected to the OS, but when using a separate ‘iOS, Android, make WEB’, ‘md5’ authentication system is required.

Thank you for your interest.
And, as far as I know, iOS is easy to implement. However, Android is quite difficult to implement the above.

@svan // Please delete the image. You will see the CCTV URL. please.

Please delete the image.

No problem. It’s also visible in your second post, so I thought you didn’t care.

1 Like

As a workaround you could launch your android device browser from a Processing app then enter your username and password when prompted. It takes very little code and does work.

import android.content.Intent;
import android.net.Uri;

void setup() {
  fullScreen();
  Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse("http://xxx.xxx.xxx.xxx:yyyyy/stw-cgi/video.cgi?msubmenu=stream&action=view&Profile=10"));
  startActivity(intent);
}
1 Like

@svan

Thank you for your attention. you are right.
It is very difficult to get certified on your own.

So, in the past, the ‘RTSP’ method was implemented as follows.

However, if you use it like that, you cannot process images within the ‘Android APP’.

There are many ways.

  1. ‘Digest authentication processing(Android)’ using ‘md5’. protocol implementation
  • but, very difficult.
  1. Create a separate streaming server and implement it as http server ‘basic authentication’
  • difficult.
  1. Receive RTSP address and implement ‘online http server’. ‘basic authentication’