This commit is contained in:
wangjiyu 2025-04-15 12:47:47 +08:00
parent 91827e8bf4
commit 2662e355b0
2 changed files with 10 additions and 10 deletions

View File

@ -1,6 +1,6 @@
g++ -shared -fPIC \
-I/usr/include/python3.10 -I/usr/include/python3.10/numpy -I./include \
-L./lib \
-L./lib -L/usr/lib/x86_64-linux-gnu \
-DRTC_NUMPY_IMPL \
rtc_plugins.cpp util/RTCContext.cpp \
-lMRTCEngine -lboost_python310 libboost_numpy310 -lpython3.10 \

View File

@ -17,17 +17,17 @@ srcChannelIndex = 46
destChannelIndex = 47
def my_callback(shmName, dataSize, dataCount, sampleRate, numChannels, channelIndex):
print(f"dataSize:{dataSize}, dataCount:{dataCount}, sampleRate:{sampleRate}, numChannels:{numChannels}, channelIndex:{channelIndex}")
print(shmName)
fd = os.open(shmName, os.O_RDONLY)
if fd == -1:
raise RuntimeError(f"无法打开共享内存 {shmName}")
print(f"data:{}shmName)
#fd = os.open(shmName, os.O_RDONLY)
#if fd == -1:
# raise RuntimeError(f"无法打开共享内存 {shmName}")
# 2. 创建内存映射
shm = mmap.mmap(fd, dataSize, mmap.MAP_SHARED, mmap.PROT_READ)
## 2. 创建内存映射
#shm = mmap.mmap(fd, dataSize, mmap.MAP_SHARED, mmap.PROT_READ)
# 3. 转换为numpy数组 (零拷贝)
audio_data = np.frombuffer(shm, dtype=c_int16, count=dataCount)
print(f" 前5个采样点: {audio_data[:5]}")
## 3. 转换为numpy数组 (零拷贝)
#audio_data = np.frombuffer(shm, dtype=c_int16, count=dataCount)
#print(f" 前5个采样点: {audio_data[:5]}")
#audioData = np.array([0, 1, -1, 0], dtype=np.int16)
#ret = rtc_plugins.sendCustomAudioData(srcChannelIndex, audioData, 48000, 1, len(audioData))
#if ret != 0: