From ae7eecfb890d9f0571ee167ff9cd3a8d264f6a9a Mon Sep 17 00:00:00 2001 From: "he.wu" Date: Tue, 21 Jan 2025 09:49:11 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat=EF=BC=9A=E7=94=A8=E6=88=B7=E7=A6=BB?= =?UTF-8?q?=E5=BC=80=E6=88=BF=E9=97=B4=E5=9B=9E=E8=B0=83python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rect.py | 15 ++++++++++++--- rtcclient.cpp | 25 ++++++++++++++++++++++++- rtcclient.h | 9 +++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/rect.py b/rect.py index 85a8af3..adeb44d 100644 --- a/rect.py +++ b/rect.py @@ -11,11 +11,12 @@ channel = 1 bitsize = 2 duration_time_s = 0.1 # url = "https://rtc-dev.uicloud.com/r/#/join" -url = "https://rtc.uicloud.com" +url = https://v.nice2meet.cn" ak = "W68FH19QN2NI186THUX3XXG4CBMYKHXL" sk = "HM9ECOGZIBR6OOWG00G3EFVDILOZSHPT" -roomid = '20589675' +roomid = '12345678930' +token = "YzhiZmNlYjhmOGYzNmVhMDE5NDdkNTQ0ZDg5ZTkxZTFiZjMyMTdjYg==" import cv2 import numpy as np @@ -24,6 +25,9 @@ import numpy as np client = RtcClient() time.sleep(2) +# 指定回调的python函数 +client.setLeaveIndicationCallback(handleLeaveIndication) + ## 加入房间 client.loadAndJoinRoom(url, token, True, roomid, '90091', 'ai_agent', 10) time.sleep(2) @@ -46,4 +50,9 @@ for i in range(200): h,w = frame.shape[:2] time.sleep(0.04) client.publishVedioStream(w,h, frame.tobytes(), len(frame.tobytes())) -client.leave(0) \ No newline at end of file +client.leave(0) + +# 设置离开房间回调,需要调用leave方法,否则数字人会重复进入会议 +def handleLeaveIndication(reason, fromId): + print(f"User {fromId} left the room with reason: {reason}")) + client.leave(reason) \ No newline at end of file diff --git a/rtcclient.cpp b/rtcclient.cpp index 158d1d2..0bc8039 100644 --- a/rtcclient.cpp +++ b/rtcclient.cpp @@ -534,10 +534,33 @@ void RtcClient::onUnpublishLocalResult(Result result, const DeviceId& fromId) void RtcClient::onPublicMessage(const AvdMessage& message) { + std::cout << "onPublicMessage ,message==" << message.message << endl; } void RtcClient::onPrivateMessage(const AvdMessage& message) { + std::cout << "onPrivateMessage ,message=" << message.message << endl; } + +// 用户离开回调异步处理 +void RtcClient::onLeaveIndication(Result reason, const rtc::UserId& fromId) { + std::cout << "onLeaveIndication callback ,reason=" << reason << ",fromId=" << fromId << endl; + if (leave_indication_callback_) { + py::gil_scoped_acquire acquire; + try { + leave_indication_callback_(reason, fromId); + } + catch (const py::error_already_set& e) { + PyErr_Print(); + } + } +} + +// 设置回调函数 +void RtcClient::setLeaveIndicationCallback(py::object callback) { + std::lock_guard guard(callback_mutex_); + leave_indication_callback_ = callback; +} + void RtcClient::onMicrophoneStatusNotify(rtc::MicrophoneStatus status, const rtc::UserId& fromUserId) { cout << "onMicrophoneStatusNotify ,status=" << status << ",fromUserId=" << fromUserId << endl; @@ -678,7 +701,7 @@ PYBIND11_MODULE(rtc_client, m) .def("publishVedioStream", &RtcClient::publishVedioStream) .def("onInitResult", &RtcClient::onInitResult) .def("subAudioStream", &RtcClient::subAudioStream) - .def("getAudioStream", &RtcClient::getAudioStream); + .def("setLeaveIndicationCallback", &RtcClient::setLeaveIndicationCallback); // .def("getAudioStream", &RtcClient::getAudioStream, // py::return_value_policy::take_ownership, // py::implicitly_convertible, py::bytes>()); diff --git a/rtcclient.h b/rtcclient.h index b0bfdd6..6b4d84b 100644 --- a/rtcclient.h +++ b/rtcclient.h @@ -47,6 +47,10 @@ public: + // 뿪ָʾص + void setLeaveIndicationCallback(py::object callback); + + public: int getState(); int ScheduleRoom(); @@ -64,6 +68,7 @@ private: // chat message callbak void onPublicMessage(const AvdMessage &message); void onPrivateMessage(const AvdMessage &message); + void onLeaveIndication(Result reason, const rtc::UserId& fromId); // audio callback void onMicrophoneStatusNotify(rtc::MicrophoneStatus status, const rtc::UserId &fromUserId); @@ -103,6 +108,10 @@ private: bool m_audioSubed; bool m_createRoomForTest; std::map m_audioPcmOutMap; + + // صصijԱ + std::mutex callback_mutex_; + py::object leave_indication_callback_; }; -- Gitee From 5a87fc82bc62977759597d18ee641d07e6976d6c Mon Sep 17 00:00:00 2001 From: "he.wu" Date: Tue, 21 Jan 2025 09:53:34 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20=E9=94=99=E5=88=A0.def("getAudioStre?= =?UTF-8?q?am"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rtcclient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/rtcclient.cpp b/rtcclient.cpp index 0bc8039..4e0e54e 100644 --- a/rtcclient.cpp +++ b/rtcclient.cpp @@ -701,6 +701,7 @@ PYBIND11_MODULE(rtc_client, m) .def("publishVedioStream", &RtcClient::publishVedioStream) .def("onInitResult", &RtcClient::onInitResult) .def("subAudioStream", &RtcClient::subAudioStream) + .def("getAudioStream", &RtcClient::getAudioStream) .def("setLeaveIndicationCallback", &RtcClient::setLeaveIndicationCallback); // .def("getAudioStream", &RtcClient::getAudioStream, // py::return_value_policy::take_ownership, -- Gitee From d4bbea86293f430948d0c0049b11f00c1045d607 Mon Sep 17 00:00:00 2001 From: "he.wu" Date: Tue, 21 Jan 2025 10:40:26 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9rect.py=E7=94=A8?= =?UTF-8?q?=E4=BA=8E=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rect.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rect.py b/rect.py index adeb44d..cf3eb9e 100644 --- a/rect.py +++ b/rect.py @@ -11,7 +11,7 @@ channel = 1 bitsize = 2 duration_time_s = 0.1 # url = "https://rtc-dev.uicloud.com/r/#/join" -url = https://v.nice2meet.cn" +url = ""https://v.nice2meet.cn" ak = "W68FH19QN2NI186THUX3XXG4CBMYKHXL" sk = "HM9ECOGZIBR6OOWG00G3EFVDILOZSHPT" @@ -25,6 +25,11 @@ import numpy as np client = RtcClient() time.sleep(2) +# 设置离开房间回调,需要调用leave方法,否则数字人会重复进入会议 +def handleLeaveIndication(reason, fromId): + print(f"User {fromId} left the room with reason: {reason}")) + client.leave(reason) + # 指定回调的python函数 client.setLeaveIndicationCallback(handleLeaveIndication) @@ -51,8 +56,3 @@ for i in range(200): time.sleep(0.04) client.publishVedioStream(w,h, frame.tobytes(), len(frame.tobytes())) client.leave(0) - -# 设置离开房间回调,需要调用leave方法,否则数字人会重复进入会议 -def handleLeaveIndication(reason, fromId): - print(f"User {fromId} left the room with reason: {reason}")) - client.leave(reason) \ No newline at end of file -- Gitee From 2d44e1145ac85e37b8a3a2cab364a090a33949ec Mon Sep 17 00:00:00 2001 From: "he.wu" Date: Tue, 21 Jan 2025 11:10:07 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9rect.py?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rect.py b/rect.py index cf3eb9e..9a13abb 100644 --- a/rect.py +++ b/rect.py @@ -11,7 +11,7 @@ channel = 1 bitsize = 2 duration_time_s = 0.1 # url = "https://rtc-dev.uicloud.com/r/#/join" -url = ""https://v.nice2meet.cn" +url = "https://v.nice2meet.cn" ak = "W68FH19QN2NI186THUX3XXG4CBMYKHXL" sk = "HM9ECOGZIBR6OOWG00G3EFVDILOZSHPT" @@ -27,7 +27,7 @@ time.sleep(2) # 设置离开房间回调,需要调用leave方法,否则数字人会重复进入会议 def handleLeaveIndication(reason, fromId): - print(f"User {fromId} left the room with reason: {reason}")) + print(f"User {fromId} left the room with reason: {reason}") client.leave(reason) # 指定回调的python函数 -- Gitee