Skip to content

Commit 1c09627

Browse files
committed
添加了注释和风格检查
1 parent 6b123ed commit 1c09627

File tree

2 files changed

+139
-68
lines changed

2 files changed

+139
-68
lines changed

src/main/java/com/qiniu/caster/CasterManager.java

Lines changed: 126 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.qiniu.util.Json;
1515
import com.qiniu.util.StringMap;
1616

17-
import java.util.HashMap;
1817

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

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

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

8889
/**
8990
*
91+
* 云导播信息
9092
* @param casterId 导播台id
9193
* @return
9294
*/
93-
public Response getCasterInfo(String casterId){
95+
public Response getCasterInfo(String casterId) {
9496
String url = String.format("%s/v1/casters/%s", server, casterId);
9597
StringMap headers = auth.authorizationV2(url);
9698
Response response = null;
@@ -104,15 +106,16 @@ public Response getCasterInfo(String casterId){
104106

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

127130
/**
128131
*
132+
* 关闭云导播
129133
* @param casterId 导播台id
130134
* @return
131135
*/
@@ -143,7 +147,13 @@ public Response stopCaster(String casterId) {
143147
return response;
144148
}
145149

146-
public Response deleteCaster(String casterId){
150+
/**
151+
*
152+
* 删除云导播
153+
* @param casterId 导播台id
154+
* @return
155+
*/
156+
public Response deleteCaster(String casterId) {
147157
String url = String.format("%s/v1/casters/%s", server, casterId);
148158
StringMap map = new StringMap().putNotNull("CasterId", casterId);
149159
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
@@ -157,7 +167,14 @@ public Response deleteCaster(String casterId){
157167
return response;
158168
}
159169

160-
public Response update(String casterId, CasterParams casterParams){
170+
/**
171+
*
172+
* 更新云导播
173+
* @param casterId 导播台id
174+
* @param casterParams 导播台更新参数
175+
* @return
176+
*/
177+
public Response update(String casterId, CasterParams casterParams) {
161178
String url = String.format("%s/v1/casters/%s", server, casterId);
162179
byte[] body = Json.encode(casterParams).getBytes(Constants.UTF_8);
163180
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
@@ -170,12 +187,19 @@ public Response update(String casterId, CasterParams casterParams){
170187
return response;
171188
}
172189

173-
public Response updatePvw(String casterId, int channel, String staticKey){
190+
/**
191+
*
192+
* 更新PVW监视器频道
193+
* @param casterId 导播台id
194+
* @param channel 监视器频道 [0,7]
195+
* @param staticKey 静态密钥
196+
* @return
197+
*/
198+
public Response updatePvw(String casterId, int channel, String staticKey) {
174199
String url = String.format("%s/v1/static/casters/%s/pvw", server, casterId);
175200
StringMap map = new StringMap().putNotNull("CasterID", casterId)
176-
.putWhen("channel", channel, channel>=0);
201+
.putWhen("channel", channel, channel >= 0);
177202
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
178-
179203
StringMap headers = new StringMap().put("Authorization", staticKey);
180204
Response response = null;
181205
try {
@@ -186,12 +210,20 @@ public Response updatePvw(String casterId, int channel, String staticKey){
186210
return response;
187211
}
188212

189-
public Response updatePgm(String casterId, int channel){
213+
/**
214+
*
215+
* 更新PGM监视器频道
216+
* @param casterId 导播台id
217+
* @param channel 监视器频道 [0,7]
218+
* @param staticKey 静态密钥
219+
* @return
220+
*/
221+
public Response updatePgm(String casterId, int channel, String staticKey) {
190222
String url = String.format("%s/v1/static/casters/%s/pgm", server, casterId);
191223
StringMap map = new StringMap().putNotNull("CasterID", casterId)
192-
.putWhen("channel", channel, channel>=0);
224+
.putWhen("channel", channel, channel >= 0);
193225
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
194-
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
226+
StringMap headers = new StringMap().put("Authorization", staticKey);
195227
Response response = null;
196228
try {
197229
response = client.post(url, body, headers, Client.JsonMime);
@@ -201,12 +233,20 @@ public Response updatePgm(String casterId, int channel){
201233
return response;
202234
}
203235

204-
public Response pvwSwitchToPgm(String casterId, boolean switchVol){
236+
/**
237+
*
238+
* PVW切换至PGM
239+
* @param casterId 导播台id
240+
* @param switchVol 是否同步切换音频
241+
* @param staticKey 静态密钥
242+
* @return
243+
*/
244+
public Response pvwSwitchToPgm(String casterId, boolean switchVol, String staticKey) {
205245
String url = String.format("%s/v1/static/casters/%s/switch", server, casterId);
206246
StringMap map = new StringMap().putNotNull("CasterID", casterId)
207247
.putNotNull("switchVol", switchVol);
208248
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
209-
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
249+
StringMap headers = new StringMap().put("Authorization", staticKey);
210250
Response response = null;
211251
try {
212252
response = client.post(url, body, headers, Client.JsonMime);
@@ -215,13 +255,25 @@ public Response pvwSwitchToPgm(String casterId, boolean switchVol){
215255
}
216256
return response;
217257
}
218-
public Response updateMonitors(String casterId, int channel, String newUrl, int vol, boolean muted){
258+
259+
/**
260+
*
261+
* 更新监视器配置
262+
* @param casterId 导播台id
263+
* @param channel 监视器频道 [0,7]
264+
* @param newUrl 监视器源流地址,支持直播流、静态视频、图片等
265+
* @param vol 音量[0,300]
266+
* @param muted 是否静音
267+
* @param staticKey 静态密钥
268+
* @return
269+
*/
270+
public Response updateMonitors(String casterId, int channel, String newUrl, int vol, boolean muted, String staticKey) {
219271
String url = String.format("%s/v1/static/casters/%s/monitors", server, casterId);
220272
StringMap map = new StringMap().putNotNull("CasterID", casterId)
221-
.putWhen("channel", channel, channel>=0)
222-
.putNotNull("url",newUrl).putWhen("vol", vol, vol>=0).putNotNull("muted",muted);
273+
.putWhen("channel", channel, channel >= 0)
274+
.putNotNull("url", newUrl).putWhen("vol", vol, vol >= 0).putNotNull("muted", muted);
223275
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
224-
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
276+
StringMap headers = new StringMap().put("Authorization", staticKey);
225277
Response response = null;
226278
try {
227279
response = client.post(url, body, headers, Client.JsonMime);
@@ -230,17 +282,31 @@ public Response updateMonitors(String casterId, int channel, String newUrl, int
230282
}
231283
return response;
232284
}
233-
public Response updatePublish(String casterId, String newUrl, int ab, int vb, boolean closed, boolean emergencyMode, int emergencyChannel, int delay){
285+
286+
/**
287+
*
288+
* 更新输出配置
289+
* @param casterId 导播台id
290+
* @param newUrl PGM推流地址
291+
* @param ab [64,512] 音频码率(Kbps),默认值为64,-1为默认值
292+
* @param vb [300,10240] 视频码率(Kbps),默认值为1000,-1为默认值
293+
* @param closed 关闭推流
294+
* @param emergencyMode 紧急模式开关
295+
* @param emergencyChannel 紧急模式监视器频道,取值范围是[0,7],默认使用0频道 [0,7]
296+
* @param delay [0,180] 延时播放,单位: 秒
297+
* @param staticKey 静态密钥
298+
* @return
299+
*/
300+
public Response updatePublish(String casterId, String newUrl, int ab, int vb, boolean closed, boolean emergencyMode, int emergencyChannel, int delay, String staticKey) {
234301
String url = String.format("%s/v1/static/casters/%s/publish", server, casterId);
235302
StringMap map = new StringMap().putNotNull("CasterID", casterId)
236-
.putNotNull("url",newUrl).putWhen("vb", vb, vb>=300)
237-
.putWhen("ab",ab, ab>=64)
238-
.putNotNull("closed",closed).putNotNull("emergencyMode",emergencyMode)
239-
.putWhen("emergencyChannel", emergencyChannel, emergencyChannel>=0)
240-
.putWhen("delay", delay, delay>=0);
241-
303+
.putNotNull("url", newUrl).putWhen("vb", vb, vb >= 0)
304+
.putWhen("ab", ab, ab >= 0)
305+
.putNotNull("closed", closed).putNotNull("emergencyMode", emergencyMode)
306+
.putWhen("emergencyChannel", emergencyChannel, emergencyChannel >= 0)
307+
.putWhen("delay", delay, delay >= 0);
242308
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
243-
StringMap headers = auth.authorizationV2(url, "POST", body, Client.JsonMime);
309+
StringMap headers = new StringMap().put("Authorization", staticKey);
244310
Response response = null;
245311
try {
246312
response = client.post(url, body, headers, Client.JsonMime);
@@ -249,10 +315,19 @@ public Response updatePublish(String casterId, String newUrl, int ab, int vb, bo
249315
}
250316
return response;
251317
}
252-
public Response changeLayout(String casterId, int layout, String staticKey){
318+
319+
/**
320+
*
321+
* 更新PVW布局ID
322+
* @param casterId 导播台id
323+
* @param layout 布局ID,-1表示不使用布局
324+
* @param staticKey 静态密钥
325+
* @return
326+
*/
327+
public Response changeLayout(String casterId, int layout, String staticKey) {
253328
String url = String.format("%s/v1/static/casters/%s/pvw/layouts", server, casterId);
254329
StringMap map = new StringMap().putNotNull("CasterID", casterId)
255-
.putWhen("layout", layout, layout>=0);
330+
.putWhen("layout", layout, layout >= 0);
256331
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
257332
StringMap headers = new StringMap().put("Authorization", staticKey);
258333
Response response = null;
@@ -263,11 +338,23 @@ public Response changeLayout(String casterId, int layout, String staticKey){
263338
}
264339
return response;
265340
}
266-
public Response updateLayout(String casterId, int layout, String title, Overlay overlay, Text text, String staticKey){
341+
342+
/**
343+
*
344+
* 更新布局配置
345+
* @param casterId 导播台ID
346+
* @param layout [0,7] 布局ID
347+
* @param title 布局标题,可留空
348+
* @param overlay 画中画配置,key为对应的监视器频道,详细参数见画中画配置(overlay)详细参数
349+
* @param text 文字水印配置,key为文字水印标题,详细参数见文字水印配置(text)详细参数
350+
* @param staticKey 静态密钥
351+
* @return
352+
*/
353+
public Response updateLayout(String casterId, int layout, String title, Overlay overlay, Text text, String staticKey) {
267354
String url = String.format("%s/v1/static/casters/%s/layouts", server, casterId);
268355
StringMap map = new StringMap().putNotNull("CasterID", casterId)
269-
.putWhen("layout", layout, layout>=0)
270-
.putNotNull("title",title).putNotNull("overlay", overlay).putNotNull("text", text);
356+
.putWhen("layout", layout, layout >= 0)
357+
.putNotNull("title", title).putNotNull("overlay", overlay).putNotNull("text", text);
271358
byte[] body = Json.encode(map).getBytes(Constants.UTF_8);
272359
StringMap headers = new StringMap().put("Authorization", staticKey);
273360
Response response = null;
@@ -278,14 +365,4 @@ public Response updateLayout(String casterId, int layout, String title, Overlay
278365
}
279366
return response;
280367
}
281-
282-
283-
284-
285-
286-
287-
288-
289-
290-
291368
}

0 commit comments

Comments
 (0)