saki4510t / UVCCamera

library and sample to access to UVC web camera on non-rooted Android device
2.95k stars 1.19k forks source link

Where does the preview delay mainly come from? #660

Open zipswich opened 2 years ago

zipswich commented 2 years ago

The delay for resolution 4656x3496 is about 1000ms. I took a look at do_preview void UVCPreview::do_preview(uvc_stream_ctrl_t *ctrl) in UVCPreview.cpp.

    for ( ; LIKELY(isRunning()) ; ) {
            frame_mjpeg = waitPreviewFrame();
            if (LIKELY(frame_mjpeg)) {
                //The following takes no time
                frame = get_frame(frame_mjpeg->width * frame_mjpeg->height * 2);
                       //The following takes 150ms
                       result = uvc_mjpeg2yuyv(frame_mjpeg, frame);   // MJPEG => yuyv
                //The following takes no time
                recycle_frame(frame_mjpeg);
                if (LIKELY(!result)) {
                               //The following takes 200 ms for uvc_mjpeg2yuyv(frame_mjpeg, frame)
                    frame = draw_preview_one(frame, &mPreviewWindow, uvc_any2rgbx, 4);
                               //The entire process takes 350ms for uvc_mjpeg2yuyv(frame_mjpeg, frame)
                    addCaptureFrame(frame);
                } else {
                    recycle_frame(frame);
                }
            }
        }

Each iteration in the loop takes about 350ms, so the major part of the 1000ms delay is from somewhere else. Could anyone offer a tip on this?

liu408309046 commented 2 years ago

Is there any solution? I have encountered a similar problem. When the resolution is set to a large one, the preview delay is very high

shengjunhu commented 2 years ago

Is there any solution? I have encountered a similar problem. When the resolution is set to a large one, the preview delay is very high

What is the maximum resolution you use ? Decoding is time-consuming during rendering.

zhouqunhuang commented 1 month ago

How to modify to reduce latency. This delay is really a headache!!