saki4510t / UVCCamera

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

Preview no image #482

Open eson-yunfei opened 5 years ago

eson-yunfei commented 5 years ago

this is log:

2019-05-30 10:50:45.425 8973-8989/com.serenegiant.usbcameratest0 I/MainActivity: supportedSize:{"formats":[{"index":1,"type":6,"default":1,"size":["1920x1080","160x120","320x240","352x288","640x480","800x600","1024x768","1280x720","1280x1024","1600x1200","1920x1080"]},{"index":2,"type":4,"default":1,"size":["640x480","1920x1080","1280x720","800x600","960x540"]}]} 2019-05-30 10:50:45.425 8973-8989/com.serenegiant.usbcameratest0 D/Surface: Surface::setBuffersUserDimensions(this=0x94b15830,w=640,h=480) 2019-05-30 10:50:45.425 8973-8989/com.serenegiant.usbcameratest0 E/libUVCCamera: [8989UVCPreview.cpp:330:startPreview]:UVCPreview::startPreview() ========= 2019-05-30 10:50:45.426 8973-9006/com.serenegiant.usbcameratest0 E/libUVCCamera: [9006UVCPreview.cpp:474:preview_thread_func]:UVCPreview::preview_thread_func() ========= 2019-05-30 10:50:45.441 8973-9006/com.serenegiant.usbcameratest0 I/libUVCCamera: [9006UVCPreview.cpp:507:prepare_preview]:frameSize=(640,480)@MJPEG 2019-05-30 10:50:45.441 8973-9006/com.serenegiant.usbcameratest0 E/libUVCCamera: [9006UVCPreview.cpp:529:do_preview]: =========== do_preview ========== 2019-05-30 10:50:45.723 8973-9006/com.serenegiant.usbcameratest0 E/libUVCCamera: [9006UVCPreview.cpp:544:do_preview]: =========== frameMode MJPEG ========== 2019-05-30 10:50:45.724 8973-9006/com.serenegiant.usbcameratest0 E/libUVCCamera: [9006UVCPreview.cpp:440:waitPreviewFrame]:pthread_mutex_lock 2019-05-30 10:50:45.724 8973-9006/com.serenegiant.usbcameratest0 E/libUVCCamera: [9006UVCPreview.cpp:442:waitPreviewFrame]:previewFrames.size() : 0 2019-05-30 10:50:45.724 8973-9006/com.serenegiant.usbcameratest0 E/libUVCCamera: [9006UVCPreview.cpp:445:waitPreviewFrame]:pthread_cond_wait

this is code :

void UVCPreview::do_preview(uvc_stream_ctrl_t ctrl) { ENTER(); LOGE(" =========== do_preview =========="); uvc_frame_t frame = NULL; uvc_frame_t frame_mjpeg = NULL; uvc_error_t result = uvc_start_streaming_bandwidth( mDeviceHandle, ctrl, uvc_preview_frame_callback, (void )this, requestBandwidth, 0);

if (LIKELY(!result)) {
    clearPreviewFrame();
    pthread_create(&capture_thread, NULL, capture_thread_func, (void *)this);

if LOCAL_DEBUG

    LOGE("Streaming...");

endif

    if (frameMode) {
        // MJPEG mode
         LOGE(" =========== frameMode  MJPEG  ==========");
        for ( ; LIKELY(isRunning()) ; ) {
            frame_mjpeg = waitPreviewFrame();
            if (LIKELY(frame_mjpeg)) {
                frame = get_frame(frame_mjpeg->width * frame_mjpeg->height * 2);
                result = uvc_mjpeg2yuyv(frame_mjpeg, frame);   // MJPEG => yuyv
             //   result = uvc_mjpeg2rgb565(frame_mjpeg, frame);

                LOGE(" uvc_mjpeg2yuyv result is %d",result);
                recycle_frame(frame_mjpeg);
                if (LIKELY(!result)) {
                    LOGE("  draw_preview_one "  );
                    frame = draw_preview_one(frame, &mPreviewWindow, uvc_any2rgbx, 4);
                    addCaptureFrame(frame);
                } else {
                    LOGE("  recycle_frame "  );
                    recycle_frame(frame);
                }
            }
        }
    } else {
        // yuvyv mode
        LOGE(" =========== frameMode  yuvyv  :%d========== ",isRunning());

        for ( ; LIKELY(isRunning()) ; ) {
        LOGE(" =========== frame for  ==========");
            frame = waitPreviewFrame();
            LOGE(" =========== waitPreviewFrame ==========");
            if (LIKELY(frame)) {
            LOGE(" =========== addCaptureFrame ==========");
                frame = draw_preview_one(frame, &mPreviewWindow, uvc_any2rgbx, 4);
                addCaptureFrame(frame);
            }
        }
    }
    pthread_cond_signal(&capture_sync);

if LOCAL_DEBUG

    LOGE("preview_thread_func:wait for all callbacks complete");

endif

    uvc_stop_streaming(mDeviceHandle);

if LOCAL_DEBUG

    LOGE("Streaming finished");

endif

} else {
    uvc_perror(result, "failed start_streaming");
}

EXIT();

}