添加如果流不存在则关闭时候报错
This commit is contained in:
parent
94c8935b1a
commit
4779c1b1bc
|
|
@ -72,12 +72,16 @@ public class StreamRecordController {
|
|||
if(Objects.isNull(streamUrl)) {
|
||||
return Response.fail(-1);
|
||||
}
|
||||
Response<StreamTask> response = Response.success(taskService.stopTask(streamUrl));
|
||||
if(Objects.isNull(response.getData().getOutFileName()) || response.getData().getOutFileName().isEmpty()){
|
||||
response.setCode(500);
|
||||
try {
|
||||
Response<StreamTask> response = Response.success(taskService.stopTask(streamUrl));
|
||||
if(Objects.isNull(response.getData()) || Objects.isNull(response.getData().getOutFileName()) || response.getData().getOutFileName().isEmpty()){
|
||||
response.setCode(500);
|
||||
}
|
||||
System.out.println("关闭录制返回 :"+ JSON.toJSONString(response));
|
||||
return response;
|
||||
}catch (Exception e){
|
||||
return Response.fail(-1);
|
||||
}
|
||||
System.out.println("关闭录制返回 :"+ JSON.toJSONString(response));
|
||||
return response;
|
||||
}
|
||||
|
||||
@GetMapping("info")
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ public interface ITaskService {
|
|||
|
||||
public String startPic(String streamUrl);
|
||||
|
||||
public StreamTask stopTask(String streamUrl);
|
||||
public StreamTask stopTask(String streamUrl) throws Exception;
|
||||
|
||||
public StreamTask getLastTask(String streamUrl);
|
||||
|
||||
|
|
|
|||
|
|
@ -44,16 +44,18 @@ public class TaskService implements ITaskService{
|
|||
StreamTask streamTask = entry.getValue();
|
||||
if(streamTask.getStartTime().getTime() < new Date().getTime() - 30 * 60 * 1000 ) {
|
||||
logger.info("清理废弃任务 {}", JSON.toJSONString(streamTask));
|
||||
StreamTask s = stopTask(entry.getKey());
|
||||
scheduler.schedule(() -> {
|
||||
File file = new File(targetPath +"/"+ s.getOutFileName());
|
||||
try {
|
||||
file.delete();
|
||||
logger.info("废弃文件删除成功");
|
||||
}catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}, 60, TimeUnit.SECONDS);
|
||||
try {
|
||||
StreamTask s = stopTask(entry.getKey());
|
||||
scheduler.schedule(() -> {
|
||||
File file = new File(targetPath +"/"+ s.getOutFileName());
|
||||
try {
|
||||
logger.info("废弃文件删除成功 {}",file.delete());
|
||||
}catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
}
|
||||
}, 60, TimeUnit.SECONDS);
|
||||
}catch (Exception ignore) {}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -93,7 +95,9 @@ public class TaskService implements ITaskService{
|
|||
Date twoHoursAgo = calendar.getTime();
|
||||
if (value.getStartTime().before(twoHoursAgo)) {
|
||||
logger.error("taskId {} 执行超时,手动关闭", key);
|
||||
stopTask(key);
|
||||
try {
|
||||
stopTask(key);
|
||||
}catch (Exception ignore) {}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -170,7 +174,9 @@ public class TaskService implements ITaskService{
|
|||
|
||||
}
|
||||
|
||||
public StreamTask stopTask(String streamUrl) {
|
||||
public StreamTask stopTask(String streamUrl) throws Exception {
|
||||
|
||||
boolean recordSuccess = true;
|
||||
StreamTask currentStreamTask = runningTasks.remove(streamUrl);
|
||||
|
||||
if (currentStreamTask!= null) {
|
||||
|
|
@ -178,11 +184,18 @@ public class TaskService implements ITaskService{
|
|||
|
||||
if (!CollectionUtils.isEmpty(currentStreamTask.getStreamProcesses())) {
|
||||
for (StreamProcess streamProcess : currentStreamTask.getStreamProcesses()) {
|
||||
if(!new File(streamProcess.getFileName()).exists()){
|
||||
recordSuccess = false;
|
||||
}
|
||||
logger.info("streamUrl {} taskId {} destroy Process {}", streamUrl,currentStreamTask.getTaskId() ,streamProcess.getInnerProcessId());
|
||||
streamProcess.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
if(!recordSuccess){
|
||||
throw new Exception("");
|
||||
}
|
||||
|
||||
try {
|
||||
String outFileName = UUID.randomUUID().toString() + ".mp4";
|
||||
StreamProcess mergeProcess = processService.mergeStream(outFileName, currentStreamTask.getStreamProcesses());
|
||||
|
|
@ -225,19 +238,10 @@ public class TaskService implements ITaskService{
|
|||
}
|
||||
|
||||
|
||||
// if( historyTasks.containsKey(streamUrl)){
|
||||
// historyTasks.get(streamUrl).add(currentStreamTask);
|
||||
// }else {
|
||||
// historyTasks.put(streamUrl, new LinkedList<>());
|
||||
// historyTasks.get(streamUrl).offerLast(currentStreamTask);
|
||||
// }
|
||||
|
||||
if(Objects.nonNull(currentStreamTask.getMergeProcess())){
|
||||
if(Objects.nonNull(currentStreamTask.getMergeProcess().getFileName()) &&
|
||||
!currentStreamTask.getMergeProcess().getFileName().isEmpty()){
|
||||
try {
|
||||
//
|
||||
// scheduler.schedule(task, 3, TimeUnit.SECONDS);
|
||||
executor.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -287,11 +291,12 @@ public class TaskService implements ITaskService{
|
|||
}
|
||||
|
||||
}else {
|
||||
if(historyTasks.containsKey(streamUrl)){
|
||||
return historyTasks.get(streamUrl).peekLast();
|
||||
}else {
|
||||
return null;
|
||||
}
|
||||
throw new Exception("");
|
||||
// if(historyTasks.containsKey(streamUrl)){
|
||||
// return historyTasks.get(streamUrl).peekLast();
|
||||
// }else {
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -350,7 +355,9 @@ public class TaskService implements ITaskService{
|
|||
|
||||
public void stopAllTask(){
|
||||
runningTasks.forEach((key, value) -> {
|
||||
stopTask(key);
|
||||
try {
|
||||
stopTask(key);
|
||||
}catch (Exception ignore){}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
spring.application.name=demo
|
||||
#server.port = 8989
|
||||
#srs.splitPath=/data/java/srs/stream_server/temp
|
||||
#srs.targetPath=/data/java/srs/srs/trunk/objs/nginx/html
|
||||
#ffmpeg=/data/ffmpeg/bin/ffmpeg
|
||||
#recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
|
||||
#livedates=8
|
||||
server.port = 8989
|
||||
srs.splitPath=/data/java/srs/stream_server/temp
|
||||
srs.targetPath=/data/java/srs/srs/trunk/objs/nginx/html
|
||||
ffmpeg=/data/ffmpeg/bin/ffmpeg
|
||||
recordPath=/data/java/srs/srs/trunk/objs/nginx/html/record
|
||||
livedates=8
|
||||
|
||||
server.port = 8080
|
||||
srs.splitPath=/Users/sunpeng/workspace/stream/temp
|
||||
srs.targetPath=/Users/sunpeng/workspace/stream/html
|
||||
ffmpeg=ffmpeg
|
||||
recordPath=/Users/sunpeng/workspace/stream/record
|
||||
livedates=7
|
||||
#server.port = 8080
|
||||
#srs.splitPath=/Users/sunpeng/workspace/stream/temp
|
||||
#srs.targetPath=/Users/sunpeng/workspace/stream/html
|
||||
#ffmpeg=ffmpeg
|
||||
#recordPath=/Users/sunpeng/workspace/stream/record
|
||||
#livedates=7
|
||||
Loading…
Reference in New Issue