libc: ../src/pj/os_core_unix.c:692: pj_thread_this: assertion "!"Calling pjlib from unknown/external
2016-07-26 11:37
597 查看
使用PjSip通信的时候,在切换用户的时候经常会报这个错,走过很多弯路,最后才发现是Java GC回收导致对象被销毁:
http://www.pjsip.org/docs/book-latest/html/intro_pjsua2.html#problems-with-garbage-collection
Garbage collection (GC) exists in Java and Python (and other languages, but we don’t support those for now), and there are some problems with it when it comes to PJSUA2 usage:
1.premature destruction of PJSUA2 objects which are created in Java and Python space and passed to the native space without keeping reference to the object
2.it delays the destruction of objects (including PJSUA2 objects), causing the code in object’s destructor to be executed out of order
3.the destruction operation by GC may run on different thread not previously registered to PJLIB, causing assertion
我们原先的消息发送是先添加好友,然后发送消息的时候直接选择好友,如下:
初始化好友:
发送消息:
后来我们发现发送消息的时候这样经常会报错
libc: ../src/pj/os_core_unix.c:692: pj_thread_this: assertion "!"Calling pjlib from unknown/external
所以我们根据文档改成了这样:
直接将初始化好友和发送消息集成到一个方法里,发送完消息后立刻将好友销毁,下次再发送消息的时候就重新初始化。换用这种方式后就再也没有遇到过之前的问题!希望能帮到你们!
http://www.pjsip.org/docs/book-latest/html/intro_pjsua2.html#problems-with-garbage-collection
Garbage collection (GC) exists in Java and Python (and other languages, but we don’t support those for now), and there are some problems with it when it comes to PJSUA2 usage:
1.premature destruction of PJSUA2 objects which are created in Java and Python space and passed to the native space without keeping reference to the object
2.it delays the destruction of objects (including PJSUA2 objects), causing the code in object’s destructor to be executed out of order
3.the destruction operation by GC may run on different thread not previously registered to PJLIB, causing assertion
我们原先的消息发送是先添加好友,然后发送消息的时候直接选择好友,如下:
初始化好友:
public static void initBuddy(final String buddyUri, final String userId) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { Log.e("will", "buddyUrl" + buddyUri); BuddyConfig bcfg = new BuddyConfig(); bcfg.setUri(buddyUri); try { buddy = account.addBuddy(bcfg); LogUtil.println(TAG + "initBuddy ", "buddy = " + buddy); addBuddyList(userId, buddy); Constants.userIdList.add(userId); buddy.subscribePresence(true); } catch (Exception e) { e.printStackTrace(); } } }); }
发送消息:
public void pjsipSendMsg(final String content, String userId) { SendInstantMessageParam prm = new SendInstantMessageParam(); prm.setContent(content); try { // myBuddy.create(account, bCfg); myBuddy.sendInstantMessage(prm); } catch (Exception e) { e.printStackTrace(); return; } }
后来我们发现发送消息的时候这样经常会报错
libc: ../src/pj/os_core_unix.c:692: pj_thread_this: assertion "!"Calling pjlib from unknown/external
所以我们根据文档改成了这样:
public void pjsipSendMsg(final String content, String userId) { if (userId == null || userId.equals("")){ userId = Constants.userId; } String buddy_uri = "<sip:" + userId + "@" + Constants.sipDomain + ";transport=tcp" + ">"; LogUtil.println(TAG + "pjsipSendMsg"," buddy_uri = " + buddy_uri); BuddyConfig bCfg = new BuddyConfig(); bCfg.setUri(buddy_uri); bCfg.setSubscribe(false); MyBuddy myBuddy = account.addBuddy(bCfg); SendInstantMessageParam prm = new SendInstantMessageParam(); prm.setContent(content); try { // myBuddy.create(account, bCfg); myBuddy.sendInstantMessage(prm); myBuddy.delete(); } catch (Exception e) { e.printStackTrace(); return; } }
直接将初始化好友和发送消息集成到一个方法里,发送完消息后立刻将好友销毁,下次再发送消息的时候就重新初始化。换用这种方式后就再也没有遇到过之前的问题!希望能帮到你们!
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories