debug
This commit is contained in:
parent
29f14acd5f
commit
9ef5758116
|
@ -51,6 +51,10 @@ int getSize() {
|
||||||
return RTCContext::instance().getSize();
|
return RTCContext::instance().getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace np = boost::python::numpy;
|
||||||
|
np::ndarray getNumpydata() {
|
||||||
|
return RTCContext::instance().getNumpydata();
|
||||||
|
}
|
||||||
py::object create_int16_array() {
|
py::object create_int16_array() {
|
||||||
// 1. 定义数组维度(1维,长度为 4)
|
// 1. 定义数组维度(1维,长度为 4)
|
||||||
npy_intp dims[1] = {4};
|
npy_intp dims[1] = {4};
|
||||||
|
@ -204,6 +208,7 @@ BOOST_PYTHON_MODULE(rtc_plugins) {
|
||||||
py::def("sendCustomAudioData", &sendCustomAudioData);
|
py::def("sendCustomAudioData", &sendCustomAudioData);
|
||||||
py::def("getSize", &getSize);
|
py::def("getSize", &getSize);
|
||||||
py::def("getData", &getData);
|
py::def("getData", &getData);
|
||||||
|
py::def("getNumpyData", &getNumpydata);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Module initialization failed");
|
PyErr_SetString(PyExc_RuntimeError, "Module initialization failed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,6 @@ while True:
|
||||||
print("resend succ")
|
print("resend succ")
|
||||||
size = rtc_plugins.getSize()
|
size = rtc_plugins.getSize()
|
||||||
print(f"data size:{size}")
|
print(f"data size:{size}")
|
||||||
frame = rtc_plugins.getData()
|
frame = rtc_plugins.getNumpyData()
|
||||||
print(f"dataCount:{frame.dataCount}")
|
print(f"frame:{frame}")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
|
@ -699,6 +699,30 @@ RetAudioFrame RTCContext::getData() {
|
||||||
}
|
}
|
||||||
return {}; // 返回空对象
|
return {}; // 返回空对象
|
||||||
}
|
}
|
||||||
|
namespace bp = boost::python;
|
||||||
|
namespace np = boost::python::numpy;
|
||||||
|
np::ndarray RTCContext::getNumpydata() {
|
||||||
|
std::lock_guard<std::mutex> lock(dataMutex_);
|
||||||
|
RetAudioFrame frame = getData();
|
||||||
|
int16_t* data_ptr = frame.data.get(); // 你的数据指针
|
||||||
|
size_t length = frame.dataCount; // 数据长度
|
||||||
|
|
||||||
|
// 创建 NumPy 数组(拷贝数据)
|
||||||
|
if (!data_ptr || length == 0) {
|
||||||
|
// 返回空数组或抛出异常
|
||||||
|
return np::zeros(bp::make_tuple(0), np::dtype::get_builtin<int16_t>());
|
||||||
|
}
|
||||||
|
|
||||||
|
np::dtype dt = np::dtype::get_builtin<int16_t>();
|
||||||
|
return np::from_data(
|
||||||
|
data_ptr,
|
||||||
|
dt,
|
||||||
|
bp::make_tuple(length),
|
||||||
|
bp::make_tuple(sizeof(int16_t)),
|
||||||
|
bp::object()
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
int16_t RTCContext::getSize() {
|
int16_t RTCContext::getSize() {
|
||||||
std::lock_guard<std::mutex> lock(dataMutex_);
|
std::lock_guard<std::mutex> lock(dataMutex_);
|
||||||
|
|
|
@ -98,6 +98,7 @@ public:
|
||||||
int16_t getSize();
|
int16_t getSize();
|
||||||
void setData(const mrtc::MRTCAudioFrame& frame);
|
void setData(const mrtc::MRTCAudioFrame& frame);
|
||||||
RetAudioFrame getData();
|
RetAudioFrame getData();
|
||||||
|
np::ndarray getNumpydata();
|
||||||
|
|
||||||
void* getpData() const;
|
void* getpData() const;
|
||||||
void setpData(void* pData);
|
void setpData(void* pData);
|
||||||
|
|
Loading…
Reference in New Issue