Skip to content

Commit 53c422a

Browse files
authored
Merge pull request #503 from qiniu/hugo
LINK-1682 update qvs-java-sdk
2 parents dc8d3d4 + 2ea7c4c commit 53c422a

15 files changed

+624
-2
lines changed

src/main/java/com/qiniu/http/Client.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,23 @@ public Response delete(String url, StringMap headers) throws QiniuException {
187187
return send(requestBuilder, headers);
188188
}
189189

190+
public Response delete(String url, RequestBody body, StringMap headers) throws QiniuException {
191+
Request.Builder requestBuilder = new Request.Builder().delete(body).url(url);
192+
return send(requestBuilder, headers);
193+
}
194+
195+
public Response delete(String url, byte[] body, StringMap headers, String contentType) throws QiniuException {
196+
RequestBody rbody;
197+
if (body != null && body.length > 0) {
198+
MediaType t = MediaType.parse(contentType);
199+
rbody = RequestBody.create(t, body);
200+
} else {
201+
MediaType t = MediaType.parse(contentType);
202+
rbody = RequestBody.create(t, new byte[0]);
203+
}
204+
return delete(url, rbody, headers);
205+
}
206+
190207
public Response post(String url, byte[] body, StringMap headers) throws QiniuException {
191208
return post(url, body, headers, DefaultMime);
192209
}

src/main/java/com/qiniu/qvs/DeviceManager.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,38 @@ public Response stopDevice(String namespaceId, String gbId, String[] channels) t
111111
return QvsResponse.post(url, params, client, auth);
112112
}
113113

114+
/*
115+
* 同步设备通道
116+
*/
117+
public Response fetchCatalog(String namespaceId, String gbId) throws QiniuException {
118+
String url = String.format("%s/v1/namespaces/%s/devices/%s/catalog/fetch", apiServer, namespaceId, gbId);
119+
return QvsResponse.post(url, new StringMap(), client, auth);
120+
}
121+
122+
/*
123+
* 查询通道详情
124+
*/
125+
public Response queryChannel(String namespaceId, String gbId, String channelId) throws QiniuException {
126+
String url = String.format("%s/v1/namespaces/%s/devices/%s/channels/%s", apiServer, namespaceId, gbId, channelId);
127+
return QvsResponse.get(url, client, auth);
128+
}
129+
130+
/*
131+
* 删除通道
132+
*/
133+
public Response deleteChannel(String namespaceId, String gbId, String channelId) throws QiniuException {
134+
String url = String.format("%s/v1/namespaces/%s/devices/%s/channels/%s", apiServer, namespaceId, gbId, channelId);
135+
return QvsResponse.delete(url, client, auth);
136+
}
137+
138+
/*
139+
* 查询本地录像列表
140+
* 普通设备chId可以忽略, 置为空即可
141+
*/
142+
public Response queryGBRecordHistories(String namespaceId, String gbId, String channelId, int start, int end) throws QiniuException {
143+
String url = String.format("%s/v1/namespaces/%s/devices/%s/recordhistories", apiServer, namespaceId, gbId);
144+
StringMap map = new StringMap().put("start", start).put("end", end).putNotNull("chId", channelId);
145+
url = UrlUtils.composeUrlWithQueries(url, map);
146+
return QvsResponse.get(url, client, auth);
147+
}
114148
}

