Skip to content

Commit

Permalink
Added support for uploading files(offline mode) to Kinesis Video Stream
Browse files Browse the repository at this point in the history
Additional fixes
  • Loading branch information
chehefen committed Dec 15, 2018
1 parent 9d88b06 commit 56f5785
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 63 deletions.
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ for **non-temporary** AWS credential.
for *temporary* AWS credential.

**Note**: NativeLibraryPath must contain your ["KinesisVideoProducerJNI"](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp#build-the-native-library-kinesisvideoproducerjni-to-run-java-demo-app) library. File name depends on your Operating System:
* `libKinesisVideoProducerJNI.so` for Linux
* `libKinesisVideoProducerJNI.dylib` for Mac OS
* `libKinesisVideoProducerJNI.so` for Linux
* `libKinesisVideoProducerJNI.dylib` for Mac OS
* `KinesisVideoProducerJNI.dll` for Windows

If you are using pre-built libraries, please specify the path of library. Take pre-build library for Mac as example, you can specify `src/resources/lib/mac` as <NativeLibraryPath>.

Demo app will start running and putting sample video frames in a loop into Kinesis Video Streams. You can change your stream settings in `DemoAppMain.java` before you run the app.

##### Run the demo application from command line
##### Run the demo application from command line

If you want to run the `DemoAppMain`, follow the [steps](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-java/issues/14) below. See [Prerequisites](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-java#prerequisites) to find available native library needed to run `DemoAppMain`.

Expand All @@ -76,10 +76,10 @@ Refer the **README.md** file in the *dockerscripts* folder for running the buil

#### Launching PutMediaDemo sample application

Run `PutMediaDemo.java` to send sample mkv stream to Kinesis Video Streams. **Note:** ACCESS_KEY and SECRET_KEY are required for running this sample application as well. However, this demo application does not require JNI.
Run `PutMediaDemo.java` to send sample mkv stream to Kinesis Video Streams. **Note:** ACCESS_KEY and SECRET_KEY are required for running this sample application as well. However, this demo application does not require JNI.

```
-Daws.accessKeyId=<YourAwsAccessKey> -Daws.secretKey=<YourAwsSecretKey>
-Daws.accessKeyId=<YourAwsAccessKey> -Daws.secretKey=<YourAwsSecretKey>
```
for **non-temporary** AWS credential.

Expand All @@ -93,7 +93,7 @@ for **non-temporary** AWS credential.

#### Additional Examples

For additional examples on using Kinesis Video Streams Java SDK and Kinesis Video Streams Parsing Library refer:
For additional examples on using Kinesis Video Streams Java SDK and Kinesis Video Streams Parsing Library refer:

##### [Kinesis Video Streams Producer SDK CPP](https://github.com/awslabs/amazon-kinesis-video-streams-producer-sdk-cpp/blob/master/README.md)
##### [Kinesis Video Streams Parser Library](https://github.com/aws/amazon-kinesis-video-streams-parser-library/blob/master/README.md)
Expand All @@ -112,11 +112,11 @@ or in MacOS
$ otool -L libKinesisVideoProducerJNI.dylib
```

This will provide details on missing libraries during linking; If the output shows missing shared libraries, then run the following commands to clean the `CMakeCache` and link again.
This will provide details on missing libraries during linking; If the output shows missing shared libraries, then run the following commands to clean the `CMakeCache` and link again.

```
rm -rf ./kinesis-video-native-build/CMakeCache.txt ./kinesis-video-native-build/CMakeFiles
```
and run `./install-script` again.

Expand All @@ -133,6 +133,10 @@ This should resolve native library loading issues.

## Release Notes

### Release 1.7.0 (3rd December 2018)
* Added support for uploading files(offline mode) to Kinesis Video Stream
* Additional fixes

### Release 1.6.0 (3rd December 2018)
* Remove streamName parameter from KinesisVideoClient.registerMediaSource() as MediaSource already has the stream name in StreamInfo.
* Add KinesisVideoClient.unregisterMediaSource() to remove MediaSource to KinesisVideoProducerStream binding from KinesisVideoClient. Customers can use unregisterMediaSource() after they stop streaming, so MediaSource data will not to be sent to Kinesis Video Streams.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public interface MediaSourceSink {

void onCodecPrivateData(final @Nullable byte[] codecPrivateData) throws KinesisVideoException;

void onCodecPrivateData(final @Nullable byte[] codecPrivateData, final int trackId) throws KinesisVideoException;

void onFragmentMetadata(final @Nonnull String metadataName, final @Nonnull String metadataValue, final boolean persistent)
throws KinesisVideoException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.amazonaws.kinesisvideo.internal.mediasource;

import static com.amazonaws.kinesisvideo.common.preconditions.Preconditions.checkNotNull;
import static com.amazonaws.kinesisvideo.util.StreamInfoConstants.DEFAULT_TRACK_ID;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -36,8 +37,13 @@ public void onFrame(@Nonnull final KinesisVideoFrame kinesisVideoFrame) throws K
}

@Override
public void onCodecPrivateData(@Nullable final byte[] bytes) throws KinesisVideoException {
producerStream.streamFormatChanged(bytes);
public void onCodecPrivateData(@Nullable final byte[] codecPrivateData) throws KinesisVideoException {
onCodecPrivateData(codecPrivateData, DEFAULT_TRACK_ID);
}

@Override
public void onCodecPrivateData(@Nullable final byte[] bytes, int trackId) throws KinesisVideoException {
producerStream.streamFormatChanged(bytes, trackId);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void getStreamData(final @Nonnull byte[] fillBuffer, int offset, int length, @No
* NOTE: CPD is @Nullable - specifying a null will remove the CPD.
* NOTE: currently, only Codec Private Data is supported while not streaming.
*/
void streamFormatChanged(final @Nullable byte[] codecPrivateData) throws ProducerException;
void streamFormatChanged(final @Nullable byte[] codecPrivateData, final int trackId) throws ProducerException;

/**
* Returns the underlying native stream handle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,13 @@ public void getStreamMetrics(final long streamHandle, @Nonnull final KinesisVide
* @param kinesisVideoFrame an KinesisVideoFrame object
* @throws ProducerException
*/
public void putFrame(final long streamHandle, final @Nonnull KinesisVideoFrame kinesisVideoFrameFrame) throws ProducerException
public void putFrame(final long streamHandle, final @Nonnull KinesisVideoFrame kinesisVideoFrame) throws ProducerException
{
Preconditions.checkState(isInitialized());
Preconditions.checkNotNull(kinesisVideoFrameFrame);
Preconditions.checkNotNull(kinesisVideoFrame);

synchronized (mSyncObject) {
putKinesisVideoFrame(mClientHandle, streamHandle, kinesisVideoFrameFrame);
putKinesisVideoFrame(mClientHandle, streamHandle, kinesisVideoFrame);
}
}

Expand Down Expand Up @@ -566,12 +566,13 @@ public void getStreamData(final long streamHandle,
* @param codecPrivateData Codec Private Data or null to reset
* @throws ProducerException
*/
public void streamFormatChanged(final long streamHandle, final @Nullable byte[] codecPrivateData) throws ProducerException
public void streamFormatChanged(final long streamHandle, final @Nullable byte[] codecPrivateData,
final long trackId) throws ProducerException
{
Preconditions.checkState(isInitialized());

synchronized (mSyncObject) {
kinesisVideoStreamFormatChanged(mClientHandle, streamHandle, codecPrivateData);
kinesisVideoStreamFormatChanged(mClientHandle, streamHandle, codecPrivateData, trackId);
}
}

Expand Down Expand Up @@ -639,6 +640,20 @@ private void storageOverflowPressure(final long remainingSize)
}
}

/**
* Reports buffer temporal overflow pressure
*/
private void bufferDurationOverflowPressure(final long streamHandle, final long remainDuration) throws ProducerException {
synchronized (mCallbackSyncObject) {
if (!mKinesisVideoHandleMap.containsKey(streamHandle)) {
throw new ProducerException("Invalid stream handle.", STATUS_INVALID_OPERATION);
}

final KinesisVideoProducerStream kinesisVideoProducerStream = mKinesisVideoHandleMap.get(streamHandle);
kinesisVideoProducerStream.bufferDurationOverflowPressure(remainDuration);
}
}

/**
* Reports stream latency pressure
*/
Expand Down Expand Up @@ -672,7 +687,7 @@ private void streamConnectionStale(final long streamHandle, final long lastAckDu
/**
* Reports received fragment ACK
*/
private void fragmentAckReceived(final long streamHandle, @Nonnull final KinesisVideoFragmentAck fragmentAck)
private void fragmentAckReceived(final long streamHandle, final long uploadHandle, @Nonnull final KinesisVideoFragmentAck fragmentAck)
throws ProducerException
{
synchronized (mCallbackSyncObject) {
Expand All @@ -681,7 +696,7 @@ private void fragmentAckReceived(final long streamHandle, @Nonnull final Kinesis
}

final KinesisVideoProducerStream kinesisVideoProducerStream = mKinesisVideoHandleMap.get(streamHandle);
kinesisVideoProducerStream.fragmentAckReceived(fragmentAck);
kinesisVideoProducerStream.fragmentAckReceived(uploadHandle, fragmentAck);
}
}

Expand Down Expand Up @@ -718,15 +733,15 @@ private void droppedFragmentReport(final long streamHandle, final long fragmentT
/**
* Reports stream error.
*/
private void streamErrorReport(final long streamHandle, final long fragmentTimecode, final long statusCode) throws ProducerException
private void streamErrorReport(final long streamHandle, final long uploadHandle, final long fragmentTimecode, final long statusCode) throws ProducerException
{
synchronized (mCallbackSyncObject) {
if (!mKinesisVideoHandleMap.containsKey(streamHandle)) {
throw new ProducerException("Invalid stream handle.", STATUS_INVALID_OPERATION);
}

final KinesisVideoProducerStream kinesisVideoProducerStream = mKinesisVideoHandleMap.get(streamHandle);
kinesisVideoProducerStream.streamErrorReport(fragmentTimecode, statusCode);
kinesisVideoProducerStream.streamErrorReport(uploadHandle, fragmentTimecode, statusCode);
}
}

Expand Down Expand Up @@ -1230,7 +1245,8 @@ private native long createKinesisVideoStream(long clientHandle, final @Nonnull S
* @param kinesisVideoFrame Kinesis Video frame to put
* @throws ProducerException
*/
private native void putKinesisVideoFrame(long clientHandle, long streamHandle, final @Nonnull KinesisVideoFrame kinesisVideoFrame)
private native void putKinesisVideoFrame(long clientHandle, long streamHandle,
final @Nonnull KinesisVideoFrame kinesisVideoFrame)
throws ProducerException;

/**
Expand All @@ -1243,7 +1259,9 @@ private native void putKinesisVideoFrame(long clientHandle, long streamHandle, f
* @param persistent whether this is persistent metadata or not
* @throws ProducerException
*/
private native void putKinesisVideoFragmentMetadata(long clientHandle, long streamHandle, final @Nonnull String metadataName, final @Nonnull String metadataValue, boolean persistent)
private native void putKinesisVideoFragmentMetadata(long clientHandle, long streamHandle,
final @Nonnull String metadataName,
final @Nonnull String metadataValue, boolean persistent)
throws ProducerException;

/**
Expand All @@ -1255,7 +1273,8 @@ private native void putKinesisVideoFragmentMetadata(long clientHandle, long stre
* @param kinesisVideoFragmentAck Kinesis Video fragment ack to report for the stream
* @throws ProducerException
*/
private native void kinesisVideoStreamFragmentAck(long clientHandle, long streamHandle, long uploadHandle, final @Nonnull KinesisVideoFragmentAck kinesisVideoFragmentAck)
private native void kinesisVideoStreamFragmentAck(long clientHandle, long streamHandle, long uploadHandle,
final @Nonnull KinesisVideoFragmentAck kinesisVideoFragmentAck)
throws ProducerException;

/**
Expand All @@ -1267,7 +1286,8 @@ private native void kinesisVideoStreamFragmentAck(long clientHandle, long stream
* @param kinesisVideoFragmentAck Kinesis Video fragment ack string to report for the stream
* @throws ProducerException
*/
private native void kinesisVideoStreamParseFragmentAck(long clientHandle, long streamHandle, long uploadHandle, final @Nonnull String kinesisVideoFragmentAck)
private native void kinesisVideoStreamParseFragmentAck(long clientHandle, long streamHandle, long uploadHandle,
final @Nonnull String kinesisVideoFragmentAck)
throws ProducerException;

/**
Expand All @@ -1288,7 +1308,8 @@ private native void getKinesisVideoMetrics(long clientHandle, @Nonnull final Kin
* @param metrics - Kinesis Video stream metrics object to fill in
* @throws ProducerException
*/
private native void getKinesisVideoStreamMetrics(long clientHandle, long streamHandle, @Nonnull final KinesisVideoStreamMetrics metrics)
private native void getKinesisVideoStreamMetrics(long clientHandle, long streamHandle,
final @Nonnull KinesisVideoStreamMetrics metrics)
throws ProducerException;

/**
Expand All @@ -1300,7 +1321,8 @@ private native void getKinesisVideoStreamMetrics(long clientHandle, long streamH
* @param streamDescription stream description object
* @throws ProducerException
*/
private native void describeStreamResultEvent(long clientHandle, long streamHandle, int httpStatusCode, final @Nullable StreamDescription streamDescription)
private native void describeStreamResultEvent(long clientHandle, long streamHandle, int httpStatusCode,
final @Nullable StreamDescription streamDescription)
throws ProducerException;

/**
Expand All @@ -1312,7 +1334,8 @@ private native void describeStreamResultEvent(long clientHandle, long streamHand
* @param streamingEndpoint streaming endpoint
* @throws ProducerException
*/
private native void getStreamingEndpointResultEvent(long clientHandle, long streamHandle, int httpStatusCode, final @Nullable String streamingEndpoint)
private native void getStreamingEndpointResultEvent(long clientHandle, long streamHandle, int httpStatusCode,
final @Nullable String streamingEndpoint)
throws ProducerException;

/**
Expand All @@ -1326,7 +1349,9 @@ private native void getStreamingEndpointResultEvent(long clientHandle, long stre
* @param tokenExpiration token expiration time in 100ns absolute time
* @throws ProducerException
*/
private native void getStreamingTokenResultEvent(long clientHandle, long streamHandle, int httpStatusCode, final @Nullable byte[] streamingToken, int tokenSize, long tokenExpiration)
private native void getStreamingTokenResultEvent(long clientHandle, long streamHandle, int httpStatusCode,
final @Nullable byte[] streamingToken, int tokenSize,
long tokenExpiration)
throws ProducerException;

/**
Expand Down Expand Up @@ -1384,9 +1409,11 @@ private native void getKinesisVideoStreamData(long clientHandle, long streamHand
* @param clientHandle the handle of the client
* @param streamHandle the handle of the stream
* @param codecPrivateData Codec Private Data bits or null to reset
* @param trackId Track Id of the changed CPD belongs to
* @throws ProducerException
*/
private native void kinesisVideoStreamFormatChanged(long clientHandle, long streamHandle, final @Nullable byte[] codecPrivateData)
private native void kinesisVideoStreamFormatChanged(long clientHandle, long streamHandle,
final @Nullable byte[] codecPrivateData, long trackId)
throws ProducerException;

/**
Expand All @@ -1398,8 +1425,8 @@ private native void kinesisVideoStreamFormatChanged(long clientHandle, long stre
* @param deviceArn device ARN if successful.
* @throws ProducerException
*/
private native void createDeviceResultEvent(long clientHandle, long deviceHandle, int httpStatusCode, final @Nullable String deviceArn)
throws ProducerException;
private native void createDeviceResultEvent(long clientHandle, long deviceHandle, int httpStatusCode,
final @Nullable String deviceArn) throws ProducerException;

/**
* Sends device certificate to token exchange result event to SDK
Expand All @@ -1412,7 +1439,8 @@ private native void createDeviceResultEvent(long clientHandle, long deviceHandle
* @param tokenExpiration token expiration time in 100ns absolute time
* @throws ProducerException
*/
private native void deviceCertToTokenResultEvent(long clientHandle, long deviceHandle, int httpStatusCode, final @Nullable byte[] token, int tokenSize, long tokenExpiration)
private native void deviceCertToTokenResultEvent(long clientHandle, long deviceHandle, int httpStatusCode,
final @Nullable byte[] token, int tokenSize, long tokenExpiration)
throws ProducerException;

/**
Expand All @@ -1424,6 +1452,7 @@ private native void deviceCertToTokenResultEvent(long clientHandle, long deviceH
* @param statusCode the status code of the termination event
* @throws ProducerException
*/
private native void kinesisVideoStreamTerminated(long clientHandle, long streamHandle, long uploadHandle, int statusCode)
private native void kinesisVideoStreamTerminated(long clientHandle, long streamHandle, long uploadHandle,
int statusCode)
throws ProducerException;
}
Loading

0 comments on commit 56f5785

Please sign in to comment.