DrmService.java
4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package com.micro.player.service;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.xgimi.gimicinema.cctvsix.activity.M1905VideoListActivity;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* @ClassName: DrmService
* @Version: V1.0
*/
public class DrmService {
private String path = "/sdcard/log.txt";
private int port = 9000;
private String drm_service = "http://127.0.0.1";
private RequestQueue mQueueSts;
public DrmService(Context context) {
mQueueSts = Volley.newRequestQueue(context);
}
public void tryToStartService() {
StringRequest request = new StringRequest(Request.Method.GET,
"http://127.0.0.1:" + port + "/1.ts?alive=1",
new Response.Listener<String>() {
@Override
public void onResponse(String arg0) {
Log.d("lovely", "startserver:" + port + "1.ts?alive=1 OK");
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError arg0) {
Log.d("lovely", "startserver:" + port + "1.ts?alive=1 NOT OK");
initDrmdecoder();
}
}) {
};
mQueueSts.add(request);
}
public boolean initDrmdecoder() {
boolean rtn = false;
try {
port = startDecoder(path.getBytes());
Log.d("lovely", "DrmService Is try to start port:" + port + "127.0.0.1:" + port);
// port <=0 时,视作开启失败
if (port <= 0) {
Log.d("lovely", "DrmService Start port failure:" + port + "");
} else {
Log.d("lovely", "DrmService running checked port:" + port + "127.0.0.1:" + port);
rtn = true;
}
} catch (Exception e) {
Log.d("lovely", "DrmService initDrmdecoder erro " + e.toString());
}
return rtn;
}
public boolean startService() {
boolean rtn = false;
int errorcount = 0;
try {
while (!IsStart()) {
port = startDecoder(path.getBytes());
// AppInfo.setErrorinfos("DrmService Is try to start port:" + port ,"127.0.0.1:" + port);
// port <=0 时,视作开启失败
if (port <= 0) {
Log.d("lovely", "DrmService Start port failure:" + port + "");
}
Thread.sleep(200);
//如果开始
errorcount++;
if (errorcount > 5) {
Log.d("lovely", "DrmService Start port over 5 times:" + errorcount + "");
break;
}
}
if (IsStart()) {
Log.d("TTTTTTTTTTTTT", "Is Start");
rtn = true;
} else {
Log.d("TTTTTTTTTTTTT", "Is NOT Start");
}
} catch (Exception e) {
Log.d("lovely", "DrmService initDrmdecoder erro " + e.toString());
}
return rtn;
}
public Uri getUrl(String url) {
Uri rtn_uri = Uri.EMPTY;
try {
rtn_uri = Uri.parse("http://127.0.0.1:"
+ Integer.toString(port) + "/zqc.ts?ip=" + M1905VideoListActivity.SERVER_IP + "&clientid=" + 18 + "&source=" + url);
Log.d("lovely", "DrmService last getUrl:" + rtn_uri.toString() + "");
} catch (Exception e) {
Log.d("lovely", "DrmService getUrl error port :" + port + "");
}
if (IsStart()) {
Log.d("lovely", "DrmService getUrl running checked port:" + port + "127.0.0.1:" + port);
} else {
Log.d("lovely", "DrmService getUrl not running checked port:" + port + "127.0.0.1:" + port);
}
return rtn_uri;
}
public boolean IsStart() {
boolean isstart = false;
try {
Process process = Runtime.getRuntime().exec("netstat");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()), 1024);
String line = null;
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("127.0.0.1:" + port))
isstart = true;
}
} catch (Exception e) {
e.printStackTrace();
}
Log.d("lovely", "isStart:" + isstart);
return isstart;
}
public static native int startDecoder(byte[] pathbytes);
static {
System.loadLibrary("decode");
}
}