Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ cm-file
target
logs
hs_err_pid*.log

out/
src/main/resources/META-INF/*
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ This script will create a stream with the given name if the stream doesn't exist
Demo app will start running and putting sample video frames in a loop into Kinesis Video Streams.
You can change your stream settings in [`DemoAppMain.java`](./src/main/demo/com/amazonaws/kinesisvideo/demoapp/DemoAppMain.java) before you run the app.

> [!NOTE]
> Make sure the stream name that you specify exists in the region the app runs in. This demo app is set to run in us-west-2 by default.

To run [`DemoAppMain.java`](./src/main/demo/com/amazonaws/kinesisvideo/demoapp/DemoAppMain.java) in `./src/main/demo` with JVM arguments:

1. Credentials: `aws.accessKeyId`, `aws.secretKey`, `aws.sessionToken` (optional)
Expand Down Expand Up @@ -111,7 +114,7 @@ java -classpath target/*jar-with-dependencies.jar \
> * `KinesisVideoProducerJNI.dll` for Windows

> [!TIP]
> Pre-built JNI libraries for some systems can be found in `src/resources/lib`.
> Pre-built JNI libraries for some systems can be found in `src/main/resources/lib`.

> [!NOTE]
> If your system isn't part of the pre-built JNI libraries, you will need to build the JNI yourself. You can find instructions [here](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-java/wiki/Building-and-Using-JNI).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void main(final String[] args) {
// Create CachedInfoServiceCallback
final CachedInfoMultiAuthServiceCallbacksImpl serviceCallbacks =
new CachedInfoMultiAuthServiceCallbacksImpl(log, executor,
configuration, new JavaKinesisVideoServiceClient(log));
configuration, new JavaKinesisVideoServiceClient());
// create Kinesis Video high level client
final KinesisVideoClient kinesisVideoClient = KinesisVideoJavaClientFactory
.createKinesisVideoClient(log, configuration, executor, null, serviceCallbacks);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.amazonaws.kinesisvideo.auth;

import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.amazonaws.kinesisvideo.common.preconditions.Preconditions;
import com.amazonaws.kinesisvideo.producer.AuthCallbacks;
Expand Down Expand Up @@ -53,12 +54,22 @@ public class DefaultAuthCallbacks implements AuthCallbacks {
*/
private long expiration;

/**
* Timeout for the credentials
*/
private int updateTimeoutMillis;

public DefaultAuthCallbacks(@Nonnull KinesisVideoCredentialsProvider credentialsProvider,
@Nonnull final ScheduledExecutorService executor,
@Nonnull Logger log) {
@Nonnull final ScheduledExecutorService executor) {
this(credentialsProvider, executor, CREDENTIALS_UPDATE_TIMEOUT_MILLIS);
}

public DefaultAuthCallbacks(@Nonnull KinesisVideoCredentialsProvider credentialsProvider,
@Nonnull final ScheduledExecutorService executor, final int updateTimeoutMillis) {
this.credentialsProvider = Preconditions.checkNotNull(credentialsProvider);
this.executor = Preconditions.checkNotNull(executor);
this.log = Preconditions.checkNotNull(log);
this.log = LogManager.getLogger(DefaultAuthCallbacks.class);
this.updateTimeoutMillis = updateTimeoutMillis;
}

