|
|
@@ -66,13 +66,16 @@ public class RtmpLiveService { |
|
|
|
}); |
|
|
|
thread.start(); |
|
|
|
status=1; |
|
|
|
String pushUrl = cmdParam.getPushUrl(); |
|
|
|
String playUrl=cmdParam.getPlayUrl(); |
|
|
|
if (cmdParam.getVlc()!=null&&cmdParam.getVlc().equals("on")) { |
|
|
|
playUrl = VLCJ.startVlcj(playUrl,cmdParam.getVlcUrl()); |
|
|
|
} |
|
|
|
//Thread.sleep(5000); |
|
|
|
String pushUrl = ""; |
|
|
|
if (cmdParam.getType() == 0){ |
|
|
|
log.info("使用指令推流"); |
|
|
|
runRtmpByCmd(cmdParam.getCmd()); |
|
|
|
}else |
|
|
|
if (cmdParam.getType() == 2) { |
|
|
|
}else if (cmdParam.getType() == 2) { |
|
|
|
log.info("获取流媒体通道"); |
|
|
|
//TODO 获取通道服务推拉流地址 |
|
|
|
JSONObject object = getChenl(); |
|
|
@@ -88,21 +91,22 @@ public class RtmpLiveService { |
|
|
|
mqttProviderConfig.publish(2, false, reTopic, object.toJSONString()); |
|
|
|
return; |
|
|
|
} |
|
|
|
runRtmp(pushUrl, cmdParam.getPlayUrl(), code); |
|
|
|
runRtmp(pushUrl, playUrl, code); |
|
|
|
//TODO end |
|
|
|
} else if (cmdParam.getType() == 1) { |
|
|
|
log.info("使用固定流媒体通道"); |
|
|
|
pushUrl = cmdParam.getPushUrl(); |
|
|
|
runRtmp(pushUrl, cmdParam.getPlayUrl(), code); |
|
|
|
runRtmp(pushUrl, playUrl, code); |
|
|
|
} else if (cmdParam.getType() == 3) { |
|
|
|
runRtmp2to2(cmdParam.getPlayUrl()); |
|
|
|
runRtmp2to2(playUrl); |
|
|
|
} else if (cmdParam.getType() == 4) { |
|
|
|
runRtmp1to2(cmdParam.getPlayUrl()); |
|
|
|
runRtmp1to2(playUrl); |
|
|
|
} |
|
|
|
/*status=0; |
|
|
|
DefaultOutHandlerMethod.outIdMap=new HashMap();*/ |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void runRtmp2to2(String playUrl) throws InterruptedException { |
|
|
|
try { |
|
|
|
String reTopic = cmdParam.getMqttTopic().replace("live", "result"); |
|
|
@@ -238,7 +242,7 @@ public class RtmpLiveService { |
|
|
|
log.info("获取播流地址:{}"); |
|
|
|
//CommandManager manager = new CommandManagerImpl(); |
|
|
|
String taskId = manager.start("push1", CommandBuidlerFactory.createBuidler() |
|
|
|
.add("ffmpeg").add("-rtsp_transport", "tcp") |
|
|
|
.add("ffmpeg -re")/*.add("-rtsp_transport", "tcp")*/ |
|
|
|
.add("-i", playUrl) |
|
|
|
.add("-vcodec", "copy") |
|
|
|
/*.add("-acodec", "copy")*/ |
|
|
@@ -277,41 +281,10 @@ public class RtmpLiveService { |
|
|
|
//ds.close(); |
|
|
|
} |
|
|
|
|
|
|
|
/*private void checkMsg1() throws InterruptedException { |
|
|
|
long oldtime = System.currentTimeMillis(); |
|
|
|
String oldMsg = ""; |
|
|
|
while (true) { |
|
|
|
String msg = OutHandler.outMsg==null?"":OutHandler.outMsg; |
|
|
|
if (!msg.equals(oldMsg)) { |
|
|
|
oldMsg=msg; |
|
|
|
oldtime=System.currentTimeMillis(); |
|
|
|
} |
|
|
|
log.info("消息输出{},状态{}",msg,status); |
|
|
|
if (System.currentTimeMillis()-oldtime>15000&&msg.equals(oldMsg)&&status==1){ |
|
|
|
//log.info("消息未输出{}",msg); |
|
|
|
if(manager.queryAll().size()>0){ |
|
|
|
Collection<CommandTasker> list = manager.queryAll(); |
|
|
|
Iterator<CommandTasker> commandTaskerIterator = list.iterator(); |
|
|
|
CommandTasker s = commandTaskerIterator.next(); |
|
|
|
log.info("0000{},{}",s.getId(),s.getCommand()); |
|
|
|
log.info("任务消息未输出",s); |
|
|
|
manager.stop(s.getId()); |
|
|
|
Thread.sleep(2000); |
|
|
|
String result= manager.start(s.getId(),s.getCommand().split("bin/")[1]); |
|
|
|
if (!StringUtils.isNullOrEmpty(result)){ |
|
|
|
oldtime= System.currentTimeMillis(); |
|
|
|
}else{ |
|
|
|
log.info("推流失败,重新推流"); |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
if (status==0){ |
|
|
|
break; |
|
|
|
} |
|
|
|
Thread.sleep(200); |
|
|
|
} |
|
|
|
}*/ |
|
|
|
private void checkMsg() throws InterruptedException { |
|
|
|
//推流起始时间 |
|
|
|
long cmdtime = System.currentTimeMillis(); |
|
|
|
//消息更新时间 |
|
|
|
long oldtime = System.currentTimeMillis(); |
|
|
|
String oldMsg = ""; |
|
|
|
long oldtime2 = System.currentTimeMillis(); |
|
|
@@ -353,7 +326,7 @@ public class RtmpLiveService { |
|
|
|
log.info("无任务,停止监听1"); |
|
|
|
break; |
|
|
|
} |
|
|
|
if (status==0&&manager.queryAll().size()==0){ |
|
|
|
if ((status==0&&manager.queryAll().size()==0)){ |
|
|
|
log.info("无任务,停止监听2"); |
|
|
|
Thread.sleep(5000); |
|
|
|
if (manager.queryAll().size()>0){ |
|
|
@@ -363,6 +336,15 @@ public class RtmpLiveService { |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
/*if (System.currentTimeMillis()-cmdtime>cmdParam.getTime()){ |
|
|
|
log.info("推流时间超时"); |
|
|
|
if (manager.queryAll().size()>0){ |
|
|
|
log.info("延迟检测推流关闭"); |
|
|
|
manager.stopAll(); |
|
|
|
manager.destory(); |
|
|
|
break; |
|
|
|
} |
|
|
|
}*/ |
|
|
|
Thread.sleep(400); |
|
|
|
} |
|
|
|
} |
|
|
@@ -379,6 +361,7 @@ public class RtmpLiveService { |
|
|
|
Iterator<CommandTasker> commandTaskerIterator = list.iterator();*/ |
|
|
|
CommandTasker s = manager.query(id); |
|
|
|
if (!ObjectUtils.isEmpty(s)) { |
|
|
|
checkVlc(cmdParam.getPlayUrl()); |
|
|
|
log.info("0000{},{}", s.getId(), s.getCommand()); |
|
|
|
log.info("任务消息未输出,重新推流", s); |
|
|
|
manager.stop(s.getId()); |
|
|
@@ -397,6 +380,20 @@ public class RtmpLiveService { |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
private void checkVlc(String playUrl) { |
|
|
|
if (cmdParam.getVlc().equals("on")) { |
|
|
|
if (VLCJ.vlcStatus!=3||VLCJ.buffstatus<0){ |
|
|
|
try { |
|
|
|
VLCJ.startVlcj(playUrl,cmdParam.getVlcUrl()); |
|
|
|
} catch (InterruptedException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
//System.out.println(VLCJ.mediaPlayerComponent.getMediaPlayer().getMediaMeta().getTrackNumber()); |
|
|
|
//VLCJ.mediaPlayerComponent.getMediaPlayer().getMediaState(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void stopRtmp() { |
|
|
|
try { |
|
|
|
status=0; |
|
|
@@ -421,6 +418,9 @@ public class RtmpLiveService { |
|
|
|
returnChenl(); |
|
|
|
mqttProviderConfig.publish(2, false, reTopic, jsonObject.toJSONString()); |
|
|
|
} |
|
|
|
if (!ObjectUtils.isEmpty(VLCJ.mediaPlayerComponent)){ |
|
|
|
VLCJ.stopVlcj(); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("", e); |
|
|
|
} |