use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.
the class DefaultServiceCallbacksImpl method createStream.
@Override
public void createStream(@NonNull final String deviceName, @NonNull final String streamName, @NonNull final String contentType, @Nullable final String kmsKeyId, final long retentionPeriod, final long callAfter, final long timeout, @Nullable final byte[] authData, final int authType, final long customData) 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() {
int statusCode;
String streamArn = null;
final KinesisVideoCredentialsProvider credentialsProvider = getCredentialsProvider(authData, log);
final long retentionInHours = retentionPeriod / Time.HUNDREDS_OF_NANOS_IN_AN_HOUR;
final long timeoutInMillis = timeout / Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
try {
streamArn = kinesisVideoServiceClient.createStream(streamName, deviceName, contentType, kmsKeyId, retentionInHours, timeoutInMillis, credentialsProvider);
statusCode = HTTP_OK;
} catch (final KinesisVideoException e) {
statusCode = getStatusCodeFromException(e);
log.error("Kinesis Video service client returned an error " + e.getMessage() + ". Reporting to Kinesis Video PIC.");
}
try {
kinesisVideoProducer.createStreamResult(customData, streamArn, statusCode);
} catch (final ProducerException e) {
// TODO: Deal with the runtime exception properly in this and following cases
throw new RuntimeException(e);
}
}
};
executor.schedule(task, delay, TimeUnit.NANOSECONDS);
}
use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.
the class DefaultServiceCallbacksImpl method getStreamingToken.
@Override
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);
}
use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.
the class DefaultServiceCallbacksImpl method getStreamingEndpoint.
@Override
public void getStreamingEndpoint(@NonNull final String streamName, @NonNull final String apiName, 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() {
final KinesisVideoCredentialsProvider credentialsProvider = getCredentialsProvider(authData, log);
final long timeoutInMillis = timeout / Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
int statusCode = HTTP_OK;
String endpoint = "";
try {
endpoint = kinesisVideoServiceClient.getDataEndpoint(streamName, apiName, timeoutInMillis, credentialsProvider);
} catch (final KinesisVideoException e) {
log.error("Kinesis Video service client returned an error " + e.getMessage() + ". Reporting to Kinesis Video PIC.");
statusCode = getStatusCodeFromException(e);
}
if (statusCode != HTTP_OK && isBlank(endpoint)) {
// TODO: more URI validation
statusCode = HTTP_NOT_FOUND;
}
try {
kinesisVideoProducer.getStreamingEndpointResult(stream, streamHandle, endpoint, statusCode);
} catch (final ProducerException e) {
throw new RuntimeException(e);
}
}
};
executor.schedule(task, delay, TimeUnit.NANOSECONDS);
}
use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.
the class BytesMediaSource method createDataAvailableCallback.
private OnStreamDataAvailable createDataAvailableCallback() {
return new OnStreamDataAvailable() {
@Override
public void onFrameDataAvailable(final ByteBuffer data) {
final long currentTimeMs = System.currentTimeMillis();
final long decodingTs = currentTimeMs * HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
final long presentationTs = currentTimeMs * HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
final long msSinceLastFrame = currentTimeMs - lastTimestampMillis;
final long frameDuration = lastTimestampMillis == 0 ? DEFAULT_FRAME_DURATION_33MS * HUNDREDS_OF_NANOS_IN_A_MILLISECOND : msSinceLastFrame * HUNDREDS_OF_NANOS_IN_A_MILLISECOND / 2;
final int flags = isKeyFrame() ? FRAME_FLAG_KEY_FRAME : FRAME_FLAG_NONE;
final KinesisVideoFrame frame = new KinesisVideoFrame(frameIndex++, flags, decodingTs, presentationTs, frameDuration, data);
// ignore frame of size 0 or duration of 0
if (frame.getSize() == 0 || frameDuration == 0) {
return;
}
lastTimestampMillis = currentTimeMs;
submitFrameOnUIThread(frame);
}
@Override
public void onFragmentMetadataAvailable(final String metadataName, final String metadataValue, final boolean persistent) {
try {
mediaSourceSink.onFragmentMetadata(metadataName, metadataValue, persistent);
} catch (final KinesisVideoException e) {
// TODO: log/throw
}
}
};
}
use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.
the class KinesisVideoAndroidServiceClient method tagStream.
@Override
public void tagStream(@NonNull final String streamArn, @Nullable final Map<String, String> tags, long timeoutInMillis, @Nullable final KinesisVideoCredentialsProvider credentialsProvider) throws KinesisVideoException {
final AWSKinesisVideoClient serviceClient = createAwsKinesisVideoClient(credentialsProvider, Region.getRegion(Regions.fromName(configuration.getRegion())), configuration.getEndpoint(), (int) timeoutInMillis);
final TagStreamRequest tagStreamRequest = new TagStreamRequest().withStreamARN(streamArn).withTags(tags);
log.debug("calling tag resource: " + tagStreamRequest.toString());
final TagStreamResult tagStreamResult;
try {
tagStreamResult = serviceClient.tagStream(tagStreamRequest);
} catch (final AmazonClientException e) {
log.exception(e, "Service call failed.");
throw new KinesisVideoException(e);
}
log.debug("tag resource result: " + tagStreamResult.toString());
}
Aggregations