opentok / opentok-android-sdk-samples

Sample applications illustrating best practices using OpenTok Android SDK.
https://tokbox.com/developer/sdks/android/
MIT License
211 stars 169 forks source link

OnPreviewFrame vs Runnable on CustomVideoCapturer #198

Closed janoonaj closed 4 years ago

janoonaj commented 5 years ago

Hello, not really an issue but a question.

there was a hugh change on the update made by @Lucashuang0802 on 3rd /May updating to SDK 2.14 on CustomVideoCapturer.java

Instead of using Camera's onPreviewFrame you are using a Runnable.

Runnable newFrame = new Runnable() {
        @Override
        public void run() {
            if (isCaptureRunning) {
                if (frame == null) {
                    VideoUtils.Size resolution = new VideoUtils.Size();
                    resolution = getPreferredResolution();
                    fps = getPreferredFramerate();
                    width = resolution.width;
                    height = resolution.height;
                    frame = new int[width * height];
                }

                provideIntArrayFrame(frame, ARGB, width, height, 0, false);
                handler.postDelayed(newFrame, 1000 / fps);
            }
        }
    };

There is no information in the log about the change, I would like to ask you if it is for performance issues; with many other small changes.

Thanks a lot,

robjperez commented 4 years ago

Hi, thanks for the comment @janoonaj ,

You are right, onPreviewFrame is what should be used.

That's how it is done in the Custom-Video-Driver sample: https://github.com/opentok/opentok-android-sdk-samples/blob/master/Custom-Video-Driver/CustomVideoDriverLib/src/main/java/com/example/tokbox/CustomVideoDriverLib/CustomVideoCapturer.java#L382