Search in sources :

Example 1 with KinesisVideoFrame

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 !");
    }
}
Also used : KinesisVideoFrame(com.amazonaws.kinesisvideo.producer.KinesisVideoFrame)

Example 2 with KinesisVideoFrame

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
            }
        }
    };
}
Also used : ByteBuffer(java.nio.ByteBuffer) KinesisVideoFrame(com.amazonaws.kinesisvideo.producer.KinesisVideoFrame) KinesisVideoException(com.amazonaws.kinesisvideo.common.exception.KinesisVideoException) OnStreamDataAvailable(com.amazonaws.kinesisvideo.internal.mediasource.OnStreamDataAvailable)

Example 3 with KinesisVideoFrame

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;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) KinesisVideoFrame(com.amazonaws.kinesisvideo.producer.KinesisVideoFrame)

Example 4 with KinesisVideoFrame

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();
}
Also used : MediaSourceSink(com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSourceSink) NonNull(androidx.annotation.NonNull) KinesisVideoFrame(com.amazonaws.kinesisvideo.producer.KinesisVideoFrame) Nullable(androidx.annotation.Nullable) Test(org.junit.Test)

Aggregations

KinesisVideoFrame (com.amazonaws.kinesisvideo.producer.KinesisVideoFrame)4 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 KinesisVideoException (com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)1 MediaSourceSink (com.amazonaws.kinesisvideo.internal.client.mediasource.MediaSourceSink)1 OnStreamDataAvailable (com.amazonaws.kinesisvideo.internal.mediasource.OnStreamDataAvailable)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ByteBuffer (java.nio.ByteBuffer)1 Test (org.junit.Test)1