From bbac7269cd470f21e63f2f06aa4e25b4a6a60397 Mon Sep 17 00:00:00 2001 From: wangjiyu Date: Sat, 3 May 2025 19:45:44 +0800 Subject: [PATCH] debug --- src/util/RTCContext.cpp | 74 ++++++++++++++++++++++++----------------- src/util/RTCContext.h | 20 ++++++++++- 2 files changed, 63 insertions(+), 31 deletions(-) diff --git a/src/util/RTCContext.cpp b/src/util/RTCContext.cpp index b898b57..0575065 100644 --- a/src/util/RTCContext.cpp +++ b/src/util/RTCContext.cpp @@ -2,9 +2,6 @@ #include "drogon/drogon_test.h" -#include -#include - void RTCContext::onRoom(uint32_t typeId, RTCENGINE_NAMESPACE::MRTCRoomInfo& roomInfo) { //LOG_DEBUG << "RTCContext::onRoom():" << roomInfo.roomId << "," << roomInfo.displayName << "," << roomInfo.userId << "," << roomInfo.message; LOG_DEBUG << "RTCContext::onRoom()"; @@ -12,10 +9,30 @@ void RTCContext::onRoom(uint32_t typeId, RTCENGINE_NAMESPACE::MRTCRoomInfo& room isOnRoom_ = true; } void RTCContext::onConsumer(uint32_t msgId, const char* roomId, const char* peerId, RTCENGINE_NAMESPACE::MRTCConsumerInfo& consumerInfo) { - LOG_DEBUG << "RTCContext::onConsumer():" << consumerInfo.roomId << "," << consumerInfo.displayName << "," << consumerInfo.channelIndex; + //LOG_DEBUG << "RTCContext::onConsumer()"; + LOG_DEBUG << "RTCContext::onConsumer():msgId:" << msgId << ", roomId:" << consumerInfo.roomId << ", displayName:" + << consumerInfo.displayName << ", channelIndex" << consumerInfo.channelIndex; std::lock_guard lock(mutex_); isOnConsumer_ = true; - //LOG_DEBUG << "RTCContext::onConsumer()"; + LOG_DEBUG << "registerSoundLevelListener"; + int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, roomId, + peerId, consumerInfo.channelIndex, this); + if (0 != ret1) + { + LOG_DEBUG << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1; + return; + } + + LOG_DEBUG << "muteAudio"; + int16_t ret2 = rtcEngine_->muteAudio(roomId, peerId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM, + false, consumerInfo.channelIndex); + if (0 != ret2) + { + LOG_DEBUG << "RTCContext::instance().muteAudio() failed, ret:" << ret2; + return; + } + + LOG_DEBUG << "init recv succ"; } void RTCContext::onRender(const char* roomId, const char* peerId, RTCENGINE_NAMESPACE::MRTCVideoSourceType sourceType, const RTCENGINE_NAMESPACE::MRTCVideoFrame& videoFrame) { @@ -111,43 +128,35 @@ bool RTCContext::initRecv(const char* destRoomId, const char* srcUserId, const i LOG_DEBUG << "wait for OnConsumer"; sleep(3); } - LOG_DEBUG << "registerSoundLevelListener"; - int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, destRoomId, - srcUserId, destChannelIndex, this); - if (0 != ret1) - { - LOG_DEBUG << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1; - return false; - } - LOG_DEBUG << "muteAudio"; - int16_t ret2 = rtcEngine_->muteAudio(destRoomId, srcUserId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM, false, destChannelIndex); - if (0 != ret2) - { - LOG_DEBUG << "RTCContext::instance().muteAudio() failed, ret:" << ret2; - return false; - } - LOG_DEBUG << "init recv succ"; return true; } -bool RTCContext::initSend(const char* destRoomId, const int16_t destChannelIndex) +bool RTCContext::initSend(const char* srcRoomId, const char* destRoomId, const int16_t destChannelIndex, + const uint8_t channelNum) { while (!isOnRoom_) { LOG_DEBUG << "wait for OnRoom"; sleep(3); } - LOG_DEBUG << "join multi room"; - int16_t ret1 = rtcEngine_->joinMultiRoom(destRoomId); - if (ret1 != 0) - { - LOG_DEBUG << "joinMultiRoom fail, ret:" << ret1; - return false; + if (std::string(srcRoomId) != std::string(destRoomId)) { + isMultiRoom_ = true; + LOG_DEBUG << "join multi room"; + int16_t ret1 = rtcEngine_->joinMultiRoom(destRoomId); + if (ret1 != 0) { + LOG_DEBUG << "joinMultiRoom fail, ret:" << ret1; + return false; + } + } else { + isMultiRoom_ = false; } mrtc::MRTCAudioOption option; - strcpy(option.dstRoomId, destRoomId); + if (std::string(srcRoomId) != std::string(destRoomId)) { + strcpy(option.dstRoomId, destRoomId); + } option.channelIndex = destChannelIndex; + option.channel = channelNum; LOG_DEBUG << "startCustomAudio"; int16_t ret2 = rtcEngine_->startCustomAudio(option); if (ret2 != 0) @@ -175,11 +184,16 @@ int16_t RTCContext::sendAudioData(uint8_t channelIndex, const void* pData, int32 int16_t RTCContext::sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate, uint64_t channelNum, uint64_t dataLen) { - while(!isOnRoom_ || !isJoinMultiRoom_) { + while(!isOnRoom_ || (isMultiRoom_ && !isJoinMultiRoom_)) { LOG_DEBUG << "wait for room and multi room before send"; sleep(3); } std::lock_guard lock(mutex_); + if (customData == nullptr) { + LOG_DEBUG << "customData is null"; + return -1; + } + LOG_DEBUG << "customData addr is:" << customData; return rtcEngine_->sendCustomAudioData(channelIndex, customData, sampleRate, channelNum, dataLen); } mrtc::IMRTCEngine* RTCContext::getRtcEngine() const diff --git a/src/util/RTCContext.h b/src/util/RTCContext.h index 44da776..8565b80 100644 --- a/src/util/RTCContext.h +++ b/src/util/RTCContext.h @@ -4,10 +4,27 @@ #include #include #include // C++17 +#include +#include +#include +#include +#include +#include + namespace fs = std::filesystem; #define ENV_PRODUCT //#define SEND_MODE +// 音频数据帧 +struct RetAudioFrame final +{ + std::unique_ptr data; + int dataCount = 0; + int sampleRate = 48000; + int numChannels = 1; + int channelIndex = 0; +}; + class RTCContext : public RTCENGINE_NAMESPACE::IMRTCRoomCallBack, public RTCENGINE_NAMESPACE::IMRTCConsumerCallBack, @@ -39,7 +56,7 @@ public: mrtc::IMRTCEngine* getRtcEngine() const; bool init(const char* selfUserId, const char* selfDisplayName, const char* selfRoomId); bool initRecv(const char* destRoomId, const char* srcUserId, const int16_t destChannelIndex); - bool initSend(const char* destRoomId, const int16_t destChannelIndex); + bool initSend(const char* srcRoomId, const char* destRoomId, const int16_t destChannelIndex, const uint8_t channelNum); void* getpData() const; void setpData(void* pData); @@ -59,6 +76,7 @@ private: bool isOnRoom_ = false; bool isOnConsumer_ = false; bool isJoinMultiRoom_ = false; + bool isMultiRoom_ = false; void onRoom(uint32_t typeId, RTCENGINE_NAMESPACE::MRTCRoomInfo& roomInfo); void onConsumer(uint32_t msgId, const char* roomId, const char* peerId, RTCENGINE_NAMESPACE::MRTCConsumerInfo& consumerInfo); void onRender(const char* roomId, const char* peerId,