Search in sources :

Example 1 with KinesisVideoException

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

Example 2 with KinesisVideoException

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);
}
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 KinesisVideoException

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

Example 4 with KinesisVideoException

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
            }
        }
    };
}
Also used : ByteBuffer(java.nio.ByteBuffer) KinesisVideoFrame(com.amazonaws.kinesisvideo.producer.KinesisVideoFrame) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException) OnStreamDataAvailable(com.amazonaws.kinesisvideo.internal.mediasource.OnStreamDataAvailable)

Example 5 with KinesisVideoException

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

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