int UVCPreview::stopPreview() { ENTER(); bool b = isRunning(); if (LIKELY(b)) { mIsRunning = false; pthread_cond_signal(&preview_sync); pthread_cond_signal(&capture_sync); if (pthread_join(capture_thread, NULL) != EXIT_SUCCESS) { LOGW("UVCPreview::terminate capture thread: pthread_join failed"); } if (pthread_join(preview_thread, NULL) != EXIT_SUCCESS) { LOGW("UVCPreview::terminate preview thread: pthread_join failed"); } clearDisplay(); } clearPreviewFrame(); clearCaptureFrame(); pthread_mutex_lock(&preview_mutex); if (mPreviewWindow) { ANativeWindow_release(mPreviewWindow); mPreviewWindow = NULL; } pthread_mutex_unlock(&preview_mutex); pthread_mutex_lock(&capture_mutex); if (mCaptureWindow) { ANativeWindow_release(mCaptureWindow); mCaptureWindow = NULL; } pthread_mutex_unlock(&capture_mutex); RETURN(0, int); }
void UVCPreview::do_preview(uvc_stream_ctrl_t *ctrl) { ENTER(); uvc_frame_t *frame = NULL; uvc_error_t result = uvc_start_iso_streaming( mDeviceHandle, ctrl, uvc_preview_frame_callback, (void *)this); if (LIKELY(!result)) { clearPreviewFrame(); pthread_create(&capture_thread, NULL, capture_thread_func, (void *)this); #if LOCAL_DEBUG LOGI("Streaming..."); #endif while (LIKELY(isRunning())) { frame = waitPreviewFrame(); if (LIKELY(frame)) { frame = draw_preview_one(frame, &mPreviewWindow, uvc_any2rgbx, 4); addCaptureFrame(frame); } } pthread_cond_signal(&capture_sync); #if LOCAL_DEBUG LOGI("preview_thread_func:wait for all callbacks complete"); #endif uvc_stop_streaming(mDeviceHandle); #if LOCAL_DEBUG LOGI("Streaming finished"); #endif } else { uvc_perror(result, "failed start_streaming"); } EXIT(); }
UVCPreview::~UVCPreview() { ENTER(); if (mPreviewWindow) ANativeWindow_release(mPreviewWindow); mPreviewWindow = NULL; if (mCaptureWindow) ANativeWindow_release(mCaptureWindow); mCaptureWindow = NULL; clearPreviewFrame(); clearCaptureFrame(); pthread_mutex_destroy(&preview_mutex); pthread_cond_destroy(&preview_sync); pthread_mutex_destroy(&capture_mutex); pthread_cond_destroy(&capture_sync); EXIT(); }