src/main/java/com/qiniu/qvs/NameSpaceManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public Response createNameSpace(NameSpace nameSpace) throws QiniuException {
5252
params.putNotNull("urlMode", nameSpace.getUrlMode());
5353
params.putNotNull("zone", nameSpace.getZone());
5454
params.putNotNull("hlsLowLatency", nameSpace.isHlsLowLatency());
55+
params.putNotNull("onDemandPull", nameSpace.isOnDemandPull());
5556

5657
String url = String.format("%s/v1/namespaces", apiServer);
5758
return QvsResponse.post(url, params, client, auth);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.qiniu.qvs;
2+
3+
import com.qiniu.common.QiniuException;
4+
import com.qiniu.http.Client;
5+
import com.qiniu.http.Response;
6+
import com.qiniu.util.Auth;
7+
import com.qiniu.util.StringMap;
8+
import com.qiniu.util.UrlUtils;
9+
10+
public class PTZManager {
11+
private final String apiServer;
12+
private final Client client;
13+
private final Auth auth;
14+
15+
public PTZManager(Auth auth) {
16+
this(auth, "http://qvs.qiniuapi.com");
17+
}
18+
19+
public PTZManager(Auth auth, String apiServer) {
20+
this(auth, apiServer, new Client());
21+
}
22+
23+
public PTZManager(Auth auth, String apiServer, Client client) {
24+
this.auth = auth;
25+
this.apiServer = apiServer;
26+
this.client = client;
27+
}
28+
29+
/*
30+
* 云台控制, 本接口用于对摄像头进行 转动镜头,如水平、垂直、缩放等操作
31+
*/
32+
public Response ptzControl(String namespaceId, String gbId, String cmd, int speed, String chId) throws QiniuException {
33+
StringMap params = new StringMap().put("cmd", cmd).put("speed", speed).putNotEmpty("chId", chId);
34+
String url = String.format("%s/v1/namespaces/%s/devices/%s/ptz", apiServer, namespaceId, gbId);
35+
return QvsResponse.post(url, params, client, auth);
36+
}
37+
38+
/*
39+
* 变焦控制
40+
*/
41+
public Response focusControl(String namespaceId, String gbId, String cmd, int speed, String chId) throws QiniuException {
42+
StringMap params = new StringMap().put("cmd", cmd).put("speed", speed).putNotEmpty("chId", chId);
43+
String url = String.format("%s/v1/namespaces/%s/devices/%s/focus", apiServer, namespaceId, gbId);
44+
return QvsResponse.post(url, params, client, auth);
45+
}
46+
47+
/*
48+
* 光圈控制
49+
*/
50+
public Response irisControl(String namespaceId, String gbId, String cmd, int speed, String chId) throws QiniuException {
51+
StringMap params = new StringMap().put("cmd", cmd).put("speed", speed).putNotEmpty("chId", chId);
52+
String url = String.format("%s/v1/namespaces/%s/devices/%s/iris", apiServer, namespaceId, gbId);
53+
return QvsResponse.post(url, params, client, auth);
54+
}
55+
56+
/*
57+
* 预置位控制
58+
*/
59+
public Response presetsControl(String namespaceId, String gbId, String cmd, String name, int presetId, String chId) throws QiniuException {
60+
StringMap params = new StringMap().put("cmd", cmd).putNotEmpty("name", name).putNotEmpty("chId", chId).putNotNull("presetId", presetId);
61+
String url = String.format("%s/v1/namespaces/%s/devices/%s/presets", apiServer, namespaceId, gbId);
62+
return QvsResponse.post(url, params, client, auth);
63+
}
64+
65+
/*
66+
* 获取预置位列表
67+
*/
68+
public Response listPresets(String namespaceId, String gbId, String chId) throws QiniuException{
69+
String url = String.format("%s/v1/namespaces/%s/devices/%s/presets", apiServer, namespaceId, gbId);
70+
StringMap map = new StringMap().putNotEmpty("chId", chId);
71+
url = UrlUtils.composeUrlWithQueries(url, map);
72+
return QvsResponse.get(url, client, auth);
73+
}
74+
}

src/main/java/com/qiniu/qvs/QvsResponse.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,21 @@ public static Response delete(String url, Client client, Auth auth) throws Qiniu
6363
}
6464
return res;
6565
}
66+
67+
public static Response delete(String url, StringMap params, Client client, Auth auth) throws QiniuException {
68+
byte[] body;
69+
String contentType = null;
70+
if (params == null) {
71+
body = null;
72+
} else {
73+
contentType = Client.JsonMime;
74+
body = Json.encode(params).getBytes(Constants.UTF_8);
75+
}
76+
StringMap headers = auth.authorizationV2(url, "DELETE", body, contentType);
77+
Response res = client.delete(url, body, headers, Client.JsonMime);
78+
if (!res.isOK()) {
79+
throw new QiniuException(res);
80+
}
81+
return res;
82+
}
6683
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.qiniu.qvs;
2+
3+
import com.qiniu.common.QiniuException;
4+
import com.qiniu.http.Client;
5+
import com.qiniu.http.Response;
6+
import com.qiniu.util.Auth;
7+
import com.qiniu.util.StringMap;
8+
9+
public class RecordManager {
10+
private final String apiServer;
11+
private final Client client;
12+
private final Auth auth;
13+
14+
public RecordManager(Auth auth) {
15+
this(auth, "http://qvs.qiniuapi.com");
16+
}
17+
18+
public RecordManager(Auth auth, String apiServer) {
19+
this(auth, apiServer, new Client());
20+
}
21+
22+
public RecordManager(Auth auth, String apiServer, Client client) {
23+
this.auth = auth;
24+
this.apiServer = apiServer;
25+
this.client = client;
26+
}
27+
28+
/*
29+
* 启动按需录制
30+
*/
31+
public Response startRecord(String namespaceId, String streamId) throws QiniuException {
32+
String url = String.format("%s/v1/namespaces/%s/streams/%s/record/start", apiServer, namespaceId, streamId);
33+
return QvsResponse.post(url, new StringMap(), client, auth);
34+
}
35+
36+
/*
37+
* 停止按需录制
38+
*/
39+
public Response stopRecord(String namespaceId, String streamId) throws QiniuException {
40+
String url = String.format("%s/v1/namespaces/%s/streams/%s/record/stop", apiServer, namespaceId, streamId);
41+
return QvsResponse.post(url, new StringMap(), client, auth);
42+
}
43+
44+
/*
45+
* 删除录制片段
46+
*/
47+
public Response deleteStreamRecordHistories(String namespaceId, String streamId, String[] files) throws QiniuException {
48+
String url = String.format("%s/v1/namespaces/%s/streams/%s/recordhistories", apiServer, namespaceId, streamId);
49+
StringMap params = new StringMap();
50+
params.putNotNull("files", files);
51+
return QvsResponse.delete(url, params, client, auth);
52+
}
53+
54+
/*
55+
* 录制视频片段合并
56+
* 参数:
57+
* fname 保存的文件名(需要带上文件格式后缀),不指定系统会随机生成
58+
* format 保存的文件格式,可以为m3u8, mp4或者flv
59+
* start 查询开始时间(unix时间戳,单位为秒)
60+
* end 查询结束时间(unix时间戳,单位为秒)
61+
* deleteTs 在不生成m3u8格式文件时是否删除对应的ts文件
62+
* pipeline 数据处理的私有队列,不指定则使用公共队列
63+
* notifyUrl 保存成功回调通知地址,不指定则不通知
64+
* deleteAfterDays 文件过期时间,默认和录制模版中的设置保持一致
65+
*/
66+
public Response recordClipsSaveas(String namespaceId, String streamId, String fname, String format, int start, int end, boolean deleteTs, String pipeline, String notifyUrl, int deleteAfterDays) throws QiniuException {
67+
String url = String.format("%s/v1/namespaces/%s/streams/%s/saveas", apiServer, namespaceId, streamId);
68+
StringMap params = new StringMap();
69+
params.putNotNull("fname", fname);
70+
params.putNotNull("format", format);
71+
params.putNotNull("start", start);
72+
params.putNotNull("end", end);
73+
params.putNotNull("deleteTs", deleteTs);
74+
params.putNotNull("pipeline", pipeline);
75+
params.putNotNull("notifyUrl", notifyUrl);
76+
params.putNotNull("deleteAfterDays", deleteAfterDays);
77+
78+
return QvsResponse.post(url, params, client, auth);
79+
}
80+
81+
/*
82+
* 录制回放
83+
*/
84+
public Response recordsPlayback(String namespaceId, String streamId, int start, int end) throws QiniuException {
85+
String url = String.format("%s/v1/namespaces/%s/streams/%s/records/playback.m3u8?start=%d&end=%d", apiServer, namespaceId, streamId, start, end);
86+
return QvsResponse.get(url, client, auth);
87+
}
88+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.qiniu.qvs;
2+
3+
import com.qiniu.common.QiniuException;
4+
import com.qiniu.http.Client;
5+
import com.qiniu.http.Response;
6+
import com.qiniu.util.Auth;
7+
import com.qiniu.util.StringMap;
8+
import com.qiniu.util.UrlUtils;
9+
10+
public class StatsManager {
11+
private final String apiServer;
12+
private final Client client;
13+
private final Auth auth;
14+
15+
public StatsManager(Auth auth) {
16+
this(auth, "http://qvs.qiniuapi.com");
17+
}
18+
19+
public StatsManager(Auth auth, String apiServer) {
20+
this(auth, apiServer, new Client());
21+
}
22+
23+
public StatsManager(Auth auth, String apiServer, Client client) {
24+
this.auth = auth;
25+
this.apiServer = apiServer;
26+
this.client = client;
27+
}
28+
29+
public Response queryFlow(String namespaceId, String streamId, String tu, int start, int end) throws QiniuException {
30+
String url = String.format("%s/v1/stats/flow", apiServer);
31+
StringMap map = new StringMap().put("nsId", namespaceId).putNotNull("streamId", streamId).put("start", start).put("end", end).put("tu", tu);
32+
url = UrlUtils.composeUrlWithQueries(url, map);
33+
return QvsResponse.get(url, client, auth);
34+
}
35+
36+
public Response queryBandwidth(String namespaceId, String streamId, String tu, int start, int end) throws QiniuException {
37+
String url = String.format("%s/v1/stats/bandwidth", apiServer);
38+
StringMap map = new StringMap().put("nsId", namespaceId).putNotNull("streamId", streamId).put("start", start).put("end", end).put("tu", tu);
39+
url = UrlUtils.composeUrlWithQueries(url, map);
40+
return QvsResponse.get(url, client, auth);
41+
}
42+
}

src/main/java/com/qiniu/qvs/StreamManager.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ public Response queryStreamRecordHistories(String namespaceId, String streamId,
145145
return QvsResponse.get(requestUrl, client, auth);
146146
}
147147

148+
// 查询录制记录
149+
public Response queryStreamRecordHistories(String namespaceId, String streamId, int start, int end, int line, String marker, String format) throws QiniuException {
150+
String requestUrl = String.format("%s/v1/namespaces/%s/streams/%s/recordhistories", apiServer, namespaceId, streamId);
151+
StringMap map = new StringMap().putNotNull("start", start).putNotNull("end", end)
152+
.putNotNull("line", line).putNotEmpty("marker", marker).putNotEmpty("format", format);
153+
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
154+
return QvsResponse.get(requestUrl, client, auth);
155+
}
156+
148157
// 查询流封面
149158
public Response queryStreamCover(String namespaceId, String streamId) throws QiniuException {
150159
String url = String.format("%s/v1/namespaces/%s/streams/%s/cover", apiServer, namespaceId, streamId);
@@ -165,4 +174,21 @@ public Response stopStream(String namespaceId, String streamId) throws QiniuExce
165174
String url = String.format("%s/v1/namespaces/%s/streams/%s/stop", apiServer, namespaceId, streamId);
166175
return QvsResponse.post(url, new StringMap(), client, auth);
167176
}
177+
178+
/*
179+
* 按需截图
180+
*/
181+
public Response ondemandSnap(String namespaceId, String streamId) throws QiniuException {
182+
String url = String.format("%s/v1/namespaces/%s/streams/%s/snap", apiServer, namespaceId, streamId);
183+
return QvsResponse.post(url, new StringMap(), client, auth);
184+
}
185+
186+
/*
187+
* 删除截图
188+
*/
189+
public Response deleteSnapshots(String namespaceId, String streamId, String[] files) throws QiniuException {
190+
String url = String.format("%s/v1/namespaces/%s/streams/%s/snapshots", apiServer, namespaceId, streamId);
191+
StringMap params = new StringMap().putNotNull("files", files);
192+
return QvsResponse.delete(url, params, client, auth);
193+
}
168194
}

