libc: ../src/pj/os_core_unix.c:692: pj_thread_this: assertion "!"Calling pjlib from unknown/external
来源:互联网 发布:长沙麻将源码 编辑:程序博客网 时间:2024/06/05 11:59
使用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
我们原先的消息发送是先添加好友,然后发送消息的时候直接选择好友,如下:
初始化好友:
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; }}直接将初始化好友和发送消息集成到一个方法里,发送完消息后立刻将好友销毁,下次再发送消息的时候就重新初始化。换用这种方式后就再也没有遇到过之前的问题!希望能帮到你们!
- libc: ../src/pj/os_core_unix.c:692: pj_thread_this: assertion "!"Calling pjlib from unknown/external
- Calling pjlib from unknown/external thread
- Calling Ruby From C
- Calling C Programs from IDL
- opencv error:assertion failed<src.cols>0&&src.rows>0>in unknown function
- Calling C From Java Is Easy
- chapter 27 Calling C from Lua
- calling lua from c in linux
- Calling Haskell from C - (DLL solution)
- Calling C and C++ from IDL (一)
- Calling C/C++ functions from C#
- Calling C Code From Mono/.NET
- dbgheap.c From vc/crt/src/*.c
- C++PJ智能指针
- Calling C++ Functions From Lua(lua调用c/c++)
- Calling CUDA program from C/C++ project
- pjlib中的list用法,节点采用pj内存池动态创建
- Calling Pro*C program from a package", version 8.0.5
- 完整框架下载地址ssm
- Qt设置全局的widget的stylesheet
- VC中CListCtrl使用技巧(部分转载)
- .net 操作Excel
- 内联与宏
- libc: ../src/pj/os_core_unix.c:692: pj_thread_this: assertion "!"Calling pjlib from unknown/external
- The following classes could not be found: - android.support.v7.internal.app.WindowDecorActionBar (Fi
- 判断应用程序是否在前台
- SpringBoot启用HTTPS协议
- 排序算法之桶排序
- C++网络摄像头数据的获取与显示 (续)
- iOS开发多线程atomic nonatomic区别
- 【Python学习】python+Eclipse+pydev环境搭建
- Fill-rate,Canvases and input 填充率,画布和输入—(Unity3d)