in src/main/java/com/amazonaws/kinesisvideo/internal/service/DefaultServiceCallbacksImpl.java [317:381]
public void getStreamingToken(
@Nonnull final String streamName,
final long callAfter,
final long timeout,
@Nullable final byte[] authData,
final int authType,
final long streamHandle,
final KinesisVideoProducerStream stream) throws ProducerException {
Preconditions.checkState(isInitialized(), "Service callbacks object should be initialized first");
final long delay = calculateRelativeServiceCallAfter(callAfter);
final Runnable task = new Runnable() {
@Override
public void run() {
// Currently, we have no support for getting a streaming token. We will refresh the credentials
// and return a credential from the credentials provider we got initially.
final KinesisVideoCredentialsProvider credentialsProvider = configuration.getCredentialsProvider();
// Stores the serialized credentials as a streaming token
byte[] serializedCredentials = null;
long expiration = 0;
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
final KinesisVideoCredentials credentials = credentialsProvider.getUpdatedCredentials();
// Serialize the credentials
expiration = credentials.getExpiration().getTime() * Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
// Serialize the credentials as streaming token
final ObjectOutput outputStream = new ObjectOutputStream(byteArrayOutputStream);
outputStream.writeObject(credentials);
outputStream.flush();
serializedCredentials = byteArrayOutputStream.toByteArray();
outputStream.close();
} catch (final IOException e) {
log.exception(e);
} catch (final KinesisVideoException e) {
log.exception(e);
} finally {
try {
byteArrayOutputStream.close();
} catch (final IOException ex) {
// Do nothing
}
}
final int statusCode = HTTP_OK;
try {
kinesisVideoProducer.getStreamingTokenResult(
stream,
streamHandle,
serializedCredentials,
expiration,
statusCode);
} catch (final ProducerException e) {
throw new RuntimeException(e);
}
}
};
executor.schedule(task, delay, TimeUnit.NANOSECONDS);
}