debug
This commit is contained in:
parent
9d53a7156f
commit
3667d3262b
|
@ -64,39 +64,30 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
|
||||||
namespace py = boost::python;
|
namespace py = boost::python;
|
||||||
|
|
||||||
// 1. 获取 GIL(绝对必要)
|
// 1. 获取 GIL(绝对必要)
|
||||||
py::gil_scoped_acquire gil;
|
PyGILState_STATE gstate = PyGILState_Ensure();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::cout << "-----------------------------------" << std::endl;
|
std::cout << "-----------------------------------" << std::endl;
|
||||||
std::cout << "dataCount:" << audioFrame.dataCount << std::endl;
|
std::cout << "dataCount:" << audioFrame.dataCount << std::endl;
|
||||||
|
|
||||||
// 2. 严格校验输入数据
|
|
||||||
if (!audioFrame.data || audioFrame.dataCount <= 0) {
|
if (!audioFrame.data || audioFrame.dataCount <= 0) {
|
||||||
std::cerr << "Invalid audio frame data" << std::endl;
|
std::cerr << "Invalid audio frame data" << std::endl;
|
||||||
|
PyGILState_Release(gstate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "step1" << std::endl;
|
std::cout << "step1" << std::endl;
|
||||||
// 3. 检查 NumPy API 状态(关键!)
|
npy_intp dims[1] = {audioFrame.dataCount};
|
||||||
if (PyArray_API == nullptr) {
|
|
||||||
std::cerr << "NumPy API not initialized" << std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << "step2" << std::endl;
|
std::cout << "step2" << std::endl;
|
||||||
// 4. 安全创建 NumPy 数组(深拷贝方案)
|
PyObject* pyArray = PyArray_SimpleNew(1, dims, NPY_INT16);
|
||||||
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;
|
|
||||||
}
|
|
||||||
std::cout << "step3" << std::endl;
|
std::cout << "step3" << std::endl;
|
||||||
|
if (!pyArray) {
|
||||||
// 5. 拷贝数据(避免外部内存问题)
|
PyGILState_Release(gstate);
|
||||||
void* array_data = PyArray_DATA((PyArrayObject*)pyArray);
|
throw std::runtime_error("Failed to create NumPy array");
|
||||||
|
}
|
||||||
std::cout << "step4" << std::endl;
|
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;
|
std::cout << "step5" << std::endl;
|
||||||
|
|
||||||
// 6. 执行回调
|
// 6. 执行回调
|
||||||
|
|
Loading…
Reference in New Issue