From 6f24ab51059d1567fa5c4b444426f70ceb972483 Mon Sep 17 00:00:00 2001 From: wangjiyu Date: Wed, 16 Apr 2025 11:26:13 +0800 Subject: [PATCH] debug --- util/RTCContext.cpp | 146 ++++++++++++++++++++++---------------------- 1 file changed, 72 insertions(+), 74 deletions(-) diff --git a/util/RTCContext.cpp b/util/RTCContext.cpp index 20a06b1..1381a4a 100644 --- a/util/RTCContext.cpp +++ b/util/RTCContext.cpp @@ -372,81 +372,79 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId, std::cout << " 数据拷贝完成" << std::endl; // 7. 执行回调 - if (!pyCallback_.is_none()) { - std::cout << "[7] 准备执行Python回调..." << std::endl; - // 增加引用计数防止提前释放 - Py_INCREF(pyCallback_.ptr()); - try { - std::cout << " pyCallback_ type: " << Py_TYPE(pyCallback_.ptr())->tp_name << std::endl; - PyObject* repr = PyObject_Repr(pyCallback_.ptr()); - if (repr) { - std::cout << " pyCallback_ repr: " << PyUnicode_AsUTF8(repr) << std::endl; - Py_DECREF(repr); // 必须手动释放 - } - // 传递共享内存信息 - /* - pyCallback_( - py::str(shm_name), // 共享内存名称 - data_size, // 数据大小 - audioFrame.dataCount, - audioFrame.sampleRate, - audioFrame.numChannels, - audioFrame.channelIndex - ); - */ - /* - pyCallback_( - audioArray, // numpy 数组 - data_size, // 数据大小 - audioFrame.dataCount, - audioFrame.sampleRate, - audioFrame.numChannels, - audioFrame.channelIndex - ); - */ - std::cout << " after callback" << std::endl; - if (PyErr_Occurred()) { - PyObject *type, *value, *traceback; - PyErr_Fetch(&type, &value, &traceback); - if (value) { - PyObject* str = PyObject_Str(value); - if (str) { - std::cerr << "Python Error: " << PyUnicode_AsUTF8(str) << std::endl; - Py_DECREF(str); - } - } - Py_XDECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); - //PyErr_Print(); - throw std::runtime_error("Python callback error"); - } - std::cout << " 回调执行成功" << std::endl; + //if (!pyCallback_.is_none()) { + // std::cout << "[7] 准备执行Python回调..." << std::endl; + // // 增加引用计数防止提前释放 + // Py_INCREF(pyCallback_.ptr()); + // try { + // std::cout << " pyCallback_ type: " << Py_TYPE(pyCallback_.ptr())->tp_name << std::endl; + // PyObject* repr = PyObject_Repr(pyCallback_.ptr()); + // if (repr) { + // std::cout << " pyCallback_ repr: " << PyUnicode_AsUTF8(repr) << std::endl; + // Py_DECREF(repr); // 必须手动释放 + // } + // // 传递共享内存信息 + // pyCallback_( + // py::str(shm_name), // 共享内存名称 + // data_size, // 数据大小 + // audioFrame.dataCount, + // audioFrame.sampleRate, + // audioFrame.numChannels, + // audioFrame.channelIndex + // ); + // /* + // pyCallback_( + // audioArray, // numpy 数组 + // data_size, // 数据大小 + // audioFrame.dataCount, + // audioFrame.sampleRate, + // audioFrame.numChannels, + // audioFrame.channelIndex + // ); + // */ + // std::cout << " after callback" << std::endl; + // if (PyErr_Occurred()) { + // PyObject *type, *value, *traceback; + // PyErr_Fetch(&type, &value, &traceback); + // if (value) { + // PyObject* str = PyObject_Str(value); + // if (str) { + // std::cerr << "Python Error: " << PyUnicode_AsUTF8(str) << std::endl; + // Py_DECREF(str); + // } + // } + // Py_XDECREF(type); + // Py_XDECREF(value); + // Py_XDECREF(traceback); + // //PyErr_Print(); + // throw std::runtime_error("Python callback error"); + // } + // std::cout << " 回调执行成功" << std::endl; - } catch (const py::error_already_set& e) { - std::cerr << "[PYTHON ERROR] "; - PyErr_Print(); // 自动打印到stderr - // 可选:获取更详细的错误信息 - if (PyErr_Occurred()) { - PyObject *type, *value, *traceback; - PyErr_Fetch(&type, &value, &traceback); - std::cerr << "Details: " - << PyUnicode_AsUTF8(PyObject_Str(value)) << std::endl; - PyErr_Restore(type, value, traceback); - } - Py_DECREF(pyCallback_.ptr()); - } catch (...) { - std::cout << "[ERROR] 回调执行失败" << std::endl; - munmap(ptr, data_size); - close(fd); - shm_unlink(shm_name); - Py_DECREF(pyCallback_.ptr()); - throw; - } - Py_DECREF(pyCallback_.ptr()); - } else { - std::cout << "[7] 无回调函数设置" << std::endl; - } + // } catch (const py::error_already_set& e) { + // std::cerr << "[PYTHON ERROR] "; + // PyErr_Print(); // 自动打印到stderr + // // 可选:获取更详细的错误信息 + // if (PyErr_Occurred()) { + // PyObject *type, *value, *traceback; + // PyErr_Fetch(&type, &value, &traceback); + // std::cerr << "Details: " + // << PyUnicode_AsUTF8(PyObject_Str(value)) << std::endl; + // PyErr_Restore(type, value, traceback); + // } + // Py_DECREF(pyCallback_.ptr()); + // } catch (...) { + // std::cout << "[ERROR] 回调执行失败" << std::endl; + // munmap(ptr, data_size); + // close(fd); + // shm_unlink(shm_name); + // Py_DECREF(pyCallback_.ptr()); + // throw; + // } + // Py_DECREF(pyCallback_.ptr()); + //} else { + // std::cout << "[7] 无回调函数设置" << std::endl; + //} // 8. 释放资源 std::cout << "[8] 释放共享内存资源..." << std::endl;