add python send example
This commit is contained in:
parent
dc585389d6
commit
6aadae175d
2
build.sh
2
build.sh
|
@ -1,5 +1,5 @@
|
||||||
g++ -shared -fPIC \
|
g++ -shared -fPIC \
|
||||||
-I/usr/include/python3.10 -I./include \
|
-I/usr/include/python3.10 -I/usr/include/python3.10/numpy -I./include \
|
||||||
-L./lib \
|
-L./lib \
|
||||||
rtc_plugins.cpp util/RTCContext.cpp \
|
rtc_plugins.cpp util/RTCContext.cpp \
|
||||||
-lMRTCEngine -lboost_python310 -lpython3.10 \
|
-lMRTCEngine -lboost_python310 -lpython3.10 \
|
||||||
|
|
|
@ -30,9 +30,9 @@ int initSend(const char* destRoomId, const int16_t destChannelIndex) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate, uint64_t channelNum,
|
int sendCustomAudioData(const int16_t destChannelIndex, void* customData, int32_t sampleRate, uint64_t channelNum,
|
||||||
uint64_t dataLen) {
|
uint64_t dataLen) {
|
||||||
return RTCContext::instance().sendCustomAudioData(channelIndex, customData, sampleRate, channelNum, dataLen);
|
return RTCContext::instance().sendCustomAudioData(destChannelIndex, customData, sampleRate, channelNum, dataLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_PYTHON_MODULE(rtc_plugins) {
|
BOOST_PYTHON_MODULE(rtc_plugins) {
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import rtc_plugins
|
||||||
|
import time
|
||||||
|
|
||||||
|
srcUserId = "srcUser1"
|
||||||
|
destUserId = "destUser1"
|
||||||
|
|
||||||
|
srcDisplayName = "srcDisplayName1"
|
||||||
|
destDisplayName = "destDisplayName1"
|
||||||
|
srcRoomId = "srcRoom1"
|
||||||
|
destRoomId = "destRoomId1"
|
||||||
|
srcChannelIndex = 42
|
||||||
|
destChannelIndex = 43
|
||||||
|
def my_callback(npData, dataCount, sampleRate, numChannels, channelIndex):
|
||||||
|
print(f"dataCount:{dataCount}, sampleRate:{sampleRate}, numChannels:{numChannels}, channelIndex:{channelIndex}")
|
||||||
|
ret = rtc_plugins.init(srcUserId, srcDisplayName, srcRoomId, my_callback)
|
||||||
|
if ret != 0:
|
||||||
|
print(f"init fail, ret:{ret}")
|
||||||
|
exit(1)
|
||||||
|
ret = rtc_plugins.initSend(destRoomId, destChannelIndex)
|
||||||
|
if ret != 0:
|
||||||
|
print(f"initSend fail, ret:{ret}")
|
||||||
|
exit(1)
|
||||||
|
while True:
|
||||||
|
ret = rtc_plugins.sendCustomAudioData(destChannelIndex, "aaaaa", 48000, 1, 10)
|
||||||
|
if ret != 0:
|
||||||
|
print(f"send fail, ret:{ret}")
|
||||||
|
time.sleep(3)
|
|
@ -43,7 +43,9 @@ void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
|
||||||
std::cout << "dataCount:" << audioFrame.dataCount << audioSourceType;
|
std::cout << "dataCount:" << audioFrame.dataCount << audioSourceType;
|
||||||
if (!py_callback_.is_none()) {
|
if (!py_callback_.is_none()) {
|
||||||
std::cout << "python callback" << std::endl;
|
std::cout << "python callback" << std::endl;
|
||||||
py_callback_(audioFrame.data, audioFrame.dataCount, audioFrame.sampleRate, audioFrame.numChannels,
|
npy_intp dims[1] = {audioFrame.dataCount};
|
||||||
|
PyObject* pyArray = PyArray_SimpleNewFromData(1, dims, NPY_INT16, audioFrame.data);
|
||||||
|
py_callback_(py::handle<>(pyArray), audioFrame.dataCount, audioFrame.sampleRate, audioFrame.numChannels,
|
||||||
audioFrame.channelIndex);
|
audioFrame.channelIndex);
|
||||||
}
|
}
|
||||||
//sendAudioData(audioFrame.channelIndex, audioFrame.data, audioFrame.sampleRate, audioFrame.numChannels,
|
//sendAudioData(audioFrame.channelIndex, audioFrame.data, audioFrame.sampleRate, audioFrame.numChannels,
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <boost/python.hpp>
|
#include <boost/python.hpp>
|
||||||
|
#include <numpy/arrayobject.h>
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
#define ENV_PRODUCT
|
#define ENV_PRODUCT
|
||||||
//#define SEND_MODE
|
//#define SEND_MODE
|
||||||
|
|
Loading…
Reference in New Issue