Search in sources :

Example 11 with KinesisVideoException

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();
}
Also used : AWSKinesisVideoClient(com.amazonaws.services.kinesisvideo.AWSKinesisVideoClient) CreateStreamResult(com.amazonaws.services.kinesisvideo.model.CreateStreamResult) CreateStreamRequest(com.amazonaws.services.kinesisvideo.model.CreateStreamRequest) AmazonClientException(com.amazonaws.AmazonClientException) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Example 12 with KinesisVideoException

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);
}
Also used : ProducerException(com.amazonaws.kinesisvideo.producer.ProducerException) KinesisVideoCredentialsProvider(com.amazonaws.kinesisvideo.auth.KinesisVideoCredentialsProvider) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Example 13 with KinesisVideoException

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);
}
Also used : StreamDescription(com.amazonaws.kinesisvideo.producer.StreamDescription) ProducerException(com.amazonaws.kinesisvideo.producer.ProducerException) KinesisVideoCredentialsProvider(com.amazonaws.kinesisvideo.auth.KinesisVideoCredentialsProvider) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Example 14 with KinesisVideoException

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);
}
Also used : ProducerException(com.amazonaws.kinesisvideo.producer.ProducerException) Tag(com.amazonaws.kinesisvideo.producer.Tag) KinesisVideoCredentialsProvider(com.amazonaws.kinesisvideo.auth.KinesisVideoCredentialsProvider) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Example 15 with KinesisVideoException

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));
    }
}
Also used : CameraAccessException(android.hardware.camera2.CameraAccessException) CameraManager(android.hardware.camera2.CameraManager) Handler(android.os.Handler) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Aggregations

KinesisVideoException (com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)16 KinesisVideoCredentialsProvider (com.amazonaws.kinesisvideo.auth.KinesisVideoCredentialsProvider)6 ProducerException (com.amazonaws.kinesisvideo.producer.ProducerException)6 AmazonClientException (com.amazonaws.AmazonClientException)5 AWSKinesisVideoClient (com.amazonaws.services.kinesisvideo.AWSKinesisVideoClient)5 KinesisVideoCredentials (com.amazonaws.kinesisvideo.auth.KinesisVideoCredentials)2 StreamDescription (com.amazonaws.kinesisvideo.producer.StreamDescription)2 CameraAccessException (android.hardware.camera2.CameraAccessException)1 CameraDevice (android.hardware.camera2.CameraDevice)1 CameraManager (android.hardware.camera2.CameraManager)1 Handler (android.os.Handler)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSSessionCredentials (com.amazonaws.auth.AWSSessionCredentials)1 CognitoCredentialsProvider (com.amazonaws.auth.CognitoCredentialsProvider)1 KinesisVideoClient (com.amazonaws.kinesisvideo.client.KinesisVideoClient)1 CameraMediaSourceConfiguration (com.amazonaws.kinesisvideo.client.mediasource.CameraMediaSourceConfiguration)1 OnStreamDataAvailable (com.amazonaws.kinesisvideo.internal.mediasource.OnStreamDataAvailable)1 KinesisVideoFrame (com.amazonaws.kinesisvideo.producer.KinesisVideoFrame)1 Tag (com.amazonaws.kinesisvideo.producer.Tag)1 AWSMobileClient (com.amazonaws.mobile.client.AWSMobileClient)1