@Nullable
Expand All @@ -78,19 +89,18 @@ public void run() {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
final KinesisVideoCredentials credentials = credentialsProvider.getUpdatedCredentials();
if (credentials == null) {
log.error("Credentials must not be null");
throw new IllegalArgumentException("Credentials must not be null");
}
expiration = credentials.getExpiration().getTime() * Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;

final ObjectOutput outputStream = new ObjectOutputStream(byteArrayOutputStream);
outputStream.writeObject(credentials);
outputStream.flush();
serializedCredentials = byteArrayOutputStream.toByteArray();
outputStream.close();
} catch (final IOException e) {
// return null
serializedCredentials = null;
expiration = 0;
log.error("Exception was thrown trying to get updated credentials", e);
} catch (final KinesisVideoException e) {
} catch (final IOException | KinesisVideoException | IllegalArgumentException e) {
// return null
serializedCredentials = null;
expiration = 0;
Expand All @@ -111,12 +121,8 @@ public void run() {

// Await for the future to complete
try {
future.get(CREDENTIALS_UPDATE_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
} catch (final InterruptedException e) {
log.error("Awaiting for the credentials update threw an exception", e);
} catch (final ExecutionException e) {
log.error("Awaiting for the credentials update threw an exception", e);
} catch (final TimeoutException e) {
future.get(this.updateTimeoutMillis, TimeUnit.MILLISECONDS);
} catch (final InterruptedException | TimeoutException | ExecutionException e) {
log.error("Awaiting for the credentials update threw an exception", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
/**
* Empty credentials provider
*/
public final class EmptyCredentialsProvider implements KinesisVideoCredentialsProvider{
public final class EmptyCredentialsProvider implements KinesisVideoCredentialsProvider {

@Override
public KinesisVideoCredentials getCredentials() throws KinesisVideoException{
public KinesisVideoCredentials getCredentials() throws KinesisVideoException {
return KinesisVideoCredentials.EMPTY_KINESIS_VIDEO_CREDENTIALS;
}

@Override
public KinesisVideoCredentials getUpdatedCredentials() throws KinesisVideoException{
public KinesisVideoCredentials getUpdatedCredentials() throws KinesisVideoException {
return KinesisVideoCredentials.EMPTY_KINESIS_VIDEO_CREDENTIALS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.util.Date;

@SuppressFBWarnings("EI_EXPOSE_REP")
public class KinesisVideoCredentials implements Serializable{
public class KinesisVideoCredentials implements Serializable {
/**
* Sentinel value indicating the credentials never expire
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public NativeKinesisVideoClient(
@Nonnull final ScheduledExecutorService executor) {
this(log,
new DefaultAuthCallbacks(configuration.getCredentialsProvider(),
executor,
log),
executor),
configuration.getStorageCallbacks(),
new DefaultServiceCallbacksImpl(log, executor, configuration, serviceClient),
new DefaultStreamCallbacks());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.amazonaws.kinesisvideo.client.KinesisVideoClientConfiguration;
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import com.amazonaws.kinesisvideo.common.function.Consumer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.amazonaws.kinesisvideo.common.preconditions.Preconditions;
import com.amazonaws.kinesisvideo.internal.producer.KinesisVideoProducer;
Expand Down Expand Up @@ -44,12 +45,14 @@ public class DefaultServiceCallbacksImpl implements ServiceCallbacks {
private class CompletionCallback implements Consumer<Exception> {
private final KinesisVideoProducerStream stream;
private final long uploadHandle;
private final Logger log;

public CompletionCallback(@Nonnull final KinesisVideoProducerStream stream,
final long uploadHandle) {

this.stream = Preconditions.checkNotNull(stream);
this.uploadHandle = uploadHandle;
this.log = LogManager.getLogger(DefaultServiceCallbacksImpl.class);
}

@Override
Expand Down Expand Up @@ -340,6 +343,10 @@ public void run() {
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
final KinesisVideoCredentials credentials = credentialsProvider.getUpdatedCredentials();
if (credentials == null) {
log.error("Credentials must not be null");
throw new IllegalArgumentException();
}

// Serialize the credentials
expiration = credentials.getExpiration().getTime() * Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
Expand All @@ -350,9 +357,7 @@ public void run() {
outputStream.flush();
serializedCredentials = byteArrayOutputStream.toByteArray();
outputStream.close();
} catch (final IOException e) {
log.error(e);
} catch (final KinesisVideoException e) {
} catch (final IOException | KinesisVideoException | IllegalArgumentException e) {
log.error(e);
} finally {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public JavaKinesisVideoClient(
@Nonnull final StreamCallbacks streamCallbacks) {
super(log,
new DefaultAuthCallbacks(configuration.getCredentialsProvider(),
executor,
log),
executor),
configuration.getStorageCallbacks(),
serviceCallbacks,
streamCallbacks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static KinesisVideoClient createKinesisVideoClient(

final Logger log = LogManager.getLogger(KinesisVideoJavaClientFactory.class);

final JavaKinesisVideoServiceClient serviceClient = new JavaKinesisVideoServiceClient(log);
final JavaKinesisVideoServiceClient serviceClient = new JavaKinesisVideoServiceClient();

final KinesisVideoClient kinesisVideoClient = new JavaKinesisVideoClient(log,
configuration,
Expand Down Expand Up @@ -173,7 +173,7 @@ public static KinesisVideoClient createKinesisVideoClient(

final Logger log = LogManager.getLogger(KinesisVideoJavaClientFactory.class);

final JavaKinesisVideoServiceClient serviceClient = new JavaKinesisVideoServiceClient(log);
final JavaKinesisVideoServiceClient serviceClient = new JavaKinesisVideoServiceClient();

final KinesisVideoClient kinesisVideoClient = new JavaKinesisVideoClient(log,
configuration,
Expand All @@ -200,7 +200,7 @@ public static KinesisVideoClient createKinesisVideoClient(
final KinesisVideoClient kinesisVideoClient = new JavaKinesisVideoClient(log,
configuration,
serviceCallbacks == null ? new DefaultServiceCallbacksImpl(log, executor, configuration,
new JavaKinesisVideoServiceClient(log)) : serviceCallbacks,
new JavaKinesisVideoServiceClient()) : serviceCallbacks,
executor,
streamCallbacks == null ? new DefaultStreamCallbacks() : streamCallbacks);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.amazonaws.kinesisvideo.java.service;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.kinesisvideo.auth.DefaultAuthCallbacks;
import com.amazonaws.kinesisvideo.auth.KinesisVideoCredentials;
import com.amazonaws.kinesisvideo.auth.KinesisVideoCredentialsProvider;
import com.amazonaws.kinesisvideo.client.KinesisVideoClientConfiguration;
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.amazonaws.kinesisvideo.common.preconditions.Preconditions;
import com.amazonaws.kinesisvideo.internal.producer.KinesisVideoProducer;
Expand Down Expand Up @@ -62,6 +64,7 @@ public CachedInfoMultiAuthServiceCallbacksImpl(@Nonnull Logger log, @Nonnull Sch
* StreamArn -> Tags for the stream
*/
private Map<String, Tag[]> tagInfoMap = new HashMap<>();
private final Logger log = LogManager.getLogger(CachedInfoMultiAuthServiceCallbacksImpl.class);


/**
Expand Down Expand Up @@ -163,6 +166,11 @@ public void getStreamingToken(
try {
final KinesisVideoCredentials credentials = kvsCredentialsProvider.getUpdatedCredentials();

if (credentials == null) {
log.error("Credentials must not be null");
throw new IllegalArgumentException();
}

// Serialize the credentials
expiration = credentials.getExpiration().getTime() * Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;

Expand All @@ -172,9 +180,7 @@ public void getStreamingToken(
outputStream.flush();
serializedCredentials = byteArrayOutputStream.toByteArray();
outputStream.close();
} catch (final IOException e) {
log.error(e);
} catch (final KinesisVideoException e) {
} catch (final IOException | KinesisVideoException | IllegalArgumentException e) {
log.error(e);
} finally {
try {
Expand Down
Loading
Loading