阅读 81

android和底层sdk的交互(c++)

1.通过JNINative里面的方法调用java接口:

     * 加入会议(ok)
     *
     * @param joinConfObject
     * @param userInfoObject
     * @param srDeviceInfoList //音视频设备信息
     * @param isMute
     * @return OnRspJoinConfCallBack
     */
    public native static int reqestJoinConf(SRSdkConferenceInfo joinConfObject,
                                            SRUserInfo userInfoObject,
                                            List<SRDeviceInfo> srDeviceInfoList,
                                            boolean isMute, boolean isV3, int termtype);
复制代码

2.在SRSdkJni.h中修改主调接口:

JNIEXPORT jint
JNICALL Java_org_suirui_srpaas_jni_JniNative_reqestJoinConf(JNIEnv *env, jclass jcls,
                                                            jobject joinConfObject,
                                                            jobject userInfoObject,
                                                            jobject srDeviceInfoList,
                                                            jboolean isMute, jboolean isV3,
                                                            jint termtype,jint mtu_size);
复制代码

3.在RSdkJni.cpp中进行参数的赋值和c++方法的调用:

JNIEXPORT jint
JNICALL Java_org_suirui_srpaas_jni_JniNative_reqestJoinConf(JNIEnv *env, jclass jcls,
                                                            jobject joinConfObject,
                                                            jobject userInfoObject,
                                                            jobject srDeviceInfoList,
                                                            jboolean isMute, jboolean isV3,
                                                            jint termtype,jint mtu_size) {
#if defined(LOG_JNI)
    Log("SRSdkJni...reqestJoinConf..");
#endif
    McInfo mcInfo;
    UserInfo userInfo;
    ConfInfo confInfo;

     std::list<SRDeviceInfo> deviceInfosList;
     if(srDeviceInfoList!=NULL){
         int i;
         jclass cls_arraylist = env->GetObjectClass(srDeviceInfoList);
         jmethodID arraylist_get = env->GetMethodID(cls_arraylist, "get", "(I)Ljava/lang/Object;");
         jmethodID arraylist_size = env->GetMethodID(cls_arraylist, "size", "()I");
         jint len = env->CallIntMethod(srDeviceInfoList, arraylist_size);
         //Log("SRSdkJni...testSRDeviceInfo..len:%d",len);
         for (i = 0; i < len; i++) {
           jobject obj_deviceInfo = env->CallObjectMethod(srDeviceInfoList, arraylist_get, i);
           jclass cls_deviceInfo = env->GetObjectClass(obj_deviceInfo);
           jmethodID getTypeId = env->GetMethodID(cls_deviceInfo, "getType", "()I");
           jint device_type = env->CallIntMethod(obj_deviceInfo, getTypeId);
           jfieldID srSourceInfosID = env->GetFieldID(cls_deviceInfo,"srSourceInfos","Ljava/util/List;");
           jobject srSourceObject_list = env->GetObjectField(obj_deviceInfo, srSourceInfosID);
            std::list<SRSourceInfo> sourceInfosList;
             if (srSourceObject_list != NULL) {
                 int j;
                 jclass cls_sourceInfoList = env->GetObjectClass(srSourceObject_list);
                 jmethodID sourceinfo_method = env->GetMethodID(cls_sourceInfoList, "get", "(I)Ljava/lang/Object;");
                 jmethodID sourceInfoList_size = env->GetMethodID(cls_sourceInfoList, "size", "()I");
                 jint sourceListLen = env->CallIntMethod(srSourceObject_list, sourceInfoList_size);
                 //Log("SRSdkJni...reqestJoinConf..getSrSourceInfos.length=%d",sourceListLen);
                 for (j = 0; j< sourceListLen; j++) {
                        jobject obj_sourceInfo = env->CallObjectMethod(srSourceObject_list, sourceinfo_method, j);
                        jclass cls_sourceInfo= env->GetObjectClass(obj_sourceInfo);
                        jmethodID getsrcid_id = env->GetMethodID(cls_sourceInfo, "getSrcid", "()I");
                        jmethodID getName_id = env->GetMethodID(cls_sourceInfo, "getName", "()Ljava/lang/String;");
                        jmethodID getPriority_id = env->GetMethodID(cls_sourceInfo, "getPriority", "()I");
                        jmethodID getisOnLive_id = env->GetMethodID(cls_sourceInfo, "getIsOnLive", "()Z");
                         jint srcid_id = env->CallIntMethod(obj_sourceInfo, getsrcid_id);
                         jint Priority_id = env->CallIntMethod(obj_sourceInfo, getPriority_id);
                         jstring name_id = (jstring)env->CallObjectMethod(obj_sourceInfo, getName_id);
                         jboolean isOnLive_id = env->CallBooleanMethod(obj_sourceInfo, getisOnLive_id);
                         Log("SRSdkJni...reqestJoinConf....55.。。srcid_id:%d, name_id:%s,Priority_id:%d..isOnLive_id:%d",srcid_id,(jstringTostring(env, name_id)).c_str(),Priority_id,isOnLive_id);
                         SRSourceInfo srSourceInfo;
                         srSourceInfo.srcid=srcid_id;
                        if(name_id!=NULL){
                          srSourceInfo.name=jstringTostring(env, name_id);
                        }
                        srSourceInfo.priority=Priority_id;
                        srSourceInfo.isOnLive=isOnLive_id;
                        Log("SRSdkJni...reqestJoinConf..sourceInfosList111=====.srcid=%d,priority=%d,isOnLive=%d",srSourceInfo.srcid,srSourceInfo.priority,srSourceInfo.isOnLive);
                        sourceInfosList.push_back(srSourceInfo);
                 }
             }
            SRDeviceInfo deviceInfo;
            deviceInfo.type = SR_DEVICETYPE(device_type);
            deviceInfo.srcinfos=sourceInfosList;
            //Log("SRSdkJni...reqestJoinConf..deviceInfosList222=====.type=%d", deviceInfo.type);
            deviceInfosList.push_back(deviceInfo);
        }
    }
    SRRtcEngineJoinConfContext context = makeJoinConfContext(env, jcls, joinConfObject,
                                                             userInfoObject, mcInfo,
                                                             userInfo, confInfo, deviceInfosList,
                                                             isMute, true, isV3,termtype,mtu_size);
    return gSdk->ReqJoinConf(context);
}
复制代码

