🔥 UVC Camera on Android, developed based on the saki4510t/UVCCamera
Scan QR code or Download |
- 1-Add
UVCCamera
API withsetPreviewRotate(int rotate)
;
public boolean setPreviewRotate(@PREVIEW_ROTATE int rotate)
- 2-Add
UVCCamera
API withsetPreviewFlip(int flipH)
;
public boolean setPreviewFlip(@PREVIEW_FLIP int flip)
- 1-fix memory leak on
addCaptureFrame(uvc_frame_t *frame)
ofUVCpreview.cpp
void UVCPreview::addCaptureFrame(uvc_frame_t *frame) {
pthread_mutex_lock(&capture_mutex);
if (LIKELY(isRunning())) {
// keep only latest one
if (captureQueu) {
recycle_frame(captureQueu);
}
captureQueu = frame;
pthread_cond_broadcast(&capture_sync);
}else{
//Add By Hsj
recycle_frame(frame);
}
pthread_mutex_unlock(&capture_mutex);
}
- 2-fix end of
pthread_join()
forstopPreview()
ofUVCPreview.cpp
int UVCPreview::stopPreview() {
bool b = isRunning();
if (LIKELY(b)) {
mIsRunning = false;
//Add lock for fix pthread_join() can't be end
pthread_mutex_lock(&preview_mutex);
pthread_cond_signal(&preview_sync);
pthread_mutex_unlock(&preview_mutex);
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();
}
...
}
- 3-fix NullPointerException for
do_capture_callback()
ofUVCPreview.cpp
void UVCPreview::do_capture_callback(JNIEnv *env, uvc_frame_t *frame) {
...
//mFrameCallbackObj or iframecallback_fields.onFrame maybe null
if (isCapturing()) {
jobject buf = env->NewDirectByteBuffer(callback_frame->data, callbackPixelBytes);
env->CallVoidMethod(mFrameCallbackObj, iframecallback_fields.onFrame, buf);
env->DeleteLocalRef(buf);
}
...
}
- NDK: ndk-r14b
- AndroidStudio: 4.0
- Author: shengjunhu
- Date : 2020/05/01
- E-Mail: [email protected]
- GitHub: https://github.com/shengjunhu
Copyright (c) 2020 shengjunhu
Please comply with the relevant third party libraries license