Skip to content

Commit

Permalink
添加了注释和风格检查
Browse files Browse the repository at this point in the history
  • Loading branch information
iuaku committed Dec 21, 2021
1 parent 6b123ed commit 1c09627
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 68 deletions.
175 changes: 126 additions & 49 deletions src/main/java/com/qiniu/caster/CasterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.qiniu.util.Json;
import com.qiniu.util.StringMap;

import java.util.HashMap;

public class CasterManager {
private final Auth auth;
Expand All @@ -39,6 +38,7 @@ public CasterManager(Auth auth, String server, Client client) {

/**
*
* 创建云导播
* @param name 导播台name
* @param casterParams 导播台参数
* @return
Expand All @@ -47,9 +47,9 @@ public Response createCaster(String name, CasterParams casterParams) {
String url = server + "/v1/casters";
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonElement jsonElement = gson.toJsonTree(casterParams);
jsonElement.getAsJsonObject().addProperty("name",name);
jsonElement.getAsJsonObject().addProperty("name", name);
byte[] body = gson.toJson(jsonElement).getBytes(Constants.UTF_8);
System.out.println(body.toString());
String a = gson.toJson(jsonElement);
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
Response response = null;
try {
Expand All @@ -62,9 +62,10 @@ public Response createCaster(String name, CasterParams casterParams) {

/**
*
* @param name 导播台name
* @param marker
* @param limit
* 云导播列表
* @param name 云导播名称前缀匹配
* @param marker 如果上一次返回的结果超过了单次查询限制,则会返回marker表示上一次读取到哪条记录;这一次请求带上marker后,继续从该marker后开始读取,设置为null为从头开始
* @param limit 返回的最大数量,设置为-1默认为50
* @return
*/
public Response findCasters(String name, String marker, int limit) {
Expand All @@ -78,7 +79,7 @@ public Response findCasters(String name, String marker, int limit) {
StringMap headers = auth.authorizationV2(url);
Response response = null;
try {
response = client.get(url,headers);
response = client.get(url, headers);
} catch (QiniuException e) {
e.printStackTrace();
}
Expand All @@ -87,10 +88,11 @@ public Response findCasters(String name, String marker, int limit) {

/**
*
* 云导播信息
* @param casterId 导播台id
* @return
*/
public Response getCasterInfo(String casterId){
public Response getCasterInfo(String casterId) {
String url = String.format("%s/v1/casters/%s", server, casterId);
StringMap headers = auth.authorizationV2(url);
Response response = null;
Expand All @@ -104,15 +106,16 @@ public Response getCasterInfo(String casterId){

/**
*
* 开启云导播
* @param casterId 导播台id
* @param start 开始时间戳
* @param hour 开启时长,设置为0,为1小时;导播台已开启时,表示延长开启时长
* @param start 开启时间,设置为-1立即启动;导播台已开启时,禁止设置开启时间,规格为时间戳(秒级)
* @param hour 开启时长,设置为-1为默认为1小时;导播台已开启时,表示延长开启时长 [1.~]
* @return
*/
public Response startCaster(String casterId, int start, int hour) {
String url = String.format("%s/v1/casters/%s/start", server, casterId);
StringMap map = new StringMap().putWhen("start", start, start>0)
.putWhen("hour", hour, hour>0);
StringMap map = new StringMap().putWhen("start", start, start > 0)
.putWhen("hour", hour, hour > 0);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
Response response = null;
Expand All @@ -126,6 +129,7 @@ public Response startCaster(String casterId, int start, int hour) {

/**
*
* 关闭云导播
* @param casterId 导播台id
* @return
*/
Expand All @@ -143,7 +147,13 @@ public Response stopCaster(String casterId) {
return response;
}

public Response deleteCaster(String casterId){
/**
*
* 删除云导播
* @param casterId 导播台id
* @return
*/
public Response deleteCaster(String casterId) {
String url = String.format("%s/v1/casters/%s", server, casterId);
StringMap map = new StringMap().putNotNull("CasterId", casterId);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
Expand All @@ -157,7 +167,14 @@ public Response deleteCaster(String casterId){
return response;
}

public Response update(String casterId, CasterParams casterParams){
/**
*
* 更新云导播
* @param casterId 导播台id
* @param casterParams 导播台更新参数
* @return
*/
public Response update(String casterId, CasterParams casterParams) {
String url = String.format("%s/v1/casters/%s", server, casterId);
byte[] body = Json.encode(casterParams).getBytes(Constants.UTF_8);
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
Expand All @@ -170,12 +187,19 @@ public Response update(String casterId, CasterParams casterParams){
return response;
}

public Response updatePvw(String casterId, int channel, String staticKey){
/**
*
* 更新PVW监视器频道
* @param casterId 导播台id
* @param channel 监视器频道 [0,7]
* @param staticKey 静态密钥
* @return
*/
public Response updatePvw(String casterId, int channel, String staticKey) {
String url = String.format("%s/v1/static/casters/%s/pvw", server, casterId);
StringMap map = new StringMap().putNotNull("CasterID", casterId)
.putWhen("channel", channel, channel>=0);
.putWhen("channel", channel, channel >= 0);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);

StringMap headers = new StringMap().put("Authorization", staticKey);
Response response = null;
try {
Expand All @@ -186,12 +210,20 @@ public Response updatePvw(String casterId, int channel, String staticKey){
return response;
}

public Response updatePgm(String casterId, int channel){
/**
*
* 更新PGM监视器频道
* @param casterId 导播台id
* @param channel 监视器频道 [0,7]
* @param staticKey 静态密钥
* @return
*/
public Response updatePgm(String casterId, int channel, String staticKey) {
String url = String.format("%s/v1/static/casters/%s/pgm", server, casterId);
StringMap map = new StringMap().putNotNull("CasterID", casterId)
.putWhen("channel", channel, channel>=0);
.putWhen("channel", channel, channel >= 0);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
StringMap headers = new StringMap().put("Authorization", staticKey);
Response response = null;
try {
response = client.post(url, body, headers, Client.JsonMime);
Expand All @@ -201,12 +233,20 @@ public Response updatePgm(String casterId, int channel){
return response;
}

public Response pvwSwitchToPgm(String casterId, boolean switchVol){
/**
*
* PVW切换至PGM
* @param casterId 导播台id
* @param switchVol 是否同步切换音频
* @param staticKey 静态密钥
* @return
*/
public Response pvwSwitchToPgm(String casterId, boolean switchVol, String staticKey) {
String url = String.format("%s/v1/static/casters/%s/switch", server, casterId);
StringMap map = new StringMap().putNotNull("CasterID", casterId)
.putNotNull("switchVol", switchVol);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
StringMap headers = new StringMap().put("Authorization", staticKey);
Response response = null;
try {
response = client.post(url, body, headers, Client.JsonMime);
Expand All @@ -215,13 +255,25 @@ public Response pvwSwitchToPgm(String casterId, boolean switchVol){
}
return response;
}
public Response updateMonitors(String casterId, int channel, String newUrl, int vol, boolean muted){

/**
*
* 更新监视器配置
* @param casterId 导播台id
* @param channel 监视器频道 [0,7]
* @param newUrl 监视器源流地址,支持直播流、静态视频、图片等
* @param vol 音量[0,300]
* @param muted 是否静音
* @param staticKey 静态密钥
* @return
*/
public Response updateMonitors(String casterId, int channel, String newUrl, int vol, boolean muted, String staticKey) {
String url = String.format("%s/v1/static/casters/%s/monitors", server, casterId);
StringMap map = new StringMap().putNotNull("CasterID", casterId)
.putWhen("channel", channel, channel>=0)
.putNotNull("url",newUrl).putWhen("vol", vol, vol>=0).putNotNull("muted",muted);
.putWhen("channel", channel, channel >= 0)
.putNotNull("url", newUrl).putWhen("vol", vol, vol >= 0).putNotNull("muted", muted);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
StringMap headers = new StringMap().put("Authorization", staticKey);
Response response = null;
try {
response = client.post(url, body, headers, Client.JsonMime);
Expand All @@ -230,17 +282,31 @@ public Response updateMonitors(String casterId, int channel, String newUrl, int
}
return response;
}
public Response updatePublish(String casterId, String newUrl, int ab, int vb, boolean closed, boolean emergencyMode, int emergencyChannel, int delay){

/**
*
* 更新输出配置
* @param casterId 导播台id
* @param newUrl PGM推流地址
* @param ab [64,512] 音频码率(Kbps),默认值为64,-1为默认值
* @param vb [300,10240] 视频码率(Kbps),默认值为1000,-1为默认值
* @param closed 关闭推流
* @param emergencyMode 紧急模式开关
* @param emergencyChannel 紧急模式监视器频道,取值范围是[0,7],默认使用0频道 [0,7]
* @param delay [0,180] 延时播放,单位: 秒
* @param staticKey 静态密钥
* @return
*/
public Response updatePublish(String casterId, String newUrl, int ab, int vb, boolean closed, boolean emergencyMode, int emergencyChannel, int delay, String staticKey) {
String url = String.format("%s/v1/static/casters/%s/publish", server, casterId);
StringMap map = new StringMap().putNotNull("CasterID", casterId)
.putNotNull("url",newUrl).putWhen("vb", vb, vb>=300)
.putWhen("ab",ab, ab>=64)
.putNotNull("closed",closed).putNotNull("emergencyMode",emergencyMode)
.putWhen("emergencyChannel", emergencyChannel, emergencyChannel>=0)
.putWhen("delay", delay, delay>=0);

.putNotNull("url", newUrl).putWhen("vb", vb, vb >= 0)
.putWhen("ab", ab, ab >= 0)
.putNotNull("closed", closed).putNotNull("emergencyMode", emergencyMode)
.putWhen("emergencyChannel", emergencyChannel, emergencyChannel >= 0)
.putWhen("delay", delay, delay >= 0);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
StringMap headers = new StringMap().put("Authorization", staticKey);
Response response = null;
try {
response = client.post(url, body, headers, Client.JsonMime);
Expand All @@ -249,10 +315,19 @@ public Response updatePublish(String casterId, String newUrl, int ab, int vb, bo
}
return response;
}
public Response changeLayout(String casterId, int layout, String staticKey){

/**
*
* 更新PVW布局ID
* @param casterId 导播台id
* @param layout 布局ID,-1表示不使用布局
* @param staticKey 静态密钥
* @return
*/
public Response changeLayout(String casterId, int layout, String staticKey) {
String url = String.format("%s/v1/static/casters/%s/pvw/layouts", server, casterId);
StringMap map = new StringMap().putNotNull("CasterID", casterId)
.putWhen("layout", layout, layout>=0);
.putWhen("layout", layout, layout >= 0);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
StringMap headers = new StringMap().put("Authorization", staticKey);
Response response = null;
Expand All @@ -263,11 +338,23 @@ public Response changeLayout(String casterId, int layout, String staticKey){
}
return response;
}
public Response updateLayout(String casterId, int layout, String title, Overlay overlay, Text text, String staticKey){

/**
*
* 更新布局配置
* @param casterId 导播台ID
* @param layout [0,7] 布局ID
* @param title 布局标题,可留空
* @param overlay 画中画配置,key为对应的监视器频道,详细参数见画中画配置(overlay)详细参数
* @param text 文字水印配置,key为文字水印标题,详细参数见文字水印配置(text)详细参数
* @param staticKey 静态密钥
* @return
*/
public Response updateLayout(String casterId, int layout, String title, Overlay overlay, Text text, String staticKey) {
String url = String.format("%s/v1/static/casters/%s/layouts", server, casterId);
StringMap map = new StringMap().putNotNull("CasterID", casterId)
.putWhen("layout", layout, layout>=0)
.putNotNull("title",title).putNotNull("overlay", overlay).putNotNull("text", text);
.putWhen("layout", layout, layout >= 0)
.putNotNull("title", title).putNotNull("overlay", overlay).putNotNull("text", text);
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
StringMap headers = new StringMap().put("Authorization", staticKey);
Response response = null;
Expand All @@ -278,14 +365,4 @@ public Response updateLayout(String casterId, int layout, String title, Overlay
}
return response;
}










}
Loading

0 comments on commit 1c09627

Please sign in to comment.