I have created one thread for calling native function which are calling the MPEG2 codec which is developed in C. And callback_handler is calling java function for giving image frame and handler is displaying the frames on image view. And it is working fine. but when I am trying to create two threads for calling native function for each thread and displaying two videos.I have created two handlers for each thread. but when I started the application it is calling native methods two times but after some function execution I am getting VM Aborting error. I have searched for that problem. And I found that one JNIEnv can have only one thread.And for that we should register thread JNIEnv with JavaVM. In callback_handler I am doing that by using this function
JNIEnv *env = RegisterWithVM(&jvm);
if((NULL == env) || (NULL == jvm))
{
__android_log_print(ANDROID_LOG_INFO,"JNI", "callback_handler call failed\n");
return;
}
And I have also tried to attch the currentThread Enviroment with JavaVM in JNi native function using that code.
gJavaVM->GetEnv((void**) &env, JNI_VERSION_1_6);
gJavaVM->AttachCurrentThread(&env, NULL);
But after using this I am getting this error.
11-28 16:40:23.430: I/JNI(323): Loaded
11-28 16:40:23.430: I/JNI(323): Find the class
11-28 16:40:23.430: I/JNI(323): Registered...
11-28 16:40:23.430: I/JNI(323): Version...65540
11-28 16:40:23.440: I/JNI(323): CallDecoding function of thread is called
11-28 16:40:23.451: I/JNI(323): StartDecoding function is called
11-28 16:40:23.451: W/dalvikvm(323): JNI WARNING: threadid=7 using env from threadid=8
11-28 16:40:23.451: W/dalvikvm(323): in Lcom/example/Internet_TV12;.CallDecoding1 (ILjava/lang/Object;)V (NewByteArray)
11-28 16:40:23.451: I/dalvikvm(323): "Thread-8" prio=5 tid=7 NATIVE
11-28 16:40:23.451: I/dalvikvm(323): | group="main" sCount=0 dsCount=0 s=N obj=0x44ee97f0 self=0x131cc0
11-28 16:40:23.470: I/JNI(323): CallDecoding function of thread is called
11-28 16:40:23.470: I/JNI(323): In JNI interface image file opened
11-28 16:40:23.470: I/JNI(323): StartDecoding function is called
11-28 16:40:23.499: I/dalvikvm(323): | sysTid=331 nice=0 sched=0/0 cgrp=default handle=1153704
11-28 16:40:23.499: I/dalvikvm(323): | schedstat=( 28746111 138980250 15 )
11-28 16:40:23.499: I/dalvikvm(323): at com.example.Internet_TV12.CallDecoding1(Native Method)
11-28 16:40:23.499: I/dalvikvm(323): at com.example.Internet_TV12$4.run(Internet_TV12.java:57)
11-28 16:40:23.499: I/dalvikvm(323): at java.lang.Thread.run(Thread.java:1096)
11-28 16:40:23.499: E/dalvikvm(323): VM aborting
Can any body please help me to resolve this problem…
Thanks in Advance
It seems that you overwrite your env variable and then use it again in different thread.