src/main/java/com/qiniu/qvs/model/NameSpace.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class NameSpace {
2525
private int urlMode; // 推拉流地址计算方式,1:static, 2:dynamic
2626
private String zone; // 存储区域
2727
private boolean hlsLowLatency; // hls低延迟开关
28+
private boolean onDemandPull; // 按需拉流开关
2829

2930
public String getId() {
3031
return id;
@@ -194,4 +195,12 @@ public void setHlsLowLatency(boolean hlsLowLatency) {
194195
this.hlsLowLatency = hlsLowLatency;
195196
}
196197

198+
public boolean isOnDemandPull() {
199+
return onDemandPull;
200+
}
201+
202+
public void setOnDemandPull(boolean onDemandPull) {
203+
this.onDemandPull = onDemandPull;
204+
}
205+
197206
}

src/main/java/com/qiniu/qvs/model/Template.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ public class Template {
1515
private int recordInterval; // 录制文件时长(单位为秒)
1616
private int snapInterval; // 截图间隔(单位为秒)
1717
private String m3u8FileNameTemplate; // m3u8文件命名格式
18+
private String flvFileNameTemplate; // flv文件命名格式
19+
private String mp4FileNameTemplate; // mp4文件命名格式
1820
private int recordType; // 录制模式, 0(不录制),1(实时录制), 2(按需录制)
19-
private int recordFileFormat; // 录制文件存储格式,取值:0(ts格式存储)
21+
private int recordFileFormat; // 录制文件存储格式(多选), 范围:1(001)~7(111), 从左往右的三位二进制数分别代表MP4, FLV, M3U8; 0代表不选择该格式, 1代表选择;例如:2(010)代表选择FLV格式,6(110)代表选择MP4和FLV格式,1(001)代表选择M3U8格式,7(111)代表三种格式均选择
2022
//record/ts/${namespaceId}/${streamId}/${startMs}-${endMs}.ts
2123
private String tsFilenametemplate;
2224
//record/snap/${namespaceId}/${streamId}/${startMs}.jpg // 录制封面
@@ -211,4 +213,21 @@ public String getM3u8FileNameTemplate() {
211213
public void setM3u8FileNameTemplate(String m3u8FileNameTemplate) {
212214
this.m3u8FileNameTemplate = m3u8FileNameTemplate;
213215
}
216+
217+
public String getFlvFileNameTemplate() {
218+
return flvFileNameTemplate;
219+
}
220+
221+
public void setFlvFileNameTemplate(String flvFileNameTemplate) {
222+
this.flvFileNameTemplate = flvFileNameTemplate;
223+
}
224+
225+
public String getMp4FileNameTemplate() {
226+
return mp4FileNameTemplate;
227+
}
228+
229+
public void setMp4FileNameTemplate(String mp4FileNameTemplate) {
230+
this.mp4FileNameTemplate = mp4FileNameTemplate;
231+
}
232+
214233
}

0 commit comments

Comments
 (0)