Search in sources :

Example 6 with KinesisVideoException

use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.

the class KinesisVideoCredentialsProviderImpl method updateCredentials.

@Override
protected KinesisVideoCredentials updateCredentials() throws KinesisVideoException {
    // Refresh the token first
    log.debug("Refreshing credentials");
    credentialsProvider.refresh();
    // Get the AWS credentials and create Kinesis Video Credentials
    final AWSCredentials awsCredentials = credentialsProvider.getCredentials();
    String sessionToken = null;
    if (awsCredentials instanceof AWSSessionCredentials) {
        final AWSSessionCredentials sessionCredentials = (AWSSessionCredentials) awsCredentials;
        sessionToken = sessionCredentials.getSessionToken();
    }
    Date expiration = KinesisVideoCredentials.CREDENTIALS_NEVER_EXPIRE;
    if (credentialsProvider instanceof CognitoCredentialsProvider) {
        final CognitoCredentialsProvider cognitoCredentialsProvider = (CognitoCredentialsProvider) credentialsProvider;
        expiration = cognitoCredentialsProvider.getSessionCredentialsExpiration();
        log.debug("Refreshed token expiration is %s", expiration);
    } else if (credentialsProvider instanceof AWSMobileClient) {
        AWSMobileClient awsMobileClient = (AWSMobileClient) credentialsProvider;
        try {
            expiration = awsMobileClient.getTokens().getAccessToken().getExpiration();
            log.debug("Refreshed token expiration is %s", expiration);
        } catch (Exception e) {
            throw new KinesisVideoException("Failed to refresh! " + e.getMessage());
        }
    }
    log.debug("Returning %scredentials with expiration %s", sessionToken == null ? "" : "session ", expiration);
    return new KinesisVideoCredentials(awsCredentials.getAWSAccessKeyId(), awsCredentials.getAWSSecretKey(), sessionToken, expiration);
}
Also used : CognitoCredentialsProvider(com.amazonaws.auth.CognitoCredentialsProvider) KinesisVideoCredentials(com.amazonaws.kinesisvideo.auth.KinesisVideoCredentials) AWSSessionCredentials(com.amazonaws.auth.AWSSessionCredentials) AWSMobileClient(com.amazonaws.mobile.client.AWSMobileClient) AWSCredentials(com.amazonaws.auth.AWSCredentials) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException) Date(java.util.Date) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Example 7 with KinesisVideoException

use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.

the class CameraAdapter method adaptCameraStateCallback.

private CameraDevice.StateCallback adaptCameraStateCallback(final OpenCameraCallback cameraOpenCameraCallback) {
    return new CameraDevice.StateCallback() {

        @Override
        public void onOpened(final CameraDevice cameraDevice) {
            Log.i(TAG, "opened" + threadId());
            mCameraDevice = cameraDevice;
            mCameraOpenCloseLock.release();
            cameraOpenCameraCallback.onOpened();
        }

        @Override
        public void onDisconnected(final CameraDevice cameraDevice) {
            Log.i(TAG, "disconnected" + threadId());
            mCameraOpenCloseLock.release();
            cameraDevice.close();
            mCameraDevice = null;
        }

        @Override
        public void onError(final CameraDevice cameraDevice, final int error) {
            Log.i(TAG, "error" + threadId());
            mCameraOpenCloseLock.release();
            cameraDevice.close();
            mCameraDevice = null;
            cameraOpenCameraCallback.onError(new KinesisVideoException("blah"));
        }
    };
}
Also used : CameraDevice(android.hardware.camera2.CameraDevice) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Example 8 with KinesisVideoException

use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.

the class KinesisVideoAndroidServiceClient method deleteStream.

