Search in sources :

Example 1 with ProducerException

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

Example 2 with ProducerException

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

Example 3 with ProducerException

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

Example 4 with ProducerException

use of com.amazonaws.kinesisvideo.producer.ProducerException 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 5 with ProducerException

use of com.amazonaws.kinesisvideo.producer.ProducerException 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)

Aggregations

KinesisVideoCredentialsProvider (com.amazonaws.kinesisvideo.auth.KinesisVideoCredentialsProvider)6 KinesisVideoException (com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)6 ProducerException (com.amazonaws.kinesisvideo.producer.ProducerException)6 KinesisVideoCredentials (com.amazonaws.kinesisvideo.auth.KinesisVideoCredentials)1 StreamDescription (com.amazonaws.kinesisvideo.producer.StreamDescription)1 Tag (com.amazonaws.kinesisvideo.producer.Tag)1