in src/main/java/com/aws/iot/edgeconnectorforkvs/EdgeConnectorForKVSService.java [593:643]
private void stopLiveVideoStreaming(EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration)
throws IOException {
ReentrantLock processLock = edgeConnectorForKVSConfiguration.getProcessLock();
try {
if (processLock.tryLock(
INIT_LOCK_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS)) {
log.info("Stop Live Video Streaming Called for " +
edgeConnectorForKVSConfiguration.getKinesisVideoStreamName());
log.info("Calling function " + Constants.getCallingFunctionName(2));
// Stop video recording provided there's no scheduled / mqtt based live streaming in progress
edgeConnectorForKVSConfiguration.setLiveStreamingRequestsCount(
edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount() - 1);
if (edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount() > 0) {
log.info("Live Streaming is being used by multiple tasks. Requests Count " +
edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
return;
}
log.info("Live Steaming Requests Count is 0. Stopping.");
VideoRecorder videoRecorder = edgeConnectorForKVSConfiguration.getVideoRecorder();
VideoUploader videoUploader = edgeConnectorForKVSConfiguration.getVideoUploader();
log.info("Toggle output stream off for KVS Stream: " +
edgeConnectorForKVSConfiguration.getKinesisVideoStreamName());
videoRecorder.toggleAppDataOutputStream(false);
log.info("Close video uploader for KVS Stream: " +
edgeConnectorForKVSConfiguration.getKinesisVideoStreamName());
videoUploader.close();
// Manually flush input stream
flushInputStream(edgeConnectorForKVSConfiguration.getInputStream());
edgeConnectorForKVSConfiguration.getInputStream().close();
edgeConnectorForKVSConfiguration.getOutputStream().close();
// Stop recording if it was kicked-off only for this live streaming
stopRecordingJob(edgeConnectorForKVSConfiguration);
} else {
log.error("Stop uploading for " + edgeConnectorForKVSConfiguration.getKinesisVideoStreamName()
+ " timeout, re-init component to restart the process.");
Constants.setFatalStatus(true);
}
} catch (InterruptedException e) {
log.error("Stop uploading for " + edgeConnectorForKVSConfiguration.getKinesisVideoStreamName()
+ " has been interrupted, re-init component to restart the process.");
Constants.setFatalStatus(true);
} finally {
if (processLock.isHeldByCurrentThread()) processLock.unlock();
}
}