推流不稳定问题修复
This commit is contained in:
parent
7dc9992bd8
commit
2843072216
|
|
@ -15,53 +15,59 @@ public class MqttLiveHandle {
|
||||||
private RtmpLiveService rtmpLiveService;
|
private RtmpLiveService rtmpLiveService;
|
||||||
|
|
||||||
public void handleLive(final String topic, MqttMessage message) throws InterruptedException {
|
public void handleLive(final String topic, MqttMessage message) throws InterruptedException {
|
||||||
String objmsg = new String(message.getPayload());
|
try {
|
||||||
final JSONObject jsonObject = JSONObject.parseObject(objmsg);
|
String objmsg = new String(message.getPayload());
|
||||||
if (topic.contains("rtmp/live")) {
|
final JSONObject jsonObject = JSONObject.parseObject(objmsg);
|
||||||
if (!ObjectUtils.isEmpty(jsonObject.get("command"))) {
|
if (topic.contains("rtmp/live")) {
|
||||||
String cmdoperat = jsonObject.get("command").toString();
|
if (!ObjectUtils.isEmpty(jsonObject.get("command"))) {
|
||||||
if (cmdoperat.equals("start")) {
|
String cmdoperat = jsonObject.get("command").toString();
|
||||||
|
if (cmdoperat.equals("start")) {
|
||||||
|
|
||||||
Thread thread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
String code = jsonObject.get("code") == null ? topic.split("/")[2] : jsonObject.get("code").toString();
|
String code = jsonObject.get("code") == null ? topic.split("/")[2] : jsonObject.get("code").toString();
|
||||||
public void run() {
|
|
||||||
try {
|
public void run() {
|
||||||
rtmpLiveService.pushServer(code);
|
try {
|
||||||
} catch (InterruptedException e) {
|
rtmpLiveService.pushServer(code);
|
||||||
e.printStackTrace();
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
thread.start();
|
||||||
thread.start();
|
} else if (cmdoperat.equals("stop")) {
|
||||||
} else if (cmdoperat.equals("stop")) {
|
rtmpLiveService.stopRtmp();
|
||||||
rtmpLiveService.stopRtmp();
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if (topic.contains("/data/DroneBMS")) {
|
||||||
}else if(topic.contains("/data/DroneBMS")){
|
log.info("获取object:", jsonObject);
|
||||||
log.info("获取object:",jsonObject);
|
if (!ObjectUtils.isEmpty(jsonObject.get("parm"))) {
|
||||||
if (!ObjectUtils.isEmpty(jsonObject.get("parm"))) {
|
log.info("获取param:", jsonObject.get("parm"));
|
||||||
log.info("获取param:",jsonObject.get("parm"));
|
JSONObject cmdoperat = jsonObject.getJSONObject("parm");
|
||||||
JSONObject cmdoperat = jsonObject.getJSONObject("parm");
|
String boolbms = cmdoperat.getString("Power");
|
||||||
String boolbms = cmdoperat.getString("Power");
|
log.info("boolbms:", jsonObject.get("Power"));
|
||||||
log.info("boolbms:",jsonObject.get("Power"));
|
if (boolbms.equals("on")) {
|
||||||
if (boolbms.equals("on")) {
|
|
||||||
|
Thread thread = new Thread(new Runnable() {
|
||||||
Thread thread = new Thread(new Runnable() {
|
String code = jsonObject.get("code") == null ? topic.split("/")[2] : jsonObject.get("code").toString();
|
||||||
String code = jsonObject.get("code") == null ? topic.split("/")[2] : jsonObject.get("code").toString();
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
rtmpLiveService.pushServer(code);
|
rtmpLiveService.pushServer(code);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
thread.start();
|
thread.start();
|
||||||
} else if (boolbms.equals("off")) {
|
} else if (boolbms.equals("off")) {
|
||||||
log.info("关闭流");
|
log.info("关闭流");
|
||||||
rtmpLiveService.stopRtmp();
|
rtmpLiveService.stopRtmp();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("",e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,8 +99,8 @@ public class RtmpLiveService {
|
||||||
} else if (cmdParam.getType() == 4) {
|
} else if (cmdParam.getType() == 4) {
|
||||||
runRtmp1to2(cmdParam.getPlayUrl());
|
runRtmp1to2(cmdParam.getPlayUrl());
|
||||||
}
|
}
|
||||||
status=0;
|
/*status=0;
|
||||||
DefaultOutHandlerMethod.outIdMap=new HashMap();
|
DefaultOutHandlerMethod.outIdMap=new HashMap();*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runRtmp2to2(String playUrl) throws InterruptedException {
|
private void runRtmp2to2(String playUrl) throws InterruptedException {
|
||||||
|
|
@ -140,11 +140,11 @@ public class RtmpLiveService {
|
||||||
jsonObject.put("msg", "推流服务启动成功");
|
jsonObject.put("msg", "推流服务启动成功");
|
||||||
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
|
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
|
||||||
}
|
}
|
||||||
Thread.sleep(cmdParam.getTime());
|
/*Thread.sleep(cmdParam.getTime());
|
||||||
log.info(manager.queryAll().toString());
|
log.info(manager.queryAll().toString());
|
||||||
// 停止全部任务
|
// 停止全部任务
|
||||||
manager.stopAll();
|
manager.stopAll();
|
||||||
manager.destory();
|
manager.destory();*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -178,11 +178,11 @@ public class RtmpLiveService {
|
||||||
jsonObject.put("msg", "推流服务启动成功");
|
jsonObject.put("msg", "推流服务启动成功");
|
||||||
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
|
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
|
||||||
}
|
}
|
||||||
Thread.sleep(cmdParam.getTime());
|
/*Thread.sleep(cmdParam.getTime());
|
||||||
log.info(manager.queryAll().toString());
|
log.info(manager.queryAll().toString());
|
||||||
// 停止全部任务
|
// 停止全部任务
|
||||||
manager.stopAll();
|
manager.stopAll();
|
||||||
manager.destory();
|
manager.destory();*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
@ -266,18 +266,18 @@ public class RtmpLiveService {
|
||||||
jsonObject.put("msg", "推流服务启动成功");
|
jsonObject.put("msg", "推流服务启动成功");
|
||||||
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
|
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
|
||||||
}
|
}
|
||||||
Thread.sleep(cmdParam.getTime());
|
/*Thread.sleep(cmdParam.getTime());
|
||||||
log.info(manager.queryAll().toString());
|
log.info(manager.queryAll().toString());
|
||||||
// 停止全部任务
|
// 停止全部任务
|
||||||
manager.stopAll();
|
manager.stopAll();
|
||||||
manager.destory();
|
manager.destory();*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("", e);
|
log.error("", e);
|
||||||
}
|
}
|
||||||
//ds.close();
|
//ds.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkMsg1() throws InterruptedException {
|
/*private void checkMsg1() throws InterruptedException {
|
||||||
long oldtime = System.currentTimeMillis();
|
long oldtime = System.currentTimeMillis();
|
||||||
String oldMsg = "";
|
String oldMsg = "";
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
@ -310,7 +310,7 @@ public class RtmpLiveService {
|
||||||
}
|
}
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
private void checkMsg() throws InterruptedException {
|
private void checkMsg() throws InterruptedException {
|
||||||
long oldtime = System.currentTimeMillis();
|
long oldtime = System.currentTimeMillis();
|
||||||
String oldMsg = "";
|
String oldMsg = "";
|
||||||
|
|
@ -358,7 +358,7 @@ public class RtmpLiveService {
|
||||||
CommandTasker s = manager.query(id);
|
CommandTasker s = manager.query(id);
|
||||||
if (!ObjectUtils.isEmpty(s)) {
|
if (!ObjectUtils.isEmpty(s)) {
|
||||||
log.info("0000{},{}", s.getId(), s.getCommand());
|
log.info("0000{},{}", s.getId(), s.getCommand());
|
||||||
log.info("任务消息未输出", s);
|
log.info("任务消息未输出,重新推流", s);
|
||||||
manager.stop(s.getId());
|
manager.stop(s.getId());
|
||||||
Thread.sleep(2000);
|
Thread.sleep(2000);
|
||||||
String result = manager.start(s.getId(), s.getCommand().split("bin/")[1]);
|
String result = manager.start(s.getId(), s.getCommand().split("bin/")[1]);
|
||||||
|
|
@ -470,11 +470,11 @@ public class RtmpLiveService {
|
||||||
jsonObject.put("msg", "推流服务启动成功");
|
jsonObject.put("msg", "推流服务启动成功");
|
||||||
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
|
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString());
|
||||||
}
|
}
|
||||||
Thread.sleep(cmdParam.getTime());
|
/*Thread.sleep(cmdParam.getTime());
|
||||||
log.info(manager.queryAll().toString());
|
log.info(manager.queryAll().toString());
|
||||||
// 停止全部任务
|
// 停止全部任务
|
||||||
manager.stopAll();
|
manager.stopAll();
|
||||||
manager.destory();
|
manager.destory();*/
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("", e);
|
log.error("", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,11 +71,8 @@ public class IndexController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String start() {
|
public String start() {
|
||||||
try {
|
try {
|
||||||
if(rtmpLiveService.manager.queryAll().size()>0){
|
log.info("http发送重启推流");
|
||||||
rtmpLiveService.status=0;
|
rtmpLiveService.stopRtmp();
|
||||||
DefaultOutHandlerMethod.outIdMap= new HashMap();
|
|
||||||
rtmpLiveService.manager.stopAll();
|
|
||||||
};
|
|
||||||
//启动线程
|
//启动线程
|
||||||
Thread thread = new Thread(new Runnable() {
|
Thread thread = new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
@ -106,11 +103,8 @@ public class IndexController {
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
public String stop() {
|
public String stop() {
|
||||||
try {
|
try {
|
||||||
if(rtmpLiveService.manager.queryAll().size()>0){
|
log.info("http发送停止推流");
|
||||||
rtmpLiveService.status=0;
|
rtmpLiveService.stopRtmp();
|
||||||
DefaultOutHandlerMethod.outIdMap= new HashMap();
|
|
||||||
rtmpLiveService.manager.stopAll();
|
|
||||||
};
|
|
||||||
return objectMapper.writeValueAsString("success");
|
return objectMapper.writeValueAsString("success");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue