|
1,java 代码 结构体定义 public class MediaInfo { public int nWidth; public int nHeight; public String strStream; }
java jni接口定义 public native static int GetMediaInfo(int handle, MediaInfo info); //? c++ ndk 实现代码 JNIEXPORT jint JNICALL Java_src_jni_RtspConnect_GetMediaInfo (JNIEnv *e, jclass c, jint h, jobject o) { //获取Java中的实例类 jclass objectClass = (e)->FindClass("src/jni/MediaInfo"); //获取类中每一个变量的定义 jfieldID strStream = (e)->GetFieldID(objectClass, "strStream", "Ljava/lang/String;"); jfieldID nHeight = (e)->GetFieldID(objectClass, "nHeight", "I"); jfieldID nWidth = (e)->GetFieldID(objectClass, "nWidth", "I"); //给每一个实例的变量付值 (e)->SetIntField(o, nHeight, 10); (e)->SetIntField(o, nWidth, 100); (e)->SetObjectField(o, strStream, (e)->NewStringUTF("my stream")); return 0; }
Java 调用 MediaInfo info = new MediaInfo(); RtspConnect.GetMediaInfo(0, info); Log.i("info", ""+info.nHeight); Log.i("info", ""+info.nWidth); Log.i("info", ""+info.strStream);
|