@Override
public void deleteStream(@NonNull final String streamName, @NonNull final String version, final Date creationTime, long timeoutInMillis, @Nullable final KinesisVideoCredentialsProvider credentialsProvider) throws KinesisVideoException {
    final AWSKinesisVideoClient serviceClient = createAwsKinesisVideoClient(credentialsProvider, Region.getRegion(Regions.fromName(configuration.getRegion())), configuration.getEndpoint(), (int) timeoutInMillis);
    final StreamDescription streamDescription = describeStream(streamName, timeoutInMillis, credentialsProvider);
    final DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest().withStreamARN(streamDescription.getStreamArn()).withCurrentVersion(streamDescription.getUpdateVersion());
    log.debug("calling delete stream: " + deleteStreamRequest.toString());
    final DeleteStreamResult deleteStreamResult;
    try {
        deleteStreamResult = serviceClient.deleteStream(deleteStreamRequest);
    } catch (final AmazonClientException e) {
        log.exception(e, "Service call failed.");
        throw new KinesisVideoException(e);
    }
    log.debug("delete stream result: " + deleteStreamResult.toString());
}
Also used : DeleteStreamRequest(com.amazonaws.services.kinesisvideo.model.DeleteStreamRequest) DeleteStreamResult(com.amazonaws.services.kinesisvideo.model.DeleteStreamResult) AWSKinesisVideoClient(com.amazonaws.services.kinesisvideo.AWSKinesisVideoClient) StreamDescription(com.amazonaws.kinesisvideo.producer.StreamDescription) AmazonClientException(com.amazonaws.AmazonClientException) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Example 9 with KinesisVideoException

use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.

the class KinesisVideoAndroidServiceClient method getDataEndpoint.

@Override
public String getDataEndpoint(@NonNull final String streamName, @NonNull final String apiName, long timeoutInMillis, @Nullable final KinesisVideoCredentialsProvider credentialsProvider) throws KinesisVideoException {
    final AWSKinesisVideoClient serviceClient = createAwsKinesisVideoClient(credentialsProvider, Region.getRegion(Regions.fromName(configuration.getRegion())), configuration.getEndpoint(), (int) timeoutInMillis);
    final GetDataEndpointRequest getDataEndpointRequest = new GetDataEndpointRequest().withStreamName(streamName).withAPIName(apiName);
    log.debug("calling get data endpoint: " + getDataEndpointRequest.toString());
    final GetDataEndpointResult getDataEndpointResult;
    try {
        getDataEndpointResult = serviceClient.getDataEndpoint(getDataEndpointRequest);
    } catch (final AmazonClientException e) {
        log.exception(e, "Service call failed.");
        throw new KinesisVideoException(e);
    }
    log.debug("get data endpoint result: " + getDataEndpointResult.toString());
    return getDataEndpointResult.getDataEndpoint();
}
Also used : AWSKinesisVideoClient(com.amazonaws.services.kinesisvideo.AWSKinesisVideoClient) AmazonClientException(com.amazonaws.AmazonClientException) GetDataEndpointRequest(com.amazonaws.services.kinesisvideo.model.GetDataEndpointRequest) GetDataEndpointResult(com.amazonaws.services.kinesisvideo.model.GetDataEndpointResult) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)

Example 10 with KinesisVideoException

use of com.amazonaws.kinesisvideo.common.exception.KinesisVideoException in project aws-sdk-android by aws-amplify.

the class KinesisVideoAndroidServiceClient method describeStream.

@Override
public StreamDescription describeStream(@NonNull final String streamName, long timeoutInMillis, @Nullable final KinesisVideoCredentialsProvider credentialsProvider) throws KinesisVideoException {
    final AWSKinesisVideoClient serviceClient = createAwsKinesisVideoClient(credentialsProvider, Region.getRegion(Regions.fromName(configuration.getRegion())), configuration.getEndpoint(), (int) timeoutInMillis);
    final DescribeStreamRequest describeStreamRequest = new DescribeStreamRequest().withStreamName(streamName);
    log.debug("calling describe stream: " + describeStreamRequest.toString());
    final DescribeStreamResult describeStreamResult;
    try {
        describeStreamResult = serviceClient.describeStream(describeStreamRequest);
    } catch (final AmazonClientException e) {
        log.exception(e, "Service call failed.");
        throw new KinesisVideoException(e);
    }
    if (null == describeStreamResult) {
        log.debug("describe stream returned null");
        return null;
    }
    log.debug("describe stream result: " + describeStreamResult.toString());
    return toStreamDescription(describeStreamResult);
}
Also used : AWSKinesisVideoClient(com.amazonaws.services.kinesisvideo.AWSKinesisVideoClient) AmazonClientException(com.amazonaws.AmazonClientException) DescribeStreamRequest(com.amazonaws.services.kinesisvideo.model.DescribeStreamRequest) DescribeStreamResult(com.amazonaws.services.kinesisvideo.model.DescribeStreamResult) 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