in functions/CDDKVSJava/src/main/java/com/amazonaws/greengrass/cddkvs/handlers/StartupHandler.java [86:156]
private void startVideoPipeline() {
Optional<String> optionalRegion = environmentProvider.getRegion();
if (!optionalRegion.isPresent()) {
log.error("Region is not available, can not start the KVS function");
return;
}
String region = optionalRegion.get();
Optional<String> optionalStreamName = environmentProvider.get("STREAM_NAME");
if (!optionalStreamName.isPresent()) {
log.error("Stream name is not available, can not start the KVS function");
return;
}
String streamName = optionalStreamName.get();
Optional<String> optionalGstPluginPath = environmentProvider.get(GST_PLUGIN_PATH_NAME);
if (!optionalGstPluginPath.isPresent()) {
// Find the plugin for them
List<Path> availablePaths = nativeProcessHelper.listAllFiles();
Optional<Path> optionalKvsSinkLocation = availablePaths.stream()
.filter(path -> path.endsWith(LIBGSTKVSSINK_SO_NAME))
.findFirst();
if (!optionalKvsSinkLocation.isPresent()) {
log.error("Plugin path not specified and the KVS sink plugin could not be found, can not start the KVS function");
return;
}
Path kvsSinkLocation = optionalKvsSinkLocation.get();
optionalGstPluginPath = Optional.of(kvsSinkLocation.getParent().toAbsolutePath().toString());
log.error("Plugin path not specified but the KVS sink plugin was found [" + kvsSinkLocation.toAbsolutePath() + "], setting " + GST_PLUGIN_PATH_NAME + " to [" + optionalGstPluginPath.get() + "]");
}
optionalGstPluginPath.ifPresent(gstPluginPath -> GLib.setEnv(GST_PLUGIN_PATH_NAME, gstPluginPath, true));
AwsCredentials credentials = defaultCredentialsProvider.resolveCredentials();
String temporaryAccessKey = credentials.accessKeyId();
String temporarySecretKey = credentials.secretAccessKey();
if (credentials instanceof AwsSessionCredentials) {
GLib.setEnv("AWS_SESSION_TOKEN", ((AwsSessionCredentials) credentials).sessionToken(), true);
}
GLib.setEnv("AWS_ACCESS_KEY_ID", temporaryAccessKey, true);
GLib.setEnv("AWS_SECRET_ACCESS_KEY", temporarySecretKey, true);
GLib.setEnv("AWS_DEFAULT_REGION", region, true);
StringBuilder commandStringBuilder = new StringBuilder();
commandStringBuilder.append("v4l2src do-timestamp=TRUE device=/dev/video0 ! videoconvert ");
commandStringBuilder.append("! video/x-raw,format=I420,width=640,height=480,framerate=15/1 ");
commandStringBuilder.append("! omxh264enc periodicty-idr=45 inline-header=FALSE ! h264parse ");
commandStringBuilder.append("! video/x-h264,stream-format=avc,alignment=au ");
commandStringBuilder.append("! kvssink stream-name=");
commandStringBuilder.append(streamName);
String commandString = commandStringBuilder.toString();
Gst.init("CDDKVSJava");
Bin bin = Gst.parseBinFromDescription(commandString, true);
pipe = new Pipeline();
pipe.addMany(bin);
pipe.play();
}