從java層向jni中傳遞GLSurfaceView的方法

來源:互聯網
上載者:User

標籤:view   sse   oba   src   extc   div   odi   技術   抽象   

從java朝jni中傳遞各種資料,是在android開發中經常需要面對的事情。對於一些典型的資料類型,網上已經有很多文章介紹,這裡列出一些資料類型:

 

對於GLSurfaceView,則使用:Landroid/opengl/GLSurfaceView;我的程式分為三層,App層,SDK層和capture層,其中capture層是採用c++調用java介面實現。下面將詳細流程敘述如下:1.在抽象java類中聲明native介面public class ConfMgr {static {try {System.loadLibrary("confmgr");}catch (Throwable e){Log.e("conf", "load so error:"+e.getMessage());}}public static native void InitAndroidVM(Context context);public static native void UninitAndroidVM();public static native void SetPreviewWnd(SurfaceView glview);}2.用javah命令產生標頭檔JNIEXPORT void JNICALL Java_com_jni_conf_ConfMgr_SetPreviewWnd(JNIEnv *env, jclass instance,jobject glview);3.實現函數介面,聲明介面SetCamPreviewWndvoid WINAPI SelectCameraFace(BOOL bFrontFace);JNIEXPORT void JNICALL Java_com_jni_conf_ConfMgr_SetPreviewWnd(JNIEnv *env, jclass instance,jobject glview){SetCamPreviewWnd(glview);}4.在SDK庫檔案中實現和聲明介面SetCamPreviewWndUTIL_EXPORT void WINAPI SetCamPreviewWnd(jobject glview);extern "C" void WINAPI SetCamPreviewWnd(jobject glview){TRACE_INFO2("vmgr::SetCamPreview");SetLocalPreview(glview);}5.在Campture庫檔案中聲明和實現SetLocalPreview介面extern "C" int32_t WINAPI SetLocalPreview(jobject glview);class androidcapturedelegate {public:static androidcapturedelegate* Create();static void Destroy(androidcapturedelegate *pDelete); androidcapturedelegate(const int32_t id);androidcapturedelegate();virtual int32_t Init();void InitCapture(int iWidth, int iHeight, int iFps, int iBitrate);static void SetLocalCamPreview(jobject glview);void SetCamPreview(jobject glview);static androidcapturedelegate *g_pAndCapDel;protected:virtual ~androidcapturedelegate();jobject _jCapturer; // Global ref to Java VideoCaptureAndroid object.};void androidcapturedelegate::SetLocalCamPreview(jobject glview){if(androidcapturedelegate::g_pAndCapDel != NULL){TRACE_INFO2("androidcapturedelegate::SetLocalCamPreview, enter");g_pAndCapDel->SetCamPreview(glview);}}void androidcapturedelegate::SetCamPreview(jobject glview){TRACE_INFO2("androidcapturedelegate::SetCamPreview, enter"); AttachThreadScoped ats(g_jvm);JNIEnv* env = ats.env();jmethodID jmethodID =env->GetMethodID(g_java_capturer_class, "setLocalPreview", "(Landroid/opengl/GLSurfaceView;)V");assert(jmethodID);env->CallVoidMethod(_jCapturer, jmethodID,glview);}6.在java檔案中實現setLocalPreview介面public class VideoCaptureAndroid implements GLSurfaceView.Renderer {private GLSurfaceView mLocalPreview = null;public VideoCaptureAndroid(long native_capturer) {}public void setLocalPreview(GLSurfaceView localPreview) {mLocalPreview = (GLSurfaceView) localPreview;mLocalPreview.setEGLContextClientVersion(2);mLocalPreview.setRenderer(mSelf);mLocalPreview.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);if(!mEnableHWCODEC) {mLocalPreview.getHolder().setFixedSize(640, 480);}}}

從java層向jni中傳遞GLSurfaceView的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.