package com.amazonaws.kvsmlinference; import com.amazonaws.auth.AWSCredentialsProvider; import com.amazonaws.client.builder.AwsClientBuilder; import com.amazonaws.kinesisvideo.parser.ebml.MkvTypeInfos; import com.amazonaws.kinesisvideo.parser.mkv.Frame; import com.amazonaws.kinesisvideo.parser.mkv.MkvDataElement; import com.amazonaws.kinesisvideo.parser.mkv.MkvElement; import com.amazonaws.kinesisvideo.parser.mkv.MkvElementVisitException; import com.amazonaws.kinesisvideo.parser.mkv.MkvValue; import com.amazonaws.kinesisvideo.parser.mkv.StreamingMkvReader; import com.amazonaws.kinesisvideo.parser.utilities.FragmentMetadataVisitor; import com.amazonaws.kinesisvideo.parser.utilities.MkvTrackMetadata; import com.amazonaws.regions.Regions; import com.amazonaws.services.kinesisvideo.AmazonKinesisVideo; import com.amazonaws.services.kinesisvideo.AmazonKinesisVideoClientBuilder; import com.amazonaws.services.kinesisvideo.AmazonKinesisVideoMedia; import com.amazonaws.services.kinesisvideo.AmazonKinesisVideoMediaClientBuilder; import com.amazonaws.services.kinesisvideo.model.APIName; import com.amazonaws.services.kinesisvideo.model.GetDataEndpointRequest; import com.amazonaws.services.kinesisvideo.model.GetMediaRequest; import com.amazonaws.services.kinesisvideo.model.GetMediaResult; import com.amazonaws.services.kinesisvideo.model.StartSelector; import com.amazonaws.services.kinesisvideo.model.StartSelectorType; import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.InputStream; import java.nio.ByteBuffer; import java.util.*; import static com.amazonaws.util.StringUtils.isNullOrEmpty; /** * Utility class to interact with KVS streams * *
Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so. *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
public final class KVSUtils {
public enum TrackName {
AUDIO_FROM_CUSTOMER("AUDIO_FROM_CUSTOMER"),
AUDIO_TO_CUSTOMER("AUDIO_TO_CUSTOMER");
private String name;
TrackName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
private static final Logger logger = LoggerFactory.getLogger(KVSUtils.class);
/**
* Fetches the next ByteBuffer of size 1024 bytes from the KVS stream by parsing the frame from the MkvElement
* Each frame has a ByteBuffer having size 1024
*
* @param streamingMkvReader
* @param fragmentVisitor
* @param tagProcessor
* @param contactId
* @return
* @throws MkvElementVisitException
*/
public static ByteBuffer getByteBufferFromStream(StreamingMkvReader streamingMkvReader,
FragmentMetadataVisitor fragmentVisitor,
KVSContactTagProcessor tagProcessor,
String contactId, String track) throws MkvElementVisitException {
while (streamingMkvReader.mightHaveNext()) {
Optional