From 3667d3262bda2fba3895013dbfd7083dcf7ac6b3 Mon Sep 17 00:00:00 2001 From: wangjiyu Date: Thu, 10 Apr 2025 11:34:01 +0800 Subject: [PATCH] debug --- util/RTCContext.cpp | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/util/RTCContext.cpp b/util/RTCContext.cpp index a980b71..bdcb4f4 100644 --- a/util/RTCContext.cpp +++ b/util/RTCContext.cpp @@ -64,39 +64,30 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId, namespace py = boost::python; // 1. 获取 GIL(绝对必要) - py::gil_scoped_acquire gil; + PyGILState_STATE gstate = PyGILState_Ensure(); try { std::cout << "-----------------------------------" << std::endl; std::cout << "dataCount:" << audioFrame.dataCount << std::endl; - - // 2. 严格校验输入数据 if (!audioFrame.data || audioFrame.dataCount <= 0) { std::cerr << "Invalid audio frame data" << std::endl; + PyGILState_Release(gstate); return; } - std::cout << "step1" << std::endl; - // 3. 检查 NumPy API 状态(关键!) - if (PyArray_API == nullptr) { - std::cerr << "NumPy API not initialized" << std::endl; - return; - } + npy_intp dims[1] = {audioFrame.dataCount}; std::cout << "step2" << std::endl; - // 4. 安全创建 NumPy 数组(深拷贝方案) - npy_intp dims[1] = {audioFrame.dataCount}; - PyObject* pyArray = PyArray_SimpleNew(1, dims, NPY_INT16); // 创建新数组 - if (!pyArray) { - std::cerr << "Failed to create NumPy array" << std::endl; - return; - } + PyObject* pyArray = PyArray_SimpleNew(1, dims, NPY_INT16); std::cout << "step3" << std::endl; - - // 5. 拷贝数据(避免外部内存问题) - void* array_data = PyArray_DATA((PyArrayObject*)pyArray); + if (!pyArray) { + PyGILState_Release(gstate); + throw std::runtime_error("Failed to create NumPy array"); + } std::cout << "step4" << std::endl; - std::memcpy(array_data, audioFrame.data, audioFrame.dataCount * sizeof(int16_t)); + std::memcpy(PyArray_DATA((PyArrayObject*)pyArray), + audioFrame.data, + audioFrame.dataCount * sizeof(int16_t)); std::cout << "step5" << std::endl; // 6. 执行回调