4.sdk那边ISRRtcEngine.h给回调方法:

            * 加入会议的回调
            * @param [in] isok
            *        是否加入会议ok
            * @param [in] error
            *        如果失败, 失败错误类
            * @param [in] stermid
            *        返回当前对应的stermid
            */
			virtual void OnRspJoinConf(const bool isok, const SRConferenceAbnormal & error, const int stermid, GroupMeetingRoomInfo &gmrinfo)
            {
                (void)isok;
                (void)error;
				(void)stermid;
				(void)gmrinfo;
            }
复制代码

5.反到 SRSdkJni.h的回调中:

void OnRspJoinConfCallBack_JNI(const bool isok, const SRConferenceAbnormal &error,
                               const int stermid,GroupMeetingRoomInfo &gmrinfo);
复制代码

6.SRSdkJni.cpp中进行数据转换:

void OnRspJoinConfCallBack_JNI(const bool isok, const SRConferenceAbnormal &error,
                               const int stermid,GroupMeetingRoomInfo &gmrinfo) {

#if defined(LOG_JNI)
    Log("SRSdkJni:...OnRspJoinConfCallBack_JNI......__%d______%d",isok,stermid);
#endif
    int needsDetach;
    JNIEnv *env = getJNIEnv(&needsDetach);
    //解析SRConferenceAbnormal
    jmethodID info_method = env->GetMethodID(SRError_class, "<init>", "()V");
    jobject error_obj = env->NewObject(SRError_class, info_method, "");
    jobject info = errorStruct(env, error, error_obj);
    //解析GroupMeetingRoomInfo
    jmethodID roomInfo_method = env->GetMethodID(srGMRoomInfo_class, "<init>", "()V");
    jobject roomInfo_obj = env->NewObject(srGMRoomInfo_class, roomInfo_method, "");
    jobject roomInfo = GMeetingRoomInfo(env, gmrinfo,roomInfo_obj);
    if (Callback_class != NULL) {
        jmethodID Callback_method = env->GetMethodID(Callback_class, "<init>",
                                                     "()V");
        jobject obj_qtt = env->NewObject(Callback_class, Callback_method, "");
        jmethodID gJinMethod = env->GetMethodID(Callback_class,
                                                "OnRspJoinConfCallBack",
                                                "(ZLorg/suirui/srpaas/entry/SRError;ILorg/suirui/srpaas/entry/GroupMeetingRoomInfo;)V");
        env->CallVoidMethod(obj_qtt, gJinMethod, isok, info,stermid,roomInfo);
        env->DeleteLocalRef(obj_qtt);
        env->DeleteLocalRef(error_obj);
        env->DeleteLocalRef(roomInfo_obj);
    }
        Log("SRSdkJni:...OnRspJoinConfCallBack_JNI......__isok=%d______stermid=%d____needsDetach=%d", isok, stermid,needsDetach);
        gs_jvm->DetachCurrentThread();
}
复制代码

7.回调到java层的callback中:

     * 入会状态回调(new)
     *
     * @param status  1:success   0:fail
     * @param srError status=false失败原因
     * @param sTermId 入会状态回调
     */
    void OnRspJoinConfCallBack(boolean status, SRError srError, int sTermId, GroupMeetingRoomInfo roomInfo) {
        log.E("OnRspJoinConfCallBack..入会状态回调...." + status + " sTermId:" + sTermId);
        if (roomInfo != null) {
            log.E("OnRspJoinConfCallBack..入会状态回调....conf_domain:" + roomInfo.getM_conf_domain() + "  confid:" + roomInfo.getM_confid()
                    + "  gmrid:" + roomInfo.getM_gmrid() + "  gmrtype:" + roomInfo.getM_gmrtype() + "  gmrname:" + roomInfo.getM_gmrname());
        }
        SdkCallBack.getInstance().OnRspJoinConfCallBack(status, srError, sTermId, roomInfo);
    }
复制代码
文章分类
Android
文章标签