com.amazonaws.services.kinesisvideo.AmazonKinesisVideo Java Examples

The following examples show how to use com.amazonaws.services.kinesisvideo.AmazonKinesisVideo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DemoAppCachedInfo.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 6 votes vote down vote up
private static void addCachedStreamInfoWithCredentialsProvider(CachedInfoMultiAuthServiceCallbacksImpl serviceCallbacks,
                                                               String streamName,
                                                               AWSCredentialsProvider credentialsProvider,
                                                               String region) {
    // Set up credentials provider for the stream name
    serviceCallbacks.addCredentialsProviderToCache(streamName, credentialsProvider);

    // Set up stream info for the stream name
    AmazonKinesisVideo kvsClient = AmazonKinesisVideoClientBuilder.standard()
            .withRegion(region)
            .withCredentials(credentialsProvider)
            .build();
    DescribeStreamResult streamInfo = kvsClient.describeStream(new DescribeStreamRequest().withStreamName(streamName));
    serviceCallbacks.addStreamInfoToCache(streamName, streamInfo);

    // Set up endpoint for the stream name
    GetDataEndpointResult dataEndpoint =
            kvsClient.getDataEndpoint(new GetDataEndpointRequest().withAPIName(APIName.PUT_MEDIA).withStreamName(streamName));
    serviceCallbacks.addStreamingEndpointToCache(streamName, dataEndpoint.getDataEndpoint());
}
 
Example #2
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteStream(@Nonnull final String streamName,
        @Nonnull final String version,
        final Date creationTime,
        final long timeoutInMillis,
        @Nullable final KinesisVideoCredentialsProvider credentialsProvider) throws KinesisVideoException {
    final AmazonKinesisVideo serviceClient = createAmazonKinesisVideoClient(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());
}
 
Example #3
Source File: ContinuousGetMediaWorker.java    From amazon-kinesis-video-streams-parser-library with Apache License 2.0 5 votes vote down vote up
public static ContinuousGetMediaWorker create(Regions region,
        AWSCredentialsProvider credentialsProvider,
        String streamName,
        StartSelector startSelector,
        AmazonKinesisVideo amazonKinesisVideo,
        GetMediaResponseStreamConsumerFactory consumer) {
    String endPoint = amazonKinesisVideo.getDataEndpoint(new GetDataEndpointRequest().withAPIName(APIName.GET_MEDIA)
            .withStreamName(streamName)).getDataEndpoint();

    return new ContinuousGetMediaWorker(region, credentialsProvider, streamName, startSelector, endPoint, consumer);
}
 
Example #4
Source File: GetMediaWorker.java    From amazon-kinesis-video-streams-parser-library with Apache License 2.0 5 votes vote down vote up
public static GetMediaWorker create(Regions region,
        AWSCredentialsProvider credentialsProvider,
        String streamName,
        StartSelector startSelector,
        AmazonKinesisVideo amazonKinesisVideo,
        MkvElementVisitor visitor) {
    String endPoint = amazonKinesisVideo.getDataEndpoint(new GetDataEndpointRequest().withAPIName(APIName.GET_MEDIA)
            .withStreamName(streamName)).getDataEndpoint();

    return new GetMediaWorker(region, credentialsProvider, streamName, startSelector, endPoint, visitor);
}
 
Example #5
Source File: GetMediaForFragmentListWorker.java    From amazon-kinesis-video-streams-parser-library with Apache License 2.0 5 votes vote down vote up
public static GetMediaForFragmentListWorker create(final String streamName, final String fragmentNumber,
                                                   final AWSCredentialsProvider awsCredentialsProvider,
                                                   final Regions region,
                                                   final AmazonKinesisVideo amazonKinesisVideo,
                                                   final MkvElementVisitor elementVisitor) {
    final GetDataEndpointRequest request = new GetDataEndpointRequest()
            .withAPIName(APIName.GET_MEDIA_FOR_FRAGMENT_LIST).withStreamName(streamName);
    final String endpoint = amazonKinesisVideo.getDataEndpoint(request).getDataEndpoint();
    return new GetMediaForFragmentListWorker(
            streamName, fragmentNumber, awsCredentialsProvider, endpoint, region, elementVisitor);
}
 
Example #6
Source File: PutMediaWorker.java    From amazon-kinesis-video-streams-parser-library with Apache License 2.0 5 votes vote down vote up
public static PutMediaWorker create(Regions region,
        AWSCredentialsProvider credentialsProvider,
        String streamName,
        InputStream inputStream,
        AmazonKinesisVideo amazonKinesisVideo) {
    String endPoint = amazonKinesisVideo.getDataEndpoint(new GetDataEndpointRequest().withAPIName(APIName.PUT_MEDIA)
            .withStreamName(streamName)).getDataEndpoint();

    return new PutMediaWorker(region, credentialsProvider, streamName, inputStream, endPoint);
}
 
Example #7
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public String getDataEndpoint(@Nonnull final String streamName,
        @Nonnull final String apiName,
        final long timeoutInMillis,
        @Nullable final KinesisVideoCredentialsProvider credentialsProvider)
        throws KinesisVideoException {
    final AmazonKinesisVideo serviceClient = createAmazonKinesisVideoClient(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();
}
 
Example #8
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public void tagStream(@Nonnull final String streamArn,
        @Nullable final Map<String, String> tags,
        final long timeoutInMillis,
        @Nullable final KinesisVideoCredentialsProvider credentialsProvider)
        throws KinesisVideoException {
    final AmazonKinesisVideo serviceClient = createAmazonKinesisVideoClient(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());
}
 
Example #9
Source File: App.java    From djl-demo with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args)
        throws IOException, ModelNotFoundException, MalformedModelException {
    AmazonKinesisVideoClientBuilder amazonKinesisVideoBuilder =
            AmazonKinesisVideoClientBuilder.standard();
    amazonKinesisVideoBuilder.setRegion(REGION.getName());
    amazonKinesisVideoBuilder.setCredentials(new SystemPropertiesCredentialsProvider());
    AmazonKinesisVideo amazonKinesisVideo = amazonKinesisVideoBuilder.build();

    File outDir = Paths.get("build/out").toFile();
    if (!outDir.exists()) {
        outDir.mkdir();
    }

    for (File outFile : outDir.listFiles()) {
        outFile.delete();
    }

    FrameVisitor frameVisitor = FrameVisitor.create(new DjlImageVisitor());

    ExecutorService executorService = Executors.newFixedThreadPool(1);

    GetMediaWorker getMediaWorker =
            GetMediaWorker.create(
                    REGION,
                    new SystemPropertiesCredentialsProvider(),
                    STREAM_NAME,
                    new StartSelector().withStartSelectorType(StartSelectorType.NOW),
                    amazonKinesisVideo,
                    frameVisitor);
    executorService.submit(getMediaWorker);
}
 
Example #10
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public StreamDescription describeStream(@Nonnull final String streamName,
        final long timeoutInMillis,
        @Nullable final KinesisVideoCredentialsProvider credentialsProvider)
        throws KinesisVideoException {
    final AmazonKinesisVideo serviceClient = createAmazonKinesisVideoClient(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);
}
 
