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