Search in sources :

Example 1 with OnStreamDataAvailable

use of com.amazonaws.kinesisvideo.internal.mediasource.OnStreamDataAvailable 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)

Aggregations

KinesisVideoException (com.amazonaws.kinesisvideo.common.exception.KinesisVideoException)1 OnStreamDataAvailable (com.amazonaws.kinesisvideo.internal.mediasource.OnStreamDataAvailable)1 KinesisVideoFrame (com.amazonaws.kinesisvideo.producer.KinesisVideoFrame)1 ByteBuffer (java.nio.ByteBuffer)1