use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.
the class KinesisVideoAndroidServiceClient method createStream.
@Override
public String createStream(@NonNull final String streamName, @NonNull final String deviceName, @NonNull final String contentType, @Nullable final String kmsKeyId, long retentionPeriodInHours, long timeoutInMillis, @Nullable final KinesisVideoCredentialsProvider credentialsProvider) throws KinesisVideoException {
final AWSKinesisVideoClient serviceClient = createAwsKinesisVideoClient(credentialsProvider, Region.getRegion(Regions.fromName(configuration.getRegion())), configuration.getEndpoint(), (int) timeoutInMillis);
final CreateStreamRequest createStreamRequest = new CreateStreamRequest().withStreamName(streamName).withDeviceName(deviceName).withMediaType(contentType).withKmsKeyId(StringUtils.isBlank(kmsKeyId) ? null : kmsKeyId).withDataRetentionInHours((int) retentionPeriodInHours).withTags(null);
log.debug("calling create stream: " + createStreamRequest.toString());
final CreateStreamResult createStreamResult;
try {
createStreamResult = serviceClient.createStream(createStreamRequest);
} catch (final AmazonClientException e) {
// Wrap into an KinesisVideoException object
log.exception(e, "Service call failed.");
throw new KinesisVideoException(e);
}
log.debug("create stream result: " + createStreamResult.toString());
return createStreamResult.getStreamARN();
}
use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.
the class DefaultServiceCallbacksImpl method putStream.
@Override
public void putStream(@NonNull final String streamName, @NonNull final String containerType, final long streamStartTime, final boolean absoluteFragmentTimes, final boolean ackRequired, @NonNull final String dataEndpoint, final long callAfter, final long timeout, @Nullable final byte[] authData, final int authType, final KinesisVideoProducerStream kinesisVideoProducerStream) 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() {
if (kinesisVideoProducerStream == null) {
throw new IllegalStateException("Couldn't find the correct stream");
}
final long timeoutInMillis = timeout / Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
final long streamStartTimeInMillis = streamStartTime / Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
int statusCode = HTTP_OK;
final KinesisVideoCredentialsProvider credentialsProvider = getCredentialsProvider(authData, log);
final long clientUploadHandle = getUploadHandle();
try {
final InputStream dataStream = kinesisVideoProducerStream.getDataStream(clientUploadHandle);
final AckConsumer ackConsumer = new AckConsumer(clientUploadHandle, kinesisVideoProducerStream, log);
final BlockingAckConsumer blockingAckConsumer = new BlockingAckConsumer(ackConsumer, log, kinesisVideoProducerStream);
final CompletionCallback completionCallback = new CompletionCallback(kinesisVideoProducerStream, clientUploadHandle);
// This will kick-off a long running operation
kinesisVideoServiceClient.putMedia(streamName, containerType, streamStartTimeInMillis, absoluteFragmentTimes, ackRequired, dataEndpoint, timeoutInMillis, credentialsProvider, dataStream, blockingAckConsumer, completionCallback);
// Block until we parse the headers
blockingAckConsumer.awaitResponse();
} catch (final KinesisVideoException e) {
statusCode = getStatusCodeFromException(e);
log.error("Kinesis Video service client returned an error " + e.getMessage() + ". Reporting to Kinesis Video PIC.");
}
try {
log.info("putStreamResult uploadHandle " + clientUploadHandle + " status " + statusCode);
kinesisVideoProducer.putStreamResult(kinesisVideoProducerStream, clientUploadHandle, 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 describeStream.
@Override
public void describeStream(@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() {
int statusCode;
StreamDescription streamDescription = null;
final KinesisVideoCredentialsProvider credentialsProvider = getCredentialsProvider(authData, log);
final long timeoutInMillis = timeout / Time.HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
try {
streamDescription = kinesisVideoServiceClient.describeStream(streamName, 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.describeStreamResult(stream, streamHandle, streamDescription, 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 tagResource.
@Override
public void tagResource(@NonNull final String resourceArn, @Nullable final Tag[] tags, 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;
Map<String, String> tagsMap = null;
if (null != tags) {
// Convert the tags to map
tagsMap = new HashMap<String, String>(tags.length);
for (final Tag tag : tags) {
tagsMap.put(tag.getName(), tag.getValue());
}
}
try {
kinesisVideoServiceClient.tagStream(resourceArn, tagsMap, 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) {
// TODO: more URI validation
statusCode = HTTP_BAD_REQUEST;
}
try {
kinesisVideoProducer.tagResourceResult(stream, streamHandle, 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 CameraAdapter method openCamera.
public void openCamera(final OpenCameraCallback cameraOpenCameraCallback) {
startBackgroundThread();
if (null == mContext || (isActivityFinishing(mContext))) {
Log.i(TAG, "trying to open camera when activity is stopped" + threadId());
return;
}
Log.i(TAG, "trying to open camera" + threadId());
final CameraManager manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
try {
tryAcquireLock();
manager.openCamera(mCameraId, adaptCameraStateCallback(cameraOpenCameraCallback), new Handler(Looper.getMainLooper()));
} catch (final CameraAccessException e) {
Log.e(TAG, "failed to open camera" + threadId(), e);
cameraOpenCameraCallback.onError(new KinesisVideoException(e));
} catch (final NullPointerException e) {
Log.e(TAG, "failed to open camera" + threadId(), e);
cameraOpenCameraCallback.onError(new KinesisVideoException(e));
} catch (final InterruptedException e) {
Log.e(TAG, "failed to open camera" + threadId(), e);
cameraOpenCameraCallback.onError(new KinesisVideoException(e));
} catch (final SecurityException e) {
Log.e(TAG, "Permission issue " + threadId(), e);
cameraOpenCameraCallback.onError(new KinesisVideoException(e));
}
}
Aggregations