android关于jni反射的一些操作
本文说明一下当用到jni的时候需要的反射功能及一些操作,应用场景在于c++反射调用java的一些变量及类的操作,下面截取项目中的代码片段。具体的可以看注释
方法如下: 1.添加如下代码在MainActivity类内 static { System.loadLibrary("hello_jni"); } public native String getstringfromC(); 2.打开终端,android studio已经提供了终端 3.首先进入java目录执行命令: javah -d ../jni com.example.root.ndk_sample.MainActivity com.example.root.ndk_sample.MainActivity是native函数的所在的包名和类名,中间使用“.”号分开 4.添加*.c文件在jni目录中 5.编写Android.mk和Application.mk 放在jni目录下面 6.Android.mk文件的内容如下: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE :=hello_jni LOCAL_SRC_FILES := hello_jni.c include $(BUILD_SHARED_LIBRARY) Application.mk 文件内容为: APP_ABI := all APP_OPIM :=debug
1:在环境变量path中配置例如“E:\work\java\android-studio\jre\bin”的路径才能用javah生成jni用的头文件。
2:在C:\Users\zhuweigang.DS\Desktop\LvsAndroidPlay\lvs_androidjni\src\main\java目录下(和com同级目录)输入:
“javah -d ../../jni com.example.lvs_androidjni.LvsAndroidInterfaceFFmpegDemux”即生成和mian同级目录的jni里面包含jni的头文件。
3:下面就用到ndk编写c的程序然后生成so,需要编写android.mk,Application.mk等等。
4:编写好android.mk和Application.mk,在同一级目录输入“ndk-build”生成.so。
5:可以用 " nm -D libLvsOpenal.so |grep interface_1init"查看是否有输出,其中“interface_1init”是javah生成的那个头文件里面的函数名称所包含的关键字。
如果成功了则显示如:
0000cf18 T Java_com_example_lvs_1androidjni_LvsAndroidInterfaceOpenAl_lvs_1openal_1interface_1init。
下面是具体的操作代码
//将java jobject(Hashmap)转为 c++用的Module_Info(用于init,需要分配内存)
static int Jobject2Module_Info(JNIEnv * env, jobject thiz,jobject jobj, Module_Info ** module_info,int * Length,
int useModuleStreamInfo_In,int useModuleStreamInfo_Out,
UseInfoType useinfotype)
{
int ret = 0;
//查看传进来的object是否是空
if (jobj == NULL)
{
LOGD("Jobject2Module_Info jobj == NULL");
return 1;
}
//得到map
jclass jmapclass = env->FindClass("java/util/HashMap");
jmethodID jkeysetmid = env->GetMethodID(jmapclass, "keySet", "()Ljava/util/Set;");
jmethodID jgetmid = env->GetMethodID(jmapclass,"get", "(Ljava/lang/Object;)Ljava/lang/Object;");
jobject jsetkey = env->CallObjectMethod(jobj,jkeysetmid);
//得到key数组(只有key没有value)
jclass jsetclass = env->FindClass("java/util/Set");
jmethodID jtoArraymid = env->GetMethodID(jsetclass, "toArray", "()[Ljava/lang/Object;");
jobjectArray jobjArray = (jobjectArray)env->CallObjectMethod(jsetkey,jtoArraymid);
if(jobjArray == NULL)
{
LOGD("error :jobjArray");
return -1;
}
jsize arraysize = env->GetArrayLength(jobjArray);
LOGD("******************arraysize:%d",(jint)arraysize);
//申请传出的数据信息结构体
Module_Info * pmodule_info = NULL; //数据信息结构体
int needlength = 0; //需要传给下层的长度
int count_info = 0; //info标号
if(arraysize > 0)
{
pmodule_info = *module_info;
pmodule_info = (Module_Info *)realloc(pmodule_info,arraysize * sizeof(Module_Info));
for (int i = 0; i< arraysize ;i++)
{
pmodule_info[i].ModuleStreamInfo_In = NULL;
pmodule_info[i].ModuleStreamInfo_Out = NULL;
}
}
//HashMap
//通过循环key数组得到value
for( int i=0; i < arraysize; i++)
{
//得到key
jobject jkeyobject = env->GetObjectArrayElement(jobjArray,i);
jclass jintclass = env->FindClass("java/lang/Integer");
jmethodID jintId = env->GetMethodID(jintclass, "intValue", "()I");
jint jkey = (jint)env->CallIntMethod(jkeyobject,jintId);
LOGD("jkey:%d",jkey);
//得到value
jobject jvalueobject = (jobject)env->CallObjectMethod(jobj,jgetmid,jkeyobject);
jclass jvalueclass = env->GetObjectClass(jvalueobject);
//stream_id
jmethodID jstream_id = env->GetMethodID(jvalueclass, "getstream_id", "()I"); //最后的参数是括号内参数括号外返回值
if(jstream_id == NULL)
{
LOGD("error :stream_id");
return -1;
}
jint info_stream_id = (jint)env->CallIntMethod(jvalueobject,jstream_id);
LOGD("stream_id:%d",info_stream_id);
//Is_ToNext_Module
jmethodID jIs_ToNext_Module_id = env->GetMethodID(jvalueclass, "getIs_ToNext_Module", "()I"); //最后的参数是括号内参数括号外返回值
if(jIs_ToNext_Module_id == NULL)
{
LOGD("error :Is_ToNext_Module");
return -1;
}
jint info_Is_ToNext_Module = (jint)env->CallIntMethod(jvalueobject,jIs_ToNext_Module_id);
LOGD("Is_ToNext_Module:%d",info_Is_ToNext_Module);
//device_type
jmethodID jdevice_type_id = env->GetMethodID(jvalueclass, "getdevice_type", "()I"); //最后的参数是括号内参数括号外返回值
if(jdevice_type_id == NULL)
{
LOGD("error :device_type");
return -1;
}
jint info_device_type = (jint)env->CallIntMethod(jvalueobject,jdevice_type_id);
LOGD("device_type:%d",info_device_type);
//CodecType
jmethodID jCodecType_id = env->GetMethodID(jvalueclass, "getCodecType", "()I"); //最后的参数是括号内参数括号外返回值
if(jCodecType_id == NULL)
{
LOGD("error :CodecType");
return -1;
}
jint info_CodecType = (jint)env->CallIntMethod(jvalueobject,jCodecType_id);
LOGD("CodecType:%d",info_CodecType);
//timebase_num
jmethodID jtimebase_num_id = env->GetMethodID(jvalueclass, "gettimebase_num", "()I"); //最后的参数是括号内参数括号外返回值
if(jtimebase_num_id == NULL)
{
LOGD("error :timebase_num");
return -1;
}
jint info_timebase_num = (jint)env->CallIntMethod(jvalueobject,jtimebase_num_id);
LOGD("timebase_num:%d",info_timebase_num);
//timebase_den
jmethodID jtimebase_den_id = env->GetMethodID(jvalueclass, "gettimebase_den", "()I"); //最后的参数是括号内参数括号外返回值
if(jtimebase_den_id == NULL)
{
LOGD("error :timebase_den");
return -1;
}
jint info_timebase_den = (jint)env->CallIntMethod(jvalueobject,jtimebase_den_id);
LOGD("timebase_den:%d",info_timebase_den);
//Channel
jmethodID jChannel_id = env->GetMethodID(jvalueclass, "getChannel", "()I"); //最后的参数是括号内参数括号外返回值
if(jChannel_id == NULL)
{
LOGD("error :Channel");
return -1;
}
jint info_Channel = (jint)env->CallIntMethod(jvalueobject,jChannel_id);
LOGD("Channel:%d",info_Channel);
//SampleFormat
jmethodID jSampleFormat_id = env->GetMethodID(jvalueclass, "getSampleFormat", "()I"); //最后的参数是括号内参数括号外返回值
if(jSampleFormat_id == NULL)
{
LOGD("error :SampleFormat");
return -1;
}
jint info_SampleFormat = (jint)env->CallIntMethod(jvalueobject,jSampleFormat_id);
LOGD("SampleFormat:%d",info_SampleFormat);
//SampleRate
jmethodID jSampleRate_id = env->GetMethodID(jvalueclass, "getSampleRate", "()I"); //最后的参数是括号内参数括号外返回值
if(jSampleRate_id == NULL)
{
LOGD("error :SampleRate");
return -1;
}
jint info_SampleRate = (jint)env->CallIntMethod(jvalueobject,jSampleRate_id);
LOGD("SampleRate:%d",info_SampleRate);
//Stream_PixFormat
jmethodID jgetStream_PixFormat_id = env->GetMethodID(jvalueclass, "getStream_PixFormat", "()I"); //最后的参数是括号内参数括号外返回值
if(jgetStream_PixFormat_id == NULL)
{
LOGD("error :Stream_PixFormat");
return -1;
}
jint info_Stream_PixFormat = (jint)env->CallIntMethod(jvalueobject,jgetStream_PixFormat_id);
LOGD("Stream_PixFormat:%d",info_Stream_PixFormat);
//Width
jmethodID jWidth_id = env->GetMethodID(jvalueclass, "getWidth", "()I"); //最后的参数是括号内参数括号外返回值
if(jWidth_id == NULL)
{
LOGD("error :Width");
return -1;
}
jint info_Width = (jint)env->CallIntMethod(jvalueobject,jWidth_id);
LOGD("Width:%d",info_Width);
//Height
jmethodID jHeight_id = env->GetMethodID(jvalueclass, "getHeight", "()I"); //最后的参数是括号内参数括号外返回值
if(jHeight_id == NULL)
{
LOGD("error :Height");
return -1;
}
jint info_Height = (jint)env->CallIntMethod(jvalueobject,jHeight_id);
LOGD("Height:%d",info_Height);
//codec_format
jmethodID jcodec_format_id = env->GetMethodID(jvalueclass, "getcodec_format", "()I"); //最后的参数是括号内参数括号外返回值
if(jcodec_format_id == NULL)
{
LOGD("error :codec_format");
return -1;
}
jint info_codec_format = (jint)env->CallIntMethod(jvalueobject,jcodec_format_id);
LOGD("codec_format:%d",info_codec_format);
//mux_format
jmethodID jmux_format_id = env->GetMethodID(jvalueclass, "getmux_format", "()I"); //最后的参数是括号内参数括号外返回值
if(jmux_format_id == NULL)
{
LOGD("error :mux_format");
return -1;
}
jint info_mux_format = (jint)env->CallIntMethod(jvalueobject,jmux_format_id);
LOGD("mux_format:%d",info_mux_format);
//pts
jmethodID jpts_id = env->GetMethodID(jvalueclass, "getpts", "()J"); //最后的参数是括号内参数括号外返回值
if(jpts_id == NULL)
{
LOGD("error :pts");
return -1;
}
jlong info_pts = (jlong)env->CallLongMethod(jvalueobject,jpts_id);
LOGD("pts:%lld",info_pts);
//dts
jmethodID jdts_id = env->GetMethodID(jvalueclass, "getdts", "()J"); //最后的参数是括号内参数括号外返回值
if(jdts_id == NULL)
{
LOGD("error :dts");
return -1;
}
jlong info_dts = (jlong)env->CallLongMethod(jvalueobject,jdts_id);
LOGD("dts:%lld",info_dts);
//BufLen
jmethodID jBufLen_id = env->GetMethodID(jvalueclass, "getBufLen", "()J"); //最后的参数是括号内参数括号外返回值
if(jBufLen_id == NULL)
{
LOGD("error :BufLen");
return -1;
}
jlong info_BufLen = (jlong)env->CallLongMethod(jvalueobject,jBufLen_id);
LOGD("BufLen:%lld",info_BufLen);
//ActualLen
jmethodID jActualLen_id = env->GetMethodID(jvalueclass, "getActualLen", "()J"); //最后的参数是括号内参数括号外返回值
if(jActualLen_id == NULL)
{
LOGD("error :ActualLen");
return -1;
}
jlong info_ActualLen = (jlong)env->CallLongMethod(jvalueobject,jActualLen_id);
LOGD("ActualLen:%lld",info_ActualLen);
//Buf
jmethodID jBuf_id = env->GetMethodID(jvalueclass, "getBuf", "()[B"); //最后的参数是括号内参数括号外返回值
if(jBuf_id == NULL)
{
LOGD("error :Buf");
return -1;
}
jbyteArray barr_Buf = (jbyteArray)env->CallObjectMethod(jvalueobject,jBuf_id,NULL);
jsize barr_Buf_size = env->GetArrayLength(barr_Buf);
jbyte* info_Buf = env->GetByteArrayElements(barr_Buf,0);
//LOGD("Buf:%s",info_Buf);
LOGD("barr_Buf_size:%d",barr_Buf_size);
/***********
//将上层传过来的value传到Module_Info中,每个模块用到的参数不同
***********/
//传给下层并且是视频流
if (info_Is_ToNext_Module == 1 &&
info_CodecType == CodecType_Video)
{
needlength ++;
pmodule_info[count_info].Is_ToNext_Module = 1;
//header
Module_HeaderInfo_FFmpeg_Video_Codec * pheaderinfo_ffmpeg_video_codec = NULL;
pheaderinfo_ffmpeg_video_codec = new Module_HeaderInfo_FFmpeg_Video_Codec();
pheaderinfo_ffmpeg_video_codec->stream_id = info_stream_id;
pmodule_info[count_info].ModuleHeaderInfo.HeaderInfo = pheaderinfo_ffmpeg_video_codec;
//StreamInfo
Module_StreamInfo * pmodulestreaminfo = NULL;
pmodulestreaminfo = new Module_StreamInfo();
pmodulestreaminfo->stream_id = info_stream_id;
pmodulestreaminfo->CodecType = (Stream_CodecType)info_CodecType;
pmodulestreaminfo->VideoInfo.PixFormat = (Stream_PixFormat)info_Stream_PixFormat;
pmodulestreaminfo->VideoInfo.Width = info_Width;
pmodulestreaminfo->VideoInfo.Height = info_Height;
pmodulestreaminfo->VideoCodecInfo.codec_format = (Stream_CodecFormat)info_codec_format;
pmodulestreaminfo->MuxInfo.mux_format = (Stream_MuxFormat)info_mux_format;
//查看需要在哪个info中填写pts dts
if(useinfotype == UseInfoType_Stream)
{
pmodulestreaminfo->VideoInfo.pts = info_pts;
pmodulestreaminfo->VideoInfo.dts = info_dts;
pmodulestreaminfo->VideoInfo.timebase_den = info_timebase_den;
pmodulestreaminfo->VideoInfo.timebase_num = info_timebase_num;
}
else if(useinfotype == UseInfoType_CodecDecode)
{
pmodulestreaminfo->VideoCodecInfo.pts = info_pts;
pmodulestreaminfo->VideoCodecInfo.dts = info_dts;
pmodulestreaminfo->VideoCodecInfo.timebase_den = info_timebase_den;
pmodulestreaminfo->VideoCodecInfo.timebase_num = info_timebase_num;
}
else if(useinfotype == UseInfoType_MuxDemux)
{
pmodulestreaminfo->MuxInfo.pts = info_pts;
pmodulestreaminfo->MuxInfo.dts = info_dts;
pmodulestreaminfo->MuxInfo.timebase_den = info_timebase_den;
pmodulestreaminfo->MuxInfo.timebase_num = info_timebase_num;
}
else
{
pmodulestreaminfo->VideoInfo.pts = info_pts;
pmodulestreaminfo->VideoInfo.dts = info_dts;
pmodulestreaminfo->VideoInfo.timebase_den = info_timebase_den;
pmodulestreaminfo->VideoInfo.timebase_num = info_timebase_num;
}
pmodulestreaminfo->BufLen = info_BufLen;
if(pmodulestreaminfo->Buf == NULL)
{
pmodulestreaminfo->Buf =(char *)calloc(pmodulestreaminfo->BufLen,sizeof(char));
}
memcpy(pmodulestreaminfo->Buf,info_Buf,info_ActualLen);
pmodulestreaminfo->ActualLen = info_ActualLen;
//如果用到的是StreamInfo_In
if(useModuleStreamInfo_In)
{
pmodule_info[count_info].ModuleStreamInfo_In = pmodulestreaminfo;
LOGD("useModuleStreamInfo_In");
}
//如果用到的是StreamInfo_Out
if(useModuleStreamInfo_Out)
{
pmodule_info[count_info].ModuleStreamInfo_Out = pmodulestreaminfo;
LOGD("useModuleStreamInfo_Out");
}
count_info ++;
}
//释放
env->ReleaseByteArrayElements(barr_Buf, info_Buf, 0);//释放资源
env->DeleteLocalRef(jkeyobject);
env->DeleteLocalRef(jintclass);
env->DeleteLocalRef(jvalueobject);
env->DeleteLocalRef(jvalueclass);
}
*Length = needlength;
*module_info = pmodule_info;
//释放
env->DeleteLocalRef(jmapclass);
env->DeleteLocalRef(jsetkey);
env->DeleteLocalRef(jsetclass);
env->DeleteLocalRef(jobjArray);
return 1;
}
//将本模块的c++用的Module_Info转化为参数jobj_Current(Hashmap)
static int Module_Info2Jobject(JNIEnv * env, jobject thiz,Module_Info * module_info,int Length,jobject jobj,
UseInfoType useinfotype)
{
int ret = 0;
//查看传进来的object是否是空
if (module_info == NULL)
{
LOGD("Module_Info2Jobject module_info == NULL");
return 1;
}
//生成object(hashmap)
jclass class_hashmap = env->GetObjectClass(jobj);
jmethodID HashMap_put_id = env->GetMethodID(class_hashmap, "put","(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
//查找要生成的vlaue类class
jclass class_LvsAndroidInfo = env->FindClass("com/android/lvs/lvsandroidinfo/LvsAndroidInfo");
if (class_LvsAndroidInfo == NULL)
{
LOGD("not found class_LvsAndroidInfo");
return -1;
}
else
{
LOGD("sucess found class_LvsAndroidInfo");
}
jclass class_LvsAndroidInfo_key = env->FindClass("java/lang/Integer");
if (class_LvsAndroidInfo_key == NULL)
{
LOGD("not found class_LvsAndroidInfo_key");
return -1;
}
else
{
LOGD("sucess found class_LvsAndroidInfo_key");
}
//生成map内容
for( int i=0; i < Length; i++)
{
int stream_id = ((Module_HeaderInfo_FFmpeg_Video_Codec *)(module_info[i].ModuleHeaderInfo.HeaderInfo))->stream_id;
LOGD("Module_HeaderInfo_FFmpeg_Video_Codec stream_id : %d",stream_id);
//key
LOGD("key");
jmethodID LvsAndroidInfo_key_id = env->GetMethodID(class_LvsAndroidInfo_key, "","(I)V"); //new这个key的id
jobject LvsAndroidInfo_keyobject = env->NewObject(class_LvsAndroidInfo_key,LvsAndroidInfo_key_id,stream_id); //new一个object
//value
LOGD("value");
jmethodID LvsAndroidInfo_id = env->GetMethodID(class_LvsAndroidInfo, "","()V"); //new这个class的id
jobject LvsAndroidInfoobject = env->NewObject(class_LvsAndroidInfo,LvsAndroidInfo_id, ""); //new一个object
//stream_id
jmethodID setstream_id_id = env->GetMethodID(class_LvsAndroidInfo, "setstream_id","(I)V");
if(setstream_id_id == NULL)
{
LOGD("error :setstream_id_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setstream_id_id,stream_id);
//Is_ToNext_Module
jmethodID setIs_ToNext_Module_id = env->GetMethodID(class_LvsAndroidInfo, "setIs_ToNext_Module","(I)V");
if(setIs_ToNext_Module_id == NULL)
{
LOGD("error :setIs_ToNext_Module_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setIs_ToNext_Module_id,module_info[i].Is_ToNext_Module);
//CodecType
jmethodID setCodecType_id = env->GetMethodID(class_LvsAndroidInfo, "setCodecType","(I)V");
if(setCodecType_id == NULL)
{
LOGD("error :setCodecType_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setCodecType_id,(int)module_info[i].ModuleStreamInfo_Out->CodecType);
//pts
jmethodID setpts_id = env->GetMethodID(class_LvsAndroidInfo, "setpts","(J)V");
if(setpts_id == NULL)
{
LOGD("error :setpts_id");
return NULL;
}
//dts
jmethodID setdts_id = env->GetMethodID(class_LvsAndroidInfo, "setdts","(J)V");
if(setdts_id == NULL)
{
LOGD("error :setdts_id");
return NULL;
}
//timebase_num
jmethodID settimebase_num_id = env->GetMethodID(class_LvsAndroidInfo, "settimebase_num","(I)V");
if(settimebase_num_id == NULL)
{
LOGD("error :settimebase_num_id");
return NULL;
}
//timebase_den
jmethodID settimebase_den_id = env->GetMethodID(class_LvsAndroidInfo, "settimebase_den","(I)V");
if(settimebase_den_id == NULL)
{
LOGD("error :settimebase_den_id");
return NULL;
}
//查看需要在哪个info中填写pts dts
if(useinfotype == UseInfoType_Stream)
{
env->CallVoidMethod(LvsAndroidInfoobject,setpts_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.pts);
env->CallVoidMethod(LvsAndroidInfoobject,setdts_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.dts);
env->CallVoidMethod(LvsAndroidInfoobject,settimebase_num_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.timebase_num);
env->CallVoidMethod(LvsAndroidInfoobject,settimebase_den_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.timebase_den);
}
else if(useinfotype == UseInfoType_CodecDecode)
{
env->CallVoidMethod(LvsAndroidInfoobject,setpts_id,module_info[i].ModuleStreamInfo_Out->VideoCodecInfo.pts);
env->CallVoidMethod(LvsAndroidInfoobject,setdts_id,module_info[i].ModuleStreamInfo_Out->VideoCodecInfo.dts);
env->CallVoidMethod(LvsAndroidInfoobject,settimebase_num_id,module_info[i].ModuleStreamInfo_Out->VideoCodecInfo.timebase_num);
env->CallVoidMethod(LvsAndroidInfoobject,settimebase_den_id,module_info[i].ModuleStreamInfo_Out->VideoCodecInfo.timebase_den);
}
else if(useinfotype == UseInfoType_MuxDemux)
{
env->CallVoidMethod(LvsAndroidInfoobject,setpts_id,module_info[i].ModuleStreamInfo_Out->MuxInfo.pts);
env->CallVoidMethod(LvsAndroidInfoobject,setdts_id,module_info[i].ModuleStreamInfo_Out->MuxInfo.dts);
env->CallVoidMethod(LvsAndroidInfoobject,settimebase_num_id,module_info[i].ModuleStreamInfo_Out->MuxInfo.timebase_num);
env->CallVoidMethod(LvsAndroidInfoobject,settimebase_den_id,module_info[i].ModuleStreamInfo_Out->MuxInfo.timebase_den);
}
else
{
env->CallVoidMethod(LvsAndroidInfoobject,setpts_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.pts);
env->CallVoidMethod(LvsAndroidInfoobject,setdts_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.dts);
env->CallVoidMethod(LvsAndroidInfoobject,settimebase_num_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.timebase_num);
env->CallVoidMethod(LvsAndroidInfoobject,settimebase_den_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.timebase_den);
}
//BufLen
jmethodID setBufLen_id = env->GetMethodID(class_LvsAndroidInfo, "setBufLen","(J)V");
if(setpts_id == NULL)
{
LOGD("error :setBufLen_id");
return NULL;
}
//这里一定故要用ModuleStreamInfo_In的buf长度,上层传过来的会比本层输出的buf大
env->CallVoidMethod(LvsAndroidInfoobject,setBufLen_id,module_info[i].ModuleStreamInfo_In->BufLen);
//ActualLen
jmethodID setActualLen_id = env->GetMethodID(class_LvsAndroidInfo, "setActualLen","(J)V");
if(setActualLen_id == NULL)
{
LOGD("error :setActualLen_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setActualLen_id,module_info[i].ModuleStreamInfo_Out->ActualLen);
//Buf
jmethodID setBuf_id = env->GetMethodID(class_LvsAndroidInfo, "setBuf","([B)V");
if(setBuf_id == NULL)
{
LOGD("error :setBuf_id");
return NULL;
}
jbyteArray bufbyteArray = env->NewByteArray(module_info[i].ModuleStreamInfo_Out->ActualLen);
env->SetByteArrayRegion(bufbyteArray,0,module_info[i].ModuleStreamInfo_Out->ActualLen,(const jbyte *)module_info[i].ModuleStreamInfo_Out->Buf);
env->CallVoidMethod(LvsAndroidInfoobject,setBuf_id,bufbyteArray);
//Stream_PixFormat
jmethodID setStream_PixFormat_id = env->GetMethodID(class_LvsAndroidInfo, "setStream_PixFormat","(I)V");
if(setStream_PixFormat_id == NULL)
{
LOGD("error :setStream_PixFormat_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setStream_PixFormat_id,(int)module_info[i].ModuleStreamInfo_Out->VideoInfo.PixFormat);
//Width
jmethodID setWidth_id = env->GetMethodID(class_LvsAndroidInfo, "setWidth","(I)V");
if(setWidth_id == NULL)
{
LOGD("error :setWidth_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setWidth_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.Width);
//Height
jmethodID setHeight_id = env->GetMethodID(class_LvsAndroidInfo, "setHeight","(I)V");
if(setHeight_id == NULL)
{
LOGD("error :setHeight_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setHeight_id,module_info[i].ModuleStreamInfo_Out->VideoInfo.Height);
//codec_format
jmethodID setcodec_format_id = env->GetMethodID(class_LvsAndroidInfo, "setcodec_format","(I)V");
if(setcodec_format_id == NULL)
{
LOGD("error :setcodec_format_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setcodec_format_id,(int)(module_info[i].ModuleStreamInfo_Out->VideoCodecInfo.codec_format));
//mux_format
jmethodID setmux_format_id = env->GetMethodID(class_LvsAndroidInfo, "setmux_format","(I)V");
if(setmux_format_id == NULL)
{
LOGD("error :setmux_format_id");
return NULL;
}
env->CallVoidMethod(LvsAndroidInfoobject,setmux_format_id,(int)module_info[i].ModuleStreamInfo_Out->MuxInfo.mux_format);
//调用hashmap put方法
env->CallObjectMethod(jobj,HashMap_put_id,LvsAndroidInfo_keyobject,LvsAndroidInfoobject);
//释放
env->DeleteLocalRef(LvsAndroidInfo_keyobject);
env->DeleteLocalRef(LvsAndroidInfoobject);
env->DeleteLocalRef(bufbyteArray);
}
//释放
env->DeleteLocalRef(class_hashmap);
env->DeleteLocalRef(class_LvsAndroidInfo);
env->DeleteLocalRef(class_LvsAndroidInfo_key);
return 1;
}
如有错误请指正: