From 2bf1e14e89965fff857fcac975466732dd36abfb Mon Sep 17 00:00:00 2001 From: wangjiyu Date: Mon, 14 Apr 2025 16:38:06 +0800 Subject: [PATCH] add test send recv --- test_time_r.py | 35 +++++++++++++++++++++++++++++++++++ test_time_s.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 test_time_r.py create mode 100644 test_time_s.py diff --git a/test_time_r.py b/test_time_r.py new file mode 100644 index 0000000..b364154 --- /dev/null +++ b/test_time_r.py @@ -0,0 +1,35 @@ +import rtc_plugins +import time +import numpy as np + +srcUserId = "destUser1" +destUserId = "srcUser1" + +srcDisplayName = "destDisplayName1" +destDisplayName = "srcDisplayName1" +srcRoomId = "destRoom1" +destRoomId = "srcRoomId1" +srcChannelIndex = 43 +destChannelIndex = 42 + +send_time = 0 +total_time = 0 +total_cnt = 0 +def my_callback(npData, dataCount, sampleRate, numChannels, channelIndex): + global destChannelIndex + audioData = np.array([0, 1, -1, 0], dtype=np.int16) + ret = rtc_plugins.sendCustomAudioData(destChannelIndex, audioData, 48000, 1, len(audioData)) + + +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) +ret = rtc_plugins.initRecv(destRoomId, srcUserId, destChannelIndex) +if ret != 0: + print(f"initRecv fail, ret:{ret}") + exit(1) diff --git a/test_time_s.py b/test_time_s.py new file mode 100644 index 0000000..0c1195d --- /dev/null +++ b/test_time_s.py @@ -0,0 +1,48 @@ +import rtc_plugins +import time +import numpy as np + +srcUserId = "srcUser1" +destUserId = "destUser1" + +srcDisplayName = "srcDisplayName1" +destDisplayName = "destDisplayName1" +srcRoomId = "srcRoom1" +destRoomId = "destRoomId1" +srcChannelIndex = 42 +destChannelIndex = 43 + +send_time = 0 +total_time = 0 +total_cnt = 0 +def my_callback(npData, dataCount, sampleRate, numChannels, channelIndex): + global total_time, total_cnt + recv_time = time.time() + total_time = total_time + (recv_time - send_time) + total_cnt = total_cnt + 1 + 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) +ret = rtc_plugins.initRecv(destRoomId, srcUserId, destChannelIndex) +if ret != 0: + print(f"initRecv fail, ret:{ret}") + exit(1) + +audioData = np.array([0, 1, -1, 0], dtype=np.int16) +for i in range(100): + send_time = time.time() + ret = rtc_plugins.sendCustomAudioData(destChannelIndex, audioData, 48000, 1, len(audioData)) + if ret != 0: + print(f"send fail, ret:{ret}") + time.sleep(3) + +print(f"total_time:{total_time}, total_cnt:{total_cnt}") +print(total_time/total_cnt) \ No newline at end of file