Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
longbai committed Sep 11, 2020
1 parent 9c4e12d commit eb7fbb6
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 155 deletions.
181 changes: 90 additions & 91 deletions src/main/java/com/qiniu/qvs/DeviceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,106 +10,105 @@
import com.qiniu.util.UrlUtils;

public class DeviceManager {
private final String apiServer;
private final Client client;
private final Auth auth;

private final String apiServer;
private final Client client;
private final Auth auth;
public DeviceManager(Auth auth) {
this(auth, "http://qvs.qiniuapi.com");
}

public DeviceManager(Auth auth) {
this(auth, "http://qvs.qiniuapi.com");
}
public DeviceManager(Auth auth, String apiServer) {
this(auth, apiServer, new Client());
}

public DeviceManager(Auth auth, String apiServer) {
this(auth, apiServer, new Client());
}

public DeviceManager(Auth auth, String apiServer, Client client) {
this.auth = auth;
this.apiServer = apiServer;
this.client = client;
}
public DeviceManager(Auth auth, String apiServer, Client client) {
this.auth = auth;
this.apiServer = apiServer;
this.client = client;
}


/*
* 创建设备
*/
public Response createDevice(String namespaceId, Device device) throws QiniuException {
StringMap params = new StringMap();
params.put("name", device.getName());
params.put("gbId", device.getGbId());
params.putNotNull("username", device.getUsername());
params.putNotNull("password", device.getPassword());
params.put("pullIfRegister", device.isPullIfRegister());
params.put("desc", device.getDesc());

String url = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId);
return QvsResponse.post(url, params, client, auth);
}

/*
* 删除设备
*/
public Response deleteDevice(String namespaceId, String gbId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.delete(url, client, auth);
}

/*
* 更新设备
*/
public Response updateDevice(String namespaceId, String gbId, PatchOperation[] patchOperation)
throws QiniuException {
StringMap params = new StringMap().put("operations", patchOperation);
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.patch(url, params, client, auth);
}

/*
* 查询设备
*/
public Response queryDevice(String namespaceId, String gbId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.get(url, client, auth);
}

/*
* 获取设备列表
*/
public Response listDevice(String namespaceId, int offset, int line, String prefix, String state, int qtype)
throws QiniuException {
String requestUrl = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId);
StringMap map = new StringMap().put("offset", offset).put("line", line).put("qtype", qtype)
.put("prefix", prefix).put("state", state);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

/*
public Response createDevice(String namespaceId, Device device) throws QiniuException {
StringMap params = new StringMap();
params.put("name", device.getName());
params.put("gbId", device.getGbId());
params.putNotNull("username", device.getUsername());
params.putNotNull("password", device.getPassword());
params.put("pullIfRegister", device.isPullIfRegister());
params.put("desc", device.getDesc());

String url = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId);
return QvsResponse.post(url, params, client, auth);
}

/*
* 删除设备
*/
public Response deleteDevice(String namespaceId, String gbId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.delete(url, client, auth);
}

/*
* 更新设备
*/
public Response updateDevice(String namespaceId, String gbId, PatchOperation[] patchOperation)
throws QiniuException {
StringMap params = new StringMap().put("operations", patchOperation);
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.patch(url, params, client, auth);
}

/*
* 查询设备
*/
public Response queryDevice(String namespaceId, String gbId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s", apiServer, namespaceId, gbId);
return QvsResponse.get(url, client, auth);
}

/*
* 获取设备列表
*/
public Response listDevice(String namespaceId, int offset, int line, String prefix, String state, int qtype)
throws QiniuException {
String requestUrl = String.format("%s/v1/namespaces/%s/devices", apiServer, namespaceId);
StringMap map = new StringMap().put("offset", offset).put("line", line).put("qtype", qtype)
.put("prefix", prefix).put("state", state);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

/*
* 获取通道列表
*/
public Response listChannels(String namespaceId, String gbId, String prefix) throws QiniuException {
String requestUrl = String.format("%s/v1/namespaces/%s/devices/%s/channels", apiServer, namespaceId, gbId);
StringMap map = new StringMap().put("prefix", prefix);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

/*
* 启动设备拉流
*/
public Response startDevice(String namespaceId, String gbId, String[] channels) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s/start", apiServer, namespaceId, gbId);
StringMap params = new StringMap().put("channels", channels);
return QvsResponse.post(url, params, client, auth);
}

/*
* 停止设备拉流
*/
public Response stopDevice(String namespaceId, String gbId, String[] channels) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s/stop", apiServer, namespaceId, gbId);
StringMap params = new StringMap().put("channels", channels);
return QvsResponse.post(url, params, client, auth);
}
public Response listChannels(String namespaceId, String gbId, String prefix) throws QiniuException {
String requestUrl = String.format("%s/v1/namespaces/%s/devices/%s/channels", apiServer, namespaceId, gbId);
StringMap map = new StringMap().put("prefix", prefix);
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

/*
* 启动设备拉流
*/
public Response startDevice(String namespaceId, String gbId, String[] channels) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s/start", apiServer, namespaceId, gbId);
StringMap params = new StringMap().put("channels", channels);
return QvsResponse.post(url, params, client, auth);
}

/*
* 停止设备拉流
*/
public Response stopDevice(String namespaceId, String gbId, String[] channels) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/devices/%s/stop", apiServer, namespaceId, gbId);
StringMap params = new StringMap().put("channels", channels);
return QvsResponse.post(url, params, client, auth);
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/qvs/StreamManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Response streamsSnapshots(String namespaceId, String streamId, int start,
requestUrl = UrlUtils.composeUrlWithQueries(requestUrl, map);
return QvsResponse.get(requestUrl, client, auth);
}

// 停用流
public Response stopStream(String namespaceId, String streamId) throws QiniuException {
String url = String.format("%s/v1/namespaces/%s/streams/%s/stop", apiServer, namespaceId, streamId);
Expand Down
108 changes: 54 additions & 54 deletions src/main/java/com/qiniu/qvs/model/Device.java
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
package com.qiniu.qvs.model;

public class Device {
private String name;// 设备名称可包含 字母、数字、中划线、下划线;1 ~ 100 个字符长
private String gbId; // 设备国标ID
private String username; // 用户名, 4~40位,可包含大写字母、小写字母、数字、中划线,建议与设备国标ID一致
private String password; // 密码, 4~40位,可包含大写字母、小写字母、数字、中划线
private boolean pullIfRegister; // 注册成功后启动拉流, 默认关闭
private String desc;// 关于设备的描述信息

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getGbId() {
return gbId;
}

public void setGbId(String gbId) {
this.gbId = gbId;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public boolean isPullIfRegister() {
return pullIfRegister;
}

public void setPullIfRegister(boolean pullIfRegister) {
this.pullIfRegister = pullIfRegister;
}

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}
private String name; // 设备名称 (可包含 字母、数字、中划线、下划线;1 ~ 100 个字符长)
private String username; // 用户名, 4~40位,可包含大写字母、小写字母、数字、中划线,建议与设备国标ID一致
private String password; // 密码, 4~40位,可包含大写字母、小写字母、数字、中划线
private boolean pullIfRegister; // 注册成功后启动拉流, 默认关闭
private String desc; // 关于设备的描述信息
private String gbId; // 设备国标ID

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getGbId() {
return gbId;
}

public void setGbId(String gbId) {
this.gbId = gbId;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public boolean isPullIfRegister() {
return pullIfRegister;
}

public void setPullIfRegister(boolean pullIfRegister) {
this.pullIfRegister = pullIfRegister;
}

public String getDesc() {
return desc;
}

public void setDesc(String desc) {
this.desc = desc;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/qiniu/qvs/model/NameSpace.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.qiniu.qvs.model;

public class NameSpace {
public static final int Static = 1;
public static final int Dynamic = 2;
private String id;
private String name; // 空间名称(格式"^[a-zA-Z0-9_-]{1,100}$")
private String desc; // 空间描述
private String accessType; // 接入类型"gb28181"或者“rtmp”
private int rtmpUrlType; // accessType为“rtmp”时,推拉流地址计算方式,1:static, 2:dynamic
public static final int Static = 1;
public static final int Dynamic = 2;
private String[] domains; // 直播域名
private String callback; // 后台服务器回调URL
private boolean disabled; // 流是否被启用, false:启用,true:禁用
Expand Down
10 changes: 4 additions & 6 deletions src/main/java/com/qiniu/qvs/model/Template.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.qiniu.qvs.model;

public class Template {
public static final int RecordNone = 0;
public static final int RecordRealtime = 1;
public static final int RecordByRequired = 2;
public static final int RecordTsFormat = 0;
private String id;
private String name; // 模版名称,格式为 4 ~ 100个字符,可包含小写字母、数字、中划线、汉字)
private String desc; // 模版描述
Expand All @@ -11,14 +15,8 @@ public class Template {
private int recordInterval; // 录制文件时长(单位为秒)
private int snapInterval; // 截图间隔(单位为秒)
private String m3u8FileNameTemplate; // m3u8文件命名格式

private int recordType; // 录制模式, 0(不录制),1(实时录制), 2(按需录制)
public static final int RecordNone = 0;
public static final int RecordRealtime = 1;
public static final int RecordByRequired = 2;
private int recordFileFormat; // 录制文件存储格式,取值:0(ts格式存储)
public static final int RecordTsFormat = 0;

//record/ts/${namespaceId}/${streamId}/${startMs}-${endMs}.ts
private String tsFilenametemplate;
//record/snap/${namespaceId}/${streamId}/${startMs}.jpg // 录制封面
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/qiniu/util/EtagV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,5 @@ private static String etagV2(InputStream in, long len, long[] parts) throws IOEx
System.arraycopy(digest, 0, ret, 1, digest.length);
return UrlSafeBase64.encodeToString(ret);
}
}
}

0 comments on commit eb7fbb6

Please sign in to comment.