Skip to content

Commit

Permalink
Expose streaming flags in java with jni (#160)
Browse files Browse the repository at this point in the history
* expose streaming flags in java with jni

* remove set method from clientinfo

* add enum

* rename vars; create new constructor

* change case for enum name
  • Loading branch information
niyatim23 authored Apr 28, 2022
1 parent b950c7d commit 7504134
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
42 changes: 38 additions & 4 deletions src/main/java/com/amazonaws/kinesisvideo/producer/ClientInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,31 @@ public class ClientInfo {
/**
* Current version for the structure as defined in the native code
*/
public static final int CLIENT_INFO_CURRENT_VERSION = 0;
public static final int CLIENT_INFO_CURRENT_VERSION = 2;
public static final int DEFAULT_LOG_LEVEL = 4;

public static enum AutomaticStreamingFlags {
AUTOMATIC_STREAMING_INTERMITTENT_PRODUCER(0), AUTOMATIC_STREAMING_ALWAYS_CONTINUOUS(256);
private final int streamingFlagValue;

private AutomaticStreamingFlags(int streamingFlagValue) {
this.streamingFlagValue = streamingFlagValue;
}

public int getStreamingFlagValue() {
return streamingFlagValue;
}

}

private final int mVersion;
private final long mCreateClientTimeout;
private final long mCreateStreamTimeout;
private final long mStopStreamTimeout;
private final long mOfflineBufferAvailabilityTimeout;
private final int mLogLevel;
private final boolean mLogMetric;
private final AutomaticStreamingFlags mAutomaticStreamingFlags;

public ClientInfo() {
mVersion = CLIENT_INFO_CURRENT_VERSION;
Expand All @@ -30,18 +45,33 @@ public ClientInfo() {
mOfflineBufferAvailabilityTimeout = 0L;
mLogLevel = DEFAULT_LOG_LEVEL;
mLogMetric = true;
mAutomaticStreamingFlags = AutomaticStreamingFlags.AUTOMATIC_STREAMING_INTERMITTENT_PRODUCER;
}

public ClientInfo(final long createClientTimeout, final long createStreamTimeout, final long stopStreamTimeout,
final long offlineBufferAvailabilityTimeout,
final int logLevel, final boolean logMetric) {
final long offlineBufferAvailabilityTimeout, final int logLevel,
final boolean logMetric) {
mVersion = CLIENT_INFO_CURRENT_VERSION;
mCreateClientTimeout = createClientTimeout;
mCreateStreamTimeout = createStreamTimeout;
mStopStreamTimeout = stopStreamTimeout;
mOfflineBufferAvailabilityTimeout = offlineBufferAvailabilityTimeout;
mLogLevel = DEFAULT_LOG_LEVEL;
mLogLevel = logLevel;
mLogMetric = logMetric;
mAutomaticStreamingFlags = AutomaticStreamingFlags.AUTOMATIC_STREAMING_INTERMITTENT_PRODUCER;
}

public ClientInfo(final long createClientTimeout, final long createStreamTimeout, final long stopStreamTimeout,
final long offlineBufferAvailabilityTimeout, final int logLevel,
final boolean logMetric, final AutomaticStreamingFlags flag) {
mVersion = CLIENT_INFO_CURRENT_VERSION;
mCreateClientTimeout = createClientTimeout;
mCreateStreamTimeout = createStreamTimeout;
mStopStreamTimeout = stopStreamTimeout;
mOfflineBufferAvailabilityTimeout = offlineBufferAvailabilityTimeout;
mLogLevel = logLevel;
mLogMetric = logMetric;
mAutomaticStreamingFlags = flag;
}

public int getVersion() {
Expand Down Expand Up @@ -71,4 +101,8 @@ public int getLoggerLogLevel() {
public boolean getLogMetric() {
return mLogMetric;
}

public int getAutomaticStreamingFlags() {
return mAutomaticStreamingFlags.getStreamingFlagValue();
}
}
Binary file modified src/main/resources/lib/mac/libKinesisVideoProducerJNI.dylib
Binary file not shown.
Binary file modified src/main/resources/lib/ubuntu/libKinesisVideoProducerJNI.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ public void offlineModeTokenRotationBlockOnSpace() {
* produced after the pause. The pause will cause the state machine to change state to a new session.
* The new session will not roll back as the previous one was closed with a persisted ACK received.
*/
@Ignore
@Test
public void realtimeIntermittentNoLatencyPressureEofr() {
KinesisVideoProducerStream kinesisVideoProducerStream;
Expand Down Expand Up @@ -495,9 +494,8 @@ public void realtimeIntermittentNoLatencyPressureEofr() {
}

/**
* This test is disabled as Java SDK does not support Auto-intermittent Producer yet
* This test is tests Intermittent Producer under latency pressure
*/
@Ignore
@Test
public void realtimeAutoIntermittentLatencyPressure() {
KinesisVideoProducerStream kinesisVideoProducerStream;
Expand All @@ -518,7 +516,6 @@ public void realtimeAutoIntermittentLatencyPressure() {
deviceInfo_ = new DeviceInfo(DEVICE_VERSION,
DEVICE_NAME, storageInfo_, NUMBER_OF_STREAMS, null);


createProducer();

keyFrameInterval_ = 60;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.kinesisvideo.auth.DefaultAuthCallbacks;
import com.amazonaws.kinesisvideo.client.KinesisVideoClientConfiguration;
import com.amazonaws.kinesisvideo.internal.producer.jni.NativeKinesisVideoProducerJni;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.amazonaws.kinesisvideo.demoapp.auth.AuthHelper;
Expand Down Expand Up @@ -59,9 +60,7 @@ public class ProducerTestBase {
protected StorageInfo storageInfo_ = new StorageInfo(0,
StorageInfo.DeviceStorageType.DEVICE_STORAGE_TYPE_IN_MEM, STORAGE_SIZE_MEGS,
SPILL_RATIO_PERCENT, STORAGE_PATH);

protected DeviceInfo deviceInfo_ = new DeviceInfo(DEVICE_VERSION,
DEVICE_NAME, storageInfo_, NUMBER_OF_STREAMS, null);
protected DeviceInfo deviceInfo_;
private final Logger log = LogManager.getLogger(ProducerTestBase.class);

// flags that are updated in case of various events like overflow, error, pressure, etc.
Expand Down Expand Up @@ -108,6 +107,17 @@ protected long getFragmentDurationMs() {
* This method is used to create a KinesisVideoProducer which is used by the later methods
*/
protected void createProducer() {
deviceInfo_ = new DeviceInfo(DEVICE_VERSION,
DEVICE_NAME, storageInfo_, NUMBER_OF_STREAMS, null,
"JNI " + NativeKinesisVideoProducerJni.EXPECTED_LIBRARY_VERSION,
new ClientInfo());
createProducer(deviceInfo_);
}

/**
* This method is used to create a KinesisVideoProducer which is used by the later methods
*/
protected void createProducer(DeviceInfo deviceInfo) {

reset(); // reset all flags to initial values so that they can be modified by the stream and storage callbacks

Expand Down Expand Up @@ -137,9 +147,8 @@ protected void createProducer() {
storageCallbacks,
defaultServiceCallbacks,
streamCallbacks);

try {
kinesisVideoProducer = kinesisVideoClient.initializeNewKinesisVideoProducer(deviceInfo_);
kinesisVideoProducer = kinesisVideoClient.initializeNewKinesisVideoProducer(deviceInfo);
} catch(Exception e) {
e.printStackTrace();
fail();
Expand Down

0 comments on commit 7504134

Please sign in to comment.