I am currently working on implementing a C++ project to retrieve the most up to date fragment from a Live KVS Stream using GetMedia
.
However whenever GetMedia
is called, the program will currently hang at that point until the stream has been stopped, only after this will the GetMedia
call return some data.
My question is:
Is there a way to retrieve the latest fragment in a stream using GetMedia, while the stream is active and live streaming from a Pi 4. Without having to stop the stream?
My Current Code is the following, please let me know if there is anything I am missing or ways I could improve or solve this issue
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
Aws::InitAPI(options);
{
Aws::Auth::AWSCredentials aws_credentials;
aws_credentials.SetAWSAccessKeyId("MY_ACCESS_KEY");
aws_credentials.SetAWSSecretKey("MY_SECRET_KEY");
Aws::Auth::SimpleAWSCredentialsProvider provider = Aws::Auth::SimpleAWSCredentialsProvider(aws_credentials);
Aws::Client::ClientConfiguration clientConfig;
clientConfig.region = Aws::Region::EU_WEST_1;
Aws::KinesisVideo::KinesisVideoClient client = Aws::KinesisVideo::KinesisVideoClient(aws_credentials, clientConfig);
Aws::KinesisVideo::Model::GetDataEndpointRequest request;
request.SetStreamName("MY_STREAM_NAME");
request.SetAPIName(Aws::KinesisVideo::Model::APIName::GET_MEDIA);
Aws::KinesisVideo::Model::GetDataEndpointOutcome result = client.GetDataEndpoint(request);
cout << result.GetError().GetExceptionName() + ": " + result.GetError().GetMessage() << endl;
cout << result.GetResult().GetDataEndpoint() << endl;
cout << "GetDataEndpoint successful: " << result.IsSuccess() << endl;
Aws::KinesisVideoMedia::KinesisVideoMediaClient* videoMediaClient = new Aws::KinesisVideoMedia::KinesisVideoMediaClient(aws_credentials, clientConfig);
Aws::KinesisVideoMedia::Model::GetMediaRequest getMediaRequest;
getMediaRequest.SetStreamName("MY_STREAM_NAME");
Aws::KinesisVideoMedia::Model::StartSelector selector;
selector.WithStartSelectorType(Aws::KinesisVideoMedia::Model::StartSelectorType::NOW);
getMediaRequest.SetStartSelector(selector);
videoMediaClient->OverrideEndpoint(result.GetResultWithOwnership().GetDataEndpoint());
videoMediaClient->EnableRequestProcessing();
videoMediaClient->SetServiceClientName("kinesisvideo");
Aws::KinesisVideoMedia::Model::GetMediaOutcome outcome = client->GetMedia(request);
if (outcome.IsSuccess()) {
cout << "Success" << endl;
char buffer[1024];
outcome.GetResultWithOwnership().GetPayload().read(buffer, 1024);
cout << buffer<< endl;
} else {
cout << "Failure" << endl;
}
}
ShutdownAPI(options);