From 4c50a1b4b75a574c9d572a9c5103af0e164e1a52 Mon Sep 17 00:00:00 2001 From: wangjiyu Date: Fri, 11 Apr 2025 08:50:11 +0800 Subject: [PATCH] debug --- util/RTCContext.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/RTCContext.cpp b/util/RTCContext.cpp index 9a7e2c0..9db77ce 100644 --- a/util/RTCContext.cpp +++ b/util/RTCContext.cpp @@ -336,6 +336,9 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId, if (!pyCallback_.is_none()) { std::cout << "[7] 准备执行Python回调..." << std::endl; try { + // 增加引用计数防止提前释放 + Py_INCREF(pyCallback_.ptr()); + std::cout << " py incr" << std::endl; // 传递共享内存信息 pyCallback_( py::str(shm_name), // 共享内存名称 @@ -345,7 +348,13 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId, audioFrame.numChannels, audioFrame.channelIndex ); + std::cout << " after callback" << std::endl; + if (PyErr_Occurred()) { + PyErr_Print(); + throw std::runtime_error("Python callback error"); + } std::cout << " 回调执行成功" << std::endl; + } catch (...) { std::cout << "[ERROR] 回调执行失败" << std::endl; munmap(ptr, data_size);