Skip to content

Commit

Permalink
Remove streamName parameter from KinesisVideoClient.registerMediaSour…
Browse files Browse the repository at this point in the history
…ce() 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.
Add getStreamInfo() to MediaSource instead of MediaSourceConfiguration. If customers have implemented their own MediaSource and MediaSourceConfiguration, they would need to provide stream information via MediaSource.getStreamInfo(). The MediaSourceConfiguration.getStreamInfo() will not work.
Some classes are moved to internal namespace.
  • Loading branch information
chehefen committed Dec 4, 2018
1 parent 326f2ff commit 9d88b06
Show file tree
Hide file tree
Showing 56 changed files with 219 additions and 105 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,38 @@ This should resolve native library loading issues.

## Release Notes

### 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.
* Add getStreamInfo() to MediaSource instead of MediaSourceConfiguration. If customers have implemented their own MediaSource and MediaSourceConfiguration, they would need to provide stream information via MediaSource.getStreamInfo(). The MediaSourceConfiguration.getStreamInfo() will not work.
* The following classes are no longer publicly available.
* MediaSource
* MediaSourceConfiguration
* MediaSourceSink
* AbstractKinesisVideoClient
* NativeKinesisVideoClient
* BytesGenerator
* BytesMediaSource
* BytesMediaSourceConfiguration
* ProducerStreamSink
* KinesisVideoServiceClient
* NativeKinesisVideoProducerJni
* NativeKinesisVideoProducerStream
* NativeLibraryLoader
* KinesisVideoMetrics
* KinesisVideoProducer
* KinesisVideoProducerStream
* KinesisVideoStreamMetrics
* ReadResult
* ServiceCallbacks
* com.amazonaws.kinesisvideo.service.exception.AccessDeniedException
* com.amazonaws.kinesisvideo.service.exception.AmazonServiceException
* com.amazonaws.kinesisvideo.service.exception.ResourceInUseException
* com.amazonaws.kinesisvideo.service.exception.ResourceNotFoundException
* AckConsumer
* BlockingAckConsumer
* DefaultServiceCallbacksImpl

### Release 1.5.0 (24th August 2018)
* Windows native library available for Producer SDK
* Intermittent producer support
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.amazonaws.kinesisvideo.demoapp;