Example #11
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
@Override
public String createStream(@Nonnull final String streamName,
        @Nonnull final String deviceName,
        @Nonnull final String contentType,
        @Nullable final String kmsKeyId,
        final long retentionPeriodInHours,
        final long timeoutInMillis,
        @Nullable final KinesisVideoCredentialsProvider credentialsProvider)
        throws KinesisVideoException {
    final AmazonKinesisVideo serviceClient = createAmazonKinesisVideoClient(credentialsProvider,
            Region.getRegion(Regions.fromName(configuration.getRegion())),
            configuration.getEndpoint(),
            (int) timeoutInMillis);

    final CreateStreamRequest createStreamRequest = new CreateStreamRequest()
            .withStreamName(streamName)
            .withDeviceName(deviceName)
            .withMediaType(contentType)
            .withKmsKeyId(isNullOrEmpty(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();
}
 
Example #12
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static AmazonKinesisVideo getAmazonKinesisVideoClient(
        @Nonnull final AWSCredentialsProvider credentialsProvider,
        @Nonnull final Region region,
        @Nonnull final String endpoint,
        final int timeoutInMillis) throws KinesisVideoException {
    return createAmazonKinesisVideoClient(credentialsProvider,
            region,
            endpoint,
            timeoutInMillis);
}
 
Example #13
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
private static AmazonKinesisVideo createAwsKinesisVideoClient(final AWSCredentials credentials,
        final Region region,
        final String endpoint,
        final int timeoutInMillis)
        throws KinesisVideoException {

    final ClientConfiguration clientConfiguration = createClientConfiguration(timeoutInMillis);
    final AmazonKinesisVideo amazonKinesisVideoClient = AmazonKinesisVideoClient.builder()
            .withClientConfiguration(clientConfiguration)
            .withCredentials(new AWSCredentialsProvider() {

                @Override
                public void refresh() {
                    // Do nothing
                }

                @Override
                public AWSCredentials getCredentials() {
                    // TODO Auto-generated method stub
                    return credentials;
                }
            })
            // .withRegion(region.getName())
            .withEndpointConfiguration(new EndpointConfiguration(endpoint, region.getName()))
            .build();

    return amazonKinesisVideoClient;
}
 
Example #14
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
private static AmazonKinesisVideo createAmazonKinesisVideoClient(
        final AWSCredentialsProvider awsCredentialsProvider,
        final Region region,
        final String endpoint,
        final int timeoutInMillis)
        throws KinesisVideoException {

    final AWSCredentials credentials = awsCredentialsProvider.getCredentials();
    return createAwsKinesisVideoClient(credentials, region, endpoint, timeoutInMillis);
}
 
Example #15
Source File: JavaKinesisVideoServiceClient.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 5 votes vote down vote up
private static AmazonKinesisVideo createAmazonKinesisVideoClient(
        final KinesisVideoCredentialsProvider credentialsProvider,
        final Region region,
        final String endpoint,
        final int timeoutInMillis)
        throws KinesisVideoException {

    final AWSCredentials credentials = createAwsCredentials(credentialsProvider);
    return createAwsKinesisVideoClient(credentials, region, endpoint, timeoutInMillis);
}
 
Example #16
Source File: PutMediaDemo.java    From amazon-kinesis-video-streams-producer-sdk-java with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args) throws Exception {
    final AmazonKinesisVideo frontendClient = AmazonKinesisVideoAsyncClient.builder()
            .withCredentials(AuthHelper.getSystemPropertiesCredentialsProvider())
            .withRegion(DEFAULT_REGION)
            .build();

    /* this is the endpoint returned by GetDataEndpoint API */
    final String dataEndpoint = frontendClient.getDataEndpoint(
            new GetDataEndpointRequest()
                    .withStreamName(STREAM_NAME)
                    .withAPIName("PUT_MEDIA")).getDataEndpoint();

    /* send the same MKV file over and over */
    while (true) {
        /* actually URI to send PutMedia request */
        final URI uri = URI.create(dataEndpoint + PUT_MEDIA_API);

        /* input stream for sample MKV file */
        final InputStream inputStream = new FileInputStream(MKV_FILE_PATH);

        /* use a latch for main thread to wait for response to complete */
        final CountDownLatch latch = new CountDownLatch(1);

        /* PutMedia client */
        final AmazonKinesisVideoPutMedia dataClient = AmazonKinesisVideoPutMediaClient.builder()
                .withRegion(DEFAULT_REGION)
                .withEndpoint(URI.create(dataEndpoint))
                .withCredentials(AuthHelper.getSystemPropertiesCredentialsProvider())
                .withConnectionTimeoutInMillis(CONNECTION_TIMEOUT_IN_MILLIS)
                .build();

        final PutMediaAckResponseHandler responseHandler = new PutMediaAckResponseHandler()  {
            @Override
            public void onAckEvent(AckEvent event) {
                System.out.println("onAckEvent " + event);
            }

            @Override
            public void onFailure(Throwable t) {
                latch.countDown();
                System.out.println("onFailure: " + t.getMessage());
                // TODO: Add your failure handling logic here
            }

            @Override
            public void onComplete() {
                System.out.println("onComplete");
                latch.countDown();
            }
        };

        /* start streaming video in a background thread */
        dataClient.putMedia(new PutMediaRequest()
                        .withStreamName(STREAM_NAME)
                        .withFragmentTimecodeType(FragmentTimecodeType.RELATIVE)
                        .withPayload(inputStream)
                        .withProducerStartTimestamp(Date.from(Instant.now())),
                responseHandler);

        /* wait for request/response to complete */
        latch.await();

        /* close the client */
        dataClient.close();
    }
}
 
Example #17
Source File: KinesisInventoryUtil.java    From pacbot with Apache License 2.0 4 votes vote down vote up
public static Map<String,List<VideoStreamVH>> fetchVideoStreamInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) {
    
    Map<String,List<VideoStreamVH>> videoStream = new LinkedHashMap<>();
    AmazonKinesisVideo amazonKinesisVideo;
    String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource\" ,\"type\": \"videoStream\" " ;
    for(Region region : RegionUtils.getRegions()) { 
        try{
            if(!skipRegions.contains(region.getName()) && region.isServiceSupported(AmazonKinesisVideo.ENDPOINT_PREFIX)){
                amazonKinesisVideo = AmazonKinesisVideoClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
                List<StreamInfo> videoStreamListTemp = new ArrayList<>();
                com.amazonaws.services.kinesisvideo.model.ListStreamsResult listStreamsResult;
                String nextToken = null;
                do{
                    listStreamsResult = amazonKinesisVideo.listStreams(new ListStreamsRequest().withNextToken(nextToken));
                    videoStreamListTemp.addAll(listStreamsResult.getStreamInfoList());
                    nextToken = listStreamsResult.getNextToken();
                }while(nextToken!=null);
                
                List<VideoStreamVH> videoStreamList = new ArrayList<>();
                for(StreamInfo streamInfo : videoStreamListTemp) {
                    List<Attribute> tags = new ArrayList<>();
                    for(Entry<String, String> entry: amazonKinesisVideo.listTagsForStream(new com.amazonaws.services.kinesisvideo.model.ListTagsForStreamRequest()
                            .withStreamARN(streamInfo.getStreamARN())).getTags().entrySet()) {
                        tags.add(new Attribute(entry.getKey(), entry.getValue()));
                    }
                    videoStreamList.add(new VideoStreamVH(streamInfo,tags));
                }
                
                if( !videoStreamList.isEmpty() ) {
                    log.debug(InventoryConstants.ACCOUNT + accountId +" Type : VideoStream "+region.getName() + " >> "+videoStreamList.size());
                    videoStream.put(accountId+delimiter+accountName+delimiter+region.getName(),videoStreamList);
                }
            }
        } catch(Exception e){
            log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
            ErrorManageUtil.uploadError(accountId, region.getName(),"videoStream",e.getMessage());
           
        }
    }
    return videoStream;
}