1、
org.webrtc.examples.androidnativeapi E/rtc: #
# Fatal error in: I:\webrtc\android\androidnativeapi\app\src\main\cpp\androidcallclient.cc, line 182
# last system error: 2
# Check failed: (&thread_checker_)->IsCurrent()
#
2021-08-03 16:28:43.573 24948-24948/org.webrtc.examples.androidnativeapi A/libc: Fatal signal 6 (SIGABRT), code -6 (SI_TKILL) in tid 24948 (ndroidnativeapi), pid 24948 (ndroidnativeapi)
解决办法:是因为界面直接调用jni native函数导致,需要在主线程调用
handler.post(() -> {
nativeConnectToPeer(nativeClient,peerid);
});
2、
最近封装janus的websocket信令,发现CreateOffer后OnSuccess无法正常回调,查资料后发现,是因为创建PeerConnectionFactory时,传入的信令线程为空指针,如下:
bool Conductor::InitializePeerConnection() {
RTC_DCHECK(!peer_connection_factory_);
RTC_DCHECK(!peer_connection_);
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
nullptr /* network_thread */, nullptr /* worker_thread */,
nullptr /* signaling_thread */, nullptr /* default_adm */,
webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(),
webrtc::CreateBuiltinVideoEncoderFactory(),
webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
nullptr /* audio_processing */);
if (!peer_connection_factory_) {
main_wnd_->MessageBox("Error", "Failed to initialize PeerConnectionFactory",
true);
DeletePeerConnection();
return false;
}
if (!CreatePeerConnection(/*dtls=*/true)) {
main_wnd_->MessageBox("Error", "CreatePeerConnection failed", true);
DeletePeerConnection();
}
AddTracks();
return peer_connection_ != nullptr;
}
方法一:
把当前线程传到CreatePeerConnectionFactory工厂类
rtc::Thread *currentThread = rtc::Thread::Current();
if (!peer_connection_factory_) {
peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
nullptr /* network_thread */, nullptr /* worker_thread */,
currentThread /* signaling_thread */, nullptr /* default_adm */,
webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(),
webrtc::CreateBuiltinVideoEncoderFactory(),
webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
nullptr /* audio_processing */);
}
方法二:
创建网络,工作,信令三种线程传到CreatePeerConnectionFactory工厂类
network_thread_ = rtc::Thread::CreateWithSocketServer();
network_thread_->SetName("network_thread", nullptr);
RTC_CHECK(network_thread_->Start()) << "Failed to start thread";
worker_thread_ = rtc::Thread::Create();
worker_thread_->SetName("worker_thread", nullptr);
RTC_CHECK(worker_thread_->Start()) << "Failed to start thread";
signaling_thread_ = rtc::Thread::Create();
signaling_thread_->SetName("signaling_thread", nullptr);
RTC_CHECK(signaling_thread_->Start()) << "Failed to start thread";
pcf_ = webrtc::CreatePeerConnectionFactory(
network_thread_.get(),
worker_thread_.get(),
signaling_thread_.get(),
adm_,
webrtc::CreateBuiltinAudioEncoderFactory(),
webrtc::CreateBuiltinAudioDecoderFactory(),
webrtc::CreateBuiltinVideoEncoderFactory(),
webrtc::CreateBuiltinVideoDecoderFactory(),
nullptr /*audio_mixer*/,
nullptr /*audio_processing*/);
if (!pcf_)
{
MSC_THROW_ERROR("error ocurred creating peerconnection factory");
}
3、rtc::Thread*currentThread = rtc::Thread::Current() //currentThread=null;
必须先
rtc::ThreadManager::Instance()->WrapCurrentThread();
rtc::Thread*currentThread = rtc::Thread::Current();
4、
undefined reference to `typeinfo for rtc::LogSink'
undefined reference to `typeinfo for webrtc::VideoTrackSource
解决办法
开始以为就是符号找不到,怎么改都无果。而且报的都是类型未定义,不是具体方法未定义,都发生在类继承的时候。后发现是webrtc编译关了rtti,打开即可:
gn gen out/mybuild-m74 --args='is_debug=false is_component_build=false is_clang=false rtc_include_tests=false rtc_use_h264=true rtc_enable_protobuf=false use_rtti=true use_custom_libcxx=false treat_warnings_as_errors=false use_ozone=true'
5、
2022-02-18 14:49:31.484 17400-17694/org.webrtc.examples.androidnativeapi E/rtc: #
# Fatal error in: ../../modules/utility/source/jvm_android.cc, line 245
# last system error: 30
# Check failed: g_jvm
#
原因
jvm未初始化
解决方法,调用webrtc::JVM::Initialize,代码如下:
extern "C" jint JNIEXPORT JNICALL JNI_OnLoad(JavaVM* jvm, void* reserved) {
webrtc::InitAndroid(jvm);
webrtc::JVM::Initialize(jvm);
RTC_CHECK(rtc::InitializeSSL()) << "Failed to InitializeSSL()";
return JNI_VERSION_1_6;
}
extern "C" void JNIEXPORT JNICALL JNI_OnUnload(JavaVM* jvm, void* reserved) {
RTC_CHECK(rtc::CleanupSSL()) << "Failed to CleanupSSL()";
}
} // namespace webrtc_examples
6、
Program received signal SIGILL, Illegal instruction.
0x7956a3a8 in _armv7_tick () from /home/leith/dev/mapbox-gl-native-mason/build/android/out/Debug/lib.target/libmapbox-gl.so
(gdb) bt
#0 0x7956a3a8 in _armv7_tick () from /home/leith/dev/mapbox-gl-native-mason/build/android/out/Debug/lib.target/libmapbox-gl.so
#1 0x795d1ccc in OPENSSL_cpuid_setup () from /home/leith/dev/mapbox-gl-native-mason/build/android/out/Debug/lib.target/libmapbox-gl.so
#2 0x400bd9c6 in ?? () from /home/leith/dev/android/linker
#3 0x400bda9e in ?? () from /home/leith/dev/android/linker
#4 0x400bdbf0 in ?? () from /home/leith/dev/android/linker
#5 0x400bdc6e in ?? () from /home/leith/dev/android/linker
#6 0x400bc1a6 in _start () from /home/leith/dev/android/linker
#7 0x41643c86 in dvmLoadNativeCode(char const*, Object*, char**) () from /home/leith/dev/android/system_lib/libdvm.so
#8 0x416600f4 in ?? () from /home/leith/dev/android/system_lib/libdvm.so
#9 0x41613ee8 in dvmJitToInterpNoChain () from /home/leith/dev/android/system_lib/libdvm.so
#10 0x41613ee8 in dvmJitToInterpNoChain () from /home/leith/dev/android/system_lib/libdvm.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
一、按F9直接忽略继续
二、在androidstudio中设置
process handle --pass true --stop false --notify true SIGILL
7、
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:22: undefined reference to `webrtc::CreateSessionDescription(std::string const&, std::string const&, webrtc::SdpParseError*)'
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:24: undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
/home/test/workspace/testwebrtc/Debug/../src/testwebrtc.cpp:25: undefined reference to `rtc::FatalMessage::FatalMessage(char const*, int, std::string*)'
./src/testwebrtc.o: In function `rtc::CheckEqImpl(int, int, char const*)':
makefile:45: recipe for target 'testwebrtc' failed
/home/test/webrtc-checkout-ankur/src/out_release_62/include/webrtc/rtc_base/checks.h:176: undefined reference to `std::string* rtc::MakeCheckOpString(int const&, int const&, char const*)'
./src/testwebrtc.o: In function `rtc::CheckLtImpl(int, int, char const*)':
/home/test/webrtc-checkout-ankur/src/out_release_62/include/webrtc/rtc_base/checks.h:179: undefined reference to `std::string* rtc::MakeCheckOpString(int const&, int const&, char const*)'
collect2: error: ld returned 1 exit status
解决办法,webrtc编译参数加上
use_custom_libcxx=false
8、
Signal: SIGTRAP (signal SIGTRAP)
在jni开发时,调试时遇到Signal: SIGTRAP (signal SIGTRAP)导致程序老是卡在某几个语句,无法正常调试。
后来发现是由于,我的jni借口函数返回值为bool,而我在程序中为加入return 语句,即函数执行完毕后不能确定一定有true/false结果返回,修改后即可正常调试。