This commit is contained in:
wangjiyu 2025-04-15 19:39:53 +08:00
parent 5179cc5aa7
commit 3dd6a84c5d
1 changed files with 9 additions and 4 deletions

View File

@ -71,7 +71,9 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
// 1. 获取GIL
std::cout << "[1] 获取GIL锁..." << std::endl;
#ifdef GIL
PyGILState_STATE gstate = PyGILState_Ensure();
//PyGILState_STATE gstate = PyGILState_Ensure();
Py_BEGIN_ALLOW_THREADS
Py_END_ALLOW_THREADS
#endif
try {
@ -187,19 +189,22 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
std::cout << "[9] 释放GIL..." << std::endl;
#ifdef GIL
PyGILState_Release(gstate);
//PyGILState_Release(gstate);
Py_BEGIN_ALLOW_THREADS
#endif
std::cout << "=== 音频处理完成 ===" << std::endl;
} catch (const std::exception& e) {
std::cout << "[EXCEPTION] 异常捕获: " << e.what() << std::endl;
#ifdef GIL
PyGILState_Release(gstate);
//PyGILState_Release(gstate);
Py_BEGIN_ALLOW_THREADS
#endif
std::cerr << "Audio process error: " << e.what() << std::endl;
}
#ifdef GIL
PyGILState_Release(gstate);
//PyGILState_Release(gstate);
Py_BEGIN_ALLOW_THREADS
#endif
}