diff --git a/rtc_plugins.cpp b/rtc_plugins.cpp index 1bf2007..0558977 100644 --- a/rtc_plugins.cpp +++ b/rtc_plugins.cpp @@ -58,6 +58,7 @@ py::object create_int16_array() { // 4. 转换为 py::object(自动管理引用计数) return py::object(py::handle<>(py_array)); } + int sendCustomAudioData(int16_t destChannelIndex, py::object pD, int32_t sampleRate, uint64_t channelNum, uint64_t dataLen) { try { @@ -71,10 +72,12 @@ int sendCustomAudioData(int16_t destChannelIndex, py::object pD, throw std::runtime_error("Failed to convert input to int16 array"); } - py::object arr = py::handle<>(py_array); - PyArrayObject* npArray = reinterpret_cast(arr.ptr()); + // 修复点:显式构造 py::object(两种写法均可) + py::object arr(py::handle<>(py_array)); // 写法1:构造函数 + // py::object arr = py::reinterpret_borrow(py_array); // 写法2:borrow语义 // 检查数据长度 + PyArrayObject* npArray = reinterpret_cast(arr.ptr()); if (PyArray_SIZE(npArray) != static_cast(dataLen)) { throw std::runtime_error("Array length does not match dataLen"); } @@ -89,6 +92,7 @@ int sendCustomAudioData(int16_t destChannelIndex, py::object pD, return -1; } } + /* int sendCustomAudioData(const int16_t destChannelIndex, py::object pyData, int32_t sampleRate, uint64_t channelNum, uint64_t dataLen) {