Skip to content

Commit 60834fa

Browse files
authored
Merge pull request #532 from HugoLipeng/qvs/VoiceChat
qvs add VoiceChat interface
2 parents 785f192 + d703a81 commit 60834fa

File tree

9 files changed

+263
-224
lines changed

9 files changed

+263
-224
lines changed

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

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.qiniu.qvs.model.PatchOperation;
66
import com.qiniu.http.Client;
77
import com.qiniu.http.Response;
8+
import com.qiniu.qvs.model.VoiceChat;
89
import com.qiniu.util.Auth;
910
import com.qiniu.util.StringMap;
1011
import com.qiniu.util.UrlUtils;
@@ -33,14 +34,7 @@ public DeviceManager(Auth auth, String apiServer, Client client) {
3334
* 创建设备
3435
*/
3536
public Response createDevice(String namespaceId, Device device) throws QiniuException {
36-
StringMap params = new StringMap();
37-
params.put("name", device.getName());
38-
params.put("gbId", device.getGbId());
39-
params.putNotNull("username", device.getUsername());
40-
params.putNotNull("password", device.getPassword());
41-
params.put("pullIfRegister", device.isPullIfRegister());
42-
params.put("desc", device.getDesc());
43-
37+
StringMap params = device.transferPostParam();
4438
String url = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId);
4539
return QvsResponse.post(url, params, client, auth);
4640
}
@@ -145,4 +139,23 @@ public Response queryGBRecordHistories(String namespaceId, String gbId, String c
145139
url = UrlUtils.composeUrlWithQueries(url, map);
146140
return QvsResponse.get(url, client, auth);
147141
}
142+
143+
public Response getVoiceChatUrl(String namespaceId, String gbId, VoiceChat voiceChat) throws QiniuException {
144+
String url = String.format("%s/v1/namespaces/%s/devices/%s/talk", apiServer, namespaceId, gbId);
145+
StringMap params = getStringMap(voiceChat);
146+
return com.qiniu.qvs.QvsResponse.post(url, params, client, auth);
147+
}
148+
149+
private StringMap getStringMap(VoiceChat voiceChat) {
150+
StringMap params = new StringMap().putNotNull("isV2", voiceChat.getLatency());
151+
params.put("channels", voiceChat.getChannels());
152+
params.put("version", voiceChat.getVersion());
153+
params.put("transProtocol", voiceChat.getTransProtocol());
154+
return params;
155+
}
156+
157+
public Response sendVoiceChatData(String url, String base64_pcm) throws QiniuException {
158+
StringMap params = new StringMap().putNotNull("base64_pcm", base64_pcm);
159+
return QvsResponse.post(url, params, client, auth);
160+
}
148161
}
Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,33 @@
11
package com.qiniu.qvs.model;
22

3+
import com.google.gson.Gson;
4+
import com.google.gson.GsonBuilder;
5+
import com.qiniu.util.StringMap;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
11+
@Builder
12+
@Data
13+
@NoArgsConstructor
14+
@AllArgsConstructor
315
public class Device {
16+
private int type; //可选项为摄像头、平台两类,1:摄像头,2:平台。
417
private String name; // 设备名称 (可包含 字母、数字、中划线、下划线;1 ~ 100 个字符长)
518
private String username; // 用户名, 4~40位,可包含大写字母、小写字母、数字、中划线,建议与设备国标ID一致
619
private String password; // 密码, 4~40位,可包含大写字母、小写字母、数字、中划线
720
private boolean pullIfRegister; // 注册成功后启动拉流, 默认关闭
821
private String desc; // 关于设备的描述信息
922
private String gbId; // 设备国标ID
1023

11-
public String getName() {
12-
return name;
13-
}
14-
15-
public void setName(String name) {
16-
this.name = name;
17-
}
18-
19-
public String getGbId() {
20-
return gbId;
21-
}
22-
23-
public void setGbId(String gbId) {
24-
this.gbId = gbId;
25-
}
26-
27-
public String getUsername() {
28-
return username;
29-
}
30-
31-
public void setUsername(String username) {
32-
this.username = username;
33-
}
34-
35-
public String getPassword() {
36-
return password;
37-
}
38-
39-
public void setPassword(String password) {
40-
this.password = password;
41-
}
42-
43-
public boolean isPullIfRegister() {
44-
return pullIfRegister;
45-
}
46-
47-
public void setPullIfRegister(boolean pullIfRegister) {
48-
this.pullIfRegister = pullIfRegister;
49-
}
50-
51-
public String getDesc() {
52-
return desc;
53-
}
54-
55-
public void setDesc(String desc) {
56-
this.desc = desc;
24+
/**
25+
* 转换为POST参数对象
26+
*
27+
* @return POST参数对象
28+
*/
29+
public StringMap transferPostParam() {
30+
Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
31+
return gson.fromJson(gson.toJson(this), StringMap.class);
5732
}
5833
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.qiniu.qvs.model;
2+
3+
public class VoiceChat {
4+
private Boolean latency; // 该字段为true时,启用低延迟版本,收到返回地址后在发送语音数据
5+
private String[] channels; // 平台设备指定需要启动的通道国标ID(为空表示启动平台下的所有设备)
6+
private String version; // 对讲国标协议版本,取值"2014"或"2016",默认为2014,例如大部分大华摄像头为GBT 28181-2014版本对讲模式
7+
private String transProtocol; // 取值"tcp"或"udp",流传输模式,默认udp
8+
9+
public Boolean getLatency() {
10+
return latency;
11+
}
12+
13+
public void setLatency(Boolean latency) {
14+
this.latency = latency;
15+
}
16+
17+
public String[] getChannels() {
18+
return channels;
19+
}
20+
21+
public void setChannels(String[] channels) {
22+
this.channels = channels;
23+
}
24+
25+
public String getVersion() {
26+
return version;
27+
}
28+
29+
public void setVersion(String version) {
30+
this.version = version;
31+
}
32+
33+
public String getTransProtocol() {
34+
return transProtocol;
35+
}
36+
37+
public void setTransProtocol(String transProtocol) {
38+
this.transProtocol = transProtocol;
39+
}
40+
}

0 commit comments

Comments
 (0)