use of com.amazonaws.kinesisvideo.producer.KinesisVideoFrame in project amazon-kinesis-video-streams-parser-library by aws.
the class KVSMediaSource method putFrameData.
public void putFrameData(final EncodedFrame encodedFrame) {
final int flags = encodedFrame.isKeyFrame() ? FRAME_FLAG_KEY_FRAME : FRAME_FLAG_NONE;
if (encodedFrame.getByteBuffer() != null) {
final KinesisVideoFrame frame = new KinesisVideoFrame(frameIndex++, flags, encodedFrame.getTimeCode() * HUNDREDS_OF_NANOS_IN_MS, encodedFrame.getTimeCode() * HUNDREDS_OF_NANOS_IN_MS, FRAME_DURATION_20_MS * HUNDREDS_OF_NANOS_IN_MS, encodedFrame.getByteBuffer());
if (frame.getSize() == 0) {
return;
}
putFrame(frame);
} else {
log.info("Frame Data is null !");
}
}
use of com.amazonaws.kinesisvideo.producer.KinesisVideoFrame in project aws-sdk-android by aws-amplify.
the class BytesMediaSource method createDataAvailableCallback.
private OnStreamDataAvailable createDataAvailableCallback() {
return new OnStreamDataAvailable() {
@Override
public void onFrameDataAvailable(final ByteBuffer data) {
final long currentTimeMs = System.currentTimeMillis();
final long decodingTs = currentTimeMs * HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
final long presentationTs = currentTimeMs * HUNDREDS_OF_NANOS_IN_A_MILLISECOND;
final long msSinceLastFrame = currentTimeMs - lastTimestampMillis;
final long frameDuration = lastTimestampMillis == 0 ? DEFAULT_FRAME_DURATION_33MS * HUNDREDS_OF_NANOS_IN_A_MILLISECOND : msSinceLastFrame * HUNDREDS_OF_NANOS_IN_A_MILLISECOND / 2;
final int flags = isKeyFrame() ? FRAME_FLAG_KEY_FRAME : FRAME_FLAG_NONE;
final KinesisVideoFrame frame = new KinesisVideoFrame(frameIndex++, flags, decodingTs, presentationTs, frameDuration, data);
// ignore frame of size 0 or duration of 0
if (frame.getSize() == 0 || frameDuration == 0) {
return;
}
lastTimestampMillis = currentTimeMs;
submitFrameOnUIThread(frame);
}
@Override
public void onFragmentMetadataAvailable(final String metadataName, final String metadataValue, final boolean persistent) {
try {
mediaSourceSink.onFragmentMetadata(metadataName, metadataValue, persistent);
} catch (final KinesisVideoException e) {
// TODO: log/throw
}
}
};
}
use of com.amazonaws.kinesisvideo.producer.KinesisVideoFrame in project aws-sdk-android by aws-amplify.
the class ImageFrameSource method createKinesisVideoFrameFromImage.
private KinesisVideoFrame createKinesisVideoFrameFromImage(final long index) {
final String filename = String.format(configuration.getFilenameFormat(), index % totalFiles + configuration.getStartFileIndex());
final long currentTimeMs = System.currentTimeMillis();
final int flags = isKeyFrame() ? FRAME_FLAG_KEY_FRAME : FRAME_FLAG_NONE;
final InputStream inputStream;
try {
inputStream = configuration.getAssetManager().open(configuration.getDir() + "/" + filename);
final byte[] data = new byte[inputStream.available()];
inputStream.read(data);
inputStream.close();
return new KinesisVideoFrame(frameCounter, flags, currentTimeMs * HUNDREDS_OF_NANOS_IN_A_MILLISECOND, currentTimeMs * HUNDREDS_OF_NANOS_IN_A_MILLISECOND, FRAME_DURATION_20_MS * HUNDREDS_OF_NANOS_IN_A_MILLISECOND, ByteBuffer.wrap(data));
} catch (final IOException e) {
log.error("Read file failed with Exception " + e.getMessage());
}
return null;
}
use of com.amazonaws.kinesisvideo.producer.KinesisVideoFrame in project aws-sdk-android by aws-amplify.
the class AndroidCameraMediaSourceTest method testInitializedState.
@Test
public void testInitializedState() throws KinesisVideoException {
cameraMediaSource = new AndroidCameraMediaSource(STREAM_NAME, context);
cameraMediaSource.configure(configuration);
MediaSourceSink sink = new MediaSourceSink() {
@Override
public void onFrame(@NonNull KinesisVideoFrame kinesisVideoFrame) throws KinesisVideoException {
}
@Override
public void onCodecPrivateData(@Nullable byte[] codecPrivateData) throws KinesisVideoException {
}
@Override
public void onCodecPrivateData(@Nullable byte[] codecPrivateData, int trackId) throws KinesisVideoException {
}
@Override
public void onFragmentMetadata(@NonNull String metadataName, @NonNull String metadataValue, boolean persistent) throws KinesisVideoException {
}
@Override
public KinesisVideoProducerStream getProducerStream() {
return null;
}
};
cameraMediaSource.initialize(sink);
assertThat(cameraMediaSource.getMediaSourceState()).isEqualTo(MediaSourceState.INITIALIZED);
assertThat(cameraMediaSource.getMediaSourceSink()).isEqualTo(sink);
cameraMediaSource.free();
}
Aggregations