From 63d598d4443f906b34bedaf49e870b7a2be1a5c8 Mon Sep 17 00:00:00 2001 From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674> Date: 星期四, 06 四月 2017 12:14:30 +0800 Subject: [PATCH] bug fix for android device --- VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp | 179 +++++++++++++++++++++-------------------------------------- 1 files changed, 64 insertions(+), 115 deletions(-) diff --git a/VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp b/VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp index d3b5233..6a3dcf0 100644 --- a/VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp +++ b/VisitFace/RtspNativeCodec/app/src/main/cpp/RtspNativeCodecJNI.cpp @@ -1,7 +1,5 @@ #include "RtspNativeCodecJNI.h" -#include <PipeLine.h> -#include <PL_RTSPClient.h> -#include <PL_AndroidMediaCodecDecoder.h> +#include "CameraWrapper.h" #include <logger.h> #include <Logger/src/logger.hpp> @@ -13,128 +11,39 @@ #include <pthread.h> std::stringstream logss; +//std::fstream logss("/storage/sdcard/log.log", std::fstream::out); +//std::fstream logss("/storage/emulated/0/log.log", std::fstream::out); Logger g_logger(logss); - -class CameraWrapper -{ -public: - PipeLine* pipeLine; - - PL_RTSPClient_Config rtspConfig; - PL_AndroidMediaCodecDecoder_Config amcdConfig; - - jmethodID faceCallback; - ANativeWindow* window; - - pthread_t live_daemon_thid; - bool running; - - CameraWrapper() : - pipeLine(nullptr), rtspConfig(), amcdConfig(), faceCallback(0), window(nullptr), - live_daemon_thid(0), running(false) - { - } - - ~CameraWrapper() - { - stop(); - delete pipeLine; - } - - bool start() - { - LOG_INFO << "CameraWrapper::start" << LOG_ENDL; - - running = true; - int ret = pthread_create(&live_daemon_thid, NULL, CameraWrapper::live_daemon_thd, this); - if(ret != 0) - { - LOGP(ERROR, "pthread_create: %s/n", strerror(ret)); - running = false; - return false; - } - - return true; - } - - void stop() - { - LOG_INFO << "CameraWrapper::stop" << LOG_ENDL; - - if (!running) - return; - - running = false; - pthread_join(live_daemon_thid, NULL); - } - - bool initPl() - { - PL_RTSPClient* rtspClient = (PL_RTSPClient*)pipeLine->push_elem("PL_RTSPClient"); - bool ret = rtspClient->init(&rtspConfig); - if (!ret) - { - LOG_ERROR << "rtspClient.init error" << std::endl; - return false; - } - - PL_AndroidMediaCodecDecoder* amcDecoder = (PL_AndroidMediaCodecDecoder*)pipeLine->push_elem("PL_AndroidMediaCodecDecoder"); - ret = amcDecoder->init(&amcdConfig); - if (!ret) - { - LOG_ERROR << "amcDecoder.init error" << std::endl; - return false; - } - - return true; - } - - static void* live_daemon_thd(void* arg) - { - LOG_INFO << "CameraWrapper::live_daemon_thd start" << LOG_ENDL; - - CameraWrapper& cameraWrapper = *(CameraWrapper*)arg; - - while(cameraWrapper.running) - { - PipeLineElem* last = cameraWrapper.pipeLine->pipe(); - bool ret = cameraWrapper.pipeLine->check_pipe_complete(last); - LOG_DEBUG << "pipe ret=" << ret << LOG_ENDL; - - if (ret) - { - PipeMaterial pm; - last->gain(pm); - } - } - - LOG_INFO << "CameraWrapper::live_daemon_thd stop, ret=" << LOG_ENDL; - } -}; CameraWrapper g_CameraWrappers[CAMERA_COUNT]; extern "C" { -void Java_com_example_nativecodec_NativeCodec_init(JNIEnv *env, jclass clazz) +void Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_init(JNIEnv *env, jclass clazz) { g_logger.set_level(VERBOSE); PipeLine::register_global_elem_creator("PL_RTSPClient", create_PL_RTSPClient); PipeLine::register_global_elem_creator("PL_AndroidMediaCodecDecoder", create_PL_AndroidMediaCodecDecoder); + +#ifdef USE_ST_SDK + PipeLine::register_global_elem_creator("PL_SensetimeFaceTrack", create_PL_SensetimeFaceTrack); +#endif for (size_t i = 0; i < CAMERA_COUNT; i++) { + g_CameraWrappers[i].cameraIdx = i + 1; + g_CameraWrappers[i].pipeLine = new PipeLine; PipeLine& pipeLine(*(g_CameraWrappers[i].pipeLine)); } } // set the surface -void Java_com_example_nativecodec_NativeCodec_setSurface(JNIEnv *env, jclass clazz, jint cameraIdx, jobject surface) +void Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_setSurface(JNIEnv *env, jclass clazz, jint cameraIdx, jobject surface) { - LOG_DEBUG << "@@@ Java_com_example_nativecodec_NativeCodec_setSurface" << LOG_ENDL; + LOG_DEBUG << "@@@ Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_setSurface" << LOG_ENDL; assert(cameraIdx <= CAMERA_COUNT); cameraIdx -= 1; @@ -150,9 +59,9 @@ LOGP(DEBUG, "@@@ setsurface %p", cameraWrapper.window); } -jboolean Java_com_example_nativecodec_NativeCodec_createPlayer(JNIEnv* env, jclass clazz, jint cameraIdx, jstring uri) +jboolean Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_createPlayer(JNIEnv* env, jclass clazz, jint cameraIdx, jstring uri) { - LOG_DEBUG << "@@@ Java_com_example_nativecodec_NativeCodec_createPlayer" << LOG_ENDL; + LOG_DEBUG << "@@@ Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_createPlayer" << LOG_ENDL; assert(cameraIdx <= CAMERA_COUNT); cameraIdx -= 1; @@ -176,6 +85,17 @@ cameraWrapper.amcdConfig.ak_height = 1080; cameraWrapper.amcdConfig.windowSurface = cameraWrapper.window; cameraWrapper.amcdConfig.releaseOutputBuffIdx = true; +#ifndef USE_ST_SDK + cameraWrapper.amcdConfig.releaseOutputBuffIdxInPay = true; +#endif + } + + { + cameraWrapper.sftConfig.point_size = 21; + cameraWrapper.sftConfig.detect_face_cnt_limit = MAX_FACE; + cameraWrapper.sftConfig.draw_face_rect = true; + cameraWrapper.sftConfig.draw_face_feature_point = true; + cameraWrapper.sftConfig.generate_face_feature = true; } bool ret = cameraWrapper.initPl(); @@ -186,9 +106,9 @@ } // shut down the native media system -void Java_com_example_nativecodec_NativeCodec_shutdown(JNIEnv* env, jclass clazz, jint cameraIdx) +void Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_shutdown(JNIEnv* env, jclass clazz, jint cameraIdx) { - LOG_DEBUG << "@@@ Java_com_example_nativecodec_NativeCodec_shutdown" << LOG_ENDL; + LOG_DEBUG << "@@@ Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_shutdown" << LOG_ENDL; assert(cameraIdx <= CAMERA_COUNT); cameraIdx -= 1; @@ -196,46 +116,75 @@ cameraWrapper.stop(); } -jboolean Java_com_example_nativecodec_NativeCodec_setFaceCallback(JNIEnv* env, jclass clazz, jint cameraIdx, jstring func) +jboolean Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_setFaceCallback(JNIEnv* env, jclass clazz, jint cameraIdx, jstring func) { - LOG_DEBUG << "@@@ Java_com_example_nativecodec_NativeCodec_setFaceCallback" << LOG_ENDL; + LOG_DEBUG << "@@@ Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_setFaceCallback" << LOG_ENDL; assert(cameraIdx <= CAMERA_COUNT); cameraIdx -= 1; - CameraWrapper& cameraWrapper(g_CameraWrappers[cameraIdx]); jclass cls = env->GetObjectClass(clazz); const char *utfFunc = env->GetStringUTFChars(func, NULL); - cameraWrapper.faceCallback = env->GetMethodID(cls, utfFunc, "(II)V"); // Java_FaceCallback_func + cameraWrapper.faceCallback = env->GetMethodID(cls, utfFunc, "(II)V"); // Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_FaceCallback_func env->ReleaseStringUTFChars(func, utfFunc); // call: //env->CallVoidMethod(obj, callback, 5 , 10); } -void Java_com_example_nativecodec_NativeCodec_lockFace(JNIEnv* env, jclass clazz, jint cameraIdx) +void Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_lockFace(JNIEnv* env, jclass clazz, jint cameraIdx) { + LOG_DEBUG << "@@@ Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_lockFace" << LOG_ENDL; assert(cameraIdx <= CAMERA_COUNT); cameraIdx -= 1; + CameraWrapper& cameraWrapper(g_CameraWrappers[cameraIdx]); + + cameraWrapper.lockFace(); } -void Java_com_example_nativecodec_NativeCodec_releaseFace(JNIEnv* env, jclass clazz, jint cameraIdx) +void Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_releaseFace(JNIEnv* env, jclass clazz, jint cameraIdx) { + LOG_DEBUG << "@@@ Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_releaseFace" << LOG_ENDL; assert(cameraIdx <= CAMERA_COUNT); cameraIdx -= 1; + CameraWrapper& cameraWrapper(g_CameraWrappers[cameraIdx]); + + cameraWrapper.releaseFace(); } -jboolean Java_com_example_nativecodec_NativeCodec_getFaceList(JNIEnv* env, jclass clazz, jint cameraIdx, jbyteArray faceListPb) +jboolean Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_getFaceList(JNIEnv* env, jclass clazz, jint cameraIdx, jbyteArray faceListPb) { + LOG_DEBUG << "@@@ Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_getFaceList" << LOG_ENDL; assert(cameraIdx <= CAMERA_COUNT); cameraIdx -= 1; + CameraWrapper& cameraWrapper(g_CameraWrappers[cameraIdx]); + + // Y channel of YUV420p, packed in protobuf + uint8_t buffer[MAX_FACE * MAX_FACE_WIDTH * MAX_FACE_HEIGHT]; + size_t buffSize = sizeof(buffer); + bool ret = false; + +#ifdef USE_ST_SDK + ret = cameraWrapper.faceCache.getFaceListPb(buffer, buffSize); +#endif + + if (!ret) + { + LOG_INFO << "No face captured" << LOG_ENDL; + return JNI_FALSE; + } + + uint8_t* _faceListPb = (uint8_t*)faceListPb; + LOG_DEBUG << _faceListPb[0] << " "<< _faceListPb[1] << " "<< _faceListPb[2] << " " <<LOG_ENDL; } -jboolean Java_com_example_nativecodec_NativeCodec_getFaceImages(JNIEnv* env, jclass clazz, jint cameraIdx, jbyteArray faceImagesIdx, jbyteArray faceImages) +jboolean Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_getFaceImages(JNIEnv* env, jclass clazz, jint cameraIdx, jintArray faceImagesIdx, jbyteArray faceImages) { + LOG_DEBUG << "@@@ Java_com_bsk_zhangbo_demoforbsk_util_RtspFaceNative_getFaceImages" << LOG_ENDL; assert(cameraIdx <= CAMERA_COUNT); cameraIdx -= 1; + CameraWrapper& cameraWrapper(g_CameraWrappers[cameraIdx]); } -- Gitblit v1.8.0