import com.amazonaws.kinesisvideo.client.KinesisVideoClient;
import com.amazonaws.kinesisvideo.client.mediasource.MediaSource;
import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSource;
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import com.amazonaws.kinesisvideo.demoapp.auth.AuthHelper;
import com.amazonaws.kinesisvideo.java.client.KinesisVideoJavaClientFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public void onAckEvent(AckEvent event) {
@Override
public void onFailure(Throwable t) {
latch.countDown();
throw new RuntimeException(t);
System.out.println("onFailure: " + t.getMessage());
// TODO: Add your failure handling logic here
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ public String getType() {
return type;
}

public void setType(String type) {
public void setType(final String type) {
this.type = type;
}

public int getErrorCode() {
return errorCode;
}

public void setErrorCode(int errorCode) {
public void setErrorCode(final int errorCode) {
this.errorCode = errorCode;
}

public long getFragmentTimecode() {
return fragmentTimecode;
}

public void setFragmentTimecode(long fragmentTimecode) {
public void setFragmentTimecode(final long fragmentTimecode) {
this.fragmentTimecode = fragmentTimecode;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.amazonaws.kinesisvideo.client;

import com.amazonaws.kinesisvideo.client.mediasource.MediaSource;
import com.amazonaws.kinesisvideo.client.mediasource.MediaSourceConfiguration;
import com.amazonaws.kinesisvideo.client.mediasource.UnknownMediaSourceException;
import com.amazonaws.kinesisvideo.client.mediasource.UnsupportedConfigurationException;
import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSource;
import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSourceConfiguration;
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import com.amazonaws.kinesisvideo.producer.DeviceInfo;

Expand Down Expand Up @@ -38,12 +38,20 @@ void initialize(@Nonnull final DeviceInfo deviceInfo)
List<MediaSourceConfiguration.Builder<? extends MediaSourceConfiguration>> listSupportedConfigurations();

/**
* Register a media source
* Register a media source. The media source will be binding to kinesis video producer stream
* to send out data from media source.
*
* @param mediaSource media source binding to kinesis video producer stream
* @throws KinesisVideoException
*/
void registerMediaSource(final MediaSource mediaSource) throws KinesisVideoException;

/**
* Un-Register a media source
* Un-Register a media source. The media source will stop binding to kinesis video producer stream
* and it cannot send data via producer stream afterwards until register again.
*
* @param mediaSource media source to stop binding to kinesis video producer stream
* @throws KinesisVideoException
*/
void unregisterMediaSource(final MediaSource mediaSource) throws KinesisVideoException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.amazonaws.kinesisvideo.common.function.Consumer;
import com.amazonaws.kinesisvideo.common.logging.Log;
import com.amazonaws.kinesisvideo.common.preconditions.Preconditions;
import com.amazonaws.kinesisvideo.encoding.ChunkEncoder;
import com.amazonaws.kinesisvideo.http.ParallelSimpleHttpClient;
import com.amazonaws.kinesisvideo.signing.KinesisVideoSigner;
Expand Down Expand Up @@ -38,7 +39,7 @@ public final class PutMediaClient {
private static final String CONNECTION = "connection";
private static final String KEEP_ALIVE = "keep-alive";
private static final String USER_AGENT = "user-agent";
private static final int BUFFER_SIZE = 128 * 128; //16kb
private static final int BUFFER_SIZE = 1024 * 1024; // 1MB
private static final double MILLI_TO_SEC = 1000;
private static final int LOGGING_INTERVAL = 250; // Rougly every 10 seconds in 25 fps
private final Builder mBuilder;
Expand Down Expand Up @@ -289,10 +290,7 @@ public Builder upstreamKbps(final long kbps) {
}

public Builder log(final Log log) {
if (log == null) {
throw new NullPointerException("log");
}
mLog = log;
mLog = Preconditions.checkNotNull(log);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSourceConfiguration;
import com.amazonaws.kinesisvideo.producer.StreamInfo;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.amazonaws.kinesisvideo.client.mediasource;

import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSourceConfiguration;

/**
* Thrown when MediaSourceService determines that the media source configuration is not supported
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static String readInputStream(final InputStream inputStream, final byte[
do {
result = inputStream.read(buffer, offset++, 1);
} while (result > -1 && arrayIndexOf(buffer, 0, offset, delimiter) == -1);
return new String(buffer, 0 , offset, StandardCharsets.UTF_8);
return new String(buffer, 0, offset, StandardCharsets.UTF_8);
}

public static int arrayIndexOf(final byte[] haystack, final int tail, final int head, final byte[] needle) {
Expand Down Expand Up @@ -165,12 +165,21 @@ private static String parseTextBody(final BufferedReader reader) {
public static Integer decodeAckInResponseBody(final InputStream inputStream,
final Consumer<String> ackTimestampConsumer) {
final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.US_ASCII));

try {
skipResponseHeaders(reader);
return parseResponseBodyAndDecodeAck(reader, ackTimestampConsumer);
} catch (final Throwable e) {
throw new RuntimeException("Exception while decoding Ack in response ! ", e);
}
}

public static Integer parseResponseBodyAndDecodeAck(final BufferedReader reader,
final Consumer<String> ackTimestampConsumer) {
String line;
int chunkSize;
int numBytesRead, offset, ackCount = 0;

try {
skipResponseHeaders(reader);
line = skipEmptyLines(reader);

// Parse chunk data
Expand Down Expand Up @@ -203,7 +212,6 @@ public static Integer decodeAckInResponseBody(final InputStream inputStream,
} catch (final Throwable e) {
throw new RuntimeException("Exception while decoding Ack in response ! ", e);
}

return ackCount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public boolean isTrusted(final X509Certificate[] chain, final String authType) t

private static class NoOpHostNameVerifier implements HostnameVerifier {
@Override
public boolean verify(String hostname, SSLSession session) {
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void accept(final OutputStream outputStream) {
};
private static final Consumer<Exception> NO_OP_COMPLETION = new Consumer<Exception>() {
@Override
public void accept(Exception object) {
public void accept(final Exception object) {
// No op;
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.amazonaws.kinesisvideo.client;
package com.amazonaws.kinesisvideo.internal.client;

import com.amazonaws.kinesisvideo.client.mediasource.MediaSource;
import com.amazonaws.kinesisvideo.client.KinesisVideoClient;
import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSource;
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import com.amazonaws.kinesisvideo.common.logging.Log;
import com.amazonaws.kinesisvideo.common.preconditions.Preconditions;
Expand Down Expand Up @@ -118,7 +119,11 @@ public void free() throws KinesisVideoException {
}

/**
* Adds an already created {@link MediaSource} to the list.
* Register a media source. The media source will be binding to kinesis video producer stream
* to send out data from media source.
*
* @param mediaSource media source binding to kinesis video producer stream
* @throws KinesisVideoException
*/
@Override
public void registerMediaSource(@Nonnull final MediaSource mediaSource) throws KinesisVideoException {
Expand All @@ -127,7 +132,11 @@ public void registerMediaSource(@Nonnull final MediaSource mediaSource) throws K
}

/**
* Removes/unregisters {@link MediaSource} from the list.
* Un-Register a media source. The media source will stop binding to kinesis video producer stream
* and it cannot send data via producer stream afterwards until register again.
*
* @param mediaSource media source to stop binding to kinesis video producer stream
* @throws KinesisVideoException
*/
@Override
public void unregisterMediaSource(@Nonnull final MediaSource mediaSource) throws KinesisVideoException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.amazonaws.kinesisvideo.client;
package com.amazonaws.kinesisvideo.internal.client;

import static com.amazonaws.kinesisvideo.common.preconditions.Preconditions.checkNotNull;

Expand All @@ -11,24 +11,25 @@
import javax.annotation.Nonnull;

import com.amazonaws.kinesisvideo.auth.DefaultAuthCallbacks;
import com.amazonaws.kinesisvideo.client.mediasource.MediaSource;
import com.amazonaws.kinesisvideo.client.mediasource.MediaSourceConfiguration;
import com.amazonaws.kinesisvideo.client.KinesisVideoClientConfiguration;
import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSource;
import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSourceConfiguration;
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import com.amazonaws.kinesisvideo.common.logging.Log;
import com.amazonaws.kinesisvideo.common.logging.LogLevel;
import com.amazonaws.kinesisvideo.common.preconditions.Preconditions;
import com.amazonaws.kinesisvideo.mediasource.ProducerStreamSink;
import com.amazonaws.kinesisvideo.internal.mediasource.ProducerStreamSink;
import com.amazonaws.kinesisvideo.producer.AuthCallbacks;
import com.amazonaws.kinesisvideo.producer.DeviceInfo;
import com.amazonaws.kinesisvideo.producer.KinesisVideoProducer;
import com.amazonaws.kinesisvideo.producer.KinesisVideoProducerStream;
import com.amazonaws.kinesisvideo.internal.producer.KinesisVideoProducer;
import com.amazonaws.kinesisvideo.internal.producer.KinesisVideoProducerStream;
import com.amazonaws.kinesisvideo.producer.ProducerException;
import com.amazonaws.kinesisvideo.producer.ServiceCallbacks;
import com.amazonaws.kinesisvideo.internal.producer.ServiceCallbacks;
import com.amazonaws.kinesisvideo.producer.StorageCallbacks;
import com.amazonaws.kinesisvideo.producer.StreamCallbacks;
import com.amazonaws.kinesisvideo.producer.client.KinesisVideoServiceClient;
import com.amazonaws.kinesisvideo.producer.jni.NativeKinesisVideoProducerJni;
import com.amazonaws.kinesisvideo.service.DefaultServiceCallbacksImpl;
import com.amazonaws.kinesisvideo.internal.producer.client.KinesisVideoServiceClient;
import com.amazonaws.kinesisvideo.internal.producer.jni.NativeKinesisVideoProducerJni;
import com.amazonaws.kinesisvideo.internal.service.DefaultServiceCallbacksImpl;
import com.amazonaws.kinesisvideo.streaming.DefaultStreamCallbacks;

/**
Expand Down Expand Up @@ -119,7 +120,7 @@ public void initialize(@Nonnull final DeviceInfo deviceInfo) throws KinesisVideo
}

@Override
public void registerMediaSource(final MediaSource mediaSource) throws KinesisVideoException {
public void registerMediaSource(@Nonnull final MediaSource mediaSource) throws KinesisVideoException {
Preconditions.checkNotNull(mediaSource);
StreamCallbacks streamCallbacks = mediaSource.getStreamCallbacks();
if (streamCallbacks == null) {
Expand All @@ -134,7 +135,7 @@ public void registerMediaSource(final MediaSource mediaSource) throws KinesisVid
}

@Override
public void unregisterMediaSource(final MediaSource mediaSource) throws KinesisVideoException {
public void unregisterMediaSource(@Nonnull final MediaSource mediaSource) throws KinesisVideoException {
Preconditions.checkNotNull(mediaSource);
super.unregisterMediaSource(mediaSource);

Expand All @@ -152,7 +153,11 @@ public void stopAllMediaSources() throws KinesisVideoException {
super.stopAllMediaSources();
for (final MediaSource mediaSource : mMediaSources) {
final KinesisVideoProducerStream producerStream = mMediaSourceToStreamMap.get(mediaSource);
producerStream.stopStreamSync();
try {
producerStream.stopStreamSync();
} catch (final KinesisVideoException e) {
mLog.exception(e, "Failed to stop media source %s due to Exception ", mediaSource);
}
}
}

Expand Down Expand Up @@ -183,7 +188,7 @@ public void free() throws KinesisVideoException {
}

/**
* Initialize a new native {@link com.amazonaws.kinesisvideo.producer.KinesisVideoProducer}.
* Initialize a new native {@link com.amazonaws.kinesisvideo.internal.producer.KinesisVideoProducer}.
* Used internally by {@link #initialize} and visible for testing.
*/
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.amazonaws.kinesisvideo.client.mediasource;
package com.amazonaws.kinesisvideo.internal.client.mediasource;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.amazonaws.kinesisvideo.client.mediasource.MediaSourceState;
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import com.amazonaws.kinesisvideo.producer.StreamCallbacks;
import com.amazonaws.kinesisvideo.producer.StreamInfo;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.amazonaws.kinesisvideo.client.mediasource;
package com.amazonaws.kinesisvideo.internal.client.mediasource;

/**
* Configuration for the media source. Each concrete media source
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.amazonaws.kinesisvideo.client.mediasource;
package com.amazonaws.kinesisvideo.internal.client.mediasource;

import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import com.amazonaws.kinesisvideo.producer.KinesisVideoFrame;
import com.amazonaws.kinesisvideo.producer.KinesisVideoProducerStream;
import com.amazonaws.kinesisvideo.internal.producer.KinesisVideoProducerStream;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.amazonaws.kinesisvideo.mediasource;
package com.amazonaws.kinesisvideo.internal.mediasource;

import java.nio.ByteBuffer;

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

import static com.amazonaws.kinesisvideo.common.preconditions.Preconditions.checkNotNull;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.amazonaws.kinesisvideo.client.mediasource.MediaSourceSink;
import com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSourceSink;
import com.amazonaws.kinesisvideo.common.exception.KinesisVideoException;
import com.amazonaws.kinesisvideo.producer.KinesisVideoFrame;
import com.amazonaws.kinesisvideo.producer.KinesisVideoProducerStream;
import com.amazonaws.kinesisvideo.internal.producer.KinesisVideoProducerStream;

/**
* Implementation of the MediaSourceSink interface that pushes frames and stream configuration
Expand Down
Loading

0 comments on commit 9d88b06

Please sign in to comment.