package com.hbbh.adapter.manager.impl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.google.common.collect.Maps;
|
import com.hbbh.adapter.dto.StreamDto;
|
import com.hbbh.adapter.manager.MonibucaManager;
|
import com.hbbh.adapter.utils.HttpClientUtil;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
|
import java.util.List;
|
import java.util.Map;
|
|
|
@Service
|
public class MonibucaManagerImpl implements MonibucaManager {
|
|
private static final Logger log = LoggerFactory.getLogger(Class.class);
|
|
|
@Value("${monica.ip}")
|
private String monicaIP;
|
@Value("${monica.port}")
|
private String monicaPort;
|
@Value("${monica.rtsp.port}")
|
private String monicaRTSPPort;
|
|
|
//入参 rtsp视频流
|
private String rtspDemo="rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov";
|
|
//返回结果,通过配置文件即可反推得到 前提是调用 rtsp/pull 接口成功
|
private String jessibucaDemo="ws://localhost:8080/live/test.flv";
|
|
//StreamPath 是发布流的唯一标识
|
private String streamPath="live/test";
|
|
|
// =========== monica监控 ===========
|
|
/**
|
* 调用Gateway API
|
* 成功返回 {"code":0}
|
* 失败返回 {"code":1,"msg":"publish badname"}
|
* @return jessibucaDemo
|
*/
|
@Override
|
public String parseVideo() {
|
String url="http://localhost:8081/rtsp/pull";
|
Map<String, String> params = Maps.newLinkedHashMap();
|
params.put("target",rtspDemo);
|
params.put("streamPath",streamPath);
|
|
String result = HttpClientUtil.doGet(url, params);
|
|
|
Map map = JSON.parseObject(result, Map.class);
|
String code = map.get("code")+"";
|
String msg = map.get("msg")+"";
|
if (!StringUtils.equals("0",code)){
|
return "-1";
|
}
|
return jessibucaDemo;
|
}
|
|
/**
|
*
|
* @param param StreamPath 是发布流的唯一标识
|
* 示例: http://localhost:8081/api/stop?stream=live/test
|
*/
|
@Override
|
public void stopStream(String param) {
|
String url="http://"+monicaIP+":"+monicaRTSPPort+"/api/stop";
|
Map<String, String> params = Maps.newLinkedHashMap();
|
params.put("stream",param);
|
String result = HttpClientUtil.doGet(url, params);
|
log.info("调用 Monibuca -stopStream- 执行结果 : {}",result);
|
}
|
|
/**
|
* GET
|
* @param param 推流入参
|
*/
|
@Override
|
public void pullStream(StreamDto param) {
|
String url="http://"+monicaIP+":"+monicaRTSPPort+"/rtsp/pull";
|
Map<String, String> params = Maps.newLinkedHashMap();
|
|
String streamPath = param.getStreamPath();
|
String target = param.getTarget();
|
|
params.put("target",target);
|
params.put("streamPath",streamPath);
|
String result = HttpClientUtil.doGet(url, params);
|
log.info("调用 Monibuca -pullStream- 执行结果 : {}",result);
|
}
|
|
/**
|
* GET
|
* @param params 推流入参
|
*/
|
@Override
|
public void pullStreamList(List<StreamDto> params) {
|
String url="http://"+monicaIP+":"+monicaRTSPPort+"/rtsp/pull";
|
|
for (StreamDto param : params) {
|
Map<String, String> paramMap = Maps.newLinkedHashMap();
|
|
String streamPath = param.getStreamPath();
|
String target = param.getTarget();
|
|
paramMap.put("target",target);
|
paramMap.put("streamPath",streamPath);
|
String result = HttpClientUtil.doGet(url, paramMap);
|
log.info("调用 Monibuca -pullStreamList- streamPath:{} 执行结果 : {}",streamPath,result);
|
}
|
}
|
|
/**
|
* GET
|
* @param param Monica启动实例名称
|
*/
|
@Override
|
public void instanceUpdate(String param) {
|
String url="http://"+monicaIP+":"+monicaPort+"/api/instance/update";
|
Map<String, String> params = Maps.newLinkedHashMap();
|
params.put("name",param);
|
String result = HttpClientUtil.doGet(url, params);
|
log.info("调用 Monibuca -instanceUpdate- 执行结果 : {}",result);
|
}
|
|
/**
|
* DELETE
|
* @param param Monica启动实例名称
|
*/
|
@Override
|
public void instanceRemove(String param) {
|
String url="http://"+monicaIP+":"+monicaPort+"/api/instance/remove";
|
Map<String, String> params = Maps.newLinkedHashMap();
|
params.put("name",param);
|
String result = HttpClientUtil.doDelete(url, params);
|
log.info("调用 Monibuca -instanceRemove- 执行结果 : {}",result);
|
}
|
|
/**
|
* POST
|
* @param param Monica启动实例名称
|
*/
|
@Override
|
public void instanceKill(String param) {
|
String url="http://"+monicaIP+":"+monicaPort+"/api/instance/kill";
|
Map<String, String> params = Maps.newLinkedHashMap();
|
params.put("name",param);
|
String result = HttpClientUtil.doPost(url, params);
|
log.info("调用 Monibuca -instanceKill- 执行结果 : {}",result);
|
}
|
|
/**
|
* POST
|
* @param param Monica启动实例名称
|
*/
|
@Override
|
public void instanceStart(String param) {
|
String url="http://"+monicaIP+":"+monicaPort+"/api/instance/start";
|
Map<String, String> params = Maps.newLinkedHashMap();
|
params.put("name",param);
|
String result = HttpClientUtil.doPost(url, params);
|
log.info("调用 Monibuca -instanceStart- 执行结果 : {}",result);
|
}
|
|
@Override
|
public void instanceCreate() {
|
String url="http://"+monicaIP+":"+monicaPort+"/api/instance/create";
|
Map<String, String> params = Maps.newLinkedHashMap();
|
params.put("path","/Users/xucheng/Downloads/store/live");
|
params.put("name","live");
|
params.put("info",info);
|
params.put("clear","true");
|
String result = HttpClientUtil.doGet(url, params);
|
log.info("调用 Monibuca -instanceCreate- 执行结果 : {}",result);
|
|
}
|
|
|
|
private String info="[Monibuca]\n" +
|
"# 是否等待流,如果为true则订阅一个尚未发布的流会进入等待发布的状态,否则返回订阅失败\n" +
|
"EnableWaitStream = true\n" +
|
"EnableAudio = true\n" +
|
"EnableVideo = true\n" +
|
"# 缓冲环大小默认是2的10次方\n" +
|
"RingSize = 10\n" +
|
"# 发布流默认过期时间 1分钟\n" +
|
"PublishTimeout = 60000000000\n" +
|
"[RTMP]\n" +
|
"ListenAddr = \":1935\"\n" +
|
"[GateWay]\n" +
|
"ListenAddr = \":8081\"\n" +
|
"[Jessica]\n" +
|
"ListenAddr = \":8080\"\n" +
|
"[LogRotate]\n" +
|
"# 日志存储目录相对或绝对\n" +
|
"Path = \"logs\"\n" +
|
"# 日志是否按大小分割,0表示不按大小分割,非零代表按该大小字节进行分割\n" +
|
"Size = 0\n" +
|
"Days = 1\n" +
|
"[Cluster]\n" +
|
"# 监听端口代表该服务器为源服务器\n" +
|
"ListenAddr = \":2019\"\n" +
|
"# 源服务器地址,用于向源服务器进行推或拉流\n" +
|
"OriginServer = \"\"\n" +
|
"# 推送模式,true表示如果此服务器有发布流,就会推送到源服务器,否则表示拉模式,即如果此服务器有订阅流则从源服务器拉流\n" +
|
"Push = true\n" +
|
"[HLS]\n" +
|
"# 是否开启写磁盘,开启后侦测到发布流就会开始写TS文件\n" +
|
"EnableWrite = false\n" +
|
"# 是否打开内存模式,在内存中保留TS数据,方便直接读取\n" +
|
"EnableMemory = false\n" +
|
"# 分片大小 单位秒\n" +
|
"Fragment = 10\n" +
|
"# 窗口数里,代表一个m3u8文件里面有几个ts\n" +
|
"Window = 2\n" +
|
"# ts文件存放目录,m3u8会存放在上一级\n" +
|
"Path = \"resource\"\n" +
|
"[HDL]\n" +
|
"ListenAddr = \":2020\"\n" +
|
"[TS]\n" +
|
"# 是否自动发布,开启后一旦有订阅流就会读取ts文件进行发布,方便测试\n" +
|
"AutoPublish = false\n" +
|
"# ts存放目录\n" +
|
"Path = \"resource\"\n" +
|
"[Record]\n" +
|
"Path = \"resource\"\n" +
|
"# 是否自动发布,开启后一旦有订阅流就会读取flv文件进行发布,方便测试\n" +
|
"AutoPublish = false\n" +
|
"# 自动录制功能\n" +
|
"AutoRecord = false\n" +
|
"[RTSP]\n" +
|
"ListenAddr = \":554\"\n" +
|
"AutoPull = true\n" +
|
"Reconnect = true\n" +
|
"RemoteAddr = \"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov\"\n" +
|
"StreamPath = \"live/rtsp\"\n" +
|
"#[[RTSP.AutoPullList]]\n" +
|
"#URL = \"rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov\"\n" +
|
"#StreamPath = \"live/rtsp2\"\n" +
|
"[WebRTC]\n" +
|
"# 公网IP地址\n" +
|
"PublicIP = [\"127.0.0.1\"]\n" +
|
"# 端口范围不配置的话是自动分配\n" +
|
"# PortMin = 30000\n" +
|
"# PortMax = 40000\n" +
|
"[GB28181]\n" +
|
"Serial = \"34020000002000000001\"\n" +
|
"Realm = \"3402000000\"\n" +
|
"Expires = 3600\n" +
|
"AutoInvite = false\n" +
|
"ListenAddr = \"192.168.1.120:5060\"";
|
}
|