debug
This commit is contained in:
parent
c8e5a8d996
commit
99f6c1fce3
|
@ -73,33 +73,42 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
|
||||||
|
|
||||||
|
|
||||||
auto numpyApi = RTCContext::numpy_api();
|
auto numpyApi = RTCContext::numpy_api();
|
||||||
|
std::cout << "step1" << std::endl;
|
||||||
if (!numpyApi) {
|
if (!numpyApi) {
|
||||||
PyGILState_Release(gstate);
|
PyGILState_Release(gstate);
|
||||||
throw std::runtime_error("NumPy C-API not initialized. Call import_array() in module init");
|
throw std::runtime_error("NumPy C-API not initialized. Call import_array() in module init");
|
||||||
}
|
}
|
||||||
|
std::cout << "step2" << std::endl;
|
||||||
using PyArray_SimpleNew_t = PyObject*(*)(int, npy_intp*, int);
|
using PyArray_SimpleNew_t = PyObject*(*)(int, npy_intp*, int);
|
||||||
|
std::cout << "step3" << std::endl;
|
||||||
auto PyArray_SimpleNew = reinterpret_cast<PyArray_SimpleNew_t>(numpy_api[93]);
|
auto PyArray_SimpleNew = reinterpret_cast<PyArray_SimpleNew_t>(numpy_api[93]);
|
||||||
|
std::cout << "step4" << std::endl;
|
||||||
|
|
||||||
// 3. 严格校验输入数据
|
// 3. 严格校验输入数据
|
||||||
if (!audioFrame.data || audioFrame.dataCount <= 0) {
|
if (!audioFrame.data || audioFrame.dataCount <= 0) {
|
||||||
PyGILState_Release(gstate);
|
PyGILState_Release(gstate);
|
||||||
throw std::invalid_argument("Invalid audio frame data");
|
throw std::invalid_argument("Invalid audio frame data");
|
||||||
}
|
}
|
||||||
|
std::cout << "step5" << std::endl;
|
||||||
|
|
||||||
// 4. 安全创建维度数组(带边界检查)
|
// 4. 安全创建维度数组(带边界检查)
|
||||||
if (audioFrame.dataCount > std::numeric_limits<npy_intp>::max()) {
|
if (audioFrame.dataCount > std::numeric_limits<npy_intp>::max()) {
|
||||||
PyGILState_Release(gstate);
|
PyGILState_Release(gstate);
|
||||||
throw std::overflow_error("Audio frame size exceeds maximum limit");
|
throw std::overflow_error("Audio frame size exceeds maximum limit");
|
||||||
}
|
}
|
||||||
|
std::cout << "step6" << std::endl;
|
||||||
npy_intp dims[1] = {static_cast<npy_intp>(audioFrame.dataCount)};
|
npy_intp dims[1] = {static_cast<npy_intp>(audioFrame.dataCount)};
|
||||||
|
|
||||||
|
std::cout << "step7" << std::endl;
|
||||||
// 5. 创建NumPy数组(带内存保护)
|
// 5. 创建NumPy数组(带内存保护)
|
||||||
PyObject* pyArray = nullptr;
|
PyObject* pyArray = nullptr;
|
||||||
pyArray = PyArray_SimpleNew(1, dims, NPY_INT16);
|
pyArray = PyArray_SimpleNew(1, dims, NPY_INT16);
|
||||||
|
std::cout << "step8" << std::endl;
|
||||||
if (!pyArray) {
|
if (!pyArray) {
|
||||||
PyGILState_Release(gstate);
|
PyGILState_Release(gstate);
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
}
|
}
|
||||||
|
std::cout << "step9" << std::endl;
|
||||||
|
|
||||||
// 6. 安全拷贝数据(带对齐检查)
|
// 6. 安全拷贝数据(带对齐检查)
|
||||||
if (reinterpret_cast<uintptr_t>(audioFrame.data) % alignof(int16_t) != 0) {
|
if (reinterpret_cast<uintptr_t>(audioFrame.data) % alignof(int16_t) != 0) {
|
||||||
|
@ -107,10 +116,12 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
|
||||||
PyGILState_Release(gstate);
|
PyGILState_Release(gstate);
|
||||||
throw std::runtime_error("Unaligned audio data pointer");
|
throw std::runtime_error("Unaligned audio data pointer");
|
||||||
}
|
}
|
||||||
|
std::cout << "step10" << std::endl;
|
||||||
std::memcpy(PyArray_DATA(reinterpret_cast<PyArrayObject*>(pyArray)),
|
std::memcpy(PyArray_DATA(reinterpret_cast<PyArrayObject*>(pyArray)),
|
||||||
audioFrame.data,
|
audioFrame.data,
|
||||||
audioFrame.dataCount * sizeof(int16_t));
|
audioFrame.dataCount * sizeof(int16_t));
|
||||||
|
|
||||||
|
std::cout << "step11" << std::endl;
|
||||||
// 7. 执行回调(带引用计数保护)
|
// 7. 执行回调(带引用计数保护)
|
||||||
if (!py_callback_.is_none()) {
|
if (!py_callback_.is_none()) {
|
||||||
try {
|
try {
|
||||||
|
@ -126,10 +137,13 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
|
||||||
throw; // 重新抛出异常
|
throw; // 重新抛出异常
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
std::cout << "step12" << std::endl;
|
||||||
|
|
||||||
// 8. 释放资源
|
// 8. 释放资源
|
||||||
Py_DECREF(pyArray);
|
Py_DECREF(pyArray);
|
||||||
|
std::cout << "step13" << std::endl;
|
||||||
PyGILState_Release(gstate);
|
PyGILState_Release(gstate);
|
||||||
|
std::cout << "step14" << std::endl;
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
std::cerr << "Audio process error: " << e.what() << std::endl;
|
std::cerr << "Audio process error: " << e.what() << std::endl;
|
||||||
|
|
Loading…
Reference in New Issue