mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: fixed wait for video file not empty in COMPOSED video recording
parent
e294ac606b
commit
03503e586c
|
@ -393,7 +393,7 @@ public class ComposedRecordingService extends RecordingService {
|
||||||
return finalRecordingArray[0];
|
return finalRecordingArray[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stopAndRemoveRecordingContainer(Recording recording, String containerId, int secondsOfWait) {
|
private void stopAndRemoveRecordingContainer(Recording recording, String containerId, int secondsOfWait) {
|
||||||
// Gracefully stop ffmpeg process
|
// Gracefully stop ffmpeg process
|
||||||
try {
|
try {
|
||||||
dockerManager.runCommandInContainer(containerId, "echo 'q' > stop");
|
dockerManager.runCommandInContainer(containerId, "echo 'q' > stop");
|
||||||
|
@ -440,21 +440,26 @@ public class ComposedRecordingService extends RecordingService {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void waitForVideoFileNotEmpty(Recording recording) throws OpenViduException {
|
protected void waitForVideoFileNotEmpty(Recording recording) throws OpenViduException {
|
||||||
boolean isPresent = false;
|
|
||||||
int i = 1;
|
final String VIDEO_FILE = this.openviduConfig.getOpenViduRecordingPath() + recording.getId() + "/"
|
||||||
int timeout = 150; // Wait for 150*150 = 22500 = 22.5 seconds
|
+ recording.getName() + ".mp4";
|
||||||
while (!isPresent && timeout <= 150) {
|
|
||||||
|
int SECONDS_MAX_WAIT = 15;
|
||||||
|
int MILLISECONDS_INTERVAL_WAIT = 100;
|
||||||
|
int LIMIT = SECONDS_MAX_WAIT * 1000 / MILLISECONDS_INTERVAL_WAIT;
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
boolean arePresent = fileExistsAndHasBytes(VIDEO_FILE);
|
||||||
|
while (!arePresent && i < LIMIT) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(150);
|
Thread.sleep(MILLISECONDS_INTERVAL_WAIT);
|
||||||
timeout++;
|
arePresent = fileExistsAndHasBytes(VIDEO_FILE);
|
||||||
File f = new File(this.openviduConfig.getOpenViduRecordingPath() + recording.getId() + "/"
|
i++;
|
||||||
+ recording.getName() + ".mp4");
|
|
||||||
isPresent = ((f.isFile()) && (f.length() > 0));
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == timeout) {
|
if (!arePresent) {
|
||||||
log.error("Recorder container failed generating video file (is empty) for session {}",
|
log.error("Recorder container failed generating video file (is empty) for session {}",
|
||||||
recording.getSessionId());
|
recording.getSessionId());
|
||||||
throw new OpenViduException(Code.RECORDING_START_ERROR_CODE,
|
throw new OpenViduException(Code.RECORDING_START_ERROR_CODE,
|
||||||
|
@ -462,7 +467,12 @@ public class ComposedRecordingService extends RecordingService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void failRecordingCompletion(Recording recording, String containerId, OpenViduException e)
|
private boolean fileExistsAndHasBytes(String fileName) {
|
||||||
|
File f = new File(fileName);
|
||||||
|
return (f.exists() && f.isFile() && f.length() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void failRecordingCompletion(Recording recording, String containerId, OpenViduException e)
|
||||||
throws OpenViduException {
|
throws OpenViduException {
|
||||||
recording.setStatus(io.openvidu.java.client.Recording.Status.failed);
|
recording.setStatus(io.openvidu.java.client.Recording.Status.failed);
|
||||||
dockerManager.removeDockerContainer(containerId, true);
|
dockerManager.removeDockerContainer(containerId, true);
|
||||||
|
|
Loading…
Reference in New Issue